Desktop: Make input routing aware of floating menus (#4498)

* Desktop: Make input routing aware of floating menus

* Desktop: Route mouse input like pen input

* Desktop: Model pointer input routing as a state machine
This commit is contained in:
Timon
2026-09-06 01:29:18 +00:00
committed by GitHub
parent 80746a7f55
commit 63725ea623
12 changed files with 188 additions and 59 deletions
+25 -1
View File
@@ -20,6 +20,7 @@ let canvasFocused = true;
let inPointerLock = false;
let lastShakeTime = 0;
const shakeSamples: { x: number; y: number; time: number }[] = [];
const openFloatingMenus = new Set<string>();
// Keyboard events
@@ -243,8 +244,14 @@ export function onWheelScroll(e: WheelEvent, editor: EditorWrapper) {
// Receives a custom event dispatched when the user begins interactively editing with the text tool.
// We keep a copy of the text input element to check against when it's active for text entry.
export function onModifyInputField(e: CustomEvent) {
export function onModifyInputField(e: CustomEvent, editor: EditorWrapper) {
textToolInteractiveInputElement = e.detail;
updateDirectInput(editor);
}
export function cleanupInputField(editor: EditorWrapper) {
textToolInteractiveInputElement = undefined;
updateDirectInput(editor);
}
// Window events
@@ -387,3 +394,20 @@ function potentiallyRestoreCanvasFocus(e: Event) {
app?.focus();
}
}
// Direct input (desktop only)
// Desktop may route viewport pointer input directly to the editor if no floating menus are open
export function updateDirectInput(editor: EditorWrapper) {
if (import.meta.env.MODE !== "native") return;
const uiCapturesViewport = openFloatingMenus.size > 0 || textToolInteractiveInputElement !== undefined;
editor.appWindowDirectInput(!uiCapturesViewport);
}
export function onFloatingMenuOpenChange(menuId: string, open: boolean, editor: EditorWrapper) {
if (open) openFloatingMenus.add(menuId);
else openFloatingMenus.delete(menuId);
updateDirectInput(editor);
}