From 3fa176a3809080dd565b5276d01fcdd64d1e4c4a Mon Sep 17 00:00:00 2001 From: Skycoder42 Date: Sun, 14 May 2017 13:32:06 +0200 Subject: [PATCH] Added XSync call for hotkey without window For #3 --- HotkeyTest/main.cpp | 9 +++++++++ QHotkey/qhotkey_x11.cpp | 2 ++ 2 files changed, 11 insertions(+) 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:"