aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--menubar/main.swift2
-rw-r--r--menubar/panel.swift14
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)
}