mirror of
https://github.com/swaywm/sway.git
synced 2024-11-14 14:34:07 +01:00
Add keyboard shortcuts inhibitor ipc subscription
Add a new type of ipc subscription so clients can be notified of changes in keyboard shortcuts inhibitors. This allows to react to those events by e.g. changing container properties (title, ...) to notify the user about this circumstance (add marker, change color, ...). For this reason the event includes information about the affected container as well. Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
This commit is contained in:
parent
d48c2998e3
commit
b6c689c72e
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user