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

+259
View File
@@ -0,0 +1,259 @@
/**
* @fileoverview Real-Chromium coverage for the header beside a camera housing (host-cutout.js and the
* `html.host-cutout` rules in styles.css).
*
* Codeman Desktop can draw the page behind the notch of a MacBook display, and whatever the header puts there
* cannot be seen or clicked. What only a real layout engine answers: that no tab, button or reading ends up
* behind the housing, in a single row, in a wrapped (L-shaped) strip and with a toolbar too wide for the room
* beside it, and that taking the housing away puts the header back exactly. The real `<header>` from
* index.html, the shipping styles.css, constants.js, app.js and host-cutout.js are loaded into a page.
*
* Port: none (page.route on a fake origin, no server).
*/
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { chromium, type Browser, type Page } from 'playwright';
const dir = resolve(import.meta.dirname, '../src/web/public');
const read = (name: string) => readFileSync(resolve(dir, name), 'utf8');
const styles = read('styles.css');
const header = /<header class="header">[\s\S]*?<\/header>/.exec(read('index.html'))![0];
const ORIGIN = 'http://app.test/';
type Rect = { left: number; right: number; top: number; bottom: number };
type Cutout = { left: number; width: number; height: number };
/** MacBook displays in whole-screen mode: viewport and housing, in points. */
const DISPLAYS: Array<{ name: string; width: number; height: number; cutout: Cutout }> = [
{ name: '14-inch, default', width: 1512, height: 982, cutout: { left: 663.5, width: 185, height: 32 } },
{ name: '16-inch, default', width: 1728, height: 1117, cutout: { left: 771.5, width: 185, height: 32 } },
{ name: '14-inch, more space', width: 1800, height: 1169, cutout: { left: 790, width: 220, height: 38 } },
{ name: '14-inch, larger text', width: 1147, height: 745, cutout: { left: 503.5, width: 140, height: 24 } },
];
const MBP14 = DISPLAYS[0];
describe('header beside a camera housing (real Chromium)', () => {
let browser: Browser;
let p: Page;
beforeAll(async () => {
browser = await chromium.launch();
});
afterAll(async () => {
await browser.close();
});
/** Open the real header at a display's size with `tabs` classic tabs. */
async function open(options: { tabs: number; width: number; height: number; attrs?: string }) {
p = await browser.newPage({
viewport: { width: options.width, height: options.height },
deviceScaleFactor: 1,
});
await p.route(ORIGIN, (route) =>
route.fulfill({
contentType: 'text/html',
body:
'<!doctype html><html data-header-stats="compact" data-tab-orientation="horizontal" ' +
`data-session-list="header" data-tab-arrangement="classic" ${options.attrs ?? ''}>` +
`<head><style>${styles}</style></head><body>${header}</body></html>`,
})
);
await p.goto(ORIGIN);
await p.addScriptTag({
content:
'var MobileDetection = { isTouchDevice: () => false, getDeviceType: () => "desktop" }, KeyboardHandler = {}, ' +
'SwipeHandler = {}, VoiceInput = {}, DeepgramProvider = {}, NotificationManager = function(){};\n' +
read('constants.js') +
'\n' +
read('app.js') +
'\nwindow.CodemanApp = CodemanApp;',
});
await p.evaluate(
({ tabs }) => {
const w = window as any;
const app = Object.create(w.CodemanApp.prototype);
app.$ = (id: string) => document.getElementById(id);
app.sessions = new Map();
app.loadAppSettingsFromStorage = () => ({});
app.getDefaultSettings = () => ({});
app.isSessionSidebarActive = () => false;
app.updateConnectionLines = () => undefined;
const strip = document.getElementById('sessionTabs')!;
for (let i = 1; i <= tabs; i++) {
const id = `s${i}`;
app.sessions.set(id, { id, name: `session-${i}` });
strip.insertAdjacentHTML(
'beforeend',
`<div class="session-tab" data-id="${id}" role="tab"><span class="tab-name">session-${i}</span></div>`
);
}
// The module asks `window.app` to measure the toolbar again, as the page does.
w.app = app;
},
{ tabs: options.tabs }
);
await p.addScriptTag({ content: read('host-cutout.js') });
await relayout();
}
const settled = () => p.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
const relayout = async () => {
await p.evaluate(() => (window as any).app.updateTabOverflowMode());
await settled();
};
const apply = async (cutout: Cutout | null) => {
expect(await p.evaluate((c) => (window as any).CodemanHostCutout.apply(c), cutout)).toBe(true);
await settled();
};
const toolbar = () =>
p.evaluate(() => document.getElementById('headerRight')!.getBoundingClientRect().toJSON()) as Promise<Rect>;
const cornered = () => p.evaluate(() => document.getElementById('sessionTabs')!.classList.contains('tabs-corner'));
/** Everything the header row paints: tabs, the brand, the toolbar's controls. */
const painted = () =>
p.evaluate(() => {
const strip = document.getElementById('sessionTabs')!.getBoundingClientRect();
const shown = (el: Element) => {
const s = getComputedStyle(el);
const r = el.getBoundingClientRect();
return s.display !== 'none' && s.visibility !== 'hidden' && r.width > 0 && r.height > 0;
};
const out: Array<{ what: string; left: number; right: number; top: number; bottom: number }> = [];
for (const el of document.querySelectorAll('#sessionTabs > .session-tab')) {
const r = el.getBoundingClientRect();
// The strip clips what it scrolls or overflows.
const box = {
left: Math.max(r.left, strip.left),
right: Math.min(r.right, strip.right),
top: Math.max(r.top, strip.top),
bottom: Math.min(r.bottom, strip.bottom),
};
if (box.right > box.left && box.bottom > box.top)
out.push({ what: 'tab ' + el.getAttribute('data-id'), ...box });
}
for (const el of document.querySelectorAll('#headerRight > *, .header-brand .logo')) {
if (!shown(el) || el.classList.contains('header-divider')) continue;
const r = el.getBoundingClientRect();
out.push({
what: el.id || el.className.toString().slice(0, 40),
left: r.left,
right: r.right,
top: r.top,
bottom: r.bottom,
});
}
return out;
});
/** What is painted behind the housing, or closer to it than `margin` px. */
const behind = async (cutout: Cutout, margin = 4) =>
(await painted()).filter(
(r) => r.top < cutout.height && r.right > cutout.left - margin && r.left < cutout.left + cutout.width + margin
);
for (const display of DISPLAYS) {
it(`keeps one row of tabs and the toolbar clear of the housing (${display.name})`, async () => {
await open({ tabs: 3, width: display.width, height: display.height });
await apply(display.cutout);
expect(await behind(display.cutout)).toEqual([]);
const box = await toolbar();
// The toolbar's box starts just left of the housing, so the tab strip ends there...
expect(box.left).toBeLessThanOrEqual(display.cutout.left);
expect(box.left).toBeGreaterThan(display.cutout.left - 16);
// ...and still ends where the header's padding begins.
expect(Math.round(display.width - box.right)).toBe(12);
await p.close();
});
it(`keeps a wrapped strip clear of the housing, and its later rows full width (${display.name})`, async () => {
await open({ tabs: 34, width: display.width, height: display.height });
await apply(display.cutout);
expect(await cornered()).toBe(true);
expect(await behind(display.cutout)).toEqual([]);
const box = await toolbar();
const tabs = (await painted()).filter((r) => r.what.startsWith('tab '));
const beside = tabs.filter((t) => t.top < box.bottom);
const below = tabs.filter((t) => t.top >= box.bottom);
// The rows beside the toolbar's box stop at the housing; the rows below it run on past the housing.
expect(beside.length).toBeGreaterThan(0);
expect(Math.max(...beside.map((t) => t.right))).toBeLessThan(display.cutout.left);
expect(Math.max(...below.map((t) => t.right))).toBeGreaterThan(display.cutout.left + display.cutout.width);
await p.close();
});
}
it('keeps a strip that is too tall for the corner left of the housing altogether', async () => {
// Past its max-height the strip scrolls and keeps the plain wrap (_syncTabStripCorner): every row then
// ends where the toolbar's box begins, which is the housing's left edge.
const display = DISPLAYS[3];
await open({ tabs: 40, width: display.width, height: display.height });
await apply(display.cutout);
expect(await cornered()).toBe(false);
expect(await behind(display.cutout)).toEqual([]);
const tabs = (await painted()).filter((r) => r.what.startsWith('tab '));
expect(Math.max(...tabs.map((t) => t.right))).toBeLessThan(display.cutout.left);
await p.close();
});
it('wraps a toolbar that is wider than the room beside the housing, below the housing', async () => {
await open({ tabs: 3, width: MBP14.width, height: MBP14.height });
// A toolbar full of readings: wider than the 660 px right of the housing.
await p.evaluate(() => {
const right = document.getElementById('headerRight')!;
for (let i = 0; i < 9; i++) {
const reading = document.createElement('div');
reading.className = 'test-reading';
reading.style.cssText = 'flex:0 0 auto;width:110px;height:24px;background:#345';
right.appendChild(reading);
}
});
await relayout();
const before = await toolbar();
await apply(MBP14.cutout);
const after = await toolbar();
expect(after.bottom - after.top).toBeGreaterThan(before.bottom - before.top + 16);
expect(await behind(MBP14.cutout)).toEqual([]);
// Nothing is cut off either: every control is inside the viewport.
for (const r of await painted()) expect(r.left, r.what).toBeGreaterThanOrEqual(0);
await p.close();
});
it('puts the header back exactly when the housing is gone', async () => {
await open({ tabs: 40, width: MBP14.width, height: MBP14.height });
const before = { toolbar: await toolbar(), painted: await painted() };
await apply(MBP14.cutout);
expect(await toolbar()).not.toEqual(before.toolbar);
await apply(null);
expect(await toolbar()).toEqual(before.toolbar);
expect(await painted()).toEqual(before.painted);
expect(await p.evaluate(() => document.documentElement.getAttribute('style') || '')).not.toContain('host-cutout');
await p.close();
});
it('sets aside a toolbar width the user chose while the housing is there', async () => {
await open({
tabs: 3,
width: MBP14.width,
height: MBP14.height,
attrs: 'data-header-right-width="set" style="--header-right-width: 300px"',
});
const chosen = await toolbar();
expect(Math.round(chosen.right - chosen.left)).toBe(300);
await apply(MBP14.cutout);
// 300 px would end the toolbar right of the housing and let the tabs run behind it.
expect((await toolbar()).left).toBeLessThanOrEqual(MBP14.cutout.left);
expect(await behind(MBP14.cutout)).toEqual([]);
await apply(null);
expect(await toolbar()).toEqual(chosen);
await p.close();
});
it('keeps the toolbar right of the housing where the header has no tabs (sidebar, rail, solo window)', async () => {
await open({ tabs: 0, width: MBP14.width, height: MBP14.height });
await apply(MBP14.cutout);
expect(await behind(MBP14.cutout)).toEqual([]);
expect((await toolbar()).left).toBeLessThanOrEqual(MBP14.cutout.left);
await p.close();
});
});
+295
View File
@@ -0,0 +1,295 @@
/**
* @fileoverview The camera housing module (host-cutout.js): what counts as a housing, when the page tells a
* native wrapper that it may be drawn behind one, what `apply` writes, and that the page, the build and the
* stylesheet carry it. The layout itself is measured in real Chromium (host-cutout.browser.test.ts).
*/
import { describe, expect, it } from 'vitest';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import vm from 'node:vm';
const publicDir = resolve(import.meta.dirname, '../src/web/public');
const read = (name: string) => readFileSync(resolve(publicDir, name), 'utf8');
const buildJs = readFileSync(resolve(import.meta.dirname, '../scripts/build.mjs'), 'utf8');
const shim = readFileSync(resolve(import.meta.dirname, '../packages/desktop/src/assets.rs'), 'utf8');
type Cutout = { left: number; width: number; height: number };
type Api = {
apply: (cutout: unknown) => boolean;
normalize: (cutout: unknown) => Cutout | null;
fits: () => boolean;
current: () => Cutout | null;
};
/** A 14-inch MacBook Pro at its default scaling. */
const MBP14: Cutout = { left: 663.5, width: 185, height: 32 };
/**
* Run the module in a page that has `dataset` on <html> and, with `host`, the bridge Codeman Desktop injects.
* Returns the module, what it told the bridge, the root's style and classes, and how to change the layout.
*/
function load(options: { dataset?: Record<string, string>; host?: boolean; pathname?: string; solo?: string } = {}) {
const calls: unknown[] = [];
const relayouts: string[] = [];
const props = new Map<string, string>();
const classes = new Set<string>();
const dataset: Record<string, string> = {
sessionList: 'header',
tabOrientation: 'horizontal',
tabArrangement: 'classic',
...options.dataset,
};
let observer: (() => void) | null = null;
const documentElement = {
dataset,
style: {
setProperty: (name: string, value: string) => props.set(name, value),
removeProperty: (name: string) => props.delete(name),
},
classList: {
add: (name: string) => classes.add(name),
remove: (name: string) => classes.delete(name),
},
};
const window: Record<string, unknown> = {
app: {
updateTabOverflowMode: () => relayouts.push('tabs'),
updateConnectionLines: () => relayouts.push('lines'),
},
};
if (options.solo !== undefined) window.__CODEMAN_SOLO__ = options.solo;
if (options.host !== false) window.CodemanHost = { cutoutReady: (ready: unknown) => calls.push(ready) };
const context = vm.createContext({
window,
document: { documentElement },
location: { pathname: options.pathname ?? '/' },
MutationObserver: class {
constructor(callback: () => void) {
observer = callback;
}
observe(target: unknown, init: { attributeFilter: string[] }) {
expect(target).toBe(documentElement);
expect(init.attributeFilter).toEqual(['data-tab-arrangement', 'data-session-list', 'data-tab-orientation']);
}
},
});
vm.runInContext(read('host-cutout.js'), context, { filename: 'host-cutout.js' });
return {
api: window.CodemanHostCutout as Api,
calls,
relayouts,
props,
classes,
/** Change the layout the way the settings do, and let the observer see it. */
setLayout(change: Record<string, string>) {
Object.assign(dataset, change);
observer?.();
},
};
}
describe('camera housing: what counts as one', () => {
it('takes three finite, positive numbers', () => {
const { api } = load();
expect(api.normalize(MBP14)).toEqual(MBP14);
expect(api.normalize({ left: '663.5', width: '185', height: '32' })).toEqual(MBP14);
expect(api.normalize({ left: 0, width: 200, height: 38 })).toEqual({ left: 0, width: 200, height: 38 });
});
it('refuses anything else, so a bad message can never empty the header', () => {
const { api } = load();
for (const bad of [
null,
undefined,
'notch',
42,
{},
{ left: 663 },
{ left: NaN, width: 185, height: 32 },
{ left: 663, width: Infinity, height: 32 },
{ left: -1, width: 185, height: 32 },
{ left: 663, width: 0, height: 32 },
{ left: 663, width: 185, height: 0 },
{ left: 663, width: 185, height: 900 },
]) {
expect(api.normalize(bad), JSON.stringify(bad)).toBeNull();
}
});
});
describe('camera housing: laying the header out around it', () => {
it('writes the housing to <html> and has the tab strip measure the toolbar again', () => {
const page = load();
expect(page.api.apply(MBP14)).toBe(true);
expect(Object.fromEntries(page.props)).toEqual({
'--host-cutout-left': '663.5px',
'--host-cutout-width': '185px',
'--host-cutout-height': '32px',
});
expect([...page.classes]).toEqual(['host-cutout']);
expect(page.api.current()).toEqual(MBP14);
expect(page.relayouts).toEqual(['tabs', 'lines']);
});
it('does nothing for the housing it already has', () => {
const page = load();
page.api.apply(MBP14);
page.relayouts.length = 0;
expect(page.api.apply({ ...MBP14 })).toBe(true);
expect(page.relayouts).toEqual([]);
});
it('puts everything back when the housing is gone', () => {
const page = load();
page.api.apply(MBP14);
page.relayouts.length = 0;
expect(page.api.apply(null)).toBe(true);
expect(page.props.size).toBe(0);
expect(page.classes.size).toBe(0);
expect(page.api.current()).toBeNull();
expect(page.relayouts).toEqual(['tabs', 'lines']);
});
it('treats a housing that is not a rectangle as none', () => {
const page = load();
page.api.apply(MBP14);
page.api.apply({ left: 663, width: -4, height: 32 });
expect(page.classes.size).toBe(0);
expect(page.props.size).toBe(0);
});
it('follows the housing to another display', () => {
const page = load();
page.api.apply(MBP14);
page.api.apply({ left: 771.5, width: 185, height: 32 });
expect(page.props.get('--host-cutout-left')).toBe('771.5px');
expect([...page.classes]).toEqual(['host-cutout']);
});
it('works before the app exists (the module runs in <head>)', () => {
const calls: unknown[] = [];
const props = new Map<string, string>();
const window: Record<string, unknown> = { CodemanHost: { cutoutReady: (r: unknown) => calls.push(r) } };
const context = vm.createContext({
window,
document: {
documentElement: {
dataset: {},
style: { setProperty: (n: string, v: string) => props.set(n, v), removeProperty: () => {} },
classList: { add: () => {}, remove: () => {} },
},
},
location: { pathname: '/' },
});
vm.runInContext(read('host-cutout.js'), context, { filename: 'host-cutout.js' });
expect(calls).toEqual([true]);
expect((window.CodemanHostCutout as Api).apply(MBP14)).toBe(true);
expect(props.get('--host-cutout-width')).toBe('185px');
});
});
describe('camera housing: telling the app whether the page may be drawn behind it', () => {
it('says yes once for the classic strip, the sidebar and the rail', () => {
expect(load().calls).toEqual([true]);
expect(load({ dataset: { sessionList: 'sidebar' } }).calls).toEqual([true]);
expect(load({ dataset: { tabOrientation: 'vertical' } }).calls).toEqual([true]);
});
it('says no while the tabs are grouped in the header strip', () => {
for (const tabArrangement of ['state', 'case', 'ledger']) {
const page = load({ dataset: { tabArrangement } });
expect(page.calls, tabArrangement).toEqual([false]);
expect(page.api.fits()).toBe(false);
}
});
it('says yes for grouped tabs that are not in the header', () => {
expect(load({ dataset: { tabArrangement: 'state', sessionList: 'sidebar' } }).calls).toEqual([true]);
expect(load({ dataset: { tabArrangement: 'ledger', tabOrientation: 'vertical' } }).calls).toEqual([true]);
});
it('says yes in a solo window, which has no tab strip, under any base path', () => {
expect(load({ dataset: { tabArrangement: 'state' }, pathname: '/session/abc' }).calls).toEqual([true]);
expect(load({ dataset: { tabArrangement: 'state' }, pathname: '/codeman/session/abc/' }).calls).toEqual([true]);
expect(load({ dataset: { tabArrangement: 'state' }, solo: 'abc' }).calls).toEqual([true]);
// A dashboard URL that only mentions the word is not one.
expect(load({ dataset: { tabArrangement: 'state' }, pathname: '/session/' }).calls).toEqual([false]);
});
it('says so again when the layout changes, and only then', () => {
const page = load();
page.setLayout({ tabArrangement: 'classic' });
expect(page.calls).toEqual([true]);
page.setLayout({ tabArrangement: 'state' });
page.setLayout({ tabArrangement: 'case' });
expect(page.calls).toEqual([true, false]);
page.setLayout({ tabOrientation: 'vertical' });
expect(page.calls).toEqual([true, false, true]);
});
it('drops the layout at once when it stops fitting, without waiting for the app', () => {
const page = load();
page.api.apply(MBP14);
page.setLayout({ tabArrangement: 'state' });
expect(page.classes.size).toBe(0);
expect(page.props.size).toBe(0);
expect(page.api.current()).toBeNull();
});
it('ignores a housing the app sent before it heard the no', () => {
const page = load({ dataset: { tabArrangement: 'ledger' } });
expect(page.api.apply(MBP14)).toBe(true);
expect(page.classes.size).toBe(0);
expect(page.api.current()).toBeNull();
});
it('is silent in a browser tab, where nothing is ever drawn behind a housing', () => {
const page = load({ host: false });
expect(page.calls).toEqual([]);
expect(page.classes.size).toBe(0);
expect(typeof page.api.apply).toBe('function');
});
});
describe('camera housing: wiring', () => {
const html = read('index.html');
const css = read('styles.css');
it('loads in <head>, not deferred, after the layout attributes are written', () => {
const tag = '<script src="host-cutout.js"></script>';
const at = html.indexOf(tag);
expect(at).toBeGreaterThan(-1);
expect(at).toBeLessThan(html.indexOf('</head>'));
// The pre-paint script that writes data-tab-arrangement and its two siblings comes first: `fits()` reads them.
expect(at).toBeGreaterThan(html.indexOf('document.documentElement.dataset.tabArrangement='));
expect(html).not.toContain('<script defer src="host-cutout.js">');
});
it('is minified and content-hashed by the build', () => {
expect(buildJs).toContain("run('minify host-cutout.js'");
expect(buildJs).toMatch(/HASHABLE[\s\S]{0,1500}'host-cutout\.js'/);
});
it('speaks the bridge Codeman Desktop injects', () => {
// packages/desktop/src/assets.rs (HOST_SHIM) and policy.rs (RawHost::CutoutReady).
expect(shim).toContain("cutoutReady: function (ready) { post({ cmd: 'cutoutReady', ready: ready !== false }); }");
expect(read('host-cutout.js')).toContain('window.CodemanHost.cutoutReady(ready)');
});
it('lays the toolbar out from the housing in every desktop layout', () => {
const rule = /html\.host-cutout \.header > \.header-right \{([^}]*)\}/.exec(css)?.[1] ?? '';
expect(rule).toContain('width: calc(100vw - 0.75rem - var(--host-cutout-left) + var(--host-cutout-gap));');
expect(rule).toContain('padding-left: calc(var(--host-cutout-width) + 2 * var(--host-cutout-gap));');
expect(rule).toContain('flex-wrap: wrap;');
expect(rule).toContain('box-sizing: border-box;');
// 0.75rem is the header's own side padding: the two must change together.
expect(/\n\.header \{[^}]*padding: 0\.35rem 0\.75rem;/.test(css)).toBe(true);
});
it('wins over a toolbar width the user chose, and hides the handle that sets it', () => {
expect(css).toMatch(
/html\[data-header-right-width\]:not\(\.host-cutout\):not\(\[data-tab-orientation='vertical'\]\)/
);
expect(css).toMatch(/html\.host-cutout \.header-divider \{\s*display: none;/);
});
});