Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions e2e/title-bar-linux-window-controls.test.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<TitleBarGeometry> {
return ctx.titleBar.evaluate<TitleBarGeometry>(READ_TITLE_BAR_GEOMETRY)
}

async function expectButtonsClearOfWindowControls(): Promise<void> {
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()
})
})
2 changes: 2 additions & 0 deletions src/preload/comfyTitleBarPreload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 })
},
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/comfyTitleBar/TitleBarApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions src/renderer/src/comfyTitleBar/TitleBarApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ComfyPanelKey>('comfy')
const installationId = ref(bridge?.getInstallationId() ?? '')
const isInstallLess = ref((bridge?.getInstallationId() ?? '') === '')
Expand Down Expand Up @@ -556,9 +558,10 @@ onUnmounted(() => {
<template>
<header
ref="titleBar"
class="title-bar relative box-border grid h-screen w-screen grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-3 border-b border-solid border-current border-b-[var(--border)] bg-[var(--titlebar-bg-active,var(--titlebar-bg))] px-3 py-0 font-sans text-[12px] leading-none font-normal text-text-muted select-none [-webkit-app-region:drag] [container:title-bar_/_inline-size] [&.is-mac]:pl-[78px] [&.is-mac.is-fullscreen]:pl-3 [&:not(.is-mac)]:pr-[140px] [&:not(.is-light)]:border-b-border [&.is-collapsed-update]:grid-cols-[minmax(0,max-content)_minmax(200px,1fr)_auto] [&.is-collapsed-update]:gap-x-4"
class="title-bar relative box-border grid h-screen w-screen grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-3 border-b border-solid border-current border-b-[var(--border)] bg-[var(--titlebar-bg-active,var(--titlebar-bg))] px-3 py-0 font-sans text-[12px] leading-none font-normal text-text-muted select-none [-webkit-app-region:drag] [container:title-bar_/_inline-size] [&.is-mac]:pl-[78px] [&.is-mac.is-fullscreen]:pl-3 [&:not(.is-mac,.is-linux)]:pr-[140px] [&.is-linux]:[--title-controls-left:env(titlebar-area-x,0px)] [&.is-linux]:[--title-controls-right:calc(100vw_-_env(titlebar-area-x,0px)_-_env(titlebar-area-width,100vw))] [&.is-linux]:pl-[calc(var(--title-controls-left)_+_12px)] [&.is-linux]:pr-[calc(var(--title-controls-right)_+_12px)] [&:not(.is-light)]:border-b-border [&.is-collapsed-update]:grid-cols-[minmax(0,max-content)_minmax(200px,1fr)_auto] [&.is-collapsed-update]:gap-x-4"
:class="{
'is-mac': isMac,
'is-linux': isLinux,
'is-light': isLight,
'is-fullscreen': isFullscreen,
'is-hover-active': isHoverActive,
Expand All @@ -578,8 +581,8 @@ onUnmounted(() => {
class="title-cluster flex items-center gap-1"
:class="
collapsedUpdate
? 'w-[var(--title-trailing-width,0px)] min-w-0 max-w-full [.title-bar:not(.is-mac)_&]:w-[calc(var(--title-trailing-width,0px)_+_128px)]'
: 'min-w-[var(--title-trailing-width,0px)] [.title-bar:not(.is-mac)_&]:min-w-[calc(var(--title-trailing-width,0px)_+_128px)]'
? 'w-[var(--title-trailing-width,0px)] min-w-0 max-w-full [.title-bar:not(.is-mac,.is-linux)_&]:w-[calc(var(--title-trailing-width,0px)_+_128px)] [.title-bar.is-linux_&]:w-[calc(var(--title-trailing-width,0px)_+_max(0px,var(--title-controls-right)_-_var(--title-controls-left)))]'
: 'min-w-[var(--title-trailing-width,0px)] [.title-bar:not(.is-mac,.is-linux)_&]:min-w-[calc(var(--title-trailing-width,0px)_+_128px)] [.title-bar.is-linux_&]:min-w-[calc(var(--title-trailing-width,0px)_+_max(0px,var(--title-controls-right)_-_var(--title-controls-left)))]'
"
>
<button
Expand Down Expand Up @@ -699,7 +702,10 @@ onUnmounted(() => {
</div>
</div>

<div ref="titleTrailing" class="title-trailing flex items-center gap-2 [justify-self:end]">
<div
ref="titleTrailing"
class="title-trailing flex items-center gap-2 [justify-self:end] [.title-bar.is-linux_&]:pl-[max(0px,var(--title-controls-left)_-_var(--title-controls-right))]"
>
<button
v-if="!isFirstUseLockdown && showAppUpdatePill"
type="button"
Expand Down
Loading