summaryrefslogtreecommitdiffstats
path: root/sway/handlers.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/handlers.c')
-rw-r--r--sway/handlers.c85
1 files changed, 58 insertions, 27 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index 470f3c95..e0acebea 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -336,6 +336,43 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s
336 return; 336 return;
337} 337}
338 338
339static bool handle_bindsym(struct sway_binding *binding) {
340 bool match = false;
341 int i;
342 for (i = 0; i < binding->keys->length; ++i) {
343 xkb_keysym_t *key = binding->keys->items[i];
344 if ((match = check_key(*key, 0)) == false) {
345 break;
346 }
347 }
348
349 if (match) {
350 struct cmd_results *res = handle_command(binding->command);
351 if (res->status != CMD_SUCCESS) {
352 sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error);
353 }
354 free_cmd_results(res);
355 return true;
356 }
357
358 return false;
359}
360
361static bool handle_bindsym_release(struct sway_binding *binding) {
362 if (binding->keys->length == 1) {
363 xkb_keysym_t *key = binding->keys->items[0];
364 if (check_released_key(*key)) {
365 struct cmd_results *res = handle_command(binding->command);
366 if (res->status != CMD_SUCCESS) {
367 sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error);
368 }
369 free_cmd_results(res);
370 return true;
371 }
372 }
373
374 return false;
375}
339 376
340static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, 377static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers,
341 uint32_t key, enum wlc_key_state state) { 378 uint32_t key, enum wlc_key_state state) {
@@ -366,33 +403,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
366 release_key(sym, key); 403 release_key(sym, key);
367 } 404 }
368 405
369 for (i = 0; i < mode->bindings->length; ++i) {
370 struct sway_binding *binding = mode->bindings->items[i];
371
372 if ((modifiers->mods ^ binding->modifiers) == 0) {
373 bool match = false;
374 int j;
375 for (j = 0; j < binding->keys->length; ++j) {
376 xkb_keysym_t *key = binding->keys->items[j];
377 if ((match = check_key(*key, 0)) == false) {
378 break;
379 }
380 }
381 if (match) {
382 if (state == WLC_KEY_STATE_PRESSED) {
383 struct cmd_results *res = handle_command(binding->command);
384 if (res->status != CMD_SUCCESS) {
385 sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error);
386 }
387 free_cmd_results(res);
388 return EVENT_HANDLED;
389 } else if (state == WLC_KEY_STATE_RELEASED) {
390 // TODO: --released
391 }
392 }
393 }
394 }
395
396 // handle bar modifiers pressed/released 406 // handle bar modifiers pressed/released
397 uint32_t modifier; 407 uint32_t modifier;
398 for (i = 0; i < config->active_bar_modifiers->length; ++i) { 408 for (i = 0; i < config->active_bar_modifiers->length; ++i) {
@@ -409,6 +419,27 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
409 } 419 }
410 // update modifiers state 420 // update modifiers state
411 modifiers_state_update(modifiers->mods); 421 modifiers_state_update(modifiers->mods);
422
423 // handle bindings
424 for (i = 0; i < mode->bindings->length; ++i) {
425 struct sway_binding *binding = mode->bindings->items[i];
426 if ((modifiers->mods ^ binding->modifiers) == 0) {
427 switch (state) {
428 case WLC_KEY_STATE_PRESSED: {
429 if (!binding->release && handle_bindsym(binding)) {
430 return EVENT_HANDLED;
431 }
432 break;
433 }
434 case WLC_KEY_STATE_RELEASED:
435 if (binding->release && handle_bindsym_release(binding)) {
436 return EVENT_HANDLED;
437 }
438 break;
439 }
440 }
441 }
442
412 return EVENT_PASSTHROUGH; 443 return EVENT_PASSTHROUGH;
413} 444}
414 445