Skip to content

Commit

Permalink
feat: press escape to close preview window
Browse files Browse the repository at this point in the history
closes #229
  • Loading branch information
ejbills committed Aug 16, 2024
1 parent 39f44f0 commit 569a27b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion DockDoor/Utilities/KeybindHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class KeybindHelper {

private func handleEvent(proxy: CGEventTapProxy, type: CGEventType, event: CGEvent) -> Unmanaged<CGEvent>? {
let keyCode = event.getIntegerValueField(.keyboardEventKeycode)
let keyBoardShortcutSaved: UserKeyBind = Defaults[.UserKeybind] // UserDefaults.standard.getKeybind()!
let keyBoardShortcutSaved: UserKeyBind = Defaults[.UserKeybind]
let shiftKeyCurrentlyPressed = event.flags.contains(.maskShift)
var userDefinedKeyCurrentlyPressed = false

Expand All @@ -80,6 +80,11 @@ class KeybindHelper {
}

else if type == .keyDown {
if SharedPreviewWindowCoordinator.shared.isVisible && keyCode == 53 { // 53 is the keycode for Escape key
SharedPreviewWindowCoordinator.shared.hideWindow()
return nil // Suppress the Escape key event
}

if (isModifierKeyPressed && keyCode == keyBoardShortcutSaved.keyCode && modifierValue == keyBoardShortcutSaved.modifierFlags) || (Defaults[.defaultCMDTABKeybind] && event.flags.contains(.maskCommand) && keyCode == 48) { // Tab key
if SharedPreviewWindowCoordinator.shared.isVisible { // Check if HoverWindow is already shown
SharedPreviewWindowCoordinator.shared.cycleWindows(goBackwards: isShiftKeyPressed) // Cycle windows based on Shift key state
Expand Down

0 comments on commit 569a27b

Please sign in to comment.