Merge configurable menu gestures

# Conflicts:
#	app/ui/shell/shell.ts
#	tests/ai-chat.test.cjs
#	tests/brightness-picker.test.cjs
This commit is contained in:
Blendman974 committed 2026-11-06 04:46:29 +01:00
commit 5ae06c1818
11 files changed
+168 -13

No files matched your search

+8
View File
@@ -667,6 +667,14 @@ export function getBrightnessPreferences() {
curve: autoBrightnessCurveSetting.getValidValue(), fadeMs: scaleAnimationDuration(SCREEN_FADE_MS, screenFadeSetting.get()) };
}
export const swapMenuGesturesSetting = new ConfigSettingBoolean({
id: "swap-menu-gestures",
label: "Long press for app menu",
storageKey: "input.swapMenuGestures",
defaultValue: false,
description: "Use long press for the app menu and tap then hold for the system menu. Apps using long press for a game action or voice capture keep their gestures. The app switcher keeps its system menu gestures.",
});
export const wakeToLastAppSetting = new ConfigSettingBoolean({
id: "wake-to-last-app",
label: "Wake into last app",
+2
View File
@@ -92,6 +92,7 @@ import {
voiceLanguageSetting,
screenTimeoutSetting,
wakeToLastAppSetting,
swapMenuGesturesSetting,
wakeWordActionSetting,
watchCanUnlockSetting,
watchCrownClockwiseNextSetting,
@@ -129,6 +130,7 @@ function settingsSections(): SettingsSection[] {
}),
toggleSettingMenuItem(lockScreenEnabledSetting),
toggleSettingMenuItem(wakeToLastAppSetting),
toggleSettingMenuItem(swapMenuGesturesSetting),
// A band (at one of five heights) / Tall / Full Screen; the
// dashboard controller moves or reflows windows on change.
enumSettingMenuItem(displayLayoutSetting),
+17 -6
View File
@@ -9,6 +9,7 @@ import {
directionalFallback,
type DirectionalInputEvent,
GESTURE_SHORT_THEN_LONG_PRESS,
GESTURE_LONG_PRESS,
gestureHints,
InputEvent,
type InputEventPayload,
@@ -55,6 +56,7 @@ import {
timeFormatSetting,
wakeWordActionSetting,
wakeToLastAppSetting,
swapMenuGesturesSetting,
windowBorderSetting,
} from "../dashboard-settings";
import { onAmbientCardsChanged } from "./ambient-cards";
@@ -1077,7 +1079,15 @@ class Shell {
return { shell: false, window: false };
}
// Long-press is the shell's own gesture: it opens the system menu
// Remap menu intent only. Apps still receive the canonical context-menu
// event, while owned holds (games / voice) retain their raw input.
const menuWindow = this.foregroundWindow();
const swapMenus = this.focus === "window" && swapMenuGesturesSetting.get() &&
!menuWindow?.holdToTalk && !menuWindow?.claimsLongPress?.();
const systemMenuGesture = swapMenus ? "short-then-long-press" : "long-press";
const appMenuGesture = swapMenus ? "long-press" : "short-then-long-press";
// The resolved system gesture opens the shell's own menu
// directly, never reaching the app — over the app's own context menu
// too (the window closes that on system-menu-opened), while an already
// open system menu just stays. Its later generic release is consumed
@@ -1085,7 +1095,7 @@ class Shell {
// app. The exception is a window that claims long-press for a move of
// its own: it gets the press forwarded, with the escape timer running
// so that holding the press long enough still opens the system menu.
if (event.type === "long-press") {
if (event.type === systemMenuGesture) {
if (this.activeVoiceLayer || !this.stack.isAtBase()) {
return { shell: true, window: false };
}
@@ -1109,11 +1119,11 @@ class Shell {
return { shell: true, window: true };
}
// The 2.2.9 tap-then-hold gesture is the app's context-menu gesture: it
// The resolved app-menu gesture is delivered as tap-then-hold: it
// goes to the foreground window (from the sidebar it focuses the window
// first), which answers with its own menu or asks for the system menu
// when it has none.
if (event.type === "short-then-long-press") {
if (event.type === appMenuGesture) {
if (this.focus === "sidebar" && !this.activeVoiceLayer && this.stack.isAtBase()) {
this.openEscapeMenu();
return { shell: true, window: false };
@@ -1145,7 +1155,7 @@ class Shell {
window.onFocus?.(this.lastInput);
}
// The window owns frameId from here (render or explicit finish).
await window.handleInput(event, frameId);
await window.handleInput(swapMenus ? { ...event, type: "short-then-long-press" } : event, frameId);
return { shell: true, window: true };
}
if (event.type === "long-press-release") {
@@ -2034,7 +2044,8 @@ class Shell {
// when the app has one (otherwise it opens this very menu, not worth a
// hint).
const footer = foreground.hasAppMenu?.()
? (foreground.holdToTalk ? undefined : gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "app menu"]]))
? (foreground.holdToTalk ? undefined : gestureHints([[this.focus === "window" && swapMenuGesturesSetting.get() && !foreground.claimsLongPress?.()
? GESTURE_LONG_PRESS : GESTURE_SHORT_THEN_LONG_PRESS, "app menu"]]))
: undefined;
const layer = new ShellOverlayMenuLayer(items, footer, () => this.yieldFocusToSidebar());
layer.selectItem(initialSelection);
+7 -5
View File
@@ -1,3 +1,4 @@
import { swapMenuGesturesSetting } from "./dashboard-settings";
import { GrayImage } from "../graphics/image";
import { singlePlane, type Plane } from "../graphics/plane";
import { GESTURE_LONG_PRESS, GESTURE_SHORT_THEN_LONG_PRESS, gestureHints, type InputEvent } from "./gestures";
@@ -6,8 +7,9 @@ import { CONTEXT_MENU_DIM, MenuLayer, type MenuItem, type MenuLayout } from "./m
import type { WorkerAppReply } from "./shell/worker-window";
/**
* The window context menu, opened by tap-then-hold: an app's own menu,
* holding its app-specific actions. The shell's system menu (long-press)
* The window context menu, opened by tap-then-hold by default: an app's own menu,
* holding its app-specific actions. The menu gesture preference can swap
* these bindings unless the app owns long-press. The shell's system menu
* carries the entries every window shares — Focus app switcher, Voice input,
* Close current app, Close all apps — so an app with nothing of its own to offer has no menu of
* its own: tap-then-hold then opens the system menu in its place, so both
@@ -28,8 +30,8 @@ export const WINDOW_MENU_LAYOUT: MenuLayout = {
};
export class WindowMenuLayer extends MenuLayer {
constructor(title: string | null, items: MenuItem[], holdToTalk = false) {
super(title, items, holdToTalk
constructor(title: string | null, items: MenuItem[], holdToTalk = false, claimsLongPress = false) {
super(title, items, (holdToTalk || (swapMenuGesturesSetting.get() && !claimsLongPress))
? { ...WINDOW_MENU_LAYOUT, footer: gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "system menu"]]) }
: WINDOW_MENU_LAYOUT);
}
@@ -123,7 +125,7 @@ export class WindowMenu {
handleInput: () => {},
};
const stack = new LayerStack(base, this.layerActions(), this.options.size, this.options.isFocused);
const layer = new WindowMenuLayer(title, items);
const layer = new WindowMenuLayer(title, items, false, this.options.claimsLongPress?.() ?? false);
if (selectedIndex !== undefined) layer.selectItem(selectedIndex);
stack.push(layer);
this.stack = stack;