diff options
author | Mykyta Holubakha <hilobakho@gmail.com> | 2016-07-21 02:06:34 +0300 |
---|---|---|
committer | Mykyta Holubakha <hilobakho@gmail.com> | 2016-07-21 21:51:20 +0300 |
commit | f52daa26c9bb4984ec857de1b18560a4c47553c8 (patch) | |
tree | 32a7e23a47f812eb107c3ff4a82bf259220e3a56 | |
parent | Fix dispatching and assigning events (diff) | |
download | sway-f52daa26c9bb4984ec857de1b18560a4c47553c8.tar.gz sway-f52daa26c9bb4984ec857de1b18560a4c47553c8.tar.zst sway-f52daa26c9bb4984ec857de1b18560a4c47553c8.zip |
Unite describe_view and describe_window
-rw-r--r-- | sway/ipc-json.c | 118 | ||||
-rw-r--r-- | sway/ipc-server.c | 2 |
2 files changed, 44 insertions, 76 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 9731e7c7..f893aabf 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -132,66 +132,6 @@ static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) | |||
132 | 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)); |
133 | } | 133 | } |
134 | 134 | ||
135 | static void ipc_json_describe_view(swayc_t *view, json_object *object) { | ||
136 | float percent = ipc_json_child_percentage(view); | ||
137 | const char *layout = ipc_json_layout_description(view->layout); | ||
138 | |||
139 | json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(view))); | ||
140 | json_object_object_add(object, "current_border_width", json_object_new_int(view->border_thickness)); | ||
141 | json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : NULL); | ||
142 | // TODO: make urgency actually work once Sway supports it | ||
143 | json_object_object_add(object, "urgent", json_object_new_boolean(false)); | ||
144 | json_object_object_add(object, "focused", json_object_new_boolean(view->is_focused)); | ||
145 | json_object_object_add(object, "type", json_object_new_string((view->is_floating) ? "floating_con" : "con")); | ||
146 | json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout)); | ||
147 | |||
148 | if (view->class) { | ||
149 | json_object_object_add(object, "class", json_object_new_string(view->class)); | ||
150 | } | ||
151 | |||
152 | if (view->app_id) { | ||
153 | json_object_object_add(object, "app_id", json_object_new_string(view->app_id)); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | json_object *ipc_json_describe_container(swayc_t *c) { | ||
158 | if (!(sway_assert(c, "Container must not be null."))) { | ||
159 | return NULL; | ||
160 | } | ||
161 | |||
162 | json_object *object = json_object_new_object(); | ||
163 | |||
164 | json_object_object_add(object, "id", json_object_new_int((intptr_t)&c)); | ||
165 | json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); | ||
166 | json_object_object_add(object, "rect", ipc_json_create_rect(c)); | ||
167 | json_object_object_add(object, "visible", json_object_new_boolean(c->visible)); | ||
168 | |||
169 | switch (c->type) { | ||
170 | case C_ROOT: | ||
171 | json_object_object_add(object, "type", json_object_new_string("root")); | ||
172 | break; | ||
173 | |||
174 | case C_OUTPUT: | ||
175 | ipc_json_describe_output(c, object); | ||
176 | break; | ||
177 | |||
178 | case C_CONTAINER: // fallthrough | ||
179 | case C_VIEW: | ||
180 | ipc_json_describe_view(c, object); | ||
181 | break; | ||
182 | |||
183 | case C_WORKSPACE: | ||
184 | ipc_json_describe_workspace(c, object); | ||
185 | break; | ||
186 | |||
187 | case C_TYPES: // fallthrough; this should never happen, I'm just trying to silence compiler warnings | ||
188 | default: | ||
189 | break; | ||
190 | } | ||
191 | |||
192 | return object; | ||
193 | } | ||
194 | |||
195 | // window is in the scratchpad ? changed : none | 135 | // window is in the scratchpad ? changed : none |
196 | static const char *ipc_json_get_scratchpad_state(swayc_t *c) { | 136 | static const char *ipc_json_get_scratchpad_state(swayc_t *c) { |
197 | int i; | 137 | int i; |
@@ -203,14 +143,8 @@ static const char *ipc_json_get_scratchpad_state(swayc_t *c) { | |||
203 | return "none"; // we ignore the fresh value | 143 | return "none"; // we ignore the fresh value |
204 | } | 144 | } |
205 | 145 | ||
206 | // simulate i3, it's probably not a good idea to use it anywhere except window events | 146 | static void ipc_json_describe_view(swayc_t *c, json_object *object) { |
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(); | 147 | json_object *props = json_object_new_object(); |
213 | json_object *arr = json_object_new_array(); | ||
214 | float percent = ipc_json_child_percentage(c); | 148 | float percent = ipc_json_child_percentage(c); |
215 | const char *layout = (c->parent->type == C_CONTAINER) ? | 149 | const char *layout = (c->parent->type == C_CONTAINER) ? |
216 | ipc_json_layout_description(c->parent->layout) : "none"; | 150 | ipc_json_layout_description(c->parent->layout) : "none"; |
@@ -245,22 +179,56 @@ json_object *ipc_json_describe_window(swayc_t *c) { | |||
245 | json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); | 179 | json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); |
246 | 180 | ||
247 | json_object_object_add(object, "window", json_object_new_int(c->handle)); // for the sake of i3 compat | 181 | 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( | 182 | json_object_object_add(props, "class", c->class ? json_object_new_string(c->class) : |
249 | c->class ? c->class : c->app_id ? c->app_id : "null")); | 183 | c->app_id ? json_object_new_string(c->app_id) : NULL); |
250 | json_object_object_add(props, "title", json_object_new_string(c->name)); | 184 | json_object_object_add(props, "title", (c->name) ? json_object_new_string(c->name) : NULL); |
251 | // json_object_object_add(props, "instance", json_object_new_string(c->name)); | 185 | json_object_object_add(props, "transient_for", NULL); // unless sway keeps track of child views |
252 | json_object_object_add(props, "transient_for", NULL); // ditto | ||
253 | json_object_object_add(object, "window_properties", props); | 186 | json_object_object_add(object, "window_properties", props); |
254 | 187 | ||
255 | json_object_object_add(object, "fullscreen_mode", | 188 | json_object_object_add(object, "fullscreen_mode", |
256 | json_object_new_int(swayc_is_fullscreen(c) ? 1 : 0)); | 189 | json_object_new_int(swayc_is_fullscreen(c) ? 1 : 0)); |
257 | json_object_object_add(object, "sticky", json_object_new_boolean(c->sticky)); | 190 | json_object_object_add(object, "sticky", json_object_new_boolean(c->sticky)); |
258 | json_object_object_add(object, "floating", json_object_new_string( | 191 | 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 | 192 | c->is_floating ? "auto_on" : "auto_off")); // unless relevant info is saved |
260 | if (c->app_id) { | 193 | |
261 | json_object_object_add(object, "app_id", json_object_new_string(c->app_id)); | 194 | json_object_object_add(object, "app_id", c->app_id ? json_object_new_string(c->app_id) : NULL); |
195 | // we do not include children, floating, unmanaged etc. as views seem to have none | ||
196 | } | ||
197 | |||
198 | json_object *ipc_json_describe_container(swayc_t *c) { | ||
199 | if (!(sway_assert(c, "Container must not be null."))) { | ||
200 | return NULL; | ||
262 | } | 201 | } |
263 | 202 | ||
203 | json_object *object = json_object_new_object(); | ||
204 | |||
205 | json_object_object_add(object, "id", json_object_new_int((intptr_t)&c)); | ||
206 | json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); | ||
207 | json_object_object_add(object, "rect", ipc_json_create_rect(c)); | ||
208 | json_object_object_add(object, "visible", json_object_new_boolean(c->visible)); | ||
209 | |||
210 | switch (c->type) { | ||
211 | case C_ROOT: | ||
212 | json_object_object_add(object, "type", json_object_new_string("root")); | ||
213 | break; | ||
214 | |||
215 | case C_OUTPUT: | ||
216 | ipc_json_describe_output(c, object); | ||
217 | break; | ||
218 | |||
219 | case C_CONTAINER: // fallthrough | ||
220 | case C_VIEW: | ||
221 | ipc_json_describe_view(c, object); | ||
222 | break; | ||
223 | |||
224 | case C_WORKSPACE: | ||
225 | ipc_json_describe_workspace(c, object); | ||
226 | break; | ||
227 | |||
228 | case C_TYPES: // fallthrough; this should never happen, I'm just trying to silence compiler warnings | ||
229 | default: | ||
230 | break; | ||
231 | } | ||
264 | 232 | ||
265 | return object; | 233 | return object; |
266 | } | 234 | } |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 8110bd41..305b6944 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -566,7 +566,7 @@ void ipc_event_window(swayc_t *window, const char *change) { | |||
566 | if (strcmp(change, "close") == 0 || !window) { | 566 | if (strcmp(change, "close") == 0 || !window) { |
567 | json_object_object_add(obj, "container", NULL); | 567 | json_object_object_add(obj, "container", NULL); |
568 | } else { | 568 | } else { |
569 | json_object_object_add(obj, "container", ipc_json_describe_window(window)); | 569 | json_object_object_add(obj, "container", ipc_json_describe_container(window)); |
570 | } | 570 | } |
571 | 571 | ||
572 | const char *json_string = json_object_to_json_string(obj); | 572 | const char *json_string = json_object_to_json_string(obj); |