Skip to content

Commit 487b96d

Browse files
committed
refactor: prepare future off-main-thread keyboard handling
1 parent 83b5319 commit 487b96d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/logic/events/KeyboardEvents.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ fileprivate let cgEventFlagsChangedHandler: CGEventTapCallBack = {_, type, cgEve
123123
if type == .flagsChanged {
124124
DispatchQueue.main.async {
125125
let modifiers = NSEvent.ModifierFlags(rawValue: UInt(cgEvent.flags.rawValue))
126+
// TODO: ideally, we want to absorb all modifier keys except holdShortcut
127+
// it was pressed down before AltTab was triggered, so we should let the up event through
126128
handleKeyboardEvent(nil, nil, nil, modifiers, false)
127129
}
128130
} else if (type == .tapDisabledByUserInput || type == .tapDisabledByTimeout) {

src/logic/events/KeyboardEventsTestable.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ func handleKeyboardEvent(_ globalId: Int?, _ shortcutState: ShortcutState?, _ ke
2222
for shortcut in ControlsTab.shortcuts.values {
2323
if shortcut.matches(globalId, shortcutState, keyCode, modifiers) && shortcut.shouldTrigger() {
2424
shortcut.executeAction(isARepeat)
25-
someShortcutTriggered = true
25+
// we want to pass-through alt-up to the active app, since it saw alt-down previously
26+
if !shortcut.id.starts(with: "holdShortcut") {
27+
someShortcutTriggered = true
28+
}
2629
}
2730
shortcut.redundantSafetyMeasures()
2831
}
32+
// TODO if we manage to move all keyboard listening to the background thread, we'll have issues returning this boolean
33+
// this function uses many objects that are also used on the main-thread. It also executes the actions
34+
// we'll have to rework this whole approach. Today we rely on somewhat in-order events/actions
35+
// special attention should be given to App.app.appIsBeingUsed which is being set to true when executing the nextWindowShortcut action
2936
return someShortcutTriggered
3037
}

0 commit comments

Comments
 (0)