diff options
Diffstat (limited to 'sway/ipc-json.c')
-rw-r--r-- | sway/ipc-json.c | 87 |
1 files changed, 70 insertions, 17 deletions
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) { |