From a076967ed05914198feee32201c684a495f8d095 Mon Sep 17 00:00:00 2001 From: Brendonovich <14191578+Brendonovich@users.noreply.github.com> Date: Thu, 5 Nov 2026 02:52:03 +0000 Subject: [PATCH] feat(app): bend the content panel around the macOS traffic lights --- packages/app/src/shell/shell.tsx | 22 +++++ .../src/shell/traffic-lights-notch.test.ts | 26 +++++ .../app/src/shell/traffic-lights-notch.tsx | 99 +++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 packages/app/src/shell/traffic-lights-notch.test.ts create mode 100644 packages/app/src/shell/traffic-lights-notch.tsx diff --git a/packages/app/src/shell/shell.tsx b/packages/app/src/shell/shell.tsx index b91e3715a8b..e2a97067f72 100644 --- a/packages/app/src/shell/shell.tsx +++ b/packages/app/src/shell/shell.tsx @@ -26,6 +26,7 @@ import { import { createPanelMotion, guardClosingFocus, panelOpacity, setPanelResizing } from "@/shell/panel-motion" import { createSidebarPeek } from "@/shell/sidebar-peek" import { windowDragEnabled } from "@/session/header/drag-area" +import { paintTrafficLightsNotch, TrafficLightsNotch } from "@/shell/traffic-lights-notch" type SidebarPose = { closed: number; peek: number | undefined } @@ -109,6 +110,20 @@ export default function Layout(props: ParentProps) { if (!peeking) peekHome = undefined } + let trafficLightsNotch: SVGSVGElement | undefined + + // The native traffic lights float over the top-left of the content once the sidebar leaves it. The content starts + // after the aside, which sits at the window's right in right-to-left layouts. + const paintNotch = () => { + const lights = + platform.platform === "desktop" && platform.os === "macos" && !platform.windowFullscreen?.() && verticalTabs() + + const rtl = document.documentElement.dir === "rtl" + const content = rtl ? 0 : state.tabsWidth * (1 - sidebar.closed) + + paintTrafficLightsNotch(trafficLightsNotch, lights ? content : undefined, platform.webviewZoom?.() ?? 1) + } + const sidebarMotion = createPanelMotion({ open: preferences.appearance.sidebarOpen, // The aside's real width moves main's edge with the sidebar's; its contents keep their width, pinned to that edge. @@ -121,6 +136,7 @@ export default function Layout(props: ParentProps) { // Dims the contents, background included, as they leave and brightens them as they arrive. paintSidebarContents() paintCollapsedSlots(closed) + paintNotch() }, measure: () => measureSidebarToggles(state.tabsWidth * sidebarHidden()), // A dock from a peek already shows the sidebar, so reduced motion has nothing to fade in. @@ -314,6 +330,12 @@ export default function Layout(props: ParentProps) { {props.children} + { + trafficLightsNotch = element + paintNotch() + }} + /> {/* On touch devices the active composer moves its actions here: the bottom edge, or the top of the keyboard. diff --git a/packages/app/src/shell/traffic-lights-notch.test.ts b/packages/app/src/shell/traffic-lights-notch.test.ts new file mode 100644 index 00000000000..74e5d26e4e5 --- /dev/null +++ b/packages/app/src/shell/traffic-lights-notch.test.ts @@ -0,0 +1,26 @@ +import { expect, it } from "bun:test" +import { trafficLightsPocket } from "./traffic-lights-notch" + +it("bends the closed sidebar's content panel around the traffic lights, its corner concentric with the zoom button", () => { + // The buttons span 20–80px across and 25–39px down at 1x. + expect(trafficLightsPocket(0, 1)).toEqual({ left: 8, right: 86, bottom: 45, top: 8, outer: 10, inner: 13 }) +}) + +it("flattens the bend into the panel's own corner as the panel's edge reaches the pocket's", () => { + const pocket = trafficLightsPocket(70, 1) + + expect(pocket?.outer).toBeCloseTo(10 * (8 / 23), 5) + expect(pocket?.inner).toBeCloseTo(13 * (8 / 23), 5) + expect(trafficLightsPocket(77.99, 1)?.outer).toBeCloseTo(0, 2) + expect(trafficLightsPocket(78, 1)).toBeUndefined() + expect(trafficLightsPocket(240, 1)).toBeUndefined() +}) + +it("stays concentric with the zoom button, which keeps its native size, under renderer zoom", () => { + const pocket = trafficLightsPocket(0, 2) + + // At 2x the buttons are 7px across on an 11.5px pitch, the first still centered 27px across and 32px down. + expect(pocket?.inner).toBe(9.5) + expect(pocket && pocket.right - pocket.inner).toBe(27 + 2 * 11.5) + expect(pocket && pocket.bottom - pocket.inner).toBe(32) +}) diff --git a/packages/app/src/shell/traffic-lights-notch.tsx b/packages/app/src/shell/traffic-lights-notch.tsx new file mode 100644 index 00000000000..df26c1ca54e --- /dev/null +++ b/packages/app/src/shell/traffic-lights-notch.tsx @@ -0,0 +1,99 @@ +import { macVerticalTrafficLights } from "@/shell/sidebar-toggle" + +// The content panels' corner radius and their offset from the window's top and start edges. +const panelRadius = 10 + +const panelInset = 8 + +// Room between the traffic lights and the pocket the panel bends around them. +const pocketPadding = 6 + +// The native buttons' size in points; they keep it at every renderer zoom. +const trafficLightSize = 14 + +/** + * The top-left corner of the content panel once it bends around the traffic lights, in CSS pixels from the window's + * top-left. `content` is where the content area starts now. Undefined while the panel is clear of the buttons. + */ +export function trafficLightsPocket(content: number, zoom: number) { + const left = content + panelInset + const lights = macVerticalTrafficLights(zoom) + const right = lights.width / zoom + pocketPadding + const bottom = (lights.y + trafficLightSize) / zoom + pocketPadding + const width = right - left + + if (width <= 0) return + + // The pocket's corner is concentric with the zoom button. + const corner = trafficLightSize / 2 / zoom + pocketPadding + // As the panel's edge reaches the pocket's, its two corners shrink together so the bend flattens into the panel's + // own rounded corner. + const scale = Math.min(1, width / (panelRadius + corner)) + + return { left, right, bottom, top: panelInset, outer: panelRadius * scale, inner: corner * scale } +} + +type Pocket = NonNullable> + +// The panel's edge from its start side, around the pocket, to its top edge, pushed `out` pixels away from the panel. +function edge(pocket: Pocket, out: number) { + const { left, right, bottom, top, outer, inner } = pocket + + return [ + `M ${left - out} ${bottom + outer}`, + `A ${outer + out} ${outer + out} 0 0 1 ${left + outer} ${bottom - out}`, + `L ${right - inner} ${bottom - out}`, + `A ${inner - out} ${inner - out} 0 0 0 ${right - out} ${bottom - inner}`, + `L ${right - out} ${top + panelRadius}`, + `A ${panelRadius + out} ${panelRadius + out} 0 0 1 ${right + panelRadius} ${top - out}`, + ].join(" ") +} + +// Clears the panel's own corner and hairline, which the bent edge replaces. +function cover(pocket: Pocket) { + const { left, right, bottom, top, outer } = pocket + + return `${edge(pocket, 0)} L ${right + panelRadius} ${top - 2} L ${left - 2} ${top - 2} L ${left - 2} ${bottom + outer} Z` +} + +/** + * Paints the window's deep background over the content panel's top-left corner, so the panel bends around the native + * traffic lights rather than passing under them. `content` is where the content area starts, in CSS pixels from the + * window's left, or undefined without traffic lights; the sidebar's motion paints it on every frame. + */ +export function paintTrafficLightsNotch(svg: SVGSVGElement | undefined, content: number | undefined, zoom: number) { + if (!svg) return + const pocket = content === undefined ? undefined : trafficLightsPocket(content, zoom) + const [fill, line] = svg.children + + if (!pocket) { + svg.style.display = "none" + + return + } + + svg.style.display = "" + fill?.setAttribute("d", cover(pocket)) + // The panel's 0.5px hairline sits just outside its edge. + line?.setAttribute("d", edge(pocket, 0.25)) +} + +export function TrafficLightsNotch(props: { ref: (element: SVGSVGElement) => void }) { + return ( + + ) +}