diff options
author | Armin Preiml <apreiml@strohwolke.at> | 2018-09-02 13:22:19 +0200 |
---|---|---|
committer | Armin Preiml <apreiml@strohwolke.at> | 2018-09-08 13:24:01 +0200 |
commit | 3d8c3e560b9c984fbcc06c3a5edbace90a34aebe (patch) | |
tree | 4c9330512d885d6df4beef3e1139e329e8aeb674 | |
parent | Merge pull request #2603 from emersion/fix-dnd (diff) | |
download | sway-3d8c3e560b9c984fbcc06c3a5edbace90a34aebe.tar.gz sway-3d8c3e560b9c984fbcc06c3a5edbace90a34aebe.tar.zst sway-3d8c3e560b9c984fbcc06c3a5edbace90a34aebe.zip |
missing ipc stuff: rebase to typesafety
-rw-r--r-- | sway/ipc-json.c | 136 |
1 files changed, 120 insertions, 16 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index abc4a086..745d129a 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -30,6 +30,20 @@ static const char *ipc_json_layout_description(enum sway_container_layout l) { | |||
30 | return "none"; | 30 | return "none"; |
31 | } | 31 | } |
32 | 32 | ||
33 | static const char *ipc_json_orientation_description(enum sway_container_layout l) { | ||
34 | switch (l) { | ||
35 | case L_VERT: | ||
36 | return "vertical"; | ||
37 | case L_HORIZ: | ||
38 | return "horizontal"; | ||
39 | case L_TABBED: | ||
40 | case L_STACKED: | ||
41 | case L_NONE: | ||
42 | break; | ||
43 | } | ||
44 | return "none"; | ||
45 | } | ||
46 | |||
33 | json_object *ipc_json_get_version() { | 47 | json_object *ipc_json_get_version() { |
34 | int major = 0, minor = 0, patch = 0; | 48 | int major = 0, minor = 0, patch = 0; |
35 | json_object *version = json_object_new_object(); | 49 | json_object *version = json_object_new_object(); |
@@ -57,9 +71,17 @@ static json_object *ipc_json_create_rect(struct wlr_box *box) { | |||
57 | return rect; | 71 | return rect; |
58 | } | 72 | } |
59 | 73 | ||
74 | static json_object *ipc_json_create_empty_rect(void) { | ||
75 | struct wlr_box empty = {0, 0, 0, 0}; | ||
76 | |||
77 | return ipc_json_create_rect(&empty); | ||
78 | } | ||
79 | |||
60 | static void ipc_json_describe_root(struct sway_root *root, json_object *object) { | 80 | static void ipc_json_describe_root(struct sway_root *root, json_object *object) { |
61 | json_object_object_add(object, "type", json_object_new_string("root")); | 81 | json_object_object_add(object, "type", json_object_new_string("root")); |
62 | json_object_object_add(object, "layout", json_object_new_string("splith")); | 82 | json_object_object_add(object, "layout", json_object_new_string("splith")); |
83 | json_object_object_add(object, "orientation", | ||
84 | json_object_new_string(ipc_json_orientation_description(L_HORIZ))); | ||
63 | } | 85 | } |
64 | 86 | ||
65 | static const char *ipc_json_get_output_transform(enum wl_output_transform transform) { | 87 | static const char *ipc_json_get_output_transform(enum wl_output_transform transform) { |
@@ -124,6 +146,22 @@ static void ipc_json_describe_output(struct sway_output *output, | |||
124 | 146 | ||
125 | json_object_object_add(object, "modes", modes_array); | 147 | json_object_object_add(object, "modes", modes_array); |
126 | json_object_object_add(object, "layout", json_object_new_string("output")); | 148 | json_object_object_add(object, "layout", json_object_new_string("output")); |
149 | |||
150 | struct sway_node *parent = node_get_parent(&output->node); | ||
151 | struct wlr_box parent_box = {0, 0, 0, 0}; | ||
152 | |||
153 | if (parent != NULL) { | ||
154 | node_get_box(parent, &parent_box); | ||
155 | } | ||
156 | |||
157 | if (parent_box.width == 0 || parent_box.height == 0) { | ||
158 | json_object_object_add(object, "percent", NULL); | ||
159 | } | ||
160 | else { | ||
161 | double percent = (output->width / parent_box.width) | ||
162 | * (output->height / parent_box.height); | ||
163 | json_object_object_add(object, "percent", json_object_new_double(percent)); | ||
164 | } | ||
127 | } | 165 | } |
128 | 166 | ||
129 | json_object *ipc_json_describe_disabled_output(struct sway_output *output) { | 167 | json_object *ipc_json_describe_disabled_output(struct sway_output *output) { |
@@ -143,6 +181,8 @@ json_object *ipc_json_describe_disabled_output(struct sway_output *output) { | |||
143 | json_object_new_string(wlr_output->serial)); | 181 | json_object_new_string(wlr_output->serial)); |
144 | json_object_object_add(object, "modes", json_object_new_array()); | 182 | json_object_object_add(object, "modes", json_object_new_array()); |
145 | 183 | ||
184 | json_object_object_add(object, "percent", NULL); | ||
185 | |||
146 | return object; | 186 | return object; |
147 | } | 187 | } |
148 | 188 | ||
@@ -162,6 +202,9 @@ static void ipc_json_describe_workspace(struct sway_workspace *workspace, | |||
162 | const char *layout = ipc_json_layout_description(workspace->layout); | 202 | const char *layout = ipc_json_layout_description(workspace->layout); |
163 | json_object_object_add(object, "layout", json_object_new_string(layout)); | 203 | json_object_object_add(object, "layout", json_object_new_string(layout)); |
164 | 204 | ||
205 | const char *orientation = ipc_json_orientation_description(workspace->layout); | ||
206 | json_object_object_add(object, "orientation", json_object_new_string(orientation)); | ||
207 | |||
165 | // Floating | 208 | // Floating |
166 | json_object *floating_array = json_object_new_array(); | 209 | json_object *floating_array = json_object_new_array(); |
167 | for (int i = 0; i < workspace->floating->length; ++i) { | 210 | for (int i = 0; i < workspace->floating->length; ++i) { |
@@ -172,35 +215,96 @@ static void ipc_json_describe_workspace(struct sway_workspace *workspace, | |||
172 | json_object_object_add(object, "floating_nodes", floating_array); | 215 | json_object_object_add(object, "floating_nodes", floating_array); |
173 | } | 216 | } |
174 | 217 | ||
218 | static const char *describe_container_border(enum sway_container_border border) { | ||
219 | switch (border) { | ||
220 | case B_NONE: | ||
221 | return "none"; | ||
222 | case B_PIXEL: | ||
223 | return "pixel"; | ||
224 | case B_NORMAL: | ||
225 | return "normal"; | ||
226 | } | ||
227 | return "unknown"; | ||
228 | } | ||
229 | |||
175 | static void ipc_json_describe_view(struct sway_container *c, json_object *object) { | 230 | static void ipc_json_describe_view(struct sway_container *c, json_object *object) { |
176 | json_object_object_add(object, "name", | 231 | const char *app_id = view_get_app_id(c->view); |
177 | c->title ? json_object_new_string(c->title) : NULL); | 232 | json_object_object_add(object, "app_id", |
178 | json_object_object_add(object, "type", json_object_new_string("con")); | 233 | app_id ? json_object_new_string(app_id) : NULL); |
234 | |||
235 | const char *class = view_get_class(c->view); | ||
236 | json_object_object_add(object, "class", | ||
237 | class ? json_object_new_string(class) : NULL); | ||
238 | |||
239 | json_object *marks = json_object_new_array(); | ||
240 | list_t *view_marks = c->view->marks; | ||
241 | for (int i = 0; i < view_marks->length; ++i) { | ||
242 | json_object_array_add(marks, json_object_new_string(view_marks->items[i])); | ||
243 | } | ||
179 | 244 | ||
180 | if (c->view) { | 245 | json_object_object_add(object, "marks", marks); |
181 | const char *app_id = view_get_app_id(c->view); | ||
182 | json_object_object_add(object, "app_id", | ||
183 | app_id ? json_object_new_string(app_id) : NULL); | ||
184 | 246 | ||
185 | const char *class = view_get_class(c->view); | 247 | struct wlr_box window_box = { |
186 | json_object_object_add(object, "class", | 248 | c->view->x - c->x, |
187 | class ? json_object_new_string(class) : NULL); | 249 | (c->current.border == B_PIXEL) ? c->current.border_thickness : 0, |
250 | c->view->width, | ||
251 | c->view->height | ||
252 | }; | ||
253 | |||
254 | json_object_object_add(object, "window_rect", ipc_json_create_rect(&window_box)); | ||
255 | |||
256 | struct wlr_box deco_box = {0, 0, 0, 0}; | ||
257 | |||
258 | if (c->current.border == B_NORMAL) { | ||
259 | deco_box.width = c->width; | ||
260 | deco_box.height = c->view->y - c->y; | ||
188 | } | 261 | } |
189 | 262 | ||
263 | json_object_object_add(object, "deco_rect", ipc_json_create_rect(&deco_box)); | ||
264 | } | ||
265 | |||
266 | static void ipc_json_describe_container(struct sway_container *c, json_object *object) { | ||
267 | json_object_object_add(object, "name", | ||
268 | c->title ? json_object_new_string(c->title) : NULL); | ||
269 | json_object_object_add(object, "type", json_object_new_string("con")); | ||
270 | |||
190 | json_object_object_add(object, "layout", | 271 | json_object_object_add(object, "layout", |
191 | json_object_new_string(ipc_json_layout_description(c->layout))); | 272 | json_object_new_string(ipc_json_layout_description(c->layout))); |
192 | 273 | ||
274 | json_object_object_add(object, "orientation", | ||
275 | json_object_new_string(ipc_json_orientation_description(c->layout))); | ||
276 | |||
193 | bool urgent = c->view ? | 277 | bool urgent = c->view ? |
194 | view_is_urgent(c->view) : container_has_urgent_child(c); | 278 | view_is_urgent(c->view) : container_has_urgent_child(c); |
195 | json_object_object_add(object, "urgent", json_object_new_boolean(urgent)); | 279 | json_object_object_add(object, "urgent", json_object_new_boolean(urgent)); |
196 | 280 | ||
281 | struct sway_node *parent = node_get_parent(&c->node); | ||
282 | struct wlr_box parent_box = {0, 0, 0, 0}; | ||
283 | |||
284 | if (parent != NULL) { | ||
285 | node_get_box(parent, &parent_box); | ||
286 | } | ||
287 | |||
288 | if (parent_box.width == 0 || parent_box.height == 0) { | ||
289 | json_object_object_add(object, "percent", NULL); | ||
290 | } | ||
291 | else { | ||
292 | double percent = (c->width / parent_box.width) | ||
293 | * (c->height / parent_box.height); | ||
294 | json_object_object_add(object, "percent", json_object_new_double(percent)); | ||
295 | } | ||
296 | |||
297 | json_object_object_add(object, "window_rect", ipc_json_create_empty_rect()); | ||
298 | json_object_object_add(object, "deco_rect", ipc_json_create_empty_rect()); | ||
299 | |||
300 | json_object_object_add(object, "border", | ||
301 | json_object_new_string(describe_container_border(c->current.border))); | ||
302 | json_object_object_add(object, "current_border_width", | ||
303 | json_object_new_int(c->current.border_thickness)); | ||
304 | json_object_object_add(object, "floating_nodes", json_object_new_array()); | ||
305 | |||
197 | if (c->view) { | 306 | if (c->view) { |
198 | json_object *marks = json_object_new_array(); | 307 | ipc_json_describe_view(c, object); |
199 | list_t *view_marks = c->view->marks; | ||
200 | for (int i = 0; i < view_marks->length; ++i) { | ||
201 | json_object_array_add(marks, json_object_new_string(view_marks->items[i])); | ||
202 | } | ||
203 | json_object_object_add(object, "marks", marks); | ||
204 | } | 308 | } |
205 | } | 309 | } |
206 | 310 | ||