Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Loop/Core/Observers/KeybindTrigger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ final class KeybindTrigger {

// If this is a valid event, don't passthrough
let result = performKeybind(
keyCode: keyCode,
type: event.type,
isARepeat: event.getIntegerValueField(.keyboardEventAutorepeat) == 1,
flags: filteredFlags,
Expand Down Expand Up @@ -148,7 +149,7 @@ final class KeybindTrigger {
/// - flags: modifier flags associated with this event.
/// - isLoopOpen: whether Loop is currently open.
/// - Returns: whether this event was processed by Loop.
private func performKeybind(type: CGEventType, isARepeat: Bool, flags: CGEventFlags, isLoopOpen: Bool) -> PerformKeybindResult {
private func performKeybind(keyCode: CGKeyCode, type: CGEventType, isARepeat: Bool, flags: CGEventFlags, isLoopOpen: Bool) -> PerformKeybindResult {
let flagKeys = sideDependentTriggerKey ? flags.keyCodes : flags.keyCodes.baseModifiers
let allPressedKeys: Set<CGKeyCode> = pressedKeys.union(flagKeys)
let actionKeys: Set<CGKeyCode> = Set(allPressedKeys.subtracting(triggerKey).map(\.baseModifier))
Expand All @@ -172,7 +173,12 @@ final class KeybindTrigger {

if type != .keyUp { // keyDown for flagsChanged
if containsTrigger {
if let action = windowActionCache.actionsByKeybind[actionKeys] {
// Try an match directly with the action keys first, then fallback to just the key code.
// This prevents failures when the user is tapping the keys in rapid succession.
let initalMatch = windowActionCache.actionsByKeybind[actionKeys]
let fallbackMatch = windowActionCache.actionsByKeybind[[keyCode]]

if let action = initalMatch ?? fallbackMatch {
if !isARepeat || action.canRepeat {
openLoop(startingAction: action, overrideExistingTriggerDelayTimerAction: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftUI

/// Handles execution of `WindowAction`s on windows within the user's workspace
enum WindowEngine {
static var currentTask: Task<(), any Error>?
/// Resize a Window
/// - Parameters:
/// - window: Window to be resized
Expand All @@ -23,13 +24,16 @@ enum WindowEngine {
on screen: NSScreen,
completion: @escaping () -> () = {}
) {
Task.detached(priority: .userInitiated) {
currentTask?.cancel()
currentTask = Task.detached(priority: .userInitiated) {
await resize(
window,
to: action,
on: screen
)

try Task.checkCancellation()

completion()
}
}
Expand Down Expand Up @@ -222,10 +226,12 @@ enum WindowEngine {
try await window.setFrameAnimated(targetFrame, bounds: bounds)
} else {
window.setFrame(targetFrame, sizeFirst: willChangeScreens)
try Task.checkCancellation()
}

if !animate, !window.frame.approximatelyEqual(to: targetFrame) {
window.setFrame(targetFrame)
try Task.checkCancellation()
}

handleSizeConstrainedWindow(window: window, bounds: bounds)
Expand Down
1 change: 1 addition & 0 deletions Loop/Window Management/Window/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ final class Window {

try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<(), Error>) in
Task {
try Task.checkCancellation()
let animation = WindowTransformAnimation(
rect,
window: self,
Expand Down