summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-01-08 14:27:41 +0100
committerLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-01-08 14:27:41 +0100
commit14147ac05676a4f914960311e3b49e4451c0576a (patch)
tree8147e214fe6e38584f3e4142d113bd5c2d770fb5 /sway
parentImplement IPC binding event (keyboard) (diff)
downloadsway-14147ac05676a4f914960311e3b49e4451c0576a.tar.gz
sway-14147ac05676a4f914960311e3b49e4451c0576a.tar.zst
sway-14147ac05676a4f914960311e3b49e4451c0576a.zip
Reduce duplicate code
Diffstat (limited to 'sway')
-rw-r--r--sway/handlers.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index 693e11eb..a298ff3e 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -336,6 +336,17 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s
336 return; 336 return;
337} 337}
338 338
339static void handle_binding_command(struct sway_binding *binding) {
340 struct sway_binding *binding_copy = sway_binding_dup(binding);
341 struct cmd_results *res = handle_command(binding->command);
342 if (res->status != CMD_SUCCESS) {
343 sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error);
344 }
345 ipc_event_binding_keyboard(binding_copy);
346 free_cmd_results(res);
347 free_sway_binding(binding_copy);
348}
349
339static bool handle_bindsym(struct sway_binding *binding) { 350static bool handle_bindsym(struct sway_binding *binding) {
340 bool match = false; 351 bool match = false;
341 int i; 352 int i;
@@ -347,14 +358,7 @@ static bool handle_bindsym(struct sway_binding *binding) {
347 } 358 }
348 359
349 if (match) { 360 if (match) {
350 struct sway_binding *binding_copy = sway_binding_dup(binding); 361 handle_binding_command(binding);
351 struct cmd_results *res = handle_command(binding->command);
352 if (res->status != CMD_SUCCESS) {
353 sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error);
354 }
355 ipc_event_binding_keyboard(binding_copy);
356 free_cmd_results(res);
357 free_sway_binding(binding_copy);
358 return true; 362 return true;
359 } 363 }
360 364
@@ -365,14 +369,7 @@ static bool handle_bindsym_release(struct sway_binding *binding) {
365 if (binding->keys->length == 1) { 369 if (binding->keys->length == 1) {
366 xkb_keysym_t *key = binding->keys->items[0]; 370 xkb_keysym_t *key = binding->keys->items[0];
367 if (check_released_key(*key)) { 371 if (check_released_key(*key)) {
368 struct sway_binding *binding_copy = sway_binding_dup(binding); 372 handle_binding_command(binding);
369 struct cmd_results *res = handle_command(binding->command);
370 if (res->status != CMD_SUCCESS) {
371 sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error);
372 }
373 ipc_event_binding_keyboard(binding_copy);
374 free_cmd_results(res);
375 free_sway_binding(binding_copy);
376 return true; 373 return true;
377 } 374 }
378 } 375 }