Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mac/Sources/Wind/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {

private func setUpPanel() {
panel.currentConfig = { [weak self] in self?.mag.config ?? Config() }
mag.panelEscape = { [weak self] in self?.panel.escapeFromTap() ?? false }
panel.save = { [weak self] c in self?.saveConfig { $0 = c } }
panel.macStatus = { [weak self] in self?.macStatusDict() ?? [:] }
panel.perf = { [weak self] in (self?.mag.level ?? 1, self?.mag.tickRing.samples ?? []) }
Expand Down
9 changes: 9 additions & 0 deletions mac/Sources/Wind/Magnifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ final class Magnifier {
private var lastButtonAt: CFTimeInterval = -1e9
private var lastKeyAt: CFTimeInterval = -1e9
private var keyAfterButton = false
/// Esc while the menu bar panel is open: returns true when the panel took it (closed). The panel
/// does not always get keys itself (macOS may refuse to activate Wind), so Wind's tap closes it.
var panelEscape: (() -> Bool)?
private var swallowEscUp = false
private var mouseDx = 0.0, mouseDy = 0.0 // movement since the last tick (for the owner)
private var lastMoveAt: CFTimeInterval = 0
private var pendingLockDx = 0.0, pendingLockDy = 0.0
Expand Down Expand Up @@ -319,6 +323,11 @@ final class Magnifier {
case .keyDown, .keyUp:
let code = UInt16(e.getIntegerValueField(.keyboardEventKeycode))
lastKeyAt = now
if code == 0x35 { // Esc: the menu bar panel's, when open
if type == .keyDown, mods.isEmpty, e.getIntegerValueField(.keyboardEventAutorepeat) == 0,
panelEscape?() == true { swallowEscUp = true; return nil }
if type == .keyUp, swallowEscUp { swallowEscUp = false; return nil }
}
if type == .keyDown {
if !mods.contains(.cmd) && !mods.contains(.ctrl) { keyAfterButton = true }
let (sw, ed) = router.triggerDown(.key(code), mods: mods,
Expand Down
62 changes: 52 additions & 10 deletions mac/Sources/Wind/MenuBarPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,40 @@ import WindCore
// order Settings > Menu bar sets (menu* keys, MenuLayout). The page is ui/panel.html (Svelte, the same
// wind://ui/ files and bridge as Settings) in a WKWebView inside a borderless panel. Built on the first
// open and then kept, hidden, so later opens show at once. Placement and the re-open guard are pure
// (WindCore/MenuPanel.swift). Lessons from Universal Clipboard's Mac panel (7ed027a, 3bb6252): activate
// the app on open or WebKit gets no mouse-moved events (no hover, no tooltips); no native shadow, the
// page draws it; close on focus loss, Esc, a second icon click, Settings and Quit. A close Wind itself
// caused (Esc, the icon, the page's close) hands activation back to the app that had it, so the text
// field Wind follows keeps its keystrokes.
// (WindCore/MenuPanel.swift). Opening asks macOS to activate Wind (the page then has the keyboard) and a close
// Wind caused hands activation back; macOS may refuse, so the panel is non-activating and key anyway, Wind's
// own pointer tracking (PanelPointerView) draws hover and tooltips, and Esc also reaches Wind's event tap.
// No native shadow, the page draws it; close on focus loss, Esc, a second icon click, Settings and Quit.
//
// Page -> host (webkit.messageHandlers.wind): panelSize {h}; getConfig; setConfig {key, value};
// setConfigs {values}; getMacStatus; panelAction {action: close | openSettings | quit | openPrivacy |
// fixZoomShortcuts | setEngine, value}; hover {id}.
// Host -> page (window.__windReceive): config {values, push}; macStatus {...}; perf {level, ms[]};
// panel {open}. First paint: window.__windInit {values, mac, perf}.

/// Tracks the pointer over the panel whether or not Wind is the active app, and hands its place to the
/// page (`window.__windPointer`), which draws hover and tooltips from it. WebKit sends hover and shows
/// `title` tooltips only while its window is key in the active app; a status item click does not always
/// leave Wind active, so the owner saw no hover on Settings/Quit and no tooltips (2026-11-23).
final class PanelPointerView: NSView {
var onPointer: ((CGPoint?) -> Void)?
private var area: NSTrackingArea?
override func updateTrackingAreas() {
super.updateTrackingAreas()
if let area { removeTrackingArea(area) }
let a = NSTrackingArea(rect: .zero, options: [.mouseMoved, .mouseEnteredAndExited, .activeAlways, .inVisibleRect],
owner: self, userInfo: nil)
addTrackingArea(a); area = a
}
private func report(_ e: NSEvent) {
let p = convert(e.locationInWindow, from: nil)
onPointer?(CGPoint(x: p.x, y: bounds.height - p.y)) // page coordinates: top-left origin
}
override func mouseMoved(with e: NSEvent) { report(e) }
override func mouseEntered(with e: NSEvent) { report(e) }
override func mouseExited(with e: NSEvent) { onPointer?(nil) }
}

/// Borderless, so it must say it can take key focus itself (the sliders want the arrow keys).
final class MenuPanelWindow: NSPanel {
var onEscape: (() -> Void)?
Expand Down Expand Up @@ -62,6 +84,7 @@ final class MenuBarPanelController: NSObject, WKScriptMessageHandler, WKNavigati
static let writeGap = 0.05
/// The control under the pointer (the page reports it), for the test state.
private(set) var hovered = ""

/// The app that was frontmost when the panel opened (nil when it was Wind), and whether Wind was active.
private var previousApp: NSRunningApplication?
private var wasActive = false
Expand All @@ -87,9 +110,10 @@ final class MenuBarPanelController: NSObject, WKScriptMessageHandler, WKNavigati
sendPerf()
send(["type": "panel", "open": true])
startPerf()
// An accessory app is not activated by a status item click; without this WebKit gets no
// mouse-moved events, so nothing on the page shows hover (Universal Clipboard 7ed027a). The
// activation policy stays .accessory: no Dock icon. close() gives activation back.
// Ask to activate Wind so the page gets the keyboard (Tab, arrows on a slider); close() gives it back.
// macOS may refuse (measured 2026-11-23: keys went on to the frontmost app), so nothing else depends
// on it: the panel is non-activating and key either way (clicks land at once), PanelPointerView draws
// hover and tooltips, and Esc reaches Wind's event tap (escapeFromTap).
wasActive = NSApp.isActive
let front = NSWorkspace.shared.frontmostApplication
previousApp = front?.processIdentifier == ProcessInfo.processInfo.processIdentifier ? nil : front
Expand Down Expand Up @@ -129,6 +153,15 @@ final class MenuBarPanelController: NSObject, WKScriptMessageHandler, WKNavigati
Log.verbose("menu bar panel: closed (\(why))")
}

/// Esc seen by Wind's event tap (main thread) while the panel is open: it closes the panel and the key is
/// swallowed. Not left to the page: whether keys reach it cannot be told from here (2026-11-23: Wind read
/// as active and frontmost while macOS sent the keys on to the app behind, so Esc did nothing).
func escapeFromTap() -> Bool {
guard isOpen else { return false }
close("esc")
return true
}

/// After a close Wind caused, the app that was frontmost before the panel opened gets activation back.
/// Not on focus loss (another app already took it), Settings (it comes forward) or Quit, and not when
/// Wind was active already (its Settings window was in front).
Expand Down Expand Up @@ -170,7 +203,7 @@ final class MenuBarPanelController: NSObject, WKScriptMessageHandler, WKNavigati
web.underPageBackgroundColor = .clear
web.navigationDelegate = self
web.autoresizingMask = [.width, .height]
let p = MenuPanelWindow(contentRect: rect, styleMask: [.borderless], backing: .buffered, defer: false)
let p = MenuPanelWindow(contentRect: rect, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
p.title = "Wind Menu Bar"
p.isFloatingPanel = true
p.level = .floating
Expand All @@ -182,7 +215,16 @@ final class MenuBarPanelController: NSObject, WKScriptMessageHandler, WKNavigati
p.becomesKeyOnlyIfNeeded = false
p.appearance = NSAppearance(named: .darkAqua)
p.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary, .transient, .ignoresCycle]
p.contentView = web
let host = PanelPointerView(frame: rect)
host.autoresizesSubviews = true
web.frame = host.bounds
host.addSubview(web)
host.onPointer = { [weak self] pt in
let arg = pt.map { String(format: "%.1f,%.1f", $0.x, $0.y) } ?? "-1,-1"
self?.web?.evaluateJavaScript("window.__windPointer && window.__windPointer(\(arg))")
}
p.acceptsMouseMovedEvents = true
p.contentView = host
p.delegate = self
p.onEscape = { [weak self] in self?.close("esc") }
panel = p; self.web = web
Expand Down
2 changes: 1 addition & 1 deletion mac/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.0
0.9.1
20 changes: 14 additions & 6 deletions mac/docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -1249,14 +1249,22 @@ counterpart of Windows' tray flyout (`src/tray_app/flyout_*`), built without an
reaches the screen top, so the icon is what keeps the card out from under the revealed bar), clamped to the
screen's visible frame; the page reports its height (more while the
engine list hangs below the card) and the window is resized and placed again.
- **Focus and hover:** an accessory app is not activated by a status item click, and without activation WebKit
gets no mouse-moved events, so nothing shows hover (Universal Clipboard 7ed027a). Opening calls `NSApp.activate()`
and makes the panel key; the activation policy stays `.accessory`.
- **Focus and hover:** opening asks macOS to activate Wind (`NSApp.activate()`), so the page has the keyboard
(Tab, a slider's arrows); a close Wind caused (Esc, the icon, the page's close, the icon hidden) hands
activation back to the app that was frontmost (`giveBackFocus`), so the text field Wind follows keeps its
keystrokes. macOS refuses that activation now and then (2026-11-23, e2e_menubar: active false, key false; Esc
and the first slider drag went elsewhere, no hover on Settings/Quit and no tooltips for the owner), so nothing
else depends on it:
- the panel is a non-activating `NSPanel` (`.nonactivatingPanel`), key either way, so clicks land at once;
- WebKit draws hover and shows `title` tooltips only while its app is active, so `PanelPointerView` tracks the
pointer with an `.activeAlways` tracking area and calls `window.__windPointer(x, y)`; the page sets a `hov`
class (rules marked `:global`, or Svelte strips them) and draws its own tooltips from `data-tip` after 500 ms;
- keys may still go on to the app behind (Wind can read as active and frontmost meanwhile), so Esc is taken
by Wind's event tap while the panel is open (`Magnifier.panelEscape`, `escapeFromTap`): it closes the panel,
engine list and all, and is swallowed.
- **Closing:** focus loss (`windowDidResignKey`), Esc, a second icon click, Settings, Quit. A click on the icon
within 300 ms of a close is the click that closed it and does not reopen (`MenuPanel.ignoreClick`, Windows'
kReopenGuardMs). A close Wind caused (Esc, the icon, the page's close, the icon hidden) gives activation back
to the app that was frontmost when the panel opened (`giveBackFocus`), so the text field Wind follows keeps its
keystrokes; not on focus loss, Settings or Quit, nor when Wind was active already.
kReopenGuardMs). Not on focus loss, Settings or Quit, nor when Wind was active already, is activation handed back.
- **Writes:** the page posts `setConfig` (sliders, already throttled to one per 50 ms with a flush on release by
the shared Slider), `setConfigs` (a toggle, both alignment keys at once) and `panelAction setEngine`. The host
types each with `SettingsWindowController.setting` and coalesces them: at most one `saveConfig` per 50 ms,
Expand Down
20 changes: 18 additions & 2 deletions mac/scripts/e2e_menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""The menu bar panel ON SCREEN in the test build, with REAL input (tools/vmouse, Karabiner, sudo).
Opens the panel through the command channel (`panel open`), then checks: the card sits under the menu
bar icon (its right edge under the icon's right edge, its top 3 pt under the menu bar) and inside the
screen's visible frame; Wind is active and the panel is key (or WebKit gets no hover); the real pointer
screen's visible frame; the panel is key (activated or not); the real pointer
over a toggle segment changes its background and the page reports the hovered control; a real slider drag
and a real toggle click write config.json; Esc closes it; a real click outside closes it; a real click
on the icon opens it and a second one closes it; a real right-click on the icon opens the native menu
Expand Down Expand Up @@ -93,7 +93,8 @@ def esc(): vmc("type ^"); time.sleep(0.4)
f"card {card} visible {vis} icon {icon}")
check("it is inside the visible frame", card[0] >= vis[0] - 0.5 and card[0] + card[2] <= vis[0] + vis[2] + 0.5
and card[1] + card[3] <= vis[1] + vis[3] + 0.5, f"card {card} visible {vis}")
check("Wind is active and the panel is key (hover needs it)", p["active"] and p["key"], f"active {p['active']} key {p['key']}")
# Key whether or not macOS let Wind activate (the panel is non-activating; 2026-11-23).
check("the panel is key", p["key"], f"active {p['active']} key {p['key']}")
loaded = until(lambda: js("return !!document.querySelector('.card .bar')"))
check("the page loaded", bool(loaded))
inner = js("const r = document.querySelector('.card').getBoundingClientRect(); return [r.x, r.y]")
Expand Down Expand Up @@ -133,6 +134,21 @@ def at(rect, fx=0.5): warp(ox + rect[0] + rect[2] * fx, oy + rect[1] + rect[3] /
warp(icon[0] + icon[2] / 2, icon[1] + icon[3] / 2); click()
check("a click on the icon opens the panel", until(lambda: panel()["open"]))
time.sleep(0.5)
# Owner 2026-11-23: opened from the icon, Settings and Quit showed no hover and nothing said what the
# icons were. Hover and tooltips come from Wind's own pointer tracking, so they work active or not.
p = panel(); card = p["card"]
inner = js("const r = document.querySelector('.card').getBoundingClientRect(); return [r.x, r.y]")
ox, oy = card[0] - inner[0], card[1] - inner[1]
for sel, text in (('.ib[data-id="settings"]', "Settings"), ('.ib[data-id="quit"]', "Quit Wind")):
at(js(RECT % sel)); vmc("move 1 0 2 16"); time.sleep(0.3)
hov = until(lambda: js(f"return document.querySelector('{sel}').classList.contains('hov')"))
bgc = js(f"return getComputedStyle(document.querySelector('{sel}')).backgroundColor")
check(f"{text}: hover from a real pointer after an icon click", bool(hov) and bgc != "rgba(0, 0, 0, 0)",
f"hov {hov} background {bgc}")
tip = until(lambda: js("const t = document.querySelector('[role=tooltip]'); return t && t.textContent"), timeout=2)
check(f"{text}: its tooltip names it", tip == text, f"tooltip {tip!r}")
warp(icon[0] + icon[2] / 2, icon[1] + icon[3] / 2)
time.sleep(0.3)
warp(icon[0] + icon[2] / 2, icon[1] + icon[3] / 2); click()
check("a second click on the icon closes it", until(lambda: not panel()["open"]))
time.sleep(0.5)
Expand Down
Loading
Loading