diff --git a/mxd.swift b/mxd.swift index 6b34155..e79110f 100644 --- a/mxd.swift +++ b/mxd.swift @@ -56,7 +56,8 @@ struct Config { // CID_BACK: .shortcut(0x30, [.maskCommand, .maskShift]), // Cmd-Shift-Tab... (0x30 = Tab) // CID_BACK: .mouseButton(3), // let each app decide what "back" means ] - // Gesture button: false = act on press (instant). true = hold+swipe ←/→ Spaces, ↓ App Exposé, tap = its action. + // Gesture button: false = act on press (instant). true = hold+swipe: ↓ App Exposé fires at once while held; + // ←/→ Spaces and ↑ Mission Control fire on release; tap = its action. var gestureSwipes = true var gestureThreshold = 60 // raw sensor counts before a hold counts as a swipe @@ -366,7 +367,7 @@ final class Device { var inbox: [[UInt8]] = [] let buf = UnsafeMutablePointer.allocate(capacity: 64) var pressed: Set = [] - var gestureDown = false, gx = 0, gy = 0 + var gestureDown = false, gestureFired = false, gx = 0, gy = 0 var busy = false var diverted: [UInt16] = [] var divertsApplied = false // buttons currently match !frontmostIgnored @@ -544,13 +545,14 @@ func syncDiverts(_ d: Device) { // MARK: - Button events func buttonDown(_ d: Device, _ cid: UInt16) { - if cid == CID_GESTURE && config.gestureSwipes { d.gestureDown = true; d.gx = 0; d.gy = 0; return } + if cid == CID_GESTURE && config.gestureSwipes { d.gestureDown = true; d.gestureFired = false; d.gx = 0; d.gy = 0; return } if let a = config.buttons[cid] { perform(a) } } func buttonUp(_ d: Device, _ cid: UInt16) { guard cid == CID_GESTURE, config.gestureSwipes, d.gestureDown else { return } d.gestureDown = false + if d.gestureFired { return } let t = config.gestureThreshold if verbose { log("gesture dx=\(d.gx) dy=\(d.gy)") } if abs(d.gx) < t && abs(d.gy) < t { perform(config.buttons[CID_GESTURE] ?? .missionControl) } @@ -594,6 +596,8 @@ func handleReport(_ d: Device, _ r: [UInt8]) { guard d.gestureDown else { return } d.gx += Int(Int16(bitPattern: UInt16(r[4]) << 8 | UInt16(r[5]))) d.gy += Int(Int16(bitPattern: UInt16(r[6]) << 8 | UInt16(r[7]))) + // slide down past the threshold fires App Exposé now, once per hold; release then does nothing + if !d.gestureFired && d.gy >= config.gestureThreshold && d.gy > abs(d.gx) { d.gestureFired = true; perform(.appExpose) } default: break } }