aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-19 20:12:05 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-19 20:12:05 -0400
commit84a778b688320ca535cee29f1b6c580ed7f36715 (patch)
tree85612a447f1a2ef710e9df1377ae01d1dfb14b41
parentRemove logging of all key presess (diff)
downloadsway-84a778b688320ca535cee29f1b6c580ed7f36715.tar.gz
sway-84a778b688320ca535cee29f1b6c580ed7f36715.tar.zst
sway-84a778b688320ca535cee29f1b6c580ed7f36715.zip
Improve key buffer handling
-rw-r--r--sway/handlers.c55
1 files changed, 26 insertions, 29 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index 6889fb22..c789662e 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -14,9 +14,8 @@
14#include "container.h" 14#include "container.h"
15#include "focus.h" 15#include "focus.h"
16 16
17uint32_t keys_pressed[32]; 17#define KEY_CACHE_SIZE 32
18int keys_pressed_length = 0; 18uint32_t keys_pressed[KEY_CACHE_SIZE];
19
20 19
21static struct wlc_origin mouse_origin; 20static struct wlc_origin mouse_origin;
22 21
@@ -284,12 +283,11 @@ static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geo
284} 283}
285 284
286static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) { 285static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) {
287 swayc_t *c = NULL; 286 swayc_t *c = get_swayc_for_handle(view, &root_container);
288 switch (state) { 287 switch (state) {
289 case WLC_BIT_FULLSCREEN: 288 case WLC_BIT_FULLSCREEN:
290 // i3 just lets it become fullscreen 289 // i3 just lets it become fullscreen
291 wlc_view_set_state(view, state, toggle); 290 wlc_view_set_state(view, state, toggle);
292 c = get_swayc_for_handle(view, &root_container);
293 if (c) { 291 if (c) {
294 sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d", view, c->name, toggle); 292 sway_log(L_DEBUG, "setting view %ld %s, fullscreen %d", view, c->name, toggle);
295 arrange_windows(c->parent, -1, -1); 293 arrange_windows(c->parent, -1, -1);
@@ -307,7 +305,9 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s
307 case WLC_BIT_MAXIMIZED: 305 case WLC_BIT_MAXIMIZED:
308 case WLC_BIT_RESIZING: 306 case WLC_BIT_RESIZING:
309 case WLC_BIT_MOVING: 307 case WLC_BIT_MOVING:
308 break;
310 case WLC_BIT_ACTIVATED: 309 case WLC_BIT_ACTIVATED:
310 sway_log(L_DEBUG, "View %p requested to be activated", c);
311 break; 311 break;
312 } 312 }
313 return; 313 return;
@@ -316,13 +316,12 @@ 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 enum { QSIZE = 32 };
320 if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) { 319 if (locked_view_focus && state == WLC_KEY_STATE_PRESSED) {
321 return false; 320 return false;
322 } 321 }
323 bool cmd_success = false; 322 bool cmd_success = false;
324 323
325 //Revert floating container back to original position on keypress 324 // Revert floating container back to original position on keypress
326 if (state == WLC_KEY_STATE_PRESSED && (dragging || resizing)) { 325 if (state == WLC_KEY_STATE_PRESSED && (dragging || resizing)) {
327 reset_floating(get_focused_view(&root_container)); 326 reset_floating(get_focused_view(&root_container));
328 } 327 }
@@ -331,20 +330,23 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
331 // Lowercase if necessary 330 // Lowercase if necessary
332 sym = tolower(sym); 331 sym = tolower(sym);
333 332
334 // Find key, if it has been pressed 333 int i;
335 int mid = 0; 334
336 while (mid < keys_pressed_length && keys_pressed[mid] != sym) { 335 for (i = 0; i < KEY_CACHE_SIZE; ++i) {
337 ++mid; 336 if (state == WLC_KEY_STATE_PRESSED && keys_pressed[i] == 0) {
337 keys_pressed[i] = sym;
338 break;
339 } else if (state == WLC_KEY_STATE_RELEASED && keys_pressed[i] == sym) {
340 keys_pressed[i] = 0;
341 break;
342 }
338 } 343 }
339 //Add or remove key depending on state 344 if (i == KEY_CACHE_SIZE) {
340 if (state == WLC_KEY_STATE_PRESSED && mid == keys_pressed_length && keys_pressed_length + 1 < QSIZE) { 345 sway_log(L_DEBUG, "Key buffer full!");
341 keys_pressed[keys_pressed_length++] = sym; 346 return false;
342 } else if (state == WLC_KEY_STATE_RELEASED && mid < keys_pressed_length) {
343 memmove(keys_pressed + mid, keys_pressed + mid + 1, sizeof*keys_pressed * (--keys_pressed_length - mid));
344 keys_pressed[keys_pressed_length] = 0;
345 } 347 }
348
346 // TODO: reminder to check conflicts with mod+q+a versus mod+q 349 // TODO: reminder to check conflicts with mod+q+a versus mod+q
347 int i;
348 for (i = 0; i < mode->bindings->length; ++i) { 350 for (i = 0; i < mode->bindings->length; ++i) {
349 struct sway_binding *binding = mode->bindings->items[i]; 351 struct sway_binding *binding = mode->bindings->items[i];
350 352
@@ -354,8 +356,8 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
354 for (j = 0; j < binding->keys->length; ++j) { 356 for (j = 0; j < binding->keys->length; ++j) {
355 match = false; 357 match = false;
356 xkb_keysym_t *key = binding->keys->items[j]; 358 xkb_keysym_t *key = binding->keys->items[j];
357 uint8_t k; 359 int k;
358 for (k = 0; k < keys_pressed_length; ++k) { 360 for (k = 0; k < KEY_CACHE_SIZE; ++k) {
359 if (keys_pressed[k] == *key) { 361 if (keys_pressed[k] == *key) {
360 match = true; 362 match = true;
361 break; 363 break;
@@ -368,15 +370,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
368 370
369 if (match) { 371 if (match) {
370 // Remove matched keys from keys_pressed 372 // Remove matched keys from keys_pressed
371 int j;
372 for (j = 0; j < binding->keys->length; ++j) {
373 uint8_t k;
374 for (k = 0; k < keys_pressed_length; ++k) {
375 memmove(keys_pressed + k, keys_pressed + k + 1, sizeof*keys_pressed * (--keys_pressed_length - k));
376 keys_pressed[keys_pressed_length] = 0;
377 break;
378 }
379 }
380 if (state == WLC_KEY_STATE_PRESSED) { 373 if (state == WLC_KEY_STATE_PRESSED) {
381 cmd_success = handle_command(config, binding->command); 374 cmd_success = handle_command(config, binding->command);
382 } else if (state == WLC_KEY_STATE_RELEASED) { 375 } else if (state == WLC_KEY_STATE_RELEASED) {
@@ -574,6 +567,10 @@ static void handle_wlc_ready(void) {
574 } 567 }
575 free_flat_list(config->cmd_queue); 568 free_flat_list(config->cmd_queue);
576 config->active = true; 569 config->active = true;
570
571 for (i = 0; i < KEY_CACHE_SIZE; ++i) {
572 keys_pressed[i] = 0;
573 }
577} 574}
578 575
579 576