The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep the native window opacity off platforms without translucency
686f6c61b5868c1f6222
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 0eff77e4cb9..a1fdb2cbbf0 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -578,6 +578,7 @@ import {defaultTranslucencyState,glassActive,glassSupportedOn,+ nativeOpacityFor,normalizeState as normalizeTranslucency,opacityNeedsSetting,translucencySupportedOn,@@ -1498,7 +1499,11 @@ nativeTheme.themeSource = readPersistedThemeSource()// — a matte blur with full-contrast text. macOS uses vibrancy; Windows 11// uses DWM acrylic/mica/tabbed. Persisted so a cold launch applies it at// window creation, before the renderer reports its value.-// macOS + Windows only; `setOpacity` is a no-op on Linux.+// macOS + Windows only. Electron documents `setOpacity` as a no-op on Linux,+// but a Linux window really does render faded when handed the value: X11+// carries it as `_NET_WM_WINDOW_OPACITY` and a native Wayland surface+// composites it into the frame. So the platform gate has to be applied to the+// value itself — see nativeOpacityFor — and not just to the Settings row.const TRANSLUCENCY_CONFIG_PATH = path.join(app.getPath('userData'), 'translucency.json')function readPersistedTranslucency() {@@ -1536,7 +1541,7 @@ const translucencyBackedWindows = new WeakSet()// window's own opacity is the record of whether that door was ever opened; see// opacityNeedsSetting for why it matters that it stays shut.function applyWindowOpacity(win) {- const opacity = windowOpacityFor(translucencyState)+ const opacity = nativeOpacityFor(translucencyState, TRANSLUCENCY_SUPPORTED)if (typeof win.setOpacity === 'function' && opacityNeedsSetting(opacity, win.getOpacity?.() ?? 1)) {win.setOpacity(opacity)@@ -1636,7 +1641,7 @@ function chatWindowSurfaceOptions() {// RESIZABLE transparent window is unsupported and breaks (electron#48421).// Every chat window is resizable....windowBackgroundMaterialOptions(translucencyState, IS_WINDOWS, GLASS_SUPPORTED),- ...windowOpacityOptions(translucencyState),+ ...windowOpacityOptions(translucencyState, TRANSLUCENCY_SUPPORTED),...windowBackingOptions(translucencyState, getWindowBackgroundColor())}}diff --git a/apps/desktop/electron/translucency.test.ts b/apps/desktop/electron/translucency.test.tsindex 5f4b4fad81c..87d83b7eba1 100644--- a/apps/desktop/electron/translucency.test.ts+++ b/apps/desktop/electron/translucency.test.ts@@ -26,6 +26,7 @@ import {glassSupportedOn,glassSurfaceKeep,hudFrostFor,+ nativeOpacityFor,normalizeBook,normalizeMaterial,normalizeMode,@@ -515,6 +516,40 @@ describe('windowOpacityOptions', () => {})})+// Linux gets the same 29% Clear default macOS does (`defaultTranslucencyValues`+// only distinguishes Windows), and `translucencySupportedOn` keeps the Settings+// row away on the strength of Electron documenting `setOpacity` as a no-op+// there. On Linux it is not a no-op on either backend: the X11 window carries+// the value as `_NET_WM_WINDOW_OPACITY` and a native Wayland surface composites+// the fade into the frame, so the window renders faded forever, with the only+// control that could undo it hidden. So the value has to be gated where it+// reaches the window, not only where the row is drawn.+describe('nativeOpacityFor', () => {+ it('leaves a platform without translucency fully opaque', () => {+ expect(nativeOpacityFor(clear(29), false)).toBe(1)+ expect(nativeOpacityFor(clear(100), false)).toBe(1)+ expect(nativeOpacityFor(glass(60, DEFAULT_GLASS_MATERIAL, 40), false)).toBe(1)+ })++ it('answers the ramp unchanged where translucency is supported', () => {+ for (const state of [clear(0), clear(29), clear(100)]) {+ expect(nativeOpacityFor(state, true)).toBe(windowOpacityFor(state))+ }+ })++ // A window that already carries a faded opacity — an upgrade from a build+ // that set it, or a profile imported from macOS — still has to be handed the+ // opaque value, or it stays faded for the rest of the session.+ it('has something to say to a window that is already faded', () => {+ expect(opacityNeedsSetting(nativeOpacityFor(clear(29), false), 0.9372)).toBe(true)+ })++ it('keeps the constructor option off an unsupported platform', () => {+ expect(windowOpacityOptions(clear(29), false)).toStrictEqual({})+ expect(windowOpacityOptions(clear(100), false)).toStrictEqual({})+ })+})+describe('opacityNeedsSetting', () => {it('skips the call for an opaque window that has never been faded', () => {expect(opacityNeedsSetting(1, 1)).toBe(false)diff --git a/apps/desktop/electron/translucency.ts b/apps/desktop/electron/translucency.tsindex 2035392cb44..8754f7ea9c0 100644--- a/apps/desktop/electron/translucency.ts+++ b/apps/desktop/electron/translucency.ts@@ -141,12 +141,29 @@ export function opacityNeedsSetting(next: number, current = 1): boolean {return next < 1 || current < 1}+/**+ * The native opacity a window should carry, given whether this platform can do+ * translucency at all.+ *+ * `translucencySupportedOn` drops the Settings row on everything but macOS and+ * Windows, on the strength of Electron documenting `setOpacity` as a no-op+ * elsewhere. On Linux it is not one: the X11 window carries the value as+ * `_NET_WM_WINDOW_OPACITY`, and a native Wayland surface composites the same+ * fade into the frame, so a Linux window really does render faded when handed+ * the value. The gate therefore belongs where the value reaches the window, not+ * only where the row is drawn, because a state persisted or imported from+ * another platform reaches this path without ever passing the Settings check.+ */+export function nativeOpacityFor(state: TranslucencyState, supported: boolean): number {+ return supported ? windowOpacityFor(state) : 1+}+/*** BrowserWindow constructor options for a chat window's native opacity. Empty* unless the state actually asks the window to fade — see opacityNeedsSetting.*/-export function windowOpacityOptions(state: TranslucencyState): { opacity?: number } {- const opacity = windowOpacityFor(state)+export function windowOpacityOptions(state: TranslucencyState, supported = true): { opacity?: number } {+ const opacity = nativeOpacityFor(state, supported)return opacityNeedsSetting(opacity) ? { opacity } : {}}