summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-01-08 14:41:09 +0100
committerLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-01-08 15:03:25 +0100
commit15cbc53a771f35e5510b643193c4ba99e9f820a2 (patch)
tree37391772505203dd0ac0b533e89359b0d5d6e040 /sway
parentReduce duplicate code (diff)
downloadsway-15cbc53a771f35e5510b643193c4ba99e9f820a2.tar.gz
sway-15cbc53a771f35e5510b643193c4ba99e9f820a2.tar.zst
sway-15cbc53a771f35e5510b643193c4ba99e9f820a2.zip
Make IPC binding event support a compile time opt.
Diffstat (limited to 'sway')
-rw-r--r--sway/handlers.c26
-rw-r--r--sway/ipc-server.c6
2 files changed, 25 insertions, 7 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index a298ff3e..76778450 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -337,14 +337,26 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s
337} 337}
338 338
339static void handle_binding_command(struct sway_binding *binding) { 339static void handle_binding_command(struct sway_binding *binding) {
340 struct sway_binding *binding_copy = sway_binding_dup(binding); 340 struct sway_binding *binding_copy = binding;
341 struct cmd_results *res = handle_command(binding->command); 341 bool reload = false;
342 if (res->status != CMD_SUCCESS) { 342 // if this is a reload command we need to make a duplicate of the
343 sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); 343 // binding since it will be gone after the reload has completed.
344 } 344 if (strcasecmp(binding->command, "reload") == 0) {
345 ipc_event_binding_keyboard(binding_copy); 345 binding_copy = sway_binding_dup(binding);
346 free_cmd_results(res); 346 reload = true;
347 }
348
349 struct cmd_results *res = handle_command(binding->command);
350 if (res->status != CMD_SUCCESS) {
351 sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error);
352 }
353 ipc_event_binding_keyboard(binding_copy);
354
355 if (reload) { // free the binding if we made a copy
347 free_sway_binding(binding_copy); 356 free_sway_binding(binding_copy);
357 }
358
359 free_cmd_results(res);
348} 360}
349 361
350static bool handle_bindsym(struct sway_binding *binding) { 362static bool handle_bindsym(struct sway_binding *binding) {
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index d8d8434c..bde20931 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -298,8 +298,10 @@ void ipc_client_handle_command(struct ipc_client *client) {
298 client->subscribed_events |= IPC_EVENT_MODE; 298 client->subscribed_events |= IPC_EVENT_MODE;
299 } else if (strcmp(event_type, "modifier") == 0) { 299 } else if (strcmp(event_type, "modifier") == 0) {
300 client->subscribed_events |= IPC_EVENT_MODIFIER; 300 client->subscribed_events |= IPC_EVENT_MODIFIER;
301#if SWAY_BINDING_EVENT
301 } else if (strcmp(event_type, "binding") == 0) { 302 } else if (strcmp(event_type, "binding") == 0) {
302 client->subscribed_events |= IPC_EVENT_BINDING; 303 client->subscribed_events |= IPC_EVENT_BINDING;
304#endif
303 } else { 305 } else {
304 ipc_send_reply(client, "{\"success\": false}", 18); 306 ipc_send_reply(client, "{\"success\": false}", 18);
305 ipc_client_disconnect(client); 307 ipc_client_disconnect(client);
@@ -636,6 +638,7 @@ void ipc_event_modifier(uint32_t modifier, const char *state) {
636 json_object_put(obj); // free 638 json_object_put(obj); // free
637} 639}
638 640
641#if SWAY_BINDING_EVENT
639static void ipc_event_binding(json_object *sb_obj) { 642static void ipc_event_binding(json_object *sb_obj) {
640 json_object *obj = json_object_new_object(); 643 json_object *obj = json_object_new_object();
641 json_object_object_add(obj, "change", json_object_new_string("run")); 644 json_object_object_add(obj, "change", json_object_new_string("run"));
@@ -646,8 +649,10 @@ static void ipc_event_binding(json_object *sb_obj) {
646 649
647 json_object_put(obj); // free 650 json_object_put(obj); // free
648} 651}
652#endif
649 653
650void ipc_event_binding_keyboard(struct sway_binding *sb) { 654void ipc_event_binding_keyboard(struct sway_binding *sb) {
655#if SWAY_BINDING_EVENT
651 json_object *sb_obj = json_object_new_object(); 656 json_object *sb_obj = json_object_new_object();
652 json_object_object_add(sb_obj, "command", json_object_new_string(sb->command)); 657 json_object_object_add(sb_obj, "command", json_object_new_string(sb->command));
653 658
@@ -679,4 +684,5 @@ void ipc_event_binding_keyboard(struct sway_binding *sb) {
679 json_object_object_add(sb_obj, "input_type", json_object_new_string("keyboard")); 684 json_object_object_add(sb_obj, "input_type", json_object_new_string("keyboard"));
680 685
681 ipc_event_binding(sb_obj); 686 ipc_event_binding(sb_obj);
687#endif
682} 688}