Skip to content

Commit a65951f

Browse files
todor-adevswha
andauthored
feat(app): let Ovis for Mac's header take the place of the window's title bar (#2642)
Feature request: #2641 ## Change While Ovis for Mac's main window shows Ovis, it folds its title bar away and the page's header takes its place, as in the Codex and Claude apps. - **Window** (`TitleBar.swift`): full-size content, a transparent bar with no title, and an empty `.unifiedCompact` toolbar. AppKit then gives the bar its height (40 pt on macOS 27) and centres the traffic lights on it itself, so nothing has to move them again on a resize or a title change. The setup, which takes the page's place when the server is gone, gets the window's bar back; a window the page opens (`showWindow`) never folds. In full screen the toolbar goes, so the bar hides with the menu bar. The View menu has no toolbar items (Reload takes the toolbar group's place), so the toolbar can't be hidden from under the header. Only the page that folded a window's bar gives it back, so the page that leaves when the server moves can't unfold the bar under the next one. - **Page** (`Resources/title-bar.js`, run like `carry-drafts.js`): as each main-window page commits, the app hands it the bar's height and the lights' right edge (`data-mac-title-bar`, `--mac-title-bar-h`, `--mac-title-bar-inset`). It also marks the lights' corner as an iPad window's (`data-window-controls`, `--window-controls-w`), so the header, the inbox's top bar and its rail keep clear of the lights by the rules they already have. `styles.css` gives the wide header the bar's height; the narrow one keeps its own, which its 44px buttons need. It is evaluated per page rather than a user script, because a window the page opens shares the main page's user scripts. - **Moving the window**: WebKit has no `app-region: drag`. A press on a top bar's bare surface (`.app-header`, the inbox's `.inbox-top` and `.thread-top`, the bars an installed desktop app drags by), or anywhere off a control within the bar's height of the window's top (the access and crash screens), arms a drag. Controls are buttons, links, fields, menus, groups and anything in the tab order; a container focused only by script (`tabindex=-1`, as `.app` is) is not one. The page's ask carries where it saw the press, and `OvisWebView` arms only the press at that point, so a late ask can't move the window from a later press elsewhere. It starts `performDrag` only on the first `mouseDragged`, then hands WebKit the mouse-up the drag took. A plain click or double click there stays the page's, and a double click does what System Settings › Desktop & Dock says of a title bar. - `WebPage` ignores the top safe area so the web view reaches the window's top. - **Clicks under the bar** (second commit): AppKit decides which views under the bar take its clicks as the bar turns transparent, and finds the page. But each time the window comes on screen (its first showing at a restored frame, after Hide, out of the Dock) it asks only SwiftUI's hosting view, which takes none, and the empty toolbar's `NSToolbarView` then took every click on the header. Whenever the window becomes visible (`didChangeOcclusionState`), `TitleBar.refresh` turns the bar transparent again, so AppKit looks again. ![Ovis for Mac: the header in the title bar's place, traffic lights at its left](https://github.com/todor-a/herdr-web-ui/blob/pr-assets/mac-header-in-title-bar.png?raw=true) The demo built from this branch (`bun scripts/demo-build.ts`), in a harness app built from `app/mac/Sources` with the real `WebPage`. The window is not the active one, hence the grey traffic lights. ## Validation macOS 27.2, Swift 6.4.2, Bun 1.4.2: - `swift build`, `swift test` in `app/mac`: pass (14 tests). - `bun test scripts/mac-title-bar.test.ts` (`title-bar.js` against fakes, as the carry test does): 8 pass; 6 of them fail on the script before the review fixes. `scripts/mac-carry-drafts.test.ts`, `src/conventions.test.ts`, `server/conventions.test.ts`, the theme and settings tests that read `styles.css`, `scripts/changelog-fold.test.ts`, `server/release-notes.test.ts`: pass. `scripts/conventions.test.ts` fails only its ratchet-base test, the same way on the merge of `main` without these changes (its base is the fork's stale `main`). `bun run typecheck`, `bun run build`: pass; `generate:themes` and `generate:types` leave no change. - A harness app built from `app/mac/Sources` (its own bundle id) with the real `WebPage`, `TitleBar` and `OvisCommands` in a SwiftUI `Window` scene, on the demo built from this branch, probed from inside (macOS 27.2, bar 38 pt, lights' right edge 66 pt): - wide header 38 px with its first button at x 74; narrow window (700 px) header 52 px with 44 px buttons inside it, padded to 78 px; inbox mode: no `.app-header`, the rail's first button at y 50, the inbox top's first control at x 94; - a press on the header's bare surface, the inbox top and the thread top arms the drag; a press on the pane does not; with only a centred-card screen (`.access-gate-screen`) on the page, a press at y 20 arms it and one at y 60 does not; - a header press, its mouse-up and a pane press sent at once: the header's ask arrives during the pane press and does not arm it (the code before this change armed any press under way); - Cmd+R still reaches Reload through the main menu; - an origin change (`127.0.0.1` to `localhost` and back, a new `WebPage` each time) leaves the bar folded; the setup in the page's place gets the bar back (28 pt, no toolbar), and the page back folds it again. - at 2d4adb3, a page that joins a window already in full screen (the setup there first, then the page; and a page from the other origin): no toolbar while in full screen; on leaving it the toolbar is back, bar 38 pt, lights 66 pt, the header 38 px with its first button at x 74. - By hand, with a real mouse, on the same harness (@todor-a): the window drags by the header's empty space and by the inbox's top bar; header buttons click and a text selection does not move the window; the View menu has no Show/Hide Toolbar or Customize Toolbar and keeps Reload; full screen hides the bar with the menu bar and the header lines up again after; below 769 px the header's buttons fit. - The original window setup and CSS have run as my own WKWebView wrapper's daily window since 2026-11-03. Skipped: `bun run check fast` as a whole (on this Mac `main` already fails unit tests that assume Linux, such as GNU tar's `--transform`). https://claude.ai/code/session_01Qe4NFe6YNuifjKD8sVKzrh --------- Co-authored-by: devswha <[email protected]>
1 parent e26581f commit a65951f

13 files changed

Lines changed: 496 additions & 6 deletions

File tree

‎app/mac/README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ The window is a WKWebView on the server's own address (`http://127.0.0.1:<port>`
1414
`scripts/plugin.ts status`). The server lets a loopback request in without pairing, and the page's
1515
cookies and drafts stay in the app's own WebKit store, apart from any browser's.
1616

17+
- While it shows Ovis the window draws no title bar: the page's header takes its place, as in the
18+
Codex and Claude apps, at the height of a compact toolbar's bar, which centres the traffic lights on
19+
it (`Sources/OvisMac/TitleBar.swift`, `Resources/title-bar.js`), and every screen keeps clear of the
20+
lights as an iPad window's does. A drag on a top bar's bare surface (the header, the inbox's), or
21+
anywhere off a control within the bar's height of the window's top, moves the window, and a double
22+
click there does what System Settings › Desktop & Dock says of a title bar. The View menu has no
23+
toolbar items. The setup, and a window the page opens, keep a title bar of their own; in full
24+
screen the bar hides with the menu bar.
1725
- **Ovis → Phone Setup…** opens the setup and the phone's QR code in a window of their own. After
1826
an Install from the app it opens by itself. **File → Open in Browser** opens the page as it is in
1927
the default browser, and **View → Reload** (Cmd+R) loads it again. No menu item takes a Cmd+Shift

‎app/mac/Resources/title-bar.js‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Ovis for Mac runs this in its main window's page as each page commits (TitleBar.swift): the window
2+
// draws no title bar there, and the page takes its place. `height` is the bar's height and `inset` the
3+
// traffic lights' right edge, as AppKit laid them out. The page marks the lights' corner as an iPad
4+
// window's (`data-window-controls`, lib/viewport.ts), so each screen keeps clear of it, and the wide
5+
// header takes the bar's height (`[data-mac-title-bar]` in src/styles.css). A press off the page's
6+
// controls, on a top bar or within the bar's height of the window's top, asks the app to move the
7+
// window once the mouse moves (`drag`, with where the press was, so the app moves the window for that
8+
// press only), and a double click there does what a title bar's does (`zoom`). A window the page
9+
// opened keeps its title bar and runs none of this.
10+
function ovisTitleBar(document, height, inset, post) {
11+
const root = document.documentElement;
12+
// once per page: the app runs it as the page commits and again once the window's bar is folded
13+
if (!root || root.dataset.macTitleBar !== undefined) return;
14+
root.dataset.macTitleBar = "";
15+
root.dataset.windowControls = "";
16+
root.style.setProperty("--mac-title-bar-h", `${height}px`);
17+
root.style.setProperty("--mac-title-bar-inset", `${inset}px`);
18+
19+
// the bars an installed desktop app drags its window by (styles.css, InboxMode.css)
20+
const BARS = ["app-header", "inbox-top", "thread-top"];
21+
const CONTROLS = "button, a, input, select, textarea, label, summary, [contenteditable], [role=button], [role=link], [role=tab], [role=group], [role=menu], [role=menuitem], [role=dialog], [role=listbox], [role=option]";
22+
// walked up to a bar, or to the page: a control, an open modal scrim or an open menu on the way
23+
// keeps the press the page's; a container focused only by script (tabindex -1, as .app is) and the
24+
// header's pane title text (role=group for accessibility) do not
25+
// the inbox's thread bar lets presses through to its pane (InboxMode.css), so the walk below never meets it: a
26+
// press in its box on what lies under it is the bar's, as on the installed desktop app's drag region
27+
const throughBar = (event) => Array.from(document.querySelectorAll(".thread-top")).some((bar) => {
28+
if (bar.contains(event.target) || !bar.parentElement?.contains(event.target)) return false;
29+
const box = bar.getBoundingClientRect();
30+
return event.clientX >= box.left && event.clientX < box.right && event.clientY >= box.top && event.clientY < box.bottom;
31+
});
32+
const bare = (event) => {
33+
if (throughBar(event)) return true;
34+
for (let node = event.target; node && typeof node.matches === "function"; node = node.parentElement) {
35+
if (node.classList.contains("modal-scrim")) return false;
36+
if ((node.matches(CONTROLS) && !node.classList.contains("context-title-text")) || node.tabIndex >= 0) return false;
37+
if (BARS.some((name) => node.classList.contains(name))) return true;
38+
}
39+
return event.clientY < height;
40+
};
41+
document.addEventListener("mousedown", (event) => {
42+
if (event.button === 0 && event.detail === 1 && bare(event)) post({ ask: "drag", x: event.clientX, y: event.clientY });
43+
}, true);
44+
document.addEventListener("dblclick", (event) => {
45+
if (event.button === 0 && bare(event)) post({ ask: "zoom" });
46+
}, true);
47+
}

‎app/mac/Sources/OvisMac/OvisMacApp.swift‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ struct OvisCommands: Commands {
6161
var body: some Commands {
6262
CommandGroup(after: .appInfo) { PhoneSetupItem() }
6363
CommandGroup(replacing: .newItem) { OpenInBrowserItem(model: model) }
64-
CommandGroup(before: .toolbar) { ReloadItem(model: model) }
64+
// in Show Toolbar's place: the main window's toolbar only sizes its folded bar (TitleBar.swift), and
65+
// hiding it would shorten the bar under the page's header
66+
CommandGroup(replacing: .toolbar) { ReloadItem(model: model) }
6567
}
6668
}
6769

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import AppKit
2+
import WebKit
3+
4+
/// The main window's title bar, folded away while the window shows the Ovis page: the page's header
5+
/// takes its place (`Resources/title-bar.js`), as the Codex and Claude apps draw their own. An empty
6+
/// compact toolbar gives the bar its height and centres the traffic lights on it; the page is handed
7+
/// that height and the lights' right edge, so its header matches the bar and starts clear of them.
8+
/// The setup, and a window the page opened, keep a title bar of their own.
9+
@MainActor
10+
enum TitleBar {
11+
private static let source = Bundle.main.url(forResource: "title-bar", withExtension: "js")
12+
.flatMap { try? String(contentsOf: $0, encoding: .utf8) }
13+
/// The page that folded each window's bar: when the server moves, the next page can join the window
14+
/// before the last one leaves it, and only the one that folded the bar gives it back.
15+
private static let folders = NSMapTable<NSWindow, NSView>.weakToWeakObjects()
16+
17+
struct Folded {
18+
let script: String
19+
let height: CGFloat
20+
}
21+
22+
/// Folds the window's bar away for `page` and returns the page's script and bar height; nil leaves
23+
/// the bar as it was (a build without the script, or a bar AppKit did not lay out as expected).
24+
static func fold(_ window: NSWindow, for page: NSView) -> Folded? {
25+
guard let source else { return nil }
26+
folders.setObject(page, forKey: window)
27+
window.styleMask.insert(.fullSizeContentView)
28+
window.titleVisibility = .hidden
29+
window.titlebarAppearsTransparent = true
30+
addToolbar(window)
31+
window.layoutIfNeeded()
32+
guard let zoom = window.standardWindowButton(.zoomButton), let bar = zoom.superview?.superview else {
33+
unfold(window, for: page)
34+
return nil
35+
}
36+
let height = bar.frame.height, inset = zoom.frame.maxX
37+
// a page joining a window already in full screen: measured with the toolbar, which full screen does
38+
// without until the window leaves it (the window's exit handler adds it back)
39+
if window.styleMask.contains(.fullScreen) { window.toolbar = nil }
40+
let post = "(ask) => window.webkit?.messageHandlers?.ovisTitleBar?.postMessage(ask)"
41+
return Folded(script: "(() => {\n\(source)\novisTitleBar(document, \(height), \(inset), \(post));\n})();", height: height)
42+
}
43+
44+
/// Whether a press at `y` points from the view's top lies inside the folded title-bar band.
45+
nonisolated static func inBarBand(y: CGFloat, height: CGFloat, fullScreen: Bool) -> Bool {
46+
!fullScreen && height > 0 && y >= 0 && y <= height
47+
}
48+
49+
/// Has AppKit look again for the views under the bar that take its clicks. It looks as the bar turns
50+
/// transparent, finding the page; but as the window comes on screen (its first showing at a restored
51+
/// frame, after Hide or the Dock) it asks only SwiftUI's view around the page, which takes none, and
52+
/// the bar then takes every click on the header.
53+
static func refresh(_ window: NSWindow) {
54+
window.titlebarAppearsTransparent = false
55+
window.titlebarAppearsTransparent = true
56+
}
57+
58+
/// The window's own bar back as `page` leaves it, for the setup that takes the page's place.
59+
static func unfold(_ window: NSWindow, for page: NSView) {
60+
guard folders.object(forKey: window) === page else { return }
61+
folders.removeObject(forKey: window)
62+
window.toolbar = nil
63+
window.isMovable = true
64+
window.titlebarAppearsTransparent = false
65+
window.titleVisibility = .visible
66+
window.styleMask.remove(.fullSizeContentView)
67+
}
68+
69+
/// In full screen the bar is a window of its own over the page, and a toolbar keeps it there: it goes
70+
/// for full screen, so the bar hides with the menu bar, and comes back after.
71+
static func addToolbar(_ window: NSWindow) {
72+
window.toolbar = NSToolbar()
73+
window.toolbarStyle = .unifiedCompact
74+
}
75+
76+
/// A double click on a title bar does what System Settings › Desktop & Dock says.
77+
static func doubleClick(_ window: NSWindow) {
78+
switch UserDefaults.standard.string(forKey: "AppleActionOnDoubleClick") {
79+
case "Minimize": window.performMiniaturize(nil)
80+
case "None": break
81+
default: window.performZoom(nil)
82+
}
83+
}
84+
}
85+
86+
/// The page's asks from its header (`title-bar.js`), taken only from the main window's page and its own
87+
/// frame: a window the page opened, and a web panel's frame of any site, can post them too.
88+
final class TitleBarMessages: NSObject, WKScriptMessageHandler {
89+
private weak var webView: OvisWebView?
90+
91+
init(_ webView: OvisWebView) {
92+
self.webView = webView
93+
}
94+
95+
func userContentController(_ controller: WKUserContentController, didReceive message: WKScriptMessage) {
96+
MainActor.assumeIsolated {
97+
guard let webView, message.webView === webView, message.frameInfo.isMainFrame, let window = webView.window else { return }
98+
guard let body = message.body as? [String: Any] else { return }
99+
switch body["ask"] as? String {
100+
case "drag":
101+
guard let x = body["x"] as? Double, let y = body["y"] as? Double else { return }
102+
webView.armDrag(at: CGPoint(x: x, y: y))
103+
case "zoom": TitleBar.doubleClick(window)
104+
default: break
105+
}
106+
}
107+
}
108+
}

‎app/mac/Sources/OvisMac/WebPage.swift‎

Lines changed: 129 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ struct WebPage: View {
2828
}
2929
}
3030
}
31+
// up to the window's top, where the page's header takes the title bar's place (TitleBar.swift)
32+
.ignoresSafeArea(.container, edges: .top)
3133
}
3234

3335
/// Hides the web view's empty white frame, which a dark window would flash.
@@ -43,9 +45,124 @@ private struct WebViewHost: NSViewRepresentable {
4345
}
4446

4547
final class OvisWebView: WKWebView {
48+
/// The main window's page, rather than the page of a window it opened.
49+
var drawsTitleBar = false
50+
/// The page's part of the folded bar, while its window has the bar folded.
51+
private var titleBarScript: String?
52+
private var titleBarHeight: CGFloat = 0
53+
private var windowWatch: [NSObjectProtocol] = []
54+
private var transparencyWatch: NSKeyValueObservation?
55+
/// Whether a cover hides the page (loading, or waiting for the server). The window server would move the
56+
/// window from a drag anywhere in the folded bar, a header tab or button included, so over the page only
57+
/// its asks (`title-bar.js`) move it, through `performDrag`; a cover asks nothing, and the bar moves it.
58+
var pageCovered = true {
59+
didSet { if titleBarScript != nil { window?.isMovable = pageCovered } }
60+
}
61+
/// The press under way, and whether the page found it on its header's bare surface.
62+
private var press: NSEvent?
63+
private var dragArmed = false
64+
65+
override func viewWillMove(toWindow newWindow: NSWindow?) {
66+
if let window, newWindow !== window, titleBarScript != nil {
67+
windowWatch.forEach(NotificationCenter.default.removeObserver)
68+
windowWatch = []
69+
transparencyWatch = nil
70+
TitleBar.unfold(window, for: self)
71+
titleBarScript = nil
72+
titleBarHeight = 0
73+
}
74+
super.viewWillMove(toWindow: newWindow)
75+
}
76+
4677
override func viewDidMoveToWindow() {
4778
super.viewDidMoveToWindow()
4879
window?.makeFirstResponder(self)
80+
guard drawsTitleBar, let window, titleBarScript == nil, let folded = TitleBar.fold(window, for: self) else { return }
81+
titleBarScript = folded.script
82+
titleBarHeight = folded.height
83+
window.isMovable = pageCovered
84+
let center = NotificationCenter.default
85+
windowWatch = [
86+
center.addObserver(forName: NSWindow.didChangeOcclusionStateNotification, object: window, queue: .main) { [weak window] _ in
87+
MainActor.assumeIsolated {
88+
guard let window, window.occlusionState.contains(.visible) else { return }
89+
TitleBar.refresh(window)
90+
}
91+
},
92+
center.addObserver(forName: NSWindow.willEnterFullScreenNotification, object: window, queue: .main) { [weak window] _ in
93+
MainActor.assumeIsolated { window?.toolbar = nil }
94+
},
95+
center.addObserver(forName: NSWindow.didExitFullScreenNotification, object: window, queue: .main) { [weak window] _ in
96+
MainActor.assumeIsolated {
97+
guard let window else { return }
98+
TitleBar.addToolbar(window)
99+
TitleBar.refresh(window)
100+
}
101+
},
102+
]
103+
// SwiftUI sets the bar's look again as it updates the window (as the page joins it, as the window turns
104+
// inactive): an opaque bar over the header, which WebKit then moves the page below. Folding it back at
105+
// once also has AppKit find the page under the bar again.
106+
transparencyWatch = window.observe(\.titlebarAppearsTransparent) { window, _ in
107+
MainActor.assumeIsolated {
108+
if !window.titlebarAppearsTransparent { window.titlebarAppearsTransparent = true }
109+
}
110+
}
111+
showHeaderInTitleBar()
112+
}
113+
114+
/// Lets a drag on the folded header move a background window on the first press, without waking
115+
/// clicks in the chat or terminal below the bar.
116+
override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
117+
if drawsTitleBar, let event, let window {
118+
var at = convert(event.locationInWindow, from: nil)
119+
if !isFlipped { at.y = bounds.height - at.y }
120+
if TitleBar.inBarBand(y: at.y, height: titleBarHeight, fullScreen: window.styleMask.contains(.fullScreen)) {
121+
return true
122+
}
123+
}
124+
return super.acceptsFirstMouse(for: event)
125+
}
126+
127+
/// Hands the page in the window its part of the folded bar: once the bar is folded, and as each page commits.
128+
func showHeaderInTitleBar() {
129+
if let titleBarScript { evaluateJavaScript(titleBarScript) }
130+
}
131+
132+
/// The press under way may move the window, if it is the one the page found on a bar: its ask comes
133+
/// after the press, and can come after a later one. It moves the window once the mouse moves, so a
134+
/// click or a double click on the bar stays the page's. `point` is where the page saw the press, in
135+
/// CSS pixels from the page's top left.
136+
func armDrag(at point: CGPoint) {
137+
guard let press else { return }
138+
var at = convert(press.locationInWindow, from: nil)
139+
if !isFlipped { at.y = bounds.height - at.y }
140+
dragArmed = abs(at.x / pageZoom - point.x) <= 1.5 && abs(at.y / pageZoom - point.y) <= 1.5
141+
}
142+
143+
override func mouseDown(with event: NSEvent) {
144+
press = event
145+
dragArmed = false
146+
super.mouseDown(with: event)
147+
}
148+
149+
override func mouseDragged(with event: NSEvent) {
150+
guard dragArmed, let press, let window else { return super.mouseDragged(with: event) }
151+
dragArmed = false
152+
self.press = nil
153+
window.performDrag(with: press)
154+
// the drag took the mouse-up, which the page still waits for to end its press
155+
if let up = NSEvent.mouseEvent(with: .leftMouseUp, location: window.mouseLocationOutsideOfEventStream, modifierFlags: [],
156+
timestamp: ProcessInfo.processInfo.systemUptime, windowNumber: window.windowNumber,
157+
context: nil, eventNumber: 0, clickCount: 1, pressure: 0) {
158+
super.mouseUp(with: up)
159+
}
160+
}
161+
162+
override func mouseUp(with event: NSEvent) {
163+
press = nil
164+
dragArmed = false
165+
super.mouseUp(with: event)
49166
}
50167
}
51168

@@ -58,8 +175,10 @@ final class WebPageController: NSObject, ObservableObject {
58175
case failed(String)
59176
}
60177

61-
@Published private(set) var state: State = .loading
62-
let webView: WKWebView
178+
@Published private(set) var state: State = .loading {
179+
didSet { webView.pageCovered = state != .shown }
180+
}
181+
let webView: OvisWebView
63182
private let origin: URL
64183
private weak var model: Model?
65184
private let isPopup: Bool
@@ -84,6 +203,7 @@ final class WebPageController: NSObject, ObservableObject {
84203
self.model = model
85204
isPopup = popupConfiguration != nil
86205
webView = OvisWebView(frame: .zero, configuration: popupConfiguration ?? Self.configuration())
206+
webView.drawsTitleBar = !isPopup
87207
super.init()
88208
webView.navigationDelegate = self
89209
webView.uiDelegate = self
@@ -92,6 +212,7 @@ final class WebPageController: NSObject, ObservableObject {
92212
guard !isPopup else { return }
93213
model.page = self
94214
reloads = model.$reloads.dropFirst().sink { [weak self] _ in self?.reload() }
215+
webView.configuration.userContentController.add(TitleBarMessages(webView), name: "ovisTitleBar")
95216
// drafts go only to this Mac's own server, as they came only from it
96217
if Self.isLoopback(origin) {
97218
let shared = Self.popups.contains { !$0.closed && $0.webView.url.map(self.isOvis) == true }
@@ -331,12 +452,17 @@ extension WebPageController: WKNavigationDelegate {
331452

332453
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
333454
if isPopup, let url = webView.url, isOvis(url) { showWindow() }
455+
if !isPopup { self.webView.showHeaderInTitleBar() }
334456
}
335457

336458
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
337459
state = .shown
338460
if let window, let title = webView.title, !title.isEmpty { window.title = title }
339-
if !isPopup { model?.pageLoaded() }
461+
if !isPopup {
462+
model?.pageLoaded()
463+
// again once loaded: at its commit a page can have no root yet, and the script waits for one
464+
self.webView.showHeaderInTitleBar()
465+
}
340466
if let token = carryToken {
341467
let shared = carryShared
342468
let before = carryBefore

‎app/mac/Tests/OvisMacTests/OvisMacTests.swift‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,15 @@ final class LinkBrowsersTests: XCTestCase {
217217
XCTAssertNil(LinkBrowsers.agentBrowserProgram(path: "", home: "/Users/u", isProgram: at([])))
218218
}
219219
}
220+
221+
final class TitleBarTests: XCTestCase {
222+
func testAcceptsFirstMouseOnlyInsideTheFoldedTitleBarBandWhenWindowed() {
223+
XCTAssertTrue(TitleBar.inBarBand(y: 0, height: 38, fullScreen: false))
224+
XCTAssertTrue(TitleBar.inBarBand(y: 19, height: 38, fullScreen: false))
225+
XCTAssertTrue(TitleBar.inBarBand(y: 38, height: 38, fullScreen: false))
226+
XCTAssertFalse(TitleBar.inBarBand(y: 38.5, height: 38, fullScreen: false))
227+
XCTAssertFalse(TitleBar.inBarBand(y: -1, height: 38, fullScreen: false))
228+
XCTAssertFalse(TitleBar.inBarBand(y: 19, height: 0, fullScreen: false))
229+
XCTAssertFalse(TitleBar.inBarBand(y: 19, height: 38, fullScreen: true))
230+
}
231+
}

0 commit comments

Comments
 (0)