forked from Blendman974/faceclaw
Add an option to move the app switcher to the right or bottom, and adjust screen depth if bottom
This commit is contained in:
1 parent
46fded856a
commit
8f99779f98
21 files changed
+827
-286
No files matched your search
+286
-146
@@ -16,6 +16,7 @@ import {
|
||||
phoneBatteryVisibilitySetting,
|
||||
ringBatteryVisibilitySetting,
|
||||
watchBatteryVisibilitySetting,
|
||||
type AppSwitcherPosition,
|
||||
type BatteryIndicatorVisibility,
|
||||
} from "../dashboard-settings";
|
||||
import { formatClockDate, formatClockTime } from "../clock-format";
|
||||
@@ -24,34 +25,43 @@ import { Layer, LayerStack } from "../layers";
|
||||
import { scrollToKeepSelectionVisible } from "../menu";
|
||||
import { lineStep } from "../metrics";
|
||||
import {
|
||||
appViewportRect,
|
||||
MIN_WINDOW_HEIGHT,
|
||||
minWindowTop,
|
||||
SHELL_OPAQUE_BLACK,
|
||||
SIDEBAR_WIDTH,
|
||||
sidebarStripVisible,
|
||||
SWITCHER_ROW_HEIGHT,
|
||||
switcherPosition,
|
||||
switcherRect,
|
||||
TOP_BAR_HEIGHT,
|
||||
windowTop,
|
||||
type WindowHeightMode,
|
||||
} from "./geometry";
|
||||
|
||||
/**
|
||||
* Sidebar icon layout comes in two variants. Few enough windows for a single
|
||||
* column keeps the roomy 36px slots (32px icons) right-aligned against the
|
||||
* separator; past one column's worth it switches to two 32px slots (28px
|
||||
* icons) that exactly fill the 64px sidebar. In the two-column variant the
|
||||
* right column (against the app area) fills first and windows past that
|
||||
* overflow into the left column, so the common case keeps every icon next to
|
||||
* the content it belongs to.
|
||||
* Sidebar icon layout (the app switcher on the left or right edge) comes in
|
||||
* two variants. Few enough windows for a single column keeps the roomy 36px
|
||||
* slots (32px icons) aligned against the separator; past one column's worth
|
||||
* it switches to two 32px slots (28px icons) that exactly fill the 64px
|
||||
* sidebar. In the two-column variant the column against the app area fills
|
||||
* first and windows past that overflow into the outer column, so the common
|
||||
* case keeps every icon next to the content it belongs to. A bottom row
|
||||
* always uses the roomy slots, laid out left to right.
|
||||
*/
|
||||
type SidebarVariant = { columns: number; columnWidth: number; iconSize: number };
|
||||
const ONE_COLUMN: SidebarVariant = { columns: 1, columnWidth: 36, iconSize: 32 };
|
||||
const TWO_COLUMN: SidebarVariant = { columns: 2, columnWidth: 32, iconSize: 28 };
|
||||
|
||||
const ICON_SPACING = 8;
|
||||
/** Icon list top/bottom margins within the sidebar band, below the top bar. */
|
||||
/** Icon list top/bottom margins within the sidebar band, below the top bar (and a bottom row's end margins). */
|
||||
const LIST_MARGIN = 10;
|
||||
const LIST_HEIGHT = MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 2 * LIST_MARGIN;
|
||||
|
||||
/** Bottom-row icons: one tall tab's worth of row, the icon inset 2px all round. */
|
||||
const ROW_ICON_SIZE = SWITCHER_ROW_HEIGHT - 4;
|
||||
const ROW_STEP = ROW_ICON_SIZE + ICON_SPACING;
|
||||
|
||||
/** Icon rows that fit in one sidebar column. */
|
||||
function rowsPerColumn(variant: SidebarVariant): number {
|
||||
return Math.max(1, ((LIST_HEIGHT + ICON_SPACING) / (variant.iconSize + ICON_SPACING)) | 0);
|
||||
@@ -61,23 +71,14 @@ function sidebarVariant(windowCount: number): SidebarVariant {
|
||||
return windowCount > rowsPerColumn(ONE_COLUMN) ? TWO_COLUMN : ONE_COLUMN;
|
||||
}
|
||||
|
||||
/** Left x of a sidebar column; columns pack rightward against the separator. */
|
||||
function columnLeft(variant: SidebarVariant, column: number): number {
|
||||
return SIDEBAR_WIDTH - (variant.columns - column) * variant.columnWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Column and top y of a visible sidebar slot; `position` counts from the
|
||||
* first visible (scrolled-to) icon. Slots fill the rightmost column top to
|
||||
* bottom, then overflow leftward. The single source of slot geometry for
|
||||
* both drawing and hit testing.
|
||||
* Left x of a sidebar column. Column 0 sits against the separator (the
|
||||
* strip's inner edge, toward the app area); further columns pack outward.
|
||||
*/
|
||||
function slotPosition(variant: SidebarVariant, listTop: number, position: number): { column: number; y: number } {
|
||||
const rows = rowsPerColumn(variant);
|
||||
return {
|
||||
column: variant.columns - 1 - ((position / rows) | 0),
|
||||
y: listTop + (position % rows) * (variant.iconSize + ICON_SPACING),
|
||||
};
|
||||
function columnLeft(variant: SidebarVariant, column: number, position: AppSwitcherPosition): number {
|
||||
return position === "right"
|
||||
? G2_LENS_WIDTH - SIDEBAR_WIDTH + column * variant.columnWidth
|
||||
: SIDEBAR_WIDTH - (column + 1) * variant.columnWidth;
|
||||
}
|
||||
|
||||
/** Top y of the sidebar's icon list (below the band's top bar). */
|
||||
@@ -86,12 +87,88 @@ function sidebarListTop(appId?: string): number {
|
||||
}
|
||||
|
||||
/**
|
||||
* Left edge of the sidebar region that actually holds icons: the one-column
|
||||
* variant leaves a dead strip left of its single right-aligned column.
|
||||
* Screenshot cropping uses this to trim the unused part.
|
||||
* One visible switcher icon's selection cell: the 2px-margined box around
|
||||
* the icon that a selection tab or box fills. `atSeparator` is whether the
|
||||
* cell touches the separator, so the selection can divert it (a tab) rather
|
||||
* than sit apart from it (a box, for sidebar overflow-column icons).
|
||||
*/
|
||||
export function sidebarContentLeft(windowCount: number): number {
|
||||
return columnLeft(sidebarVariant(windowCount), 0);
|
||||
type SwitcherCell = { x: number; y: number; width: number; height: number; atSeparator: boolean };
|
||||
|
||||
type SwitcherLayout = {
|
||||
position: AppSwitcherPosition;
|
||||
iconSize: number;
|
||||
/** How many icons fit at once; the list scrolls to keep the selection among them. */
|
||||
visibleCount: number;
|
||||
/**
|
||||
* Cell of the icon `slot` places past the first visible (scrolled-to) one.
|
||||
* The single source of slot geometry for both drawing and hit testing.
|
||||
*/
|
||||
cell: (slot: number) => SwitcherCell;
|
||||
};
|
||||
|
||||
/** Switcher geometry for the foreground window (a bottom row sits under it). */
|
||||
function switcherLayout(windowCount: number, heightMode: WindowHeightMode, appId?: string): SwitcherLayout {
|
||||
const position = switcherPosition();
|
||||
if (position === "bottom") {
|
||||
const row = switcherRect(heightMode, appId);
|
||||
return {
|
||||
position,
|
||||
iconSize: ROW_ICON_SIZE,
|
||||
visibleCount: Math.max(1, ((row.width - 2 * LIST_MARGIN + ICON_SPACING) / ROW_STEP) | 0),
|
||||
cell: (slot) => ({
|
||||
x: row.x + LIST_MARGIN - 2 + slot * ROW_STEP, y: row.y, width: ROW_ICON_SIZE + 4, height: SWITCHER_ROW_HEIGHT,
|
||||
atSeparator: true,
|
||||
}),
|
||||
};
|
||||
}
|
||||
// Slots fill the column against the separator top to bottom, then
|
||||
// overflow outward.
|
||||
const variant = sidebarVariant(windowCount);
|
||||
const rows = rowsPerColumn(variant);
|
||||
const listTop = sidebarListTop(appId);
|
||||
return {
|
||||
position,
|
||||
iconSize: variant.iconSize,
|
||||
visibleCount: rows * variant.columns,
|
||||
cell: (slot) => {
|
||||
const column = (slot / rows) | 0;
|
||||
return {
|
||||
x: columnLeft(variant, column, position),
|
||||
y: listTop + (slot % rows) * (variant.iconSize + ICON_SPACING) - 2,
|
||||
width: variant.columnWidth,
|
||||
height: variant.iconSize + 4,
|
||||
atSeparator: column === 0,
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Horizontal extent of the sidebar region that actually holds icons: the
|
||||
* one-column variant leaves a dead strip on the outer side of its single
|
||||
* column. Screenshot cropping uses this to trim the unused part.
|
||||
*/
|
||||
export function sidebarContentSpan(windowCount: number): { left: number; right: number } {
|
||||
const variant = sidebarVariant(windowCount);
|
||||
const width = variant.columns * variant.columnWidth;
|
||||
return switcherPosition() === "right"
|
||||
? { left: G2_LENS_WIDTH - SIDEBAR_WIDTH, right: G2_LENS_WIDTH - SIDEBAR_WIDTH + width }
|
||||
: { left: SIDEBAR_WIDTH - width, right: SIDEBAR_WIDTH };
|
||||
}
|
||||
|
||||
/**
|
||||
* Horizontal extent of the top bar: the foreground window's, short of a side
|
||||
* strip overlaid on it (full-panel mode, sidebar focused).
|
||||
*/
|
||||
function topBarSpan(state: ShellChromeState): { left: number; right: number } {
|
||||
const viewport = appViewportRect(state.foregroundHeightMode, state.foregroundAppId);
|
||||
let left = viewport.x, right = viewport.x + viewport.width;
|
||||
if (sidebarStripVisible(state.focus, state.foregroundAppId)) {
|
||||
const position = switcherPosition();
|
||||
if (position === "left") left = Math.max(left, SIDEBAR_WIDTH);
|
||||
if (position === "right") right = Math.min(right, G2_LENS_WIDTH - SIDEBAR_WIDTH);
|
||||
}
|
||||
return { left, right };
|
||||
}
|
||||
const NOTIFICATION_ICON_SIZE = 24;
|
||||
const BORDER_VALUE = 40;
|
||||
@@ -195,12 +272,12 @@ export function makeImageWindowIcon(
|
||||
}
|
||||
|
||||
/**
|
||||
* Base layer of the shell surface: the window sidebar on the left and the
|
||||
* status top bar. Everything not explicitly painted stays 0 (transparent on
|
||||
* the color-key shell surface), so the app viewport shows through.
|
||||
* Base layer of the shell surface: the window sidebar (or bottom row) and
|
||||
* the status top bar. Everything not explicitly painted stays 0 (transparent
|
||||
* on the color-key shell surface), so the app viewport shows through.
|
||||
*/
|
||||
export class ShellChromeLayer implements Layer {
|
||||
// First sidebar row shown; adjusted each paint to keep the selection visible.
|
||||
// First switcher icon shown; adjusted each paint to keep the selection visible.
|
||||
private scrollRow = 0;
|
||||
|
||||
constructor(private readonly getState: () => ShellChromeState) {}
|
||||
@@ -214,7 +291,7 @@ export class ShellChromeLayer implements Layer {
|
||||
this.drawSidebar(image, state);
|
||||
}
|
||||
this.drawTopBar(image, state);
|
||||
drawAmbientCards(image);
|
||||
drawAmbientCards(image, topBarSpan(state).right);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -223,13 +300,14 @@ export class ShellChromeLayer implements Layer {
|
||||
if (sidebarStripVisible(state.focus, state.foregroundAppId)) {
|
||||
const canvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
this.drawSidebar(canvas, state);
|
||||
parts.push(shellCrop(canvas, 0, minWindowTop(state.foregroundAppId), SIDEBAR_WIDTH, MIN_WINDOW_HEIGHT, 1));
|
||||
const strip = switcherRect(state.foregroundHeightMode, state.foregroundAppId);
|
||||
parts.push(shellCrop(canvas, strip.x, strip.y, strip.width, strip.height, 1));
|
||||
}
|
||||
const canvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
this.drawTopBar(canvas, state);
|
||||
const left = sidebarStripVisible(state.focus, state.foregroundAppId) ? SIDEBAR_WIDTH : 0;
|
||||
parts.push({ ...shellCrop(canvas, left, windowTop(state.foregroundHeightMode, state.foregroundAppId), G2_LENS_WIDTH-left, TOP_BAR_HEIGHT, 2), depth: -2 });
|
||||
drawAmbientCards(canvas, parts);
|
||||
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 });
|
||||
drawAmbientCards(canvas, bar.right, parts);
|
||||
return parts;
|
||||
}
|
||||
|
||||
@@ -239,19 +317,18 @@ export class ShellChromeLayer implements Layer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Which window's sidebar icon is under (x, y) on screen, if any — the same
|
||||
* slot geometry drawSidebar uses, so a touch on the phone's mirror lands on
|
||||
* the icon the mirror showed.
|
||||
* Which window's switcher icon is under (x, y) on screen, if any — the
|
||||
* same slot geometry drawSidebar uses, so a touch on the phone's mirror
|
||||
* lands on the icon the mirror showed.
|
||||
*/
|
||||
windowIndexAt(x: number, y: number, windowCount: number): number | null {
|
||||
if (x < 0 || x >= SIDEBAR_WIDTH || windowCount === 0) return null;
|
||||
const variant = sidebarVariant(windowCount);
|
||||
const listTop = sidebarListTop(this.getState().foregroundAppId);
|
||||
const lastVisible = Math.min(windowCount, this.scrollRow + rowsPerColumn(variant) * variant.columns);
|
||||
if (windowCount === 0) return null;
|
||||
const state = this.getState();
|
||||
const layout = switcherLayout(windowCount, state.foregroundHeightMode, state.foregroundAppId);
|
||||
const lastVisible = Math.min(windowCount, this.scrollRow + layout.visibleCount);
|
||||
for (let index = this.scrollRow; index < lastVisible; index++) {
|
||||
const { column, y: slotY } = slotPosition(variant, listTop, index - this.scrollRow);
|
||||
const left = columnLeft(variant, column);
|
||||
if (x >= left && x < left + variant.columnWidth && y >= slotY - 2 && y < slotY + variant.iconSize + 2) {
|
||||
const cell = layout.cell(index - this.scrollRow);
|
||||
if (x >= cell.x && x < cell.x + cell.width && y >= cell.y && y < cell.y + cell.height) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
@@ -259,60 +336,48 @@ export class ShellChromeLayer implements Layer {
|
||||
}
|
||||
|
||||
private drawSidebar(image: GrayImage, state: ShellChromeState): void {
|
||||
// Align the sidebar with the app's preferred band. Legacy tall terminal
|
||||
// sessions keep the sidebar at the global band position.
|
||||
const bandTop = minWindowTop(state.foregroundAppId);
|
||||
const bandBottom = bandTop + MIN_WINDOW_HEIGHT;
|
||||
image.fillRect(0, bandTop, SIDEBAR_WIDTH, MIN_WINDOW_HEIGHT, SHELL_OPAQUE_BLACK);
|
||||
// A side strip aligns with the app's preferred band (legacy tall
|
||||
// terminal sessions keep it at the global band position); a bottom row
|
||||
// sits under the foreground window.
|
||||
const strip = switcherRect(state.foregroundHeightMode, state.foregroundAppId);
|
||||
image.fillRect(strip.x, strip.y, strip.width, strip.height, SHELL_OPAQUE_BLACK);
|
||||
|
||||
// Scroll the icon list to keep the selection visible; chevrons mark
|
||||
// windows off-screen above/below. Icons fill the right column top to
|
||||
// bottom, then overflow into the left one, so a visible slot's column is
|
||||
// decided by its position within the scrolled window.
|
||||
// windows off-screen before/after. Sidebar icons fill the column against
|
||||
// the separator top to bottom, then overflow into the outer one, so a
|
||||
// visible slot's column is decided by its position within the scrolled
|
||||
// window.
|
||||
const count = state.windows.length;
|
||||
const variant = sidebarVariant(count);
|
||||
const iconSize = variant.iconSize;
|
||||
const iconMarginX = ((variant.columnWidth - iconSize) / 2) | 0;
|
||||
// Column index of the rightmost column (the one that fills first).
|
||||
const firstColumn = variant.columns - 1;
|
||||
const listTop = sidebarListTop(state.foregroundAppId);
|
||||
const visibleCount = rowsPerColumn(variant) * variant.columns;
|
||||
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, visibleCount, count);
|
||||
const lastVisible = Math.min(count, this.scrollRow + visibleCount);
|
||||
const slotOf = (index: number) => slotPosition(variant, listTop, index - this.scrollRow);
|
||||
const layout = switcherLayout(count, state.foregroundHeightMode, state.foregroundAppId);
|
||||
const { iconSize, position } = layout;
|
||||
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, layout.visibleCount, count);
|
||||
const lastVisible = Math.min(count, this.scrollRow + layout.visibleCount);
|
||||
const cellOf = (index: number) => layout.cell(index - this.scrollRow);
|
||||
|
||||
// The selection is a "diversion" of the sidebar/main separator line: the
|
||||
// line bulges right around the selected icon (rounded on the left, open
|
||||
// to the main area on the right), so the separator is drawn with a gap
|
||||
// there. When the sidebar has focus, the diversion is filled white and
|
||||
// the icon drawn inverted. Only the right column touches the separator;
|
||||
// a selected overflow icon gets a self-contained box instead.
|
||||
const sep = SIDEBAR_WIDTH - 1;
|
||||
// Start beside the app content, leaving the area alongside the top bar open.
|
||||
const sepTop = Math.max(bandTop, windowTop(state.foregroundHeightMode, state.foregroundAppId) + TOP_BAR_HEIGHT);
|
||||
// The selection is a "diversion" of the switcher/main separator line:
|
||||
// the line bulges toward the main area around the selected icon (rounded
|
||||
// on the outer side, open to the main area), so the separator is drawn
|
||||
// with a gap there. When the switcher has focus, the diversion is filled
|
||||
// white and the icon drawn inverted. Only the sidebar column against the
|
||||
// separator touches it; a selected overflow icon gets a self-contained
|
||||
// box instead.
|
||||
const selVisible = state.selectedIndex >= this.scrollRow && state.selectedIndex < lastVisible;
|
||||
const selSlot = selVisible ? slotOf(state.selectedIndex) : null;
|
||||
const selTabTop = selSlot && selSlot.column === firstColumn ? selSlot.y - 2 : null;
|
||||
if (selTabTop !== null) {
|
||||
image.drawLine(sep, sepTop, sep, selTabTop, BORDER_VALUE);
|
||||
image.drawLine(sep, selTabTop + iconSize + 4, sep, bandBottom - 1, BORDER_VALUE);
|
||||
} else {
|
||||
image.drawLine(sep, sepTop, sep, bandBottom - 1, BORDER_VALUE);
|
||||
}
|
||||
const selCell = selVisible ? cellOf(state.selectedIndex) : null;
|
||||
drawSeparator(image, state, strip, selCell?.atSeparator ? selCell : null);
|
||||
|
||||
for (let index = this.scrollRow; index < lastVisible; index++) {
|
||||
const window = state.windows[index]!;
|
||||
const { column, y } = slotOf(index);
|
||||
const left = columnLeft(variant, column);
|
||||
const x = left + iconMarginX;
|
||||
const cell = cellOf(index);
|
||||
const x = cell.x + (((cell.width - iconSize) / 2) | 0);
|
||||
const y = cell.y + (((cell.height - iconSize) / 2) | 0);
|
||||
const selected = index === state.selectedIndex;
|
||||
const focused = selected && state.focus === "sidebar";
|
||||
if (selected && column === firstColumn) {
|
||||
drawSelectionTab(image, left, y - 2, y + iconSize + 2, focused);
|
||||
if (selected && cell.atSeparator) {
|
||||
drawSelectionTab(image, cell, position, focused);
|
||||
} else if (selected) {
|
||||
// Spans the full column: only 2px of margin flanks the icon in its
|
||||
// slot, so anything wider would clip at the screen edge.
|
||||
drawSelectionBox(image, left, y - 2, variant.columnWidth, iconSize + 4, focused);
|
||||
drawSelectionBox(image, cell.x, cell.y, cell.width, cell.height, focused);
|
||||
}
|
||||
// Paint unselected icons into their own resource so only the replayed copy moves.
|
||||
const icon = selected ? image : new GrayImage(iconSize, iconSize + 1);
|
||||
@@ -327,14 +392,26 @@ export class ShellChromeLayer implements Layer {
|
||||
if (!selected) image.drawDepthImage(icon, x, y - 1, -2);
|
||||
}
|
||||
|
||||
if (position === "bottom") {
|
||||
// Chevrons sit in the row's end margins, pointing off either end.
|
||||
const chevronY = strip.y + ((strip.height / 2) | 0);
|
||||
if (this.scrollRow > 0) {
|
||||
drawChevron(image, strip.x + 6, chevronY, "left");
|
||||
}
|
||||
if (lastVisible < count) {
|
||||
drawChevron(image, strip.x + strip.width - 6, chevronY, "right");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Chevrons center over the icon area, which in the one-column variant is
|
||||
// narrower than the sidebar strip.
|
||||
const chevronX = ((columnLeft(variant, 0) + SIDEBAR_WIDTH) / 2) | 0;
|
||||
const span = sidebarContentSpan(count);
|
||||
const chevronX = ((span.left + span.right) / 2) | 0;
|
||||
if (this.scrollRow > 0) {
|
||||
drawChevron(image, chevronX, bandTop + TOP_BAR_HEIGHT + 6, -1);
|
||||
drawChevron(image, chevronX, strip.y + TOP_BAR_HEIGHT + 6, "up");
|
||||
}
|
||||
if (lastVisible < count) {
|
||||
drawChevron(image, chevronX, bandBottom - 6, 1);
|
||||
drawChevron(image, chevronX, strip.y + strip.height - 6, "down");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,11 +421,11 @@ export class ShellChromeLayer implements Layer {
|
||||
// its height mode puts that (screen top for max height). It moves when
|
||||
// the foreground switches to a window of a different height.
|
||||
const barTop = windowTop(state.foregroundHeightMode, state.foregroundAppId);
|
||||
// The bar spans the app viewport; with the sidebar overlaid (full-panel
|
||||
// mode, sidebar focused) it still starts past the strip.
|
||||
const barLeft = sidebarStripVisible(state.focus, state.foregroundAppId) ? SIDEBAR_WIDTH : 0;
|
||||
image.fillRect(barLeft, barTop, G2_LENS_WIDTH - barLeft, TOP_BAR_HEIGHT, SHELL_OPAQUE_BLACK);
|
||||
image.drawLine(barLeft, barTop + TOP_BAR_HEIGHT - 1, G2_LENS_WIDTH - 1, barTop + TOP_BAR_HEIGHT - 1, BORDER_VALUE);
|
||||
// The bar spans the app viewport; with a side strip overlaid (full-panel
|
||||
// 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);
|
||||
|
||||
const now = new Date();
|
||||
const clock = `${formatClockDate(now)} ${formatClockTime(now)}`;
|
||||
@@ -356,7 +433,7 @@ export class ShellChromeLayer implements Layer {
|
||||
const textY = barTop + Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0);
|
||||
image.drawText(font, clockX, textY, clock, 210);
|
||||
|
||||
const batteryLeft = this.drawTopBarBatteries(image, state, barTop);
|
||||
const batteryLeft = this.drawTopBarBatteries(image, state, barTop, barRight);
|
||||
const trayLeft = drawTrayIcons(image, state.trayIcons, batteryLeft, barTop);
|
||||
|
||||
const iconsX = clockX + font.measureText(clock) + 16;
|
||||
@@ -379,9 +456,10 @@ export class ShellChromeLayer implements Layer {
|
||||
* running the Faceclaw watch app is reachable (no placeholder otherwise).
|
||||
* The Settings > Customization > Battery indicators submenu picks the style (label beside a gauge icon or percentage, or stacked above
|
||||
* either) and, per device, whether the indicator shows always, only below
|
||||
* 50%, or never. Returns the left edge of the battery block.
|
||||
* 50%, or never. `barRight` is the bar's right edge (short of a right-hand
|
||||
* sidebar). Returns the left edge of the battery block.
|
||||
*/
|
||||
private drawTopBarBatteries(image: GrayImage, state: ShellChromeState, barTop: number): number {
|
||||
private drawTopBarBatteries(image: GrayImage, state: ShellChromeState, barTop: number, barRight: number): number {
|
||||
const mode = batteryDisplayModeSetting.get();
|
||||
const items: BatteryItem[] = [];
|
||||
const phone = readPhoneBatteryState();
|
||||
@@ -401,9 +479,9 @@ export class ShellChromeLayer implements Layer {
|
||||
pushBatteryItem(items, ringBatteryVisibilitySetting.get(), "R1", state.battery.ring,
|
||||
Boolean(state.battery.ringCharging));
|
||||
}
|
||||
if (!items.length) return G2_LENS_WIDTH;
|
||||
if (!items.length) return barRight;
|
||||
if (mode === "stacked" || mode === "stacked-percentage") {
|
||||
return drawStackedBatteries(image, items, barTop, mode === "stacked-percentage");
|
||||
return drawStackedBatteries(image, items, barTop, barRight, mode === "stacked-percentage");
|
||||
}
|
||||
|
||||
const font = getDefaultSmallFont();
|
||||
@@ -411,7 +489,7 @@ export class ShellChromeLayer implements Layer {
|
||||
const labelGap = 5;
|
||||
const itemGap = 12;
|
||||
const textY = barTop + Math.max(0, ((TOP_BAR_HEIGHT - font.lineHeight) / 2) | 0);
|
||||
let x = G2_LENS_WIDTH - BATTERY_BLOCK_RIGHT_MARGIN;
|
||||
let x = barRight - BATTERY_BLOCK_RIGHT_MARGIN;
|
||||
for (let index = items.length - 1; index >= 0; index--) {
|
||||
const item = items[index]!;
|
||||
const percentText = `${item.percent}%`;
|
||||
@@ -474,14 +552,14 @@ const STACKED_ITEM_GAP = 10;
|
||||
|
||||
/**
|
||||
* Stacked styles: each label centered above its gauge icon (or percentage
|
||||
* text), right-aligned in the bar. Returns the left edge of the battery
|
||||
* block.
|
||||
* text), right-aligned in the bar (ending at barRight). Returns the left edge
|
||||
* of the battery block.
|
||||
*/
|
||||
function drawStackedBatteries(image: GrayImage, items: BatteryItem[], barTop: number, percentage: boolean): number {
|
||||
function drawStackedBatteries(image: GrayImage, items: BatteryItem[], barTop: number, barRight: number, percentage: boolean): number {
|
||||
const font = getFont("terminusv12");
|
||||
const labelTop = barTop + STACKED_LABEL_BASELINE - font.ascent;
|
||||
const percentTop = barTop + STACKED_PERCENT_BASELINE - font.ascent;
|
||||
let x = G2_LENS_WIDTH - BATTERY_BLOCK_RIGHT_MARGIN;
|
||||
let x = barRight - BATTERY_BLOCK_RIGHT_MARGIN;
|
||||
for (let index = items.length - 1; index >= 0; index--) {
|
||||
const item = items[index]!;
|
||||
const percentText = `${item.percent}%`;
|
||||
@@ -521,16 +599,18 @@ const AMBIENT_MAX_LINES_PER_CARD = 3;
|
||||
/**
|
||||
* Paint the active ambient cards bottom-up: the oldest card sits at the very
|
||||
* bottom of the window band and newer ones stack above it. Cards that would
|
||||
* cross into the top bar are dropped rather than clipped.
|
||||
* cross into the top bar are dropped rather than clipped. `right` is the
|
||||
* top bar's right edge, which the cards align to.
|
||||
*/
|
||||
const ambientKeys = new Map<string, number>();
|
||||
function drawAmbientCards(image: GrayImage, parts?: Plane[]): void {
|
||||
function drawAmbientCards(image: GrayImage, right: number, parts?: Plane[]): void {
|
||||
const cards = activeAmbientCards();
|
||||
if (!cards.length) return;
|
||||
const font = getDefaultSmallFont();
|
||||
const bandTop = minWindowTop();
|
||||
const bandBottom = bandTop + MIN_WINDOW_HEIGHT;
|
||||
const x = G2_LENS_WIDTH - AMBIENT_CARD_WIDTH - AMBIENT_CARD_MARGIN;
|
||||
// Right-aligned with the top bar: clear of a right-hand sidebar.
|
||||
const x = right - AMBIENT_CARD_WIDTH - AMBIENT_CARD_MARGIN;
|
||||
const textWidth = AMBIENT_CARD_WIDTH - 2 * AMBIENT_CARD_PADDING_X;
|
||||
let bottom = bandBottom - AMBIENT_CARD_MARGIN;
|
||||
for (const card of cards) {
|
||||
@@ -591,33 +671,81 @@ const TAB_EXTEND = 0;
|
||||
const TAB_STROKE = 150;
|
||||
|
||||
/**
|
||||
* Draw the selection "diversion" of the separator line around a sidebar icon
|
||||
* in the rightmost column: rounded on the left, square and open on the right,
|
||||
* extending a few px past the separator into the main area. Focused = filled
|
||||
* white; otherwise an outline. `left` is the column's left edge, which the
|
||||
* rounded corners curve in from.
|
||||
* Draw the switcher/main separator line along the strip's inner edge, with
|
||||
* a gap where the selection tab `gap` diverts it.
|
||||
*/
|
||||
function drawSelectionTab(image: GrayImage, left: number, top: number, bottom: number, focused: boolean): void {
|
||||
const right = SIDEBAR_WIDTH - 1 + TAB_EXTEND;
|
||||
if (focused) {
|
||||
for (let yy = top; yy < bottom; yy++) {
|
||||
const x = left + tabLeftInset(yy, top, bottom, TAB_RADIUS);
|
||||
image.fillRect(x, yy, right - x + 1, 1, 255);
|
||||
function drawSeparator(
|
||||
image: GrayImage,
|
||||
state: ShellChromeState,
|
||||
strip: { x: number; y: number; width: number; height: number },
|
||||
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;
|
||||
if (gap) {
|
||||
image.drawLine(strip.x, 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);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Outline: the tab shape minus the same shape inset by a pixel, row by row.
|
||||
// Stroking the curve one pixel per row instead would leave gaps wherever the
|
||||
// corner steps in by more than one pixel, and the top/bottom edges have to
|
||||
// start at the same inset the curve uses or they part company from it.
|
||||
for (let yy = top; yy < bottom; yy++) {
|
||||
const outer = left + tabLeftInset(yy, top, bottom, TAB_RADIUS);
|
||||
// The top and bottom rows are the horizontal edges: solid out to the open
|
||||
// right side. In between only the left edge is stroked.
|
||||
const inner = yy > top && yy < bottom - 1
|
||||
? left + 1 + tabLeftInset(yy, top + 1, bottom - 1, TAB_RADIUS - 1)
|
||||
: right + 1;
|
||||
image.fillRect(outer, yy, Math.max(1, Math.min(inner, right + 1) - outer), 1, TAB_STROKE);
|
||||
const sep = switcherPosition() === "right" ? strip.x : strip.x + strip.width - 1;
|
||||
const bottom = strip.y + strip.height - 1;
|
||||
// Start beside the app content, leaving the area alongside the top bar open.
|
||||
const top = Math.max(strip.y, windowTop(state.foregroundHeightMode, state.foregroundAppId) + TOP_BAR_HEIGHT);
|
||||
if (gap) {
|
||||
image.drawLine(sep, top, sep, gap.y, BORDER_VALUE);
|
||||
image.drawLine(sep, gap.y + gap.height, sep, bottom, BORDER_VALUE);
|
||||
} else {
|
||||
image.drawLine(sep, top, sep, bottom, BORDER_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the selection "diversion" of the separator line around a switcher
|
||||
* icon whose cell touches the separator: rounded on the outer side, square
|
||||
* and open on the side toward the main area, extending TAB_EXTEND px past
|
||||
* the separator into it. Focused = filled white; otherwise an outline.
|
||||
*
|
||||
* Drawn in tab-local coordinates: `along` runs parallel to the separator,
|
||||
* `across` from the rounded outer edge (0) to the open edge, and fillAcross
|
||||
* maps a run of one along-line onto the screen for the strip's orientation.
|
||||
*/
|
||||
function drawSelectionTab(image: GrayImage, cell: SwitcherCell, position: AppSwitcherPosition, focused: boolean): void {
|
||||
const vertical = position !== "bottom";
|
||||
const along = vertical ? cell.height : cell.width;
|
||||
const across = (vertical ? cell.width : cell.height) + TAB_EXTEND;
|
||||
const fillAcross = (i: number, from: number, to: number, value: number) => {
|
||||
switch (position) {
|
||||
case "left":
|
||||
image.fillRect(cell.x + from, cell.y + i, to - from, 1, value);
|
||||
break;
|
||||
case "right":
|
||||
image.fillRect(cell.x + cell.width - to, cell.y + i, to - from, 1, value);
|
||||
break;
|
||||
default:
|
||||
image.fillRect(cell.x + i, cell.y + cell.height - to, 1, to - from, value);
|
||||
}
|
||||
};
|
||||
if (focused) {
|
||||
for (let i = 0; i < along; i++) {
|
||||
fillAcross(i, tabInset(i, 0, along, TAB_RADIUS), across, 255);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Outline: the tab shape minus the same shape inset by a pixel, line by
|
||||
// line. Stroking the curve one pixel per line instead would leave gaps
|
||||
// wherever the corner steps in by more than one pixel, and the two edges
|
||||
// running across have to start at the same inset the curve uses or they
|
||||
// part company from it.
|
||||
for (let i = 0; i < along; i++) {
|
||||
const outer = tabInset(i, 0, along, TAB_RADIUS);
|
||||
// The first and last lines are the edges running across: solid out to
|
||||
// the open side. In between only the outer edge is stroked.
|
||||
const inner = i > 0 && i < along - 1 ? 1 + tabInset(i, 1, along - 1, TAB_RADIUS - 1) : across;
|
||||
fillAcross(i, outer, Math.max(outer + 1, Math.min(inner, across)), TAB_STROKE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -634,24 +762,36 @@ function drawSelectionBox(image: GrayImage, x: number, y: number, width: number,
|
||||
}
|
||||
}
|
||||
|
||||
/** Left boundary x of the tab at row yy: 0 in the middle, curving to the rounded left corners. */
|
||||
function tabLeftInset(yy: number, top: number, bottom: number, radius: number): number {
|
||||
const cy = yy + 0.5;
|
||||
let dy = 0;
|
||||
if (cy < top + radius) {
|
||||
dy = top + radius - cy;
|
||||
} else if (cy > bottom - radius) {
|
||||
dy = cy - (bottom - radius);
|
||||
/**
|
||||
* How far the tab's outer edge is inset at along-line i (of the tab spanning
|
||||
* start..end): 0 in the middle, curving in toward the rounded corners.
|
||||
*/
|
||||
function tabInset(i: number, start: number, end: number, radius: number): number {
|
||||
const c = i + 0.5;
|
||||
let d = 0;
|
||||
if (c < start + radius) {
|
||||
d = start + radius - c;
|
||||
} else if (c > end - radius) {
|
||||
d = c - (end - radius);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return Math.max(0, Math.round(radius - Math.sqrt(Math.max(0, radius * radius - dy * dy))));
|
||||
return Math.max(0, Math.round(radius - Math.sqrt(Math.max(0, radius * radius - d * d))));
|
||||
}
|
||||
|
||||
/** Small triangle marker for sidebar overflow; direction -1 = up, 1 = down. */
|
||||
function drawChevron(image: GrayImage, centerX: number, y: number, direction: -1 | 1): void {
|
||||
/**
|
||||
* Small triangle marker for switcher overflow, pointing the way the hidden
|
||||
* icons are; (x, y) is the middle of its base.
|
||||
*/
|
||||
function drawChevron(image: GrayImage, x: number, y: number, direction: "up" | "down" | "left" | "right"): void {
|
||||
const half = 5;
|
||||
const tipY = direction < 0 ? y - 3 : y + 3;
|
||||
image.drawLine(centerX - half, y, centerX, tipY, 140);
|
||||
image.drawLine(centerX, tipY, centerX + half, y, 140);
|
||||
if (direction === "left" || direction === "right") {
|
||||
const tipX = direction === "left" ? x - 3 : x + 3;
|
||||
image.drawLine(x, y - half, tipX, y, 140);
|
||||
image.drawLine(tipX, y, x, y + half, 140);
|
||||
return;
|
||||
}
|
||||
const tipY = direction === "up" ? y - 3 : y + 3;
|
||||
image.drawLine(x - half, y, x, tipY, 140);
|
||||
image.drawLine(x, tipY, x + half, y, 140);
|
||||
}
|
||||
+146
-27
@@ -1,5 +1,7 @@
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../../graphics/image";
|
||||
import {
|
||||
appSwitcherPositionSetting,
|
||||
type AppSwitcherPosition,
|
||||
displayModeSetting,
|
||||
type DisplayModeSetting,
|
||||
verticalPositionSetting,
|
||||
@@ -7,19 +9,36 @@ import {
|
||||
navigateVerticalPositionSetting,
|
||||
terminalDisplayModeSetting,
|
||||
terminalVerticalPositionSetting,
|
||||
uiDepthSetting,
|
||||
} from "../dashboard-settings";
|
||||
|
||||
/** Top bar: 24px notification icons plus a little padding. */
|
||||
export const TOP_BAR_HEIGHT = 28;
|
||||
/**
|
||||
* Width of the sidebar strip as painted. Leaves the app viewport exactly
|
||||
* 576px wide — the surface width EvenHub apps expect — except in the
|
||||
* full-panel display mode, where the strip overlays the app (see
|
||||
* sidebarWidth). Icon column layout within the strip (one wide column vs.
|
||||
* two narrow ones) is the chrome layer's business.
|
||||
* Width of the sidebar strip as painted (the app switcher on the left or
|
||||
* right edge). App windows get the other 576px — the surface width EvenHub
|
||||
* apps expect — and keep that width with the switcher at the bottom too,
|
||||
* except in the full-panel display mode, where the switcher overlays the
|
||||
* app (see sidebarWidth). Icon column layout within the strip (one wide
|
||||
* column vs. two narrow ones) is the chrome layer's business.
|
||||
*/
|
||||
export const SIDEBAR_WIDTH = 64;
|
||||
|
||||
/**
|
||||
* Height of the app switcher as a row under the window: one tall tab, the
|
||||
* 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
|
||||
* whole display's stereo shift (uiDepth).
|
||||
*/
|
||||
export const SWITCHER_ROW_HEIGHT = 36;
|
||||
|
||||
/** Which edge the app switcher is on (Settings > Customization). */
|
||||
export function switcherPosition(): AppSwitcherPosition {
|
||||
return appSwitcherPositionSetting.get();
|
||||
}
|
||||
|
||||
/** The Display > Display mode setting (see dashboard-settings.ts). */
|
||||
function appDisplayMode(appId?: string) {
|
||||
return appId === "navigate" ? navigateDisplayModeSetting.get()
|
||||
@@ -31,21 +50,110 @@ export function displayMode(appId?: string): DisplayModeSetting {
|
||||
return mode === "global" || mode === "default" ? displayModeSetting.get() : mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* How much of the screen's width the sidebar takes away from app windows:
|
||||
* the strip, or nothing in the full-panel mode (where the chrome paints the
|
||||
* strip over the window while the sidebar has focus).
|
||||
*/
|
||||
export function sidebarWidth(appId?: string): number {
|
||||
return displayMode(appId) === "640x480" ? 0 : SIDEBAR_WIDTH;
|
||||
/** The full-panel mode: windows fill the panel; the switcher overlays them only while it has focus. */
|
||||
function fullPanel(appId?: string): boolean {
|
||||
return displayMode(appId) === "640x480";
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the sidebar strip is on screen: always when it reserves width; in
|
||||
* How much of the screen's width the sidebar takes away from app windows:
|
||||
* the strip, or nothing when the switcher is a bottom row or in the
|
||||
* full-panel mode (where the chrome paints the strip over the window while
|
||||
* the sidebar has focus).
|
||||
*/
|
||||
export function sidebarWidth(appId?: string): number {
|
||||
return fullPanel(appId) || switcherPosition() === "bottom" ? 0 : SIDEBAR_WIDTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* How much of the screen's height a bottom switcher row takes away from app
|
||||
* windows: the row, or nothing beside a side strip or in the full-panel mode
|
||||
* (where the row overlays the window's bottom edge while it has focus).
|
||||
*/
|
||||
export function switcherRowHeight(appId?: string): number {
|
||||
return !fullPanel(appId) && switcherPosition() === "bottom" ? SWITCHER_ROW_HEIGHT : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the switcher strip is on screen: always when it reserves room; in
|
||||
* the full-panel mode (where it overlays the window) only while it has focus.
|
||||
*/
|
||||
export function sidebarStripVisible(focus: "sidebar" | "window", appId?: string): boolean {
|
||||
return sidebarWidth(appId) > 0 || focus === "sidebar";
|
||||
return !fullPanel(appId) || focus === "sidebar";
|
||||
}
|
||||
|
||||
/**
|
||||
* Screen rect of the switcher strip. A side strip aligns to the min-height
|
||||
* band (like the shell overlays). A bottom row sits right under the given
|
||||
* (foreground) window and spans its width, so a band shorter than the
|
||||
* screen has no gap below it; it moves when the foreground switches to a
|
||||
* window of another height, as the top bar does. In the full-panel mode the
|
||||
* row overlays the bottom edge of the screen.
|
||||
*/
|
||||
export function switcherRect(heightMode: WindowHeightMode, appId?: string): { x: number; y: number; width: number; height: number } {
|
||||
switch (switcherPosition()) {
|
||||
case "bottom":
|
||||
return {
|
||||
x: appViewportLeft(appId),
|
||||
y: switcherRowHeight(appId) > 0
|
||||
? windowTop(heightMode, appId) + windowBandHeight(heightMode, appId)
|
||||
: G2_LENS_HEIGHT - SWITCHER_ROW_HEIGHT,
|
||||
width: appViewportWidth(appId),
|
||||
height: SWITCHER_ROW_HEIGHT,
|
||||
};
|
||||
case "right":
|
||||
return { x: G2_LENS_WIDTH - SIDEBAR_WIDTH, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: MIN_WINDOW_HEIGHT };
|
||||
default:
|
||||
return { x: 0, y: minWindowTop(appId), width: SIDEBAR_WIDTH, height: MIN_WINDOW_HEIGHT };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* the top of a bottom row (under the given foreground window) down.
|
||||
*/
|
||||
export function isOnSwitcherEdge(x: number, y: number, heightMode: WindowHeightMode, appId?: string): boolean {
|
||||
switch (switcherPosition()) {
|
||||
case "bottom":
|
||||
return y >= switcherRect(heightMode, appId).y;
|
||||
case "right":
|
||||
return x >= G2_LENS_WIDTH - SIDEBAR_WIDTH;
|
||||
default:
|
||||
return x < SIDEBAR_WIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
/** Width of app windows: the panel's in the full-panel mode, else 576 (see SIDEBAR_WIDTH). */
|
||||
function appViewportWidth(appId?: string): number {
|
||||
return fullPanel(appId) ? G2_LENS_WIDTH : G2_LENS_WIDTH - SIDEBAR_WIDTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Left edge (x) of app windows: past a left strip, centred above a bottom
|
||||
* row (see SWITCHER_ROW_HEIGHT), else the screen edge.
|
||||
*/
|
||||
export function appViewportLeft(appId?: string): number {
|
||||
if (fullPanel(appId)) return 0;
|
||||
switch (switcherPosition()) {
|
||||
case "left":
|
||||
return SIDEBAR_WIDTH;
|
||||
case "bottom":
|
||||
return SIDEBAR_WIDTH / 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
export function uiDepth(): number {
|
||||
return switcherPosition() === "bottom" ? Number(uiDepthSetting.get()) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,13 +165,13 @@ export function effectiveHeightMode(mode: WindowHeightMode, appId?: string): Win
|
||||
}
|
||||
|
||||
/**
|
||||
* X of the display's true horizontal centre, in app-viewport coordinates. The
|
||||
* sidebar pushes the viewport to the right, so UI the wearer physically aims
|
||||
* with — a compass rose, a calibration crosshair — has to offset by it rather
|
||||
* than use the viewport's own centre.
|
||||
* X of the display's true horizontal centre, in app-viewport coordinates. A
|
||||
* side strip pushes the viewport off centre, so UI the wearer physically
|
||||
* aims with — a compass rose, a calibration crosshair — has to offset by it
|
||||
* rather than use the viewport's own centre.
|
||||
*/
|
||||
export function screenCenterInViewportX(): number {
|
||||
return Math.round(G2_LENS_WIDTH / 2) - sidebarWidth();
|
||||
return Math.round(G2_LENS_WIDTH / 2) - appViewportLeft();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,20 +186,27 @@ export const SHELL_OPAQUE_BLACK = 1;
|
||||
* firmware uses, leaving most of the field of view clear; "medium" is one
|
||||
* top bar taller, so the content area below the bar is a full 288px (the
|
||||
* EvenHub app surface height); "max" uses the whole 480px screen (terminal
|
||||
* views). All include a top bar drawn by the shell at the window's top edge.
|
||||
* views), less a bottom switcher row. All include a top bar drawn by the
|
||||
* shell at the window's top edge.
|
||||
*/
|
||||
export type WindowHeightMode = "min" | "medium" | "max";
|
||||
|
||||
/** Total height (top bar + content) of a min-height window. */
|
||||
export const MIN_WINDOW_HEIGHT = 288;
|
||||
/** Farthest down a min-height window can start. */
|
||||
export const MIN_WINDOW_MAX_TOP = G2_LENS_HEIGHT - MIN_WINDOW_HEIGHT;
|
||||
|
||||
/**
|
||||
* Height of the screen area windows are placed in: the whole screen, less
|
||||
* a bottom switcher row's height.
|
||||
*/
|
||||
function windowAreaHeight(appId?: string): number {
|
||||
return G2_LENS_HEIGHT - switcherRowHeight(appId);
|
||||
}
|
||||
|
||||
/** Total height (top bar + content) of a window's band in the given mode. */
|
||||
export function windowBandHeight(mode: WindowHeightMode, appId?: string): number {
|
||||
switch (effectiveHeightMode(mode, appId)) {
|
||||
case "max":
|
||||
return G2_LENS_HEIGHT;
|
||||
return windowAreaHeight(appId);
|
||||
case "medium":
|
||||
return MIN_WINDOW_HEIGHT + TOP_BAR_HEIGHT;
|
||||
default:
|
||||
@@ -129,15 +244,19 @@ export function minWindowTop(appId?: string): number {
|
||||
return windowTop("min", appId);
|
||||
}
|
||||
|
||||
/** Top edge (y) of a window's top bar; max-height windows pin to the screen top. */
|
||||
/**
|
||||
* Top edge (y) of a window's top bar; max-height windows pin to the screen
|
||||
* top. A bottom switcher row hangs under the band, so the band and row
|
||||
* together distribute the screen's slack.
|
||||
*/
|
||||
export function windowTop(mode: WindowHeightMode, appId?: string): number {
|
||||
return Math.round((G2_LENS_HEIGHT - windowBandHeight(mode, appId)) * verticalPositionFraction(appId));
|
||||
return Math.round((windowAreaHeight(appId) - windowBandHeight(mode, appId)) * verticalPositionFraction(appId));
|
||||
}
|
||||
|
||||
/** App-content viewport size for a height mode (independent of vertical position). */
|
||||
export function appViewportSize(mode: WindowHeightMode, appId?: string): { width: number; height: number } {
|
||||
return {
|
||||
width: G2_LENS_WIDTH - sidebarWidth(appId),
|
||||
width: appViewportWidth(appId),
|
||||
height: windowBandHeight(mode, appId) - TOP_BAR_HEIGHT,
|
||||
};
|
||||
}
|
||||
@@ -150,7 +269,7 @@ export function appViewportRect(mode: WindowHeightMode, appId?: string): {
|
||||
height: number;
|
||||
} {
|
||||
return {
|
||||
x: sidebarWidth(appId),
|
||||
x: appViewportLeft(appId),
|
||||
y: windowTop(mode, appId) + TOP_BAR_HEIGHT,
|
||||
...appViewportSize(mode, appId),
|
||||
};
|
||||
|
||||
+68
-37
@@ -7,6 +7,7 @@ import { acceptInput } from "../input-monitor";
|
||||
import type { RawInputEvent } from "../../native/faceclaw-communicator";
|
||||
import {
|
||||
directionalFallback,
|
||||
type DirectionalInputEvent,
|
||||
GESTURE_SHORT_THEN_LONG_PRESS,
|
||||
gestureHints,
|
||||
InputEvent,
|
||||
@@ -44,19 +45,23 @@ import {
|
||||
wakeWordActionSetting,
|
||||
} from "../dashboard-settings";
|
||||
import { onAmbientCardsChanged } from "./ambient-cards";
|
||||
import { ShellChromeLayer, sidebarContentLeft, type ShellChromeState, type ShellChromeWindow } from "./chrome-layer";
|
||||
import { ShellChromeLayer, sidebarContentSpan, type ShellChromeState, type ShellChromeWindow } from "./chrome-layer";
|
||||
import { ShellModalLayer } from "./modal-layer";
|
||||
import { ToolDebugMenuLayer } from "./tool-debug-layer";
|
||||
import { BrightnessPickerLayer } from "./brightness-picker-layer";
|
||||
import { toolRegistry } from "../../assistant/tool-registry";
|
||||
import {
|
||||
appViewportRect,
|
||||
minWindowTop,
|
||||
sidebarWidth,
|
||||
TOP_BAR_HEIGHT,
|
||||
switcherPosition,
|
||||
switcherRowHeight,
|
||||
uiDepth,
|
||||
windowBandHeight,
|
||||
windowTop,
|
||||
type WindowHeightMode,
|
||||
} from "./geometry";
|
||||
import type { AppSwitcherPosition } from "../dashboard-settings";
|
||||
|
||||
/**
|
||||
* The shell: owns the window registry, focus, screen on/off, and the shell
|
||||
@@ -228,12 +233,14 @@ class ShellOverlayMenuLayer extends MenuLayer {
|
||||
constructor(items: MenuItem[], footer: string | undefined, private readonly onClosed: () => void) {
|
||||
// Aligned to the min-height window band (like the sidebar), wherever the
|
||||
// vertical position setting currently puts it; centered over the
|
||||
// application area, i.e. the part of the screen past the sidebar strip
|
||||
// (the whole screen in the full-panel mode, where the strip overlays).
|
||||
// application area, i.e. the part of the screen beside a side strip
|
||||
// (the whole width with a bottom row, or in the full-panel mode, where
|
||||
// the strip overlays).
|
||||
const width = 272;
|
||||
const area = appViewportRect("min");
|
||||
super("System", items, {
|
||||
x: sidebarWidth() + (((G2_LENS_WIDTH - sidebarWidth() - width) / 2) | 0),
|
||||
y: minWindowTop() + TOP_BAR_HEIGHT + 8,
|
||||
x: area.x + (((area.width - width) / 2) | 0),
|
||||
y: area.y + 8,
|
||||
width,
|
||||
minHeight: 150,
|
||||
squareCorners: true,
|
||||
@@ -308,9 +315,28 @@ class ShellAlertLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
/** Every setting the top bar paints from, as one comparable string. */
|
||||
function topBarSettingsKey(): string {
|
||||
return `${batteryIndicatorSettingsKey()}|${timeFormatSetting.get()}`;
|
||||
/**
|
||||
* What a watch swipe means while the app switcher has focus, as the ring
|
||||
* gesture it stands for. Swipes are spatial: along the strip they move the
|
||||
* selection, toward the app area they enter the selected window, and away
|
||||
* from it there is nowhere further to go (ignored).
|
||||
*/
|
||||
const SWITCHER_SWIPES: Record<
|
||||
AppSwitcherPosition,
|
||||
Partial<Record<DirectionalInputEvent["type"], "scroll-up" | "scroll-down" | "click">>
|
||||
> = {
|
||||
left: { "swipe-up": "scroll-up", "swipe-down": "scroll-down", "swipe-right": "click" },
|
||||
right: { "swipe-up": "scroll-up", "swipe-down": "scroll-down", "swipe-left": "click" },
|
||||
bottom: { "swipe-left": "scroll-up", "swipe-right": "scroll-down", "swipe-up": "click" },
|
||||
};
|
||||
|
||||
/**
|
||||
* Every setting the shell's paint depends on that nothing else repaints it
|
||||
* for (the top bar's contents, the scene's stereo depth), as one comparable
|
||||
* string.
|
||||
*/
|
||||
function chromeSettingsKey(): string {
|
||||
return `${batteryIndicatorSettingsKey()}|${timeFormatSetting.get()}|${uiDepth()}`;
|
||||
}
|
||||
|
||||
class Shell {
|
||||
@@ -373,8 +399,8 @@ class Shell {
|
||||
|
||||
// Top-bar settings we mirror into the chrome; a change to any of them
|
||||
// repaints the shell surface so the top bar reflects it immediately.
|
||||
private topBarSettingsSubscribed = false;
|
||||
private lastTopBarSettingsKey: string | null = null;
|
||||
private chromeSettingsSubscribed = false;
|
||||
private lastChromeSettingsKey: string | null = null;
|
||||
|
||||
configure(config: ShellConfig): void {
|
||||
// Nearly every state change ends in a shell render request, so it is
|
||||
@@ -387,7 +413,7 @@ class Shell {
|
||||
},
|
||||
};
|
||||
this.stack.setActions(config.actions);
|
||||
this.subscribeToTopBarSettings();
|
||||
this.subscribeToChromeSettings();
|
||||
this.subscribeToAmbientCards();
|
||||
}
|
||||
|
||||
@@ -405,14 +431,14 @@ class Shell {
|
||||
});
|
||||
}
|
||||
|
||||
private subscribeToTopBarSettings(): void {
|
||||
if (this.topBarSettingsSubscribed) return;
|
||||
this.topBarSettingsSubscribed = true;
|
||||
this.lastTopBarSettingsKey = topBarSettingsKey();
|
||||
private subscribeToChromeSettings(): void {
|
||||
if (this.chromeSettingsSubscribed) return;
|
||||
this.chromeSettingsSubscribed = true;
|
||||
this.lastChromeSettingsKey = chromeSettingsKey();
|
||||
onAnySettingChanged(() => {
|
||||
const key = topBarSettingsKey();
|
||||
if (key === this.lastTopBarSettingsKey) return;
|
||||
this.lastTopBarSettingsKey = key;
|
||||
const key = chromeSettingsKey();
|
||||
if (key === this.lastChromeSettingsKey) return;
|
||||
this.lastChromeSettingsKey = key;
|
||||
this.config.requestShellRender();
|
||||
});
|
||||
}
|
||||
@@ -701,8 +727,13 @@ class Shell {
|
||||
this.config.requestShellRender();
|
||||
}
|
||||
|
||||
/** Paint the shell surface: transparent chrome, or all-transparent when asleep. */
|
||||
paintScene(): Uint8Array { return encodeShellScene(this.screenOn ? this.stack.paintUndimmed() : []); }
|
||||
/**
|
||||
* Paint the shell surface: transparent chrome, or all-transparent when
|
||||
* asleep. The scene also carries the whole display's stereo depth.
|
||||
*/
|
||||
paintScene(): Uint8Array {
|
||||
return this.screenOn ? encodeShellScene(this.stack.paintUndimmed(), uiDepth()) : encodeShellScene([]);
|
||||
}
|
||||
|
||||
paintSurface(): Plane[] {
|
||||
if (!this.screenOn) {
|
||||
@@ -904,20 +935,24 @@ class Shell {
|
||||
|
||||
/**
|
||||
* Screen rect actually occupied by content, for cropping screenshots: the
|
||||
* foreground window's band (full screen for a max-height window, the
|
||||
* vertical-position-dependent 288px band otherwise), minus the sidebar
|
||||
* strip left of the icon columns when the one-column variant is active.
|
||||
* 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.
|
||||
*/
|
||||
screenshotCropRect(): { x: number; y: number; width: number; height: number } {
|
||||
const appId = this.foregroundWindow()?.appId;
|
||||
const heightMode = this.foregroundWindow()?.heightMode ?? "min";
|
||||
const x = sidebarWidth(appId) === 0 ? 0 : sidebarContentLeft(this.windows.length);
|
||||
return {
|
||||
x,
|
||||
y: windowTop(heightMode, appId),
|
||||
width: G2_LENS_WIDTH - x,
|
||||
height: windowBandHeight(heightMode, appId),
|
||||
};
|
||||
const viewport = appViewportRect(heightMode, appId);
|
||||
let left = viewport.x, right = viewport.x + viewport.width;
|
||||
if (sidebarWidth(appId) > 0) {
|
||||
const strip = sidebarContentSpan(this.windows.length);
|
||||
left = Math.min(left, strip.left);
|
||||
right = Math.max(right, strip.right);
|
||||
}
|
||||
const y = windowTop(heightMode, appId);
|
||||
const bottom = y + windowBandHeight(heightMode, appId) + switcherRowHeight(appId);
|
||||
return { x: left, y, width: right - left, height: bottom - y };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -966,7 +1001,8 @@ class Shell {
|
||||
}
|
||||
|
||||
private handleSidebarInput(event: InputEvent): ShellInputOutcome {
|
||||
switch (event.type) {
|
||||
const type = isDirectionalInput(event) ? SWITCHER_SWIPES[switcherPosition()][event.type] : event.type;
|
||||
switch (type) {
|
||||
case "double-click":
|
||||
// A double-tap at the root (the app switcher selected) turns the
|
||||
// display off — from the ring and the watch scheme alike; watch-scheme
|
||||
@@ -974,17 +1010,12 @@ class Shell {
|
||||
this.sleep();
|
||||
return { shell: true, window: false };
|
||||
case "scroll-up":
|
||||
case "swipe-up":
|
||||
this.moveSelection(-1);
|
||||
return { shell: true, window: false };
|
||||
case "scroll-down":
|
||||
case "swipe-down":
|
||||
this.moveSelection(1);
|
||||
return { shell: true, window: false };
|
||||
case "click":
|
||||
case "swipe-right":
|
||||
// Right: into the selected window (spatially, the window is to the
|
||||
// sidebar's right). Left has nowhere further to go and is ignored.
|
||||
if (this.windows.length) {
|
||||
this.focus = "window";
|
||||
this.foregroundWindow()?.onFocus?.(this.lastInput);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { wrapText } from "../../graphics/textwrap";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
@@ -6,7 +6,7 @@ import type { ToolDebugEntry } from "../../assistant/tool-registry";
|
||||
import { InputEvent } from "../gestures";
|
||||
import { Layer, LayerContext, PaintBelow } from "../layers";
|
||||
import { MenuLayer, drawListScrollbar, type MenuItem } from "../menu";
|
||||
import { minWindowTop, sidebarWidth, TOP_BAR_HEIGHT } from "./geometry";
|
||||
import { appViewportRect } from "./geometry";
|
||||
import { lineStep } from "../metrics";
|
||||
|
||||
/**
|
||||
@@ -21,18 +21,19 @@ const DIALOG_WIDTH = 420;
|
||||
// the band below the top bar with an 8px margin on each side.
|
||||
const DETAIL_HEIGHT = 208;
|
||||
|
||||
/** Dialog left edge: past the sidebar strip where one reserves width. */
|
||||
/** Dialog left edge: inside the app area, clear of a left sidebar strip. */
|
||||
function dialogX(): number {
|
||||
return sidebarWidth() + 8;
|
||||
return appViewportRect("min").x + 8;
|
||||
}
|
||||
|
||||
/** Detail box width: the app area (clear of a right sidebar strip) less margins. */
|
||||
function detailWidth(): number {
|
||||
return G2_LENS_WIDTH - dialogX() - 8;
|
||||
return appViewportRect("min").width - 16;
|
||||
}
|
||||
|
||||
/** Dialog top edge, aligned to the min-height band's content area. */
|
||||
function dialogY(): number {
|
||||
return minWindowTop() + TOP_BAR_HEIGHT + 8;
|
||||
return appViewportRect("min").y + 8;
|
||||
}
|
||||
const DETAIL_PADDING = 14;
|
||||
|
||||
|
||||
Reference in new issue
Block a user