From 37d4ab42645cff4d0651090b78bc14ee13d6386a Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sat, 14 Nov 2026 19:57:53 -0800 Subject: [PATCH] fix(titlebar): keep title bar buttons clear of Linux window controls Since Electron 43 a Linux window with a title bar overlay gets its minimize, maximize and close buttons where the desktop's button layout puts them: left, right or both, and only the buttons the desktop shows. Up to Electron 42 they were always three buttons on the right. The title bar reserved a fixed 140px on the right and 12px on the left, so after the move to Electron 45 (#2107): - with the buttons on the left, they covered the menu button; - with elementary's layout (close left, maximize right), close covered it; - on default GNOME (close only), 101px next to the button stayed empty. On Linux the title bar now pads each side by the width Electron reports as taken by window controls (the titlebar-area environment variables, which also reach the title bar's own view) plus the usual 12px. The centre pill stays centred in the window whichever side is wider. Windows keeps its fixed 140px and macOS its traffic-light inset; their rules only gained a "not Linux" condition. Validation, in an Ubuntu 24.04 container running the real app on Electron 45.3.2 under Xvfb: - Measured and screenshotted four layouts (Ubuntu, GNOME default, all left, elementary) at 1280px and at the 800px minimum, before and after. After the change every title bar button is inside the free area on all of them. - e2e/title-bar-linux-window-controls.test.ts starts the app with controls on both sides and checks the buttons against the area Electron reports, at the opening size and at the minimum width. It passes on this change and fails on the previous title bar with "the leftmost title bar button sits under the window controls on the left". - TitleBarApp.test.ts passes. Not checked: a real GNOME, KDE or Wayland session, and right-to-left locales. Electron 43 also rounds the corners of frameless windows where the desktop supports it; under X11 in the container, with and without a compositor, the window kept square corners, so that was not observed. --- e2e/title-bar-linux-window-controls.test.ts | 98 +++++++++++++++++++ src/preload/comfyTitleBarPreload.ts | 2 + .../src/comfyTitleBar/TitleBarApp.test.ts | 3 +- .../src/comfyTitleBar/TitleBarApp.vue | 14 ++- 4 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 e2e/title-bar-linux-window-controls.test.ts diff --git a/e2e/title-bar-linux-window-controls.test.ts b/e2e/title-bar-linux-window-controls.test.ts new file mode 100644 index 000000000..03bb88b9c --- /dev/null +++ b/e2e/title-bar-linux-window-controls.test.ts @@ -0,0 +1,98 @@ +import { mkdir, writeFile } from 'node:fs/promises' +import path from 'node:path' +import { test, expect } from '@playwright/test' +import { launchApp, type AppContext } from './launchApp' + +const CLOSE_AND_MINIMIZE_LEFT_MAXIMIZE_RIGHT = 'close,minimize:maximize' +const MINIMUM_WINDOW_WIDTH = 800 + +interface Span { + left: number + right: number +} + +interface TitleBarGeometry { + windowWidth: number + freeOfWindowControls: Span + buttons: Span +} + +const READ_TITLE_BAR_GEOMETRY = `(() => { + const free = navigator.windowControlsOverlay.getTitlebarAreaRect() + const rects = Array.from(document.querySelectorAll('header button, header [role="button"]')) + .map((element) => element.getBoundingClientRect()) + .filter((rect) => rect.width > 0 && rect.height > 0) + return { + windowWidth: window.innerWidth, + freeOfWindowControls: { left: free.x, right: free.x + free.width }, + buttons: { + left: Math.min(...rects.map((rect) => rect.left)), + right: Math.max(...rects.map((rect) => rect.right)) + } + } +})()` + +let ctx: AppContext + +async function putWindowControlsOnBothSides(homeDir: string): Promise { + for (const gtkVersion of ['gtk-3.0', 'gtk-4.0']) { + const settingsDir = path.join(homeDir, '.config', gtkVersion) + await mkdir(settingsDir, { recursive: true }) + await writeFile( + path.join(settingsDir, 'settings.ini'), + `[Settings]\ngtk-decoration-layout=${CLOSE_AND_MINIMIZE_LEFT_MAXIMIZE_RIGHT}\n` + ) + } +} + +function titleBarGeometry(): Promise { + return ctx.titleBar.evaluate(READ_TITLE_BAR_GEOMETRY) +} + +async function expectButtonsClearOfWindowControls(): Promise { + await expect(async () => { + const { windowWidth, freeOfWindowControls, buttons } = await titleBarGeometry() + expect( + freeOfWindowControls.left, + 'the desktop drew no window controls on the left' + ).toBeGreaterThan(0) + expect( + freeOfWindowControls.right, + 'the desktop drew no window controls on the right' + ).toBeLessThan(windowWidth) + expect( + buttons.left, + 'the leftmost title bar button sits under the window controls on the left' + ).toBeGreaterThanOrEqual(freeOfWindowControls.left) + expect( + buttons.right, + 'the rightmost title bar button sits under the window controls on the right' + ).toBeLessThanOrEqual(freeOfWindowControls.right) + }).toPass({ timeout: 15_000 }) +} + +test.beforeAll(async () => { + ctx = await launchApp({ + settings: { firstUseCompleted: true, telemetryEnabled: false }, + onSetup: ({ homeDir }) => putWindowControlsOnBothSides(homeDir) + }) +}) + +test.afterAll(async () => { + await ctx.cleanup() +}) + +test('title bar buttons stay clear of the window controls a Linux desktop puts on either side @linux', async () => { + await test.step('at the size the window opens with', expectButtonsClearOfWindowControls) + + await test.step('at the narrowest the window can get', async () => { + await ctx.app.evaluate(({ BrowserWindow }, width) => { + const win = BrowserWindow.getAllWindows().find((w) => !w.isDestroyed() && w.isVisible()) + win?.setSize(width, win.getSize()[1] ?? 600) + }, MINIMUM_WINDOW_WIDTH) + await expect + .poll(async () => (await titleBarGeometry()).windowWidth, { timeout: 15_000 }) + .toBe(MINIMUM_WINDOW_WIDTH) + await expectButtonsClearOfWindowControls() + }) +}) diff --git a/src/preload/comfyTitleBarPreload.ts b/src/preload/comfyTitleBarPreload.ts index a35a78c54..dae5abd25 100644 --- a/src/preload/comfyTitleBarPreload.ts +++ b/src/preload/comfyTitleBarPreload.ts @@ -41,6 +41,7 @@ export interface DownloadsTrayState { export interface ComfyTitleBarBridge { getInstallationId(): string | null isMac(): boolean + isLinux(): boolean setPanel(panel: ComfyPanelKey): void openNewWindow(): void openFileMenu(anchor: TitleMenuAnchor): void @@ -116,6 +117,7 @@ function readInstallationId(): string | null { const bridge: ComfyTitleBarBridge = { getInstallationId: () => readInstallationId(), isMac: () => (g.navigator?.userAgent ?? '').toLowerCase().includes('mac'), + isLinux: () => (g.navigator?.userAgent ?? '').toLowerCase().includes('linux'), setPanel: (panel) => { ipcRenderer.send('comfy-window:set-panel', { panel }) }, diff --git a/src/renderer/src/comfyTitleBar/TitleBarApp.test.ts b/src/renderer/src/comfyTitleBar/TitleBarApp.test.ts index cd90aa7ee..88c2cbb33 100644 --- a/src/renderer/src/comfyTitleBar/TitleBarApp.test.ts +++ b/src/renderer/src/comfyTitleBar/TitleBarApp.test.ts @@ -71,7 +71,7 @@ interface MockBridgeState { } function installMockBridge( - opts: { isMac?: boolean; installationId?: string | null } = {} + opts: { isMac?: boolean; isLinux?: boolean; installationId?: string | null } = {} ): MockBridgeState { const state: MockBridgeState = { panelChangedCallbacks: [], @@ -114,6 +114,7 @@ function installMockBridge( const bridge = { getInstallationId: () => installationId, isMac: () => !!opts.isMac, + isLinux: () => !!opts.isLinux, setPanel: (panel: string) => state.setPanelCalls.push(panel), openNewWindow: () => { state.newWindowCalls += 1 diff --git a/src/renderer/src/comfyTitleBar/TitleBarApp.vue b/src/renderer/src/comfyTitleBar/TitleBarApp.vue index 2c9e42b29..914dde843 100644 --- a/src/renderer/src/comfyTitleBar/TitleBarApp.vue +++ b/src/renderer/src/comfyTitleBar/TitleBarApp.vue @@ -59,6 +59,7 @@ interface DownloadsTrayState { interface Bridge { getInstallationId: () => string | null isMac: () => boolean + isLinux: () => boolean setPanel: (panel: ComfyPanelKey) => void openNewWindow: () => void openFileMenu: (anchor: MenuAnchor) => void @@ -142,6 +143,7 @@ const titleDownloadsBadgeClass = 'pointer-events-none absolute -top-1 -right-1 inline-flex h-3.5 min-w-3.5 items-center justify-center rounded-[999px] bg-[var(--action,#60a5fa)] px-1 py-0 text-[9px] leading-none font-bold text-white tabular-nums [box-shadow:0_0_0_2px_var(--titlebar-bg-active,var(--titlebar-bg,var(--neutral-900)))] [.title-bar:not(.is-light)_&:not(.is-unseen,.is-error)]:text-background [&.is-unseen]:bg-[#22c55e] [&.is-error]:bg-[var(--danger)] [.title-downloads-tray.has-active_&]:animate-[title-downloads-pulse_1.6s_ease-in-out_infinite] [.title-downloads-tray.is-flashing_&]:[animation:title-downloads-flash_0.55s_cubic-bezier(0.2,0.9,0.3,1.4)_1,title-downloads-pulse_1.6s_ease-in-out_infinite_0.6s]' const isMac = ref(bridge?.isMac() ?? false) +const isLinux = ref(bridge?.isLinux() ?? false) const activePanel = ref('comfy') const installationId = ref(bridge?.getInstallationId() ?? '') const isInstallLess = ref((bridge?.getInstallationId() ?? '') === '') @@ -556,9 +558,10 @@ onUnmounted(() => {