From 336b6f5780109501dd8c3d98ca336265af021808 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Tue, 14 Dec 2021 17:53:17 +0100 Subject: [PATCH] store the native mapping --- src/widgets/qxtglobalshortcut.cpp | 8 ++++---- src/widgets/qxtglobalshortcut_p.h | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/widgets/qxtglobalshortcut.cpp b/src/widgets/qxtglobalshortcut.cpp index cd618142..e96029e3 100644 --- a/src/widgets/qxtglobalshortcut.cpp +++ b/src/widgets/qxtglobalshortcut.cpp @@ -77,8 +77,8 @@ bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut) Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier | Qt::KeypadModifier; key = shortcut.isEmpty() ? Qt::Key(0) : Qt::Key((shortcut[0] ^ allMods) & shortcut[0]); mods = shortcut.isEmpty() ? Qt::KeyboardModifiers(0) : Qt::KeyboardModifiers(shortcut[0] & allMods); - const quint32 nativeKey = nativeKeycode(key, mods); - const quint32 nativeMods = nativeModifiers(mods); + nativeKey = nativeKeycode(key, mods); + nativeMods = nativeModifiers(mods); const bool res = registerShortcut(nativeKey, nativeMods); if (res) shortcuts.insert(qMakePair(nativeKey, nativeMods), &qxt_p()); @@ -90,8 +90,6 @@ bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut) bool QxtGlobalShortcutPrivate::unsetShortcut() { bool res = false; - const quint32 nativeKey = nativeKeycode(key, mods); - const quint32 nativeMods = nativeModifiers(mods); if (shortcuts.value(qMakePair(nativeKey, nativeMods)) == &qxt_p()) res = unregisterShortcut(nativeKey, nativeMods); if (res) @@ -100,6 +98,8 @@ bool QxtGlobalShortcutPrivate::unsetShortcut() qWarning() << "QxtGlobalShortcut failed to unregister:" << QKeySequence(key + mods).toString(); key = Qt::Key(0); mods = Qt::KeyboardModifiers(0); + nativeKey = 0; + nativeMods = 0; return res; } diff --git a/src/widgets/qxtglobalshortcut_p.h b/src/widgets/qxtglobalshortcut_p.h index 9e852794..4d1149c3 100644 --- a/src/widgets/qxtglobalshortcut_p.h +++ b/src/widgets/qxtglobalshortcut_p.h @@ -55,6 +55,9 @@ public: Qt::Key key; Qt::KeyboardModifiers mods; + quint32 nativeKey = 0; + quint32 nativeMods = 0; + bool setShortcut(const QKeySequence& shortcut); bool unsetShortcut();