diff --git a/include/ipc.h b/include/ipc.h index 9deafff4..fcf1133b 100644 --- a/include/ipc.h +++ b/include/ipc.h @@ -37,6 +37,7 @@ enum ipc_command_type { IPC_EVENT_BAR_STATE_UPDATE = ((1<<31) | 20), IPC_EVENT_INPUT = ((1<<31) | 21), IPC_EVENT_IDLE_INHIBITOR = ((1<<31) | 22), + IPC_EVENT_KEYBOARD_SHORTCUTS_INHIBITOR = ((1<<31) | 23), }; #endif diff --git a/include/sway/ipc-json.h b/include/sway/ipc-json.h index 66520350..2f36c795 100644 --- a/include/sway/ipc-json.h +++ b/include/sway/ipc-json.h @@ -5,6 +5,7 @@ #include "sway/tree/container.h" #include "sway/desktop/idle_inhibit_v1.h" #include "sway/input/input-manager.h" +#include "sway/input/seat.h" #include "sway/tree/container.h" json_object *ipc_json_get_version(void); @@ -20,5 +21,7 @@ json_object *ipc_json_describe_seat(struct sway_seat *seat); json_object *ipc_json_describe_bar_config(struct bar_config *bar); json_object *ipc_json_describe_idle_inhibitor( struct sway_idle_inhibitor_v1 *sway_inhibitor); +json_object *ipc_json_describe_keyboard_shortcuts_inhibitor( + struct sway_keyboard_shortcuts_inhibitor *sway_inhibitor); #endif diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h index 8e5336f1..4590e006 100644 --- a/include/sway/ipc-server.h +++ b/include/sway/ipc-server.h @@ -4,6 +4,7 @@ #include "sway/config.h" #include "sway/desktop/idle_inhibit_v1.h" #include "sway/input/input-manager.h" +#include "sway/input/seat.h" #include "sway/tree/container.h" #include "ipc.h" @@ -24,5 +25,8 @@ void ipc_event_binding(struct sway_binding *binding); void ipc_event_input(const char *change, struct sway_input_device *device); void ipc_event_output(void); void ipc_event_idle_inhibitor(struct sway_idle_inhibitor_v1 *inhibitor, const char *change); +void ipc_event_keyboard_shortcuts_inhibitor( + struct sway_keyboard_shortcuts_inhibitor *inhibitor, + const char *change); #endif diff --git a/sway/commands/seat/shortcuts_inhibitor.c b/sway/commands/seat/shortcuts_inhibitor.c index 7c7f99cf..ce895cde 100644 --- a/sway/commands/seat/shortcuts_inhibitor.c +++ b/sway/commands/seat/shortcuts_inhibitor.c @@ -2,6 +2,7 @@ #include "sway/commands.h" #include "sway/input/seat.h" #include "sway/input/input-manager.h" +#include "sway/ipc-server.h" #include "util.h" static struct cmd_results *handle_action(struct seat_config *sc, @@ -12,6 +13,8 @@ static struct cmd_results *handle_action(struct seat_config *sc, wl_list_for_each(sway_inhibitor, &seat->keyboard_shortcuts_inhibitors, link) { + ipc_event_keyboard_shortcuts_inhibitor( + sway_inhibitor, "deactivate"); wlr_keyboard_shortcuts_inhibitor_v1_deactivate( sway_inhibitor->inhibitor); } @@ -39,8 +42,12 @@ static struct cmd_results *handle_action(struct seat_config *sc, } if (inhibit) { + ipc_event_keyboard_shortcuts_inhibitor( + sway_inhibitor, "activate"); wlr_keyboard_shortcuts_inhibitor_v1_activate(inhibitor); } else { + ipc_event_keyboard_shortcuts_inhibitor( + sway_inhibitor, "deactivate"); wlr_keyboard_shortcuts_inhibitor_v1_deactivate(inhibitor); } diff --git a/sway/commands/shortcuts_inhibitor.c b/sway/commands/shortcuts_inhibitor.c index ffa1a5c9..45eb5d6e 100644 --- a/sway/commands/shortcuts_inhibitor.c +++ b/sway/commands/shortcuts_inhibitor.c @@ -3,6 +3,7 @@ #include "sway/commands.h" #include "sway/config.h" #include "sway/input/seat.h" +#include "sway/ipc-server.h" #include "sway/tree/container.h" #include "sway/tree/view.h" @@ -33,12 +34,13 @@ struct cmd_results *cmd_shortcuts_inhibitor(int argc, char **argv) { continue; } + ipc_event_keyboard_shortcuts_inhibitor( + sway_inhibitor, "deactivate"); wlr_keyboard_shortcuts_inhibitor_v1_deactivate( sway_inhibitor->inhibitor); sway_log(SWAY_DEBUG, "Deactivated keyboard shortcuts " "inhibitor for seat %s on view", seat->wlr_seat->name); - } } else { return cmd_results_new(CMD_INVALID, diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index c1bbdde0..e668f1a7 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -290,6 +290,8 @@ static void handle_keyboard_shortcuts_inhibitor_destroy( sway_log(SWAY_DEBUG, "Removing keyboard shortcuts inhibitor"); + ipc_event_keyboard_shortcuts_inhibitor(sway_inhibitor, "destroy"); + // sway_seat::keyboard_shortcuts_inhibitors wl_list_remove(&sway_inhibitor->link); wl_list_remove(&sway_inhibitor->destroy.link); @@ -313,6 +315,8 @@ static void handle_keyboard_shortcuts_inhibit_new_inhibitor( } sway_inhibitor->inhibitor = inhibitor; + ipc_event_keyboard_shortcuts_inhibitor(sway_inhibitor, "create"); + sway_inhibitor->destroy.notify = handle_keyboard_shortcuts_inhibitor_destroy; wl_signal_add(&inhibitor->events.destroy, &sway_inhibitor->destroy); @@ -353,6 +357,7 @@ static void handle_keyboard_shortcuts_inhibit_new_inhibitor( return; } + ipc_event_keyboard_shortcuts_inhibitor(sway_inhibitor, "activate"); wlr_keyboard_shortcuts_inhibitor_v1_activate(inhibitor); } diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 6f6a3dc6..562f61c4 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -1468,3 +1468,17 @@ json_object *ipc_json_describe_idle_inhibitor( return object; } + +json_object *ipc_json_describe_keyboard_shortcuts_inhibitor( + struct sway_keyboard_shortcuts_inhibitor *sway_inhibitor) { + json_object *object = json_object_new_object(); + + struct sway_view *view = view_from_wlr_surface( + sway_inhibitor->inhibitor->surface); + if (view && view->container) { + json_object_object_add(object, "container", + ipc_json_describe_node(&view->container->node)); + } + + return object; +} diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 8a452567..e52a26e5 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -537,6 +537,24 @@ void ipc_event_idle_inhibitor(struct sway_idle_inhibitor_v1 *inhibitor, const ch json_object_put(obj); } +void ipc_event_keyboard_shortcuts_inhibitor( + struct sway_keyboard_shortcuts_inhibitor *inhibitor, + const char *change) { + if (!ipc_has_event_listeners(IPC_EVENT_KEYBOARD_SHORTCUTS_INHIBITOR)) { + return; + } + sway_log(SWAY_DEBUG, "Sending keyboard shortcuts " + "inhibitor::%s event", change); + json_object *obj = json_object_new_object(); + json_object_object_add(obj, "change", json_object_new_string(change)); + json_object_object_add(obj, "keyboard_shortcuts_inhibitor", + ipc_json_describe_keyboard_shortcuts_inhibitor(inhibitor)); + + const char *json_string = json_object_to_json_string(obj); + ipc_send_event(json_string, IPC_EVENT_KEYBOARD_SHORTCUTS_INHIBITOR); + json_object_put(obj); +} + int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { struct ipc_client *client = data; @@ -775,6 +793,9 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt client->subscribed_events |= event_mask(IPC_EVENT_INPUT); } else if (strcmp(event_type, "idle_inhibitor") == 0) { client->subscribed_events |= event_mask(IPC_EVENT_IDLE_INHIBITOR); + } else if (strcmp(event_type, "keyboard_shortcuts_inhibitor") == 0) { + client->subscribed_events |= event_mask( + IPC_EVENT_KEYBOARD_SHORTCUTS_INHIBITOR); } else { const char msg[] = "{\"success\": false}"; ipc_send_reply(client, payload_type, msg, strlen(msg));