mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 01:41:30 +00:00
Add IPC event types
Adds custom IPC_EVENT_* types
This commit is contained in:
parent
a20226772e
commit
19833fbc8b
|
@ -10,6 +10,13 @@ enum ipc_command_type {
|
||||||
IPC_GET_MARKS = 5,
|
IPC_GET_MARKS = 5,
|
||||||
IPC_GET_BAR_CONFIG = 6,
|
IPC_GET_BAR_CONFIG = 6,
|
||||||
IPC_GET_VERSION = 7,
|
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
|
IPC_SWAY_GET_PIXELS = 0x81
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -290,9 +290,9 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
||||||
for (int i = 0; i < json_object_array_length(request); i++) {
|
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));
|
const char *event_type = json_object_get_string(json_object_array_get_idx(request, i));
|
||||||
if (strcmp(event_type, "workspace") == 0) {
|
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) {
|
} else if (strcmp(event_type, "barconfig_update") == 0) {
|
||||||
client->subscribed_events |= IPC_GET_BAR_CONFIG;
|
client->subscribed_events |= IPC_EVENT_BARCONFIG_UPDATE;
|
||||||
} else {
|
} else {
|
||||||
ipc_send_reply(client, "{\"success\": false}", 18);
|
ipc_send_reply(client, "{\"success\": false}", 18);
|
||||||
ipc_client_disconnect(client);
|
ipc_client_disconnect(client);
|
||||||
|
@ -562,6 +562,19 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
|
||||||
return json;
|
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) {
|
void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) {
|
||||||
json_object *obj = json_object_new_object();
|
json_object *obj = json_object_new_object();
|
||||||
json_object_object_add(obj, "change", json_object_new_string(change));
|
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);
|
const char *json_string = json_object_to_json_string(obj);
|
||||||
|
ipc_send_event(json_string, IPC_EVENT_WORKSPACE);
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
json_object_put(obj); // free
|
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) {
|
void ipc_event_barconfig_update(struct bar_config *bar) {
|
||||||
json_object *json = ipc_json_describe_bar_config(bar);
|
json_object *json = ipc_json_describe_bar_config(bar);
|
||||||
const char *json_string = json_object_to_json_string(json);
|
const char *json_string = json_object_to_json_string(json);
|
||||||
int i;
|
ipc_send_event(json_string, IPC_EVENT_BARCONFIG_UPDATE);
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
json_object_put(json); // free
|
json_object_put(json); // free
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue