Fire App Exposé on slide down while held
Press the thumb button and slide down, and App Exposé fires as soon as the slide crosses the threshold, once per hold. The release then does nothing. Left, right, up and tap still act on release. Assisted-by: Claude Sonnet 5.5 Signed-off-by: Yigit BALABAN <balaban@yigid.dev>
This commit is contained in:
1 parent
1ba58f696c
commit
05444bb091
1 file changed
+7
-3
@@ -56,7 +56,8 @@ struct Config {
|
|||||||
// CID_BACK: .shortcut(0x30, [.maskCommand, .maskShift]), // Cmd-Shift-Tab... (0x30 = Tab)
|
// CID_BACK: .shortcut(0x30, [.maskCommand, .maskShift]), // Cmd-Shift-Tab... (0x30 = Tab)
|
||||||
// CID_BACK: .mouseButton(3), // let each app decide what "back" means
|
// 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 gestureSwipes = true
|
||||||
var gestureThreshold = 60 // raw sensor counts before a hold counts as a swipe
|
var gestureThreshold = 60 // raw sensor counts before a hold counts as a swipe
|
||||||
|
|
||||||
@@ -366,7 +367,7 @@ final class Device {
|
|||||||
var inbox: [[UInt8]] = []
|
var inbox: [[UInt8]] = []
|
||||||
let buf = UnsafeMutablePointer<UInt8>.allocate(capacity: 64)
|
let buf = UnsafeMutablePointer<UInt8>.allocate(capacity: 64)
|
||||||
var pressed: Set<UInt16> = []
|
var pressed: Set<UInt16> = []
|
||||||
var gestureDown = false, gx = 0, gy = 0
|
var gestureDown = false, gestureFired = false, gx = 0, gy = 0
|
||||||
var busy = false
|
var busy = false
|
||||||
var diverted: [UInt16] = []
|
var diverted: [UInt16] = []
|
||||||
var divertsApplied = false // buttons currently match !frontmostIgnored
|
var divertsApplied = false // buttons currently match !frontmostIgnored
|
||||||
@@ -544,13 +545,14 @@ func syncDiverts(_ d: Device) {
|
|||||||
// MARK: - Button events
|
// MARK: - Button events
|
||||||
|
|
||||||
func buttonDown(_ d: Device, _ cid: UInt16) {
|
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) }
|
if let a = config.buttons[cid] { perform(a) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func buttonUp(_ d: Device, _ cid: UInt16) {
|
func buttonUp(_ d: Device, _ cid: UInt16) {
|
||||||
guard cid == CID_GESTURE, config.gestureSwipes, d.gestureDown else { return }
|
guard cid == CID_GESTURE, config.gestureSwipes, d.gestureDown else { return }
|
||||||
d.gestureDown = false
|
d.gestureDown = false
|
||||||
|
if d.gestureFired { return }
|
||||||
let t = config.gestureThreshold
|
let t = config.gestureThreshold
|
||||||
if verbose { log("gesture dx=\(d.gx) dy=\(d.gy)") }
|
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) }
|
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 }
|
guard d.gestureDown else { return }
|
||||||
d.gx += Int(Int16(bitPattern: UInt16(r[4]) << 8 | UInt16(r[5])))
|
d.gx += Int(Int16(bitPattern: UInt16(r[4]) << 8 | UInt16(r[5])))
|
||||||
d.gy += Int(Int16(bitPattern: UInt16(r[6]) << 8 | UInt16(r[7])))
|
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
|
default: break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user