diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.java b/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.java new file mode 100644 index 00000000..864c906c --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.java @@ -0,0 +1,161 @@ +package com.faceclaw.app; + +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Path; +import android.util.Log; + +import androidx.core.graphics.PathParser; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Renders a small subset of SVG (the shapes used by Lucide / simple Noun + * Project icons: path, circle, ellipse, rect, line, polyline, polygon) to a + * grayscale coverage buffer for use as an on-glasses icon. Icons are stroked + * (Lucide style: fill="none", 2px stroke, round caps/joins); the returned + * bytes are one coverage value per pixel (0=transparent .. 255=opaque white), + * row-major, size*size. Called once per icon and cached on the TS side. + */ +public final class IconRenderer { + private static final String TAG = "IconRenderer"; + private static final Pattern TAG_RE = Pattern.compile("<(path|circle|ellipse|rect|line|polyline|polygon)\\b([^>]*)>"); + private static final Pattern VIEWBOX_RE = Pattern.compile("viewBox\\s*=\\s*\"([^\"]*)\""); + + private IconRenderer() {} + + public static byte[] renderSvgGray(String svg, int size, float strokeWidth) { + if (svg == null || size <= 0) { + return new byte[0]; + } + try { + float viewW = 24f, viewH = 24f; + Matcher vb = VIEWBOX_RE.matcher(svg); + if (vb.find()) { + String[] parts = vb.group(1).trim().split("[\\s,]+"); + if (parts.length == 4) { + viewW = Float.parseFloat(parts[2]); + viewH = Float.parseFloat(parts[3]); + } + } + Path path = new Path(); + Matcher m = TAG_RE.matcher(svg); + while (m.find()) { + appendElement(path, m.group(1), m.group(2)); + } + if (path.isEmpty()) { + return new byte[0]; + } + + Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + float scale = Math.min(size / viewW, size / viewH); + // Center the (square) viewBox in the bitmap. + canvas.translate((size - viewW * scale) / 2f, (size - viewH * scale) / 2f); + canvas.scale(scale, scale); + Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); + paint.setStyle(Paint.Style.STROKE); + paint.setStrokeWidth(strokeWidth); + paint.setStrokeCap(Paint.Cap.ROUND); + paint.setStrokeJoin(Paint.Join.ROUND); + paint.setColor(0xffffffff); + canvas.drawPath(path, paint); + + int[] pixels = new int[size * size]; + bitmap.getPixels(pixels, 0, size, 0, 0, size, size); + byte[] gray = new byte[size * size]; + for (int i = 0; i < pixels.length; i++) { + gray[i] = (byte) ((pixels[i] >>> 24) & 0xff); // alpha = coverage + } + return gray; + } catch (Exception e) { + Log.w(TAG, "icon render failed", e); + return new byte[0]; + } + } + + private static void appendElement(Path path, String tag, String attrs) { + switch (tag) { + case "path": { + String d = attr(attrs, "d"); + if (d != null) { + Path sub = PathParser.createPathFromPathData(d); + if (sub != null) { + path.addPath(sub); + } + } + break; + } + case "circle": { + float cx = num(attrs, "cx", 0), cy = num(attrs, "cy", 0), r = num(attrs, "r", 0); + if (r > 0) path.addCircle(cx, cy, r, Path.Direction.CW); + break; + } + case "ellipse": { + float cx = num(attrs, "cx", 0), cy = num(attrs, "cy", 0); + float rx = num(attrs, "rx", 0), ry = num(attrs, "ry", 0); + if (rx > 0 && ry > 0) path.addOval(cx - rx, cy - ry, cx + rx, cy + ry, Path.Direction.CW); + break; + } + case "rect": { + float x = num(attrs, "x", 0), y = num(attrs, "y", 0); + float w = num(attrs, "width", 0), h = num(attrs, "height", 0); + float rx = num(attrs, "rx", 0), ry = num(attrs, "ry", rx > 0 ? rx : 0); + if (rx <= 0) rx = ry; + if (ry <= 0) ry = rx; + if (w > 0 && h > 0) { + if (rx > 0 || ry > 0) { + path.addRoundRect(x, y, x + w, y + h, rx, ry, Path.Direction.CW); + } else { + path.addRect(x, y, x + w, y + h, Path.Direction.CW); + } + } + break; + } + case "line": { + path.moveTo(num(attrs, "x1", 0), num(attrs, "y1", 0)); + path.lineTo(num(attrs, "x2", 0), num(attrs, "y2", 0)); + break; + } + case "polyline": + case "polygon": { + String points = attr(attrs, "points"); + if (points != null) { + String[] nums = points.trim().split("[\\s,]+"); + boolean started = false; + for (int i = 0; i + 1 < nums.length; i += 2) { + float px = Float.parseFloat(nums[i]); + float py = Float.parseFloat(nums[i + 1]); + if (!started) { + path.moveTo(px, py); + started = true; + } else { + path.lineTo(px, py); + } + } + if (tag.equals("polygon")) path.close(); + } + break; + } + default: + break; + } + } + + private static String attr(String attrs, String name) { + Matcher m = Pattern.compile("\\b" + name + "\\s*=\\s*\"([^\"]*)\"").matcher(attrs); + return m.find() ? m.group(1) : null; + } + + private static float num(String attrs, String name, float fallback) { + String value = attr(attrs, name); + if (value == null) return fallback; + try { + return Float.parseFloat(value.trim()); + } catch (NumberFormatException e) { + return fallback; + } + } +} diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index 5942d72a..f82e2803 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -896,13 +896,13 @@ class DashboardController { this.requestShellRender(); return; } - host.openWindow({ windowId: "terminal:hub", title: "Terminal", iconLetter: "T", focus: true }); + host.openWindow({ windowId: "terminal:hub", title: "Terminal", iconLetter: "T", icon: "terminal", focus: true }); this.appendLog("launched terminal:hub"); return; } const serial = this.nextWindowSerial++; const windowId = `${appId}:${serial}`; - host.openWindow({ windowId, title: `Stopwatch ${serial}`, iconLetter: "S", focus: true }); + host.openWindow({ windowId, title: `Stopwatch ${serial}`, iconLetter: "S", icon: "timer", focus: true }); this.appendLog(`launched ${windowId}`); } diff --git a/app/graphics/icons.ts b/app/graphics/icons.ts new file mode 100644 index 00000000..27577971 --- /dev/null +++ b/app/graphics/icons.ts @@ -0,0 +1,69 @@ +import { GrayImage } from "./image"; + +declare const com: any; +declare const global: any; + +/** + * Vector icons for window indicators (and anywhere else). SVGs are rendered + * once to a correctly sized grayscale bitmap by the Java IconRenderer (a + * small SVG subset: path/circle/rect/line/polyline) and cached here. To add + * an icon, drop its SVG source into ICON_SVGS — Lucide icons + * (https://lucide.dev, stroked, 24px viewBox) work as-is; simple single-color + * Noun Project glyphs also work. + */ + +// Stroke width in viewBox units (Lucide's default is 2). +const ICON_STROKE_WIDTH = 2; + +// Lucide icons (MIT/ISC licensed). Kept verbatim so they can be diffed +// against upstream if an icon needs updating. +export const ICON_SVGS = { + "layout-grid": + '', + timer: + '', + terminal: + '', + "file-text": + '', + music: + '', + activity: + '', + bell: + '', + "flask-conical": + '', + settings: + '', + mic: + '', +} as const; + +export type IconName = keyof typeof ICON_SVGS; + +const cache = new Map(); + +/** Render an icon SVG to a size×size grayscale bitmap, rendered once and cached. */ +export function renderIcon(name: IconName, size: number): GrayImage | null { + const key = `${name}:${size}`; + const cached = cache.get(key); + if (cached !== undefined) return cached; + + let icon: GrayImage | null = null; + if (global.isAndroid) { + try { + const bytes = com.faceclaw.app.IconRenderer.renderSvgGray(ICON_SVGS[name], Math.round(size), ICON_STROKE_WIDTH); + if (bytes && bytes.length >= size * size) { + icon = new GrayImage(size, size, 0); + for (let i = 0; i < size * size; i++) { + icon.pixels[i] = bytes[i] & 0xff; + } + } + } catch (error) { + console.warn(`renderIcon(${name}) failed: ${error}`); + } + } + cache.set(key, icon); + return icon; +} diff --git a/app/ui/apps/buzzer-demo.ts b/app/ui/apps/buzzer-demo.ts index 159651d1..84bb27f8 100644 --- a/app/ui/apps/buzzer-demo.ts +++ b/app/ui/apps/buzzer-demo.ts @@ -2,6 +2,8 @@ import { getDefaultSmallFont } from "../../graphics/bdffont"; import { GrayImage } from "../../graphics/image"; import { clamp } from "../../util/numeric-util"; import { Layer, type DashboardInputEvent, type LayerActions, type LayerContext } from "../layers"; +import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../gestures"; +import { drawSelectionHighlight } from "../menu"; import { buildSoundSequencePayload, CFW_SEQ_MAX, @@ -36,7 +38,7 @@ export class BuzzerDemoLayer implements Layer { const image = new GrayImage(width, height, 0); image.drawText(font, 20, 8, "Buzzer demo", 220); - const status = this.playing ? `Playing: ${this.playing}` : "Click to play"; + const status = this.playing ? `Playing: ${this.playing}` : `${GESTURE_CLICK} play`; image.drawText(font, width - 24 - font.measureText(status), 8, status, 140); const listHeight = height - HEADER_HEIGHT - FOOTER_HEIGHT; @@ -54,14 +56,13 @@ export class BuzzerDemoLayer implements Layer { const y = HEADER_HEIGHT + (index - this.scrollRow) * ROW_HEIGHT; const selected = index === this.selectedIndex; if (selected) { - image.fillRoundedRect(LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, 15, 4); - image.drawRoundedRect(LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, 45, 4); + drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, ctx.stack.isFocused(), 4); } image.drawText(font, LIST_X, y + 1, effect.name, selected ? 255 : 200); image.drawText(font, LIST_X + 110, y + 1, effect.desc, selected ? 180 : 120); } - image.drawText(font, 20, height - 16, "Scroll: select Click: play Double-click: back", 110); + image.drawText(font, 20, height - 16, `${GESTURE_SCROLL} select ${GESTURE_CLICK} play ${GESTURE_DOUBLE_CLICK} back`, 110); return image; } diff --git a/app/ui/apps/file-browser.ts b/app/ui/apps/file-browser.ts index 1d81542c..f24729cb 100644 --- a/app/ui/apps/file-browser.ts +++ b/app/ui/apps/file-browser.ts @@ -1,6 +1,8 @@ import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont"; import { GrayImage } from "../../graphics/image"; import { clamp } from "../../util/numeric-util"; +import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../gestures"; +import { drawSelectionHighlight } from "../menu"; import { hasAllFilesAccess, listDirectory, @@ -70,14 +72,13 @@ export class FileBrowserLayer implements Layer { const y = HEADER_HEIGHT + (index - this.scrollRow) * ROW_HEIGHT; const selected = index === this.selectedIndex; if (selected) { - image.fillRoundedRect(LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, 15, 4); - image.drawRoundedRect(LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, 45, 4); + drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, ctx.stack.isFocused(), 4); } const value = rowValue(row, selected); image.drawText(font, LIST_X, y + 1, truncateRight(font, row.label, width - 2 * LIST_X), value); } - image.drawText(font, 20, height - 16, "Click: open Double-click: up / back", 110); + image.drawText(font, 20, height - 16, `${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} up / back`, 110); return image; } diff --git a/app/ui/apps/nightscout.ts b/app/ui/apps/nightscout.ts index e5e5c31a..0348d572 100644 --- a/app/ui/apps/nightscout.ts +++ b/app/ui/apps/nightscout.ts @@ -5,6 +5,7 @@ import { nightscoutBridge, type NightscoutState } from "../../native/nightscout- import { isNightscoutSettingsConfigured } from "../dashboard-settings"; import { formatAgeShortFromTimestamp, formatTimestamp } from "~/util/date-util"; +import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../gestures"; const nightscoutLargeFont = getDefaultLargeFont(); const NIGHTSCOUT_STALE_MS = 15 * 60 * 1000; const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000; @@ -294,7 +295,6 @@ export class NightscoutLayer implements Layer { const nightscout = nightscoutBridge.snapshot(); const nowMs = Date.now(); const footerY = height - 26; - image.drawRect(12, 12, width - 24, height - 24, 52); image.drawText(font, 22, 16, "Nightscout", 220); if (!isNightscoutSettingsConfigured() || nightscout.configurationMissing) { @@ -306,7 +306,7 @@ export class NightscoutLayer implements Layer { if (!nightscout.available || !nightscout.latest) { image.drawText(font, 22, 44, "No Nightscout data available.", 180); image.drawText(font, 22, 58, truncateLine(nightscout.status, 60), 140); - image.drawText(font, 22, footerY, "Click: refresh Double-click: back", 110); + image.drawText(font, 22, footerY, `${GESTURE_CLICK} refresh ${GESTURE_DOUBLE_CLICK} back`, 110); return image; } @@ -340,7 +340,7 @@ export class NightscoutLayer implements Layer { const graphHeight = Math.max(40, height - 128 - 48); drawNightscoutGraph(image, { x: 22, y: 128, width: width - 44, height: graphHeight }, nightscout, nowMs, font); image.drawText(font, 22, height - 42, "2-hour glucose history with basal / carbs / boluses", 130); - image.drawText(font, 22, footerY, "Click: refresh Double-click: back", 110); + image.drawText(font, 22, footerY, `${GESTURE_CLICK} refresh ${GESTURE_DOUBLE_CLICK} back`, 110); return image; } diff --git a/app/ui/apps/teleprompt.ts b/app/ui/apps/teleprompt.ts index 006b48bb..8d28ae32 100644 --- a/app/ui/apps/teleprompt.ts +++ b/app/ui/apps/teleprompt.ts @@ -31,7 +31,6 @@ export class TelepromptLayer implements Layer { const image = new GrayImage(width, height, 0); const footerY = height - FOOTER_MARGIN; this.bodyLineCount = Math.max(1, Math.floor((footerY - BODY_Y) / LINE_STEP)); - image.drawRect(12, 12, width - 24, height - 24, 52); image.drawText(font, MARGIN_X + 4, TITLE_Y, truncateToWidth(font, this.title, width - 2 * MARGIN_X - 8), 220); const lines = this.getLines(font, width); diff --git a/app/ui/apps/transcribe.ts b/app/ui/apps/transcribe.ts index 1f0eb40b..0c415666 100644 --- a/app/ui/apps/transcribe.ts +++ b/app/ui/apps/transcribe.ts @@ -9,6 +9,7 @@ import { Layer, type DashboardInputEvent, type LayerContext } from "../layers"; * (createTranscribeAppWindow); this layer accumulates the transcript, shows * it, and saves it to Downloads on click. */ +import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../gestures"; export class TranscribeLayer implements Layer { private status = "Listening..."; // Finalized utterances, plus the live (replace-semantics) partial appended @@ -37,7 +38,6 @@ export class TranscribeLayer implements Layer { const text = this.displayText() || "Listening..."; const wrapped = wrapTranscribeText(font, text, width - 64); - image.drawRect(12, 12, width - 24, height - 24, 52); image.drawText(font, 24, 20, "Transcribe", 200); image.drawText(font, 24, 40, this.saveNotice || this.status, 110); @@ -50,7 +50,7 @@ export class TranscribeLayer implements Layer { image.drawText(font, 32, y, wrapped[index]!, 230); } - image.drawText(font, 24, footerY, "Click: save Double-click: back", 110); + image.drawText(font, 24, footerY, `${GESTURE_CLICK} save ${GESTURE_DOUBLE_CLICK} back`, 110); return image; } diff --git a/app/ui/dashboard-settings.ts b/app/ui/dashboard-settings.ts index eef02c1e..78e4da23 100644 --- a/app/ui/dashboard-settings.ts +++ b/app/ui/dashboard-settings.ts @@ -1,3 +1,4 @@ +import { GESTURE_DOUBLE_CLICK } from "./gestures"; import { getBooleanSetting, getStringSetting, @@ -430,14 +431,13 @@ export class EditTextSettingLayer implements Layer { // viewport in the settings app). const { width, height } = ctx.stack.getBaseSize(); const image = new GrayImage(width, height, 0); - image.drawRect(12, 12, width - 24, height - 24, 52); image.drawText(font, 22, 16, this.setting.glassesEditTitle, 220); const message = wrapText(font, "Look at the phone app to type a value.", width - 48); for (let index = 0; index < message.length; index++) { image.drawText(font, 22, 52 + index * 14, message[index]!, 200); } image.drawText(font, 22, 110, truncateSetting(this.setting.get(), 52), 220); - image.drawText(font, 22, height - 36, "Double-click to go back", 110); + image.drawText(font, 22, height - 36, `${GESTURE_DOUBLE_CLICK} back`, 110); return image; } diff --git a/app/ui/gestures.ts b/app/ui/gestures.ts new file mode 100644 index 00000000..b5b8fce7 --- /dev/null +++ b/app/ui/gestures.ts @@ -0,0 +1,24 @@ +/** + * Compact glyphs for the ring gestures, used in on-glasses hint text instead + * of spelling the gesture out. All codepoints exist in terminus12/16. + * + * click · (U+00B7 middle dot) + * double-click ·· (twice) + * scroll ▲▼ (U+25B2 / U+25BC) + * long-press - (hyphen-minus) + */ +export const GESTURE_CLICK = "·"; +export const GESTURE_DOUBLE_CLICK = "··"; +export const GESTURE_SCROLL_UP = "▲"; +export const GESTURE_SCROLL_DOWN = "▼"; +export const GESTURE_SCROLL = "▲▼"; +export const GESTURE_LONG_PRESS = "-"; + +/** + * Join "glyph action" hint pairs into a single line, e.g. + * gestureHints([[GESTURE_CLICK, "save"], [GESTURE_DOUBLE_CLICK, "back"]]) + * => "· save ·· back" + */ +export function gestureHints(pairs: Array<[string, string]>): string { + return pairs.map(([glyph, action]) => `${glyph} ${action}`).join(" "); +} diff --git a/app/ui/layers.ts b/app/ui/layers.ts index b1ea5af9..a80817b9 100644 --- a/app/ui/layers.ts +++ b/app/ui/layers.ts @@ -57,8 +57,17 @@ export class LayerStack { private readonly ctx: LayerContext; private readonly baseWidth: number; private readonly baseHeight: number; + private readonly focusedFn: () => boolean; - constructor(baseLayer: Layer, actions: LayerActions, baseSize?: { width: number; height: number }) { + constructor( + baseLayer: Layer, + actions: LayerActions, + baseSize?: { width: number; height: number }, + // Whether this stack is the current input target; drives the strength of + // selection highlights (a visible-but-unfocused window dims its selection). + // Defaults to always-focused for shell overlays and standalone stacks. + isFocused: () => boolean = () => true, + ) { this.layers = [baseLayer]; this.ctx = { stack: this, @@ -66,6 +75,11 @@ export class LayerStack { }; this.baseWidth = baseSize?.width ?? G2_LENS_WIDTH; this.baseHeight = baseSize?.height ?? G2_LENS_HEIGHT; + this.focusedFn = isFocused; + } + + isFocused(): boolean { + return this.focusedFn(); } push(layer: Layer): void { diff --git a/app/ui/menu.ts b/app/ui/menu.ts index 3109e3d9..e68bdbaa 100644 --- a/app/ui/menu.ts +++ b/app/ui/menu.ts @@ -4,6 +4,7 @@ import { getDefaultSmallFont, type BdfFont } from "../graphics/bdffont"; import { clamp } from "../util/numeric-util"; import { DashboardInputEvent, Layer, LayerContext, PaintBelow } from "./layers"; +import { GESTURE_DOUBLE_CLICK } from "./gestures"; const DEFAULT_MENU_X = 8; const DEFAULT_MENU_Y = 8; const DEFAULT_MENU_WIDTH = 272; @@ -46,6 +47,26 @@ export type MenuItem = { render?: (args: MenuItemRenderArgs) => void; }; +/** + * Draw a selection highlight for a list row. A focused list fills the row and + * outlines it; a visible-but-unfocused list draws only the outline, so the + * selection stays legible without implying it will receive input. + */ +export function drawSelectionHighlight( + image: GrayImage, + x: number, + y: number, + width: number, + height: number, + focused: boolean, + radius = 6, +): void { + if (focused) { + image.fillRoundedRect(x, y, width, height, MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL, radius); + } + image.drawRoundedRect(x, y, width, height, MENU_HIGHLIGHT_SELECTED_BORDER_STROKE, radius); +} + export function drawToggleMenuItem( image: GrayImage, font: BdfFont, @@ -122,14 +143,22 @@ export class MenuLayer implements Layer { } const bodyY = y + chromeTop; + const focused = ctx.stack.isFocused(); const lastVisibleRow = Math.min(this.items.length, this.scrollRow + visibleRowCount); for (let index = this.scrollRow; index < lastVisibleRow; index++) { const item = this.items[index]!; const rowY = bodyY + (index - this.scrollRow) * MENU_ROW_HEIGHT; const selected = index === this.selectedIndex; if (selected) { - image.fillRoundedRect(x + 12, rowY + MENU_HIGHLIGHT_Y_OFFSET, width - 24, MENU_HIGHLIGHT_HEIGHT, MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL); - image.drawRoundedRect(x + 12, rowY + MENU_HIGHLIGHT_Y_OFFSET, width - 24, MENU_HIGHLIGHT_HEIGHT, MENU_HIGHLIGHT_SELECTED_BORDER_STROKE); + drawSelectionHighlight( + image, + x + 12, + rowY + MENU_HIGHLIGHT_Y_OFFSET, + width - 24, + MENU_HIGHLIGHT_HEIGHT, + focused, + 8, + ); } if (item.render) { item.render({ @@ -214,7 +243,7 @@ export class TextPageLayer implements Layer { for (let index = 0; index < wrapped.length; index++) { image.drawText(font, 24, 42 + index * 14, wrapped[index]!, 190); } - image.drawText(font, 24, 252, "Double-click to go back", 110); + image.drawText(font, 24, 252, `${GESTURE_DOUBLE_CLICK} back`, 110); return image; } diff --git a/app/ui/notifications.ts b/app/ui/notifications.ts index 9af8340c..f6c0fea1 100644 --- a/app/ui/notifications.ts +++ b/app/ui/notifications.ts @@ -3,6 +3,7 @@ import { formatRelativeTime } from "~/util/date-util"; import { BdfFont, getDefaultSmallFont } from "../graphics/bdffont"; import { GrayImage } from "../graphics/image"; import { wrapText } from "../graphics/textwrap"; +import { GESTURE_DOUBLE_CLICK } from "./gestures"; import { dismissNotification, invokeNotificationAction, @@ -81,7 +82,7 @@ export class NotificationsListLayer implements Layer { if (!notifications.length) { image.drawText(font, 24, 72, "No current Android notifications.", 190); - image.drawText(font, 24, height - 36, "Double-click: back to sidebar", 110); + image.drawText(font, 24, height - 36, `${GESTURE_DOUBLE_CLICK} back`, 110); return image; } diff --git a/app/ui/shell/chrome-layer.ts b/app/ui/shell/chrome-layer.ts index 2efaf714..49995335 100644 --- a/app/ui/shell/chrome-layer.ts +++ b/app/ui/shell/chrome-layer.ts @@ -5,6 +5,7 @@ import { readActiveNotificationIcons } from "../../native/notification-icons"; import { readPhoneBatteryState } from "../../native/phone-battery"; import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../util/render-freshness"; import { clamp } from "../../util/numeric-util"; +import { renderIcon, type IconName } from "../../graphics/icons"; import { batteryDisplayModeSetting } from "../dashboard-settings"; import { Layer } from "../layers"; import { SHELL_OPAQUE_BLACK, SIDEBAR_WIDTH, TOP_BAR_HEIGHT } from "./geometry"; @@ -33,7 +34,7 @@ export type ShellChromeState = { trayIcons: GrayImage[]; }; -/** Reusable placeholder window icon: rounded outline with a single letter. */ +/** Placeholder window icon: rounded outline with a single letter. */ export function makeLetterWindowIcon(letter: string): ShellChromeWindow["drawIcon"] { return (image, x, y, size) => { const font = getDefaultMediumFont(); @@ -44,6 +45,22 @@ export function makeLetterWindowIcon(letter: string): ShellChromeWindow["drawIco }; } +/** Window icon rendered from an SVG (Lucide), rendered once per size and cached. */ +export function makeSvgWindowIcon(name: IconName): ShellChromeWindow["drawIcon"] { + return (image, x, y, size) => { + const icon = renderIcon(name, size); + if (!icon) return; + const dx = x + Math.max(0, ((size - icon.width) / 2) | 0); + const dy = y + Math.max(0, ((size - icon.height) / 2) | 0); + image.bitBlt(icon, dx, dy, { transparentZero: true }); + }; +} + +/** SVG icon when a name is given, else the letter placeholder. */ +export function windowIcon(icon: IconName | undefined, letter: string): ShellChromeWindow["drawIcon"] { + return icon ? makeSvgWindowIcon(icon) : makeLetterWindowIcon(letter); +} + /** * 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 diff --git a/app/ui/shell/debug-tests-app.ts b/app/ui/shell/debug-tests-app.ts index 5e032864..7963d7c1 100644 --- a/app/ui/shell/debug-tests-app.ts +++ b/app/ui/shell/debug-tests-app.ts @@ -43,6 +43,7 @@ export function createDebugTestsAppWindow(options: InProcessAppOptions): InProce windowId: DEBUG_TESTS_WINDOW_ID, title: "Debug tests", iconLetter: "Db", + icon: "flask-conical", closeable: true, actions: options.actions, baseLayer: new YieldAtRootLayer(menu), diff --git a/app/ui/shell/in-process-window.ts b/app/ui/shell/in-process-window.ts index 98078332..2243e0fa 100644 --- a/app/ui/shell/in-process-window.ts +++ b/app/ui/shell/in-process-window.ts @@ -1,7 +1,8 @@ import { GrayImage } from "../../graphics/image"; import { beginRenderPass, endRenderPass } from "../../util/render-freshness"; import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, PaintBelow } from "../layers"; -import { makeLetterWindowIcon } from "./chrome-layer"; +import { windowIcon } from "./chrome-layer"; +import { type IconName } from "../../graphics/icons"; import { APP_VIEWPORT } from "./geometry"; import { shell, type ShellWindow } from "./shell"; @@ -17,6 +18,8 @@ export type InProcessWindowOptions = { windowId: string; title: string; iconLetter: string; + /** Lucide icon name for the sidebar indicator; falls back to iconLetter. */ + icon?: IconName; closeable: boolean; /** Shared actions; requestRender is rebound to this window's render. */ actions: LayerActions; @@ -52,6 +55,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces options.baseLayer, { ...options.actions, requestRender }, { width: APP_VIEWPORT.width, height: APP_VIEWPORT.height }, + () => shell.isWindowFocused(options.windowId), ); // Data sources with caches (e.g. notification icons) may serve stale data @@ -83,7 +87,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces options.onClosed?.(); options.removeSurface?.(); }, - drawIcon: makeLetterWindowIcon(options.iconLetter), + drawIcon: windowIcon(options.icon, options.iconLetter), handleInput: async (event, frameId) => { await stack.handleInput(event); await render(frameId); diff --git a/app/ui/shell/launcher-app.ts b/app/ui/shell/launcher-app.ts index 1c6752ef..23427dc1 100644 --- a/app/ui/shell/launcher-app.ts +++ b/app/ui/shell/launcher-app.ts @@ -50,6 +50,7 @@ export function createLauncherWindow(options: LauncherOptions): ShellWindow { windowId: LAUNCHER_WINDOW_ID, title: "Apps", iconLetter: "A", + icon: "layout-grid", closeable: false, actions: options.actions, baseLayer: new YieldAtRootLayer(menu), diff --git a/app/ui/shell/music-app.ts b/app/ui/shell/music-app.ts index 56c1577b..55f75e7d 100644 --- a/app/ui/shell/music-app.ts +++ b/app/ui/shell/music-app.ts @@ -2,6 +2,8 @@ import { getDefaultSmallFont } from "../../graphics/bdffont"; import { GrayImage } from "../../graphics/image"; import { wrapText } from "../../graphics/textwrap"; import { clamp } from "../../util/numeric-util"; +import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../gestures"; +import { drawSelectionHighlight } from "../menu"; import { mediaControllerBridge, type MediaControllerState, @@ -63,14 +65,14 @@ class MusicAppLayer implements Layer { for (let index = 0; index < lines.length; index++) { image.drawText(font, 24, 44 + index * 14, lines[index]!, 180); } - image.drawText(font, 20, height - 16, "Click: open settings Double-click: back", 110); + image.drawText(font, 20, height - 16, `${GESTURE_CLICK} open settings ${GESTURE_DOUBLE_CLICK} back`, 110); return image; } if (!media.available) { image.drawText(font, 24, 44, "No active media session.", 180); image.drawText(font, 24, 62, "Start playback in another app on the phone.", 150); - image.drawText(font, 20, height - 16, "Double-click: back to sidebar", 110); + image.drawText(font, 20, height - 16, `${GESTURE_DOUBLE_CLICK} back`, 110); return image; } @@ -104,14 +106,13 @@ class MusicAppLayer implements Layer { const y = LIST_TOP + (index - this.scrollRow) * ROW_HEIGHT; const selected = index === this.selectedIndex; if (selected) { - image.fillRoundedRect(LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, 15, 4); - image.drawRoundedRect(LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, 45, 4); + drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, ROW_HEIGHT - 1, ctx.stack.isFocused(), 4); } const value = !row.enabled ? (selected ? 130 : 90) : selected ? 255 : 200; image.drawText(font, LIST_X, y + 1, truncate(font, row.label, width - 2 * LIST_X), value); } - image.drawText(font, 20, height - 16, "Scroll: select Click: activate Double-click: back", 110); + image.drawText(font, 20, height - 16, `${GESTURE_SCROLL} select ${GESTURE_CLICK} activate ${GESTURE_DOUBLE_CLICK} back`, 110); return image; } @@ -198,6 +199,7 @@ export function createMusicAppWindow(options: InProcessAppOptions): InProcessWin windowId: MUSIC_WINDOW_ID, title: "Music", iconLetter: "M", + icon: "music", closeable: true, actions: options.actions, baseLayer: new YieldAtRootLayer(new MusicAppLayer()), diff --git a/app/ui/shell/nightscout-app.ts b/app/ui/shell/nightscout-app.ts index 58164429..bdbd6f7c 100644 --- a/app/ui/shell/nightscout-app.ts +++ b/app/ui/shell/nightscout-app.ts @@ -32,6 +32,7 @@ export function createNightscoutAppWindow(options: InProcessAppOptions): InProce windowId: NIGHTSCOUT_WINDOW_ID, title: "Nightscout", iconLetter: "Ns", + icon: "activity", closeable: true, actions: options.actions, baseLayer: new YieldAtRootLayer(new NightscoutLayer()), diff --git a/app/ui/shell/notifications-app.ts b/app/ui/shell/notifications-app.ts index 837b2f3c..70828236 100644 --- a/app/ui/shell/notifications-app.ts +++ b/app/ui/shell/notifications-app.ts @@ -20,6 +20,7 @@ export function createNotificationsAppWindow(options: InProcessAppOptions): InPr windowId: NOTIFICATIONS_WINDOW_ID, title: "Notifications", iconLetter: "N", + icon: "bell", closeable: true, actions: options.actions, baseLayer: new YieldAtRootLayer(new NotificationsListLayer()), diff --git a/app/ui/shell/settings-app.ts b/app/ui/shell/settings-app.ts index e76db83e..1cf90cb2 100644 --- a/app/ui/shell/settings-app.ts +++ b/app/ui/shell/settings-app.ts @@ -37,6 +37,7 @@ export function createSettingsAppWindow(options: SettingsAppOptions): SettingsAp windowId: SETTINGS_WINDOW_ID, title: "Settings", iconLetter: "Se", + icon: "settings", closeable: true, actions: options.actions, baseLayer: new YieldAtRootLayer(createSettingsMenuLayer()), diff --git a/app/ui/shell/shell.ts b/app/ui/shell/shell.ts index b7c3a6f7..c90f21f7 100644 --- a/app/ui/shell/shell.ts +++ b/app/ui/shell/shell.ts @@ -334,6 +334,11 @@ class Shell { return this.windows[this.selectedIndex] ?? this.windows[0]; } + /** Whether a window is the current input target (foreground + focus in-window). */ + isWindowFocused(windowId: string): boolean { + return this.screenOn && this.focus === "window" && this.foregroundWindow()?.windowId === windowId; + } + private handleSidebarInput(event: DashboardInputEvent): ShellInputOutcome { switch (event.type) { case "double-click": diff --git a/app/ui/shell/teleprompt-app.ts b/app/ui/shell/teleprompt-app.ts index 0fb12bb4..93c45ace 100644 --- a/app/ui/shell/teleprompt-app.ts +++ b/app/ui/shell/teleprompt-app.ts @@ -42,6 +42,7 @@ export function createTelepromptBrowserWindow(options: TelepromptBrowserOptions) windowId: TELEPROMPT_WINDOW_ID, title: "Teleprompt", iconLetter: "Tp", + icon: "file-text", closeable: true, actions: options.actions, baseLayer: browser, @@ -64,6 +65,7 @@ export function createTelepromptDocumentWindow( windowId, title, iconLetter: "Tp", + icon: "file-text", closeable: true, actions: options.actions, baseLayer: new YieldAtRootLayer(new TelepromptLayer(text, title)), diff --git a/app/ui/shell/transcribe-app.ts b/app/ui/shell/transcribe-app.ts index 4bbb2dd9..0e7402b1 100644 --- a/app/ui/shell/transcribe-app.ts +++ b/app/ui/shell/transcribe-app.ts @@ -55,6 +55,7 @@ export function createTranscribeAppWindow(options: TranscribeAppOptions): InProc windowId: TRANSCRIBE_WINDOW_ID, title: "Transcribe", iconLetter: "Tr", + icon: "mic", closeable: true, actions, baseLayer: new YieldAtRootLayer(layer), diff --git a/app/ui/shell/worker-window.ts b/app/ui/shell/worker-window.ts index 7f221f90..99a0e82c 100644 --- a/app/ui/shell/worker-window.ts +++ b/app/ui/shell/worker-window.ts @@ -1,5 +1,6 @@ import { GrayImage } from "../../graphics/image"; -import { makeLetterWindowIcon } from "./chrome-layer"; +import { windowIcon } from "./chrome-layer"; +import { type IconName } from "../../graphics/icons"; import { shell, type ShellWindow } from "./shell"; /** @@ -24,6 +25,7 @@ export type WorkerAppReply = windowId: string; title: string; iconLetter: string; + icon?: IconName; focus?: boolean; } | { type: "set-title"; windowId: string; title: string } @@ -43,6 +45,8 @@ export type WorkerWindowSpec = { windowId: string; title: string; iconLetter: string; + /** Lucide icon name for the sidebar indicator; falls back to iconLetter. */ + icon?: IconName; /** Foreground and focus the window once its surface exists. */ focus?: boolean; }; @@ -84,6 +88,7 @@ export class WorkerAppHost { windowId: message.windowId, title: message.title, iconLetter: message.iconLetter, + icon: message.icon, focus: message.focus, }); break; @@ -134,7 +139,7 @@ export class WorkerAppHost { this.post({ type: "close-window", windowId: spec.windowId }); this.options.removeSurface(surfaceId); }, - drawIcon: makeLetterWindowIcon(spec.iconLetter), + drawIcon: windowIcon(spec.icon, spec.iconLetter), handleInput: (event, frameId) => { this.post({ type: "input", windowId: spec.windowId, event, frameId }); }, diff --git a/app/workers/stopwatch-app.worker.ts b/app/workers/stopwatch-app.worker.ts index c5c9c14c..82d40752 100644 --- a/app/workers/stopwatch-app.worker.ts +++ b/app/workers/stopwatch-app.worker.ts @@ -12,6 +12,7 @@ import * as frameTimings from "../native/frame-timings"; import type { DashboardInputEvent } from "../ui/layers"; import type { WorkerAppMessage } from "../ui/shell/worker-window"; +import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../ui/gestures"; declare const global: any; declare const com: any; @@ -140,8 +141,8 @@ function paint(window: StopwatchWindow): GrayImage { const hintsY = window.viewportHeight - 66; image.drawText(smallFont, 90, hintsY, stateLabel, 150); - image.drawText(smallFont, 90, hintsY + 18, "Click: start / pause", 150); - image.drawText(smallFont, 90, hintsY + 36, "Double-click: back to sidebar", 150); + image.drawText(smallFont, 90, hintsY + 18, `${GESTURE_CLICK} start / pause`, 150); + image.drawText(smallFont, 90, hintsY + 36, `${GESTURE_DOUBLE_CLICK} back`, 150); return image; } diff --git a/app/workers/terminal-app.worker.ts b/app/workers/terminal-app.worker.ts index 6aff58c6..e05d01dd 100644 --- a/app/workers/terminal-app.worker.ts +++ b/app/workers/terminal-app.worker.ts @@ -16,6 +16,7 @@ import "@nativescript/core/globals"; import { GrayImage } from "../graphics/image"; import { getFont } from "../graphics/bdffont"; import * as frameTimings from "../native/frame-timings"; +import { GESTURE_DOUBLE_CLICK } from "../ui/gestures"; import { G2MirrorClient, type G2MirrorSession, @@ -356,7 +357,7 @@ function openViewWindowFor(session: G2MirrorSession): void { const windowId = `terminal:view:${nextViewSerial++}`; const label = sessionLabel(session); pendingViews.set(windowId, { socket: session.socket, label }); - post({ type: "open-window-request", windowId, title: label, iconLetter: "T", focus: true }); + post({ type: "open-window-request", windowId, title: label, iconLetter: "T", icon: "terminal", focus: true }); } function paint(window: TerminalWindow): GrayImage { @@ -389,7 +390,7 @@ function paintHub(window: HubWindow): GrayImage { image.drawText(terminalFont, 32, y + 2, items[index]!.label, selected ? 255 : 200); } - image.drawText(terminalFont, 24, viewportHeight - 24, "Double-click: back to sidebar", 110); + image.drawText(terminalFont, 24, viewportHeight - 24, `${GESTURE_DOUBLE_CLICK} back`, 110); return image; } @@ -404,7 +405,7 @@ function paintView(window: ViewWindow): GrayImage { const image = new GrayImage(viewportWidth, viewportHeight, 0); if (!window.receivedData) { image.drawText(terminalFont, 24, 110, window.status, 170); - image.drawText(terminalFont, 24, 130, "Double-click: back to sidebar", 110); + image.drawText(terminalFont, 24, 130, `${GESTURE_DOUBLE_CLICK} back`, 110); return image; } const cursor = window.emulator.cursor();