aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/ipc.h7
-rw-r--r--sway/ipc-server.c36
2 files changed, 24 insertions, 19 deletions
diff --git a/include/ipc.h b/include/ipc.h
index 75be58a6..e0b3b736 100644
--- a/include/ipc.h
+++ b/include/ipc.h
@@ -10,6 +10,13 @@ enum ipc_command_type {
IPC_GET_MARKS = 5,
IPC_GET_BAR_CONFIG = 6,
IPC_GET_VERSION = 7,
+ // Events send from sway to clients. Events have the higest bit set.
+ IPC_EVENT_WORKSPACE = (1 << 31 | 0),
+ IPC_EVENT_OUTPUT = (1 << 31 | 1),
+ IPC_EVENT_MODE = (1 << 31 | 2),
+ IPC_EVENT_WINDOW = (1 << 31 | 3),
+ IPC_EVENT_BARCONFIG_UPDATE = (1 << 31 | 4),
+ IPC_EVENT_BINDING = (1 << 31 | 5),
IPC_SWAY_GET_PIXELS = 0x81
};
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index e161c756..2bb25202 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -290,9 +290,9 @@ void ipc_client_handle_command(struct ipc_client *client) {
for (int i = 0; i < json_object_array_length(request); i++) {
const char *event_type = json_object_get_string(json_object_array_get_idx(request, i));
if (strcmp(event_type, "workspace") == 0) {
- client->subscribed_events |= IPC_GET_WORKSPACES;
+ client->subscribed_events |= IPC_EVENT_WORKSPACE;
} else if (strcmp(event_type, "barconfig_update") == 0) {
- client->subscribed_events |= IPC_GET_BAR_CONFIG;
+ client->subscribed_events |= IPC_EVENT_BARCONFIG_UPDATE;
} else {
ipc_send_reply(client, "{\"success\": false}", 18);
ipc_client_disconnect(client);
@@ -562,6 +562,19 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
return json;
}
+void ipc_send_event(const char *json_string, enum ipc_command_type event) {
+ int i;
+ struct ipc_client *client;
+ for (i = 0; i < ipc_client_list->length; i++) {
+ client = ipc_client_list->items[i];
+ if ((client->subscribed_events & event) == 0) {
+ continue;
+ }
+ client->current_command = event;
+ ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
+ }
+}
+
void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) {
json_object *obj = json_object_new_object();
json_object_object_add(obj, "change", json_object_new_string(change));
@@ -580,14 +593,7 @@ void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) {
}
const char *json_string = json_object_to_json_string(obj);
-
- for (int i = 0; i < ipc_client_list->length; i++) {
- struct ipc_client *client = ipc_client_list->items[i];
- if ((client->subscribed_events & IPC_GET_WORKSPACES) == 0) {
- continue;
- }
- ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
- }
+ ipc_send_event(json_string, IPC_EVENT_WORKSPACE);
json_object_put(obj); // free
}
@@ -595,15 +601,7 @@ void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) {
void ipc_event_barconfig_update(struct bar_config *bar) {
json_object *json = ipc_json_describe_bar_config(bar);
const char *json_string = json_object_to_json_string(json);
- int i;
- struct ipc_client *client;
- for (i = 0; i < ipc_client_list->length; ++i) {
- client = ipc_client_list->items[i];
- if ((client->subscribed_events & IPC_GET_BAR_CONFIG) == 0) {
- continue;
- }
- ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
- }
+ ipc_send_event(json_string, IPC_EVENT_BARCONFIG_UPDATE);
json_object_put(json); // free
}