From 39bcce3786ac9f08f0ff80b7c51bd4b2e7a96106 Mon Sep 17 00:00:00 2001 From: Matteo Ceruti Date: Thu, 24 Aug 2023 00:12:03 +0200 Subject: Fix shortcuts on macOS: Must distinguish Key Pressed and Release. Otherise Shortcuts do not work --- qxt-mini/qxtglobalshortcut.cpp | 2 +- qxt-mini/qxtglobalshortcut_mac.cpp | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'qxt-mini') diff --git a/qxt-mini/qxtglobalshortcut.cpp b/qxt-mini/qxtglobalshortcut.cpp index 52758f71..dec11dc4 100644 --- a/qxt-mini/qxtglobalshortcut.cpp +++ b/qxt-mini/qxtglobalshortcut.cpp @@ -180,7 +180,7 @@ void QxtGlobalShortcutPrivate::activateShortcut(quint32 nativeKey, quint32 nativ shortcut->qxt_d().keystate = false; if (shortcut->isEnabled()) - emit shortcut->activated(true); + emit shortcut->activated(is_down); } #endif } diff --git a/qxt-mini/qxtglobalshortcut_mac.cpp b/qxt-mini/qxtglobalshortcut_mac.cpp index 59d0a40c..c91d763d 100644 --- a/qxt-mini/qxtglobalshortcut_mac.cpp +++ b/qxt-mini/qxtglobalshortcut_mac.cpp @@ -49,14 +49,13 @@ OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event, { Q_UNUSED(nextHandler); Q_UNUSED(data); - if (GetEventClass(event) == kEventClassKeyboard && GetEventKind(event) == kEventHotKeyPressed) + if (GetEventClass(event) == kEventClassKeyboard && (GetEventKind(event) == kEventHotKeyPressed || GetEventKind(event) == kEventHotKeyReleased)) { EventHotKeyID keyID; GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(keyID), NULL, &keyID); Identifier id = keyIDs.key(keyID.id); if(id != Identifier()) { - QxtGlobalShortcutPrivate::activateShortcut(id.second, id.first, true); - QxtGlobalShortcutPrivate::activateShortcut(id.second, id.first, false); + QxtGlobalShortcutPrivate::activateShortcut(id.second, id.first, GetEventKind(event) == kEventHotKeyPressed); } } return noErr; @@ -235,10 +234,12 @@ bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativ if (!qxt_mac_handler_installed) { qxt_mac_handler_installed = true; - EventTypeSpec t; - t.eventClass = kEventClassKeyboard; - t.eventKind = kEventHotKeyPressed; - InstallApplicationEventHandler(&qxt_mac_handle_hot_key, 1, &t, NULL, NULL); + EventTypeSpec t[2]; + t[0].eventClass = kEventClassKeyboard; + t[0].eventKind = kEventHotKeyPressed; + t[1].eventClass = kEventClassKeyboard; + t[1].eventKind = kEventHotKeyReleased; + InstallApplicationEventHandler(&qxt_mac_handle_hot_key, 2, t, NULL, NULL); } EventHotKeyID keyID; -- cgit v1.2.3