diff --git a/src/libs/ui/mainwindow.cpp b/src/libs/ui/mainwindow.cpp index c4791dd..eb8f9ee 100644 --- a/src/libs/ui/mainwindow.cpp +++ b/src/libs/ui/mainwindow.cpp @@ -67,13 +67,15 @@ MainWindow::MainWindow(Core::Application *app, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_application(app), - m_settings(app->settings()), - m_globalShortcut(new QxtGlobalShortcut(m_settings->showShortcut, this)) + m_settings(app->settings()) { ui->setupUi(this); - // initialise key grabber - connect(m_globalShortcut, &QxtGlobalShortcut::activated, this, &MainWindow::toggleWindow); + // Initialize the global shortcut handler if supported. + if (QxtGlobalShortcut::isSupported()) { + m_globalShortcut = new QxtGlobalShortcut(m_settings->showShortcut, this); + connect(m_globalShortcut, &QxtGlobalShortcut::activated, this, &MainWindow::toggleWindow); + } setupTabBar(); @@ -119,10 +121,16 @@ MainWindow::MainWindow(Core::Application *app, QWidget *parent) : } connect(ui->actionPreferences, &QAction::triggered, this, [this]() { - m_globalShortcut->setEnabled(false); + if (m_globalShortcut) { + m_globalShortcut->setEnabled(false); + } + QScopedPointer dialog(new SettingsDialog(this)); dialog->exec(); - m_globalShortcut->setEnabled(true); + + if (m_globalShortcut) { + m_globalShortcut->setEnabled(true); + } }); ui->actionBack->setShortcut(QKeySequence::Back); @@ -518,7 +526,9 @@ void MainWindow::keyPressEvent(QKeyEvent *keyEvent) void MainWindow::applySettings() { - m_globalShortcut->setShortcut(m_settings->showShortcut); + if (m_globalShortcut) { + m_globalShortcut->setShortcut(m_settings->showShortcut); + } if (m_settings->showSystrayIcon) createTrayIcon(); @@ -557,7 +567,7 @@ void MainWindow::applySettings() void MainWindow::toggleWindow() { - const bool checkActive = sender() == m_globalShortcut; + const bool checkActive = m_globalShortcut && sender() == m_globalShortcut; if (!isVisible() || (checkActive && !isActiveWindow())) { bringToFront(); diff --git a/src/libs/ui/qxtglobalshortcut/qxtglobalshortcut.cpp b/src/libs/ui/qxtglobalshortcut/qxtglobalshortcut.cpp index 14420e5..0eb753b 100644 --- a/src/libs/ui/qxtglobalshortcut/qxtglobalshortcut.cpp +++ b/src/libs/ui/qxtglobalshortcut/qxtglobalshortcut.cpp @@ -54,6 +54,7 @@ #include "qxtglobalshortcut_p.h" #include +#include #ifndef Q_OS_MACOS int QxtGlobalShortcutPrivate::ref = 0; @@ -235,6 +236,16 @@ bool QxtGlobalShortcut::isEnabled() const return d->enabled; } +/*! + * \brief QxtGlobalShortcut::isSupported checks if the current platform is supported. + */ +bool QxtGlobalShortcut::isSupported() +{ + return QGuiApplication::platformName() == QLatin1String("windows") + || QGuiApplication::platformName() == QLatin1String("xcb") + || QGuiApplication::platformName() == QLatin1String("cocoa"); +} + void QxtGlobalShortcut::setEnabled(bool enabled) { Q_D(QxtGlobalShortcut); diff --git a/src/libs/ui/qxtglobalshortcut/qxtglobalshortcut.h b/src/libs/ui/qxtglobalshortcut/qxtglobalshortcut.h index 05b52a0..a547017 100644 --- a/src/libs/ui/qxtglobalshortcut/qxtglobalshortcut.h +++ b/src/libs/ui/qxtglobalshortcut/qxtglobalshortcut.h @@ -77,6 +77,8 @@ public: bool isEnabled() const; + static bool isSupported(); + public slots: void setEnabled(bool enabled); diff --git a/src/libs/ui/settingsdialog.cpp b/src/libs/ui/settingsdialog.cpp index cd0b90e..0a28c11 100644 --- a/src/libs/ui/settingsdialog.cpp +++ b/src/libs/ui/settingsdialog.cpp @@ -24,6 +24,8 @@ #include "settingsdialog.h" #include "ui_settingsdialog.h" +#include + #include #include @@ -75,6 +77,9 @@ SettingsDialog::SettingsDialog(QWidget *parent) : setTabOrder(ui->defaultFontComboBox, ui->fontSizeComboBox); setTabOrder(ui->fontSizeComboBox, ui->serifFontComboBox); + // Disable global shortcut settings if not supported. + ui->globalHotKeyGroupBox->setEnabled(QxtGlobalShortcut::isSupported()); + QWebSettings *webSettings = QWebSettings::globalSettings(); // Avoid casting in each connect.