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

+24
View File
@@ -17,6 +17,7 @@ import {
isWatchInput,
makeInputEvent,
} from "../gestures";
import type { KeyEvent } from "../../g2/keyboard/keys";
import { Layer, LayerActions, LayerContext, LayerStack, noopLayerActions } from "../layers";
import { CONTEXT_MENU_DIM, MenuLayer, type MenuItem } from "../menu";
import { VoiceInputLayer, type VoiceSendTarget } from "./voice-input";
@@ -192,6 +193,14 @@ export type ShellWindow = {
* only windows that consume typed text (the terminal) implement it.
*/
receiveTextInput?: (text: string, options?: { submit?: boolean }) => void;
/**
* Take a key from a hardware keyboard (app/g2/keyboard) as a key. Optional:
* only windows that give keys a meaning of their own (the terminal)
* implement it, and they get every key while they have input focus,
* presses and releases alike. For the rest the controller turns the few
* navigation keys into ring gestures (navigationGestureForKey).
*/
handleKeyEvent?: (event: KeyEvent) => void;
/** Foreground state changed: this window's surface is (not) the visible one. */
setForeground?: (foreground: boolean) => void;
/**
@@ -1606,6 +1615,21 @@ class Shell {
this.foregroundWindow()?.receiveTextInput?.(text, options);
}
/**
* Offer a hardware-keyboard key to the window that has input focus. True
* when that window takes keys (ShellWindow.handleKeyEvent) and got this
* one; false when the key is the caller's to interpret: the screen is off,
* the sidebar or a shell overlay has focus, or the window has no use for
* keys. Typing counts as activity for the screen timeout.
*/
receiveKeyEvent(event: KeyEvent): boolean {
const window = this.inputTargetWindow();
if (!window?.handleKeyEvent) return false;
if (event.phase === "down") this.lastInputAtMs = Date.now();
window.handleKeyEvent(event);
return true;
}
/**
* Open the voice dialog aimed at the foreground window. Called when the
* user picks Voice input from the system menu (or an app asks via a
+19
View File
@@ -28,6 +28,8 @@ export type WorkerAppMessage =
| { type: "close-window"; windowId: string }
| { type: "input"; windowId: string; event: unknown; frameId: number; focused: boolean }
| { type: "text-input"; windowId: string; text: string; submit?: boolean }
/** A hardware-keyboard key (a KeyEvent), for windows opened with acceptsKeys. */
| { type: "key"; windowId: string; event: unknown; focused: boolean }
| { type: "render"; windowId: string; focused: boolean }
| { type: "foreground"; windowId: string; foreground: boolean; focused: boolean }
/**
@@ -81,6 +83,8 @@ export type WorkerAppReply =
focus?: boolean;
/** Window height: the standard 288px band ("min", default) or full screen ("max"). */
heightMode?: WindowHeightMode;
/** Send the window hardware-keyboard keys (see WorkerWindowSpec). */
acceptsKeys?: boolean;
}
| {
/**
@@ -196,6 +200,13 @@ export type WorkerWindowSpec = {
* of all four directions in every window state (see ShellWindow).
*/
acceptsDirectional?: boolean;
/**
* Deliver hardware-keyboard keys to the worker as "key" messages while the
* window has input focus, instead of the navigation-gesture fallback. The
* worker then owns what every key means in every window state, navigation
* included (see ShellWindow.handleKeyEvent).
*/
acceptsKeys?: boolean;
};
export type WorkerAppHostOptions = {
@@ -335,6 +346,7 @@ export class WorkerAppHost {
iconGlyph: message.iconGlyph,
focus: message.focus,
heightMode: message.heightMode,
acceptsKeys: message.acceptsKeys,
});
break;
case "set-height-mode":
@@ -522,6 +534,13 @@ export class WorkerAppHost {
receiveTextInput: (text, options) => {
this.post({ type: "text-input", windowId: spec.windowId, text, ...(options?.submit === undefined ? {} : { submit: options.submit }) });
},
...(spec.acceptsKeys
? {
handleKeyEvent: (event) => {
this.post({ type: "key", windowId: spec.windowId, event, focused: shell.isWindowFocused(spec.windowId) });
},
}
: {}),
setForeground: (foreground) => {
this.options.setSurfaceVisible(surfaceId, foreground);
if (foreground) {