Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Fix tab bar double-click restoring maximized window

Dee42820d0c1e79
diff --git a/desktop/macos/Runner/SwarmTitlebar.swift b/desktop/macos/Runner/SwarmTitlebar.swift
index 300603350..dac3fba06 100644
--- a/desktop/macos/Runner/SwarmTitlebar.swift
+++ b/desktop/macos/Runner/SwarmTitlebar.swift
@@ -1369,7 +1369,8 @@ private final class SwarmTabStrip: NSView {
private var commandHeld = false
private var flagsMonitor: Any?
private var resignObserver: NSObjectProtocol?
- override var mouseDownCanMoveWindow: Bool { true }
+ // Dragging is explicit below. AppKit must not also start a titlebar gesture.
+ override var mouseDownCanMoveWindow: Bool { false }
override init(frame: NSRect) {
super.init(frame: frame)
@@ -1575,13 +1576,12 @@ private final class SwarmTabStrip: NSView {
}
override func mouseDown(with event: NSEvent) {
- // A double-click on the strip's background zooms the window. This is the
- // one place that does: the Flutter bar under the strip only drags, since
- // its own double-tap zoomed a second time, straight back (owner,
- // 2026-09-15: "maximizes out and resizes back").
if ownsBackgroundDoubleClick(event) { window?.performZoom(nil) }
else if event.clickCount == 1 { window?.performDrag(with: event) }
}
+ // Own the release as well as the press. Forwarding it lets AppKit zoom a
+ // second time on mouse-up, immediately restoring the previous window size.
+ override func mouseUp(with event: NSEvent) {}
fileprivate func ownsBackgroundDoubleClick(_ event: NSEvent) -> Bool {
if event.clickCount == 1 {
lastBackgroundClick = (event.timestamp, event.locationInWindow)
diff --git a/desktop/tool/check_swarm_titlebar.sh b/desktop/tool/check_swarm_titlebar.sh
index 2e202b4c4..1c7e71c3a 100644
--- a/desktop/tool/check_swarm_titlebar.sh
+++ b/desktop/tool/check_swarm_titlebar.sh
@@ -16,13 +16,17 @@ if [[ ! -d "$framework_dir/FlutterMacOS.framework/Modules" ]]; then
fi
check_dir="$(mktemp -d "${TMPDIR:-/tmp}/harness-v2-titlebar.XXXXXX")"
trap 'rm -rf "$check_dir"' EXIT
+check_source="$desktop_dir/tool/swarm_titlebar_checks.swift"
+if [[ "${2:-}" == "--window-zoom" ]]; then
+ check_source="$desktop_dir/tool/window_zoom_checks.swift"
+fi
cat "$desktop_dir/macos/Runner/HarnessKeymap.swift" \
"$desktop_dir/macos/Runner/SwarmTitlebar.swift" \
- "$desktop_dir/tool/swarm_titlebar_checks.swift" > "$check_dir/main.swift"
+ "$check_source" > "$check_dir/main.swift"
xcrun swiftc -swift-version 5 -module-cache-path "$check_dir/module-cache" \
-F "$framework_dir" -framework FlutterMacOS \
-Xlinker -rpath -Xlinker "$framework_dir" \
"$check_dir/main.swift" -o "$check_dir/check-titlebar"
-# Optional native-container checks create a hidden NSWindow. They never show
+# Optional --window-layout / --window-zoom checks create a hidden NSWindow. They never show
# the window, boot Flutter, connect to agents or read saved app data.
HARNESS_TITLEBAR_ASSETS="$desktop_dir/assets" "$check_dir/check-titlebar" "${2:-}"
diff --git a/desktop/tool/window_zoom_checks.swift b/desktop/tool/window_zoom_checks.swift
new file mode 100644
index 000000000..bf6b6fc94
--- /dev/null
+++ b/desktop/tool/window_zoom_checks.swift
@@ -0,0 +1,141 @@
+// Appended to the production AppKit source by check_swarm_titlebar.sh --window-zoom.
+// No Flutter engine, saved app state or visible windows are needed.
+private struct WindowZoomCheckFailure: Error {
+ let message: String
+}
+
+private var windowZoomCheckCount = 0
+private func checkWindowZoom(_ condition: @autoclosure () -> Bool, _ message: String) throws {
+ guard condition() else { throw WindowZoomCheckFailure(message: message) }
+ windowZoomCheckCount += 1
+}
+
+private final class WindowZoomMouseUpProbe: NSResponder {
+ var mouseUps = 0
+ override func mouseUp(with event: NSEvent) { mouseUps += 1 }
+}
+
+private final class WindowZoomCheckWindow: NSWindow {
+ var zoomCount = 0
+ var dragCount = 0
+ override func zoom(_ sender: Any?) {
+ zoomCount += 1
+ super.zoom(sender)
+ }
+ // A synthetic mouse-down has no real tracking loop to hand off to.
+ override func performDrag(with event: NSEvent) { dragCount += 1 }
+}
+
+private final class WindowZoomCheckMessenger: NSObject, FlutterBinaryMessenger {
+ func send(onChannel channel: String, message: Data?) {}
+ func send(onChannel channel: String, message: Data?, binaryReply callback: FlutterBinaryReply?) {
+ callback?(FlutterStandardMethodCodec.sharedInstance().encodeSuccessEnvelope(nil))
+ }
+ func setMessageHandlerOnChannel(_ channel: String,
+ binaryMessageHandler handler: FlutterBinaryMessageHandler?) -> FlutterBinaryMessengerConnection { 1 }
+ func cleanUpConnection(_ connection: FlutterBinaryMessengerConnection) {}
+}
+
+private func windowZoomMouseEvent(_ type: NSEvent.EventType, count: Int,
+ point: NSPoint, time: TimeInterval, window: NSWindow? = nil) -> NSEvent {
+ NSEvent.mouseEvent(with: type, location: point, modifierFlags: [], timestamp: time,
+ windowNumber: window?.windowNumber ?? 0, context: nil,
+ eventNumber: count, clickCount: count, pressure: 1)!
+}
+
+private extension SwarmTabStrip {
+ func checkReleaseIsolation() throws {
+ let parent = nextResponder
+ let probe = WindowZoomMouseUpProbe()
+ nextResponder = probe
+ defer { nextResponder = parent }
+ // Exercise both halves of each click. Checking only the double-click
+ // predicate misses mouse-up bubbling into AppKit's own titlebar zoom.
+ for count in 1...3 {
+ for type: NSEvent.EventType in [.leftMouseDown, .leftMouseUp] {
+ let event = windowZoomMouseEvent(type, count: count, point: NSPoint(x: 40, y: 20),
+ time: Double(count) * NSEvent.doubleClickInterval / 4)
+ if type == .leftMouseDown { mouseDown(with: event) }
+ else { mouseUp(with: event) }
+ }
+ try checkWindowZoom(probe.mouseUps == 0,
+ "Background click \(count) cannot also reach AppKit's titlebar zoom handler")
+ }
+ try checkWindowZoom(!mouseDownCanMoveWindow,
+ "Explicit background drag and zoom handling opts out of automatic window movement")
+ }
+
+ func checkTabDoubleClick(_ window: WindowZoomCheckWindow) throws {
+ update(["enabled": true, "activeId": "test", "tabs": [["id": "test", "name": "Test tab"]]])
+ var actions: [String] = []
+ emit = { method, _ in actions.append(method) }
+ let tab = tabs[0]
+ let point = tab.convert(NSPoint(x: tab.bounds.midX, y: tab.bounds.midY), to: nil)
+ let zoomCount = window.zoomCount
+ for count in 1...2 {
+ tab.mouseDown(with: windowZoomMouseEvent(.leftMouseDown, count: count, point: point,
+ time: Double(count) * NSEvent.doubleClickInterval / 4, window: window))
+ tab.mouseUp(with: windowZoomMouseEvent(.leftMouseUp, count: count, point: point,
+ time: Double(count) * NSEvent.doubleClickInterval / 4, window: window))
+ }
+ try checkWindowZoom(actions == ["select", "rename"], "A tab double-click still selects and renames")
+ try checkWindowZoom(window.zoomCount == zoomCount, "A tab double-click does not resize the window")
+ }
+
+ func checkWindowGestures(_ window: WindowZoomCheckWindow) throws {
+ let restoredFrame = window.frame
+ for sequence in 0..<2 {
+ let point = convert(NSPoint(x: createButton.frame.minX - 12, y: bounds.midY), to: nil)
+ for count in 1...2 {
+ let time = Double(sequence + 1) + Double(count) * NSEvent.doubleClickInterval / 4
+ mouseDown(with: windowZoomMouseEvent(.leftMouseDown, count: count, point: point,
+ time: time, window: window))
+ mouseUp(with: windowZoomMouseEvent(.leftMouseUp, count: count, point: point,
+ time: time, window: window))
+ }
+ // Include delayed titlebar layout/resize callbacks, not just mouseDown.
+ RunLoop.current.run(until: Date(timeIntervalSinceNow: 0.35))
+ try checkWindowZoom(window.zoomCount == sequence + 1,
+ "Each complete background double-click zooms the native window exactly once")
+ try checkWindowZoom(window.dragCount == sequence + 1,
+ "The first background click still hands window dragging to AppKit")
+ try checkWindowZoom(window.isZoomed == (sequence == 0),
+ "The native window stays maximized until the next deliberate double-click")
+ }
+ try checkWindowZoom(window.frame == restoredFrame,
+ "The next background double-click restores the original window frame")
+ try checkTabDoubleClick(window)
+ try checkWindowZoom(!window.isVisible, "Window gesture checks never display the test window")
+ }
+}
+
+private extension SwarmTitlebar {
+ func checkWindowGestures(_ window: WindowZoomCheckWindow) throws {
+ configure()
+ window.contentView?.superview?.layoutSubtreeIfNeeded()
+ resize()
+ window.contentView?.superview?.layoutSubtreeIfNeeded()
+ strip.layoutSubtreeIfNeeded()
+ try strip.checkWindowGestures(window)
+ }
+}
+
+let windowZoomCheckApp = NSApplication.shared
+windowZoomCheckApp.setActivationPolicy(.prohibited)
+do {
+ try checkWindowZoom(NSEvent.doubleClickInterval > 0,
+ "AppKit must be able to read the system double-click interval")
+ let strip = SwarmTabStrip(frame: NSRect(x: 0, y: 0, width: 900, height: 52))
+ try strip.checkReleaseIsolation()
+ let window = WindowZoomCheckWindow(contentRect: NSRect(x: 120, y: 120, width: 960, height: 640),
+ styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: false)
+ window.isReleasedWhenClosed = false
+ defer { window.close() }
+ let titlebar = SwarmTitlebar(window: window, messenger: WindowZoomCheckMessenger())
+ try titlebar.checkWindowGestures(window)
+ print("AppKit window zoom: \(windowZoomCheckCount) checks passed; no windows displayed.")
+} catch {
+ let message = (error as? WindowZoomCheckFailure)?.message ?? String(describing: error)
+ FileHandle.standardError.write(Data("AppKit window zoom failed: \(message)\n".utf8))
+ exit(1)
+}