feat(app): bend the content panel around the macOS traffic lights

This commit is contained in:
Brendonovich
2026-11-05 02:52:03 +00:00
Unverified
parent 9dc81059ee
commit a076967ed0
3 changed files with 147 additions and 0 deletions
+22
View File
@@ -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) {
<Suspense>{props.children}</Suspense>
</PluginServerCover>
</main>
<TrafficLightsNotch
ref={(element) => {
trafficLightsNotch = element
paintNotch()
}}
/>
<CollapsedSidebarToggle />
</div>
{/* On touch devices the active composer moves its actions here: the bottom edge, or the top of the keyboard.
@@ -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)
})
@@ -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<ReturnType<typeof trafficLightsPocket>>
// 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 (
<svg
ref={props.ref}
data-slot="traffic-lights-notch"
aria-hidden="true"
class="pointer-events-none absolute top-0 left-0 z-[5] size-40 overflow-visible"
style={{ display: "none" }}
>
<path class="fill-[var(--v2-background-bg-deep)]" />
{/* The hairline the panels' raised elevation draws around them. */}
<path
fill="none"
stroke-width="0.5"
class="stroke-[var(--v2-alpha-dark-12)] [[data-color-scheme=dark]_&]:stroke-[var(--v2-alpha-light-16)]"
/>
</svg>
)
}