Skip to content

Commit 16eaeb5

Browse files
authored
fix: allow search/launcher hotkeys to work while capslock is on (#1567)
1 parent d54b54e commit 16eaeb5

File tree

1 file changed

+53
-51
lines changed

1 file changed

+53
-51
lines changed

src/search.ts

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { JsonIPC } from 'launcher_service'
88

99
const GLib: GLib = imports.gi.GLib;
1010

11-
const { Clutter, Gio, Pango, Shell, St } = imports.gi;
11+
const { Clutter, Gio, Pango, Shell, St, Gdk } = imports.gi;
1212
const { ModalDialog } = imports.ui.modalDialog;
1313

1414
const { overview, wm } = imports.ui.main;
@@ -87,107 +87,109 @@ export class Search {
8787
});
8888

8989
this.text.connect("key-press-event", (_: any, event: any) => {
90-
const c = event.get_key_symbol();
91-
const s = event.get_state();
90+
const key = Gdk.keyval_name(Gdk.keyval_to_upper(event.get_key_symbol()));
91+
const ctrlKey = Boolean(event.get_state() & Clutter.ModifierType.CONTROL_MASK);
9292

9393
const is_down = (): boolean => {
94-
return c == 65364 || (s == Clutter.ModifierType.CONTROL_MASK && c == 106)
95-
|| (s == Clutter.ModifierType.CONTROL_MASK && c == 110)
94+
return key === "Down" ||
95+
(ctrlKey && key === "J") ||
96+
(ctrlKey && key === "N");
9697
}
9798

9899
const is_up = (): boolean => {
99-
return c == 65362 || c == 65056 || (s == Clutter.ModifierType.CONTROL_MASK && c == 107)
100-
|| (s == Clutter.ModifierType.CONTROL_MASK && c == 112)
100+
return key === "Up" || key === "ISO_Left_Tab" ||
101+
(ctrlKey && key === "K") ||
102+
(ctrlKey && key === "P");
101103
}
102104

103105
// Up arrow or left tab was pressed
104106
const up_arrow = () => {
105107
if (0 < this.active_id) {
106-
this.select_id(this.active_id - 1)
108+
this.select_id(this.active_id - 1);
107109
} else if (this.active_id == 0) {
108-
this.select_id(this.widgets.length - 1)
110+
this.select_id(this.widgets.length - 1);
109111
}
110112
}
111113

112114
// Down arrow or tab was pressed
113115
const down_arrow = () => {
114116
if (this.active_id + 1 < this.widgets.length) {
115-
this.select_id(this.active_id + 1)
117+
this.select_id(this.active_id + 1);
116118
} else if (this.active_id + 1 == this.widgets.length) {
117-
this.select_id(0)
119+
this.select_id(0);
118120
}
119121
}
120122

121123
// Delay key repeat events, and handle up/down arrow movements if on repeat.
122124
if (event.get_flags() != Clutter.EventFlags.NONE) {
123-
const now = global.get_current_time()
125+
const now = global.get_current_time();
124126

125127
if (now - this.last_trigger < 100) {
126-
return
128+
return;
127129
}
128130

129131
this.last_trigger = now;
130132

131133
if (is_up()) {
132-
up_arrow()
134+
up_arrow();
133135
this.select(this.active_id);
134136
} else if (is_down()) {
135-
down_arrow()
137+
down_arrow();
136138
this.select(this.active_id);
137139
}
138140

139141
return;
140142
}
141143

142-
this.last_trigger = global.get_current_time()
144+
this.last_trigger = global.get_current_time();
143145

144-
if (c === 65307) {
146+
if (key === "Escape") {
145147
// Escape key was pressed
146148
this.reset();
147149
this.close();
148150
this.cancel();
149151
return;
150-
} else if (c === 65289) {
152+
} else if (key === "Tab") {
151153
// Tab was pressed, check for tab completion
152-
this.complete()
154+
this.complete();
153155
return;
154156
}
155157

156158
if (is_up()) {
157-
up_arrow()
159+
up_arrow();
158160
} else if (is_down()) {
159-
down_arrow()
160-
} else if (s == Clutter.ModifierType.CONTROL_MASK && c == 49) {
161-
this.activate_id(0)
162-
return
163-
} else if (s == Clutter.ModifierType.CONTROL_MASK && c == 50) {
164-
this.activate_id(1)
165-
return
166-
} else if (s == Clutter.ModifierType.CONTROL_MASK && c == 51) {
167-
this.activate_id(2)
168-
return
169-
} else if (s == Clutter.ModifierType.CONTROL_MASK && c == 52) {
170-
this.activate_id(3)
171-
return
172-
} else if (s == Clutter.ModifierType.CONTROL_MASK && c == 53) {
173-
this.activate_id(4)
174-
return
175-
} else if (s == Clutter.ModifierType.CONTROL_MASK && c == 54) {
176-
this.activate_id(5)
177-
return
178-
} else if (s == Clutter.ModifierType.CONTROL_MASK && c == 55) {
179-
this.activate_id(6)
180-
return
181-
} else if (s == Clutter.ModifierType.CONTROL_MASK && c == 56) {
182-
this.activate_id(7)
183-
return
184-
} else if (s == Clutter.ModifierType.CONTROL_MASK && c == 57) {
185-
this.activate_id(8)
186-
return
187-
} else if (s == Clutter.ModifierType.CONTROL_MASK && c == 113) {
161+
down_arrow();
162+
} else if (ctrlKey && key === "1") {
163+
this.activate_id(0);
164+
return;
165+
} else if (ctrlKey && key === "2") {
166+
this.activate_id(1);
167+
return;
168+
} else if (ctrlKey && key === "3") {
169+
this.activate_id(2);
170+
return;
171+
} else if (ctrlKey && key === "4") {
172+
this.activate_id(3);
173+
return;
174+
} else if (ctrlKey && key === "5") {
175+
this.activate_id(4);
176+
return;
177+
} else if (ctrlKey && key === "6") {
178+
this.activate_id(5);
179+
return;
180+
} else if (ctrlKey && key === "7") {
181+
this.activate_id(6);
182+
return;
183+
} else if (ctrlKey && key === "8") {
184+
this.activate_id(7);
185+
return;
186+
} else if (ctrlKey && key === "9") {
187+
this.activate_id(8);
188+
return;
189+
} else if (ctrlKey && key === "Q") {
188190
// Ctrl + Q shall quit the selected application
189-
this.quit(this.active_id)
190-
return
191+
this.quit(this.active_id);
192+
return;
191193
}
192194

193195
this.select(this.active_id);

0 commit comments

Comments
 (0)