From a2378a3ed12e62ea34ad9475084ecb5a387386a5 Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Tue, 27 Oct 2026 12:15:03 +0200 Subject: panel: a click that moves a point or two is still a click any pointer movement between press and release started a panel drag and swallowed the click, so clicking a row often did nothing and had to be repeated: in a logged session, 12 of 17 clicks were taken as drags. the 5 that counted waited at most 4 ms and ran `dingger focus` in 60-120 ms. a drag now needs more than 4 points of movement (isDrag, selftest). --- menubar/main.swift | 2 ++ menubar/panel.swift | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/menubar/main.swift b/menubar/main.swift index c37386e..1b6ce4f 100644 --- a/menubar/main.swift +++ b/menubar/main.swift @@ -408,6 +408,8 @@ if arguments.contains("--selftest") { if importanceListed != importanceExpected { failures.append("order: status first, then importance, then time: \(importanceListed)") } + if isDrag(from: .zero, to: NSPoint(x: 2, y: 3)) { failures.append("click: a few points of jitter is a click") } + if !isDrag(from: .zero, to: NSPoint(x: 0, y: 5)) { failures.append("click: moving 5 points is a drag") } let high = Row(paneId: "%1", agent: "pi", name: "Fix it", status: .done, session: "s", window: "w", since: 1, importance: .high) if rowTitle(high).string != "✓ ! Fix it" || rowTitlePrefix(high) != "✓ ! " { failures.append("title: a high agent is marked: \(rowTitle(high).string)") diff --git a/menubar/panel.swift b/menubar/panel.swift index 8edab70..6619dc0 100644 --- a/menubar/panel.swift +++ b/menubar/panel.swift @@ -194,10 +194,17 @@ func darkHUD() -> NSVisualEffectView { return effect } +/// Whether the pointer moved far enough from where the button went down to +/// be a drag: a click on a trackpad or mouse moves it a point or two. +func isDrag(from down: NSPoint, to now: NSPoint) -> Bool { + hypot(now.x - down.x, now.y - down.y) > 4 +} + /// A click target that does not swallow drags: a drag moves the panel. class ClickView: NSView { var onClick: () -> Void = {} private var dragged = false + private var downAt = NSPoint.zero var hovered = false { didSet { needsDisplay = true; hoverChanged() } } func hoverChanged() {} @@ -222,10 +229,13 @@ class ClickView: NSView { override func mouseEntered(with event: NSEvent) { hovered = true } override func mouseExited(with event: NSEvent) { hovered = false } - override func mouseDown(with event: NSEvent) { dragged = false } + override func mouseDown(with event: NSEvent) { + dragged = false + downAt = NSEvent.mouseLocation + } override func mouseDragged(with event: NSEvent) { - if !dragged { + if !dragged, isDrag(from: downAt, to: NSEvent.mouseLocation) { dragged = true window?.performDrag(with: event) } -- cgit v1.2.3