Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

spaces macOS: 48px top bar, traffic lights centred on it (#5324)

Francesco Bonacci3511b253dd01
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIWindow.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIWindow.swift
index f8d2d7b4b5..fc35834705 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIWindow.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIWindow.swift
@@ -31,7 +31,7 @@ public final class WebUIWindowController: NSWindowController, NSWindowDelegate,
/// The traffic lights' width plus a gap, for `--titlebar-left-inset`.
static let fallbackLeftInset: CGFloat = 78
- static let titlebarHeight: CGFloat = 38
+ static let titlebarHeight: CGFloat = 48
/// Where the window's frame is saved (the defaults' `NSWindow Frame <name>`).
static let frameName = "CuaSpacesWebUI"
static let devServer = URL(string: "http://localhost:5174/")!
@@ -296,7 +296,23 @@ public final class WebUIWindowController: NSWindowController, NSWindowDelegate,
return max(Self.fallbackLeftInset, (right + 20).rounded())
}
+ /// Centres the traffic lights on the page's top bar (`titlebarHeight`):
+ /// a transparent title bar is shorter, so they would sit above the
+ /// search field's centre line. Nothing to do in full screen.
+ func centerTrafficLights() {
+ guard let window, !window.styleMask.contains(.fullScreen),
+ let close = window.standardWindowButton(.closeButton), let bar = close.superview,
+ let host = bar.superview else { return }
+ let height = Self.titlebarHeight
+ bar.frame = NSRect(x: bar.frame.minX, y: host.bounds.height - height, width: bar.frame.width, height: height)
+ for kind in [NSWindow.ButtonType.closeButton, .miniaturizeButton, .zoomButton] {
+ guard let button = window.standardWindowButton(kind) else { continue }
+ button.setFrameOrigin(NSPoint(x: button.frame.minX, y: ((height - button.frame.height) / 2).rounded()))
+ }
+ }
+
func applyInset() {
+ centerTrafficLights()
let inset = Int(leftInset)
webView.titlebarLeftInset = CGFloat(inset)
webView.evaluateJavaScript(
@@ -443,6 +459,7 @@ public final class WebUIWindowController: NSWindowController, NSWindowDelegate,
// MARK: - Window
+ public func windowDidResize(_ notification: Notification) { centerTrafficLights() }
public func windowDidEnterFullScreen(_ notification: Notification) { applyInset() }
public func windowDidExitFullScreen(_ notification: Notification) { applyInset() }
diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/BridgeContractTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/BridgeContractTests.swift
index e0a3ab19ba..95d7d5e485 100644
--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/BridgeContractTests.swift
+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/BridgeContractTests.swift
@@ -246,7 +246,7 @@ struct BridgeContractTests {
("keyvault.run", ["command": ["type": "revoke-grant", "id": "grant-1"]]),
("teleport.remembered", ["providerId": "chrome", "spaceId": space]),
("window.setBackgroundColor", ["color": "#16181c"]),
- ("window.setDragRegions", ["rects": [["x": 78, "y": 0, "width": 400, "height": 38]]]),
+ ("window.setDragRegions", ["rects": [["x": 78, "y": 0, "width": 400, "height": 48]]]),
("window.setDropTargets", ["targets": [["spaceId": space, "x": 20, "y": 60, "width": 232, "height": 180]]]),
("startup.get", [:]),
]