diff --git a/src/core/utilities.cpp b/src/core/utilities.cpp index 2610a4040..8214fabe1 100644 --- a/src/core/utilities.cpp +++ b/src/core/utilities.cpp @@ -700,6 +700,10 @@ QString FiddleFileExtension(const QString &filename, const QString &new_extensio return PathWithoutFilenameExtension(filename) + "." + new_extension; } +QString GetEnv(const QString &key) { + return QString::fromLocal8Bit(qgetenv(key.toLocal8Bit())); +} + void SetEnv(const char *key, const QString &value) { #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 ScopedWCharArray::ScopedWCharArray(const QString &str) diff --git a/src/core/utilities.h b/src/core/utilities.h index 0094e027a..4e0bd3487 100644 --- a/src/core/utilities.h +++ b/src/core/utilities.h @@ -122,6 +122,7 @@ QUrl GetRelativePathToStrawberryBin(const QUrl &url); QString PathWithoutFilenameExtension(const QString &filename); QString FiddleFileExtension(const QString &filename, const QString &new_extension); +QString GetEnv(const QString &key); void SetEnv(const char *key, const QString &value); void IncreaseFDLimit(); void CheckPortable(); @@ -153,7 +154,9 @@ QString GetRandomStringWithChars(const int len); QString GetRandomStringWithCharsAndNumbers(const int len); QString GetRandomString(const int len, const QString &UseCharacters); -} +QString DesktopEnvironment(); + +} // namespace class ScopedWCharArray { public: diff --git a/src/globalshortcuts/globalshortcuts.cpp b/src/globalshortcuts/globalshortcuts.cpp index 9aacdb44c..001c4b1e5 100644 --- a/src/globalshortcuts/globalshortcuts.cpp +++ b/src/globalshortcuts/globalshortcuts.cpp @@ -52,7 +52,7 @@ GlobalShortcuts::GlobalShortcuts(QWidget *parent) : QWidget(parent), dbus_backend_(nullptr), system_backend_(nullptr), - use_dbus_(true), + use_gsd_(true), use_x11_(false) { @@ -97,7 +97,7 @@ GlobalShortcuts::GlobalShortcuts(QWidget *parent) 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. - use_dbus_ = settings_.value("use_dbus", true).toBool(); + use_gsd_ = settings_.value("use_gsd", true).toBool(); use_x11_ = settings_.value("use_x11", true).toBool(); Unregister(); @@ -152,7 +152,7 @@ bool GlobalShortcuts::IsX11Available() const { } 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 if (use_x11_) #endif diff --git a/src/globalshortcuts/globalshortcuts.h b/src/globalshortcuts/globalshortcuts.h index c9082c30c..104abc45d 100644 --- a/src/globalshortcuts/globalshortcuts.h +++ b/src/globalshortcuts/globalshortcuts.h @@ -97,7 +97,7 @@ class GlobalShortcuts : public QWidget { QMap shortcuts_; QSettings settings_; - bool use_dbus_; + bool use_gsd_; bool use_x11_; }; diff --git a/src/settings/shortcutssettingspage.cpp b/src/settings/shortcutssettingspage.cpp index b8acb4797..3d97e0bea 100644 --- a/src/settings/shortcutssettingspage.cpp +++ b/src/settings/shortcutssettingspage.cpp @@ -70,8 +70,8 @@ GlobalShortcutsSettingsPage::GlobalShortcutsSettingsPage(SettingsDialog *dialog) #if !defined(Q_OS_WIN) && !defined(Q_OS_MACOS) #ifdef HAVE_DBUS - connect(ui_->checkbox_dbus, SIGNAL(clicked(bool)), SLOT(DBusChanged(bool))); - connect(ui_->button_dbus_open, SIGNAL(clicked()), SLOT(OpenGnomeKeybindingProperties())); + connect(ui_->checkbox_gsd, SIGNAL(clicked(bool)), SLOT(GSDChanged(bool))); + connect(ui_->button_gsd_open, SIGNAL(clicked()), SLOT(OpenGnomeKeybindingProperties())); #endif #ifdef HAVE_X11 connect(ui_->checkbox_x11, SIGNAL(clicked(bool)), SLOT(X11Changed(bool))); @@ -102,15 +102,18 @@ void GlobalShortcutsSettingsPage::Load() { if (!initialised_) { initialised_ = true; + de_ = Utilities::DesktopEnvironment(); + ui_->widget_warning->hide(); + connect(ui_->button_macos_open, SIGNAL(clicked()), manager, SLOT(ShowMacAccessibilityDialog())); if (manager->IsGsdAvailable()) { - qLog(Debug) << "Gnome D-Bus backend is available."; - ui_->widget_dbus->show(); + qLog(Debug) << "Gnome (GSD) D-Bus backend is available."; + ui_->widget_gsd->show(); } else { - qLog(Debug) << "Gnome D-Bus backend is unavailable."; - ui_->widget_dbus->hide(); + qLog(Debug) << "Gnome (GSD) D-Bus backend is unavailable."; + ui_->widget_gsd->hide(); } if (manager->IsX11Available()) { @@ -140,9 +143,9 @@ void GlobalShortcutsSettingsPage::Load() { SetShortcut(s.s.id, s.s.action->shortcut()); } - bool use_dbus = settings_.value("use_dbus", true).toBool(); - if (ui_->widget_dbus->isVisibleTo(this)) { - ui_->checkbox_dbus->setChecked(use_dbus); + bool use_gsd = settings_.value("use_gsd", true).toBool(); + if (ui_->widget_gsd->isVisibleTo(this)) { + ui_->checkbox_gsd->setChecked(use_gsd); } 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) #ifdef HAVE_DBUS - DBusChanged(true); + GSDChanged(true); #endif #ifdef HAVE_X11 X11Changed(true); @@ -176,7 +179,7 @@ void GlobalShortcutsSettingsPage::Save() { 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()); dialog()->global_shortcuts_manager()->ReloadSettings(); @@ -192,31 +195,31 @@ void GlobalShortcutsSettingsPage::X11Changed(bool) { if (ui_->checkbox_x11->isChecked()) { ui_->list->setEnabled(true); ui_->shortcut_options->setEnabled(true); + X11Warning(); } else { ui_->list->setEnabled(false); ui_->shortcut_options->setEnabled(false); + ui_->widget_warning->hide(); } } #endif // HAVE_X11 #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()) { ui_->checkbox_x11->setEnabled(false); - ui_->list->setEnabled(false); - ui_->shortcut_options->setEnabled(false); } - if (ui_->checkbox_x11->isChecked()) { 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 { if (!ui_->checkbox_x11->isEnabled()) { @@ -224,6 +227,7 @@ void GlobalShortcutsSettingsPage::DBusChanged(bool) { if (ui_->checkbox_x11->isChecked()) { ui_->list->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(); + } + +} diff --git a/src/settings/shortcutssettingspage.h b/src/settings/shortcutssettingspage.h index 0bd84f598..07a95270c 100644 --- a/src/settings/shortcutssettingspage.h +++ b/src/settings/shortcutssettingspage.h @@ -62,7 +62,7 @@ class GlobalShortcutsSettingsPage : public SettingsPage { void X11Changed(bool); #endif #ifdef HAVE_DBUS - void DBusChanged(bool); + void GSDChanged(bool); void OpenGnomeKeybindingProperties(); #endif #endif @@ -81,6 +81,8 @@ class GlobalShortcutsSettingsPage : public SettingsPage { void SetShortcut(const QString &id, const QKeySequence &key); + void X11Warning(); + private: Ui_GlobalShortcutsSettingsPage *ui_; @@ -91,6 +93,8 @@ class GlobalShortcutsSettingsPage : public SettingsPage { QMap shortcuts_; QString current_id_; + QString de_; + }; #endif // GLOBALSHORTCUTSSETTINGSPAGE_H diff --git a/src/settings/shortcutssettingspage.ui b/src/settings/shortcutssettingspage.ui index b386b7bdc..014970772 100644 --- a/src/settings/shortcutssettingspage.ui +++ b/src/settings/shortcutssettingspage.ui @@ -19,7 +19,7 @@ - + 0 @@ -34,7 +34,7 @@ 0 - + 0 @@ -42,12 +42,12 @@ - Use Gnome D-Bus shortcut keys + Use Gnome (GSD) D-Bus shortcut keys - + Open... @@ -90,6 +90,62 @@ + + + + + + + + 0 + 0 + + + + + 48 + 48 + + + + + 48 + 48 + + + + + 64 + 64 + + + + + + + :/icons/48x48/dialog-warning.png + + + + + + + + 0 + 0 + + + + + + + true + + + + + +