Repository navigation
feat(desktop): draw the Windows title bar in the page #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kgoedecke
merged 3 commits into
doop-design:main
from
davidabou:feat/windows-custom-titlebar
Nov 21, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import type { ReactNode } from 'react' | ||
| import { cn } from '@/lib/utils' | ||
| import { Pressable } from './ui/pressable' | ||
| import { useT } from '../lib/i18n' | ||
| import { closeWindow, minimizeWindow, toggleMaximizeWindow, useWindowFrame } from '../lib/windowFrame' | ||
|
|
||
| /** | ||
| * Minimize / maximize / close for the Windows shell once the page has | ||
| * replaced the native frame (src/lib/windowFrame.ts); renders nothing | ||
| * anywhere else. Sized and drawn like the Windows 11 caption buttons — | ||
| * 46px wide, full bar height, 10px hairline glyphs — so the window still | ||
| * reads as a Windows window. | ||
| */ | ||
| export function WindowControls({ className }: { className?: string }) { | ||
| const t = useT() | ||
| const custom = useWindowFrame((s) => s.custom) | ||
| const maximized = useWindowFrame((s) => s.maximized) | ||
| if (!custom) return null | ||
| return ( | ||
| <div className={cn('flex flex-none self-stretch', className)}> | ||
| <CaptionButton label={t('shell.windowMinimize')} onClick={minimizeWindow}> | ||
| <path d="M0 5.5h10" /> | ||
| </CaptionButton> | ||
| <CaptionButton | ||
| label={t(maximized ? 'shell.windowRestore' : 'shell.windowMaximize')} | ||
| onClick={toggleMaximizeWindow} | ||
| > | ||
| {maximized ? <path d="M.5 2.5h7v7h-7zM2.5 2.5v-2h7v7h-2" /> : <path d="M.5.5h9v9h-9z" />} | ||
| </CaptionButton> | ||
| <CaptionButton | ||
| label={t('shell.windowClose')} | ||
| onClick={closeWindow} | ||
| /* red on hover is how Windows marks Close; the failure red stands in | ||
| for the system's so it follows the theme */ | ||
| className="hover:bg-destructive hover:text-white active:bg-destructive/90" | ||
| > | ||
| <path d="M0 0l10 10M10 0L0 10" /> | ||
| </CaptionButton> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| function CaptionButton({ | ||
| label, | ||
| onClick, | ||
| className, | ||
| children, | ||
| }: { | ||
| label: string | ||
| onClick: () => void | ||
| className?: string | ||
| children: ReactNode | ||
| }) { | ||
| return ( | ||
| <Pressable | ||
| layout="inline" | ||
| aria-label={label} | ||
| title={label} | ||
| onClick={onClick} | ||
| className={cn( | ||
| 'w-[46px] cursor-default justify-center text-ink-soft transition-colors hover:bg-ink/[0.06] hover:text-ink active:bg-ink/[0.1]', | ||
| className, | ||
| )} | ||
| > | ||
| <svg viewBox="0 0 10 10" className="size-2.5" fill="none" stroke="currentColor" strokeWidth={1} aria-hidden> | ||
| {children} | ||
| </svg> | ||
| </Pressable> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* The window frame on Windows. macOS shells overlay the title bar from the | ||
| start (desktop/src-tauri/src/main.rs); Windows shells open with the native | ||
| frame and the page swaps it for its own: the tab strip (and, on screens | ||
| without it, ShellDragBar) carries minimize / maximize / close | ||
| (src/components/WindowControls.tsx). | ||
|
|
||
| The page drops the frame rather than the shell, because shell and app ship | ||
| apart: a shell older than the `set_decorations` grant refuses the call and | ||
| keeps its native frame, and a server running an app older than this module | ||
| never asks — so no combination leaves a window without a way to close it. | ||
| Detected by the call succeeding rather than by version, like the other | ||
| shell capabilities. */ | ||
|
|
||
| import { create } from 'zustand' | ||
| import { desktopPlatform } from './shell' | ||
|
|
||
| type AppWindow = { | ||
| setDecorations: (decorations: boolean) => Promise<void> | ||
| isMaximized: () => Promise<boolean> | ||
| onResized: (handler: () => void) => Promise<() => void> | ||
| minimize: () => Promise<void> | ||
| toggleMaximize: () => Promise<void> | ||
| close: () => Promise<void> | ||
| } | ||
|
|
||
| type FrameBridge = { | ||
| __TAURI__?: { window?: { getCurrentWindow?: () => AppWindow } } | ||
| } | ||
|
|
||
| type FrameState = { | ||
| /** The page draws the window controls: the native frame is gone. */ | ||
| custom: boolean | ||
| /** Shows Restore instead of Maximize. */ | ||
| maximized: boolean | ||
| } | ||
|
|
||
| export const useWindowFrame = create<FrameState>(() => ({ custom: false, maximized: false })) | ||
|
|
||
| function appWindow(): AppWindow | null { | ||
| return (globalThis as FrameBridge).__TAURI__?.window?.getCurrentWindow?.() ?? null | ||
| } | ||
|
|
||
| /** Swap the native frame for the page's own. Runs once from | ||
| * initDesktopShell; a no-op off Windows and outside the shell. */ | ||
| export async function initWindowFrame(): Promise<void> { | ||
| if (desktopPlatform() !== 'windows') return | ||
| const win = appWindow() | ||
| if (!win) return | ||
| try { | ||
| await win.setDecorations(false) | ||
|
davidabou marked this conversation as resolved.
Resolved
|
||
| } catch { | ||
| /* a shell without the grant: its native frame stays, and so must | ||
| the page's hands off the controls */ | ||
| return | ||
| } | ||
| const syncMaximized = () => | ||
| win | ||
| .isMaximized() | ||
| .then((maximized) => useWindowFrame.setState({ maximized })) | ||
| .catch(console.error) | ||
| useWindowFrame.setState({ custom: true }) | ||
| await syncMaximized() | ||
| /* Win+Up, Aero snap and the drag region's double-click maximize without | ||
| going through the controls */ | ||
| await win.onResized(() => void syncMaximized()) | ||
| } | ||
|
|
||
| export function minimizeWindow() { | ||
| appWindow()?.minimize().catch(console.error) | ||
| } | ||
|
|
||
| export function toggleMaximizeWindow() { | ||
| appWindow()?.toggleMaximize().catch(console.error) | ||
| } | ||
|
|
||
| export function closeWindow() { | ||
| appWindow()?.close().catch(console.error) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.