diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c556b0e0..447fd5846 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ option(enable-swaybar "Enables the swaybar utility" YES) option(enable-swaygrab "Enables the swaygrab utility" YES) option(enable-swaymsg "Enables the swaymsg utility" YES) option(enable-gdk-pixbuf "Use Pixbuf to support more image formats" YES) +option(enable-binding-event "Enables binding event subscription" YES) find_package(JsonC REQUIRED) find_package(PCRE REQUIRED) @@ -112,6 +113,9 @@ if(enable-swaylock) message(WARNING "Not building swaylock - cairo, pango, and PAM are required.") endif() endif() +if(enable-binding-event) + add_definitions(-DSWAY_BINDING_EVENT=1) +endif() install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/sway.desktop diff --git a/sway/handlers.c b/sway/handlers.c index a298ff3e2..76778450f 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 } static void handle_binding_command(struct sway_binding *binding) { - struct sway_binding *binding_copy = sway_binding_dup(binding); - struct cmd_results *res = handle_command(binding->command); - if (res->status != CMD_SUCCESS) { - sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); - } - ipc_event_binding_keyboard(binding_copy); - free_cmd_results(res); + struct sway_binding *binding_copy = binding; + bool reload = false; + // if this is a reload command we need to make a duplicate of the + // binding since it will be gone after the reload has completed. + if (strcasecmp(binding->command, "reload") == 0) { + binding_copy = sway_binding_dup(binding); + reload = true; + } + + struct cmd_results *res = handle_command(binding->command); + if (res->status != CMD_SUCCESS) { + sway_log(L_ERROR, "Command '%s' failed: %s", res->input, res->error); + } + ipc_event_binding_keyboard(binding_copy); + + if (reload) { // free the binding if we made a copy free_sway_binding(binding_copy); + } + + free_cmd_results(res); } static bool handle_bindsym(struct sway_binding *binding) { diff --git a/sway/ipc-server.c b/sway/ipc-server.c index d8d8434c0..bde209312 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -298,8 +298,10 @@ void ipc_client_handle_command(struct ipc_client *client) { client->subscribed_events |= IPC_EVENT_MODE; } else if (strcmp(event_type, "modifier") == 0) { client->subscribed_events |= IPC_EVENT_MODIFIER; +#if SWAY_BINDING_EVENT } else if (strcmp(event_type, "binding") == 0) { client->subscribed_events |= IPC_EVENT_BINDING; +#endif } else { ipc_send_reply(client, "{\"success\": false}", 18); ipc_client_disconnect(client); @@ -636,6 +638,7 @@ void ipc_event_modifier(uint32_t modifier, const char *state) { json_object_put(obj); // free } +#if SWAY_BINDING_EVENT static void ipc_event_binding(json_object *sb_obj) { json_object *obj = json_object_new_object(); json_object_object_add(obj, "change", json_object_new_string("run")); @@ -646,8 +649,10 @@ static void ipc_event_binding(json_object *sb_obj) { json_object_put(obj); // free } +#endif void ipc_event_binding_keyboard(struct sway_binding *sb) { +#if SWAY_BINDING_EVENT json_object *sb_obj = json_object_new_object(); json_object_object_add(sb_obj, "command", json_object_new_string(sb->command)); @@ -679,4 +684,5 @@ void ipc_event_binding_keyboard(struct sway_binding *sb) { json_object_object_add(sb_obj, "input_type", json_object_new_string("keyboard")); ipc_event_binding(sb_obj); +#endif }