From 7c45ef45b4c5509f62a328dbb9ccf91014a52225 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Fri, 8 May 2026 00:36:37 -0700 Subject: [PATCH] feat(windows): custom title bar with renderer-drawn window controls (#1583) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the default Windows native title bar with a custom renderer-drawn titlebar to match the macOS experience: - Set titleBarStyle:'hidden' on win32 to remove the OS chrome - Add min/max/close buttons (Fluent-style SVG) fixed to the top-right corner, rendered last in DOM order so they're never blocked by -webkit-app-region:drag - Route close through IPC (window:close-requested) so the terminal-running confirmation guard stays active; minimize/maximize via window:minimize and window:maximize IPC channels - Add maximize state sync (window:maximize-changed) so the restore icon shows correctly - Add Orca logo + ··· application-menu button on the left in place of the bare pl-2 spacer; ··· calls Menu.getApplicationMenu().popup() replicating Alt-key reveal - Add window-controls-titlebar-spacer to reserve 138px on the right of the full-width titlebar so content isn't obscured by the overlay Co-authored-by: Neil Parker --- src/main/window/createMainWindow.test.ts | 4 + src/main/window/createMainWindow.ts | 65 ++++++++++++++- src/preload/api-types.ts | 5 ++ src/preload/index.ts | 29 +++++++ src/renderer/src/App.tsx | 100 ++++++++++++++++++++++- src/renderer/src/assets/main.css | 61 ++++++++++++++ 6 files changed, 260 insertions(+), 4 deletions(-) diff --git a/src/main/window/createMainWindow.test.ts b/src/main/window/createMainWindow.test.ts index acd93f539..6de088db2 100644 --- a/src/main/window/createMainWindow.test.ts +++ b/src/main/window/createMainWindow.test.ts @@ -97,6 +97,10 @@ describe('createMainWindow', () => { expect(browserWindowOptions).toMatchObject({ titleBarStyle: 'hiddenInset' }) + } else if (process.platform === 'win32') { + expect(browserWindowOptions).toMatchObject({ + titleBarStyle: 'hidden' + }) } else { expect(browserWindowOptions.titleBarStyle).toBeUndefined() } diff --git a/src/main/window/createMainWindow.ts b/src/main/window/createMainWindow.ts index ec92d3a93..b0dd4fc67 100644 --- a/src/main/window/createMainWindow.ts +++ b/src/main/window/createMainWindow.ts @@ -1,5 +1,5 @@ /* oxlint-disable max-lines */ -import { app, BrowserWindow, ipcMain, nativeTheme, screen, shell } from 'electron' +import { app, BrowserWindow, ipcMain, Menu, nativeTheme, screen, shell } from 'electron' import { join } from 'path' import { is } from '@electron-toolkit/utils' import icon from '../../../resources/icon.png?asset' @@ -155,7 +155,17 @@ export function createMainWindow( // conventions (File Explorer, Firefox, etc.). autoHideMenuBar: true, backgroundColor: nativeTheme.shouldUseDarkColors ? '#0a0a0a' : '#ffffff', - titleBarStyle: process.platform === 'darwin' ? 'hiddenInset' : undefined, + // Why: on macOS 'hiddenInset' keeps the native traffic lights positioned + // inside our custom 42px titlebar. On Windows 'hidden' removes the default + // OS title bar (which would otherwise stack on top of our renderer titlebar + // and waste vertical space) while still allowing our renderer to draw its + // own drag region and window controls. + titleBarStyle: + process.platform === 'darwin' + ? 'hiddenInset' + : process.platform === 'win32' + ? 'hidden' + : undefined, // Why: initial position for 1x zoom; syncTrafficLightPosition() adjusts // dynamically when the user changes UI zoom. ...(process.platform === 'darwin' @@ -296,11 +306,13 @@ export function createMainWindow( return } store?.updateUI({ windowMaximized: true }) + mainWindow.webContents.send('window:maximize-changed', true) }) mainWindow.on('unmaximize', () => { if (windowClosing) { return } + mainWindow.webContents.send('window:maximize-changed', false) const bounds = mainWindow.getBounds() // Why: mirror the saveBounds guard — unmaximize during teardown can land // at MIN_WIDTH × MIN_HEIGHT and we must not persist those as the user's @@ -590,6 +602,51 @@ export function createMainWindow( } ipcMain.on(trafficLightChannel, onSyncTrafficLights) + // Why: renderer-drawn window controls on Windows send these to replicate the + // native title bar buttons that 'hidden' titleBarStyle removes. + const minimizeChannel = 'window:minimize' + const onMinimize = (): void => { + if (!mainWindow.isDestroyed()) { + mainWindow.minimize() + } + } + const maximizeChannel = 'window:maximize' + const onMaximize = (): void => { + if (mainWindow.isDestroyed()) { + return + } + if (mainWindow.isMaximized()) { + mainWindow.unmaximize() + } else { + mainWindow.maximize() + } + } + // Why: send window:close-requested directly rather than calling + // mainWindow.close() and letting the 'close' event re-send it. Calling + // mainWindow.close() from within an IPC message handler on Windows can cause + // the 'close' event to misfire (e.preventDefault() doesn't suppress the OS + // close in all Windows configurations). Going straight to the renderer's + // close guard (Terminal.tsx onWindowCloseRequested) keeps the flow identical + // to what happens when confirmWindowClose() ultimately calls mainWindow.close() + // with windowCloseConfirmed = true. + const requestCloseChannel = 'window:request-close' + const onRequestClose = (): void => { + if (!mainWindow.isDestroyed()) { + mainWindow.webContents.send('window:close-requested', { isQuitting: false }) + } + } + // Why: the ··· button in the renderer-drawn title bar on Windows pops up + // the application menu at the cursor position, replicating the Alt-key + // reveal that autoHideMenuBar normally provides. + const popupMenuChannel = 'menu:popup' + const onPopupMenu = (): void => { + Menu.getApplicationMenu()?.popup({ window: mainWindow }) + } + ipcMain.on(minimizeChannel, onMinimize) + ipcMain.on(maximizeChannel, onMaximize) + ipcMain.on(requestCloseChannel, onRequestClose) + ipcMain.on(popupMenuChannel, onPopupMenu) + ipcMain.on(confirmCloseChannel, onConfirmClose) mainWindow.on('closed', () => { // Why: default-deny the Cmd+B carve-out after the window is gone so a @@ -597,6 +654,10 @@ export function createMainWindow( // with the webContents lifecycle resets above. markdownEditorFocused = false ipcMain.removeListener(trafficLightChannel, onSyncTrafficLights) + ipcMain.removeListener(minimizeChannel, onMinimize) + ipcMain.removeListener(maximizeChannel, onMaximize) + ipcMain.removeListener(requestCloseChannel, onRequestClose) + ipcMain.removeListener(popupMenuChannel, onPopupMenu) ipcMain.removeListener(confirmCloseChannel, onConfirmClose) ipcMain.removeListener(markdownFocusChannel, onMarkdownEditorFocused) app.removeListener('before-quit', freezeBoundsOnQuit) diff --git a/src/preload/api-types.ts b/src/preload/api-types.ts index c52235917..a8458795b 100644 --- a/src/preload/api-types.ts +++ b/src/preload/api-types.ts @@ -1074,6 +1074,11 @@ export type PreloadApi = { syncTrafficLights: (zoomFactor: number) => void setMarkdownEditorFocused: (focused: boolean) => void onFullscreenChanged: (callback: (isFullScreen: boolean) => void) => () => void + minimize: () => void + maximize: () => void + onMaximizeChanged: (callback: (isMaximized: boolean) => void) => () => void + requestClose: () => void + popupMenu: () => void onWindowCloseRequested: (callback: (data: { isQuitting: boolean }) => void) => () => void confirmWindowClose: () => void } diff --git a/src/preload/index.ts b/src/preload/index.ts index 99eb0a0a7..8d3eb0306 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -1914,6 +1914,35 @@ const api = { ipcRenderer.on('window:fullscreen-changed', listener) return () => ipcRenderer.removeListener('window:fullscreen-changed', listener) }, + /** Windows only: minimize the window via the renderer-drawn title bar. */ + minimize: (): void => { + ipcRenderer.send('window:minimize') + }, + /** Windows only: toggle maximize/restore via the renderer-drawn title bar. */ + maximize: (): void => { + ipcRenderer.send('window:maximize') + }, + /** Windows only: subscribe to maximize state changes so the renderer-drawn + * maximize button can show the correct restore/maximize icon. */ + onMaximizeChanged: (callback: (isMaximized: boolean) => void): (() => void) => { + const listener = (_event: Electron.IpcRendererEvent, isMaximized: boolean) => + callback(isMaximized) + ipcRenderer.on('window:maximize-changed', listener) + return () => ipcRenderer.removeListener('window:maximize-changed', listener) + }, + /** Windows only: request a close from the renderer-drawn close button. + * Routes through main so the BrowserWindow 'close' event fires and the + * terminal-running confirmation guard in the renderer stays active. + * window.close() is unreliable in sandboxed renderers. */ + requestClose: (): void => { + ipcRenderer.send('window:request-close') + }, + /** Windows only: pop up the application menu at the cursor position. + * Replicates the Alt-key reveal that autoHideMenuBar normally provides, + * triggered by the ··· button in the renderer-drawn title bar. */ + popupMenu: (): void => { + ipcRenderer.send('menu:popup') + }, /** Fired by the main process when the user tries to close the window * (X button, Cmd+Q, etc.). Renderer should show a confirmation dialog * if terminals are still running, then call confirmWindowClose(). diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 5946d8d29..88b1f659d 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -2,7 +2,8 @@ import { lazy, Suspense, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react' import { getDefaultUIState } from '../../shared/constants' -import { ArrowLeft, ArrowRight, Minimize2, PanelLeft, PanelRight } from 'lucide-react' +import { ArrowLeft, ArrowRight, Minimize2, MoreHorizontal, PanelLeft, PanelRight } from 'lucide-react' +import logo from '../../../resources/logo.svg' import { SYNC_FIT_PANES_EVENT, TOGGLE_TERMINAL_PANE_EXPAND_EVENT } from '@/constants/terminal' import { syncZoomCSSVar } from '@/lib/ui-zoom' import { buildAppFontFamily } from '@/lib/app-font-family' @@ -45,6 +46,67 @@ import { } from '@/store/slices/worktree-nav-history' const isMac = navigator.userAgent.includes('Mac') +const isWindows = !isMac && navigator.userAgent.includes('Windows') + +// Why: 'hidden' titleBarStyle on Windows removes the native OS title bar, +// so we render our own minimize/maximize/close buttons. These SVG icons match +// the Fluent/Win11 style: thin 10×10 paths on a 40×30 hit area. +function WindowControls(): React.JSX.Element { + const [maximized, setMaximized] = useState(false) + useEffect(() => { + return window.api.ui.onMaximizeChanged(setMaximized) + }, []) + return ( +
+ + + +
+ ) +} + const Landing = lazy(() => import('./components/Landing')) const TaskPage = lazy(() => import('./components/TaskPage')) const Settings = lazy(() => import('./components/settings/Settings')) @@ -711,7 +773,33 @@ function App(): React.JSX.Element { // collapsed (Cmd+B), producing a half-occluded, non-scrollable tab strip.
-
+ {isMac && !isFullScreen ? ( +
+ ) : isWindows ? ( + /* Why: on Windows the native title bar is hidden, so we render the + Orca logo as a non-interactive identity anchor and a ··· button + that pops up the application menu (the same menu revealed by Alt + on the default autoHideMenuBar). */ + <> + + + + + + + Application menu + + + + ) : ( +
+ )} {showSidebar && ( @@ -947,6 +1035,9 @@ function App(): React.JSX.Element { an identical close button — hide this copy so only one is visible at a time. */} {!rightSidebarOpen && rightSidebarToggle} + {/* Why: reserve space so content is not obscured by the + fixed-position window-controls overlay on Windows. */} + {isWindows &&
}
) : null}
@@ -1071,6 +1162,11 @@ function App(): React.JSX.Element { + {/* Why: rendered last so it sits after all -webkit-app-region:drag elements + in DOM order. Electron's hit-test for drag regions is DOM-order-based and + ignores z-index — placing WindowControls earlier caused the drag region to + win, making the buttons unclickable. */} + {isWindows && }
) } diff --git a/src/renderer/src/assets/main.css b/src/renderer/src/assets/main.css index b6429b8ef..a648a8049 100644 --- a/src/renderer/src/assets/main.css +++ b/src/renderer/src/assets/main.css @@ -405,6 +405,67 @@ flex-shrink: 0; } +/* Why: small identity anchor on Windows where the native window chrome is + hidden. Sized to sit comfortably in the 42px titlebar with a little + horizontal breathing room. The SVG fill is white; light mode inverts it to + black so it reads on the light titlebar background. */ +.titlebar-logo { + height: 16px; + flex-shrink: 0; + margin: 0 4px 0 10px; + opacity: 0.75; +} + +:not(.dark) .titlebar-logo { + filter: invert(1); +} + +/* Why: Windows-only custom title bar buttons that replace the native OS chrome + removed by titleBarStyle:'hidden'. Anchored to the top-right corner of the + viewport so they overlay any layout mode (full titlebar, workspace split, etc.) + and stay accessible at all times. */ +.window-controls { + position: fixed; + top: 0; + right: 0; + z-index: 9999; + display: flex; + flex-direction: row; + height: 42px; + -webkit-app-region: no-drag; +} + +.window-controls-btn { + display: flex; + align-items: center; + justify-content: center; + width: 46px; + height: 42px; + background: transparent; + border: none; + color: var(--muted-foreground); + cursor: pointer; + transition: background 100ms, color 100ms; +} + +.window-controls-btn:hover { + background: var(--accent); + color: var(--foreground); +} + +.window-controls-close:hover { + background: #c42b1c; + color: #fff; +} + +/* Why: flex spacer that reserves the width occupied by the three window-control + buttons (3 × 46px) so that the preceding titlebar content is not obscured by + the fixed-position overlay on Windows. */ +.window-controls-titlebar-spacer { + flex-shrink: 0; + width: 138px; +} + .sidebar-toggle { -webkit-app-region: no-drag; background: none;