aboutsummaryrefslogtreecommitdiff
path: root/menubar
diff options
context:
space:
mode:
authorIgor Soarez <igor@soarez.org>2026-10-20 15:01:18 +0300
committerIgor Soarez <igor@soarez.org>2026-10-20 15:01:18 +0300
commitaa4d6fcd9eac0d0fe051d6307ed6009adefbb2e1 (patch)
treec20523f3753f7c04b34f163135d1419094a9838f /menubar
parenteed9c9c1141e118e43b0055f935dd891d89bebd6 (diff)
fix clicks from the menu bar app: find tmux without homebrew on PATH
launchd starts the menu bar app with PATH=/usr/bin:/bin:/usr/sbin:/sbin, so the `dingger focus` it runs for every click (panel rows, menu rows, the jump shortcut) could not find homebrew's tmux and failed with a misleading "no tmux client attached"; the app discarded the error. dingger now finds tmux on PATH or in the usual install locations (DINGGER_TMUX overrides), reports a missing tmux as such, and the app logs failed jumps. also: panel rows own every click inside them (labels took the clicks and counted as window-drag background). e2e step 14 repeats the menu bar row click and dingger focus under launchd's environment; both fail with the previous binaries.
Diffstat (limited to 'menubar')
-rw-r--r--menubar/main.swift5
-rw-r--r--menubar/model.swift31
-rw-r--r--menubar/panel.swift10
3 files changed, 42 insertions, 4 deletions
diff --git a/menubar/main.swift b/menubar/main.swift
index e9294e8..c1891ab 100644
--- a/menubar/main.swift
+++ b/menubar/main.swift
@@ -136,8 +136,8 @@ final class Menubar: NSObject, NSApplicationDelegate, NSMenuDelegate {
/// The jump shortcut: same as clicking the tmux status line.
@objc private func jumpToTopWaiting() {
DispatchQueue.global().async {
- let output = run(dinggerBinary, ["focus"]) ?? "failed"
- log("jump: dingger focus \(output.isEmpty ? "ok" : output)")
+ let result = runReporting(dinggerBinary, ["focus"])
+ log("jump: dingger focus \(result.ok ? "ok" : "failed: \(result.output)")")
DispatchQueue.main.async { self.refresh() }
}
}
@@ -155,6 +155,7 @@ final class Menubar: NSObject, NSApplicationDelegate, NSMenuDelegate {
}
private func jump(to paneId: String) {
+ log("jump: to \(paneId)")
DispatchQueue.global().async {
focus(paneId)
DispatchQueue.main.async { self.refresh() }
diff --git a/menubar/model.swift b/menubar/model.swift
index e60cb84..67a693a 100644
--- a/menubar/model.swift
+++ b/menubar/model.swift
@@ -126,12 +126,38 @@ func run(_ path: String, _ args: [String]) -> String? {
return String(data: data, encoding: .utf8)
}
+/// Like run(), but reports why a command failed: exit status and stderr.
+func runReporting(_ path: String, _ args: [String]) -> (ok: Bool, output: String) {
+ let process = Process()
+ process.executableURL = URL(fileURLWithPath: path)
+ process.arguments = args
+ let out = Pipe(), err = Pipe()
+ process.standardOutput = out
+ process.standardError = err
+ do {
+ try process.run()
+ } catch {
+ return (false, "cannot run \(path): \(error.localizedDescription)")
+ }
+ let stdout = String(data: out.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? ""
+ let stderr = String(data: err.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? ""
+ process.waitUntilExit()
+ let text = (stdout + stderr).trimmingCharacters(in: .whitespacesAndNewlines)
+ return (process.terminationStatus == 0, text)
+}
+
+/// The tmux binary: launchd gives apps a PATH without Homebrew, so look in
+/// the usual places.
+let tmuxBinary: String = environment["DINGGER_TMUX"]
+ ?? ["/opt/homebrew/bin/tmux", "/usr/local/bin/tmux", "/usr/bin/tmux"]
+ .first { FileManager.default.isExecutableFile(atPath: $0) } ?? "/opt/homebrew/bin/tmux"
+
func tmux(_ args: [String]) -> String? {
var all = ["-u"]
if let socket = environment["DINGGER_TMUX_SOCKET"] {
all += ["-L", socket]
}
- return run(environment["DINGGER_TMUX"] ?? "/opt/homebrew/bin/tmux", all + args)
+ return run(tmuxBinary, all + args)
}
let dinggerBinary = environment["DINGGER_BIN"] ?? (NSHomeDirectory() + "/.local/bin/dingger")
@@ -162,7 +188,8 @@ func fetchRows() -> [Row] {
/// Show the pane and mark it attended; the same code path as the tmux
/// status-line click.
func focus(_ paneId: String) {
- _ = run(dinggerBinary, ["focus", "--pane", paneId])
+ let result = runReporting(dinggerBinary, ["focus", "--pane", paneId])
+ if !result.ok { log("jump: dingger focus --pane \(paneId) failed: \(result.output)") }
}
// MARK: rendering
diff --git a/menubar/panel.swift b/menubar/panel.swift
index 357ff91..e6ff569 100644
--- a/menubar/panel.swift
+++ b/menubar/panel.swift
@@ -151,6 +151,15 @@ private class ClickView: NSView {
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
+ // Own every click inside, including over labels: a text field would
+ // otherwise take the click (and count as a window-drag background).
+ override func hitTest(_ point: NSPoint) -> NSView? {
+ bounds.contains(convert(point, from: superview)) ? self : nil
+ }
+
+ // Dragging is done here (performDrag), not by the window server.
+ override var mouseDownCanMoveWindow: Bool { false }
+
override func updateTrackingAreas() {
super.updateTrackingAreas()
trackingAreas.forEach(removeTrackingArea)
@@ -170,6 +179,7 @@ private class ClickView: NSView {
}
override func mouseUp(with event: NSEvent) {
+ log("panel: mouse up (dragged: \(dragged))")
if !dragged { onClick() }
}
}