App menu: the titlebar logo opens it too, hung under the logo on its side of the window

The logo at the start of the titlebar is now a button (aria-haspopup, keyboard reachable, tooltip) and a second trigger of the same menu: same component and model, only the anchor differs (`openAppMenu({ anchor: 'logo' })`). A submenu opens toward the middle of the window, else on the other side, else over the menu (`submenuLeft`, tested). A click on the logo never starts a window drag; a press that moves more than 5px does (the window's `startDragging`), so the logo still moves the window like the titlebar around it. A right-click shows the window's system menu. Clear of the macOS traffic lights: the logo sits after the titlebar's 78px inset and the menu hangs below it. The button at the end and the account menu's row stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
CRTkafa 2026-09-30 22:15:09 +07:00
parent 632ba863c9
commit 9d9f0ab10a
9 changed files with 133 additions and 28 deletions

View file

@ -1065,6 +1065,7 @@ function tauriTypes() {
' toggleMaximize(): Promise<void>;', ' toggleMaximize(): Promise<void>;',
' close(): Promise<void>;', ' close(): Promise<void>;',
" startResizeDragging(direction: 'North' | 'South' | 'East' | 'West' | 'NorthEast' | 'NorthWest' | 'SouthEast' | 'SouthWest'): Promise<void>;", " startResizeDragging(direction: 'North' | 'South' | 'East' | 'West' | 'NorthEast' | 'NorthWest' | 'SouthEast' | 'SouthWest'): Promise<void>;",
' startDragging(): Promise<void>;',
' isMaximized(): Promise<boolean>;', ' isMaximized(): Promise<boolean>;',
' onResized(handler: () => void): Promise<() => void>;', ' onResized(handler: () => void): Promise<() => void>;',
' setBackgroundColor(color: [number, number, number, number]): Promise<void>;', ' setBackgroundColor(color: [number, number, number, number]): Promise<void>;',

View file

@ -1,7 +1,8 @@
// The app menu: the titlebar's "Settings and more" button, at the far end of the titlebar cluster // The app menu: the titlebar's "Settings and more" button, at the far end of the titlebar cluster
// (before the caption buttons on Windows and Linux; macOS has none there). It opens on click, on // (before the caption buttons on Windows and Linux; macOS has none there). It opens on click, on
// Alt+F and F10 (Shell.tsx; a focused tab forwards the keys), from the command palette and from the // Alt+F and F10 (Shell.tsx; a focused tab forwards the keys), from the command palette, from the
// last row of the account menu. Its rows are the app's (`ShellSite.menu`, menuModel.ts): built-in // last row of the account menu, and from the app's logo at the start of the titlebar (the same
// menu, hung under the logo on its side of the window). Its rows are the app's (`ShellSite.menu`, menuModel.ts): built-in
// ones by name, each shown only when the app serves what it needs, and the app's own. // ones by name, each shown only when the app serves what it needs, and the app's own.
// //
// Like every shell menu it is an overlay: while open the shell is raised above the tab webviews // Like every shell menu it is an overlay: while open the shell is raised above the tab webviews
@ -19,19 +20,19 @@ import { useDev, usePaneTick, useT } from './hooks.ts';
import { formatNumber } from './i18n.ts'; import { formatNumber } from './i18n.ts';
import { Icon, type IconName } from './icons.tsx'; import { Icon, type IconName } from './icons.tsx';
import { import {
DEFAULT_MENU, ZOOM_MAX, ZOOM_MIN, findSpec, joinGroups, languageChoice, languageRows, menuText, moveStop, planMenu, shortcutText, specRows, submenuKeys, typeahead, DEFAULT_MENU, ZOOM_MAX, ZOOM_MIN, findSpec, joinGroups, languageChoice, languageRows, menuText, moveStop, planMenu, shortcutText, specRows, submenuKeys, submenuLeft, typeahead,
type BuiltinMenuItem, type MenuEnv, type MenuItemRow, type MenuRow, type BuiltinMenuItem, type MenuEnv, type MenuItemRow, type MenuRow,
} from './menuModel.ts'; } from './menuModel.ts';
import { hasFeature, site } from './site.ts'; import { hasFeature, site } from './site.ts';
import { isWeb, setOverlay, shell, type TabParams } from './state.ts'; import { isWeb, setOverlay, shell, type TabParams } from './state.ts';
import { openWorkspaceSave } from './TitlebarExtras.tsx'; import { openWorkspaceSave } from './TitlebarExtras.tsx';
import { os } from './windowBinding.ts'; import { os, startDrag, systemMenu } from './windowBinding.ts';
import { loadWorkspaces, restoreWorkspace, workspaceList, workspaces } from './workspaces.ts'; import { loadWorkspaces, restoreWorkspace, workspaceList, workspaces } from './workspaces.ts';
import { readZoom, stepZoom, zoomOf, zoomTarget } from './zoomStore.ts'; import { readZoom, stepZoom, zoomOf, zoomTarget } from './zoomStore.ts';
import './appMenu.css'; import './appMenu.css';
/** How the menu is asked to open: at a submenu, with the first row focused (keyboard), or closing if it is open. */ /** How the menu is asked to open: under the logo instead of its button, at a submenu, with the first row focused (keyboard), or closing if it is open. */
export type AppMenuRequest = { submenu?: string; keyboard?: boolean; toggle?: boolean }; export type AppMenuRequest = { anchor?: 'button' | 'logo'; submenu?: string; keyboard?: boolean; toggle?: boolean };
/** Opens the app menu (Alt+F / F10, the palette, the account menu's last row). */ /** Opens the app menu (Alt+F / F10, the palette, the account menu's last row). */
export const openAppMenu = (request: AppMenuRequest = {}) => window.dispatchEvent(new CustomEvent('bt-app-menu', { detail: request })); export const openAppMenu = (request: AppMenuRequest = {}) => window.dispatchEvent(new CustomEvent('bt-app-menu', { detail: request }));
@ -44,6 +45,16 @@ const getError = (error: unknown) => (error instanceof Error ? error.message : S
const percent = (factor: number) => formatNumber(factor, { style: 'percent', maximumFractionDigits: 0 }); const percent = (factor: number) => formatNumber(factor, { style: 'percent', maximumFractionDigits: 0 });
type Focus = { level: number; id?: string; edge?: 'first' | 'last' | 'menu' }; type Focus = { level: number; id?: string; edge?: 'first' | 'last' | 'menu' };
/** Where the menu hangs: under its button (from the window's end edge) or under the logo (from its start edge). */
type Anchor = { at: 'button' | 'logo'; top: number; left?: number; right?: number };
/** Which trigger the open menu hangs from (null: closed), for the triggers' `aria-expanded`. */
let openAt: Anchor['at'] | null = null;
function noteOpen(at: Anchor['at'] | null) {
if (openAt === at) return;
openAt = at;
window.dispatchEvent(new CustomEvent('bt-app-menu-state'));
}
/** The rows of one level a key can stop on: enabled items; the zoom row counts once. */ /** The rows of one level a key can stop on: enabled items; the zoom row counts once. */
function stopsOf(menu: HTMLElement): HTMLElement[] { function stopsOf(menu: HTMLElement): HTMLElement[] {
@ -62,7 +73,7 @@ export function AppMenu() {
const menu = config.menu ?? {}; const menu = config.menu ?? {};
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [path, setPath] = useState<string[]>([]); const [path, setPath] = useState<string[]>([]);
const [anchor, setAnchor] = useState({ top: 50, right: 8 }); const [anchor, setAnchor] = useState<Anchor>({ at: 'button', top: 50, right: 8 });
const [mode, setMode] = useState<string | null>(null); const [mode, setMode] = useState<string | null>(null);
const [asking, setAsking] = useState<{ to: string; changes: number } | null>(null); const [asking, setAsking] = useState<{ to: string; changes: number } | null>(null);
const [version, setVersion] = useState(''); const [version, setVersion] = useState('');
@ -89,8 +100,12 @@ export function AppMenu() {
}, []); }, []);
function show(request: AppMenuRequest = {}) { function show(request: AppMenuRequest = {}) {
const rect = button.current?.getBoundingClientRect(); const logo = request.anchor === 'logo' ? document.querySelector('.bt-titlebar-logo') : null;
if (rect) setAnchor({ top: Math.round(rect.bottom + 6), right: Math.max(8, Math.round(window.innerWidth - rect.right)) }); const rect = (logo ?? button.current)?.getBoundingClientRect();
if (rect) {
const top = Math.round(rect.bottom + 6);
setAnchor(logo ? { at: 'logo', top, left: Math.max(8, Math.round(rect.left - 3)) } : { at: 'button', top, right: Math.max(8, Math.round(window.innerWidth - rect.right)) });
}
const active = document.activeElement as HTMLElement | null; const active = document.activeElement as HTMLElement | null;
before.current = active && active !== document.body && document.hasFocus() ? active : null; before.current = active && active !== document.body && document.hasFocus() ? active : null;
// Keys pressed in a tab open the menu: the shell takes the keyboard. // Keys pressed in a tab open the menu: the shell takes the keyboard.
@ -121,7 +136,8 @@ export function AppMenu() {
useEffect(() => { useEffect(() => {
const onRequest = (event: Event) => { const onRequest = (event: Event) => {
const request = (event as CustomEvent<AppMenuRequest | undefined>).detail ?? {}; const request = (event as CustomEvent<AppMenuRequest | undefined>).detail ?? {};
if (live.current.open && request.toggle) close('escape'); else show(request); // Asked again from the other trigger, the open menu moves there instead of closing.
if (live.current.open && request.toggle && (request.anchor ?? 'button') === (openAt ?? 'button')) close('escape'); else show(request);
}; };
window.addEventListener('bt-app-menu', onRequest); window.addEventListener('bt-app-menu', onRequest);
return () => window.removeEventListener('bt-app-menu', onRequest); return () => window.removeEventListener('bt-app-menu', onRequest);
@ -131,6 +147,7 @@ export function AppMenu() {
if (!open) return; if (!open) return;
// Native tab webviews would cover the menu. // Native tab webviews would cover the menu.
setOverlay(1); setOverlay(1);
noteOpen(anchor.at);
const away = () => close(); const away = () => close();
// Keys while nothing in the menu has focus (a click on its padding): Esc closes, arrows enter it. // Keys while nothing in the menu has focus (a click on its padding): Esc closes, arrows enter it.
const onKey = (event: KeyboardEvent) => { const onKey = (event: KeyboardEvent) => {
@ -145,8 +162,8 @@ export function AppMenu() {
window.addEventListener('blur', away); window.addEventListener('blur', away);
window.addEventListener('resize', away); window.addEventListener('resize', away);
window.addEventListener('keydown', onKey); window.addEventListener('keydown', onKey);
return () => { setOverlay(-1); window.removeEventListener('blur', away); window.removeEventListener('resize', away); window.removeEventListener('keydown', onKey); }; return () => { setOverlay(-1); noteOpen(null); window.removeEventListener('blur', away); window.removeEventListener('resize', away); window.removeEventListener('keydown', onKey); };
}, [open]); }, [open, anchor.at]);
const layer = (level: number) => layers.current?.querySelector<HTMLElement>(`[data-level="${level}"]`) ?? null; const layer = (level: number) => layers.current?.querySelector<HTMLElement>(`[data-level="${level}"]`) ?? null;
@ -162,10 +179,9 @@ export function AppMenu() {
const box = parent.getBoundingClientRect(); const box = parent.getBoundingClientRect();
el.style.maxHeight = `${window.innerHeight - edge * 2}px`; el.style.maxHeight = `${window.innerHeight - edge * 2}px`;
const { width, height } = el.getBoundingClientRect(); const { width, height } = el.getBoundingClientRect();
// The menu hangs at the window's end edge: a submenu opens on its other side, else beside it, else over it. const left = submenuLeft(box, width, window.innerWidth, edge);
const left = box.left - width + 3 >= edge ? box.left - width + 3 // It slides in from the side it hangs on.
: box.right + width - 3 <= window.innerWidth - edge ? box.right - 3 el.style.setProperty('--bt-app-sub-from', left < box.left ? '6px' : '-6px');
: Math.max(edge, Math.min(box.left - width + 3, window.innerWidth - width - edge));
const top = Math.max(edge, Math.min((row?.getBoundingClientRect().top ?? box.top) - 6, window.innerHeight - height - edge)); const top = Math.max(edge, Math.min((row?.getBoundingClientRect().top ?? box.top) - 6, window.innerHeight - height - edge));
el.style.left = `${Math.round(left)}px`; el.style.left = `${Math.round(left)}px`;
el.style.top = `${Math.round(top)}px`; el.style.top = `${Math.round(top)}px`;
@ -448,16 +464,16 @@ export function AppMenu() {
// An error belongs to the level it happened on: the deepest one open. // An error belongs to the level it happened on: the deepest one open.
if (error) levels[levels.length - 1]!.rows = [...levels[levels.length - 1]!.rows, { kind: 'note', id: 'error', title: '', text: error, tone: 'error' }]; if (error) levels[levels.length - 1]!.rows = [...levels[levels.length - 1]!.rows, { kind: 'note', id: 'error', title: '', text: error, tone: 'error' }];
return levels.map(({ rows, label }, level) => <div key={level === 0 ? 'root' : `${level}:${path[level - 1]}`} role="menu" aria-label={label} tabIndex={-1} data-level={level} return levels.map(({ rows, label }, level) => <div key={level === 0 ? 'root' : `${level}:${path[level - 1]}`} role="menu" aria-label={label} tabIndex={-1} data-level={level}
className={level === 0 ? 'bt-menu bt-app-menu bt-pop bt-pop--right' : 'bt-menu bt-app-menu bt-app-sub'} className={level === 0 ? `bt-menu bt-app-menu bt-pop${anchor.at === 'logo' ? '' : ' bt-pop--right'}` : 'bt-menu bt-app-menu bt-app-sub'}
style={level === 0 ? { top: anchor.top, right: anchor.right, maxHeight: `calc(100vh - ${anchor.top + 8}px)` } : undefined}> style={level === 0 ? { top: anchor.top, left: anchor.left, right: anchor.right, maxHeight: `calc(100vh - ${anchor.top + 8}px)` } : undefined}>
{rows.map((row, index) => renderRow(row, level, index))} {rows.map((row, index) => renderRow(row, level, index))}
</div>); </div>);
} }
const label = menuText('label'); const label = menuText('label');
return <> return <>
<button ref={button} type="button" className="bt-app-button" aria-haspopup="menu" aria-expanded={open} aria-label={label} title={`${label} (${APP_MENU_KEYS})`} <button ref={button} type="button" className="bt-app-button" aria-haspopup="menu" aria-expanded={open && anchor.at === 'button'} aria-label={label} title={`${label} (${APP_MENU_KEYS})`}
onClick={event => (open ? close('escape') : show({ keyboard: event.detail === 0 }))}> onClick={event => (open && anchor.at === 'button' ? close('escape') : show({ keyboard: event.detail === 0 }))}>
<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="5.75" r="1.6"/><circle cx="12" cy="12" r="1.6"/><circle cx="12" cy="18.25" r="1.6"/></svg> <svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="5.75" r="1.6"/><circle cx="12" cy="12" r="1.6"/><circle cx="12" cy="18.25" r="1.6"/></svg>
</button> </button>
{open && createPortal(<div className="bt-menu-backdrop" onMouseDown={() => close()} onContextMenu={event => { event.preventDefault(); close(); }}> {open && createPortal(<div className="bt-menu-backdrop" onMouseDown={() => close()} onContextMenu={event => { event.preventDefault(); close(); }}>
@ -467,3 +483,41 @@ export function AppMenu() {
</div>, document.body)} </div>, document.body)}
</>; </>;
} }
/**
* The app's logo at the start of the titlebar: a second trigger of the same menu, hung under the
* logo. A click opens it; a press that turns into a drag moves the window, as the titlebar around
* it does; a right-click shows the window's system menu, where a titlebar icon has always had it.
*/
export function AppMenuLogo() {
useT();
const [expanded, setExpanded] = useState(openAt === 'logo');
const press = useRef<{ x: number; y: number; dragged: boolean } | null>(null);
useEffect(() => {
const update = () => setExpanded(openAt === 'logo');
window.addEventListener('bt-app-menu-state', update);
return () => window.removeEventListener('bt-app-menu-state', update);
}, []);
const { product, logo } = site();
const label = menuText('label');
return <button type="button" className="bt-titlebar-logo" aria-haspopup="menu" aria-expanded={expanded} aria-label={`${product}: ${label}`} title={`${product} · ${label}`}
onPointerDown={event => { if (event.button === 0) press.current = { x: event.clientX, y: event.clientY, dragged: false }; }}
onPointerMove={event => {
const start = press.current;
if (!start || start.dragged || !(event.buttons & 1)) return;
// The press became a drag: the window moves, and no menu opens when the button is released.
if (Math.hypot(event.clientX - start.x, event.clientY - start.y) > 5) { start.dragged = true; startDrag(); }
}}
onClick={event => {
const dragged = press.current?.dragged;
press.current = null;
if (!dragged) openAppMenu({ anchor: 'logo', toggle: true, keyboard: event.detail === 0 });
}}
onContextMenu={event => {
event.preventDefault(); event.stopPropagation();
const scale = window.devicePixelRatio || 1;
systemMenu(Math.round(event.screenX * scale), Math.round(event.screenY * scale));
}}>
<img src={logo} alt="" draggable={false}/>
</button>;
}

View file

@ -2,7 +2,7 @@ import { useEffect, type CSSProperties, type MouseEvent as ReactMouseEvent } fro
import { RESIZE_BORDER } from '../chrome.ts'; import { RESIZE_BORDER } from '../chrome.ts';
import { chipFor } from '../updateModel.ts'; import { chipFor } from '../updateModel.ts';
import { AccountSwitcher } from './AccountSwitcher.tsx'; import { AccountSwitcher } from './AccountSwitcher.tsx';
import { AppMenu } from './AppMenu.tsx'; import { AppMenu, AppMenuLogo } from './AppMenu.tsx';
import { invoke } from './bridge.ts'; import { invoke } from './bridge.ts';
import { useT, useUpdateStatus } from './hooks.ts'; import { useT, useUpdateStatus } from './hooks.ts';
import { tx } from './i18n.ts'; import { tx } from './i18n.ts';
@ -23,12 +23,13 @@ export function titlebarContextMenu(event: ReactMouseEvent | MouseEvent) {
/** /**
* The 44px titlebar row. It sits under the dockview root: the top groups' tab headers are * The 44px titlebar row. It sits under the dockview root: the top groups' tab headers are
* transparent and let clicks through to the drag layer, the logo and the caption buttons. * transparent and let clicks through to the drag layer, the logo and the caption buttons. The logo
* is the app menu's second trigger (AppMenu.tsx); everything else that is empty drags the window.
*/ */
export function Titlebar({ maximized }: { maximized: boolean }) { export function Titlebar({ maximized }: { maximized: boolean }) {
return <header className="bt-titlebar" onContextMenu={titlebarContextMenu}> return <header className="bt-titlebar" onContextMenu={titlebarContextMenu}>
<div className="bt-titlebar-drag" data-tauri-drag-region/> <div className="bt-titlebar-drag" data-tauri-drag-region/>
<img className="bt-titlebar-logo" src={site().logo} alt="" draggable={false} data-tauri-drag-region/> <AppMenuLogo/>
<div className="bt-titlebar-spacer" data-tauri-drag-region/> <div className="bt-titlebar-spacer" data-tauri-drag-region/>
<TitlebarExtras/> <TitlebarExtras/>
<AccountSwitcher/> <AccountSwitcher/>

View file

@ -13,6 +13,18 @@
.bt-app-button:focus-visible { outline: 0; box-shadow: var(--bt-ring); } .bt-app-button:focus-visible { outline: 0; box-shadow: var(--bt-ring); }
.bt-shell .bt-app-button svg { width: 16px; height: 16px; fill: currentColor; stroke: none; } .bt-shell .bt-app-button svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
/* The logo at the start of the titlebar: the menu's second trigger (a 30px target around the 20px
mark; with its margins it takes the 50px the tab strip leaves in --bt-tb-left). */
.bt-titlebar-logo {
align-self: center; display: inline-grid; place-items: center; width: 30px; height: 30px; flex: 0 0 30px; margin: 0 9px 0 11px; padding: 0; box-sizing: border-box; /* rtl-ok: titlebar */
border: 1px solid transparent; border-radius: 9px; background: transparent; cursor: pointer; -webkit-user-drag: none;
transition: background-color var(--bt-t1) var(--bt-ease), border-color var(--bt-t1) var(--bt-ease);
}
.bt-titlebar-logo img { display: block; width: 20px; height: 20px; pointer-events: none; -webkit-user-drag: none; }
.bt-titlebar-logo:hover { background: var(--bt-hover); border-color: var(--bt-line-soft); }
.bt-titlebar-logo[aria-expanded=true] { background: var(--bt-hover); border-color: rgb(var(--bt-accent-rgb) / .5); }
.bt-titlebar-logo:focus-visible { outline: 0; box-shadow: var(--bt-ring); }
/* The menu and its submenus. `display: contents`: the layers are positioned on their own. */ /* The menu and its submenus. `display: contents`: the layers are positioned on their own. */
.bt-app-layers { display: contents; } .bt-app-layers { display: contents; }
.bt-menu.bt-app-menu { .bt-menu.bt-app-menu {
@ -24,7 +36,7 @@
width: max-content; min-width: 224px; max-width: min(320px, calc(100vw - 16px)); z-index: 1; width: max-content; min-width: 224px; max-width: min(320px, calc(100vw - 16px)); z-index: 1;
animation: bt-app-sub-in var(--bt-t1) var(--bt-ease-out); animation: bt-app-sub-in var(--bt-t1) var(--bt-ease-out);
} }
@keyframes bt-app-sub-in { from { opacity: 0; transform: translateX(6px); } } @keyframes bt-app-sub-in { from { opacity: 0; transform: translateX(var(--bt-app-sub-from, 6px)); } }
.bt-app-menu hr { flex: none; width: auto; align-self: stretch; } .bt-app-menu hr { flex: none; width: auto; align-self: stretch; }
/* Rows: one highlight, wherever it comes from (the pointer moves the focus, as the arrows do); /* Rows: one highlight, wherever it comes from (the pointer moves the focus, as the arrows do);

View file

@ -305,6 +305,24 @@ export function submenuKeys(rtl: boolean): { open: string; close: string } {
return rtl ? { open: 'ArrowLeft', close: 'ArrowRight' } : { open: 'ArrowRight', close: 'ArrowLeft' }; return rtl ? { open: 'ArrowLeft', close: 'ArrowRight' } : { open: 'ArrowRight', close: 'ArrowLeft' };
} }
/**
* The left edge of a submenu `width` wide beside its menu (`parent`), in a window `viewport` wide.
* The menu hangs at one edge of the window (under its button at the end, under the logo at the
* start): the submenu opens toward the middle, else on the other side, else over the menu, and
* always stays `edge` pixels inside the window.
*/
export function submenuLeft(parent: { left: number; right: number }, width: number, viewport: number, edge = 8): number {
const overlap = 3;
const before = parent.left - width + overlap;
const after = parent.right - overlap;
const fits = (x: number) => x >= edge && x + width <= viewport - edge;
const first = (parent.left + parent.right) / 2 > viewport / 2 ? before : after;
const second = first === before ? after : before;
if (fits(first)) return first;
if (fits(second)) return second;
return Math.max(edge, Math.min(first, viewport - width - edge));
}
/** A shortcut as the platform writes it: `Ctrl+Shift+T` on Windows and Linux, `⇧⌘T` on macOS. */ /** A shortcut as the platform writes it: `Ctrl+Shift+T` on Windows and Linux, `⇧⌘T` on macOS. */
export function shortcutText(shortcut: string, mac: boolean): string { export function shortcutText(shortcut: string, mac: boolean): string {
const parts = shortcut.split('+').map(part => part.trim()).filter(Boolean); const parts = shortcut.split('+').map(part => part.trim()).filter(Boolean);

View file

@ -91,12 +91,11 @@ html, body, #root { height: 100%; margin: 0; overflow: hidden; background: var(-
pointer events only on its own controls; everything else falls through to the tabs and their pointer events only on its own controls; everything else falls through to the tabs and their
drag region. With no tabs the titlebar itself is the drag region again. */ drag region. With no tabs the titlebar itself is the drag region again. */
.bt-titlebar { z-index: 2; pointer-events: none; } .bt-titlebar { z-index: 2; pointer-events: none; }
.bt-titlebar > :not(.bt-titlebar-drag):not(.bt-titlebar-spacer):not(.bt-titlebar-logo) { pointer-events: auto; } .bt-titlebar > :not(.bt-titlebar-drag):not(.bt-titlebar-spacer) { pointer-events: auto; }
.bt-shell--empty .bt-titlebar > * { pointer-events: auto; } .bt-shell--empty .bt-titlebar > * { pointer-events: auto; }
/* Above the dock, so it must not paint: the tab strips hosted in the titlebar row show through it. */ /* Above the dock, so it must not paint: the tab strips hosted in the titlebar row show through it. */
.bt-shell:not(.bt-shell--empty) .bt-titlebar { background: transparent; } .bt-shell:not(.bt-shell--empty) .bt-titlebar { background: transparent; }
html[data-os=macos] .bt-titlebar { padding-left: 78px; } /* rtl-ok: traffic lights; the titlebar stays LTR */ html[data-os=macos] .bt-titlebar { padding-left: 78px; } /* rtl-ok: traffic lights; the titlebar stays LTR */
.bt-titlebar-logo { width: 20px; height: 20px; margin: 12px 14px 12px 16px; flex: 0 0 20px; -webkit-user-drag: none; }
.bt-titlebar-spacer { flex: 1; min-width: 48px; } .bt-titlebar-spacer { flex: 1; min-width: 48px; }
.bt-captions { display: flex; } .bt-captions { display: flex; }
.bt-caption { width: 46px; height: 44px; display: grid; place-items: center; padding: 0; background: transparent; border: 0; color: var(--bt-text-2); cursor: default; transition: background-color var(--bt-t1) var(--bt-ease), color var(--bt-t1) var(--bt-ease); } .bt-caption { width: 46px; height: 44px; display: grid; place-items: center; padding: 0; background: transparent; border: 0; color: var(--bt-text-2); cursor: default; transition: background-color var(--bt-t1) var(--bt-ease), color var(--bt-t1) var(--bt-ease); }

View file

@ -6,5 +6,5 @@ import { currentWindow, invoke } from './bridge.ts';
export { frameless, isTauri, os, type ResizeDirection } from '../windowControls.ts'; export { frameless, isTauri, os, type ResizeDirection } from '../windowControls.ts';
export const { minimize, toggleMaximize, close, startResize, onMaximizedChange, systemMenu } = export const { minimize, toggleMaximize, close, startResize, startDrag, onMaximizedChange, systemMenu } =
createWindowControls((command, args) => invoke(command, args), currentWindow); createWindowControls((command, args) => invoke(command, args), currentWindow);

View file

@ -9,6 +9,8 @@ export type NativeWindow = {
toggleMaximize(): Promise<void>; toggleMaximize(): Promise<void>;
close(): Promise<void>; close(): Promise<void>;
startResizeDragging(direction: ResizeDirection): Promise<void>; startResizeDragging(direction: ResizeDirection): Promise<void>;
/** Moves the window with the pointer (the titlebar logo, once a press on it becomes a drag). */
startDragging?(): Promise<void>;
isMaximized(): Promise<boolean>; isMaximized(): Promise<boolean>;
onResized(handler: () => void): Promise<() => void>; onResized(handler: () => void): Promise<() => void>;
}; };
@ -25,6 +27,8 @@ export function createWindowControls(invoke: Invoke, currentWindow: () => Native
toggleMaximize: () => currentWindow().toggleMaximize().catch(() => {}), toggleMaximize: () => currentWindow().toggleMaximize().catch(() => {}),
close: () => currentWindow().close().catch(() => {}), close: () => currentWindow().close().catch(() => {}),
startResize: (direction: ResizeDirection) => currentWindow().startResizeDragging(direction).catch(() => {}), startResize: (direction: ResizeDirection) => currentWindow().startResizeDragging(direction).catch(() => {}),
/** Starts a native window move while the pointer is down (nothing where the app's window lacks it, or in a preview). */
startDrag: () => { try { void currentWindow().startDragging?.().catch(() => {}); } catch { /* No native window. */ } },
onMaximizedChange: (cb: (maximized: boolean) => void) => { onMaximizedChange: (cb: (maximized: boolean) => void) => {
const read = () => { currentWindow().isMaximized().then(cb).catch(() => {}); }; const read = () => { currentWindow().isMaximized().then(cb).catch(() => {}); };
read(); read();

View file

@ -9,7 +9,7 @@ import { fileURLToPath } from 'node:url';
import { setShellI18n, type ShellI18n } from '../src/frame/i18n.ts'; import { setShellI18n, type ShellI18n } from '../src/frame/i18n.ts';
import { import {
DEFAULT_MENU, MENU_BUILTINS, MENU_MESSAGES, ZOOM_MAX, ZOOM_MIN, ZOOM_STEPS, builtinAvailable, findSpec, joinGroups, languageChoice, languageRows, menuText, menuWith, DEFAULT_MENU, MENU_BUILTINS, MENU_MESSAGES, ZOOM_MAX, ZOOM_MIN, ZOOM_STEPS, builtinAvailable, findSpec, joinGroups, languageChoice, languageRows, menuText, menuWith,
menuWithout, moveStop, planMenu, shortcutText, specRows, submenuKeys, typeahead, zoomPercent, zoomStep, menuWithout, moveStop, planMenu, shortcutText, specRows, submenuKeys, submenuLeft, typeahead, zoomPercent, zoomStep,
type MenuEnv, type MenuGroups, type MenuItemRow, type MenuItemSpec, type MenuLanguage, type MenuRow, type MenuEnv, type MenuGroups, type MenuItemRow, type MenuItemSpec, type MenuLanguage, type MenuRow,
} from '../src/frame/menuModel.ts'; } from '../src/frame/menuModel.ts';
import { buildItems } from '../src/frame/paletteModel.ts'; import { buildItems } from '../src/frame/paletteModel.ts';
@ -107,6 +107,22 @@ test('arrows wrap, Home and End jump, and with nothing focused an arrow enters a
assert.deepEqual(submenuKeys(true), { open: 'ArrowLeft', close: 'ArrowRight' }); assert.deepEqual(submenuKeys(true), { open: 'ArrowLeft', close: 'ArrowRight' });
}); });
test('a submenu opens toward the middle of the window and never leaves it', () => {
// Under the button at the window's end: to the left of the menu.
assert.equal(submenuLeft({ left: 990, right: 1294 }, 250, 1440), 990 - 250 + 3);
// Under the logo at the window's start: to the right of the menu.
assert.equal(submenuLeft({ left: 8, right: 312 }, 250, 1440), 312 - 3);
// No room toward the middle: the other side.
assert.equal(submenuLeft({ left: 100, right: 404 }, 250, 700), 404 - 3);
// No room on either side (a narrow window): over the menu, inside the window.
assert.equal(submenuLeft({ left: 11, right: 315 }, 250, 420), 162);
assert.equal(submenuLeft({ left: 108, right: 412 }, 250, 420), 8);
for (const [left, width, viewport] of [[0, 300, 320], [40, 310, 330], [500, 260, 1000], [900, 320, 1000]] as const) {
const at = submenuLeft({ left, right: left + 304 }, width, viewport);
assert.ok(at >= 8 && (at + width <= viewport - 8 || at === 8), `${left}/${width}/${viewport}: ${at}`);
}
});
test('type-ahead finds the next row that starts with what was typed', () => { test('type-ahead finds the next row that starts with what was typed', () => {
const labels = ['New tab', 'Split right', 'Split down', 'Language', 'Theme', 'Settings…', 'Écran', 'İstanbul']; const labels = ['New tab', 'Split right', 'Split down', 'Language', 'Theme', 'Settings…', 'Écran', 'İstanbul'];
assert.equal(typeahead(labels, -1, 's'), 1); assert.equal(typeahead(labels, -1, 's'), 1);