aboutsummaryrefslogtreecommitdiffstats
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-02-27 19:53:15 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-02-27 19:53:15 -0500
commit02804584e518fdf38e82eacedbe7606a87f004fc (patch)
treec3d61812289a8de405c601f7657d371bbe378f89 /sway/ipc-server.c
parentUtilize wlr_xwayland_surface_is_unmanaged (diff)
downloadsway-02804584e518fdf38e82eacedbe7606a87f004fc.tar.gz
sway-02804584e518fdf38e82eacedbe7606a87f004fc.tar.zst
sway-02804584e518fdf38e82eacedbe7606a87f004fc.zip
ipc new window event
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r--sway/ipc-server.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 4c0953e8..156de380 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -240,6 +240,57 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) {
240 return 0; 240 return 0;
241} 241}
242 242
243static void ipc_send_event(const char *json_string, enum ipc_command_type event) {
244 static struct {
245 enum ipc_command_type event;
246 enum ipc_feature feature;
247 } security_mappings[] = {
248 { IPC_EVENT_WORKSPACE, IPC_FEATURE_EVENT_WORKSPACE },
249 { IPC_EVENT_OUTPUT, IPC_FEATURE_EVENT_OUTPUT },
250 { IPC_EVENT_MODE, IPC_FEATURE_EVENT_MODE },
251 { IPC_EVENT_WINDOW, IPC_FEATURE_EVENT_WINDOW },
252 { IPC_EVENT_BINDING, IPC_FEATURE_EVENT_BINDING },
253 { IPC_EVENT_INPUT, IPC_FEATURE_EVENT_INPUT }
254 };
255
256 uint32_t security_mask = 0;
257 for (size_t i = 0; i < sizeof(security_mappings) / sizeof(security_mappings[0]); ++i) {
258 if (security_mappings[i].event == event) {
259 security_mask = security_mappings[i].feature;
260 break;
261 }
262 }
263
264 int i;
265 struct ipc_client *client;
266 for (i = 0; i < ipc_client_list->length; i++) {
267 client = ipc_client_list->items[i];
268 if (!(client->security_policy & security_mask)) {
269 continue;
270 }
271 if ((client->subscribed_events & event_mask(event)) == 0) {
272 continue;
273 }
274 client->current_command = event;
275 if (!ipc_send_reply(client, json_string, (uint32_t) strlen(json_string))) {
276 wlr_log_errno(L_INFO, "Unable to send reply to IPC client");
277 ipc_client_disconnect(client);
278 }
279 }
280}
281
282void ipc_event_window(swayc_t *window, const char *change) {
283 wlr_log(L_DEBUG, "Sending window::%s event", change);
284 json_object *obj = json_object_new_object();
285 json_object_object_add(obj, "change", json_object_new_string(change));
286 json_object_object_add(obj, "container", ipc_json_describe_container_recursive(window));
287
288 const char *json_string = json_object_to_json_string(obj);
289 ipc_send_event(json_string, IPC_EVENT_WINDOW);
290
291 json_object_put(obj); // free
292}
293
243int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { 294int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) {
244 struct ipc_client *client = data; 295 struct ipc_client *client = data;
245 296
@@ -361,6 +412,45 @@ void ipc_client_handle_command(struct ipc_client *client) {
361 goto exit_cleanup; 412 goto exit_cleanup;
362 } 413 }
363 414
415 case IPC_SUBSCRIBE:
416 {
417 // TODO: Check if they're permitted to use these events
418 struct json_object *request = json_tokener_parse(buf);
419 if (request == NULL) {
420 ipc_send_reply(client, "{\"success\": false}", 18);
421 wlr_log_errno(L_INFO, "Failed to read request");
422 goto exit_cleanup;
423 }
424
425 // parse requested event types
426 for (size_t i = 0; i < json_object_array_length(request); i++) {
427 const char *event_type = json_object_get_string(json_object_array_get_idx(request, i));
428 if (strcmp(event_type, "workspace") == 0) {
429 client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE);
430 } else if (strcmp(event_type, "barconfig_update") == 0) {
431 client->subscribed_events |= event_mask(IPC_EVENT_BARCONFIG_UPDATE);
432 } else if (strcmp(event_type, "mode") == 0) {
433 client->subscribed_events |= event_mask(IPC_EVENT_MODE);
434 } else if (strcmp(event_type, "window") == 0) {
435 client->subscribed_events |= event_mask(IPC_EVENT_WINDOW);
436 } else if (strcmp(event_type, "modifier") == 0) {
437 client->subscribed_events |= event_mask(IPC_EVENT_MODIFIER);
438 } else if (strcmp(event_type, "binding") == 0) {
439 client->subscribed_events |= event_mask(IPC_EVENT_BINDING);
440 } else {
441 ipc_send_reply(client, "{\"success\": false}", 18);
442 json_object_put(request);
443 wlr_log_errno(L_INFO, "Failed to parse request");
444 goto exit_cleanup;
445 }
446 }
447
448 json_object_put(request);
449
450 ipc_send_reply(client, "{\"success\": true}", 17);
451 goto exit_cleanup;
452 }
453
364 case IPC_GET_INPUTS: 454 case IPC_GET_INPUTS:
365 { 455 {
366 json_object *inputs = json_object_new_array(); 456 json_object *inputs = json_object_new_array();