From ee8b98d1b0ed2a78e7a50d0397abe3fa65f8ce69 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Thu, 1 Oct 2026 18:26:46 -0700 Subject: [PATCH] Refine the UI of app-switcher-on-bottom UI --- CHANGELOG | 4 ++ app/ui/dashboard-settings.ts | 7 +-- app/ui/shell/chrome-layer.ts | 84 +++++++++++++++++++++++++++++++++--- app/ui/shell/geometry.ts | 18 ++++++-- app/ui/shell/shell.ts | 7 ++- tests/app-layout.test.cjs | 79 ++++++++++++++++++++++++++++++++- 6 files changed, 186 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6b68dd24..cccf23ec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ # Changelog +## 0.8.2 - Future + +* Add an option to move the app switcher to the right or bottom, and adjust screen depth if bottom + ## 0.8.1 - 2026-09-30 ### Assorted Features and Bug Fixes diff --git a/app/ui/dashboard-settings.ts b/app/ui/dashboard-settings.ts index c07f7b41..6b82638f 100644 --- a/app/ui/dashboard-settings.ts +++ b/app/ui/dashboard-settings.ts @@ -367,15 +367,16 @@ export const appSwitcherPositionSetting = new ConfigSettingEnum({ diff --git a/app/ui/shell/chrome-layer.ts b/app/ui/shell/chrome-layer.ts index 30a644a3..8a6607b5 100644 --- a/app/ui/shell/chrome-layer.ts +++ b/app/ui/shell/chrome-layer.ts @@ -35,6 +35,7 @@ import { switcherPosition, switcherRect, TOP_BAR_HEIGHT, + windowFramed, windowTop, type WindowHeightMode, } from "./geometry"; @@ -291,6 +292,8 @@ export class ShellChromeLayer implements Layer { this.drawSidebar(image, state); } this.drawTopBar(image, state); + const frame = windowFrameRect(state); + if (frame) drawWindowFrame(image, frame); drawAmbientCards(image, topBarSpan(state).right); return image; } @@ -307,6 +310,20 @@ export class ShellChromeLayer implements Layer { this.drawTopBar(canvas, state); const bar = topBarSpan(state); parts.push({ ...shellCrop(canvas, bar.left, windowTop(state.foregroundHeightMode, state.foregroundAppId), bar.right - bar.left, TOP_BAR_HEIGHT, 2), depth: -2 }); + const frame = windowFrameRect(state); + if (frame) { + // Over the top bar, whose bottom row it shares, but at the screen's + // own depth rather than the bar's -2, which on top of a -62 screen + // depth would shift a side off the screen. Split into its two sides + // (corners included) and the top between them, as one surface would + // be almost all transparent. + const frameCanvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0); + drawWindowFrame(frameCanvas, frame); + const [leftKey, rightKey, topKey] = windowFrameKeys(), sideHeight = frame.height - 1; + parts.push(shellCrop(frameCanvas, frame.x, frame.y, FRAME_RADIUS, sideHeight, leftKey)); + parts.push(shellCrop(frameCanvas, frame.x + frame.width - FRAME_RADIUS, frame.y, FRAME_RADIUS, sideHeight, rightKey)); + parts.push(shellCrop(frameCanvas, frame.x + FRAME_RADIUS, frame.y, frame.width - 2 * FRAME_RADIUS, 1, topKey)); + } drawAmbientCards(canvas, bar.right, parts); return parts; } @@ -425,7 +442,10 @@ export class ShellChromeLayer implements Layer { // mode, sidebar focused) it still stops at the strip. const { left: barLeft, right: barRight } = topBarSpan(state); image.fillRect(barLeft, barTop, barRight - barLeft, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK); - image.drawLine(barLeft, barTop + TOP_BAR_HEIGHT - 1, barRight - 1, barTop + TOP_BAR_HEIGHT - 1, BORDER_VALUE); + // A framed window's frame draws this line as its top (drawWindowFrame). + if (!windowFramed(state.foregroundAppId)) { + image.drawLine(barLeft, barTop + TOP_BAR_HEIGHT - 1, barRight - 1, barTop + TOP_BAR_HEIGHT - 1, BORDER_VALUE); + } const now = new Date(); const clock = `${formatClockDate(now)} ${formatClockTime(now)}`; @@ -665,6 +685,55 @@ function attentionDot(value: number): GrayImage { return dot; } +type Rect = { x: number; y: number; width: number; height: number }; + +/** Corner radius of the foreground window's frame. */ +const FRAME_RADIUS = 8; + +/** + * The rounded frame around the foreground window's content (below its top + * bar), when it has one (geometry.ts windowFramed): one pixel all round. + * Its sides run down the pixel just outside each side of the window, and + * its top is the top bar's bottom row, in place of the bar's divider. Its + * bottom is the switcher row's top edge, where drawSeparator draws it so + * the selection tab can divert it. + */ +function windowFrameRect(state: ShellChromeState): Rect | null { + if (!windowFramed(state.foregroundAppId)) return null; + const viewport = appViewportRect(state.foregroundHeightMode, state.foregroundAppId); + return { x: viewport.x - 1, y: viewport.y - 1, width: viewport.width + 2, height: viewport.height + 2 }; +} + +/** Shell surface keys of the window frame's left side, right side and top. */ +let frameKeys: [number, number, number] | undefined; +function windowFrameKeys(): [number, number, number] { + if (!frameKeys) frameKeys = [LayerStack.allocateShellKey(), LayerStack.allocateShellKey(), LayerStack.allocateShellKey()]; + return frameKeys; +} + +/** + * Draw the window frame (see windowFrameRect) but for its bottom row, + * stroked line by line like the selection tab's outline. Outside each + * rounded corner it paints opaque black, so the window's square corners + * don't show past the curve. Everything but the top's straight run lies + * within FRAME_RADIUS of the sides. + */ +function drawWindowFrame(image: GrayImage, frame: Rect): void { + const { x, y, width, height } = frame; + for (let i = 0; i < height - 1; i++) { + const outer = tabInset(i, 0, height, FRAME_RADIUS); + image.fillRect(x, y + i, outer, 1, SHELL_OPAQUE_BLACK); + image.fillRect(x + width - outer, y + i, outer, 1, SHELL_OPAQUE_BLACK); + if (i === 0) { + image.fillRect(x + outer, y, width - 2 * outer, 1, BORDER_VALUE); + continue; + } + const stroke = Math.max(1, 1 + tabInset(i, 1, height - 1, FRAME_RADIUS - 1) - outer); + image.fillRect(x + outer, y + i, stroke, 1, BORDER_VALUE); + image.fillRect(x + width - outer - stroke, y + i, stroke, 1, BORDER_VALUE); + } +} + const TAB_RADIUS = 6; // How far the diversion pokes past the separator into the main area. const TAB_EXTEND = 0; @@ -681,13 +750,18 @@ function drawSeparator( gap: SwitcherCell | null, ): void { if (switcherPosition() === "bottom") { - // Along the row's top edge, the full width of the row. - const y = strip.y, right = strip.x + strip.width - 1; + // Along the row's top edge: the full width of the row, or between the + // corners of the window frame, whose bottom side this is. + const frame = windowFrameRect(state); + const inset = frame ? tabInset(frame.height - 1, 0, frame.height, FRAME_RADIUS) : 0; + const left = frame ? frame.x + inset : strip.x; + const right = frame ? frame.x + frame.width - 1 - inset : strip.x + strip.width - 1; + const y = strip.y; if (gap) { - image.drawLine(strip.x, y, gap.x, y, BORDER_VALUE); + image.drawLine(left, y, gap.x, y, BORDER_VALUE); image.drawLine(gap.x + gap.width, y, right, y, BORDER_VALUE); } else { - image.drawLine(strip.x, y, right, y, BORDER_VALUE); + image.drawLine(left, y, right, y, BORDER_VALUE); } return; } diff --git a/app/ui/shell/geometry.ts b/app/ui/shell/geometry.ts index 2a983b22..de41a0f2 100644 --- a/app/ui/shell/geometry.ts +++ b/app/ui/shell/geometry.ts @@ -29,7 +29,8 @@ export const SIDEBAR_WIDTH = 64; * same 36px (a 32px icon plus 2px either side) as a one-column sidebar slot. * The row is wide enough that it never needs the sidebar's smaller * two-column icons. It comes out of the height available to windows; their - * width stays 576, centred, leaving SIDEBAR_WIDTH / 2 at each side for the + * width stays 576, centred, leaving SIDEBAR_WIDTH / 2 at each side: one + * pixel for the side of the window's frame (windowFramed), the rest for the * whole display's stereo shift (uiDepth). */ export const SWITCHER_ROW_HEIGHT = 36; @@ -108,6 +109,17 @@ export function switcherRect(heightMode: WindowHeightMode, appId?: string): { x: } } +/** + * Whether the foreground window's content gets a rounded frame (drawn by + * the chrome layer): with a reserved bottom switcher row, whose top edge is + * the frame's bottom side, as the top bar's divider is its top. Its left and right sides take the pixel just outside + * the 576-wide window; there's no room in the full-panel mode, nor need + * beside a side strip. + */ +export function windowFramed(appId?: string): boolean { + return switcherRowHeight(appId) > 0; +} + /** * Whether a screen point lies on the switcher's side of the screen, for * touches on the phone's mirror: anywhere in a side strip's column, or from @@ -149,8 +161,8 @@ export function appViewportLeft(appId?: string): number { * Stereo depth of the whole display (Settings > Customization > Depth), in * the firmware's depth units; the shell scene carries it to the compositor, * which shifts the screen and everything drawn over it per lens. Only with - * the switcher at the bottom, where the windows' side margins leave room for - * the shift. + * the switcher at the bottom, where the windows' side margins, less the + * window frame's pixel, leave room for the shift. */ export function uiDepth(): number { return switcherPosition() === "bottom" ? Number(uiDepthSetting.get()) : 0; diff --git a/app/ui/shell/shell.ts b/app/ui/shell/shell.ts index d73f6bdf..5df8d535 100644 --- a/app/ui/shell/shell.ts +++ b/app/ui/shell/shell.ts @@ -58,6 +58,7 @@ import { switcherRowHeight, uiDepth, windowBandHeight, + windowFramed, windowTop, type WindowHeightMode, } from "./geometry"; @@ -938,7 +939,7 @@ class Shell { * foreground window's band (full height for a max-height window, the * vertical-position-dependent 288px band otherwise) plus the switcher: a * side strip's icon columns (minus the outer dead strip the one-column - * variant leaves), or the row under it. + * variant leaves), or the row under it and the window frame's sides. */ screenshotCropRect(): { x: number; y: number; width: number; height: number } { const appId = this.foregroundWindow()?.appId; @@ -950,6 +951,10 @@ class Shell { left = Math.min(left, strip.left); right = Math.max(right, strip.right); } + if (windowFramed(appId)) { + left -= 1; + right += 1; + } const y = windowTop(heightMode, appId); const bottom = y + windowBandHeight(heightMode, appId) + switcherRowHeight(appId); return { x: left, y, width: right - left, height: bottom - y }; diff --git a/tests/app-layout.test.cjs b/tests/app-layout.test.cjs index 1b451f48..49a0972c 100644 --- a/tests/app-layout.test.cjs +++ b/tests/app-layout.test.cjs @@ -85,6 +85,9 @@ test('all explicit size/position combinations stay within the display and align assert.ok(row.y + row.height <= 480); // A reserved bottom row hangs right under the window, as wide as it. if (g.switcherRowHeight(appId)) assert.deepEqual([row.x, row.y, row.width], [rect.x, rect.y + rect.height, rect.width]); + // The frame's sides, just outside the window, survive the + // deepest shift (±62 moves each lens 31px). + if (g.windowFramed(appId)) assert.ok(rect.x - 1 - 31 >= 0 && rect.x + rect.width + 31 < 640); } } } @@ -101,6 +104,7 @@ test('the app switcher can sit on the right edge', () => { assert.equal(g.screenCenterInViewportX(), 320); assert.equal(g.isOnSwitcherEdge(600, 10, 'min'), true); assert.equal(g.isOnSwitcherEdge(10, 200, 'min'), false); + assert.equal(g.windowFramed(), false); // Depth needs the bottom row's side margins. g.settings.uiDepthSetting.value = '32'; assert.equal(g.uiDepth(), 0); @@ -123,15 +127,88 @@ test('a bottom app switcher centres 576-wide windows and hangs one tall tab unde assert.equal(g.switcherRect('min').y, 444); // The true centre is the viewport's own with the window centred. assert.equal(g.screenCenterInViewportX(), 288); - // Depth applies only here. + // Depth applies only here, as does the window frame. g.settings.uiDepthSetting.value = '-48'; assert.equal(g.uiDepth(), -48); + assert.equal(g.windowFramed(), true); // Full panel: windows fill the panel and the row overlays the bottom edge while focused. g.settings.displayModeSetting.value = '640x480'; assert.deepEqual(g.rect('max'), { x: 0, y: 28, width: 640, height: 452 }); assert.deepEqual({ ...g.switcherRect('max') }, { x: 0, y: 444, width: 640, height: 36 }); assert.equal(g.sidebarStripVisible('window'), false); assert.equal(g.sidebarStripVisible('sidebar'), true); + assert.equal(g.windowFramed(), false); +}); + +test('a bottom app switcher frames the foreground window\'s content in a rounded border', () => { + const g = geometry(); + g.settings.appSwitcherPositionSetting.value = 'bottom'; + g.settings.uiDepthSetting.value = '62'; + const graphics = require('../.test-build/app/graphics/image.js'); + const shellScene = require('../.test-build/app/graphics/shell-scene.js'); + const font = { lineHeight: 12, ascent: 10, measureText: (text) => text.length * 4, drawText() {} }; + let nextKey = 100; + const modules = { + '../../graphics/shell-scene': shellScene, '../../graphics/image': graphics, + '../../graphics/ui-fonts': { getDefaultSmallFont: () => font, getDefaultMediumFont: () => font }, + './ambient-cards': { activeAmbientCards: () => [] }, + '../../native/notification-icons': { readActiveNotificationIcons: () => ({ icons: [], stale: false }) }, + '../../native/phone-battery': { readPhoneBatteryState: () => ({ battery: null }) }, + '../../util/render-freshness': { renderPassAllowsStaleData: () => false }, + '../dashboard-settings': { batteryDisplayModeSetting: { get: () => 'icon' } }, + '../clock-format': { formatClockDate: () => '', formatClockTime: () => '' }, + '../layers': { LayerStack: { allocateShellKey: () => nextKey++ } }, + '../menu': { scrollToKeepSelectionVisible: () => 0 }, + './geometry': g, + }; + const context = { exports: {}, require: (name) => modules[name] ?? {} }; + vm.runInNewContext(js(read('app/ui/shell/chrome-layer.ts')), context); + const state = { + windows: [{ attention: false, drawIcon() {} }], selectedIndex: 0, focus: 'window', foregroundHeightMode: 'min', + battery: { headset: null, ring: null, watch: null }, trayIcons: [], + }; + const chrome = new context.exports.ShellChromeLayer(() => state); + const parts = chrome.paintParts(); + // The min band's content spans y=106..365, between the bar's bottom row + // (the frame's top) at 105 and the row's top edge (its bottom) at 366. + const part = (key) => parts.find((p) => p.shellKey === key); + const [left, right, top, strip] = [part(100), part(101), part(102), part(1)]; + assert.deepEqual([left.x, left.y, left.image.width, left.image.height], [31, 105, 8, 261]); + assert.deepEqual([right.x, right.image.width], [601, 8]); + assert.deepEqual([top.x, top.y, top.image.width, top.image.height], [39, 105, 562, 1]); + assert.ok(!left.depth && !right.depth && !top.depth); + const at = (p, x, y) => p.image.pixels[(y - p.y) * p.image.width + x - p.x]; + // Straight sides just outside the window; the top along the bar's bottom row. + assert.equal(at(left, 31, 200), 40); + assert.equal(at(right, 608, 200), 40); + assert.equal(at(top, 300, 105), 40); + // Rounded corners: black outside the curve, the window's own corner masked. + assert.equal(at(left, 31, 105), 1); + assert.equal(at(left, 36, 105), 40); + assert.equal(at(left, 32, 106), 1); + assert.equal(at(left, 32, 365), 1); + assert.equal(at(right, 607, 365), 1); + // The separator is the bottom side, starting where the corner's curve ends. + assert.equal(at(strip, 35, 366), 1); + assert.equal(at(strip, 36, 366), 40); + assert.equal(at(strip, 603, 366), 40); + assert.equal(at(strip, 604, 366), 1); + // Parts after the -2 top bar, so the frame draws over it. + assert.ok(parts.indexOf(part(2)) < parts.indexOf(left)); + shellScene.encodeShellScene(parts, g.uiDepth()); + // The flat paint matches. The bar's own divider gives way to the frame's + // top, and the frame stops short of the bar. + const image = chrome.paint(); + assert.equal(image.pixels[200 * 640 + 31], 40); + assert.equal(image.pixels[200 * 640 + 608], 40); + assert.equal(image.pixels[105 * 640 + 33], 1); + assert.equal(image.pixels[105 * 640 + 300], 40); + assert.equal(image.pixels[90 * 640 + 31], 0); + const bar = part(2); + assert.equal(bar.image.pixels[(105 - bar.y) * bar.image.width + 300 - bar.x], 1); + // No frame in the full-panel mode. + g.settings.displayModeSetting.value = '640x480'; + assert.equal(chrome.paintParts().filter((p) => p.shellKey >= 100).length, 0); }); // Exercise the real worker message handler with platform work stubbed out.