Skip to content

Commit

Permalink
Fix shortcuts on macOS: Must distinguish Key Pressed and Release. Oth…
Browse files Browse the repository at this point in the history
…erise Shortcuts do not work
  • Loading branch information
Matteo Ceruti committed Aug 23, 2023
1 parent 10bcee2 commit 19dd03e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion qxt-mini/qxtglobalshortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 8 additions & 7 deletions qxt-mini/qxtglobalshortcut_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 19dd03e

Please sign in to comment.