diff options
author | Mykyta Holubakha <hilobakho@gmail.com> | 2016-07-19 23:28:06 +0300 |
---|---|---|
committer | Mykyta Holubakha <hilobakho@gmail.com> | 2016-07-21 21:51:20 +0300 |
commit | 2029fef6b8ce7d9e332bd616bb9c6a76fa404c06 (patch) | |
tree | b1f7493a8633aa3249814a3aaa31057fa43f3bf6 | |
parent | Initial work on window events (diff) | |
download | sway-2029fef6b8ce7d9e332bd616bb9c6a76fa404c06.tar.gz sway-2029fef6b8ce7d9e332bd616bb9c6a76fa404c06.tar.zst sway-2029fef6b8ce7d9e332bd616bb9c6a76fa404c06.zip |
More progress on window events
-rw-r--r-- | include/ipc-json.h | 1 | ||||
-rw-r--r-- | sway/ipc-json.c | 92 | ||||
-rw-r--r-- | sway/ipc-server.c | 2 |
3 files changed, 90 insertions, 5 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/sway/ipc-json.c b/sway/ipc-json.c index ca45557c..9731e7c7 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)); |
@@ -123,7 +134,7 @@ static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) | |||
123 | 134 | ||
124 | static void ipc_json_describe_view(swayc_t *view, json_object *object) { | 135 | static void ipc_json_describe_view(swayc_t *view, json_object *object) { |
125 | float percent = ipc_json_child_percentage(view); | 136 | float percent = ipc_json_child_percentage(view); |
126 | const char *layout = ipc_json_layout_description(view); | 137 | const char *layout = ipc_json_layout_description(view->layout); |
127 | 138 | ||
128 | json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(view))); | 139 | json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(view))); |
129 | json_object_object_add(object, "current_border_width", json_object_new_int(view->border_thickness)); | 140 | json_object_object_add(object, "current_border_width", json_object_new_int(view->border_thickness)); |
@@ -181,6 +192,79 @@ json_object *ipc_json_describe_container(swayc_t *c) { | |||
181 | return object; | 192 | return object; |
182 | } | 193 | } |
183 | 194 | ||
195 | // window is in the scratchpad ? changed : none | ||
196 | static const char *ipc_json_get_scratchpad_state(swayc_t *c) { | ||
197 | int i; | ||
198 | for (i = 0; i < scratchpad->length; i++) { | ||
199 | if (scratchpad->items[i] == c) { | ||
200 | return "changed"; | ||
201 | } | ||
202 | } | ||
203 | return "none"; // we ignore the fresh value | ||
204 | } | ||
205 | |||
206 | // simulate i3, it's probably not a good idea to use it anywhere except window events | ||
207 | json_object *ipc_json_describe_window(swayc_t *c) { | ||
208 | if (!(sway_assert(c, "Container must not be null."))) { | ||
209 | return NULL; | ||
210 | } | ||
211 | json_object *object = json_object_new_object(); | ||
212 | json_object *props = json_object_new_object(); | ||
213 | json_object *arr = json_object_new_array(); | ||
214 | float percent = ipc_json_child_percentage(c); | ||
215 | const char *layout = (c->parent->type == C_CONTAINER) ? | ||
216 | ipc_json_layout_description(c->parent->layout) : "none"; | ||
217 | const char *last_layout = (c->parent->type == C_CONTAINER) ? | ||
218 | ipc_json_layout_description(c->parent->prev_layout) : "none"; | ||
219 | |||
220 | json_object_object_add(object, "id", json_object_new_int(c->handle)); | ||
221 | json_object_object_add(object, "type", json_object_new_string((c->is_floating) ? "floating_con" : "con")); | ||
222 | |||
223 | json_object_object_add(object, "scratchpad_state", | ||
224 | json_object_new_string(ipc_json_get_scratchpad_state(c))); | ||
225 | json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : NULL); | ||
226 | // TODO: make urgency actually work once Sway supports it | ||
227 | json_object_object_add(object, "urgent", json_object_new_boolean(false)); | ||
228 | json_object_object_add(object, "focused", json_object_new_boolean(c->is_focused)); | ||
229 | |||
230 | json_object_object_add(object, "layout", | ||
231 | (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout)); | ||
232 | json_object_object_add(object, "last_split_layout", | ||
233 | (strcmp(last_layout, "null") == 0) ? NULL : json_object_new_string(last_layout)); | ||
234 | json_object_object_add(object, "workspace_layout", | ||
235 | json_object_new_string(ipc_json_layout_description(swayc_parent_by_type(c, C_WORKSPACE)->layout))); | ||
236 | |||
237 | json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(c))); | ||
238 | json_object_object_add(object, "current_border_width", json_object_new_int(c->border_thickness)); | ||
239 | |||
240 | json_object_object_add(object, "rect", ipc_json_create_rect(c)); | ||
241 | json_object_object_add(object, "deco_rect", ipc_json_create_rect_from_geometry(c->title_bar_geometry)); | ||
242 | json_object_object_add(object, "geometry", ipc_json_create_rect_from_geometry(c->cached_geometry)); | ||
243 | json_object_object_add(object, "window_rect", ipc_json_create_rect_from_geometry(c->actual_geometry)); //? | ||
244 | |||
245 | json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); | ||
246 | |||
247 | json_object_object_add(object, "window", json_object_new_int(c->handle)); // for the sake of i3 compat | ||
248 | json_object_object_add(props, "class", json_object_new_string( | ||
249 | c->class ? c->class : c->app_id ? c->app_id : "null")); | ||
250 | json_object_object_add(props, "title", json_object_new_string(c->name)); | ||
251 | // json_object_object_add(props, "instance", json_object_new_string(c->name)); | ||
252 | json_object_object_add(props, "transient_for", NULL); // ditto | ||
253 | json_object_object_add(object, "window_properties", props); | ||
254 | |||
255 | json_object_object_add(object, "fullscreen_mode", | ||
256 | json_object_new_int(swayc_is_fullscreen(c) ? 1 : 0)); | ||
257 | json_object_object_add(object, "sticky", json_object_new_boolean(c->sticky)); | ||
258 | json_object_object_add(object, "floating", json_object_new_string( | ||
259 | c->is_floating ? "auto_on" : "auto_off")); // not sure if all the info is saved | ||
260 | if (c->app_id) { | ||
261 | json_object_object_add(object, "app_id", json_object_new_string(c->app_id)); | ||
262 | } | ||
263 | |||
264 | |||
265 | return object; | ||
266 | } | ||
267 | |||
184 | json_object *ipc_json_get_version() { | 268 | json_object *ipc_json_get_version() { |
185 | json_object *version = json_object_new_object(); | 269 | json_object *version = json_object_new_object(); |
186 | 270 | ||
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 1dc3ab79..24df4649 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -564,7 +564,7 @@ void ipc_event_window(swayc_t *window, const char *change) { | |||
564 | if (strcmp(change, "close") == 0 || !window) { | 564 | if (strcmp(change, "close") == 0 || !window) { |
565 | json_object_object_add(obj, "container", NULL); | 565 | json_object_object_add(obj, "container", NULL); |
566 | } else { | 566 | } else { |
567 | json_object_object_add(obj, "container", ipc_json_describe_container(window)); | 567 | json_object_object_add(obj, "container", ipc_json_describe_window(window)); |
568 | } | 568 | } |
569 | 569 | ||
570 | const char *json_string = json_object_to_json_string(obj); | 570 | const char *json_string = json_object_to_json_string(obj); |