Add bluetooth keyboard support

G2 only: You can pair the glasses with a bluetooth keyboard. It will
relay key events, and you can use it to type in some apps and to
navigate the UI.
This commit is contained in:
James Babcock committed 2026-11-15 01:54:54 -08:00
1 parent 9372b2742c
commit fd3c26333f
46 files changed
+3867 -41

No files matched your search

+9
View File
@@ -103,6 +103,7 @@ import { openSettingsSubMenu, SettingsPanelLayer, type SettingsSection } from ".
import { uiFontPickerMenuItem } from "../font-picker";
import { NotificationFilterLayer } from "../notification-filter";
import { compatibleModelDiscoveryMenuItem } from "../openai-compatible-model-picker";
import { keyboardSettingsMenuItem } from "../keyboard-settings";
import { isVeniceApiBaseUrl } from "../../native/openai-chat";
/** The Settings section the Notifications app's "Settings" menu item opens. */
@@ -242,6 +243,14 @@ function settingsSections(): SettingsSection[] {
],
renderDetail: renderWatchStatus,
},
// A Bluetooth keyboard paired with the glasses themselves (the G2's
// custom firmware hosts it; app/g2/keyboard/). Hidden rather than left
// out: the Settings window can be open across a change of glasses.
{
label: "Keyboard",
items: [keyboardSettingsMenuItem()],
hidden: () => glassesTypeSetting.get() !== "g2",
},
{
label: "Developer",
items: [
+30 -2
View File
@@ -28,6 +28,13 @@ export type SettingsSection = {
height: number;
ctx: LayerContext;
}) => number | void;
/**
* Leave the section out of the list while this returns true. Re-read on
* every paint and input, for a section that only applies with some other
* setting (the paired glasses' type): the Settings window outlives changes
* to those.
*/
hidden?: () => boolean;
};
const LEFT_W = 150;
@@ -66,7 +73,7 @@ export class SettingsPanelLayer implements Layer {
constructor(private readonly sections: SettingsSection[]) {
this.leftMenu = new Menu<SettingsSection>({
items: sections,
items: sections.filter((section) => !section.hidden?.()),
wrap: true,
rowGap: ROW_GAP,
highlight: { radius: 6 },
@@ -108,9 +115,28 @@ export class SettingsPanelLayer implements Layer {
return this.leftMenu.selectedItem ?? this.sections[0]!;
}
/**
* Bring the left column in line with which sections are hidden now. The
* highlight stays on its section; if that one just went away it moves to
* the list's start, with focus back in the left column.
*/
private syncSections(): void {
const visible = this.sections.filter((section) => !section.hidden?.());
const shown = this.leftMenu.items;
if (visible.length === shown.length && visible.every((section, index) => section === shown[index])) return;
const selected = this.leftMenu.selectedItem;
const index = selected ? visible.indexOf(selected) : -1;
this.leftMenu.setItems(visible, Math.max(0, index));
if (index < 0) {
this.focus = "left";
this.resetRight();
}
}
/** Select a left-column section by label (deep link, e.g. from an app's menu). */
focusSection(label: string): void {
const index = this.sections.findIndex((section) => section.label === label);
this.syncSections();
const index = this.leftMenu.items.findIndex((section) => section.label === label);
if (index < 0) return;
this.leftMenu.select(index);
this.focus = "left";
@@ -123,6 +149,7 @@ export class SettingsPanelLayer implements Layer {
const { width, height, padding } = viewport;
const image = new GrayImage(width, height, 0);
const appFocused = ctx.stack.isFocused();
this.syncSections();
const section = this.section();
const rightItems = section.items;
this.rightMenu.setItems(rightItems);
@@ -228,6 +255,7 @@ export class SettingsPanelLayer implements Layer {
}
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
this.syncSections();
const scroll = scrollEventFor(event);
if (this.focus === "left") {
if (scroll) {