@gtkx/testing 2.0.0-beta.11 → 2.0.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/accessible-native.d.ts.map +1 -1
- package/dist/accessible-native.js.map +1 -1
- package/dist/act.d.ts +7 -1
- package/dist/act.d.ts.map +1 -1
- package/dist/act.js +54 -4
- package/dist/act.js.map +1 -1
- package/dist/bound-queries.d.ts +1 -1
- package/dist/bound-queries.d.ts.map +1 -1
- package/dist/bound-queries.js.map +1 -1
- package/dist/build-queries.d.ts +1 -1
- package/dist/build-queries.d.ts.map +1 -1
- package/dist/build-queries.js +1 -1
- package/dist/build-queries.js.map +1 -1
- package/dist/cleanup-registry.d.ts.map +1 -1
- package/dist/cleanup-registry.js +4 -1
- package/dist/cleanup-registry.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/editable.d.ts.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +16 -4
- package/dist/fire-event.js.map +1 -1
- package/dist/frame-sync.d.ts.map +1 -1
- package/dist/frame-sync.js +1 -10
- package/dist/frame-sync.js.map +1 -1
- package/dist/harness-window.d.ts +8 -2
- package/dist/harness-window.d.ts.map +1 -1
- package/dist/harness-window.js +28 -5
- package/dist/harness-window.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +5 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +5 -0
- package/dist/internal.js.map +1 -1
- package/dist/matchers.d.ts +4 -1
- package/dist/matchers.d.ts.map +1 -1
- package/dist/matchers.js +29 -9
- package/dist/matchers.js.map +1 -1
- package/dist/normalize.d.ts +1 -1
- package/dist/normalize.d.ts.map +1 -1
- package/dist/normalize.js +1 -1
- package/dist/normalize.js.map +1 -1
- package/dist/pretty-widget.d.ts +4 -2
- package/dist/pretty-widget.d.ts.map +1 -1
- package/dist/pretty-widget.js +7 -5
- package/dist/pretty-widget.js.map +1 -1
- package/dist/production.d.ts.map +1 -1
- package/dist/queries.d.ts +2 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +22 -11
- package/dist/queries.js.map +1 -1
- package/dist/register-test-hooks.js +8 -0
- package/dist/register-test-hooks.js.map +1 -1
- package/dist/render-hook.js.map +1 -1
- package/dist/render.d.ts +14 -6
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +46 -31
- package/dist/render.js.map +1 -1
- package/dist/role-helpers.d.ts.map +1 -1
- package/dist/role-helpers.js.map +1 -1
- package/dist/role-naming.d.ts.map +1 -1
- package/dist/screen.d.ts.map +1 -1
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js.map +1 -1
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.d.ts.map +1 -1
- package/dist/suggestions.js +1 -1
- package/dist/suggestions.js.map +1 -1
- package/dist/timers.d.ts.map +1 -1
- package/dist/traversal.d.ts.map +1 -1
- package/dist/types.d.ts +10 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/usage-error.d.ts +9 -0
- package/dist/usage-error.d.ts.map +1 -0
- package/dist/usage-error.js +13 -0
- package/dist/usage-error.js.map +1 -0
- package/dist/user-event/adjustment.d.ts.map +1 -1
- package/dist/user-event/adjustment.js +6 -5
- package/dist/user-event/adjustment.js.map +1 -1
- package/dist/user-event/click.d.ts +15 -7
- package/dist/user-event/click.d.ts.map +1 -1
- package/dist/user-event/click.js +165 -44
- package/dist/user-event/click.js.map +1 -1
- package/dist/user-event/column-header-click.d.ts.map +1 -1
- package/dist/user-event/column-header-click.js +1 -1
- package/dist/user-event/column-header-click.js.map +1 -1
- package/dist/user-event/controller.d.ts +11 -3
- package/dist/user-event/controller.d.ts.map +1 -1
- package/dist/user-event/controller.js +26 -4
- package/dist/user-event/controller.js.map +1 -1
- package/dist/user-event/dispatch.d.ts +1 -1
- package/dist/user-event/dispatch.d.ts.map +1 -1
- package/dist/user-event/dispatch.js +9 -6
- package/dist/user-event/dispatch.js.map +1 -1
- package/dist/user-event/editable-label-click.d.ts +5 -0
- package/dist/user-event/editable-label-click.d.ts.map +1 -0
- package/dist/user-event/editable-label-click.js +12 -0
- package/dist/user-event/editable-label-click.js.map +1 -0
- package/dist/user-event/event-wrapper.d.ts +11 -1
- package/dist/user-event/event-wrapper.d.ts.map +1 -1
- package/dist/user-event/event-wrapper.js +66 -12
- package/dist/user-event/event-wrapper.js.map +1 -1
- package/dist/user-event/gesture.d.ts.map +1 -1
- package/dist/user-event/gesture.js +70 -29
- package/dist/user-event/gesture.js.map +1 -1
- package/dist/user-event/index.d.ts +55 -18
- package/dist/user-event/index.d.ts.map +1 -1
- package/dist/user-event/index.js +43 -9
- package/dist/user-event/index.js.map +1 -1
- package/dist/user-event/indexed-children.d.ts.map +1 -1
- package/dist/user-event/keyboard.d.ts +27 -2
- package/dist/user-event/keyboard.d.ts.map +1 -1
- package/dist/user-event/keyboard.js +291 -44
- package/dist/user-event/keyboard.js.map +1 -1
- package/dist/user-event/list-row-click.d.ts +2 -1
- package/dist/user-event/list-row-click.d.ts.map +1 -1
- package/dist/user-event/list-row-click.js +10 -6
- package/dist/user-event/list-row-click.js.map +1 -1
- package/dist/user-event/native-click.d.ts +2 -1
- package/dist/user-event/native-click.d.ts.map +1 -1
- package/dist/user-event/native-click.js +17 -5
- package/dist/user-event/native-click.js.map +1 -1
- package/dist/user-event/notebook-tab-click.d.ts.map +1 -1
- package/dist/user-event/notebook-tab-click.js +1 -1
- package/dist/user-event/notebook-tab-click.js.map +1 -1
- package/dist/user-event/pointer.d.ts +5 -3
- package/dist/user-event/pointer.d.ts.map +1 -1
- package/dist/user-event/pointer.js +72 -27
- package/dist/user-event/pointer.js.map +1 -1
- package/dist/user-event/selection.d.ts.map +1 -1
- package/dist/user-event/selection.js +46 -15
- package/dist/user-event/selection.js.map +1 -1
- package/dist/user-event/state.d.ts +2 -1
- package/dist/user-event/state.d.ts.map +1 -1
- package/dist/user-event/state.js +1 -1
- package/dist/user-event/state.js.map +1 -1
- package/dist/user-event/tab-view-click.d.ts +8 -0
- package/dist/user-event/tab-view-click.d.ts.map +1 -0
- package/dist/user-event/tab-view-click.js +37 -0
- package/dist/user-event/tab-view-click.js.map +1 -0
- package/dist/user-event/text.d.ts +3 -2
- package/dist/user-event/text.d.ts.map +1 -1
- package/dist/user-event/text.js +34 -14
- package/dist/user-event/text.js.map +1 -1
- package/dist/wait-for.d.ts.map +1 -1
- package/dist/wait-for.js.map +1 -1
- package/dist/widget-accessible-properties.d.ts +13 -3
- package/dist/widget-accessible-properties.d.ts.map +1 -1
- package/dist/widget-accessible-properties.js +59 -21
- package/dist/widget-accessible-properties.js.map +1 -1
- package/dist/widget-getters.d.ts.map +1 -1
- package/dist/widget-getters.js +0 -1
- package/dist/widget-getters.js.map +1 -1
- package/dist/widget-target.d.ts.map +1 -1
- package/dist/widget-target.js +2 -1
- package/dist/widget-target.js.map +1 -1
- package/dist/window-state.d.ts.map +1 -1
- package/dist/window-state.js +3 -1
- package/dist/window-state.js.map +1 -1
- package/dist/within.d.ts.map +1 -1
- package/dist/within.js.map +1 -1
- package/package.json +17 -19
- package/src/accessible-native.ts +2 -2
- package/src/act.ts +70 -6
- package/src/bound-queries.ts +1 -1
- package/src/build-queries.ts +52 -70
- package/src/cleanup-registry.ts +5 -1
- package/src/errors.ts +6 -6
- package/src/fire-event.ts +23 -9
- package/src/frame-sync.ts +1 -13
- package/src/harness-window.ts +37 -6
- package/src/index.ts +2 -12
- package/src/internal.ts +5 -0
- package/src/matchers.ts +70 -42
- package/src/normalize.ts +1 -4
- package/src/pretty-widget.ts +8 -5
- package/src/queries.ts +42 -21
- package/src/register-test-hooks.ts +11 -0
- package/src/render-hook.tsx +1 -1
- package/src/render.tsx +57 -36
- package/src/role-helpers.ts +1 -1
- package/src/screenshot.ts +3 -8
- package/src/suggestions.ts +1 -1
- package/src/types.ts +22 -17
- package/src/usage-error.ts +16 -0
- package/src/user-event/adjustment.ts +10 -7
- package/src/user-event/click.ts +221 -48
- package/src/user-event/column-header-click.ts +1 -1
- package/src/user-event/controller.ts +49 -4
- package/src/user-event/dispatch.ts +17 -7
- package/src/user-event/editable-label-click.ts +17 -0
- package/src/user-event/event-wrapper.ts +105 -14
- package/src/user-event/gesture.ts +105 -35
- package/src/user-event/index.ts +113 -57
- package/src/user-event/keyboard.ts +416 -52
- package/src/user-event/list-row-click.ts +12 -6
- package/src/user-event/native-click.ts +23 -6
- package/src/user-event/notebook-tab-click.ts +1 -1
- package/src/user-event/pointer.ts +101 -35
- package/src/user-event/selection.ts +72 -25
- package/src/user-event/state.ts +4 -2
- package/src/user-event/tab-view-click.ts +59 -0
- package/src/user-event/text.ts +42 -18
- package/src/wait-for.ts +1 -4
- package/src/widget-accessible-properties.ts +85 -26
- package/src/widget-getters.ts +1 -3
- package/src/widget-target.ts +2 -1
- package/src/window-state.ts +4 -3
- package/src/within.ts +2 -2
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import * as Gdk from "@gtkx/gi/gdk";
|
|
2
2
|
import * as Gio from "@gtkx/gi/gio";
|
|
3
3
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
4
|
+
import { getInstanceType, TYPE_INVALID, typeFromName, typeIsA } from "@gtkx/runtime";
|
|
4
5
|
import { hasSignalListener } from "@gtkx/runtime/internal";
|
|
5
6
|
import type { UserEventState } from "./state.js";
|
|
6
7
|
import { getEditableDelegate } from "../editable.js";
|
|
7
8
|
import { fireEvent } from "../fire-event.js";
|
|
8
|
-
import { ancestors, descendants } from "../traversal.js";
|
|
9
|
+
import { ancestors, children, descendants } from "../traversal.js";
|
|
10
|
+
import { receivesEventsFor } from "./controller.js";
|
|
9
11
|
import { wrapEvent } from "./event-wrapper.js";
|
|
12
|
+
import { usageError } from "../usage-error.js";
|
|
13
|
+
import { getWidgetTypeName } from "../widget-getters.js";
|
|
14
|
+
import { activeToplevel, mappedToplevels } from "../window-state.js";
|
|
10
15
|
|
|
11
16
|
/** Options for `userEvent.tab`. */
|
|
12
17
|
type TabOptions = {
|
|
@@ -16,9 +21,16 @@ type TabOptions = {
|
|
|
16
21
|
|
|
17
22
|
type KeyAction = { keyval: number; isPress: boolean };
|
|
18
23
|
type ParseStep = { actions: KeyAction[]; next: number };
|
|
24
|
+
type TypedStep = { text: string } | { actions: KeyAction[] };
|
|
25
|
+
type TypedParseStep = { step: TypedStep; next: number };
|
|
19
26
|
type KeyStopController = Gtk.EventControllerKey | Gtk.ShortcutController;
|
|
20
|
-
type
|
|
27
|
+
type ControllerStop = { widget: Gtk.Widget; controller: KeyStopController };
|
|
28
|
+
type CompletionStop = { widget: Gtk.Widget; completionList: Gtk.Widget };
|
|
29
|
+
type KeyStop = ControllerStop | CompletionStop;
|
|
21
30
|
type KeyTarget = { root: Gtk.Root | null; focus: Gtk.Widget | null };
|
|
31
|
+
type MatchingShortcut = { shortcut: Gtk.Shortcut; host: Gtk.Widget; index: number };
|
|
32
|
+
|
|
33
|
+
const lastActivatedShortcuts: WeakMap<Gtk.ShortcutController, number> = new WeakMap();
|
|
22
34
|
|
|
23
35
|
const KEY_MAP: Record<string, number> = {
|
|
24
36
|
Enter: Gdk.KEY_Return,
|
|
@@ -54,6 +66,7 @@ const KEY_MAP: Record<string, number> = {
|
|
|
54
66
|
};
|
|
55
67
|
|
|
56
68
|
const KEY_CONTROLLER_SIGNALS = ["key-pressed", "key-released"];
|
|
69
|
+
const LITERAL_BRACE = "{{";
|
|
57
70
|
|
|
58
71
|
const MODIFIER_KEYVAL_TO_MASK: Record<number, number> = {
|
|
59
72
|
[Gdk.KEY_Shift_L]: Gdk.ModifierType.SHIFT_MASK,
|
|
@@ -66,6 +79,17 @@ const MODIFIER_KEYVAL_TO_MASK: Record<number, number> = {
|
|
|
66
79
|
[Gdk.KEY_Meta_R]: Gdk.ModifierType.META_MASK,
|
|
67
80
|
};
|
|
68
81
|
|
|
82
|
+
const MODIFIER_NAMES: [string, number][] = [
|
|
83
|
+
["Control", Gdk.ModifierType.CONTROL_MASK],
|
|
84
|
+
["Shift", Gdk.ModifierType.SHIFT_MASK],
|
|
85
|
+
["Alt", Gdk.ModifierType.ALT_MASK],
|
|
86
|
+
["Meta", Gdk.ModifierType.META_MASK],
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
/** The modifier keys pressed and not yet released, named as `keyboard` input names them. */
|
|
90
|
+
const heldModifiers = (state: UserEventState): string[] =>
|
|
91
|
+
MODIFIER_NAMES.filter(([, mask]) => (state.modifierState & mask) !== 0).map(([name]) => name);
|
|
92
|
+
|
|
69
93
|
/** Moves focus within the widget's root. */
|
|
70
94
|
const tab = (widget: Gtk.Widget, options?: TabOptions): Promise<void> =>
|
|
71
95
|
wrapEvent(widget, () => {
|
|
@@ -77,6 +101,12 @@ const tab = (widget: Gtk.Widget, options?: TabOptions): Promise<void> =>
|
|
|
77
101
|
}
|
|
78
102
|
});
|
|
79
103
|
|
|
104
|
+
const characterKeyval = (keyName: string): number | undefined => {
|
|
105
|
+
const [character, ...rest] = Array.from(keyName);
|
|
106
|
+
|
|
107
|
+
return character === undefined || rest.length > 0 ? undefined : Gdk.unicodeToKeyval(character.codePointAt(0) ?? 0);
|
|
108
|
+
};
|
|
109
|
+
|
|
80
110
|
const parseKeyToken = (token: string): { keyval: number; isPress: boolean; isRelease: boolean } => {
|
|
81
111
|
let keyName = token;
|
|
82
112
|
let isPress = true;
|
|
@@ -90,10 +120,10 @@ const parseKeyToken = (token: string): { keyval: number; isPress: boolean; isRel
|
|
|
90
120
|
isRelease = false;
|
|
91
121
|
}
|
|
92
122
|
|
|
93
|
-
const keyval = KEY_MAP[keyName];
|
|
123
|
+
const keyval = KEY_MAP[keyName] ?? characterKeyval(keyName);
|
|
94
124
|
|
|
95
125
|
if (keyval === undefined) {
|
|
96
|
-
throw new Error(`Unknown key: {${keyName}}`);
|
|
126
|
+
throw usageError(new Error(`Unknown key: {${keyName}}`));
|
|
97
127
|
}
|
|
98
128
|
|
|
99
129
|
return { keyval, isPress, isRelease };
|
|
@@ -154,6 +184,46 @@ const parseKeyboardInput = (input: string): KeyAction[] => {
|
|
|
154
184
|
return actions;
|
|
155
185
|
};
|
|
156
186
|
|
|
187
|
+
const characterActions = (text: string): KeyAction[] =>
|
|
188
|
+
Array.from(text, (character) => parseCharAt(character, 0).actions).flat();
|
|
189
|
+
|
|
190
|
+
const parseTypedCharAt = (input: string, i: number): TypedParseStep => {
|
|
191
|
+
const text = String.fromCodePoint(input.codePointAt(i) ?? 0);
|
|
192
|
+
|
|
193
|
+
return { step: { text }, next: i + text.length };
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const parseTypedStepAt = (input: string, i: number): TypedParseStep => {
|
|
197
|
+
if (input.startsWith(LITERAL_BRACE, i)) {
|
|
198
|
+
return { step: { text: "{" }, next: i + LITERAL_BRACE.length };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (input[i] !== "{") {
|
|
202
|
+
return parseTypedCharAt(input, i);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const brace = parseBraceAt(input, i);
|
|
206
|
+
|
|
207
|
+
if (brace === null) {
|
|
208
|
+
throw usageError(new Error(`Unclosed key descriptor at ${String(i)} in "${input}"; type a literal { as {{`));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return { step: { actions: brace.actions }, next: brace.next };
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const parseTypedInput = (input: string): TypedStep[] => {
|
|
215
|
+
const steps: TypedStep[] = [];
|
|
216
|
+
let i = 0;
|
|
217
|
+
|
|
218
|
+
while (i < input.length) {
|
|
219
|
+
const { step, next } = parseTypedStepAt(input, i);
|
|
220
|
+
steps.push(step);
|
|
221
|
+
i = next;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return steps;
|
|
225
|
+
};
|
|
226
|
+
|
|
157
227
|
const updateModifierState = (state: UserEventState, action: KeyAction): void => {
|
|
158
228
|
const mask = MODIFIER_KEYVAL_TO_MASK[action.keyval];
|
|
159
229
|
|
|
@@ -172,15 +242,22 @@ const isTriggerMatch = (
|
|
|
172
242
|
trigger: Gtk.ShortcutTrigger | null,
|
|
173
243
|
keyval: number,
|
|
174
244
|
modifiers: Gdk.ModifierType,
|
|
245
|
+
areMnemonicsEnabled: boolean,
|
|
175
246
|
): boolean => {
|
|
176
247
|
if (trigger instanceof Gtk.KeyvalTrigger) {
|
|
177
248
|
return trigger.getKeyval() === keyval && trigger.getModifiers() === modifiers;
|
|
178
249
|
}
|
|
179
250
|
|
|
251
|
+
if (trigger instanceof Gtk.MnemonicTrigger) {
|
|
252
|
+
const mnemonicKeyval = keyval === Gdk.KEY_ISO_Left_Tab ? Gdk.KEY_Tab : Gdk.keyvalToLower(keyval);
|
|
253
|
+
|
|
254
|
+
return areMnemonicsEnabled && trigger.getKeyval() === mnemonicKeyval;
|
|
255
|
+
}
|
|
256
|
+
|
|
180
257
|
if (trigger instanceof Gtk.AlternativeTrigger) {
|
|
181
258
|
return (
|
|
182
|
-
isTriggerMatch(trigger.getFirst(), keyval, modifiers) ||
|
|
183
|
-
isTriggerMatch(trigger.getSecond(), keyval, modifiers)
|
|
259
|
+
isTriggerMatch(trigger.getFirst(), keyval, modifiers, areMnemonicsEnabled) ||
|
|
260
|
+
isTriggerMatch(trigger.getSecond(), keyval, modifiers, areMnemonicsEnabled)
|
|
184
261
|
);
|
|
185
262
|
}
|
|
186
263
|
|
|
@@ -227,32 +304,62 @@ const managedShortcutHost = (manager: Gtk.Widget, shortcut: Gtk.Shortcut): Gtk.W
|
|
|
227
304
|
return null;
|
|
228
305
|
};
|
|
229
306
|
|
|
230
|
-
const isMovingFocus = (action: Gtk.ShortcutAction): boolean =>
|
|
231
|
-
action instanceof Gtk.SignalAction && action.getSignalName() === "move-focus";
|
|
232
|
-
|
|
233
307
|
const isShortcutLive = (host: Gtk.Widget): boolean => host.isSensitive() && host.getMapped();
|
|
234
308
|
|
|
235
|
-
const didRunShortcutAction = (shortcut: Gtk.Shortcut, host: Gtk.Widget): boolean => {
|
|
309
|
+
const didRunShortcutAction = (shortcut: Gtk.Shortcut, host: Gtk.Widget, flags: Gtk.ShortcutActionFlags): boolean => {
|
|
236
310
|
const action = shortcut.getAction();
|
|
237
311
|
|
|
238
|
-
if (action === null ||
|
|
312
|
+
if (action === null || !isShortcutLive(host)) {
|
|
239
313
|
return false;
|
|
240
314
|
}
|
|
241
315
|
|
|
242
|
-
return action.activate(
|
|
316
|
+
return action.activate(flags, host, shortcut.getArguments());
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const mnemonicModifiersFor = (widget: Gtk.Widget, keyval: number, modifiers: Gdk.ModifierType): Gdk.ModifierType => {
|
|
320
|
+
const display = widget.getDisplay();
|
|
321
|
+
const [, keys] = display.mapKeyval(keyval);
|
|
322
|
+
const key = keys[0];
|
|
323
|
+
const consumed = key === undefined ? 0 : display.translateKey(key.keycode, modifiers, key.group)[4];
|
|
324
|
+
|
|
325
|
+
return modifiers & ~consumed & Gtk.acceleratorGetDefaultModMask();
|
|
243
326
|
};
|
|
244
327
|
|
|
245
|
-
const
|
|
246
|
-
|
|
328
|
+
const matchingShortcuts = (
|
|
329
|
+
controller: Gtk.ShortcutController,
|
|
247
330
|
widget: Gtk.Widget,
|
|
248
331
|
keyval: number,
|
|
249
332
|
modifiers: Gdk.ModifierType,
|
|
250
|
-
):
|
|
251
|
-
|
|
252
|
-
|
|
333
|
+
): MatchingShortcut[] => {
|
|
334
|
+
const count = controller.getNItems();
|
|
335
|
+
|
|
336
|
+
if (count === 0) {
|
|
337
|
+
return [];
|
|
253
338
|
}
|
|
254
339
|
|
|
255
|
-
|
|
340
|
+
const areMnemonicsEnabled = mnemonicModifiersFor(widget, keyval, modifiers) === controller.getMnemonicsModifiers();
|
|
341
|
+
const offset = areMnemonicsEnabled ? (lastActivatedShortcuts.get(controller) ?? 0) + 1 : 0;
|
|
342
|
+
const matches: MatchingShortcut[] = [];
|
|
343
|
+
|
|
344
|
+
for (let j = 0; j < count; j++) {
|
|
345
|
+
const index = (offset + j) % count;
|
|
346
|
+
const shortcut = controller.getItem(index);
|
|
347
|
+
|
|
348
|
+
if (
|
|
349
|
+
!(shortcut instanceof Gtk.Shortcut) ||
|
|
350
|
+
!isTriggerMatch(shortcut.getTrigger(), keyval, modifiers, areMnemonicsEnabled)
|
|
351
|
+
) {
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const host = managedShortcutHost(widget, shortcut) ?? widget;
|
|
356
|
+
|
|
357
|
+
if (isShortcutLive(host)) {
|
|
358
|
+
matches.push({ shortcut, host, index });
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return matches;
|
|
256
363
|
};
|
|
257
364
|
|
|
258
365
|
const didActivateMatchingShortcut = (
|
|
@@ -261,16 +368,14 @@ const didActivateMatchingShortcut = (
|
|
|
261
368
|
keyval: number,
|
|
262
369
|
modifiers: number,
|
|
263
370
|
): boolean => {
|
|
264
|
-
const
|
|
371
|
+
const matches = matchingShortcuts(controller, widget, keyval, modifiers);
|
|
265
372
|
|
|
266
|
-
for (
|
|
267
|
-
const
|
|
373
|
+
for (const [index, match] of matches.entries()) {
|
|
374
|
+
const flags = (index === matches.length - 1 ? Gtk.ShortcutActionFlags.EXCLUSIVE : 0) as Gtk.ShortcutActionFlags;
|
|
268
375
|
|
|
269
|
-
if (
|
|
270
|
-
|
|
271
|
-
}
|
|
376
|
+
if (didRunShortcutAction(match.shortcut, match.host, flags)) {
|
|
377
|
+
lastActivatedShortcuts.set(controller, match.index);
|
|
272
378
|
|
|
273
|
-
if (didActivateShortcut(shortcut, widget, keyval, modifiers)) {
|
|
274
379
|
return true;
|
|
275
380
|
}
|
|
276
381
|
}
|
|
@@ -314,33 +419,169 @@ const didDispatchAccelsOnWindow = (window: Gtk.Window, keyval: number, modifiers
|
|
|
314
419
|
return false;
|
|
315
420
|
};
|
|
316
421
|
|
|
317
|
-
const didDispatchApplicationAccels = (
|
|
318
|
-
const root =
|
|
422
|
+
const didDispatchApplicationAccels = (target: Gtk.Widget, keyval: number, modifiers: number): boolean => {
|
|
423
|
+
const root = target.getRoot();
|
|
424
|
+
|
|
425
|
+
return (
|
|
426
|
+
root instanceof Gtk.Window &&
|
|
427
|
+
receivesEventsFor(root, Gtk.PropagationLimit.SAME_NATIVE, target) &&
|
|
428
|
+
didDispatchAccelsOnWindow(root, keyval, modifiers)
|
|
429
|
+
);
|
|
430
|
+
};
|
|
319
431
|
|
|
320
|
-
|
|
432
|
+
const SEARCH_BAR_CAPTURE_NAME = "gtk-search-bar-capture";
|
|
433
|
+
const ENTRY_COMPLETION_CLASS = "entry-completion";
|
|
434
|
+
const FILE_CHOOSER_ENTRY_TYPE_NAME = "GtkFileChooserEntry";
|
|
435
|
+
const CELL_EDITABLE_TYPE_NAME = "GtkCellEditableWidget";
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* GTK has no public getter for a text view's own key controller (`gtk_text_view_get_key_controller` is private) and
|
|
439
|
+
* lists controllers newest first, so the last key controller is the one the text view added when it was created.
|
|
440
|
+
* Controllers that subclasses such as GtkSourceView add read the current event, which emulated keys lack.
|
|
441
|
+
*/
|
|
442
|
+
const isTextViewKeyController = (controller: Gtk.EventController, widget: Gtk.Widget): boolean =>
|
|
443
|
+
controllersOn(widget)
|
|
444
|
+
.filter((current) => current instanceof Gtk.EventControllerKey)
|
|
445
|
+
.toArray()
|
|
446
|
+
.at(-1) === controller;
|
|
447
|
+
|
|
448
|
+
const isTextViewLibraryController = (controller: Gtk.EventController, widget: Gtk.Widget): boolean =>
|
|
449
|
+
widget instanceof Gtk.TextView && !isTextViewKeyController(controller, widget);
|
|
450
|
+
|
|
451
|
+
const capturesKeysOf = (candidate: Gtk.Widget, widget: Gtk.Widget): boolean =>
|
|
452
|
+
(candidate instanceof Gtk.SearchEntry || candidate instanceof Gtk.SearchBar) &&
|
|
453
|
+
candidate.getKeyCaptureWidget() === widget;
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* A search entry or search bar with a key capture widget adds a key controller to that widget, which forwards the
|
|
457
|
+
* current event to the entry. The search bar names its controller; the search entry leaves its own unnamed.
|
|
458
|
+
*/
|
|
459
|
+
const isSearchKeyCapture = (controller: Gtk.EventController, widget: Gtk.Widget): boolean => {
|
|
460
|
+
const name = controller.getName();
|
|
461
|
+
|
|
462
|
+
return (
|
|
463
|
+
name === SEARCH_BAR_CAPTURE_NAME ||
|
|
464
|
+
(name === null &&
|
|
465
|
+
(capturesKeysOf(widget, widget) ||
|
|
466
|
+
descendants(widget).some((candidate) => capturesKeysOf(candidate, widget))))
|
|
467
|
+
);
|
|
321
468
|
};
|
|
322
469
|
|
|
323
|
-
const
|
|
470
|
+
const isFileChooserForwarder = (_controller: Gtk.EventController, widget: Gtk.Widget): boolean =>
|
|
471
|
+
widget instanceof Gtk.FileChooserWidget || getWidgetTypeName(widget) === FILE_CHOOSER_ENTRY_TYPE_NAME;
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Widget types from other libraries whose key controllers read the current event: WebKit filters it through its input
|
|
475
|
+
* method and passes it to the web process.
|
|
476
|
+
*/
|
|
477
|
+
const EVENT_READING_LIBRARY_TYPE_NAMES = ["WebKitWebViewBase"];
|
|
478
|
+
|
|
479
|
+
const isLibraryEventReader = (_controller: Gtk.EventController, widget: Gtk.Widget): boolean =>
|
|
480
|
+
EVENT_READING_LIBRARY_TYPE_NAMES.some((name) => {
|
|
481
|
+
const type = typeFromName(name);
|
|
482
|
+
|
|
483
|
+
return type !== TYPE_INVALID && typeIsA(getInstanceType(widget), type);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
const isDeprecatedPopup = (widget: Gtk.Widget): boolean =>
|
|
487
|
+
widget instanceof Gtk.Popover &&
|
|
488
|
+
(widget.getParent() instanceof Gtk.ComboBox || widget.hasCssClass(ENTRY_COMPLETION_CLASS));
|
|
489
|
+
|
|
490
|
+
const isDeprecatedWidgetForwarder = (_controller: Gtk.EventController, widget: Gtk.Widget): boolean =>
|
|
491
|
+
widget instanceof Gtk.TreeView ||
|
|
492
|
+
getWidgetTypeName(widget) === CELL_EDITABLE_TYPE_NAME ||
|
|
493
|
+
isDeprecatedPopup(widget);
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Key controllers GTK and its libraries add without a JavaScript listener whose handlers need the real key event,
|
|
497
|
+
* which emulated keys lack: they filter it through an input method, forward it with
|
|
498
|
+
* `gtk_event_controller_key_forward()` or read it directly, and log a critical without one. Emulated keys skip them;
|
|
499
|
+
* every other key controller receives the keys.
|
|
500
|
+
*/
|
|
501
|
+
const REAL_EVENT_KEY_HANDLERS: ((controller: Gtk.EventController, widget: Gtk.Widget) => boolean)[] = [
|
|
502
|
+
isTextViewLibraryController,
|
|
503
|
+
isSearchKeyCapture,
|
|
504
|
+
isFileChooserForwarder,
|
|
505
|
+
isDeprecatedWidgetForwarder,
|
|
506
|
+
isLibraryEventReader,
|
|
507
|
+
];
|
|
508
|
+
|
|
509
|
+
const needsRealKeyEvent = (controller: Gtk.EventController, widget: Gtk.Widget): boolean =>
|
|
510
|
+
REAL_EVENT_KEY_HANDLERS.some((needsEvent) => needsEvent(controller, widget));
|
|
511
|
+
|
|
512
|
+
const SOURCE_COMPLETION_CONTROLLER_NAME = "gtk-source-completion";
|
|
513
|
+
const SOURCE_COMPLETION_LIST_TYPE_NAME = "GtkSourceCompletionList";
|
|
514
|
+
const SOURCE_COMPLETION_LIST_BOX_TYPE_NAME = "GtkSourceCompletionListBox";
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* GtkSourceView's completion adds a key controller to the view. While the completion list shows, the controller hides
|
|
518
|
+
* the list on {Escape} and forwards every other key to the list's box with `gtk_event_controller_key_forward()`, where
|
|
519
|
+
* the box's bindings move the selection and choose the selected proposal. Emulated keys have no event to forward, so
|
|
520
|
+
* they take the same path through the box's own controllers.
|
|
521
|
+
*/
|
|
522
|
+
const completionListFor = (controller: Gtk.EventController, widget: Gtk.Widget): Gtk.Widget | null =>
|
|
523
|
+
controller.getName() === SOURCE_COMPLETION_CONTROLLER_NAME
|
|
524
|
+
? (children(widget).find((child) => getWidgetTypeName(child) === SOURCE_COMPLETION_LIST_TYPE_NAME) ?? null)
|
|
525
|
+
: null;
|
|
526
|
+
|
|
527
|
+
const isKeyStopController = (controller: Gtk.EventController, widget: Gtk.Widget): controller is KeyStopController => {
|
|
324
528
|
if (controller instanceof Gtk.ShortcutController) {
|
|
325
529
|
return controller.getScope() === Gtk.ShortcutScope.LOCAL;
|
|
326
530
|
}
|
|
327
531
|
|
|
328
|
-
return
|
|
532
|
+
return (
|
|
533
|
+
controller instanceof Gtk.EventControllerKey &&
|
|
534
|
+
(hasSignalListener(controller, KEY_CONTROLLER_SIGNALS) || !needsRealKeyEvent(controller, widget))
|
|
535
|
+
);
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
const keyStopFor = (controller: Gtk.EventController, widget: Gtk.Widget): KeyStop | null => {
|
|
539
|
+
const completionList = completionListFor(controller, widget);
|
|
540
|
+
|
|
541
|
+
if (completionList !== null) {
|
|
542
|
+
return { widget, completionList };
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return isKeyStopController(controller, widget) ? { widget, controller } : null;
|
|
329
546
|
};
|
|
330
547
|
|
|
331
|
-
const keyStopsInPhase = (widget: Gtk.Widget, phase: Gtk.PropagationPhase): KeyStop[] => {
|
|
548
|
+
const keyStopsInPhase = (widget: Gtk.Widget, phase: Gtk.PropagationPhase, target: Gtk.Widget): KeyStop[] => {
|
|
332
549
|
const stops: KeyStop[] = [];
|
|
333
550
|
|
|
334
551
|
for (const controller of controllersOn(widget)) {
|
|
335
|
-
|
|
336
|
-
|
|
552
|
+
const stop =
|
|
553
|
+
controller.getPropagationPhase() === phase &&
|
|
554
|
+
receivesEventsFor(widget, controller.getPropagationLimit(), target)
|
|
555
|
+
? keyStopFor(controller, widget)
|
|
556
|
+
: null;
|
|
557
|
+
|
|
558
|
+
if (stop !== null) {
|
|
559
|
+
stops.push(stop);
|
|
337
560
|
}
|
|
338
561
|
}
|
|
339
562
|
|
|
340
563
|
return stops;
|
|
341
564
|
};
|
|
342
565
|
|
|
566
|
+
const forwardedKeyStops = (target: Gtk.Widget): KeyStop[] =>
|
|
567
|
+
[Gtk.PropagationPhase.CAPTURE, Gtk.PropagationPhase.TARGET, Gtk.PropagationPhase.BUBBLE].flatMap((phase) =>
|
|
568
|
+
keyStopsInPhase(target, phase, target),
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
const focusWithin = (widget: Gtk.Widget): Gtk.Widget | null => {
|
|
572
|
+
const root = widget.getRoot();
|
|
573
|
+
const focus = root instanceof Gtk.Window ? root.getFocus() : null;
|
|
574
|
+
|
|
575
|
+
return focus?.getMapped() === true && focus.isAncestor(widget) ? focus : null;
|
|
576
|
+
};
|
|
577
|
+
|
|
343
578
|
const propagationChain = (widget: Gtk.Widget): Gtk.Widget[] => {
|
|
579
|
+
const focus = focusWithin(widget);
|
|
580
|
+
|
|
581
|
+
if (focus !== null) {
|
|
582
|
+
return [focus, ...ancestors(focus)];
|
|
583
|
+
}
|
|
584
|
+
|
|
344
585
|
const delegate = getEditableDelegate(widget);
|
|
345
586
|
const below = delegate === null ? [] : [delegate];
|
|
346
587
|
|
|
@@ -352,13 +593,35 @@ const keyPropagationChain = (widget: Gtk.Widget): KeyStop[] => {
|
|
|
352
593
|
const [eventWidget = widget] = chain;
|
|
353
594
|
|
|
354
595
|
return [
|
|
355
|
-
...chain.toReversed().flatMap((current) => keyStopsInPhase(current, Gtk.PropagationPhase.CAPTURE)),
|
|
356
|
-
...keyStopsInPhase(eventWidget, Gtk.PropagationPhase.TARGET),
|
|
357
|
-
...chain.flatMap((current) => keyStopsInPhase(current, Gtk.PropagationPhase.BUBBLE)),
|
|
596
|
+
...chain.toReversed().flatMap((current) => keyStopsInPhase(current, Gtk.PropagationPhase.CAPTURE, eventWidget)),
|
|
597
|
+
...keyStopsInPhase(eventWidget, Gtk.PropagationPhase.TARGET, eventWidget),
|
|
598
|
+
...chain.flatMap((current) => keyStopsInPhase(current, Gtk.PropagationPhase.BUBBLE, eventWidget)),
|
|
358
599
|
];
|
|
359
600
|
};
|
|
360
601
|
|
|
361
|
-
const
|
|
602
|
+
const didCompletionHandlePress = (completionList: Gtk.Widget, keyval: number, modifiers: Gdk.ModifierType): boolean => {
|
|
603
|
+
if (!completionList.getVisible()) {
|
|
604
|
+
return false;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
if (keyval === Gdk.KEY_Escape) {
|
|
608
|
+
completionList.setVisible(false);
|
|
609
|
+
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
const box = descendants(completionList).find(
|
|
614
|
+
(descendant) => getWidgetTypeName(descendant) === SOURCE_COMPLETION_LIST_BOX_TYPE_NAME,
|
|
615
|
+
);
|
|
616
|
+
|
|
617
|
+
return box !== undefined && forwardedKeyStops(box).some((stop) => didStopHandlePress(stop, keyval, modifiers));
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
function didStopHandlePress(stop: KeyStop, keyval: number, modifiers: Gdk.ModifierType): boolean {
|
|
621
|
+
if ("completionList" in stop) {
|
|
622
|
+
return didCompletionHandlePress(stop.completionList, keyval, modifiers);
|
|
623
|
+
}
|
|
624
|
+
|
|
362
625
|
const { controller, widget } = stop;
|
|
363
626
|
|
|
364
627
|
if (controller instanceof Gtk.ShortcutController) {
|
|
@@ -366,7 +629,7 @@ const didStopHandlePress = (stop: KeyStop, keyval: number, modifiers: Gdk.Modifi
|
|
|
366
629
|
}
|
|
367
630
|
|
|
368
631
|
return controller.emit("key-pressed", keyval, 0, modifiers);
|
|
369
|
-
}
|
|
632
|
+
}
|
|
370
633
|
|
|
371
634
|
const keyTargetFor = (widget: Gtk.Widget): KeyTarget => {
|
|
372
635
|
const root = widget.getRoot();
|
|
@@ -382,8 +645,9 @@ const isKeyTargetInvalidated = (widget: Gtk.Widget, target: KeyTarget): boolean
|
|
|
382
645
|
|
|
383
646
|
const didHandlePress = (widget: Gtk.Widget, keyval: number, modifiers: Gdk.ModifierType): boolean => {
|
|
384
647
|
const target = keyTargetFor(widget);
|
|
648
|
+
const [eventWidget = widget] = propagationChain(widget);
|
|
385
649
|
|
|
386
|
-
if (didDispatchApplicationAccels(
|
|
650
|
+
if (didDispatchApplicationAccels(eventWidget, keyval, modifiers)) {
|
|
387
651
|
return true;
|
|
388
652
|
}
|
|
389
653
|
|
|
@@ -402,39 +666,139 @@ const didHandlePress = (widget: Gtk.Widget, keyval: number, modifiers: Gdk.Modif
|
|
|
402
666
|
|
|
403
667
|
const emitKeyReleased = (widget: Gtk.Widget, keyval: number, modifiers: Gdk.ModifierType): void => {
|
|
404
668
|
for (const stop of keyPropagationChain(widget)) {
|
|
405
|
-
if (stop.controller instanceof Gtk.EventControllerKey) {
|
|
669
|
+
if ("controller" in stop && stop.controller instanceof Gtk.EventControllerKey) {
|
|
406
670
|
stop.controller.emit("key-released", keyval, 0, modifiers);
|
|
407
671
|
}
|
|
408
672
|
}
|
|
409
673
|
};
|
|
410
674
|
|
|
411
|
-
const applyKeyPress = async (widget: Gtk.Widget, keyval: number, modifiers: Gdk.ModifierType): Promise<
|
|
675
|
+
const applyKeyPress = async (widget: Gtk.Widget, keyval: number, modifiers: Gdk.ModifierType): Promise<boolean> => {
|
|
412
676
|
if (didHandlePress(widget, keyval, modifiers)) {
|
|
413
|
-
return;
|
|
677
|
+
return true;
|
|
414
678
|
}
|
|
415
679
|
|
|
416
680
|
if (keyval === Gdk.KEY_Return && widget instanceof Gtk.Editable) {
|
|
417
681
|
await fireEvent(widget, "activate");
|
|
682
|
+
|
|
683
|
+
return true;
|
|
418
684
|
}
|
|
685
|
+
|
|
686
|
+
return false;
|
|
419
687
|
};
|
|
420
688
|
|
|
421
|
-
const
|
|
689
|
+
const isUnhandledPress = async (widget: Gtk.Widget, state: UserEventState, action: KeyAction): Promise<boolean> => {
|
|
422
690
|
updateModifierState(state, action);
|
|
423
691
|
|
|
424
|
-
if (action.isPress) {
|
|
425
|
-
|
|
692
|
+
if (!action.isPress) {
|
|
693
|
+
emitKeyReleased(widget, action.keyval, state.modifierState);
|
|
426
694
|
|
|
427
|
-
return;
|
|
695
|
+
return false;
|
|
428
696
|
}
|
|
429
697
|
|
|
430
|
-
|
|
698
|
+
const isHandled = await applyKeyPress(widget, action.keyval, state.modifierState);
|
|
699
|
+
|
|
700
|
+
return !isHandled && MODIFIER_KEYVAL_TO_MASK[action.keyval] === undefined;
|
|
431
701
|
};
|
|
432
702
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
703
|
+
/**
|
|
704
|
+
* Returns a function that resolves the widget keys meant for `widget` reach now: the widget, or the widget outside it
|
|
705
|
+
* that focus has moved to since, as after a {Tab}.
|
|
706
|
+
*/
|
|
707
|
+
const followKeyFocus = (widget: Gtk.Widget): (() => Gtk.Widget) => {
|
|
708
|
+
const start = keyTargetFor(widget);
|
|
709
|
+
|
|
710
|
+
return () => {
|
|
711
|
+
const { root, focus } = keyTargetFor(widget);
|
|
712
|
+
|
|
713
|
+
return root === start.root && focus !== null && focus !== start.focus && !focus.isAncestor(widget)
|
|
714
|
+
? focus
|
|
715
|
+
: widget;
|
|
716
|
+
};
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
/** Applies the key actions and returns the keyvals of the presses, other than modifiers, that nothing handled. */
|
|
720
|
+
const applyKeyActions = async (widget: Gtk.Widget, state: UserEventState, actions: KeyAction[]): Promise<number[]> => {
|
|
721
|
+
const keyWidget = followKeyFocus(widget);
|
|
722
|
+
const unhandled: number[] = [];
|
|
723
|
+
|
|
724
|
+
for (const action of actions) {
|
|
725
|
+
if (await isUnhandledPress(keyWidget(), state, action)) {
|
|
726
|
+
unhandled.push(action.keyval);
|
|
437
727
|
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
return unhandled;
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
const keyLabel = (keyval: number): string => {
|
|
734
|
+
const name = Object.keys(KEY_MAP).find((key) => KEY_MAP[key] === keyval);
|
|
735
|
+
const character = Gdk.keyvalToUnicode(keyval);
|
|
736
|
+
|
|
737
|
+
if (name !== undefined) {
|
|
738
|
+
return `{${name}}`;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
return character === 0 ? `{${Gdk.keyvalName(keyval) ?? String(keyval)}}` : String.fromCodePoint(character);
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
const canTakeFocus = (widget: Gtk.Widget): boolean => widget.getFocusable() && widget.getCanFocus();
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Focuses a target whose window has its focus elsewhere, as a user does before typing, so the window's own bindings
|
|
748
|
+
* such as {Space} and {Enter} activating the focus widget act on the target. An entry that delegates its focus to its
|
|
749
|
+
* text, such as a search entry, takes it there without selecting the text, as a click does. A widget that passes its
|
|
750
|
+
* focus to a child, such as a menu button to its button, focuses that child.
|
|
751
|
+
*/
|
|
752
|
+
const focusKeyTarget = (widget: Gtk.Widget): void => {
|
|
753
|
+
if (focusWithin(widget) !== null) {
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
const delegate = getEditableDelegate(widget);
|
|
758
|
+
|
|
759
|
+
if (delegate instanceof Gtk.Text && canTakeFocus(delegate)) {
|
|
760
|
+
delegate.grabFocusWithoutSelecting();
|
|
761
|
+
} else {
|
|
762
|
+
widget.grabFocus();
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Sends the key sequence and returns the keys, as `keyboard` input would name them, whose presses nothing on the
|
|
768
|
+
* widget, its focused descendant or their ancestors handled.
|
|
769
|
+
*/
|
|
770
|
+
const keyboard = async (state: UserEventState, widget: Gtk.Widget, input: string): Promise<string[]> => {
|
|
771
|
+
let unhandled: number[] = [];
|
|
772
|
+
|
|
773
|
+
await wrapEvent(widget, async () => {
|
|
774
|
+
focusKeyTarget(widget);
|
|
775
|
+
unhandled = await applyKeyActions(widget, state, parseKeyboardInput(input));
|
|
438
776
|
});
|
|
439
777
|
|
|
440
|
-
|
|
778
|
+
return [...new Set(unhandled.map((keyval) => keyLabel(keyval)))];
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
const focusedKeyWidget = (): Gtk.Widget => {
|
|
782
|
+
const window = activeToplevel() ?? mappedToplevels()[0];
|
|
783
|
+
|
|
784
|
+
if (window === undefined) {
|
|
785
|
+
throw usageError(new Error("No window is open to receive the keys"));
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
const focus = window.getFocus();
|
|
789
|
+
|
|
790
|
+
return focus?.getMapped() ? focus : window;
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
export {
|
|
794
|
+
applyKeyActions,
|
|
795
|
+
characterActions,
|
|
796
|
+
focusedKeyWidget,
|
|
797
|
+
followKeyFocus,
|
|
798
|
+
heldModifiers,
|
|
799
|
+
keyboard,
|
|
800
|
+
parseTypedInput,
|
|
801
|
+
tab,
|
|
802
|
+
type TabOptions,
|
|
803
|
+
type TypedStep,
|
|
804
|
+
};
|