diff options
-rw-r--r-- | include/ipc-json.h | 1 | ||||
-rw-r--r-- | include/ipc-server.h | 4 | ||||
-rw-r--r-- | sway/commands.c | 2 | ||||
-rw-r--r-- | sway/extensions.c | 2 | ||||
-rw-r--r-- | sway/focus.c | 4 | ||||
-rw-r--r-- | sway/handlers.c | 3 | ||||
-rw-r--r-- | sway/ipc-json.c | 87 | ||||
-rw-r--r-- | sway/ipc-server.c | 31 | ||||
-rw-r--r-- | sway/layout.c | 2 |
9 files changed, 113 insertions, 23 deletions
diff --git a/include/ipc-json.h b/include/ipc-json.h index f90d801e..02b07a23 100644 --- a/include/ipc-json.h +++ b/include/ipc-json.h | |||
@@ -9,5 +9,6 @@ json_object *ipc_json_get_version(); | |||
9 | json_object *ipc_json_describe_bar_config(struct bar_config *bar); | 9 | json_object *ipc_json_describe_bar_config(struct bar_config *bar); |
10 | json_object *ipc_json_describe_container(swayc_t *c); | 10 | json_object *ipc_json_describe_container(swayc_t *c); |
11 | json_object *ipc_json_describe_container_recursive(swayc_t *c); | 11 | json_object *ipc_json_describe_container_recursive(swayc_t *c); |
12 | json_object *ipc_json_describe_window(swayc_t *c); | ||
12 | 13 | ||
13 | #endif | 14 | #endif |
diff --git a/include/ipc-server.h b/include/ipc-server.h index aef3aa07..1d199134 100644 --- a/include/ipc-server.h +++ b/include/ipc-server.h | |||
@@ -18,6 +18,10 @@ void ipc_event_barconfig_update(struct bar_config *bar); | |||
18 | */ | 18 | */ |
19 | void ipc_event_mode(const char *mode); | 19 | void ipc_event_mode(const char *mode); |
20 | /** | 20 | /** |
21 | * Send IPC window change event | ||
22 | */ | ||
23 | void ipc_event_window(swayc_t *window, const char *change); | ||
24 | /** | ||
21 | * Sends an IPC modifier event to all listening clients. The modifier event | 25 | * Sends an IPC modifier event to all listening clients. The modifier event |
22 | * includes a key 'change' with the value of state and a key 'modifier' with | 26 | * includes a key 'change' with the value of state and a key 'modifier' with |
23 | * the name of that modifier. | 27 | * the name of that modifier. |
diff --git a/sway/commands.c b/sway/commands.c index aaacf0fc..5cf93c53 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -679,6 +679,7 @@ static struct cmd_results *cmd_floating(int argc, char **argv) { | |||
679 | view->width = view->height = 0; | 679 | view->width = view->height = 0; |
680 | arrange_windows(swayc_active_workspace(), -1, -1); | 680 | arrange_windows(swayc_active_workspace(), -1, -1); |
681 | remove_view_from_scratchpad(view); | 681 | remove_view_from_scratchpad(view); |
682 | ipc_event_window(view, "floating"); | ||
682 | } | 683 | } |
683 | set_focused_container(view); | 684 | set_focused_container(view); |
684 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 685 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
@@ -2495,6 +2496,7 @@ static struct cmd_results *cmd_fullscreen(int argc, char **argv) { | |||
2495 | arrange_windows(container, -1, -1); | 2496 | arrange_windows(container, -1, -1); |
2496 | workspace->fullscreen = NULL; | 2497 | workspace->fullscreen = NULL; |
2497 | } | 2498 | } |
2499 | ipc_event_window(container, "fullscreen_mode"); | ||
2498 | 2500 | ||
2499 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 2501 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
2500 | } | 2502 | } |
diff --git a/sway/extensions.c b/sway/extensions.c index 1fe15ac5..4611f33e 100644 --- a/sway/extensions.c +++ b/sway/extensions.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include "log.h" | 8 | #include "log.h" |
9 | #include "input_state.h" | 9 | #include "input_state.h" |
10 | #include "extensions.h" | 10 | #include "extensions.h" |
11 | #include "ipc-server.h" | ||
11 | 12 | ||
12 | struct desktop_shell_state desktop_shell; | 13 | struct desktop_shell_state desktop_shell; |
13 | 14 | ||
@@ -128,6 +129,7 @@ static void set_lock_surface(struct wl_client *client, struct wl_resource *resou | |||
128 | } | 129 | } |
129 | wlc_view_set_state(view->handle, WLC_BIT_FULLSCREEN, true); | 130 | wlc_view_set_state(view->handle, WLC_BIT_FULLSCREEN, true); |
130 | workspace->fullscreen = view; | 131 | workspace->fullscreen = view; |
132 | ipc_event_window(view, "fullscreen_mode"); | ||
131 | desktop_shell.is_locked = true; | 133 | desktop_shell.is_locked = true; |
132 | // reset input state | 134 | // reset input state |
133 | input_init(); | 135 | input_init(); |
diff --git a/sway/focus.c b/sway/focus.c index ff064b72..97fa4b98 100644 --- a/sway/focus.c +++ b/sway/focus.c | |||
@@ -118,6 +118,10 @@ bool set_focused_container(swayc_t *c) { | |||
118 | c = focused; | 118 | c = focused; |
119 | } | 119 | } |
120 | 120 | ||
121 | if (c->type == C_VIEW) { | ||
122 | // dispatch a window event | ||
123 | ipc_event_window(c, "focus"); | ||
124 | } | ||
121 | // update container focus from here to root, making necessary changes along | 125 | // update container focus from here to root, making necessary changes along |
122 | // the way | 126 | // the way |
123 | swayc_t *p = c; | 127 | swayc_t *p = c; |
diff --git a/sway/handlers.c b/sway/handlers.c index b95a6e65..abed8cd7 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -369,6 +369,7 @@ static bool handle_view_created(wlc_handle handle) { | |||
369 | suspend_workspace_cleanup = true; | 369 | suspend_workspace_cleanup = true; |
370 | 370 | ||
371 | if (newview) { | 371 | if (newview) { |
372 | ipc_event_window(newview, "new"); | ||
372 | set_focused_container(newview); | 373 | set_focused_container(newview); |
373 | swayc_t *output = swayc_parent_by_type(newview, C_OUTPUT); | 374 | swayc_t *output = swayc_parent_by_type(newview, C_OUTPUT); |
374 | arrange_windows(output, -1, -1); | 375 | arrange_windows(output, -1, -1); |
@@ -461,6 +462,7 @@ static void handle_view_destroyed(wlc_handle handle) { | |||
461 | } | 462 | } |
462 | 463 | ||
463 | arrange_windows(parent, -1, -1); | 464 | arrange_windows(parent, -1, -1); |
465 | ipc_event_window(parent, "close"); | ||
464 | } else { | 466 | } else { |
465 | // Is it unmanaged? | 467 | // Is it unmanaged? |
466 | int i; | 468 | int i; |
@@ -555,6 +557,7 @@ static void handle_view_properties_updated(wlc_handle view, uint32_t mask) { | |||
555 | } else if (c->border_type == B_NORMAL) { | 557 | } else if (c->border_type == B_NORMAL) { |
556 | update_view_border(c); | 558 | update_view_border(c); |
557 | } | 559 | } |
560 | ipc_event_window(c, "title"); | ||
558 | } | 561 | } |
559 | } | 562 | } |
560 | } | 563 | } |
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index ca45557c..4e5ea896 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -17,6 +17,17 @@ static json_object *ipc_json_create_rect(swayc_t *c) { | |||
17 | return rect; | 17 | return rect; |
18 | } | 18 | } |
19 | 19 | ||
20 | static json_object *ipc_json_create_rect_from_geometry(struct wlc_geometry g) { | ||
21 | json_object *rect = json_object_new_object(); | ||
22 | |||
23 | json_object_object_add(rect, "x", json_object_new_int(g.origin.x)); | ||
24 | json_object_object_add(rect, "y", json_object_new_int(g.origin.y)); | ||
25 | json_object_object_add(rect, "width", json_object_new_int(g.size.w)); | ||
26 | json_object_object_add(rect, "height", json_object_new_int(g.size.h)); | ||
27 | |||
28 | return rect; | ||
29 | } | ||
30 | |||
20 | static const char *ipc_json_border_description(swayc_t *c) { | 31 | static const char *ipc_json_border_description(swayc_t *c) { |
21 | const char *border; | 32 | const char *border; |
22 | 33 | ||
@@ -38,10 +49,10 @@ static const char *ipc_json_border_description(swayc_t *c) { | |||
38 | return border; | 49 | return border; |
39 | } | 50 | } |
40 | 51 | ||
41 | static const char *ipc_json_layout_description(swayc_t *c) { | 52 | static const char *ipc_json_layout_description(enum swayc_layouts l) { |
42 | const char *layout; | 53 | const char *layout; |
43 | 54 | ||
44 | switch (c->layout) { | 55 | switch (l) { |
45 | case L_VERT: | 56 | case L_VERT: |
46 | layout = "splitv"; | 57 | layout = "splitv"; |
47 | break; | 58 | break; |
@@ -111,7 +122,7 @@ static void ipc_json_describe_output(swayc_t *output, json_object *object) { | |||
111 | static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) { | 122 | static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) { |
112 | int num = (isdigit(workspace->name[0])) ? atoi(workspace->name) : -1; | 123 | int num = (isdigit(workspace->name[0])) ? atoi(workspace->name) : -1; |
113 | bool focused = root_container.focused == workspace->parent && workspace->parent->focused == workspace; | 124 | bool focused = root_container.focused == workspace->parent && workspace->parent->focused == workspace; |
114 | const char *layout = ipc_json_layout_description(workspace); | 125 | const char *layout = ipc_json_layout_description(workspace->layout); |
115 | 126 | ||
116 | json_object_object_add(object, "num", json_object_new_int(num)); | 127 | json_object_object_add(object, "num", json_object_new_int(num)); |
117 | json_object_object_add(object, "focused", json_object_new_boolean(focused)); | 128 | json_object_object_add(object, "focused", json_object_new_boolean(focused)); |
@@ -121,26 +132,68 @@ static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) | |||
121 | json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout)); | 132 | json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout)); |
122 | } | 133 | } |
123 | 134 | ||
124 | static void ipc_json_describe_view(swayc_t *view, json_object *object) { | 135 | // window is in the scratchpad ? changed : none |
125 | float percent = ipc_json_child_percentage(view); | 136 | static const char *ipc_json_get_scratchpad_state(swayc_t *c) { |
126 | const char *layout = ipc_json_layout_description(view); | 137 | int i; |
138 | for (i = 0; i < scratchpad->length; i++) { | ||
139 | if (scratchpad->items[i] == c) { | ||
140 | return "changed"; | ||
141 | } | ||
142 | } | ||
143 | return "none"; // we ignore the fresh value | ||
144 | } | ||
145 | |||
146 | static void ipc_json_describe_view(swayc_t *c, json_object *object) { | ||
147 | json_object *props = json_object_new_object(); | ||
148 | float percent = ipc_json_child_percentage(c); | ||
149 | const char *layout = (c->parent->type == C_CONTAINER) ? | ||
150 | ipc_json_layout_description(c->parent->layout) : "none"; | ||
151 | const char *last_layout = (c->parent->type == C_CONTAINER) ? | ||
152 | ipc_json_layout_description(c->parent->prev_layout) : "none"; | ||
153 | wlc_handle parent = wlc_view_get_parent(c->handle); | ||
154 | |||
155 | json_object_object_add(object, "id", json_object_new_int(c->handle)); | ||
156 | json_object_object_add(object, "type", json_object_new_string((c->is_floating) ? "floating_con" : "con")); | ||
127 | 157 | ||
128 | json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(view))); | 158 | json_object_object_add(object, "scratchpad_state", |
129 | json_object_object_add(object, "current_border_width", json_object_new_int(view->border_thickness)); | 159 | json_object_new_string(ipc_json_get_scratchpad_state(c))); |
130 | json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : NULL); | 160 | json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : NULL); |
131 | // TODO: make urgency actually work once Sway supports it | 161 | // TODO: make urgency actually work once Sway supports it |
132 | json_object_object_add(object, "urgent", json_object_new_boolean(false)); | 162 | json_object_object_add(object, "urgent", json_object_new_boolean(false)); |
133 | json_object_object_add(object, "focused", json_object_new_boolean(view->is_focused)); | 163 | json_object_object_add(object, "focused", json_object_new_boolean(c->is_focused)); |
134 | json_object_object_add(object, "type", json_object_new_string((view->is_floating) ? "floating_con" : "con")); | ||
135 | json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout)); | ||
136 | 164 | ||
137 | if (view->class) { | 165 | json_object_object_add(object, "layout", |
138 | json_object_object_add(object, "class", json_object_new_string(view->class)); | 166 | (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout)); |
139 | } | 167 | json_object_object_add(object, "last_split_layout", |
168 | (strcmp(last_layout, "null") == 0) ? NULL : json_object_new_string(last_layout)); | ||
169 | json_object_object_add(object, "workspace_layout", | ||
170 | json_object_new_string(ipc_json_layout_description(swayc_parent_by_type(c, C_WORKSPACE)->layout))); | ||
140 | 171 | ||
141 | if (view->app_id) { | 172 | json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(c))); |
142 | json_object_object_add(object, "app_id", json_object_new_string(view->app_id)); | 173 | json_object_object_add(object, "current_border_width", json_object_new_int(c->border_thickness)); |
143 | } | 174 | |
175 | json_object_object_add(object, "rect", ipc_json_create_rect(c)); | ||
176 | json_object_object_add(object, "deco_rect", ipc_json_create_rect_from_geometry(c->title_bar_geometry)); | ||
177 | json_object_object_add(object, "geometry", ipc_json_create_rect_from_geometry(c->cached_geometry)); | ||
178 | json_object_object_add(object, "window_rect", ipc_json_create_rect_from_geometry(c->actual_geometry)); | ||
179 | |||
180 | json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); | ||
181 | |||
182 | json_object_object_add(object, "window", json_object_new_int(c->handle)); // for the sake of i3 compat | ||
183 | json_object_object_add(props, "class", c->class ? json_object_new_string(c->class) : | ||
184 | c->app_id ? json_object_new_string(c->app_id) : NULL); | ||
185 | json_object_object_add(props, "title", (c->name) ? json_object_new_string(c->name) : NULL); | ||
186 | json_object_object_add(props, "transient_for", parent ? json_object_new_int(parent) : NULL); | ||
187 | json_object_object_add(object, "window_properties", props); | ||
188 | |||
189 | json_object_object_add(object, "fullscreen_mode", | ||
190 | json_object_new_int(swayc_is_fullscreen(c) ? 1 : 0)); | ||
191 | json_object_object_add(object, "sticky", json_object_new_boolean(c->sticky)); | ||
192 | json_object_object_add(object, "floating", json_object_new_string( | ||
193 | c->is_floating ? "auto_on" : "auto_off")); // we can't state the cause | ||
194 | |||
195 | json_object_object_add(object, "app_id", c->app_id ? json_object_new_string(c->app_id) : NULL); | ||
196 | // we do not include children, floating, unmanaged etc. as views have none | ||
144 | } | 197 | } |
145 | 198 | ||
146 | json_object *ipc_json_describe_container(swayc_t *c) { | 199 | json_object *ipc_json_describe_container(swayc_t *c) { |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 0729bfd5..305b6944 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -54,6 +54,8 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay | |||
54 | void ipc_get_workspaces_callback(swayc_t *workspace, void *data); | 54 | void ipc_get_workspaces_callback(swayc_t *workspace, void *data); |
55 | void ipc_get_outputs_callback(swayc_t *container, void *data); | 55 | void ipc_get_outputs_callback(swayc_t *container, void *data); |
56 | 56 | ||
57 | #define event_mask(ev) (1 << (ev & 0x7F)) | ||
58 | |||
57 | void ipc_init(void) { | 59 | void ipc_init(void) { |
58 | ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); | 60 | ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); |
59 | if (ipc_socket == -1) { | 61 | if (ipc_socket == -1) { |
@@ -334,16 +336,18 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
334 | for (int i = 0; i < json_object_array_length(request); i++) { | 336 | for (int i = 0; i < json_object_array_length(request); i++) { |
335 | const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); | 337 | const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); |
336 | if (strcmp(event_type, "workspace") == 0) { | 338 | if (strcmp(event_type, "workspace") == 0) { |
337 | client->subscribed_events |= IPC_EVENT_WORKSPACE; | 339 | client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE); |
338 | } else if (strcmp(event_type, "barconfig_update") == 0) { | 340 | } else if (strcmp(event_type, "barconfig_update") == 0) { |
339 | client->subscribed_events |= IPC_EVENT_BARCONFIG_UPDATE; | 341 | client->subscribed_events |= event_mask(IPC_EVENT_BARCONFIG_UPDATE); |
340 | } else if (strcmp(event_type, "mode") == 0) { | 342 | } else if (strcmp(event_type, "mode") == 0) { |
341 | client->subscribed_events |= IPC_EVENT_MODE; | 343 | client->subscribed_events |= event_mask(IPC_EVENT_MODE); |
344 | } else if (strcmp(event_type, "window") == 0) { | ||
345 | client->subscribed_events |= event_mask(IPC_EVENT_WINDOW); | ||
342 | } else if (strcmp(event_type, "modifier") == 0) { | 346 | } else if (strcmp(event_type, "modifier") == 0) { |
343 | client->subscribed_events |= IPC_EVENT_MODIFIER; | 347 | client->subscribed_events |= event_mask(IPC_EVENT_MODIFIER); |
344 | #if SWAY_BINDING_EVENT | 348 | #if SWAY_BINDING_EVENT |
345 | } else if (strcmp(event_type, "binding") == 0) { | 349 | } else if (strcmp(event_type, "binding") == 0) { |
346 | client->subscribed_events |= IPC_EVENT_BINDING; | 350 | client->subscribed_events |= event_mask(IPC_EVENT_BINDING); |
347 | #endif | 351 | #endif |
348 | } else { | 352 | } else { |
349 | ipc_send_reply(client, "{\"success\": false}", 18); | 353 | ipc_send_reply(client, "{\"success\": false}", 18); |
@@ -522,7 +526,7 @@ void ipc_send_event(const char *json_string, enum ipc_command_type event) { | |||
522 | struct ipc_client *client; | 526 | struct ipc_client *client; |
523 | for (i = 0; i < ipc_client_list->length; i++) { | 527 | for (i = 0; i < ipc_client_list->length; i++) { |
524 | client = ipc_client_list->items[i]; | 528 | client = ipc_client_list->items[i]; |
525 | if ((client->subscribed_events & event) == 0) { | 529 | if ((client->subscribed_events & event_mask(event)) == 0) { |
526 | continue; | 530 | continue; |
527 | } | 531 | } |
528 | client->current_command = event; | 532 | client->current_command = event; |
@@ -556,6 +560,21 @@ void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change) { | |||
556 | json_object_put(obj); // free | 560 | json_object_put(obj); // free |
557 | } | 561 | } |
558 | 562 | ||
563 | void ipc_event_window(swayc_t *window, const char *change) { | ||
564 | json_object *obj = json_object_new_object(); | ||
565 | json_object_object_add(obj, "change", json_object_new_string(change)); | ||
566 | if (strcmp(change, "close") == 0 || !window) { | ||
567 | json_object_object_add(obj, "container", NULL); | ||
568 | } else { | ||
569 | json_object_object_add(obj, "container", ipc_json_describe_container(window)); | ||
570 | } | ||
571 | |||
572 | const char *json_string = json_object_to_json_string(obj); | ||
573 | ipc_send_event(json_string, IPC_EVENT_WINDOW); | ||
574 | |||
575 | json_object_put(obj); // free | ||
576 | } | ||
577 | |||
559 | void ipc_event_barconfig_update(struct bar_config *bar) { | 578 | void ipc_event_barconfig_update(struct bar_config *bar) { |
560 | json_object *json = ipc_json_describe_bar_config(bar); | 579 | json_object *json = ipc_json_describe_bar_config(bar); |
561 | const char *json_string = json_object_to_json_string(json); | 580 | const char *json_string = json_object_to_json_string(json); |
diff --git a/sway/layout.c b/sway/layout.c index 2e0bf0bb..d32b4139 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -91,6 +91,7 @@ void add_floating(swayc_t *ws, swayc_t *child) { | |||
91 | if (!ws->focused) { | 91 | if (!ws->focused) { |
92 | ws->focused = child; | 92 | ws->focused = child; |
93 | } | 93 | } |
94 | ipc_event_window(child, "floating"); | ||
94 | } | 95 | } |
95 | 96 | ||
96 | swayc_t *add_sibling(swayc_t *fixed, swayc_t *active) { | 97 | swayc_t *add_sibling(swayc_t *fixed, swayc_t *active) { |
@@ -305,6 +306,7 @@ void move_container(swayc_t *container, enum movement_direction dir) { | |||
305 | parent = child->parent; | 306 | parent = child->parent; |
306 | } | 307 | } |
307 | arrange_windows(parent->parent, -1, -1); | 308 | arrange_windows(parent->parent, -1, -1); |
309 | ipc_event_window(container, "move"); | ||
308 | set_focused_container_for(parent->parent, container); | 310 | set_focused_container_for(parent->parent, container); |
309 | } | 311 | } |
310 | 312 | ||