App menu: one home in the titlebar, the logo

The top-right ⋮ and the logo opened the same menu: one of them was redundant.
The logo stays as the only titlebar trigger (the app's own mark, where an app
menu lives); the right side is back to workspaces, accounts and the window
buttons. Alt+F, F10, the palette and the account menu's last row open the
menu under the logo. Apps that want a separate button keep <AppMenu/>'s
default trigger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
CRTkafa 2026-10-01 04:26:40 +07:00
parent 48ff509b15
commit 311f5d9e20
2 changed files with 12 additions and 7 deletions

View file

@ -69,7 +69,7 @@ function stopsOf(menu: HTMLElement): HTMLElement[] {
return all.filter(el => !('zoom' in el.dataset) || el === keep);
}
export function AppMenu() {
export function AppMenu({ trigger = true }: { trigger?: boolean } = {}) {
const t = useT();
usePaneTick();
const dev = useDev();
@ -107,9 +107,13 @@ export function AppMenu() {
};
}, []);
/** Where a request without an anchor opens: the button when this app shows one, else the logo. */
const home = (): Anchor['at'] => (trigger ? 'button' : 'logo');
function show(request: AppMenuRequest = {}) {
diag(`menu open: anchor=${request.anchor ?? 'button'} keyboard=${!!request.keyboard} hasFocus=${document.hasFocus()} active=${describe(document.activeElement)}`);
const logo = request.anchor === 'logo' ? document.querySelector('.bt-titlebar-logo') : null;
const at = request.anchor ?? home();
diag(`menu open: anchor=${at} keyboard=${!!request.keyboard} hasFocus=${document.hasFocus()} active=${describe(document.activeElement)}`);
const logo = at === 'logo' ? document.querySelector('.bt-titlebar-logo') : null;
const rect = (logo ?? button.current)?.getBoundingClientRect();
if (rect) {
const top = Math.round(rect.bottom + 6);
@ -162,7 +166,7 @@ export function AppMenu() {
const onRequest = (event: Event) => {
const request = (event as CustomEvent<AppMenuRequest | undefined>).detail ?? {};
// 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);
if (live.current.open && request.toggle && (request.anchor ?? home()) === (openAt ?? home())) close('escape'); else show(request);
};
window.addEventListener('bt-app-menu', onRequest);
return () => window.removeEventListener('bt-app-menu', onRequest);
@ -559,10 +563,10 @@ export function AppMenu() {
const label = menuText('label');
return <>
<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})`}
{trigger && <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 && 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>
</button>
</button>}
{open && createPortal(<div className="bt-menu-backdrop" onMouseDown={() => close()} onContextMenu={event => { event.preventDefault(); close(); }}>
<div ref={layers} className="bt-app-layers" onMouseDown={event => event.stopPropagation()} onContextMenu={event => { event.preventDefault(); event.stopPropagation(); }} onKeyDown={onKey}>
{renderMenus()}