The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep the Linux HUD clickable and recoverable
Brooklyn Nicholsonb595fcd5e164
diff --git a/apps/desktop/electron/hud-geometry.test.ts b/apps/desktop/electron/hud-geometry.test.tsnew file mode 100644index 00000000000..4ee07f73990--- /dev/null+++ b/apps/desktop/electron/hud-geometry.test.ts@@ -0,0 +1,64 @@+import assert from 'node:assert/strict'++import { test } from 'vitest'++import { applyHudResetBounds, defaultHudBounds } from './hud-geometry'++test('defaultHudBounds restores the standard centered bottom layout', () => {+ assert.deepEqual(defaultHudBounds({ x: 0, y: 25, width: 1440, height: 875 }), {+ x: 410,+ y: 508,+ width: 620,+ height: 320+ })+})++test('defaultHudBounds fits the default layout to a small work area', () => {+ assert.deepEqual(defaultHudBounds({ x: -800, y: 0, width: 480, height: 240 }), {+ x: -800,+ y: 0,+ width: 480,+ height: 240+ })+})++test('defaultHudBounds keeps the spawn fallback when no display is available', () => {+ assert.deepEqual(defaultHudBounds(), { x: undefined, y: undefined, width: 620, height: 320 })+})++test('applyHudResetBounds restores the resize lock and reports native failure', () => {+ let resizable = false+ const win = {+ isDestroyed: () => false,+ isResizable: () => resizable,+ setResizable: (value: boolean) => {+ resizable = value+ },+ setBounds: () => {+ throw new Error('window disappeared')+ }+ }++ assert.equal(applyHudResetBounds(win, { x: 0, y: 0, width: 620, height: 320 }), false)+ assert.equal(resizable, false)+})++test('applyHudResetBounds flips resizable on while the size changes', () => {+ let resizable = false+ const applied: Array<{ height: number; width: number }> = []+ const win = {+ isDestroyed: () => false,+ isResizable: () => resizable,+ setResizable: (value: boolean) => {+ resizable = value+ },+ setBounds: (bounds: { height: number; width: number }) => {+ assert.equal(resizable, true)+ applied.push({ width: bounds.width, height: bounds.height })+ }+ }++ assert.equal(applyHudResetBounds(win, { x: 10, y: 20, width: 620, height: 320 }), true)+ assert.equal(resizable, false)+ assert.deepEqual(applied, [{ width: 620, height: 320 }])+})diff --git a/apps/desktop/electron/hud-geometry.ts b/apps/desktop/electron/hud-geometry.tsnew file mode 100644index 00000000000..1cd8795ada1--- /dev/null+++ b/apps/desktop/electron/hud-geometry.ts@@ -0,0 +1,74 @@+export const HUD_WIDTH = 620+export const HUD_HEIGHT = 320+export const HUD_BOTTOM_MARGIN = 72++export interface HudWorkArea {+ height: number+ width: number+ x: number+ y: number+}++/** Display-aware default bounds used to spawn and recover the HUD layout. */+export function defaultHudBounds(area?: HudWorkArea): {+ height: number+ width: number+ x?: number+ y?: number+} {+ if (!area) {+ return { width: HUD_WIDTH, height: HUD_HEIGHT, x: undefined, y: undefined }+ }++ const width = Math.min(HUD_WIDTH, area.width)+ const height = Math.min(HUD_HEIGHT, area.height)++ return {+ width,+ height,+ x: Math.round(area.x + (area.width - width) / 2),+ y: Math.round(Math.max(area.y, area.y + area.height - height - HUD_BOTTOM_MARGIN))+ }+}++export interface HudBoundsWindow {+ isDestroyed(): boolean+ isResizable(): boolean+ setBounds(bounds: { height: number; width: number; x?: number; y?: number }): void+ setResizable(resizable: boolean): void+}++/**+ * Apply recovery bounds. The HUD is created non-resizable (a transparent+ * frameless window must not expose a system resize hot-zone), which on+ * Windows/Linux also blocks programmatic setBounds sizing — flip it on+ * briefly, same as the corner-resize IPC.+ *+ * On native Wayland the compositor ignores the position half of setBounds+ * (clients cannot place themselves). Size still applies, which is what+ * unsticks the tall/narrow persisted geometry from #87055.+ */+export function applyHudResetBounds(+ win: HudBoundsWindow,+ bounds: { height: number; width: number; x?: number; y?: number }+): boolean {+ try {+ const wasResizable = win.isResizable()++ if (!wasResizable) {+ win.setResizable(true)+ }++ try {+ win.setBounds(bounds)+ } finally {+ if (!wasResizable && !win.isDestroyed()) {+ win.setResizable(false)+ }+ }++ return true+ } catch {+ return false+ }+}diff --git a/apps/desktop/electron/hud-input-policy.test.ts b/apps/desktop/electron/hud-input-policy.test.tsnew file mode 100644index 00000000000..a1ff0b33635--- /dev/null+++ b/apps/desktop/electron/hud-input-policy.test.ts@@ -0,0 +1,73 @@+/**+ * Unit tests for the HUD input policy. The split is the point: the solid+ * fallback has to reach the X11 windows where the input region never comes+ * back, and has to leave native Wayland (and macOS/Windows) on click-through.+ */++import assert from 'node:assert/strict'++import { test } from 'vitest'++import { hudInputPolicy } from './hud-input-policy'++const X11_SESSION = { DISPLAY: ':0', XDG_SESSION_TYPE: 'x11' }+const WAYLAND_SESSION = { WAYLAND_DISPLAY: 'wayland-0', XDG_SESSION_TYPE: 'wayland' }+const XWAYLAND_SESSION = { DISPLAY: ':0', WAYLAND_DISPLAY: 'wayland-0', XDG_SESSION_TYPE: 'wayland' }++test('the click-through design is kept everywhere it works', () => {+ for (const platform of ['darwin', 'win32']) {+ assert.equal(hudInputPolicy(platform, {}, []), 'click-through')+ assert.equal(hudInputPolicy(platform, X11_SESSION, []), 'click-through')+ }+})++test('an X11 session gets the solid HUD', () => {+ assert.equal(hudInputPolicy('linux', X11_SESSION, []), 'solid')+})++test('a Wayland session keeps click-through — Electron 20+ is a native Wayland client there', () => {+ assert.equal(hudInputPolicy('linux', WAYLAND_SESSION, []), 'click-through')+ assert.equal(hudInputPolicy('linux', XWAYLAND_SESSION, []), 'click-through')+})++test('asking for a native Wayland surface keeps the click-through path', () => {+ for (const argv of [['--ozone-platform=wayland'], ['--ozone-platform-hint=wayland']]) {+ assert.equal(hudInputPolicy('linux', WAYLAND_SESSION, argv), 'click-through')+ }++ assert.equal(+ hudInputPolicy('linux', { ...WAYLAND_SESSION, ELECTRON_OZONE_PLATFORM_HINT: 'wayland' }, []),+ 'click-through'+ )+})++test('an auto hint follows the session', () => {+ assert.equal(hudInputPolicy('linux', WAYLAND_SESSION, ['--ozone-platform-hint=auto']), 'click-through')+ assert.equal(hudInputPolicy('linux', X11_SESSION, ['--ozone-platform-hint=auto']), 'solid')+ assert.equal(hudInputPolicy('linux', XWAYLAND_SESSION, ['--ozone-platform-hint=auto']), 'click-through')+})++test('asking for X11 on a Wayland session gets the solid HUD', () => {+ assert.equal(hudInputPolicy('linux', WAYLAND_SESSION, ['--ozone-platform=x11']), 'solid')+ assert.equal(+ hudInputPolicy('linux', { ...WAYLAND_SESSION, ELECTRON_OZONE_PLATFORM_HINT: 'x11' }, []),+ 'solid'+ )+})++test('the explicit switch beats the hint, and the last switch wins', () => {+ assert.equal(+ hudInputPolicy('linux', WAYLAND_SESSION, ['--ozone-platform-hint=auto', '--ozone-platform=x11']),+ 'solid'+ )+ assert.equal(+ hudInputPolicy('linux', X11_SESSION, ['--ozone-platform=x11', '--ozone-platform=wayland']),+ 'click-through'+ )+})++test('a backend nobody recognises follows the session, not a silent X11 default', () => {+ assert.equal(hudInputPolicy('linux', X11_SESSION, ['--ozone-platform=headless']), 'solid')+ assert.equal(hudInputPolicy('linux', WAYLAND_SESSION, ['--ozone-platform=headless']), 'click-through')+ assert.equal(hudInputPolicy('linux', {}, []), 'solid')+})diff --git a/apps/desktop/electron/hud-input-policy.ts b/apps/desktop/electron/hud-input-policy.tsnew file mode 100644index 00000000000..bce5d0dae37--- /dev/null+++ b/apps/desktop/electron/hud-input-policy.ts@@ -0,0 +1,98 @@+/**+ * Which input model the HUD can safely use on this system.+ *+ * The HUD's default is per-element click-through: the window ignores the mouse+ * and turns solid only where the renderer's hit test finds a control under the+ * cursor. That design rests on `setIgnoreMouseEvents(false)` actually handing+ * the input region back. On X11 it does not — once a window has ignored the+ * mouse the X server keeps hit-testing straight through it, and no later call+ * restores it. Ignore is a one-way door there, so the only policy that works+ * is never to walk through it: keep the HUD a normal solid window.+ *+ * That trade is a real loss — a solid HUD swallows clicks in the faded band+ * above the composer — so it is scoped to the Ozone backend where restore is+ * known to be broken, not to every Linux desktop.+ *+ * The windowing backend, not the login session type, is what decides this.+ * Electron 20+ defaults `ozone-platform-hint` to `auto`, which prefers a+ * native Wayland surface on a Wayland session. That is why HUD drag via+ * `setBounds` is a no-op for those users (#82851): they are already a Wayland+ * client. Native Wayland keeps click-through (main's cursor poll re-arms it).+ * X11 and explicit XWayland (`--ozone-platform=x11` / `ozone_platform_hint:+ * x11`) take the solid path.+ */++export type HudInputPolicy = 'click-through' | 'solid'++type Backend = 'wayland' | 'x11'++/**+ * The Ozone platform this process was asked for, or null when nothing asked.+ *+ * `--ozone-platform` names a backend outright and `--ozone-platform-hint`+ * (equivalently `ELECTRON_OZONE_PLATFORM_HINT`) asks for one, with `auto`+ * meaning "Wayland if the session is Wayland". The explicit switch wins over+ * the hint, and a repeated switch resolves last-one-wins, matching Chromium.+ */+function requestedOzonePlatform(env: NodeJS.ProcessEnv, argv: readonly string[]): null | string {+ let explicit: null | string = null+ let hint: null | string = null++ for (const arg of argv) {+ const match = /^--ozone-platform(-hint)?=(.+)$/.exec(arg)++ if (!match) {+ continue+ }++ if (match[1]) {+ hint = match[2].toLowerCase()+ } else {+ explicit = match[2].toLowerCase()+ }+ }++ return explicit ?? hint ?? env.ELECTRON_OZONE_PLATFORM_HINT?.toLowerCase() ?? null+}++function sessionIsWayland(env: NodeJS.ProcessEnv): boolean {+ return env.XDG_SESSION_TYPE === 'wayland' || (Boolean(env.WAYLAND_DISPLAY) && !env.DISPLAY)+}++/**+ * The backend Electron will actually use on Linux.+ *+ * Unset / `auto` follows the session: Wayland sessions get a native Wayland+ * surface (Electron 20+ default), X11 sessions stay on X11. An explicit+ * `--ozone-platform=x11` (or `desktop.ozone_platform_hint: x11`) is the+ * COSMIC always-on-top escape hatch and lands on the solid HUD path.+ */+function linuxBackend(env: NodeJS.ProcessEnv, argv: readonly string[]): Backend {+ const requested = requestedOzonePlatform(env, argv)++ if (requested === 'x11') {+ return 'x11'+ }++ if (requested === 'wayland') {+ return 'wayland'+ }++ return sessionIsWayland(env) ? 'wayland' : 'x11'+}++/**+ * The input model the HUD should use.+ *+ * macOS and Windows keep the click-through design: `setIgnoreMouseEvents(true,+ * { forward: true })` is `@platform darwin,win32`, so the renderer goes on+ * seeing the cursor while the window ignores it and can re-arm whenever the+ * pointer comes back to the bar.+ */+export function hudInputPolicy(platform: string, env: NodeJS.ProcessEnv, argv: readonly string[]): HudInputPolicy {+ if (platform !== 'linux') {+ return 'click-through'+ }++ return linuxBackend(env, argv) === 'x11' ? 'solid' : 'click-through'+}diff --git a/apps/desktop/electron/hud-ipc.ts b/apps/desktop/electron/hud-ipc.tsindex d141e3b0825..76b8b4f0a18 100644--- a/apps/desktop/electron/hud-ipc.ts+++ b/apps/desktop/electron/hud-ipc.ts@@ -4,6 +4,7 @@// latch when handing the session back to the app window.import { type BrowserWindow, ipcMain } from 'electron'+import { hudInputPolicy } from './hud-input-policy'import { hudFrostFor, type TranslucencyState } from './translucency'export interface HudIpcDeps {@@ -13,6 +14,7 @@ export interface HudIpcDeps {getHudWindow: () => BrowserWindow | nullopenHudWindow: (sessionId: null | string, profile: null | string) => voidcloseHudWindow: () => void+ resetHudLayout: () => booleansetHudSessionId: (sessionId: null | string) => void}@@ -22,6 +24,7 @@ export function registerHudIpc({getHudWindow,openHudWindow,closeHudWindow,+ resetHudLayout,setHudSessionId}: HudIpcDeps) {// Whether the band currently covers the window below the bar. The renderer@@ -111,9 +114,19 @@ export function registerHudIpc({ipcMain.on('hermes:hud:ignore-mouse', (_event, ignore) => {const hudWindow = getHudWindow()- if (hudWindow && !hudWindow.isDestroyed()) {- hudWindow.setIgnoreMouseEvents(Boolean(ignore), { forward: true })+ if (!hudWindow || hudWindow.isDestroyed()) {+ return}++ // On X11 ignore-mouse is a one-way door: setIgnoreMouseEvents(false)+ // cannot restore the input region afterwards. Veto the request there so+ // the HUD stays a normal solid window. Native Wayland and macOS/Windows+ // keep the per-element path.+ if (Boolean(ignore) && hudInputPolicy(process.platform, process.env, process.argv) === 'solid') {+ return+ }++ hudWindow.setIgnoreMouseEvents(Boolean(ignore), { forward: true })})ipcMain.on('hermes:hud:move-by', (event, delta) => {@@ -175,6 +188,16 @@ export function registerHudIpc({}})+ ipcMain.handle('hermes:hud:reset-layout', event => {+ const hudWindow = getHudWindow()++ if (!hudWindow || hudWindow.isDestroyed() || event.sender !== hudWindow.webContents) {+ return { ok: false }+ }++ return { ok: resetHudLayout() }+ })+// The HUD renderer reporting which session it is on, so the close broadcast// can hand it back to the app window (see hudSessionId).ipcMain.on('hermes:hud:session', (event, sessionId) => {diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 7cd87d8a994..1667b7080d8 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -194,6 +194,8 @@ import {} from './hardening'import { cursorPointInWindow } from './hud-cursor'import { startHudGameOverlayWatch } from './hud-game-overlay'+import { applyHudResetBounds, defaultHudBounds } from './hud-geometry'+import { hudInputPolicy } from './hud-input-policy'import { registerHudIpc } from './hud-ipc'import { snapHudBounds } from './hud-snap'import { createHudSnapShortcut } from './hud-snap-shortcut'@@ -6604,6 +6606,19 @@ function restorePersistedZoomLevel(window) {const saved = readZoomState()if (saved != null) {+ // Drift-guard: skip when this window already shows the persisted level.+ // Blindly re-applying on every resize/move would race the compositor's+ // surface reconfigure during a Wayland resize storm (Cosmic tiled mode+ // fires one whenever a new session window opens — #84818) and keep the+ // renderer notification stream churning for no gain. The settle-verify+ // chain in installZoomReassertOnWindowEvents re-applies only when the+ // window actually drifted from the persisted level.+ const current = window.webContents?.getZoomLevel?.()++ if (current != null && Math.abs(current - saved) < 1e-9) {+ return+ }+applyZoomLevel(window.webContents, saved)return@@ -11610,9 +11625,6 @@ let hudProfile = null// of a game chat frame, and where one belongs. Defaults only: once the user// moves or resizes the HUD, hud-state.json wins (same pattern as the main// window's window-state.json).-const HUD_WIDTH = 620-const HUD_HEIGHT = 320-const HUD_BOTTOM_MARGIN = 72const HUD_STATE_PATH = path.join(app.getPath('userData'), 'hud-state.json')function readHudState() {@@ -11647,6 +11659,26 @@ function persistHudState() {}}+function resetHudWindowLayout(): boolean {+ if (!hudWindow || hudWindow.isDestroyed()) {+ return false+ }++ const win = hudWindow+ const display = screen.getDisplayNearestPoint(screen.getCursorScreenPoint())+ const bounds = defaultHudBounds(display?.workArea)++ if (!applyHudResetBounds(win, bounds)) {+ rememberLog('[hud-state] reset layout failed while applying native bounds')++ return false+ }++ persistHudState()++ return true+}+const schedulePersistHudState = debounce(persistHudState, 250)// How often Linux gets told where the cursor is. Fast enough that the bar is@@ -11679,6 +11711,8 @@ function applyHudSnapToPointer() {// setBounds — NOT setPosition alone: on Windows, a transparent frameless// window silently grows ~1px per setPosition call (see move-by handler).+ // On native Wayland the compositor ignores the position half; the snap+ // shortcut is therefore a documented no-op there.hudWindow.setBounds({x: origin.x,y: origin.y,@@ -11715,6 +11749,21 @@ function startHudCursorFeed(win: BrowserWindow) {return}+ // On an X11 window `setIgnoreMouseEvents(false)` does not restore the input+ // region once the window has ignored the mouse. Ignore is a one-way door+ // there, so the HUD is held solid for its whole life (the companion veto+ // is in the hermes:hud:ignore-mouse handler). Native Wayland keeps the+ // poll — that is what re-arms click-through when the pointer returns.+ if (hudInputPolicy(process.platform, process.env, process.argv) === 'solid') {+ try {+ win.setIgnoreMouseEvents(false)+ } catch {+ // best effort+ }++ return+ }+let last: string | null = nullconst timer = setInterval(() => {@@ -11805,19 +11854,7 @@ function hudBounds() {const display = screen.getDisplayNearestPoint(screen.getCursorScreenPoint())const area = display?.workArea- if (!area) {- return { width: HUD_WIDTH, height: HUD_HEIGHT, x: undefined, y: undefined }- }-- const width = Math.min(HUD_WIDTH, area.width)- const height = Math.min(HUD_HEIGHT, area.height)-- return {- width,- height,- x: Math.round(area.x + (area.width - width) / 2),- y: Math.round(Math.max(area.y, area.y + area.height - height - HUD_BOTTOM_MARGIN))- }+ return defaultHudBounds(area)}function hudUrl(sessionId, profile) {@@ -12664,6 +12701,7 @@ const hudIpc = registerHudIpc({getHudWindow: () => hudWindow,openHudWindow,closeHudWindow,+ resetHudLayout: resetHudWindowLayout,setHudSessionId: value => {hudSessionId = value}diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.tsindex 00987700689..a15d72d3a98 100644--- a/apps/desktop/electron/preload.ts+++ b/apps/desktop/electron/preload.ts@@ -75,6 +75,7 @@ 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),+ resetLayout: () => ipcRenderer.invoke('hermes:hud:reset-layout'),// 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.diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.tsindex 65ba0dafeb7..cc6a3151f9e 100644--- a/apps/desktop/src/global.d.ts+++ b/apps/desktop/src/global.d.ts@@ -96,6 +96,7 @@ declare global {setIgnoreMouse: (ignore: boolean) => voidmoveBy: (delta: { x: number; y: number; width: number; height: number }) => voidsetBounds: (bounds: { x: number; y: number; width: number; height: number }) => void+ resetLayout: () => Promise<{ ok: boolean }>setFrost: (showing: boolean) => Promise<{ ok: boolean }>setSession: (sessionId: null | string) => voidonGoto: (callback: (sessionId: string) => void) => () => voiddiff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex 2545df5935f..34600cebe2c 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -3695,6 +3695,15 @@ DEFAULT_CONFIG = {# explicit ozone backend, or GPU workaround flags. A list of strings;# a single string is also accepted and shell-split."electron_flags": [],+ # Linux Ozone backend hint, bridged to ELECTRON_OZONE_PLATFORM_HINT+ # at launch (an explicit env var still wins). "auto" is Chromium's+ # default — Wayland on a Wayland session, X11 otherwise.+ # Set "x11" to run under XWayland when a compositor ignores+ # always-on-top for native Wayland clients (COSMIC, issue #84011).+ # That also lands the HUD on the solid-window input path, because+ # setIgnoreMouseEvents is a one-way door on X11.+ # "wayland" forces a native Wayland surface.+ "ozone_platform_hint": "auto",# GPU hardware acceleration policy for the desktop app:# "auto" - let the app detect remote displays (SSH/VNC/RDP) and# disable GPU only then (default; current behavior).diff --git a/hermes_cli/main.py b/hermes_cli/main.pyindex 1346b0a827e..fbcc01e42e1 100644--- a/hermes_cli/main.py+++ b/hermes_cli/main.py@@ -7768,26 +7768,29 @@ def _detect_linux_password_store() -> str | None:return None-def _desktop_launch_options() -> tuple[list[str], str, str]:+def _desktop_launch_options() -> tuple[list[str], str, str, str]:"""Read `desktop.*` launch options from config.yaml.- Returns ``(electron_flags, disable_gpu, password_store)`` where+ Returns ``(electron_flags, disable_gpu, password_store, ozone_hint)`` where``electron_flags`` is a list of extra Electron CLI flags, ``disable_gpu``is one of "auto"/"1"/"0" (normalized for the HERMES_DESKTOP_DISABLE_GPU- env var the Electron app reads), and ``password_store`` is "auto" or one+ env var the Electron app reads), ``password_store`` is "auto" or oneof the Chromium password-store backends (unknown values normalize to- "auto"). Best-effort: any config error yields the safe defaults- ``([], "auto", "auto")`` so a malformed config never blocks the launch.+ "auto"), and ``ozone_hint`` is one of "auto"/"x11"/"wayland" (normalized+ for ``ELECTRON_OZONE_PLATFORM_HINT``). Best-effort: any config error+ yields the safe defaults ``([], "auto", "auto", "auto")`` so a malformed+ config never blocks the launch."""flags: list[str] = []disable_gpu = "auto"password_store = "auto"+ ozone_hint = "auto"try:from hermes_cli.config import load_configdesktop_cfg = (load_config() or {}).get("desktop") or {}except Exception:- return flags, disable_gpu, password_store+ return flags, disable_gpu, password_store, ozone_hintraw_flags = desktop_cfg.get("electron_flags")if isinstance(raw_flags, str):@@ -7812,7 +7815,13 @@ def _desktop_launch_options() -> tuple[list[str], str, str]:low_store = raw_store.strip().lower()if low_store in _LINUX_PASSWORD_STORES:password_store = low_store- return flags, disable_gpu, password_store++ raw_ozone = desktop_cfg.get("ozone_platform_hint", "auto")+ if isinstance(raw_ozone, str):+ low_ozone = raw_ozone.strip().lower()+ if low_ozone in ("auto", "x11", "wayland"):+ ozone_hint = low_ozone+ return flags, disable_gpu, password_store, ozone_hintdef _register_linux_desktop_entry() -> None:@@ -7863,12 +7872,18 @@ def cmd_gui(args: argparse.Namespace):env["HERMES_DESKTOP_CWD"] = os.getcwd()# Desktop launch options from config.yaml (`desktop.electron_flags`,- # `desktop.disable_gpu`). The GPU policy is bridged to the env var the- # Electron app already reads; an explicit env var still wins over config so- # `HERMES_DESKTOP_DISABLE_GPU=... hermes desktop` keeps working.- config_electron_flags, config_disable_gpu, config_password_store = _desktop_launch_options()+ # `desktop.disable_gpu`, `desktop.ozone_platform_hint`). The GPU policy+ # and ozone hint are bridged to env vars the Electron/Chromium process+ # already reads; an explicit env var still wins over config so+ # `HERMES_DESKTOP_DISABLE_GPU=... hermes desktop` and+ # `ELECTRON_OZONE_PLATFORM_HINT=... hermes desktop` keep working.+ config_electron_flags, config_disable_gpu, config_password_store, config_ozone_hint = (+ _desktop_launch_options()+ )if config_disable_gpu != "auto" and "HERMES_DESKTOP_DISABLE_GPU" not in os.environ:env["HERMES_DESKTOP_DISABLE_GPU"] = config_disable_gpu+ if config_ozone_hint != "auto" and "ELECTRON_OZONE_PLATFORM_HINT" not in os.environ:+ env["ELECTRON_OZONE_PLATFORM_HINT"] = config_ozone_hint# Linux keychain backend for safeStorage (`desktop.password_store`).# Chromium needs the --password-store switch to pick the right keychain;diff --git a/tests/hermes_cli/test_gui_command.py b/tests/hermes_cli/test_gui_command.pyindex 6d310bfd6aa..42cdb459a44 100644--- a/tests/hermes_cli/test_gui_command.py+++ b/tests/hermes_cli/test_gui_command.py@@ -588,10 +588,75 @@ def test_gui_skips_desktop_entry_off_linux(tmp_path, monkeypatch):def test_desktop_launch_options_normalizes_password_store(raw, expected):cfg = {"desktop": {"password_store": raw}}with patch("hermes_cli.config.load_config", return_value=cfg):- _, _, store = cli_main._desktop_launch_options()+ _, _, store, _ = cli_main._desktop_launch_options()assert store == expected+ "raw,expected",+ [+ ("x11", "x11"),+ ("WAYLAND", "wayland"),+ ("auto", "auto"),+ ("bogus", "auto"),+ (True, "auto"),+ ],+)+def test_desktop_launch_options_normalizes_ozone_hint(raw, expected):+ """``desktop.ozone_platform_hint`` normalizes to x11/wayland/auto."""+ cfg = {"desktop": {"ozone_platform_hint": raw}}+ with patch("hermes_cli.config.load_config", return_value=cfg):+ _, _, _, hint = cli_main._desktop_launch_options()+ assert hint == expected+++def test_desktop_launch_options_ozone_hint_defaults_auto():+ with patch("hermes_cli.config.load_config", return_value={}):+ assert cli_main._desktop_launch_options()[3] == "auto"+++def test_gui_bridges_ozone_hint_to_launch_env(tmp_path, monkeypatch):+ """COSMIC HUD: ``desktop.ozone_platform_hint: x11`` sets+ ``ELECTRON_OZONE_PLATFORM_HINT`` on the launched Electron process."""+ root = _make_desktop_tree(tmp_path)+ monkeypatch.setattr(cli_main, "PROJECT_ROOT", root)+ _make_packaged_executable(root, monkeypatch)++ ok = subprocess.CompletedProcess([], 0)+ cfg = {"desktop": {"ozone_platform_hint": "x11"}}++ with patch("hermes_cli.main.shutil.which", return_value="/usr/bin/npm"), \+ patch("hermes_cli.main._run_npm_install_deterministic", return_value=ok), \+ patch("hermes_cli.main._desktop_build_needed", return_value=True), \+ patch("hermes_cli.main._write_desktop_build_stamp"), \+ patch("hermes_cli.main._desktop_macos_relaunchable_fixup"), \+ patch("hermes_cli.main._desktop_linux_sandbox_fixup", return_value=True), \+ patch("hermes_cli.config.load_config", return_value=cfg), \+ patch("hermes_cli.linux_desktop_entry.install_desktop_entry", return_value=None), \+ patch("hermes_cli.main.subprocess.run", side_effect=[ok, ok]) as mock_run, \+ pytest.raises(SystemExit):+ cli_main.cmd_gui(_ns())++ launch_env = mock_run.call_args_list[1].kwargs["env"]+ assert launch_env.get("ELECTRON_OZONE_PLATFORM_HINT") == "x11"++ monkeypatch.setenv("ELECTRON_OZONE_PLATFORM_HINT", "wayland")+ with patch("hermes_cli.main.shutil.which", return_value="/usr/bin/npm"), \+ patch("hermes_cli.main._run_npm_install_deterministic", return_value=ok), \+ patch("hermes_cli.main._desktop_build_needed", return_value=True), \+ patch("hermes_cli.main._write_desktop_build_stamp"), \+ patch("hermes_cli.main._desktop_macos_relaunchable_fixup"), \+ patch("hermes_cli.main._desktop_linux_sandbox_fixup", return_value=True), \+ patch("hermes_cli.config.load_config", return_value=cfg), \+ patch("hermes_cli.linux_desktop_entry.install_desktop_entry", return_value=None), \+ patch("hermes_cli.main.subprocess.run", side_effect=[ok, ok]) as mock_run2, \+ pytest.raises(SystemExit):+ cli_main.cmd_gui(_ns())++ launch_env = mock_run2.call_args_list[1].kwargs["env"]+ assert launch_env.get("ELECTRON_OZONE_PLATFORM_HINT") == "wayland"++# --- desktop.password_store detection & bridging (linux) ------------------