feat(windows): custom title bar with renderer-drawn window controls (#1583)

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 <nwparker@anthropic.com>
This commit is contained in:
Neil
2026-05-08 00:36:37 -07:00
committed by GitHub
co-authored by Neil Parker
parent 83b3369ea5
commit 7c45ef45b4
6 changed files with 260 additions and 4 deletions
+4
View File
@@ -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()
}
+63 -2
View File
@@ -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)
+5
View File
@@ -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
}
+29
View File
@@ -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().
+98 -2
View File
@@ -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 (
<div className="window-controls">
<button
className="window-controls-btn"
aria-label="Minimize"
onClick={() => window.api.ui.minimize()}
>
<svg width="10" height="10" viewBox="0 0 10 10" aria-hidden>
<path d="M0 5h10v1H0z" fill="currentColor" />
</svg>
</button>
<button
className="window-controls-btn"
aria-label={maximized ? 'Restore' : 'Maximize'}
onClick={() => window.api.ui.maximize()}
>
{maximized ? (
// Restore icon (two overlapping squares)
<svg width="10" height="10" viewBox="0 0 10 10" aria-hidden>
<path
d="M2 0v2H0v8h8V8h2V0H2zm6 9H1V3h7v6zM9 7H8V2H3V1h6v6z"
fill="currentColor"
/>
</svg>
) : (
// Maximize icon (single square outline)
<svg width="10" height="10" viewBox="0 0 10 10" aria-hidden>
<path d="M0 0v10h10V0H0zm9 9H1V1h8v8z" fill="currentColor" />
</svg>
)}
</button>
<button
className="window-controls-btn window-controls-close"
aria-label="Close"
// Why: IPC to main so the BrowserWindow 'close' event fires, which
// sends 'window:close-requested' back to the renderer and keeps the
// terminal-running confirmation guard active. window.close() is
// unreliable in sandboxed renderers.
onClick={() => window.api.ui.requestClose()}
>
<svg width="10" height="10" viewBox="0 0 10 10" aria-hidden>
<path
d="M1 0L0 1l4 4-4 4 1 1 4-4 4 4 1-1-4-4 4-4-1-1-4 4-4-4z"
fill="currentColor"
/>
</svg>
</button>
</div>
)
}
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.
<div ref={titlebarLeftControlsRef} className="flex h-full w-full shrink-0 items-center">
<div className="flex h-full items-center">
<div className={isMac && !isFullScreen ? 'titlebar-traffic-light-pad' : 'pl-2'} />
{isMac && !isFullScreen ? (
<div className="titlebar-traffic-light-pad" />
) : 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). */
<>
<img src={logo} alt="" aria-hidden className="titlebar-logo" />
<Tooltip>
<TooltipTrigger asChild>
<button
className="titlebar-icon-button"
aria-label="Application menu"
onClick={() => window.api.ui.popupMenu()}
>
<MoreHorizontal size={14} />
</button>
</TooltipTrigger>
<TooltipContent side="bottom" sideOffset={6}>
Application menu
</TooltipContent>
</Tooltip>
</>
) : (
<div className="pl-2" />
)}
{showSidebar && (
<Tooltip>
<TooltipTrigger asChild>
@@ -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 && <div className="window-controls-titlebar-spacer" />}
</div>
) : null}
<div className="flex flex-row flex-1 min-h-0 overflow-hidden">
@@ -1071,6 +1162,11 @@ function App(): React.JSX.Element {
<ZoomOverlay />
<SshPassphraseDialog />
<Toaster closeButton toastOptions={{ className: 'font-sans text-sm' }} />
{/* 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 && <WindowControls />}
</div>
)
}
+61
View File
@@ -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;