feat(desktop): full screen over the whole display, the strip beside the camera included

On a MacBook with a camera housing (the notch), macOS's full screen ends the
window below the housing and paints the strip beside it black. No setting
changes that, so the Mac app gets a second kind of full screen, off by default:
View > Full Screen Uses the Area Beside the Camera.

The app (packages/desktop/src/whole_screen.rs):
- The window loses its title bar, the Dock and the menu bar auto-hide, and the
  window gets the display's whole frame, which reaches behind the housing.
- An override of toggleFullScreen: on tao's window class decides per request,
  so the green button, the menu item, its shortcut and the launch into full
  screen all follow the option. It only applies on a display with a housing.
- performClose: asks the delegate while the window has no close button.
- Changes into and out of macOS's own full screen are tracked from AppKit's
  notifications: while one is under way the window is not restyled and its
  frame is not saved. The Dock and menu-bar options are reconciled, so what a
  native Space in front kept from being set or taken off is done afterwards.
- Info.plist: NSPrefersDisplaySafeAreaCompatibilityMode = false.

The page (src/web/public/host-cutout.js, styles.css):
- A page is drawn behind the housing only after it said it copes
  (CodemanHost.cutoutReady); the app answers with where the housing is, and
  the toolbar's box starts left of it and pads its content past it, so the
  tabs end before the housing and the toolbar begins after it.
- Until then the web view stays below the housing with a black strip above it,
  which is what full screen looked like before: an older server, the connect
  page and a raw file are unchanged.
- With the tabs grouped by state, by case or as a ledger in the header strip
  the page says no: ending every row at the housing costs more height than the
  strip gives.

Not yet seen on a MacBook with a housing: the AppKit path was type-checked,
unit-tested where it is pure and reviewed, on a Mac mini without one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-11-24 10:36:56 +01:00
1 parent 5548c17c4a
commit d5ddf2e250
19 files changed
+2493 -36

No files matched your search

+6 -2
View File
@@ -36,18 +36,21 @@ security-framework = "3"
# through wry and tao, so no new crate is added.
libc = "0.2"
# JavaScript dialogs, HTTP Basic challenges, clearing cookies and the window's
# content size (src/macos.rs). The versions wry already pulls in, so no new
# crate is added.
# content size (src/macos.rs), and full screen over the whole display
# (src/whole_screen.rs). The versions wry already pulls in, so no new crate is
# added.
objc2 = { version = "0.6.5", default-features = false, features = ["std"] }
block2 = { version = "0.6.2", default-features = false, features = ["std"] }
objc2-foundation = { version = "0.3.2", default-features = false, features = [
"std",
"objc2-core-foundation",
"block2",
"NSArray",
"NSBundle",
"NSDate",
"NSDictionary",
"NSGeometry",
"NSNotification",
"NSObject",
"NSOperation",
"NSProcessInfo",
@@ -71,6 +74,7 @@ objc2-app-kit = { version = "0.3.2", default-features = false, features = [
"NSButton",
"NSControl",
"NSResponder",
"NSScreen",
"NSTextField",
"NSView",
"NSWindow",
+66 -1
View File
@@ -34,7 +34,7 @@ cannot do.
| **Start Codeman** | On the This Mac tab, and when `http://127.0.0.1:<port>` or `http://localhost:<port>` 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. |
| **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. |
| **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). |
@@ -274,6 +274,51 @@ address. So the app looks for running Codeman servers of this user (`ps`)
before it offers or runs a start, and offers to connect to the ones it finds
instead (`found_addresses` in `src/setup.rs`, unit-tested).
**Full screen over the whole display is the app's own, not macOS's.** A native
full-screen Space never reaches behind a MacBook's camera housing: the system
ends the window below it and paints the strip beside it black, and no setting
changes that. What reaches it is the older kind of full screen, the one
terminals offer for the same reason (Ghostty's `macos-non-native-fullscreen`,
WezTerm's `macos_fullscreen_extend_behind_notch`, iTerm2's and kitty's
traditional full screen): the window loses its title bar, the Dock and the menu
bar auto-hide, and the window gets the display's whole frame
(`src/whole_screen.rs`). Every request for full screen ends in
`-[NSWindow toggleFullScreen:]`, so the app adds an override of that one method
to tao's window class and decides there, which is what makes the green button
and the menu item follow the option without the app owning either. One more
override keeps a window without a title bar usable: `⌘W` asks to close as the
close button would (AppKit's version only beeps without one). The two kinds of
full screen never overlap: AppKit says when a window begins and ends a change
into or out of its own full screen, and while one is under way the app neither
takes the title bar off nor saves the window's frame, so switching the option
while the window is in macOS's full screen waits for the Space to close first.
The Dock and the menu bar are set to auto-hide only while a window is in this
mode, and what could not be set or taken off because a native Space was in
front is done when that changes.
`NSPrefersDisplaySafeAreaCompatibilityMode` is `false` in `Info.plist`, which
tells macOS that the app handles the housing itself; without it the system may
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.
**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
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
shell may say it (`policy::parse_ipc`), so a rendered HTML file or a web tab
cannot get the page drawn behind the camera.
**Closing the main window quits the app.** Codeman's sessions keep running on
the server, so nothing is lost, and reopening takes about a second.
@@ -479,6 +524,26 @@ crosses, so the login is never on a command line.
built-in display's brightness when the lid opens again, and an Apple display
with its own light sensor. If the logo does not move under a closed lid, the
menu line says "stayed dark".
- **Full screen over the whole display has not been seen on a real MacBook
yet** (as of this change). The decisions, the menu, the page's layout around
the housing and every AppKit fact the overrides rest on were checked (the
page in Chromium at the sizes of the 14 and 16 inch displays, the rest on a
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.
- **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.
- **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
+8
View File
@@ -31,6 +31,14 @@
<true/>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<!-- The app handles the camera housing of a MacBook display itself
(src/whole_screen.rs): its full screen can cover the whole display,
and nothing is drawn behind the housing. Without this key macOS may
shrink the display's active area ("compatibility mode") as soon as a
window reaches behind the housing, and Finder's Get Info offers
"Scale to fit below built-in camera". -->
<key>NSPrefersDisplaySafeAreaCompatibilityMode</key>
<false/>
<key>NSHumanReadableCopyright</key>
<string>MIT License, Codeman Contributors</string>
<!-- Voice dictation and gesture control ask for these; without the
+7 -1
View File
@@ -59,6 +59,10 @@ pub fn respond(request: Request<Vec<u8>>) -> Response<Cow<'static, [u8]>> {
/// server restarted, and nothing in the page asks for the login again.
/// - defines `__codemanDesktopRefused(id)` (not enumerable) for
/// [`refused_script`].
/// - `cutoutReady(ready)` lets Codeman's page say whether it keeps its
/// 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.
pub const HOST_SHIM: &str = r#"(function () {
'use strict';
if (!/^https?:$/.test(location.protocol) || window.CodemanHost) return;
@@ -88,7 +92,8 @@ pub const HOST_SHIM: &str = r#"(function () {
return u && u.href.length <= MAX_URL ? post({ cmd: 'openWindow', url: u.href }) : false;
},
closeWindow: function () { post({ cmd: 'closeWindow' }); },
focusWindow: function () { post({ cmd: 'focusWindow' }); }
focusWindow: function () { post({ cmd: 'focusWindow' }); },
cutoutReady: function (ready) { post({ cmd: 'cutoutReady', ready: ready !== false }); }
})
});
@@ -273,6 +278,7 @@ mod tests {
"openWindow",
"closeWindow",
"focusWindow",
"cutoutReady",
"__codemanDesktopRefused",
"sessionExpired",
"'auxclick'",
+15
View File
@@ -45,6 +45,9 @@ pub struct Config {
pub auto_connect: bool,
/// 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).
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
/// value this version does not know reads as off: a bad style must not make
@@ -80,6 +83,7 @@ impl Default for Config {
servers: Vec::new(),
auto_connect: true,
start_fullscreen: false,
whole_screen: false,
logo_blink: BlinkStyles::default(),
keep_awake: keep_awake::Settings::default(),
window: None,
@@ -470,6 +474,16 @@ mod tests {
assert_eq!(c.keep_awake, Settings::default());
}
#[test]
fn full_screen_over_the_whole_display_is_off_until_chosen() {
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);
}
#[test]
fn the_style_a_mac_saved_before_there_were_states_is_kept() {
use crate::logo::BlinkStyle;
@@ -486,6 +500,7 @@ mod tests {
assert!(c.remember("http://127.0.0.1:3000/", None, false).is_empty());
assert!(c.remember("https://box.ts.net/", Some("admin"), true).is_empty());
c.start_fullscreen = true;
c.whole_screen = true;
c.window = Some(WindowFrame {
x: 10.0,
y: 20.0,
+174 -23
View File
@@ -5,7 +5,9 @@
//! browser tab cannot: a connect screen that remembers servers (`config`,
//! `login`), runs or installs Codeman on this machine (`setup`,
//! `local_server`, `gui_install`) and installs it on another one over SSH
//! (`terminal_install`), real full screen, native menus (`menu`), pop-outs as
//! (`terminal_install`), real full screen (on a MacBook with a camera
//! housing over the whole display, if asked: `whole_screen`), native menus
//! (`menu`), pop-outs as
//! app windows (Codeman's `window.CodemanHost` bridge), downloads to
//! ~/Downloads, passwords in the Keychain (`credentials`), on macOS the
//! JavaScript dialogs and HTTP Basic challenges wry leaves out (`macos`), and
@@ -41,6 +43,9 @@ mod policy;
mod probe;
mod setup;
mod terminal_install;
// The pure half is only used by the macOS half and the tests.
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
mod whole_screen;
use std::cell::RefCell;
use std::collections::{HashMap, VecDeque};
@@ -198,6 +203,14 @@ enum UserEvent {
OldHelperRemoved(keep_awake::AdminOutcome),
/// What the closed lid did with the logo last (logo::watch_lid_status).
LogoLidStatus(String),
/// A window entered or left full screen over the whole display
/// (whole_screen.rs), named by `whole_screen::window_key`. The green
/// button and the menu item ask AppKit, not the app, so this is how the
/// app hears of it.
#[cfg(target_os = "macos")]
WholeScreenChanged {
window: usize,
},
}
struct ProbeDone {
@@ -329,8 +342,11 @@ struct App {
/// The connect page opens the agent chooser when it next loads: the menu
/// asked for it from a Codeman page.
add_agent_on_load: bool,
/// The main window goes into full screen once the event loop runs.
fullscreen_at_launch: bool,
/// While the main window may still have to be put into the full screen it
/// asked for at launch: when to look next, and how many retries were made.
/// asked for (at launch, or when the kind of full screen was switched):
/// when to look next, and how many retries were made.
fullscreen_retry: Option<(Instant, u8)>,
/// The child that watches the connected server and blinks the logo.
logo_watch: logo::Watcher,
@@ -378,6 +394,15 @@ fn main() {
};
let config_path = config_path.filter(|_| can_save);
let notice = (!can_save).then(|| SETTINGS_UNREADABLE.to_string());
#[cfg(target_os = "macos")]
{
whole_screen::set_enabled(config.whole_screen);
// Runs inside an AppKit callback: only post an event.
let changed_proxy = proxy.clone();
whole_screen::set_change_handler(Box::new(move |window| {
let _ = changed_proxy.send_event(UserEvent::WholeScreenChanged { window });
}));
}
logo::recover_at_launch();
// A lid keeper that was killed left lid sleep off; and 1.50.1's helper, where
// it is still installed, gets nothing to act on.
@@ -393,6 +418,8 @@ fn main() {
create_main_window(&event_loop, &config).unwrap_or_else(|e| fatal(&format!("Could not open a window: {e}")));
let webview = build_webview(&window, true, true, Load::ConnectPage, &proxy, &phase)
.unwrap_or_else(|e| fatal(&format!("Could not create the web view: {e}")));
#[cfg(target_os = "macos")]
whole_screen::install(&window, &webview);
let main_id = window.id();
let mut windows = HashMap::new();
@@ -424,6 +451,7 @@ fn main() {
keychain,
install_reader: Arc::new(AtomicU64::new(0)),
add_agent_on_load: false,
fullscreen_at_launch: wants_fullscreen,
fullscreen_retry: wants_fullscreen.then(|| (Instant::now() + FULLSCREEN_FIRST_CHECK, 0)),
logo_watch: logo::Watcher::default(),
keep_awake: keep_awake::KeepAwake::new(move |generation, text| {
@@ -483,8 +511,12 @@ fn placed_position(window: &Window) -> Result<PhysicalPosition<i32>, NotSupporte
}
}
/// The main window, and whether it was asked into full screen (App's
/// `fullscreen_retry` then makes sure it gets there).
/// The main window, and whether it is to open in full screen. It is built at
/// its windowed frame and put into full screen once the event loop runs
/// (`fullscreen_at_launch`; `fullscreen_retry` then makes sure it gets there),
/// never built into it: a window built straight into full screen gets the
/// whole screen as its frame, and that is the frame AppKit puts back when the
/// user leaves full screen.
fn create_main_window(
target: &EventLoopWindowTarget<UserEvent>,
config: &Config,
@@ -508,17 +540,31 @@ fn create_main_window(
}
}
let window = builder.build(target)?;
// Full screen is entered after the window exists at its windowed frame,
// not set on the builder: a window built straight into full screen gets
// the whole screen as its frame, and that is the frame AppKit puts back
// when the user leaves full screen.
let fullscreen = config.start_fullscreen || config.window.is_some_and(|f| f.fullscreen);
if fullscreen {
window.set_fullscreen(Some(Fullscreen::Borderless(None)));
}
Ok((window, fullscreen))
}
/// Puts `window` into full screen: over the whole display where that applies
/// (whole_screen.rs), macOS's own everywhere else. A window that is still on
/// its way out of macOS's full screen is left alone; the caller asks again.
fn enter_full_screen(window: &Window) {
#[cfg(target_os = "macos")]
match whole_screen::enter(window) {
whole_screen::Entry::Entered | whole_screen::Entry::Busy => return,
whole_screen::Entry::NotWanted => {}
}
window.set_fullscreen(Some(Fullscreen::Borderless(None)));
}
/// Whether `window` is in full screen, of either kind.
fn in_full_screen(window: &Window) -> bool {
#[cfg(target_os = "macos")]
if whole_screen::is_active(window) {
return true;
}
window.fullscreen().is_some()
}
/// The Authorization header for a login, when there is a password.
fn basic_auth(username: Option<&str>, password: Option<&str>) -> Option<String> {
username.zip(password).map(|(u, p)| policy::basic_auth_header(u, p))
@@ -770,6 +816,11 @@ impl App {
self.menu.window_menu.set_as_windows_menu_for_nsapp();
self.menu.help_menu.set_as_help_menu_for_nsapp();
}
if std::mem::take(&mut self.fullscreen_at_launch) {
if let Some(main) = self.windows.get(&self.main_id) {
enter_full_screen(&main.window);
}
}
}
Event::WindowEvent { window_id, event, .. } => self.on_window_event(window_id, event, target, control_flow),
Event::UserEvent(event) => self.on_user_event(event, target),
@@ -824,12 +875,14 @@ impl App {
};
}
/// The main window asked for full screen at launch: if it is not there
/// yet, ask again, a few times at most. tao reports a window as full
/// screen from the moment it is asked and puts that back only when the
/// entry fails, so `fullscreen()` being None means it failed. Stops once
/// the window is in full screen or minimized, so a user who leaves full
/// screen later is never pulled back.
/// The main window asked for full screen (at launch, or to change the kind
/// it is in): if it is not there yet, ask again, a few times at most. tao
/// reports a window as full screen from the moment it is asked and puts
/// that back only when the entry fails, so `fullscreen()` being None means
/// it failed, or that the window is on its way to the whole display and
/// has to leave macOS's full screen first. Stops once the window is in
/// full screen or minimized, so a user who leaves full screen later is
/// never pulled back.
fn retry_fullscreen(&mut self, now: Instant) {
let Some((_, attempts)) = self.fullscreen_retry else {
return;
@@ -838,10 +891,10 @@ impl App {
let Some(main) = self.windows.get(&self.main_id) else {
return;
};
if main.window.fullscreen().is_some() || main.window.is_minimized() || attempts >= FULLSCREEN_ATTEMPTS {
if in_full_screen(&main.window) || main.window.is_minimized() || attempts >= FULLSCREEN_ATTEMPTS {
return;
}
main.window.set_fullscreen(Some(Fullscreen::Borderless(None)));
enter_full_screen(&main.window);
self.fullscreen_retry = Some((now + FULLSCREEN_RETRY_EVERY, attempts + 1));
}
@@ -875,7 +928,14 @@ impl App {
*control_flow = ControlFlow::Exit;
}
}
WindowEvent::Moved(_) | WindowEvent::Resized(_) if id == self.main_id => self.record_main_frame(),
WindowEvent::Moved(_) | WindowEvent::Resized(_) | WindowEvent::ScaleFactorChanged { .. } => {
// A window over the whole display follows the display it is on.
#[cfg(target_os = "macos")]
self.sync_whole_screen(id);
if id == self.main_id {
self.record_main_frame();
}
}
_ => {}
}
}
@@ -894,6 +954,20 @@ impl App {
}
}
UserEvent::LogoLidStatus(line) => self.show_lid_status(line),
#[cfg(target_os = "macos")]
UserEvent::WholeScreenChanged { window } => {
let id = self
.windows
.iter()
.find(|(_, w)| whole_screen::window_key(&w.window) == window)
.map(|(id, _)| *id);
if let Some(id) = id {
self.sync_whole_screen(id);
if id == self.main_id {
self.record_main_frame();
}
}
}
UserEvent::ServerStartDone {
generation,
url,
@@ -953,6 +1027,15 @@ impl App {
if let Some(w) = self.windows.get_mut(&window) {
w.committed = Url::parse(&url).ok();
}
// A new document has not said that it keeps clear of a camera
// housing: its web view stays below it until it does.
#[cfg(target_os = "macos")]
{
if let Some(w) = self.windows.get(&window) {
whole_screen::set_page_ready(&w.window, false);
}
self.sync_whole_screen(window);
}
}
UserEvent::DownloadStarted { window, url, file_name } => {
// A pop-out opened only to fetch a file would sit empty: hide
@@ -1301,6 +1384,7 @@ 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::DEVTOOLS => {
if let Some(w) = self.focused_window_id().and_then(|id| self.windows.get(&id)) {
w.webview.open_devtools();
@@ -1346,6 +1430,60 @@ impl App {
}
HostCmd::OpenExternal(raw) => self.open_external_raw(&raw),
HostCmd::SessionExpired => self.on_session_expired(window),
HostCmd::CutoutReady(ready) => {
#[cfg(target_os = "macos")]
{
if let Some(w) = self.windows.get(&window) {
whole_screen::set_page_ready(&w.window, ready);
}
self.sync_whole_screen(window);
}
#[cfg(not(target_os = "macos"))]
let _ = ready;
}
}
}
/// 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
/// (`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;
};
self.config.whole_screen = on;
self.config_dirty = true;
#[cfg(target_os = "macos")]
{
whole_screen::set_enabled(on);
let Some(main) = self.windows.get(&self.main_id) else {
return;
};
let window = &main.window;
let whole = whole_screen::is_active(window);
if on && !whole && window.fullscreen().is_some() && whole_screen::applies_to(window) {
window.set_fullscreen(None);
} else if !on && whole {
whole_screen::leave(window);
window.set_fullscreen(Some(Fullscreen::Borderless(None)));
} else {
return;
}
self.fullscreen_retry = Some((Instant::now() + FULLSCREEN_FIRST_CHECK, 0));
}
}
/// 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).
#[cfg(target_os = "macos")]
fn sync_whole_screen(&self, id: WindowId) {
if let Some(w) = self.windows.get(&id) {
if let Some(script) = whole_screen::sync(&w.window) {
let _ = w.webview.evaluate_script(&script);
}
}
}
@@ -1937,6 +2075,8 @@ impl App {
return false;
}
};
#[cfg(target_os = "macos")]
whole_screen::install(&window, &webview);
let kind = Kind::Popout {
opened_url,
hidden_for_download: false,
@@ -1984,6 +2124,10 @@ impl App {
if id == self.main_id {
return;
}
#[cfg(target_os = "macos")]
if let Some(w) = self.windows.get(&id) {
whole_screen::forget(&w.window);
}
self.windows.remove(&id);
self.downloads.retain(|(window, _), _| *window != id);
}
@@ -2016,7 +2160,7 @@ impl App {
return;
};
let w = &main.window;
let fullscreen = w.fullscreen().is_some();
let fullscreen = in_full_screen(w);
let mut frame = self.config.window.unwrap_or(WindowFrame {
x: 0.0,
y: 0.0,
@@ -2025,8 +2169,15 @@ impl App {
fullscreen,
});
// In full screen or minimized the live geometry is not the windowed
// frame; the saved one is kept for the next launch.
if !fullscreen && !w.is_minimized() {
// 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).
#[cfg(target_os = "macos")]
let transitional = whole_screen::in_transition(w);
#[cfg(not(target_os = "macos"))]
let transitional = false;
if !fullscreen && !transitional && !w.is_minimized() {
let sf = w.scale_factor();
if let Ok(pos) = placed_position(w) {
let p = pos.to_logical::<f64>(sf);
+37 -4
View File
@@ -17,6 +17,7 @@ pub mod menu_id {
pub const ADD_AGENT: &str = "add-agent";
pub const RELOAD: &str = "reload";
pub const START_FULLSCREEN: &str = "start-fullscreen";
pub const WHOLE_SCREEN: &str = "whole-screen";
pub const LOGO_BLINK: &str = "logo-blink";
pub const DEVTOOLS: &str = "devtools";
pub const HELP_DOCS: &str = "help-docs";
@@ -28,6 +29,10 @@ pub struct AppMenu {
pub window_menu: Submenu,
pub help_menu: Submenu,
pub start_fullscreen: CheckMenuItem,
/// Full screen over the whole display (whole_screen.rs). None on a Mac with
/// no camera housing in sight, where macOS's full screen already uses
/// every pixel.
pub whole_screen: Option<CheckMenuItem>,
/// The one switch for the logo. None on a Mac without a lit logo, which has no
/// such menu.
pub logo_switch: Option<CheckMenuItem>,
@@ -120,6 +125,16 @@ fn build_keep_awake(config: &Config) -> muda::Result<(Submenu, KeepAwakeMenu)> {
))
}
#[cfg(target_os = "macos")]
fn whole_screen_available() -> bool {
crate::whole_screen::available()
}
#[cfg(not(target_os = "macos"))]
fn whole_screen_available() -> bool {
false
}
pub fn build_menu(config: &Config) -> muda::Result<AppMenu> {
let bar = Menu::new();
let about = PredefinedMenuItem::about(
@@ -186,6 +201,18 @@ pub fn build_menu(config: &Config) -> muda::Result<AppMenu> {
config.start_fullscreen,
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(|| {
CheckMenuItem::with_id(
menu_id::WHOLE_SCREEN,
"Full Screen Uses the Area Beside the Camera",
true,
config.whole_screen,
None,
)
});
let view = Submenu::with_items(
"View",
true,
@@ -208,6 +235,11 @@ pub fn build_menu(config: &Config) -> muda::Result<AppMenu> {
),
],
)?;
// Right under "Always Open in Full Screen", before the logo items and the separator.
if let Some(item) = &whole_screen {
view.insert(item, 4)?;
}
let after_full_screen = 4 + usize::from(whole_screen.is_some());
// Only a Mac with a lit Apple logo has these items at all: the switch, and the
// style for each state behind it.
let mut logo_styles = Vec::new();
@@ -235,11 +267,11 @@ pub fn build_menu(config: &Config) -> muda::Result<AppMenu> {
}
submenu.append(&group)?;
}
// Right under "Always Open in Full Screen", before the separator.
// Under the full-screen items, before the separator.
let lid = MenuItem::new(logo::lid_status_line(), false, None);
view.insert(&switch, 4)?;
view.insert(&submenu, 5)?;
view.insert(&lid, 6)?;
view.insert(&switch, after_full_screen)?;
view.insert(&submenu, after_full_screen + 1)?;
view.insert(&lid, after_full_screen + 2)?;
logo_switch = Some(switch);
logo_lid = Some(lid);
}
@@ -269,6 +301,7 @@ pub fn build_menu(config: &Config) -> muda::Result<AppMenu> {
window_menu,
help_menu,
start_fullscreen,
whole_screen,
logo_switch,
logo_styles,
keep_awake,
+52 -2
View File
@@ -585,6 +585,10 @@ pub enum HostCmd {
/// The page got a 401 from its own server: the session cookie is gone (a
/// server restart) and the page cannot recover on its own.
SessionExpired,
/// Whether the page keeps its controls clear of a camera housing when it
/// 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),
}
/// Calls the bundled connect page makes.
@@ -720,11 +724,23 @@ enum RawConnect {
#[derive(Deserialize)]
#[serde(tag = "cmd", rename_all = "camelCase", deny_unknown_fields)]
enum RawHost {
OpenWindow { url: String },
OpenWindow {
url: String,
},
CloseWindow,
FocusWindow,
OpenExternal { url: String },
OpenExternal {
url: String,
},
SessionExpired,
CutoutReady {
#[serde(default = "yes")]
ready: bool,
},
}
fn yes() -> bool {
true
}
/// The shape of a CLI catalogue id. It becomes one argument of `install.sh`,
@@ -821,6 +837,7 @@ pub fn parse_ipc(frame_url: &str, body: &str, phase: &Phase, is_main_window: boo
RawHost::FocusWindow => HostCmd::FocusWindow,
RawHost::OpenExternal { url } if url.len() <= MAX_URL_LEN => HostCmd::OpenExternal(url),
RawHost::SessionExpired => HostCmd::SessionExpired,
RawHost::CutoutReady { ready } => HostCmd::CutoutReady(ready),
_ => return None,
};
Some(Ipc::Host(cmd))
@@ -1536,6 +1553,36 @@ mod tests {
),
Some(Ipc::Host(HostCmd::SessionExpired))
);
// The dashboard and a session pop-out both say when they keep clear
// of a camera housing.
assert_eq!(
parse_ipc(main, r#"{"cmd":"cutoutReady","ready":true}"#, &loaded, true),
Some(Ipc::Host(HostCmd::CutoutReady(true)))
);
assert_eq!(
parse_ipc(
"http://127.0.0.1:3000/session/1",
r#"{"cmd":"cutoutReady","ready":true}"#,
&loaded,
false
),
Some(Ipc::Host(HostCmd::CutoutReady(true)))
);
// A layout that would only lose room behind the housing says no; a
// message without the field is a yes, and a field of another type is
// no message at all.
assert_eq!(
parse_ipc(main, r#"{"cmd":"cutoutReady","ready":false}"#, &loaded, true),
Some(Ipc::Host(HostCmd::CutoutReady(false)))
);
assert_eq!(
parse_ipc(main, r#"{"cmd":"cutoutReady"}"#, &loaded, true),
Some(Ipc::Host(HostCmd::CutoutReady(true)))
);
assert_eq!(
parse_ipc(main, r#"{"cmd":"cutoutReady","ready":"yes"}"#, &loaded, true),
None
);
// Untrusted surfaces, other origins, connect commands: refused.
for frame in [
"http://127.0.0.1:3000/html-view/c/x.html",
@@ -1548,6 +1595,9 @@ mod tests {
] {
assert_eq!(parse_ipc(frame, r#"{"cmd":"focusWindow"}"#, &loaded, true), None);
assert_eq!(parse_ipc(frame, r#"{"cmd":"sessionExpired"}"#, &loaded, true), None);
// 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);
}
assert_eq!(
parse_ipc(main, r#"{"cmd":"startServer","url":"x"}"#, &loaded, true),
File diff suppressed because it is too large. Load diff