diff --git a/HotkeyTest/main.cpp b/HotkeyTest/main.cpp index 3640393..f95d6fd 100644 --- a/HotkeyTest/main.cpp +++ b/HotkeyTest/main.cpp @@ -1,11 +1,20 @@ #include "hottestwidget.h" #include +//#define START_BACKGROUND + int main(int argc, char *argv[]) { QApplication a(argc, argv); HotTestWidget w; + +#ifdef START_BACKGROUND + auto startKey = new QHotkey(QKeySequence(Qt::MetaModifier | Qt::ControlModifier | Qt::Key_S), true, &w); + QObject::connect(startKey, &QHotkey::activated, + &w, &QWidget::show); +#else w.show(); +#endif return a.exec(); } diff --git a/QHotkey/qhotkey_x11.cpp b/QHotkey/qhotkey_x11.cpp index 95062d2..f10e350 100644 --- a/QHotkey/qhotkey_x11.cpp +++ b/QHotkey/qhotkey_x11.cpp @@ -106,6 +106,7 @@ bool QHotkeyPrivateX11::registerShortcut(QHotkey::NativeShortcut shortcut) GrabModeAsync, GrabModeAsync); } + XSync(display, QueuedAlready); if(errorHandler.hasError) { qCWarning(logQHotkey) << "Failed to register hotkey. Error:" @@ -129,6 +130,7 @@ bool QHotkeyPrivateX11::unregisterShortcut(QHotkey::NativeShortcut shortcut) shortcut.modifier | specialMod, DefaultRootWindow(display)); } + XSync(display, QueuedAlready); if(errorHandler.hasError) { qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"