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/panel.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'menubar/panel.swift') 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