summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--sway/handlers.c26
-rw-r--r--sway/ipc-server.c6
3 files changed, 29 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9c556b0e..447fd584 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -44,6 +44,7 @@ option(enable-swaybar "Enables the swaybar utility" YES)
44option(enable-swaygrab "Enables the swaygrab utility" YES) 44option(enable-swaygrab "Enables the swaygrab utility" YES)
45option(enable-swaymsg "Enables the swaymsg utility" YES) 45option(enable-swaymsg "Enables the swaymsg utility" YES)
46option(enable-gdk-pixbuf "Use Pixbuf to support more image formats" YES) 46option(enable-gdk-pixbuf "Use Pixbuf to support more image formats" YES)
47option(enable-binding-event "Enables binding event subscription" YES)
47 48
48find_package(JsonC REQUIRED) 49find_package(JsonC REQUIRED)
49find_package(PCRE REQUIRED) 50find_package(PCRE REQUIRED)
@@ -112,6 +113,9 @@ if(enable-swaylock)
112 message(WARNING "Not building swaylock - cairo, pango, and PAM are required.") 113 message(WARNING "Not building swaylock - cairo, pango, and PAM are required.")
113 endif() 114 endif()
114endif() 115endif()
116if(enable-binding-event)
117 add_definitions(-DSWAY_BINDING_EVENT=1)
118endif()
115 119
116install( 120install(
117 FILES ${CMAKE_CURRENT_SOURCE_DIR}/sway.desktop 121 FILES ${CMAKE_CURRENT_SOURCE_DIR}/sway.desktop
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}