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(() => {