Add brightness control to the system context menu

This commit is contained in:
James Babcock committed 2026-09-09 02:09:08 -07:00
1 parent 0765e943fb
commit 92d5857c3e
3 files changed
+81 -2

No files matched your search

+1
View File
@@ -6,6 +6,7 @@
* Notifications: Add notification filters
* Phone screen preview: Add rotation option; improve landscape layout
* Add "AI Chat" app (conversational-style use of the voice assistant with hold-to-talk)
* Add rightness control to the system context menu
## 0.6.5 - 2026-09-04
* Changed context menu gestures: — for system, ●— for app context menu.
+66
View File
@@ -0,0 +1,66 @@
import type { GrayImage } from "../../graphics/image";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { clamp } from "../../util/numeric-util";
import { brightnessSetting, brightnessSettingToLevel, type BrightnessSetting } from "../dashboard-settings";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, gestureHints, type InputEvent } from "../gestures";
import type { Layer, LayerContext, PaintBelow } from "../layers";
import { appViewportRect, SHELL_OPAQUE_BLACK } from "./geometry";
const DIALOG_WIDTH = 272;
const BAR_WIDTH = 12;
const BAR_HEIGHT = 100;
/** Manual brightness changes apply immediately so the wearer can judge the level. */
export class BrightnessPickerLayer implements Layer {
constructor(private readonly onClosed: () => void) {}
onRemoved(): void {
this.onClosed();
}
paint(_ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
const image = paintBelow();
const font = getDefaultSmallFont();
const viewport = appViewportRect("min");
const height = BAR_HEIGHT + 3 * font.lineHeight + 56;
const left = viewport.x + Math.round((viewport.width - DIALOG_WIDTH) / 2);
const top = viewport.y + Math.round((viewport.height - height) / 2);
image.fillRoundedRect(left, top, DIALOG_WIDTH, height, SHELL_OPAQUE_BLACK, 8);
image.drawRoundedRect(left, top, DIALOG_WIDTH, height, 110, 8);
const centeredText = (text: string, y: number, value: number) => {
image.drawText(font, left + Math.round((DIALOG_WIDTH - font.measureText(text)) / 2), y, text, value);
};
centeredText("Brightness", top + 12, 235);
const barX = left + Math.round((DIALOG_WIDTH - BAR_WIDTH) / 2);
const barY = top + font.lineHeight + 24;
const level = brightnessSettingToLevel(brightnessSetting.get());
image.drawRect(barX - 2, barY - 2, BAR_WIDTH + 4, BAR_HEIGHT + 4, 150);
const filledHeight = Math.round(BAR_HEIGHT * (level ?? 0) / 100);
image.fillRect(barX, barY + BAR_HEIGHT - filledHeight, BAR_WIDTH, filledHeight, 255);
image.drawText(font, barX + BAR_WIDTH + 12, barY + Math.round((BAR_HEIGHT - font.lineHeight) / 2),
level === null ? "Auto" : `${level}%`, 235);
centeredText(gestureHints([[GESTURE_SCROLL, "adjust"]]), barY + BAR_HEIGHT + 12, 150);
centeredText(gestureHints([[`${GESTURE_CLICK} / ${GESTURE_DOUBLE_CLICK}`, "confirm"]]),
barY + BAR_HEIGHT + font.lineHeight + 16, 150);
return image;
}
handleInput(event: InputEvent, ctx: LayerContext): void {
switch (event.type) {
case "scroll-up":
case "scroll-down": {
const level = brightnessSettingToLevel(brightnessSetting.get());
// Respect Auto if it was enabled on the phone while this dialog was open.
if (level === null) return;
const next = clamp(level + (event.type === "scroll-up" ? 10 : -10), 0, 100);
if (next !== level) brightnessSetting.set(String(next) as BrightnessSetting);
return;
}
case "click":
case "double-click":
ctx.stack.pop();
return;
}
}
}
+14 -2
View File
@@ -35,6 +35,7 @@ import {
assistantModelSetting,
assistantSkipConfirmationSetting,
batteryDisplayModeSetting,
brightnessSetting,
onAnySettingChanged,
openAiApiKeySetting,
timeFormatSetting,
@@ -44,6 +45,7 @@ import { onAmbientCardsChanged } from "./ambient-cards";
import { ShellChromeLayer, sidebarContentLeft, 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 {
minWindowTop,
@@ -63,7 +65,7 @@ import {
* Input flow: every event enters via receiveInput. The shell consumes
* everything while the sidebar or a shell overlay has focus and forwards the
* rest to the focused window. Long-press opens the shell-owned system menu
* (Focus app switcher, Voice input, Close window, Debug) without reaching the
* (Focus app switcher, Voice input, Brightness, Close window, Debug) without reaching the
* app, so the shell keeps working when a window's handler hangs; a window
* that claims long-press for a move of its own gets it forwarded instead, and
* holding the press past the escape threshold still opens the system menu.
@@ -1337,7 +1339,7 @@ class Shell {
/**
* The system/escape menu: the entries every window shares (Focus app
* switcher, Voice input, Close window) plus Debug. Shell-owned and
* switcher, Voice input, Brightness, Close window) plus Debug. Shell-owned and
* shell-drawn (never the app's), so an unresponsive app can always be
* closed. It opens for long-press (over the app's own menu too), after an
* extended hold in a window that claims long-press, and on a window's
@@ -1384,6 +1386,16 @@ class Shell {
},
},
);
if (brightnessSetting.get() !== "auto") {
items.push({
label: "Brightness",
onSelect: (ctx) => {
ctx.stack.pop();
ctx.stack.push(new BrightnessPickerLayer(() => this.yieldFocusToSidebar()));
this.config.requestShellRender();
},
});
}
items.push({
label: "Debug",
onSelect: (ctx) => {