forked from Blendman974/faceclaw
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:
1 parent
9372b2742c
commit
fd3c26333f
46 files changed
+3867
-41
No files matched your search
@@ -55,6 +55,8 @@ import {
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import { getActiveDisplay } from "../../native/active-display";
|
||||
import { GESTURE_DOUBLE_CLICK, type InputEvent } from "../../ui/gestures";
|
||||
import { navigationGestureForKey, type KeyEvent } from "../../g2/keyboard/keys";
|
||||
import { encodeTerminalKey, terminalScrollbackKey } from "./terminal-keys";
|
||||
import { G2MirrorClient, type G2MirrorClientOptions, type G2MirrorSession, type G2MirrorState } from "../../native/g2mirror-client";
|
||||
import { onSettingsStoreChanged } from "../../native/settings-store";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
@@ -435,6 +437,13 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "key": {
|
||||
const window = windows.get(message.windowId);
|
||||
if (!window) break;
|
||||
window.focused = message.focused;
|
||||
handleKey(window, message.event as KeyEvent);
|
||||
break;
|
||||
}
|
||||
case "render": {
|
||||
const window = windows.get(message.windowId);
|
||||
if (!window) break;
|
||||
@@ -1260,6 +1269,35 @@ function handleInput(window: TerminalWindow, event: InputEvent, frameId: number)
|
||||
frameTimings.finishFrame(frameId, "discarded: terminal view ignored input");
|
||||
}
|
||||
|
||||
/**
|
||||
* A key from a hardware keyboard (the glasses' keyboard bridge). A session
|
||||
* with nothing over it gets the key as its terminal would, every key
|
||||
* included: Escape and the arrows belong to the program, so leaving is still
|
||||
* the ring's double tap. Anywhere else (the hub's lists, an open menu) the
|
||||
* navigation keys act as the ring gestures they stand for.
|
||||
*/
|
||||
function handleKey(window: TerminalWindow, event: KeyEvent): void {
|
||||
if (window.kind === "view" && !window.menu?.isOpen()) {
|
||||
activeViewId = window.windowId;
|
||||
const page = terminalScrollbackKey(event);
|
||||
if (page !== null) {
|
||||
handleViewScroll(window, page, 0);
|
||||
return;
|
||||
}
|
||||
const bytes = encodeTerminalKey(event, window.emulator.applicationCursorKeys());
|
||||
if (bytes === null) return;
|
||||
// Typing follows the live screen, as in any terminal emulator.
|
||||
if (window.scrollTop !== null) {
|
||||
window.scrollTop = null;
|
||||
scheduleRender(window);
|
||||
}
|
||||
window.client.sendInput(bytes);
|
||||
return;
|
||||
}
|
||||
const gesture = navigationGestureForKey(event);
|
||||
if (gesture) handleInput(window, { type: gesture, source: "ring", timestampMs: event.timestampMs }, 0);
|
||||
}
|
||||
|
||||
/** Top visible absolute line index when following the live bottom. */
|
||||
function followTop(window: ViewWindow): number {
|
||||
return window.historyNext + window.emulator.bufferLength() - window.gridRows;
|
||||
@@ -1800,6 +1838,7 @@ function openViewWindow(control: ControlConnection, socket: string, label: strin
|
||||
focus: true,
|
||||
// Default to tall sessions; the app display setting can override this.
|
||||
heightMode: "max",
|
||||
acceptsKeys: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user