diff --git a/apps/desktop/src/app/hud/glass.ts b/apps/desktop/src/app/hud/glass.ts index 572f68b58f..2a917e4433 100644 --- a/apps/desktop/src/app/hud/glass.ts +++ b/apps/desktop/src/app/hud/glass.ts @@ -3,14 +3,18 @@ import { type RefObject, useEffect } from 'react' /** The caret is in the composer — see the `:has()` rules in styles.css. */ const TYPING_SELECTOR = '[data-slot="composer-rich-input"]:focus' +/** An open completion list owns the surface; the band falls back behind it. */ +const DRAWER_SELECTOR = '[data-slot="composer-completion-drawer"]' + /** * Native frost behind the band. * - * macOS vibrancy, not CSS — `backdrop-filter` reaches nothing here, because a - * transparent window's backdrop root is the document and the desktop was never - * in it. Vibrancy is composited by WindowServer BELOW the web contents, which - * is what lets it see the desktop and also what makes it untouchable from the - * page: no mask, clip or stacking order can shape it. + * A platform material, not CSS — `backdrop-filter` reaches nothing here, + * because a transparent window's backdrop root is the document and the desktop + * was never in it. The material is composited BELOW the web contents (macOS + * vibrancy via WindowServer, Windows 11 via the DWM backdrop), which is what + * lets it see the desktop and also what makes it untouchable from the page: no + * mask, clip or stacking order can shape it. * * That is survivable because the band is a flat panel. It was NOT survivable * while the band carried a vertical gradient — the frost stayed a slab under a @@ -31,38 +35,79 @@ const TYPING_SELECTOR = '[data-slot="composer-rich-input"]:focus' * document.activeElement, which stays put when the window is blurred and would * latch the frost on forever once the user had ever typed here. * - * `backing` is the veto over both of those. Because the frost is the window and - * not the sheet, it is only ever right when the sheet covers the window; short - * of that the excess is frost over empty space. Gating the caller's `engaged` - * alone would not do it — focus turns the frost on by itself, which is how a - * brand new thread still frosted its whole empty window. + * Two vetoes sit over that: + * + * - `backing` — because the frost is the window and not the sheet, it is only + * ever right when the sheet covers the window; short of that the excess is + * frost over empty space. Gating the caller's `engaged` alone would not do + * it — focus turns the frost on by itself, which is how a brand new thread + * still frosted its whole empty window. + * - An open completion drawer, which drops the band to 25% and blurs it + * (see the `composer-completion-drawer` rule in styles.css). Full-strength + * frost behind a band that has deliberately stepped back is the same bare + * slab in a different disguise. Observed rather than passed in: the drawer + * mounts inside the composer subtree from three different call sites, so a + * prop would need every one of them to remember. + * + * Whether the frost is wanted AT ALL is the user's translucency setting, and + * that answer lives in main (`hudFrostFor`) next to the state it reads. This + * hook reports what the band is doing; it does not decide the material. */ export function useHudGlass(rootRef: RefObject, engaged: boolean, backing: boolean): void { useEffect(() => { const root = rootRef.current - const setVibrancy = window.hermesDesktop?.hud?.setVibrancy + const setFrost = window.hermesDesktop?.hud?.setFrost - if (!root || !setVibrancy) { + if (!root || !setFrost) { return } let on: boolean | null = null const apply = () => { - const next = backing && (engaged || root.querySelector(TYPING_SELECTOR) !== null) + const next = + backing && + root.querySelector(DRAWER_SELECTOR) === null && + (engaged || root.querySelector(TYPING_SELECTOR) !== null) if (on !== next) { on = next - void setVibrancy(next) + void setFrost(next) } } + // The drawer mounts and unmounts without any focus change, so neither + // focusin/focusout nor a re-render is guaranteed to follow it. Coalesced + // to a frame: this observes the whole shell, and a streaming reply mutates + // the transcript tens of times a second — the drawer's state cannot change + // more than once per paint, so re-deciding per mutation is pure churn. + let frame: null | number = null + + const schedule = () => { + if (frame === null) { + frame = requestAnimationFrame(() => { + frame = null + apply() + }) + } + } + + const observer = new MutationObserver(schedule) + + observer.observe(root, { childList: true, subtree: true }) + apply() root.addEventListener('focusin', apply) root.addEventListener('focusout', apply) return () => { - void setVibrancy(false) + void setFrost(false) + observer.disconnect() + + if (frame !== null) { + cancelAnimationFrame(frame) + } + root.removeEventListener('focusin', apply) root.removeEventListener('focusout', apply) } diff --git a/apps/desktop/src/store/translucency.test.ts b/apps/desktop/src/store/translucency.test.ts index a2861a952f..1e9e0cadc9 100644 --- a/apps/desktop/src/store/translucency.test.ts +++ b/apps/desktop/src/store/translucency.test.ts @@ -400,6 +400,28 @@ describe('glass is confined to chat windows', () => { // The mode is still the user's choice — only the page rewrite is withheld. expect($translucency.get().mode).toBe('glass') expect(document.documentElement.hasAttribute('data-hermes-glass')).toBe(false) + }) + + // The HUD paints its band from the app's field mix, so it needs the setting + // and the tint number even though its surfaces must not be rewritten. The + // two flags are what keep those separable: keying the band off + // `data-hermes-glass` would silently never match. + it('still publishes the live setting and the tint to a special-purpose window', () => { + setSearch('?win=hud') + setTranslucency(60) + setTranslucencyMode('glass') + + expect(document.documentElement.hasAttribute('data-hermes-glass-on')).toBe(true) + expect(document.documentElement.style.getPropertyValue('--translucency-glass-keep')).toBe('40%') + }) + + it('withdraws both flags when glass is switched off', () => { + setSearch('?win=hud') + setTranslucency(60) + setTranslucencyMode('glass') + setTranslucencyMode('clear') + + expect(document.documentElement.hasAttribute('data-hermes-glass-on')).toBe(false) expect(document.documentElement.style.getPropertyValue('--translucency-glass-keep')).toBe('') }) diff --git a/apps/desktop/src/store/translucency.ts b/apps/desktop/src/store/translucency.ts index b37bc25989..4bb0c89944 100644 --- a/apps/desktop/src/store/translucency.ts +++ b/apps/desktop/src/store/translucency.ts @@ -262,24 +262,38 @@ const applyGlassSurfaces = ({ intensity, mode, scope }: TranslucencyState): void } const root = document.documentElement - const glassOn = mode === 'glass' && intensity > 0 && GLASS_SUPPORTED && isChatWindow() + // Is the user's Glass setting live at all — the same answer in every window. + const glassLive = mode === 'glass' && intensity > 0 && GLASS_SUPPORTED + // ...and may THIS window's field surfaces be rewritten for it. Only real + // chat windows: the HUD, pet overlay, quick entry and wake indicator are + // transparent windows that own their backgrounds, and the surface rewrite + // would fight them. The HUD still wants the first answer, because its band + // paints the app's field mix from `--translucency-glass-keep` and its native + // frost is gated on the setting being on (see the `[data-hud-glass]` rules + // and hudFrostFor) — which is why these are two flags and not one. + const glassOn = glassLive && isChatWindow() // Clear mode fades the whole window uniformly, so overlay text and the // covered transcript blend; styles.css strengthens the overlay scrim while // this attribute is present. Native opacity applies in every window kind, so // no chat-window gate. const clearOn = mode === 'clear' && intensity > 0 + root.toggleAttribute('data-hermes-glass-on', glassLive) root.toggleAttribute('data-hermes-glass', glassOn) root.toggleAttribute('data-hermes-clear', clearOn) - if (glassOn) { - root.setAttribute('data-hermes-glass-scope', scope) + if (glassLive) { root.style.setProperty('--translucency-glass-keep', `${glassSurfaceKeep(intensity)}%`) } else { - root.removeAttribute('data-hermes-glass-scope') root.style.removeProperty('--translucency-glass-keep') } + if (glassOn) { + root.setAttribute('data-hermes-glass-scope', scope) + } else { + root.removeAttribute('data-hermes-glass-scope') + } + if (glassOn && scope === 'sidebar') { startRailTracking() } else { diff --git a/apps/desktop/src/styles.css b/apps/desktop/src/styles.css index 3816915bf8..ada6d1d210 100644 --- a/apps/desktop/src/styles.css +++ b/apps/desktop/src/styles.css @@ -2579,19 +2579,32 @@ button[data-slot='aui_msg-reactions'] svg { scroll or a stray click while you're aiming at the app behind it. Focus the composer and it becomes a real scrollable surface. This also means hover alone can't reveal the band anymore — hover is not engagement. */ -/* The band's sheet, behind the transcript: a tint wearing the same gradient - mask as the text, so the whole surface ramps out together and the band has no - top edge at all. - - No desktop blur under it, and that is a limit rather than an omission. CSS - backdrop-filter reaches nothing here — a transparent window's backdrop root - is the document, and the desktop was never in it (verified on the real - window, not assumed). macOS vibrancy does see the desktop, but WindowServer - composites it below the web contents after this process has finished drawing, - so no mask, clip or stacking order can shape it; left on under a fading tint - it stays a flat slab and the top of the band goes pale exactly where it - should be disappearing. The way through is NSVisualEffectView.maskImage - behind a small native addon, which is its own change. */ +/* The band's sheet, behind the transcript: a tint the whole surface ramps out + with, so the band has no top edge at all. + + CSS backdrop-filter reaches nothing here — a transparent window's backdrop + root is the document, and the desktop was never in it (verified on the real + window, not assumed). The blur is a native platform material instead, and + because it is composited below the web contents after this process has + finished drawing, no mask, clip or stacking order can shape it: it is the + whole window rectangle or nothing. That is why it is switched on only while + the band covers the window (useHudGlass) and why the sheet must be a flat + panel — under a fading GRADIENT the frost stayed a slab and the top of the + band went pale exactly where it should have been disappearing. Shaping it + would need NSVisualEffectView.maskImage behind a native addon. + + Under Glass the sheet wears the SAME paint the docked thread does: + `--ui-bg-chrome` kept at `--translucency-glass-keep`, the one number + store/translucency publishes from the Tint slider (see the + `[data-hermes-glass]` block). One painter, one token, one lever — the band + reads as the app's thread surface rather than as a HUD-only lookalike that + drifts the first time either side is touched. + + With Glass off there is no material behind the window, so the sheet keeps + its own card tint. Heavier than the text in front of it, deliberately: with + no blur to separate the band from what it lies over, the sheet is the only + thing keeping half-opacity text off someone else's UI. Fade the words, keep + the paper. */ [data-hud-shell] [data-hud-glass] { position: absolute; right: var(--hud-band-inset); @@ -2600,10 +2613,6 @@ button[data-slot='aui_msg-reactions'] svg { z-index: 0; pointer-events: none; border-radius: 0.75rem 0.75rem 0 0; - /* Heavier than the text in front of it, deliberately: with no blur to - separate the band from what it lies over, the sheet is the only thing - keeping half-opacity text off someone else's UI. Fade the words, keep the - paper. */ background: color-mix(in srgb, var(--dt-card) 80%, transparent); /* Slides down behind the bar as it fades. A TRANSFORM, not height: it is composited, so it stays smooth where animating height re-lays-out the panel @@ -2637,6 +2646,43 @@ button[data-slot='aui_msg-reactions'] svg { transition-duration: var(--hud-reveal); } +/* ── Under Glass ───────────────────────────────────────────────────────────── + The band becomes the app's thread surface: the docked window's field mix, + over the platform material. + + Keyed to `data-hermes-glass-on` — "the user's Glass setting is live" — and + NOT to `data-hermes-glass`, which additionally means "this window's field + surfaces may be rewritten" and is false here by design: the HUD is a + transparent window that owns its own backgrounds (isChatWindow). Two flags, + because the HUD wants the setting without the rewrite. */ +:root[data-hermes-glass-on] [data-hud-shell] [data-hud-glass] { + background: color-mix(in srgb, var(--ui-bg-chrome) var(--translucency-glass-keep, 100%), transparent); +} + +/* The band spans the window edge to edge under glass. The 8px side inset keeps + the sheet clear of the bar's corner controls when it is an opaque panel — + but the frost is the WINDOW, so an inset sheet leaves a hairline of bare + untinted material down both sides. Nothing to hold off the material's edge: + the window's own rounded corners are where the band ends. */ +:root[data-hermes-glass-on] [data-hud-shell] { + --hud-band-inset: 0px; +} + +:root[data-hermes-glass-on] [data-hud-shell] [data-hud-glass] { + border-radius: 0.75rem 0.75rem 0 0; +} + +/* Engaged, the field steps up the same way the docked thread's does — but + never below the resting tint, so a high lever cannot make focusing the + composer paint MORE transparent than glancing at it. */ +:root[data-hermes-glass-on] [data-hud-shell]:has([data-slot='composer-rich-input']:focus) [data-hud-glass] { + background: color-mix( + in srgb, + var(--ui-bg-chrome) min(100%, calc(var(--translucency-glass-keep, 100%) + 12%)), + transparent + ); +} + /* Engaged means the caret is in the composer, not merely that the window holds focus somewhere. Activating a window restores focus to whatever had it last, so `:focus-within` counted grabbing the bar to DRAG the HUD as sitting down