Skip to content

The agent that grows with you

feat(desktop): back the HUD band with the same window material the app uses

Brooklyn Nicholson7f9e79b2e17c
diff --git a/apps/desktop/electron/hud-ipc.ts b/apps/desktop/electron/hud-ipc.ts
index 8a8b7cf000d..3eff9c14889 100644
--- a/apps/desktop/electron/hud-ipc.ts
+++ b/apps/desktop/electron/hud-ipc.ts
@@ -4,15 +4,84 @@
// latch when handing the session back to the app window.
import { type BrowserWindow, ipcMain } from 'electron'
+import { hudFrostFor, type TranslucencyState } from './translucency'
+
export interface HudIpcDeps {
isMac: boolean
+ isWindows: boolean
+ glassSupported: boolean
+ /** Main's authoritative translucency state (Settings → Appearance). */
+ getTranslucencyState: () => TranslucencyState
getHudWindow: () => BrowserWindow | null
openHudWindow: (sessionId: null | string, profile: null | string) => void
closeHudWindow: () => void
setHudSessionId: (sessionId: null | string) => void
}
-export function registerHudIpc({ isMac, getHudWindow, openHudWindow, closeHudWindow, setHudSessionId }: HudIpcDeps) {
+export function registerHudIpc({
+ isMac,
+ isWindows,
+ glassSupported,
+ getTranslucencyState,
+ getHudWindow,
+ openHudWindow,
+ closeHudWindow,
+ setHudSessionId
+}: HudIpcDeps) {
+ // Whether the band currently covers the window below the bar. The renderer
+ // is the only party that can know this (it measures the transcript), and it
+ // is half of the frost decision — the other half is the user's setting,
+ // which main owns. Latched so a Settings change can re-decide without
+ // waiting for the HUD to report again.
+ let bandShowing = false
+ let applied: null | string = null
+ let appliedTo: BrowserWindow | null = null
+
+ // Real frosted glass behind the band — the thing CSS backdrop-filter cannot do,
+ // because Chromium composites a transparent window's page against nothing and
+ // the desktop is not in its backdrop root. The material IS the window's content
+ // view, so it frosts the whole rectangle; the HUD's layout leaves no dead
+ // margins for that reason, and it only turns on while the band is showing
+ // (idle HUD mode must be the bar and nothing else).
+ //
+ // Diffed before issuing: `setVibrancy` carries a 150ms animation that restarts
+ // if re-issued, so a repeated call would keep the material from ever settling
+ // (the same churn the chat windows' native-diff contract exists to prevent).
+ //
+ // The diff is keyed to the WINDOW as well as the value. A HUD respawn (the
+ // profile switch in openHudWindow destroys and rebuilds it) hands back a
+ // fresh window carrying no material, and a latch that only remembered the
+ // value would recognise its own last answer and skip — leaving the new HUD
+ // unfrosted until something else happened to change the signature.
+ const applyHudFrost = () => {
+ const hudWindow = getHudWindow()
+
+ if (!hudWindow || hudWindow.isDestroyed()) {
+ applied = null
+ appliedTo = null
+
+ return
+ }
+
+ const frost = hudFrostFor(getTranslucencyState(), bandShowing)
+ const signature = `${frost.vibrancy ?? 'off'}:${frost.backgroundMaterial}`
+
+ if (applied === signature && appliedTo === hudWindow) {
+ return
+ }
+
+ applied = signature
+ appliedTo = hudWindow
+
+ if (isMac && typeof hudWindow.setVibrancy === 'function') {
+ hudWindow.setVibrancy(frost.vibrancy)
+ }
+
+ if (isWindows && glassSupported && typeof hudWindow.setBackgroundMaterial === 'function') {
+ hudWindow.setBackgroundMaterial(frost.backgroundMaterial)
+ }
+ }
+
ipcMain.handle('hermes:hud:open', async (_event, request) => {
openHudWindow(
typeof request?.sessionId === 'string' ? request.sessionId : null,
@@ -22,18 +91,9 @@ export function registerHudIpc({ isMac, getHudWindow, openHudWindow, closeHudWin
return { ok: true }
})
- // Real frosted glass behind the band — the thing CSS backdrop-filter cannot do,
- // because Chromium composites a transparent window's page against nothing and
- // the desktop is not in its backdrop root. Vibrancy IS the window's content
- // view, so it frosts the whole rectangle; the HUD's layout leaves no dead
- // margins for that reason, and the renderer only turns it on while the band is
- // showing (idle HUD mode must be the bar and nothing else).
- ipcMain.handle('hermes:hud:vibrancy', (_event, on) => {
- const hudWindow = getHudWindow()
-
- if (hudWindow && !hudWindow.isDestroyed() && isMac) {
- hudWindow.setVibrancy(on ? 'hud' : null)
- }
+ ipcMain.handle('hermes:hud:frost', (_event, showing) => {
+ bandShowing = Boolean(showing)
+ applyHudFrost()
return { ok: true }
})
@@ -125,4 +185,8 @@ export function registerHudIpc({ isMac, getHudWindow, openHudWindow, closeHudWin
return { ok: true }
})
+
+ // Main re-applies the frost when the translucency SETTING changes, since the
+ // band's own report only fires when the band itself moves.
+ return { applyHudFrost }
}
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 09170cc6300..4afca3a9c23 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -12136,8 +12136,11 @@ registerPetOverlayIpc({
})
// --- HUD mode (chrome-free floating chat) — see hud-ipc.ts. ---------------
-registerHudIpc({
+const hudIpc = registerHudIpc({
isMac: IS_MAC,
+ isWindows: IS_WINDOWS,
+ glassSupported: GLASS_SUPPORTED,
+ getTranslucencyState: () => translucencyState,
getHudWindow: () => hudWindow,
openHudWindow,
closeHudWindow,
@@ -13897,6 +13900,12 @@ ipcMain.on('hermes:translucency', (_event, payload) => {
scheduleTranslucencyWrite()
+ // The HUD's frost reads the same setting but answers on its own terms (see
+ // hudFrostFor) — and it is a transparent window, so it is deliberately not
+ // in the chat fan-out below. It self-diffs, so an unrelated change costs
+ // nothing native.
+ hudIpc.applyHudFrost()
+
if (changed.backing || changed.material || changed.opacity) {
for (const win of BrowserWindow.getAllWindows()) {
applyWindowTranslucency(win, changed)
diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.ts
index 2d1ba597cec..4b745b13533 100644
--- a/apps/desktop/electron/preload.ts
+++ b/apps/desktop/electron/preload.ts
@@ -75,7 +75,10 @@ contextBridge.exposeInMainWorld('hermesDesktop', {
setIgnoreMouse: ignore => ipcRenderer.send('hermes:hud:ignore-mouse', ignore),
moveBy: delta => ipcRenderer.send('hermes:hud:move-by', delta),
setBounds: bounds => ipcRenderer.send('hermes:hud:set-bounds', bounds),
- setVibrancy: on => ipcRenderer.invoke('hermes:hud:vibrancy', on),
+ // Whether the band covers the window below the bar. Main pairs it with the
+ // user's translucency setting to decide the native frost (macOS vibrancy /
+ // Windows 11 DWM backdrop) — see hudFrostFor.
+ setFrost: showing => ipcRenderer.invoke('hermes:hud:frost', showing),
// The HUD tells main which session it is on; main hands that back to the
// app window when the HUD closes, so the app can re-home onto it.
setSession: sessionId => ipcRenderer.send('hermes:hud:session', sessionId),
diff --git a/apps/desktop/electron/translucency.test.ts b/apps/desktop/electron/translucency.test.ts
index 6795fdd5d70..351fc72576b 100644
--- a/apps/desktop/electron/translucency.test.ts
+++ b/apps/desktop/electron/translucency.test.ts
@@ -23,6 +23,7 @@ import {
glassMaterialsFor,
glassSupportedOn,
glassSurfaceKeep,
+ hudFrostFor,
normalizeMaterial,
normalizeMode,
normalizeScope,
@@ -245,6 +246,53 @@ describe('vibrancyFor', () => {
})
})
+// The HUD is a transparent window, so its frost has no opaque page to hide
+// behind: every state that isn't "frost wanted" has to resolve to no material
+// at all, or the band leaves a grey slab hanging over another app.
+describe('hudFrostFor', () => {
+ it('wears the chosen frost on both platforms while the band is showing', () => {
+ expect(hudFrostFor(glass(60, 'header'), true)).toEqual({ vibrancy: 'header', backgroundMaterial: 'mica' })
+ expect(hudFrostFor(glass(60, 'under-window'), true)).toEqual({
+ vibrancy: 'under-window',
+ backgroundMaterial: 'acrylic'
+ })
+ })
+
+ // The material is the whole window rectangle and nothing on the page can
+ // clip it, so a hidden band must mean no frost — this is the veto that keeps
+ // idle HUD mode the bar and nothing else.
+ it('is off whenever the band is not covering the window', () => {
+ expect(hudFrostFor(glass(60, 'header'), false)).toEqual({ vibrancy: null, backgroundMaterial: 'none' })
+ })
+
+ // ...and the setting is the other veto: Glass off, or the tint at zero,
+ // means the HUD never frosts however engaged the band is.
+ it('is off whenever glass itself is off', () => {
+ expect(hudFrostFor(clear(60), true)).toEqual({ vibrancy: null, backgroundMaterial: 'none' })
+ expect(hudFrostFor(glass(0, 'header'), true)).toEqual({ vibrancy: null, backgroundMaterial: 'none' })
+ })
+
+ // Unlike a chat window, which keeps 'sidebar' under its titlebar band in
+ // every non-glass state. Pinning this is what stops someone "fixing" the
+ // null into a resting material and painting the slab back.
+ it('resolves off to no material at all, not to a resting one', () => {
+ expect(hudFrostFor(clear(60), true).vibrancy).toBeNull()
+ expect(vibrancyFor(clear(60))).toBe('sidebar')
+ })
+
+ // The tint is painted by the renderer, exactly as it is for a chat window —
+ // dragging it must not re-issue setVibrancy, whose 150ms animation restarts
+ // on every call and never lets the material settle.
+ it('does not move any native property as the tint slider is dragged', () => {
+ for (let intensity = 1; intensity <= 100; intensity += 1) {
+ expect(hudFrostFor(glass(intensity, 'popover'), true)).toEqual({
+ vibrancy: 'popover',
+ backgroundMaterial: 'tabbed'
+ })
+ }
+ })
+})
+
describe('glassSupportedOn', () => {
it('is on for macOS regardless of kernel version', () => {
expect(glassSupportedOn('darwin')).toBe(true)
diff --git a/apps/desktop/electron/translucency.ts b/apps/desktop/electron/translucency.ts
index 6e524a8d8fc..72f936e9ccf 100644
--- a/apps/desktop/electron/translucency.ts
+++ b/apps/desktop/electron/translucency.ts
@@ -26,6 +26,7 @@ export {
glassMaterialsFor,
glassSupportedOn,
glassSurfaceKeep,
+ hudFrostFor,
normalizeMaterial,
normalizeMode,
normalizeScope,
diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.ts
index 1bd046c80de..4dcefedaf7b 100644
--- a/apps/desktop/src/global.d.ts
+++ b/apps/desktop/src/global.d.ts
@@ -96,7 +96,7 @@ declare global {
setIgnoreMouse: (ignore: boolean) => void
moveBy: (delta: { x: number; y: number; width: number; height: number }) => void
setBounds: (bounds: { x: number; y: number; width: number; height: number }) => void
- setVibrancy: (on: boolean) => Promise<{ ok: boolean }>
+ setFrost: (showing: boolean) => Promise<{ ok: boolean }>
setSession: (sessionId: null | string) => void
onGoto: (callback: (sessionId: string) => void) => () => void
onChanged: (callback: (state: { open: boolean; sessionId: null | string }) => void) => () => void
diff --git a/apps/shared/src/translucency.ts b/apps/shared/src/translucency.ts
index da32fd102fb..fe8ea43b5f5 100644
--- a/apps/shared/src/translucency.ts
+++ b/apps/shared/src/translucency.ts
@@ -274,6 +274,33 @@ export function glassMaterialsFor(isWindows: boolean): readonly GlassMaterial[]
return isWindows ? WINDOWS_GLASS_MATERIALS : GLASS_MATERIALS
}
+/**
+ * The native frost a HUD-style transparent window should carry.
+ *
+ * Two gates, because the HUD's frost answers to more than the setting. The
+ * material is the WINDOW's — nothing on the page can clip it — so it is only
+ * ever right while the band actually covers the window below the bar;
+ * `showing` is the renderer's answer to that (see `useHudGlass`). The setting
+ * is the other half: Glass off, or the tint at zero, means no frost at all.
+ *
+ * The off answer is `null` rather than a resting material, which is the one
+ * way this differs from `vibrancyFor`. A chat window is opaque and keeps
+ * 'sidebar' under its titlebar band whatever the setting says; a transparent
+ * window has no opaque page to hide an unwanted material behind, so off has
+ * to mean off or the frost is a grey slab hanging over someone else's app.
+ */
+export function hudFrostFor(
+ state: TranslucencyState,
+ showing: boolean
+): { backgroundMaterial: WindowsBackgroundMaterial; vibrancy: GlassMaterial | null } {
+ const active = showing && glassActive(state)
+
+ return {
+ vibrancy: active ? state.material : null,
+ backgroundMaterial: active ? backgroundMaterialFor(state) : 'none'
+ }
+}
+
/**
* The rung the picker highlights. A frost with no rung of its own here — a
* Mac's 'header' read on Windows — folds onto the rung that renders the same