Add warning when enabling X11 shortcuts on gnome, cinnamon and KDE
This commit is contained in:
parent
3241815a11
commit
f90de75e3a
@ -700,6 +700,10 @@ QString FiddleFileExtension(const QString &filename, const QString &new_extensio
|
|||||||
return PathWithoutFilenameExtension(filename) + "." + new_extension;
|
return PathWithoutFilenameExtension(filename) + "." + new_extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString GetEnv(const QString &key) {
|
||||||
|
return QString::fromLocal8Bit(qgetenv(key.toLocal8Bit()));
|
||||||
|
}
|
||||||
|
|
||||||
void SetEnv(const char *key, const QString &value) {
|
void SetEnv(const char *key, const QString &value) {
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
@ -767,6 +771,33 @@ QString GetRandomString(const int len, const QString &UseCharacters) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString DesktopEnvironment() {
|
||||||
|
|
||||||
|
const QString de = GetEnv("XDG_CURRENT_DESKTOP");
|
||||||
|
if (!de.isEmpty()) return de;
|
||||||
|
|
||||||
|
if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION")) return "KDE";
|
||||||
|
if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID")) return "Gnome";
|
||||||
|
|
||||||
|
QString session = GetEnv("DESKTOP_SESSION");
|
||||||
|
int slash = session.lastIndexOf('/');
|
||||||
|
if (slash != -1) {
|
||||||
|
QSettings desktop_file(QString(session + ".desktop"), QSettings::IniFormat);
|
||||||
|
desktop_file.beginGroup("Desktop Entry");
|
||||||
|
QString name = desktop_file.value("DesktopNames").toString();
|
||||||
|
desktop_file.endGroup();
|
||||||
|
if (!name.isEmpty()) return name;
|
||||||
|
session = session.mid(slash + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session == "kde") return "KDE";
|
||||||
|
else if (session == "gnome") return "Gnome";
|
||||||
|
else if (session == "xfce") return "XFCE";
|
||||||
|
|
||||||
|
return "Unknown";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Utilities
|
} // namespace Utilities
|
||||||
|
|
||||||
ScopedWCharArray::ScopedWCharArray(const QString &str)
|
ScopedWCharArray::ScopedWCharArray(const QString &str)
|
||||||
|
@ -122,6 +122,7 @@ QUrl GetRelativePathToStrawberryBin(const QUrl &url);
|
|||||||
QString PathWithoutFilenameExtension(const QString &filename);
|
QString PathWithoutFilenameExtension(const QString &filename);
|
||||||
QString FiddleFileExtension(const QString &filename, const QString &new_extension);
|
QString FiddleFileExtension(const QString &filename, const QString &new_extension);
|
||||||
|
|
||||||
|
QString GetEnv(const QString &key);
|
||||||
void SetEnv(const char *key, const QString &value);
|
void SetEnv(const char *key, const QString &value);
|
||||||
void IncreaseFDLimit();
|
void IncreaseFDLimit();
|
||||||
void CheckPortable();
|
void CheckPortable();
|
||||||
@ -153,7 +154,9 @@ QString GetRandomStringWithChars(const int len);
|
|||||||
QString GetRandomStringWithCharsAndNumbers(const int len);
|
QString GetRandomStringWithCharsAndNumbers(const int len);
|
||||||
QString GetRandomString(const int len, const QString &UseCharacters);
|
QString GetRandomString(const int len, const QString &UseCharacters);
|
||||||
|
|
||||||
}
|
QString DesktopEnvironment();
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
class ScopedWCharArray {
|
class ScopedWCharArray {
|
||||||
public:
|
public:
|
||||||
|
@ -52,7 +52,7 @@ GlobalShortcuts::GlobalShortcuts(QWidget *parent)
|
|||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
dbus_backend_(nullptr),
|
dbus_backend_(nullptr),
|
||||||
system_backend_(nullptr),
|
system_backend_(nullptr),
|
||||||
use_dbus_(true),
|
use_gsd_(true),
|
||||||
use_x11_(false)
|
use_x11_(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ GlobalShortcuts::GlobalShortcuts(QWidget *parent)
|
|||||||
void GlobalShortcuts::ReloadSettings() {
|
void GlobalShortcuts::ReloadSettings() {
|
||||||
|
|
||||||
// The actual shortcuts have been set in our actions for us by the config dialog already - we just need to reread the gnome settings.
|
// The actual shortcuts have been set in our actions for us by the config dialog already - we just need to reread the gnome settings.
|
||||||
use_dbus_ = settings_.value("use_dbus", true).toBool();
|
use_gsd_ = settings_.value("use_gsd", true).toBool();
|
||||||
use_x11_ = settings_.value("use_x11", true).toBool();
|
use_x11_ = settings_.value("use_x11", true).toBool();
|
||||||
|
|
||||||
Unregister();
|
Unregister();
|
||||||
@ -152,7 +152,7 @@ bool GlobalShortcuts::IsX11Available() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GlobalShortcuts::Register() {
|
void GlobalShortcuts::Register() {
|
||||||
if (use_dbus_ && dbus_backend_ && dbus_backend_->Register()) return;
|
if (use_gsd_ && dbus_backend_ && dbus_backend_->Register()) return;
|
||||||
#ifdef HAVE_X11 // If this system has X11, only use the system backend if X11 is enabled in the global shortcut settings
|
#ifdef HAVE_X11 // If this system has X11, only use the system backend if X11 is enabled in the global shortcut settings
|
||||||
if (use_x11_)
|
if (use_x11_)
|
||||||
#endif
|
#endif
|
||||||
|
@ -97,7 +97,7 @@ class GlobalShortcuts : public QWidget {
|
|||||||
QMap<QString, Shortcut> shortcuts_;
|
QMap<QString, Shortcut> shortcuts_;
|
||||||
QSettings settings_;
|
QSettings settings_;
|
||||||
|
|
||||||
bool use_dbus_;
|
bool use_gsd_;
|
||||||
bool use_x11_;
|
bool use_x11_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -70,8 +70,8 @@ GlobalShortcutsSettingsPage::GlobalShortcutsSettingsPage(SettingsDialog *dialog)
|
|||||||
|
|
||||||
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
|
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
|
||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
connect(ui_->checkbox_dbus, SIGNAL(clicked(bool)), SLOT(DBusChanged(bool)));
|
connect(ui_->checkbox_gsd, SIGNAL(clicked(bool)), SLOT(GSDChanged(bool)));
|
||||||
connect(ui_->button_dbus_open, SIGNAL(clicked()), SLOT(OpenGnomeKeybindingProperties()));
|
connect(ui_->button_gsd_open, SIGNAL(clicked()), SLOT(OpenGnomeKeybindingProperties()));
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_X11
|
#ifdef HAVE_X11
|
||||||
connect(ui_->checkbox_x11, SIGNAL(clicked(bool)), SLOT(X11Changed(bool)));
|
connect(ui_->checkbox_x11, SIGNAL(clicked(bool)), SLOT(X11Changed(bool)));
|
||||||
@ -102,15 +102,18 @@ void GlobalShortcutsSettingsPage::Load() {
|
|||||||
if (!initialised_) {
|
if (!initialised_) {
|
||||||
initialised_ = true;
|
initialised_ = true;
|
||||||
|
|
||||||
|
de_ = Utilities::DesktopEnvironment();
|
||||||
|
ui_->widget_warning->hide();
|
||||||
|
|
||||||
connect(ui_->button_macos_open, SIGNAL(clicked()), manager, SLOT(ShowMacAccessibilityDialog()));
|
connect(ui_->button_macos_open, SIGNAL(clicked()), manager, SLOT(ShowMacAccessibilityDialog()));
|
||||||
|
|
||||||
if (manager->IsGsdAvailable()) {
|
if (manager->IsGsdAvailable()) {
|
||||||
qLog(Debug) << "Gnome D-Bus backend is available.";
|
qLog(Debug) << "Gnome (GSD) D-Bus backend is available.";
|
||||||
ui_->widget_dbus->show();
|
ui_->widget_gsd->show();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qLog(Debug) << "Gnome D-Bus backend is unavailable.";
|
qLog(Debug) << "Gnome (GSD) D-Bus backend is unavailable.";
|
||||||
ui_->widget_dbus->hide();
|
ui_->widget_gsd->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (manager->IsX11Available()) {
|
if (manager->IsX11Available()) {
|
||||||
@ -140,9 +143,9 @@ void GlobalShortcutsSettingsPage::Load() {
|
|||||||
SetShortcut(s.s.id, s.s.action->shortcut());
|
SetShortcut(s.s.id, s.s.action->shortcut());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool use_dbus = settings_.value("use_dbus", true).toBool();
|
bool use_gsd = settings_.value("use_gsd", true).toBool();
|
||||||
if (ui_->widget_dbus->isVisibleTo(this)) {
|
if (ui_->widget_gsd->isVisibleTo(this)) {
|
||||||
ui_->checkbox_dbus->setChecked(use_dbus);
|
ui_->checkbox_gsd->setChecked(use_gsd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool use_x11 = settings_.value("use_x11", false).toBool();
|
bool use_x11 = settings_.value("use_x11", false).toBool();
|
||||||
@ -152,7 +155,7 @@ void GlobalShortcutsSettingsPage::Load() {
|
|||||||
|
|
||||||
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
|
#if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS)
|
||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
DBusChanged(true);
|
GSDChanged(true);
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_X11
|
#ifdef HAVE_X11
|
||||||
X11Changed(true);
|
X11Changed(true);
|
||||||
@ -176,7 +179,7 @@ void GlobalShortcutsSettingsPage::Save() {
|
|||||||
settings_.setValue(s.s.id, s.key.toString());
|
settings_.setValue(s.s.id, s.key.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
settings_.setValue("use_dbus", ui_->checkbox_dbus->isChecked());
|
settings_.setValue("use_gsd", ui_->checkbox_gsd->isChecked());
|
||||||
settings_.setValue("use_x11", ui_->checkbox_x11->isChecked());
|
settings_.setValue("use_x11", ui_->checkbox_x11->isChecked());
|
||||||
|
|
||||||
dialog()->global_shortcuts_manager()->ReloadSettings();
|
dialog()->global_shortcuts_manager()->ReloadSettings();
|
||||||
@ -192,31 +195,31 @@ void GlobalShortcutsSettingsPage::X11Changed(bool) {
|
|||||||
if (ui_->checkbox_x11->isChecked()) {
|
if (ui_->checkbox_x11->isChecked()) {
|
||||||
ui_->list->setEnabled(true);
|
ui_->list->setEnabled(true);
|
||||||
ui_->shortcut_options->setEnabled(true);
|
ui_->shortcut_options->setEnabled(true);
|
||||||
|
X11Warning();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ui_->list->setEnabled(false);
|
ui_->list->setEnabled(false);
|
||||||
ui_->shortcut_options->setEnabled(false);
|
ui_->shortcut_options->setEnabled(false);
|
||||||
|
ui_->widget_warning->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif // HAVE_X11
|
#endif // HAVE_X11
|
||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
void GlobalShortcutsSettingsPage::DBusChanged(bool) {
|
void GlobalShortcutsSettingsPage::GSDChanged(bool) {
|
||||||
|
|
||||||
if (!ui_->widget_dbus->isVisibleTo(this)) return;
|
if (!ui_->widget_gsd->isVisibleTo(this)) return;
|
||||||
|
|
||||||
if (ui_->checkbox_dbus->isChecked()) {
|
if (ui_->checkbox_gsd->isChecked()) {
|
||||||
if (ui_->checkbox_x11->isEnabled()) {
|
if (ui_->checkbox_x11->isEnabled()) {
|
||||||
ui_->checkbox_x11->setEnabled(false);
|
ui_->checkbox_x11->setEnabled(false);
|
||||||
ui_->list->setEnabled(false);
|
|
||||||
ui_->shortcut_options->setEnabled(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ui_->checkbox_x11->isChecked()) {
|
if (ui_->checkbox_x11->isChecked()) {
|
||||||
ui_->checkbox_x11->setChecked(false);
|
ui_->checkbox_x11->setChecked(false);
|
||||||
ui_->list->setEnabled(false);
|
|
||||||
ui_->shortcut_options->setEnabled(false);
|
|
||||||
}
|
}
|
||||||
|
ui_->list->setEnabled(false);
|
||||||
|
ui_->shortcut_options->setEnabled(false);
|
||||||
|
ui_->widget_warning->hide();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!ui_->checkbox_x11->isEnabled()) {
|
if (!ui_->checkbox_x11->isEnabled()) {
|
||||||
@ -224,6 +227,7 @@ void GlobalShortcutsSettingsPage::DBusChanged(bool) {
|
|||||||
if (ui_->checkbox_x11->isChecked()) {
|
if (ui_->checkbox_x11->isChecked()) {
|
||||||
ui_->list->setEnabled(true);
|
ui_->list->setEnabled(true);
|
||||||
ui_->shortcut_options->setEnabled(true);
|
ui_->shortcut_options->setEnabled(true);
|
||||||
|
X11Warning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,3 +300,23 @@ void GlobalShortcutsSettingsPage::ChangeClicked() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GlobalShortcutsSettingsPage::X11Warning() {
|
||||||
|
|
||||||
|
if (de_.toLower() == "kde" || de_.toLower() == "gnome" || de_.toLower() == "x-cinnamon") {
|
||||||
|
QString text(tr("Using X11 shortcuts on %1 is not recommended and can cause keyboard to become unresponsive!").arg(de_));
|
||||||
|
if (de_.toLower() == "kde")
|
||||||
|
text += tr(" Shortcuts on %1 are usually used through MPRIS D-Bus and should be configured in %1 settings instead.").arg(de_);
|
||||||
|
else if (de_.toLower() == "gnome")
|
||||||
|
text += tr(" Shortcuts on %1 are usually used through GSD D-Bus and should be configured in gnome-settings-daemon instead.").arg(de_);
|
||||||
|
else if (de_.toLower() == "x-cinnamon")
|
||||||
|
text += tr(" Shortcuts on %1 are usually used through GSD D-Bus and should be configured in cinnamon-settings-daemon instead.").arg(de_);
|
||||||
|
else
|
||||||
|
text += tr(" Shortcuts should be configured in %1 settings instead.").arg(de_);
|
||||||
|
ui_->label_warn_text->setText(text);
|
||||||
|
ui_->widget_warning->show();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui_->widget_warning->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -62,7 +62,7 @@ class GlobalShortcutsSettingsPage : public SettingsPage {
|
|||||||
void X11Changed(bool);
|
void X11Changed(bool);
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
void DBusChanged(bool);
|
void GSDChanged(bool);
|
||||||
void OpenGnomeKeybindingProperties();
|
void OpenGnomeKeybindingProperties();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -81,6 +81,8 @@ class GlobalShortcutsSettingsPage : public SettingsPage {
|
|||||||
|
|
||||||
void SetShortcut(const QString &id, const QKeySequence &key);
|
void SetShortcut(const QString &id, const QKeySequence &key);
|
||||||
|
|
||||||
|
void X11Warning();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui_GlobalShortcutsSettingsPage *ui_;
|
Ui_GlobalShortcutsSettingsPage *ui_;
|
||||||
|
|
||||||
@ -91,6 +93,8 @@ class GlobalShortcutsSettingsPage : public SettingsPage {
|
|||||||
QMap<QString, Shortcut> shortcuts_;
|
QMap<QString, Shortcut> shortcuts_;
|
||||||
|
|
||||||
QString current_id_;
|
QString current_id_;
|
||||||
|
QString de_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GLOBALSHORTCUTSSETTINGSPAGE_H
|
#endif // GLOBALSHORTCUTSSETTINGSPAGE_H
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="widget_dbus" native="true">
|
<widget class="QWidget" name="widget_gsd" native="true">
|
||||||
<layout class="QHBoxLayout" name="layout_gnome">
|
<layout class="QHBoxLayout" name="layout_gnome">
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
@ -34,7 +34,7 @@
|
|||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkbox_dbus">
|
<widget class="QCheckBox" name="checkbox_gsd">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@ -42,12 +42,12 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Use Gnome D-Bus shortcut keys</string>
|
<string>Use Gnome (GSD) D-Bus shortcut keys</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="button_dbus_open">
|
<widget class="QPushButton" name="button_gsd_open">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Open...</string>
|
<string>Open...</string>
|
||||||
</property>
|
</property>
|
||||||
@ -90,6 +90,62 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget_warning" native="true">
|
||||||
|
<layout class="QHBoxLayout" name="layout_warning">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_warn_icon">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>48</width>
|
||||||
|
<height>48</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>48</width>
|
||||||
|
<height>48</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="baseSize">
|
||||||
|
<size>
|
||||||
|
<width>64</width>
|
||||||
|
<height>64</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="pixmap">
|
||||||
|
<pixmap resource="../../data/icons.qrc">:/icons/48x48/dialog-warning.png</pixmap>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_warn_text">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="widget_macos" native="true">
|
<widget class="QWidget" name="widget_macos" native="true">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user