From 150f01e9b42163a2a69975cb6033efd306fc5f4f Mon Sep 17 00:00:00 2001 From: Codeman maintainer Date: Tue, 24 Nov 2026 19:59:58 +0100 Subject: [PATCH] feat(desktop): the whole-display full screen is on by default, has a switch in App Settings, and the tabs go around the camera Three things the owner asked for after seeing the first build on a MacBook Pro with a camera housing, and one bug that run found. On by default. `wholeScreen` in desktop.json now reads as on when it is absent. The View menu item shows only while a display with a housing is connected, since the option's own value no longer says anything about the Mac. A switch in App Settings (Appearance > Mac App). The setting stays the app's: the app tells each page what the switch shows (`CodemanHostCutout.option({ available, enabled })`, on every page load and whenever it changes), the group shows only inside the app on a Mac with such a display, and saving sends a changed switch back through `CodemanHost.setWholeScreen` (IPC `wholeScreen`, trusted frames only). The menu item and every open page follow. It is never a key of the settings the page stores or the server keeps. Tabs on both sides of the camera. The toolbar's box used to start left of the housing, so the first row of tabs ended there and the room up to the toolbar stayed empty: three of ten tabs in the first row on that display. Now `fitTabs()` reads the tabs' rectangles, finds the one that would overlap the housing and gives the room to the tab before it as its right margin, so the row carries on right of the housing (five of ten there, same header height). Nothing is added to the strip and no tab is reordered. The tab strip calls it once its row mode is decided and before it measures one row; a resize observer follows a tab that grows or is added with no render behind it. The toolbar keeps its own box, a user-chosen width included, and takes the covering box (`html.host-cutout-toolbar`) only when it would reach the housing, and in a solo window. The bug: a window that comes out of a macOS Space is its own first responder and takes no keys. Ticking the option while in macOS's full screen left the terminal with a hollow cursor until a click. The web view now gets the keys when nothing else had them. Seen on the MacBook with the first build: launch into the mode, typing, the menu bar sliding in over the header, leaving and entering, both change-overs, relaunch, command+W, Dock and menu bar never stuck. Not yet seen there: this commit's default, switch and focus fix (the Mac went to sleep before the second round). Co-Authored-By: Claude Fable 5.2 --- .changeset/desktop-whole-screen.md | 2 +- docs/versioning-policy.md | 5 +- packages/desktop/README.md | 45 ++-- packages/desktop/src/assets.rs | 6 +- packages/desktop/src/config.rs | 16 +- packages/desktop/src/main.rs | 43 +++- packages/desktop/src/menu.rs | 6 +- packages/desktop/src/policy.rs | 24 ++ packages/desktop/src/whole_screen.rs | 53 ++++- src/web/CLAUDE.md | 2 +- src/web/public/app.js | 5 + src/web/public/host-cutout.js | 260 +++++++++++++++++++-- src/web/public/i18n.js | 4 + src/web/public/index.html | 15 ++ src/web/public/settings-ui.js | 22 ++ src/web/public/styles.css | 21 +- test/host-cutout.browser.test.ts | 155 ++++++++++--- test/host-cutout.test.ts | 333 ++++++++++++++++++++++++++- 18 files changed, 899 insertions(+), 118 deletions(-) diff --git a/.changeset/desktop-whole-screen.md b/.changeset/desktop-whole-screen.md index cbe8c9ac..19f2cdf0 100644 --- a/.changeset/desktop-whole-screen.md +++ b/.changeset/desktop-whole-screen.md @@ -2,4 +2,4 @@ 'aicodeman': patch --- -**Mac app: full screen over the whole display.** On a MacBook with a camera housing (the notch), macOS's full screen leaves a black bar across the top of the display. With **View > Full Screen Uses the Area Beside the Camera** turned on, the Mac app's full screen covers the whole display instead: Codeman's header moves up beside the camera, the tabs to its left and the toolbar to its right, and the terminal gains the height of the bar. The green button, the menu item, ⌃⌘F and the launch into full screen all follow the option, and switching it while the window is in full screen changes it over at once. It is off until you turn it on, because it is not a macOS Space: the window covers the desktop it is on instead of sliding into a Space of its own. The page stays below the camera, as before, with a Codeman server from before this release and while the tabs are grouped by state, by case or as a ledger in the header strip, where ending every row of tabs at the camera would cost more room than the bar gives. +**Mac app: full screen over the whole display.** On a MacBook with a camera housing (the notch), macOS's full screen leaves a black bar across the top of the display. The Mac app's full screen now covers the whole display instead: Codeman's header moves up beside the camera, the tabs go around it on both sides, the toolbar stays at the right, and the terminal gains the height of the bar. The green button, the menu item, ⌃⌘F and the launch into full screen all take it. It is on by default and can be turned off with **View > Full Screen Uses the Area Beside the Camera** or the same switch in **App Settings > Appearance > Mac App** (both only show on a Mac whose display has a camera housing); switching it while the window is in full screen changes it over at once. Off gives macOS's own full screen back, which is a Space of its own: the whole-display kind covers the desktop it is on instead. The page stays below the camera, as before, with a Codeman server from before this release and while the tabs are grouped by state, by case or as a ledger in the header strip. diff --git a/docs/versioning-policy.md b/docs/versioning-policy.md index 7e4ad397..a94d7c6d 100644 --- a/docs/versioning-policy.md +++ b/docs/versioning-policy.md @@ -64,8 +64,9 @@ These may change in a **MINOR** (or even PATCH) release without a MAJOR bump: Gesture Control (beta), Agent Teams (`CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1`), the native-wrapper window bridge (`window.CodemanHost.openWindow` / `closeWindow` / `focusWindow` / - `cutoutReady`, and `window.CodemanHostCutout.apply`, which a wrapper calls - to say where a display's camera housing is), and + `cutoutReady` / `setWholeScreen`, and `window.CodemanHostCutout.apply` and + `.option`, which a wrapper calls to say where a display's camera housing is + and what its own full-screen option is set to), and anything labeled experimental in the UI or docs. These may change or be removed at any time. diff --git a/packages/desktop/README.md b/packages/desktop/README.md index b48a8b92..904b8c99 100644 --- a/packages/desktop/README.md +++ b/packages/desktop/README.md @@ -34,7 +34,7 @@ cannot do. | **Start Codeman** | On the This Mac tab, and when `http://127.0.0.1:` or `http://localhost:` answers nothing, one click runs `codeman web -d` (or `~/.codeman/app`) with your login shell's environment, so the server gets your real PATH (Homebrew, nvm) for the agents it spawns. zsh, bash and other POSIX shells run the start themselves; fish, nu, xonsh, tcsh and other shells only report their environment, and the start runs under `/bin/sh` with it. Offered for those two addresses only: `codeman web -d` listens on 127.0.0.1. | | **Login** | The app answers the server's HTTP Basic login requests itself, with the login you connected with, so the page keeps working after the server restarts (a restart forgets every session cookie). It answers only for Codeman's own pages under the server's base path: a web tab or a rendered HTML file that asks for a Basic login of its own is left to WebKit and never gets your Codeman password. WebKit keeps no copy of the login, so every request for it gets the current one. Each connect first clears the app's cookies, so connecting to the same server as another user really switches users (local storage, where Codeman keeps its per-device settings, stays; a dashboard in a web tab that keeps its own login in a cookie may ask for it again). A page that still gets a 401 reloads once. If the server refuses the login (the password was changed, say), the app does not keep sending it: it checks it with a single probe, and only if the server refuses that too does the connect screen come back with a notice. That does not take focus from the app you are in: if Codeman is in the background, its Dock icon bounces. | | **Dialogs** | Codeman's `confirm()`, `prompt()` and `alert()` (Delete case, Kill all sessions, Update Codeman, discarding unsaved edits, ...) show as native macOS dialogs. wry implements none of them, and without them WKWebView answers Cancel without showing anything. Each dialog's first line names the page it comes from, and says so when that is an embedded frame (a web tab, a rendered HTML preview), so a frame cannot pass its text off as Codeman's. | -| **Full screen** | `⌃⌘F` or the green button. The last state is restored at launch; *Always Open in Full Screen* forces it. Leaving full screen returns to the saved window size and position. On a MacBook with a camera housing (the notch), macOS's full screen leaves a black bar across the top of the display. **View > Full Screen Uses the Area Beside the Camera** (off until you turn it on, and only in the menu on a Mac with such a display) makes full screen cover the whole display instead: Codeman's header moves up beside the camera, its tabs to the left and its toolbar to the right, and the terminal gains the height of the bar. Every way into full screen then takes it on that display (the green button, the menu item, `⌃⌘F`, the launch into full screen), and turning the option on or off while the window is in full screen changes it over at once. On a display without a housing nothing changes. See Decisions for what it trades, and Known limits. | +| **Full screen** | `⌃⌘F` or the green button. The last state is restored at launch; *Always Open in Full Screen* forces it. Leaving full screen returns to the saved window size and position. On a MacBook with a camera housing (the notch), macOS's full screen leaves a black bar across the top of the display. **Full Screen Uses the Area Beside the Camera** (on unless you turn it off; in the View menu and as a switch in Codeman's App Settings under Appearance > Mac App, both only on a Mac with such a display) makes full screen cover the whole display instead: Codeman's header moves up beside the camera, its tabs on both sides of it and its toolbar at the right, and the terminal gains the height of the bar. Every way into full screen then takes it on that display (the green button, the menu item, `⌃⌘F`, the launch into full screen), and turning the option on or off while the window is in full screen changes it over at once. On a display without a housing nothing changes. See Decisions for what it trades, and Known limits. | | **Menus** | A real Edit menu (without one, `⌘C`/`⌘V` do nothing in a WKWebView), Reload `⌘R`, Switch Server `⇧⌘O`, Developer Tools `⌥⌘I`. The page sees every key first, so Codeman's own shortcuts keep working. If the main window ends up showing a raw file instead of Codeman, `⌘R` takes it back to Codeman. | | **Pop-outs** | Implements Codeman's existing native-wrapper bridge, `window.CodemanHost` (`openInHostWindow` in `src/web/public/app.js`), so popping out a session or a file preview opens a real app window, and the pop-out icon is on by default. Session and rendered-HTML pop-outs come only from Codeman's own pop-out button. A `window.open` from page script opens only Codeman's file and download windows, without taking keyboard focus, at most 3 at once and then 1 per second. Only Codeman's own pop-out pages become app windows (see Decisions); when the app refuses one, Codeman shows a toast. Each pop-out opens a step down and to the right of the window in use, never exactly on top of another one. A web tab's *Open in new tab* opens the dashboard in your default browser, as it would from a browser tab. | | **Links** | On Codeman's own pages (the dashboard and session windows), a link to another site opens in your default browser, also on `⌘`-click or a middle click. Pages can send at most 3 links to the browser at once, then 1 per second. Inside a rendered HTML preview or a web tab, a plain link to another site does nothing, while one that asks for a new window (`target="_blank"`, `window.open`) opens in your default browser within the same budget (see Known limits). | @@ -301,21 +301,35 @@ shrink the display's active area as soon as a window reaches behind the housing. It is not a Space, and that is the trade: the window covers the desktop it is on, there is no slide animation, a three-finger swipe does not lead to it, and -another app's window on that desktop comes up in front of it. That is why it is -an option. On a display without a housing macOS's full screen already uses -every pixel, so the option changes nothing there and the window keeps its Space. +another app's window on that desktop comes up in front of it. That is why it +can be turned off, in the View menu or with the switch in Codeman's App +Settings (Appearance > Mac App), which is the same setting: the page asks the +app through `CodemanHost.setWholeScreen()` and the app tells every page what +the switch shows. It is on by default: on a display with a housing the black +bar costs more than the Space gives. On a display without a housing macOS's +full screen already uses every pixel, so the option changes nothing there and +the window keeps its Space. + +**Leaving macOS's full screen leaves the window without a first responder.** +A window that comes out of a native Space is its own first responder and takes +no keys, so a window that goes on to cover the whole display (the option +turned on while in macOS's full screen) gives the keys to the web view itself. +Seen on a MacBook Pro before the fix: the cursor stayed hollow and typing went +nowhere until a click. **A page is drawn behind the housing only after it said it copes.** The housing hides whatever is behind it, so the header has to keep its controls out of the way, and only the page can do that. Codeman's page says so through `CodemanHost.cutoutReady()` (`src/web/public/host-cutout.js`) and is then told where the housing is, in points from the top-left corner, and lays its header -out around it. Until a page has said so the web view stays below the housing +out around it: the tab that would sit under the housing starts just right of +it, and a toolbar that would reach it is moved past it. Until a page has said +so the web view stays below the housing and the strip above it is black, as in macOS's full screen. That covers an older Codeman server (its page never says it), the connect page, a raw file, and a layout the page itself declines: with the tabs grouped by state, by case -or as a ledger in the header strip, every row of tabs would have to end at the -housing, which costs more height than the strip gives. Only Codeman's own app +or as a ledger in the header strip, the rows are laid out by rules the page +cannot open a gap in. Only Codeman's own app shell may say it (`policy::parse_ipc`), so a rendered HTML file or a web tab cannot get the page drawn behind the camera. @@ -531,19 +545,20 @@ crosses, so the login is never on a command line. Mac mini, which has no housing and no screen session). Not seen: the window behind a real housing, the menu bar sliding in over it, the change-over from macOS's full screen, a second display, and closing the lid. -- **In that mode the tabs get the room left of the camera only.** A wrapped tab - strip runs its later rows across the whole width, but its first row ends at - the housing, and the room between the housing and the toolbar stays empty. On - a 14 inch display that is about three tabs fewer in the first row, so with - many tabs the strip can need one row more, which takes back what the bar - gave. With the tabs in the sidebar or the rail, or with a few tabs, the whole - height of the bar is gained. +- **In that mode the tabs go around the camera in the classic tab strip only.** + A row of tabs loses the width of the housing and 8 points on each side of it, + nothing else. With the tabs grouped by state, by case or as a ledger in the + header strip the page stays below the camera, with the black strip above it. +- **Turning the option on while in macOS's full screen shows the normal window + for under a second**, between the Space closing and the window covering the + display. - **Minimize does nothing in that mode** (`⌘M` beeps): the window has no title bar, as in macOS's full screen. The menu item says *Toggle Full Screen* in both kinds of full screen. - **A MacBook started with its lid closed has no menu item for it** until the app is started with the built-in display open: the item only exists while a - display with a housing is connected at launch, or the option is already on. + display with a housing is connected at launch. The switch in App Settings + shows as soon as a page loads while such a display is connected. - **Self-signed HTTPS is refused.** A server started with `codeman web --https` uses a self-signed certificate, and WKWebView rejects it (wry has no trust override). Use `http://127.0.0.1:3000` for a server on this Mac. For another diff --git a/packages/desktop/src/assets.rs b/packages/desktop/src/assets.rs index 19422b48..8957f774 100644 --- a/packages/desktop/src/assets.rs +++ b/packages/desktop/src/assets.rs @@ -63,6 +63,8 @@ pub fn respond(request: Request>) -> Response> { /// controls clear of a camera housing, so a full screen over the whole /// display may put the page behind it (`whole_screen.rs`; the page's side is /// `src/web/public/host-cutout.js`). Anything but `false` is a yes. +/// - `setWholeScreen(on)` is the settings page's switch for that full screen +/// (View > Full Screen Uses the Area Beside the Camera). Only `true` is on. pub const HOST_SHIM: &str = r#"(function () { 'use strict'; if (!/^https?:$/.test(location.protocol) || window.CodemanHost) return; @@ -93,7 +95,8 @@ pub const HOST_SHIM: &str = r#"(function () { }, closeWindow: function () { post({ cmd: 'closeWindow' }); }, focusWindow: function () { post({ cmd: 'focusWindow' }); }, - cutoutReady: function (ready) { post({ cmd: 'cutoutReady', ready: ready !== false }); } + cutoutReady: function (ready) { post({ cmd: 'cutoutReady', ready: ready !== false }); }, + setWholeScreen: function (on) { return post({ cmd: 'wholeScreen', on: on === true }); } }) }); @@ -279,6 +282,7 @@ mod tests { "closeWindow", "focusWindow", "cutoutReady", + "setWholeScreen", "__codemanDesktopRefused", "sessionExpired", "'auxclick'", diff --git a/packages/desktop/src/config.rs b/packages/desktop/src/config.rs index d0983f49..79d21ff7 100644 --- a/packages/desktop/src/config.rs +++ b/packages/desktop/src/config.rs @@ -46,7 +46,8 @@ pub struct Config { /// Always open in full screen (otherwise the last state is restored). pub start_fullscreen: bool, /// On a display with a camera housing, full screen covers the whole - /// display, the strip beside the camera included (whole_screen.rs). + /// display, the strip beside the camera included (whole_screen.rs). On + /// unless it was turned off; a display without a housing never sees it. pub whole_screen: bool, /// Whether the lit Apple logo shows what the agents are doing, and its style /// for each state (logo.rs). The menu only shows on a Mac that has one. A @@ -83,7 +84,7 @@ impl Default for Config { servers: Vec::new(), auto_connect: true, start_fullscreen: false, - whole_screen: false, + whole_screen: true, logo_blink: BlinkStyles::default(), keep_awake: keep_awake::Settings::default(), window: None, @@ -475,13 +476,16 @@ mod tests { } #[test] - fn full_screen_over_the_whole_display_is_off_until_chosen() { - assert!(!Config::default().whole_screen); + fn full_screen_over_the_whole_display_is_on_until_turned_off() { + assert!(Config::default().whole_screen); // A file from before the option. let c: Config = serde_json::from_str(r#"{"startFullscreen":true}"#).unwrap(); - assert!(!c.whole_screen); - let c: Config = serde_json::from_str(r#"{"wholeScreen":true}"#).unwrap(); assert!(c.whole_screen); + let c: Config = serde_json::from_str(r#"{"wholeScreen":false}"#).unwrap(); + assert!(!c.whole_screen); + // Turned off, it stays off across a save. + let back: Config = serde_json::from_str(&serde_json::to_string(&c).unwrap()).unwrap(); + assert!(!back.whole_screen); } #[test] diff --git a/packages/desktop/src/main.rs b/packages/desktop/src/main.rs index ba459910..68e8df41 100644 --- a/packages/desktop/src/main.rs +++ b/packages/desktop/src/main.rs @@ -1384,7 +1384,12 @@ impl App { self.config_dirty = true; self.to_connect_page(json!({ "type": "prefs", "startFullscreen": value })); } - menu_id::WHOLE_SCREEN => self.toggle_whole_screen(), + menu_id::WHOLE_SCREEN => { + // muda has already flipped the item's check mark. + if let Some(on) = self.menu.whole_screen.as_ref().map(|item| item.is_checked()) { + self.set_whole_screen(on); + } + } menu_id::DEVTOOLS => { if let Some(w) = self.focused_window_id().and_then(|id| self.windows.get(&id)) { w.webview.open_devtools(); @@ -1437,27 +1442,35 @@ impl App { whole_screen::set_page_ready(&w.window, ready); } self.sync_whole_screen(window); + // A page that announces itself has just loaded: its + // settings switch needs the option's state. + self.tell_whole_screen_option(Some(window)); } #[cfg(not(target_os = "macos"))] let _ = ready; } + HostCmd::SetWholeScreen(on) => self.set_whole_screen(on), } } - /// View > Full Screen Uses the Area Beside the Camera. A main window that - /// is in full screen changes over at once, so the user sees what the - /// option does: out of macOS's full screen and, once its Space has closed + /// View > Full Screen Uses the Area Beside the Camera, and the same switch + /// in Codeman's settings page. A main window that is in full screen + /// changes over at once, so the user sees what the option does: out of + /// macOS's full screen and, once its Space has closed /// (`retry_fullscreen`), over the whole display, or straight back from the /// whole display into macOS's. - fn toggle_whole_screen(&mut self) { - let Some(on) = self.menu.whole_screen.as_ref().map(|item| item.is_checked()) else { - return; - }; + fn set_whole_screen(&mut self, on: bool) { + // The menu item and every page's switch show the same thing, whichever + // of them was used. + if let Some(item) = &self.menu.whole_screen { + item.set_checked(on); + } self.config.whole_screen = on; self.config_dirty = true; #[cfg(target_os = "macos")] { whole_screen::set_enabled(on); + self.tell_whole_screen_option(None); let Some(main) = self.windows.get(&self.main_id) else { return; }; @@ -1475,6 +1488,18 @@ impl App { } } + /// Tells one window's page, or every window's, what the option's switch in + /// its settings shows (whole_screen::option_script). + #[cfg(target_os = "macos")] + fn tell_whole_screen_option(&self, only: Option) { + let script = whole_screen::option_script(whole_screen::available(), self.config.whole_screen); + for (id, w) in &self.windows { + if only.is_none_or(|one| one == *id) { + let _ = w.webview.evaluate_script(&script); + } + } + } + /// Brings a window in line with full screen over the whole display: its /// frame, how far its web view stays below a camera housing, and what its /// page knows about the housing (whole_screen::sync). @@ -2172,7 +2197,7 @@ impl App { // frame; the saved one is kept for the next launch. Nor is it while // the window animates into or out of macOS's full screen, which tao // stops reporting as full screen the moment the app asks it to leave - // (toggle_whole_screen). + // (set_whole_screen). #[cfg(target_os = "macos")] let transitional = whole_screen::in_transition(w); #[cfg(not(target_os = "macos"))] diff --git a/packages/desktop/src/menu.rs b/packages/desktop/src/menu.rs index 618f249f..d92ed2f2 100644 --- a/packages/desktop/src/menu.rs +++ b/packages/desktop/src/menu.rs @@ -202,9 +202,9 @@ pub fn build_menu(config: &Config) -> muda::Result { None, ); // Only where it can do something: a display with a camera housing is - // connected, or the option is already on (a MacBook started with its lid - // closed still gets the item that turns it off). - let whole_screen = (whole_screen_available() || config.whole_screen).then(|| { + // connected. The option is on unless it was turned off, so its own value + // says nothing about the Mac. + let whole_screen = whole_screen_available().then(|| { CheckMenuItem::with_id( menu_id::WHOLE_SCREEN, "Full Screen Uses the Area Beside the Camera", diff --git a/packages/desktop/src/policy.rs b/packages/desktop/src/policy.rs index 2ae29f98..21f4e8e5 100644 --- a/packages/desktop/src/policy.rs +++ b/packages/desktop/src/policy.rs @@ -589,6 +589,9 @@ pub enum HostCmd { /// is told where one is (whole_screen.rs), and so may be drawn behind it. /// A page says no for a layout that would only lose room that way. CutoutReady(bool), + /// Codeman's settings page turned "full screen uses the area beside the + /// camera" on or off (the View menu's item, from the page). + SetWholeScreen(bool), } /// Calls the bundled connect page makes. @@ -737,6 +740,9 @@ enum RawHost { #[serde(default = "yes")] ready: bool, }, + WholeScreen { + on: bool, + }, } fn yes() -> bool { @@ -838,6 +844,7 @@ pub fn parse_ipc(frame_url: &str, body: &str, phase: &Phase, is_main_window: boo RawHost::OpenExternal { url } if url.len() <= MAX_URL_LEN => HostCmd::OpenExternal(url), RawHost::SessionExpired => HostCmd::SessionExpired, RawHost::CutoutReady { ready } => HostCmd::CutoutReady(ready), + RawHost::WholeScreen { on } => HostCmd::SetWholeScreen(on), _ => return None, }; Some(Ipc::Host(cmd)) @@ -1583,6 +1590,18 @@ mod tests { parse_ipc(main, r#"{"cmd":"cutoutReady","ready":"yes"}"#, &loaded, true), None ); + // The settings page's switch for the whole-display full screen: on or + // off, said outright. No field, or one of another type, is no message. + assert_eq!( + parse_ipc(main, r#"{"cmd":"wholeScreen","on":true}"#, &loaded, true), + Some(Ipc::Host(HostCmd::SetWholeScreen(true))) + ); + assert_eq!( + parse_ipc(main, r#"{"cmd":"wholeScreen","on":false}"#, &loaded, true), + Some(Ipc::Host(HostCmd::SetWholeScreen(false))) + ); + assert_eq!(parse_ipc(main, r#"{"cmd":"wholeScreen"}"#, &loaded, true), None); + assert_eq!(parse_ipc(main, r#"{"cmd":"wholeScreen","on":1}"#, &loaded, true), None); // Untrusted surfaces, other origins, connect commands: refused. for frame in [ "http://127.0.0.1:3000/html-view/c/x.html", @@ -1598,6 +1617,11 @@ mod tests { // A rendered HTML file or a web tab must not get the page drawn // behind the camera by claiming it copes. assert_eq!(parse_ipc(frame, r#"{"cmd":"cutoutReady"}"#, &loaded, true), None); + // Nor may one change the app's own settings. + assert_eq!( + parse_ipc(frame, r#"{"cmd":"wholeScreen","on":false}"#, &loaded, true), + None + ); } assert_eq!( parse_ipc(main, r#"{"cmd":"startServer","url":"x"}"#, &loaded, true), diff --git a/packages/desktop/src/whole_screen.rs b/packages/desktop/src/whole_screen.rs index 40ba9bad..73d077df 100644 --- a/packages/desktop/src/whole_screen.rs +++ b/packages/desktop/src/whole_screen.rs @@ -168,6 +168,15 @@ pub fn page_script(cutout: Option) -> String { ) } +/// Tells the page what its settings switch shows: whether this Mac has a +/// display the option does anything on, and whether the option is on. Like +/// [`page_script`], it does nothing in a page without the cutout module. +pub fn option_script(available: bool, enabled: bool) -> String { + format!( + "window.CodemanHostCutout&&typeof window.CodemanHostCutout.option==='function'&&window.CodemanHostCutout.option({{available:{available},enabled:{enabled}}});" + ) +} + // NSApplicationPresentationOptions, as plain bits so the rule below is tested // on any host (`imp` asserts they match AppKit's). const AUTO_HIDE_DOCK: usize = 1 << 0; @@ -960,12 +969,19 @@ mod imp { changed(id); } + /// Puts the keys back where they were before the title bar went or came. + /// A window is its own first responder when nothing else is, and takes no + /// keys: one that has just come out of macOS's full screen is left like + /// that (seen on a MacBook Pro: the option ticked while in macOS's full + /// screen, and typing went nowhere until a click). The page then gets the + /// keys, being the only thing in the window. fn restore_responder(window: &NSWindow, responder: Option>) { - if let Some(responder) = responder { - // A window is its own first responder when nothing else is. - if !ptr::eq(Retained::as_ptr(&responder).cast::(), ptr::from_ref(window)) { - window.makeFirstResponder(Some(&responder)); - } + let other = responder.filter(|r| !ptr::eq(Retained::as_ptr(r).cast::(), ptr::from_ref(window))); + if let Some(responder) = other { + window.makeFirstResponder(Some(&responder)); + } else if let Some(web_view) = with_tracked(key(window), |t| t.web_view.clone()) { + let page: &NSResponder = &web_view; + window.makeFirstResponder(Some(page)); } } @@ -1235,6 +1251,33 @@ mod tests { ); } + #[test] + fn the_page_is_told_what_its_settings_switch_shows() { + assert_eq!( + option_script(true, false), + "window.CodemanHostCutout&&typeof window.CodemanHostCutout.option==='function'\ + &&window.CodemanHostCutout.option({available:true,enabled:false});" + ); + assert!(option_script(false, true).ends_with(".option({available:false,enabled:true});")); + } + + /// Measured on a MacBook Pro (Mac17,13, macOS 27.2) at its default + /// resolution: a housing 59 pt wide in a strip 40 pt high. + #[test] + fn a_narrow_housing_is_read_like_a_wide_one() { + assert_eq!( + housing(1512.0, 40.0, 726.5, 726.5), + Some(Housing { + height: 40.0, + cutout: Some(Cutout { + left: 726.5, + width: 59.0, + height: 40.0, + }), + }) + ); + } + #[test] fn entering_hides_the_dock_and_the_menu_bar_and_remembers_what_it_added() { assert_eq!( diff --git a/src/web/CLAUDE.md b/src/web/CLAUDE.md index 7c1e2a29..898e266a 100644 --- a/src/web/CLAUDE.md +++ b/src/web/CLAUDE.md @@ -40,7 +40,7 @@ Frontend JS modules have `@fileoverview` with `@dependency`/`@loadorder` tags. L **Tab layouts** (`tabArrangement`, per-device, default `classic`; `state`/`case`/`ledger` are opt-in; Discussion #426): `state` (option C) splits the list into needs you / waiting / working / idle (idle is `quiet`: its heading stays as the row's anchor but draws no label; `tabStateOrder: 'urgent-last'` flips the order, needs you at the bottom): rows in the desktop header strip with left-aligned labels in a measured column (the brand sits over the strip's corner, so the rows after the first start under "Codeman"), sections in the flat rail and the sidebar, inline dividers on the tablet strip, group order with no headings on phones. `case` (option A) wraps each case's tabs in one `.tab-cluster` box and hides the `-` of a generated name (`.tab-name-case`). `ledger` (option B) is a CSS-only grid on the desktop header strip. `classic` is the old strip; once it wraps on desktop it is L-shaped via `_syncTabStripCorner()` (the toolbar sits over its top-right corner and later rows run the full width under it, a strip already past its max-height keeps the plain wrap): ⚠️ `.tabs-corner` comes off before the wrap is measured, and the strip is `display: block` in that state, so flex-only rules do not apply to it there (`test/tab-strip-corner.browser.test.ts`). Pure cores: `CodemanTabTriage` and `CodemanTabClusters` (constants.js). ⚠️ `state` is the flex `order` property plus `aria-hidden` heading/break elements reconciled in place by `_syncTabTriageChrome()` after BOTH render paths, never a DOM reorder (a state change is an incremental pass). ⚠️ `case` boxes ARE a DOM grouping, so the incremental path rebuilds whenever `_tabClusterLayout().key` changes; membership follows `_mobileOverviewCaseFor()` like the home screens. ⚠️ Drag only reorders within a group or box (`_isTabDropAcrossGroups()`). ⚠️ Named groups in the vertical rail win over both groupings. ⚠️ `classic` must leave no trace (no headings, no inline order, no boxes, no name split), and the ledger must not change the markup. ⚠️ Grouping is a render layer: `sessionOrder`, Alt+[ / Alt+], Ctrl+Tab and Alt+1..9 keep the canonical order, and only the phone swipe walks the drawn order (`nextSession({ visual: true })` through `_stripSessionOrder()`, the same `_visibleTabRows()` walk the strip's arrow keys use); an active session the list does not draw steps in at the first or last row, and an empty drawn list goes nowhere rather than falling back to a hidden session (`test/session-swipe-gesture.test.ts`). Tests: `test/tab-triage.test.ts`, `test/tab-clusters.test.ts`. → [architecture-invariants#tab-layouts-by-state-by-case-ledger](../../docs/architecture-invariants.md#tab-layouts-by-state-by-case-ledger) -**Header beside a camera housing** (`host-cutout.js`, the `html.host-cutout` rules in styles.css; Codeman Desktop only, `packages/desktop/src/whole_screen.rs`): the Mac app can take a MacBook's whole display, and the page's top edge is then the display's, with the camera housing (the notch) covering a piece of the header row. The app puts a page there only after the page said it copes: the module calls `CodemanHost.cutoutReady(true)` and is answered with `CodemanHostCutout.apply({ left, width, height })` (CSS pixels from the viewport's top-left corner; `apply(null)` when there is none any more), which sets `--host-cutout-left/-width/-height` and the class. ⚠️ The layout is ONE box: the toolbar (`#headerRight`) starts just left of the housing, runs to the header's right padding and pads its content past the housing, so the tabs (or a solo window's title) end where it begins, and `_syncTabStripCorner()` sizes the L-shaped strip's float from that same box. Never position anything else in the header's first row by the housing, and anything new that paints in that row must sit inside the tab strip or the toolbar. ⚠️ `0.75rem` in the rule is the header's own side padding; change the two together (pinned by the test). ⚠️ The rule replaces a toolbar width the user chose (`html[data-header-right-width]:not(.host-cutout)`) and hides the divider handle while it holds. ⚠️ With the tabs grouped by state, by case or as a ledger IN THE HEADER STRIP every row sits beside the toolbar, so ending them at the housing costs more height than the strip gives (measured 69 px for 32 px): `fits()` says no there, the module answers `cutoutReady(false)` and drops the layout at once, and the app keeps the page below the housing. It re-announces only when `data-tab-arrangement`, `data-session-list` or `data-tab-orientation` change; a solo window always fits. ⚠️ The script is in `` and NOT deferred, after the pre-paint script that writes those attributes: the app hears before first paint, so the page is not painted below the housing first and behind it a moment later; `window.app` may not exist yet, so it is only used through `?.`. In a browser tab there is no `CodemanHost.cutoutReady` and the module does nothing. Tests: `test/host-cutout.test.ts`, `test/host-cutout.browser.test.ts` (browser suite, not in the gate). +**Header beside a camera housing** (`host-cutout.js`, the `html.host-cutout-toolbar` rules in styles.css; Codeman Desktop only, `packages/desktop/src/whole_screen.rs`): the Mac app can take a MacBook's whole display, and the page's top edge is then the display's, with the camera housing (the notch) covering a piece of the header row. The app puts a page there only after the page said it copes: the module calls `CodemanHost.cutoutReady(true)` and is answered with `CodemanHostCutout.apply({ left, width, height })` (CSS pixels from the viewport's top-left corner; `apply(null)` when there is none any more), which sets `--host-cutout-left/-width/-height` and the class `host-cutout`. ⚠️ The TABS go around the housing by a MARGIN, never by an element: `fitTabs()` reads rectangles, finds the tab that would overlap the housing (8 px of air on each side, `GAP`, the same value as `--host-cutout-gap`) and gives the room to the tab BEFORE it in the row as its right margin, so a tab that no longer fits right of the housing wraps flush left; only a row's first tab takes the margin itself. Nothing is added to `#sessionTabs` and no tab is reordered, so order, drag and key walks see the strip they always saw; never solve it with a spacer element or `order`. It is geometric (no knowledge of the strip's mode), covers every row beside the housing and none below it. ⚠️ `updateTabOverflowMode()` calls it LAST, once the row mode and the corner are decided, and `_decideTabOverflow()` calls it right before measuring one row (the gap is part of what a row has to hold); the module's own ResizeObserver (border boxes of the strip, every tab, the toolbar and its children) and a childList observer follow changes with no render behind them (a selected tab widening, a reading arriving), always one animation frame later: a size changed inside the observer callback is reported as a ResizeObserver loop. ⚠️ The TOOLBAR (`#headerRight`) stays as it is while it ends right of the housing, the user's chosen width and the divider handle included. `fitToolbar()` gives it the covering box (`html.host-cutout-toolbar`: from just left of the housing to the header's right padding, content padded past the housing, wrapping below it) only when it would reach the housing, always in a solo window (its title shares the row), and until the header is parsed; it measures the toolbar with that class OFF, so the answer never depends on the answer before. `0.75rem` in the rule is the header's own side padding; change the two together (pinned by the test). Anything new that paints in the header's first row must sit inside the tab strip or the toolbar. ⚠️ With the tabs grouped by state, by case or as a ledger IN THE HEADER STRIP the rows follow rules a margin cannot open a gap in (flex `order`, cluster boxes, a grid): `fits()` says no there, the module answers `cutoutReady(false)` and drops the layout at once, and the app keeps the page below the housing. It re-announces only when `data-tab-arrangement`, `data-session-list` or `data-tab-orientation` change. ⚠️ The option itself is the APP's (its `desktop.json`, default on), never a key of the settings blob or of `SettingsUpdateSchema`: the app calls `CodemanHostCutout.option({ available, enabled })` on every page load and whenever it changes, App Settings shows the group `#appSettingsHostGroup` (Appearance > Mac App) only while `available`, and `saveAppSettings()` sends a changed switch through `CodemanHostCutout.setWholeScreen()`, whatever becomes of the rest of the save. ⚠️ The script is in `` and NOT deferred, after the pre-paint script that writes those attributes: the app hears before first paint, so the page is not painted below the housing first and behind it a moment later; `window.app` may not exist yet, so it is only used through `?.`. In a browser tab there is no `CodemanHost.cutoutReady` and the module does nothing. Tests: `test/host-cutout.test.ts` (a row model of the strip), `test/host-cutout.browser.test.ts` (real Chromium, browser suite, not in the gate). **Header stats styles** (`headerStatsStyle`, per-device, desktop only, default `compact`; Discussion #426 option G): `tiles` / `compact` (two pills, a ring beside every value) / `classic` (as before), keyed on `data-header-stats` (pre-paint + `applyHeaderStatsStyle()`), forced to `classic` below 768px and in a solo window. ⚠️ The clustered styles MOVE `#connectionIndicator` into `#headerSystemStats` and `#planUsageChip` right after it; `classic` moves them back to comment anchors. ⚠️ WS joins the pill only while System Stats is shown. ⚠️ The extra parts (stat rings, tile words, plan rings, meters) are always rendered and hidden by default in CSS, which is what keeps `classic` unchanged; tile words are derived beside the connection descriptor, never added to it (`test/connection-indicator.test.ts` pins its shape). ⚠️ A tile is a three-row grid (label, value, bar) with pixel line-heights and the bundled JetBrains Mono; never lay the bar over a fixed-height tile (a taller system mono put the value on top of it). The WS tile's grid lives on the inner `.connection-tile`, because JS writes the indicator's `display` inline. Tests: `test/header-stats-style.test.ts`. → [architecture-invariants#header-stats-styles](../../docs/architecture-invariants.md#header-stats-styles) diff --git a/src/web/public/app.js b/src/web/public/app.js index 94636082..33f1260d 100644 --- a/src/web/public/app.js +++ b/src/web/public/app.js @@ -7014,6 +7014,9 @@ class CodemanApp { container.classList.remove('tabs-corner'); this._decideTabOverflow(container); this._syncTabStripCorner(container); + // Beside a camera housing (Codeman Desktop, host-cutout.js) the tabs go around it. Last, once the strip's + // mode is decided: the gap depends on where the tabs ended up. + window.CodemanHostCutout?.fitTabs?.(container); } _decideTabOverflow(container) { @@ -7064,6 +7067,8 @@ class CodemanApp { // Measure the natural one-row overflow, then enable wrapping only if needed. container.classList.remove('tabs-auto-wrap'); + // The gap at a camera housing is part of what one row has to hold. + window.CodemanHostCutout?.fitTabs?.(container); const shouldWrap = window.CodemanTabOverflow?.shouldAutoWrapTabs ? window.CodemanTabOverflow.shouldAutoWrapTabs({ deviceType, diff --git a/src/web/public/host-cutout.js b/src/web/public/host-cutout.js index 53a49445..5d4e3096 100644 --- a/src/web/public/host-cutout.js +++ b/src/web/public/host-cutout.js @@ -2,21 +2,31 @@ * @fileoverview Keeps the header clear of a camera housing (the notch of a MacBook display). * * In a browser tab nothing is ever drawn behind the housing: macOS keeps windows, and its own full screen, - * below it. Codeman Desktop can take the whole display (its View menu: "Full Screen Uses the Area Beside the - * Camera"), and the page's top edge is then the display's, with the housing covering a piece of the header - * row. A page has to keep its controls out from under it, so the app only puts a page there after the page - * said it can: this module calls `CodemanHost.cutoutReady(true)`, and the app answers with - * `CodemanHostCutout.apply({ left, width, height })`, the housing in CSS pixels from the viewport's top-left - * corner, or `apply(null)` when there is none any more (full screen left, the window moved to another display). + * below it. Codeman Desktop can take the whole display (its View menu, and the switch in App Settings: "Full + * Screen Uses the Area Beside the Camera"), and the page's top edge is then the display's, with the housing + * covering a piece of the header row. A page has to keep its controls out from under it, so the app only puts + * a page there after the page said it can: this module calls `CodemanHost.cutoutReady(true)`, and the app + * answers with `CodemanHostCutout.apply({ left, width, height })`, the housing in CSS pixels from the + * viewport's top-left corner, or `apply(null)` when there is none any more (full screen left, the window + * moved to another display). * - * The layout itself is CSS (styles.css, `html.host-cutout`): the toolbar's box starts just left of the housing - * and its content just right of it, so the tabs end before the housing and the toolbar begins after it. This - * module only sets the three custom properties and the class, then has the tab strip measure the toolbar again. + * Two things in the header's first row can reach the housing, and each is kept clear in its own way: * - * Not every layout gains from that. With the tabs grouped by state, by case or as a ledger in the header strip, - * every row of tabs sits beside the toolbar, so ending them all at the housing costs more height than the strip - * beside the housing gives (measured: 69 px more header for a 32 px strip). For those the page says - * `cutoutReady(false)` and stays below the housing; it says so again whenever the layout changes. + * - The tabs go AROUND it (`fitTabs`): the tab that would sit under the housing starts just right of it, by + * way of a margin on the tab before it, so the row carries on to the toolbar. Nothing is added to the strip + * and no tab changes place in it, so every reader of the strip (order, drag, keys) sees what it always saw. + * - The toolbar normally ends well right of the housing and stays as it is. One that would reach it (many + * readings, a width the user dragged, a solo window whose title shares the row) takes the box of styles.css + * instead (`html.host-cutout-toolbar`): from just left of the housing to the header's right edge, its + * content padded past the housing, so whatever is left of it ends before the housing (`fitToolbar`). + * + * Not every layout gains from that. With the tabs grouped by state, by case or as a ledger in the header + * strip, the rows are laid out by rules of their own that a margin cannot open a gap in. For those the page + * says `cutoutReady(false)` and stays below the housing; it says so again whenever the layout changes. + * + * The app also says what the option's switch shows, `CodemanHostCutout.option({ available, enabled })`, on + * every page load and whenever it changes; App Settings reads it through `wholeScreen()` and turns it on or + * off with `setWholeScreen(on)`. The setting is the app's own (its `desktop.json`), never the server's. * * A page without this module (an older Codeman server) never calls `cutoutReady`, and the app keeps it below * the housing with a black strip above it, the way macOS's full screen looks. @@ -29,6 +39,10 @@ /** No housing is larger than this; a larger value is a mistake and must not empty the header. */ const MAX_HEIGHT = 200; + /** Room kept free on each side of the housing, in px. styles.css uses the same value (--host-cutout-gap). */ + const GAP = 8; + /** A row of tabs is cleared in one pass; more than a few rows beside a housing is not a real header. */ + const MAX_PASSES = 8; /** `cutout` as three finite numbers, or null when it is not a usable rectangle. */ function normalize(cutout) { @@ -44,15 +58,21 @@ /** The tab arrangements that lay out every row of the header strip themselves (app.js, Tab layouts). */ const GROUPED = ['state', 'case', 'ledger']; - /** Whether the header gains from being drawn beside the housing in the layout the page is in. */ + /** + * A solo window (/session/:id, under any base path) has no tab strip. Its URL says so before the server's + * own marker is parsed, which sits at the end of . + */ + function isSolo() { + return ( + /\/session\/[^/]+\/?$/.test(location.pathname) || + (typeof window.__CODEMAN_SOLO__ === 'string' && window.__CODEMAN_SOLO__ !== '') + ); + } + + /** Whether the header can be drawn beside the housing in the layout the page is in. */ function fits() { const data = document.documentElement.dataset; - // A solo window (/session/:id, under any base path) has no tab strip. Its URL says so before the server's - // own marker is parsed, which sits at the end of . - const solo = - /\/session\/[^/]+\/?$/.test(location.pathname) || - (typeof window.__CODEMAN_SOLO__ === 'string' && window.__CODEMAN_SOLO__ !== ''); - const tabsInHeader = !solo && data.sessionList !== 'sidebar' && data.tabOrientation !== 'vertical'; + const tabsInHeader = !isSolo() && data.sessionList !== 'sidebar' && data.tabOrientation !== 'vertical'; return !(tabsInHeader && GROUPED.includes(data.tabArrangement)); } @@ -74,12 +94,167 @@ } } + // ---------------------------------------------------------------- the tabs + + /** The tabs whose margin `fitTabs` widened. Nothing else sets a margin on a tab's own style. */ + const moved = new Set(); + /** What the last pass did, so a caller can tell whether a tab moved. */ + let movedKey = ''; + + function clearGaps() { + for (const tab of moved) { + tab.style.removeProperty('margin-left'); + tab.style.removeProperty('margin-right'); + } + moved.clear(); + } + + /** + * Moves every tab out from under the housing. A tab that would overlap it (with `GAP` px of air on each + * side) starts right of it instead. The room is given to the tab BEFORE it in the row, as its right margin: + * a tab that no longer fits in the row after that wraps to the next one flush left, where a margin of its + * own would indent it. Only the first tab of a row has no such neighbour and takes the room itself. + * + * Purely geometric (it reads rectangles, never the strip's mode), so it holds in the single row, the + * wrapped strip and the L-shaped one, and does nothing where the tabs are nowhere near the housing (the + * sidebar, the rail). Returns true when a tab moved since the last pass. + */ + function fitTabs(strip) { + const host = strip || document.getElementById('sessionTabs'); + clearGaps(); + let key = ''; + if (current && host) { + const left = current.left - GAP; + const right = current.left + current.width + GAP; + const tabs = host.querySelectorAll('.session-tab'); + for (let pass = 0; pass < MAX_PASSES; pass++) { + // The rows that sit beside the housing, and the first tab in them that overlaps it. + const beside = []; + let hit = null; + for (let i = 0; i < tabs.length; i++) { + const rect = tabs[i].getBoundingClientRect(); + if (rect.width <= 0 || rect.height <= 0) continue; + if (rect.top >= current.height || rect.bottom <= 0) continue; + const entry = { tab: tabs[i], rect, index: i }; + beside.push(entry); + if (rect.right <= left || rect.left >= right) continue; + if (!hit || rect.top < hit.rect.top - 1 || (rect.top <= hit.rect.top + 1 && rect.left < hit.rect.left)) { + hit = entry; + } + } + if (!hit) break; + let before = null; + for (const entry of beside) { + if (entry === hit || entry.rect.right > hit.rect.left + 1) continue; + if (entry.rect.bottom <= hit.rect.top + 2 || entry.rect.top >= hit.rect.bottom - 2) continue; + if (!before || entry.rect.right > before.rect.right) before = entry; + } + const target = before || hit; + const side = before ? 'margin-right' : 'margin-left'; + const base = parseFloat(getComputedStyle(target.tab).getPropertyValue(side)) || 0; + const margin = Math.ceil(base + right - hit.rect.left); + target.tab.style.setProperty(side, margin + 'px'); + moved.add(target.tab); + key += target.index + side + margin + ';'; + } + } + const changed = key !== movedKey; + movedKey = key; + return changed; + } + + // ---------------------------------------------------------------- the toolbar + + /** What the toolbar's box was decided on, so a pass with nothing new costs one string. */ + let toolbarKey = null; + + /** + * Decides whether the toolbar needs the box that covers the housing (`html.host-cutout-toolbar`, + * styles.css). It is measured as it lies without that box, so the answer never depends on the answer before. + * Returns true when it changed. + */ + function fitToolbar() { + const root = document.documentElement; + const had = root.classList.contains('host-cutout-toolbar'); + if (!current) { + toolbarKey = null; + root.classList.remove('host-cutout-toolbar'); + return had; + } + const toolbar = document.getElementById('headerRight'); + if (!toolbar) { + // The header is not parsed yet: cover the housing until it can be measured. + root.classList.add('host-cutout-toolbar'); + return !had; + } + let key = `${window.innerWidth}|${current.left}|${current.width}|${root.dataset.headerRightWidth ?? ''}|${isSolo()}`; + for (const child of toolbar.children) key += '|' + child.offsetWidth; + if (key === toolbarKey) return false; + toolbarKey = key; + root.classList.remove('host-cutout-toolbar'); + const box = toolbar.getBoundingClientRect(); + // A solo window's title shares the row and has nothing else to stop it at the housing. + const needs = isSolo() || (box.width > 0 && box.left < current.left + current.width + GAP); + root.classList.toggle('host-cutout-toolbar', needs); + return needs !== had; + } + /** The tab strip measures the toolbar (wrap, the L-shaped corner), and the lineage lines follow the tabs. */ function relayout() { - window.app?.updateTabOverflowMode?.(); + if (typeof window.app?.updateTabOverflowMode === 'function') window.app.updateTabOverflowMode(); + else fitTabs(); window.app?.updateConnectionLines?.(); } + // ---------------------------------------------------------------- keeping it current + + let sizes = null; + let children = null; + let frame = 0; + + /** A size changed with no render behind it (a tab selected, renamed or hovered, a reading arriving). */ + function schedule() { + if (frame || !current) return; + // Not in the observer's own callback: a tab that wraps makes the strip taller, and a size changed there + // is reported as a ResizeObserver loop. + frame = requestAnimationFrame(() => { + frame = 0; + if (!current) return; + if (fitToolbar()) relayout(); + else if (fitTabs()) window.app?.updateConnectionLines?.(); + }); + } + + function watch() { + sizes?.disconnect(); + children?.disconnect(); + if (!current || typeof ResizeObserver !== 'function') return; + const strip = document.getElementById('sessionTabs'); + const toolbar = document.getElementById('headerRight'); + if (!strip) return; + sizes ??= new ResizeObserver(schedule); + // Tabs come and go, and so do the toolbar's readings: watch the new ones too. + children ??= new MutationObserver(() => { + watch(); + schedule(); + }); + // The border box: a tab that only gains padding moves its neighbours just the same. + const box = { box: 'border-box' }; + sizes.observe(strip, box); + for (const tab of strip.querySelectorAll('.session-tab')) sizes.observe(tab, box); + children.observe(strip, { childList: true }); + if (toolbar) { + sizes.observe(toolbar, box); + for (const child of toolbar.children) sizes.observe(child, box); + children.observe(toolbar, { childList: true }); + } + if (!strip.dataset.hostCutoutScroll) { + // A strip past its max-height scrolls its rows up beside the housing. + strip.dataset.hostCutoutScroll = '1'; + strip.addEventListener('scroll', schedule, { passive: true }); + } + } + /** * Lay the header out around `cutout`, or (null, or anything that is not a rectangle) as if there were none. * Returns true, so a caller can tell that the page took it. @@ -108,14 +283,47 @@ root.style.removeProperty('--host-cutout-width'); root.style.removeProperty('--host-cutout-height'); } + toolbarKey = null; + fitToolbar(); + watch(); relayout(); return true; } + // ---------------------------------------------------------------- the option's switch + + /** What the app said its option is: `{ available, enabled }`, or null outside the app. */ + let option = null; + + /** Called by the app on every page load and whenever the option changes, from its menu or from a page. */ + function setOption(state) { + option = + state && typeof state === 'object' + ? { available: state.available === true, enabled: state.enabled === true } + : null; + window.app?.syncHostWholeScreenSetting?.(); + return true; + } + + /** Turns the option on or off in the app. False when there is no app to tell. */ + function setWholeScreen(on) { + try { + if (typeof window.CodemanHost?.setWholeScreen !== 'function') return false; + return window.CodemanHost.setWholeScreen(on === true) !== false; + } catch { + return false; + } + } + window.CodemanHostCutout = { apply, normalize, fits, + fitTabs, + option: setOption, + /** The app's option as it stands (`{ available, enabled }`), or null where there is none. */ + wholeScreen: () => option, + setWholeScreen, /** The housing the header is laid out around right now, or null. */ current: () => current, }; @@ -129,4 +337,14 @@ attributeFilter: ['data-tab-arrangement', 'data-session-list', 'data-tab-orientation'], }); } + // The app can answer before the header exists: measure it once it does. + if (typeof document.addEventListener === 'function') { + document.addEventListener('DOMContentLoaded', () => { + if (!current) return; + toolbarKey = null; + fitToolbar(); + watch(); + relayout(); + }); + } })(); diff --git a/src/web/public/i18n.js b/src/web/public/i18n.js index 5b768a14..3d92a53d 100644 --- a/src/web/public/i18n.js +++ b/src/web/public/i18n.js @@ -498,6 +498,10 @@ '会话列表显示为顶栏横向标签条,或左侧可折叠侧边栏(Alt+B)。完整侧边栏为每个会话显示与主界面相同的详细信息。', 'Tall Tabs (Name + Folder)': '双行标签(名称 + 文件夹)', 'Pop-out Button on Tabs': '标签页弹出窗口按钮', + 'Mac App': 'Mac 应用', + 'Full Screen Uses the Area Beside the Camera': '全屏使用摄像头两侧的区域', + 'Full screen covers the whole display, and the tabs and toolbar sit beside the camera. Off uses the full screen of macOS, which leaves a black bar across the top.': + '全屏覆盖整个显示屏,标签页和工具栏位于摄像头两侧。关闭后使用 macOS 自带的全屏,顶部会留下一条黑边。', 'New Session Button on Tabs': '标签页新建会话按钮', 'A + on the tab that starts a session in the same case and group, in any installed CLI.': '标签页上的 + 按钮,可在同一案例和分组中,用任一已安装的 CLI 启动新会话。', diff --git a/src/web/public/index.html b/src/web/public/index.html index 8d93b2ad..b6c6d444 100644 --- a/src/web/public/index.html +++ b/src/web/public/index.html @@ -2605,6 +2605,21 @@ + + +