aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-19 20:52:52 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-19 20:52:52 -0400
commit1d8591d9026c19f5c308bed5961341b00aef69ca (patch)
tree1bdb05a71b0128b014901af8d60608869ec58000
parentImprove key buffer handling (diff)
downloadsway-1d8591d9026c19f5c308bed5961341b00aef69ca.tar.gz
sway-1d8591d9026c19f5c308bed5961341b00aef69ca.tar.zst
sway-1d8591d9026c19f5c308bed5961341b00aef69ca.zip
Improve key handling somewhat
XKB is fucking bullshit
-rw-r--r--sway/handlers.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index c789662e..18f1d13c 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -316,6 +316,14 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s
316 316
317static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, 317static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers,
318 uint32_t key, uint32_t sym, enum wlc_key_state state) { 318 uint32_t key, uint32_t sym, enum wlc_key_state state) {
319
320 static const uint32_t modifier_syms[] = {
321 XKB_KEY_Shift_L, XKB_KEY_Shift_R, XKB_KEY_Control_L, XKB_KEY_Control_R,
322 XKB_KEY_Caps_Lock, XKB_KEY_Shift_Lock, XKB_KEY_Meta_L, XKB_KEY_Meta_R,
323 XKB_KEY_Alt_L, XKB_KEY_Alt_R, XKB_KEY_Super_L, XKB_KEY_Super_R,
324 XKB_KEY_Hyper_L, XKB_KEY_Hyper_R
325 };
326
319 if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { 327 if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) {
320 return false; 328 return false;
321 } 329 }
@@ -327,12 +335,28 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
327 } 335 }
328 336
329 struct sway_mode *mode = config->current_mode; 337 struct sway_mode *mode = config->current_mode;
338
339 if (!isalnum(sym)) {
340 // God fucking dammit
341 return false;
342 }
343
330 // Lowercase if necessary 344 // Lowercase if necessary
331 sym = tolower(sym); 345 sym = tolower(sym);
332 346
333 int i; 347 int i;
348 bool mod = false;
334 349
335 for (i = 0; i < KEY_CACHE_SIZE; ++i) { 350 for (i = 0; i < sizeof(modifier_syms) / sizeof(uint32_t); ++i) {
351 if (modifier_syms[i] == sym) {
352 mod = true;
353 break;
354 }
355 }
356
357 int total = 0;
358 for (i = 0; i < KEY_CACHE_SIZE && !mod; ++i) {
359 total += keys_pressed[i] != 0;
336 if (state == WLC_KEY_STATE_PRESSED && keys_pressed[i] == 0) { 360 if (state == WLC_KEY_STATE_PRESSED && keys_pressed[i] == 0) {
337 keys_pressed[i] = sym; 361 keys_pressed[i] = sym;
338 break; 362 break;
@@ -341,10 +365,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
341 break; 365 break;
342 } 366 }
343 } 367 }
344 if (i == KEY_CACHE_SIZE) {
345 sway_log(L_DEBUG, "Key buffer full!");
346 return false;
347 }
348 368
349 // TODO: reminder to check conflicts with mod+q+a versus mod+q 369 // TODO: reminder to check conflicts with mod+q+a versus mod+q
350 for (i = 0; i < mode->bindings->length; ++i) { 370 for (i = 0; i < mode->bindings->length; ++i) {