aboutsummaryrefslogtreecommitdiffstats
path: root/sway/ipc-json.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 16:51:36 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 22:11:08 -0400
commit6836074fed83255438960fdc9597532d8bcae4bd (patch)
treeafc1f5292e934ef012800c6575f7fb8e0e303eee /sway/ipc-json.c
parentFixed laggy focused output boolean (diff)
downloadsway-6836074fed83255438960fdc9597532d8bcae4bd.tar.gz
sway-6836074fed83255438960fdc9597532d8bcae4bd.tar.zst
sway-6836074fed83255438960fdc9597532d8bcae4bd.zip
Implement enough IPC for swaybar to work
Diffstat (limited to 'sway/ipc-json.c')
-rw-r--r--sway/ipc-json.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 977f1ecb..24e41581 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -9,6 +9,7 @@
9#include "sway/input/seat.h" 9#include "sway/input/seat.h"
10#include <wlr/types/wlr_box.h> 10#include <wlr/types/wlr_box.h>
11#include <wlr/types/wlr_output.h> 11#include <wlr/types/wlr_output.h>
12#include "wlr-layer-shell-unstable-v1-protocol.h"
12 13
13json_object *ipc_json_get_version() { 14json_object *ipc_json_get_version() {
14 int major = 0, minor = 0, patch = 0; 15 int major = 0, minor = 0, patch = 0;
@@ -198,3 +199,136 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) {
198 199
199 return object; 200 return object;
200} 201}
202
203json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
204 if (!sway_assert(bar, "Bar must not be NULL")) {
205 return NULL;
206 }
207
208 json_object *json = json_object_new_object();
209 json_object_object_add(json, "id", json_object_new_string(bar->id));
210 json_object_object_add(json, "mode", json_object_new_string(bar->mode));
211 json_object_object_add(json, "hidden_state",
212 json_object_new_string(bar->hidden_state));
213 json_object_object_add(json, "position",
214 json_object_new_string(bar->position));
215 json_object_object_add(json, "status_command",
216 json_object_new_string(bar->status_command));
217 json_object_object_add(json, "font",
218 json_object_new_string((bar->font) ? bar->font : config->font));
219 if (bar->separator_symbol) {
220 json_object_object_add(json, "separator_symbol",
221 json_object_new_string(bar->separator_symbol));
222 }
223 json_object_object_add(json, "bar_height",
224 json_object_new_int(bar->height));
225 json_object_object_add(json, "wrap_scroll",
226 json_object_new_boolean(bar->wrap_scroll));
227 json_object_object_add(json, "workspace_buttons",
228 json_object_new_boolean(bar->workspace_buttons));
229 json_object_object_add(json, "strip_workspace_numbers",
230 json_object_new_boolean(bar->strip_workspace_numbers));
231 json_object_object_add(json, "binding_mode_indicator",
232 json_object_new_boolean(bar->binding_mode_indicator));
233 json_object_object_add(json, "verbose",
234 json_object_new_boolean(bar->verbose));
235 json_object_object_add(json, "pango_markup",
236 json_object_new_boolean(bar->pango_markup));
237
238 json_object *colors = json_object_new_object();
239 json_object_object_add(colors, "background",
240 json_object_new_string(bar->colors.background));
241 json_object_object_add(colors, "statusline",
242 json_object_new_string(bar->colors.statusline));
243 json_object_object_add(colors, "separator",
244 json_object_new_string(bar->colors.separator));
245
246 if (bar->colors.focused_background) {
247 json_object_object_add(colors, "focused_background",
248 json_object_new_string(bar->colors.focused_background));
249 } else {
250 json_object_object_add(colors, "focused_background",
251 json_object_new_string(bar->colors.background));
252 }
253
254 if (bar->colors.focused_statusline) {
255 json_object_object_add(colors, "focused_statusline",
256 json_object_new_string(bar->colors.focused_statusline));
257 } else {
258 json_object_object_add(colors, "focused_statusline",
259 json_object_new_string(bar->colors.statusline));
260 }
261
262 if (bar->colors.focused_separator) {
263 json_object_object_add(colors, "focused_separator",
264 json_object_new_string(bar->colors.focused_separator));
265 } else {
266 json_object_object_add(colors, "focused_separator",
267 json_object_new_string(bar->colors.separator));
268 }
269
270 json_object_object_add(colors, "focused_workspace_border",
271 json_object_new_string(bar->colors.focused_workspace_border));
272 json_object_object_add(colors, "focused_workspace_bg",
273 json_object_new_string(bar->colors.focused_workspace_bg));
274 json_object_object_add(colors, "focused_workspace_text",
275 json_object_new_string(bar->colors.focused_workspace_text));
276
277 json_object_object_add(colors, "inactive_workspace_border",
278 json_object_new_string(bar->colors.inactive_workspace_border));
279 json_object_object_add(colors, "inactive_workspace_bg",
280 json_object_new_string(bar->colors.inactive_workspace_bg));
281 json_object_object_add(colors, "inactive_workspace_text",
282 json_object_new_string(bar->colors.inactive_workspace_text));
283
284 json_object_object_add(colors, "active_workspace_border",
285 json_object_new_string(bar->colors.active_workspace_border));
286 json_object_object_add(colors, "active_workspace_bg",
287 json_object_new_string(bar->colors.active_workspace_bg));
288 json_object_object_add(colors, "active_workspace_text",
289 json_object_new_string(bar->colors.active_workspace_text));
290
291 json_object_object_add(colors, "urgent_workspace_border",
292 json_object_new_string(bar->colors.urgent_workspace_border));
293 json_object_object_add(colors, "urgent_workspace_bg",
294 json_object_new_string(bar->colors.urgent_workspace_bg));
295 json_object_object_add(colors, "urgent_workspace_text",
296 json_object_new_string(bar->colors.urgent_workspace_text));
297
298 if (bar->colors.binding_mode_border) {
299 json_object_object_add(colors, "binding_mode_border",
300 json_object_new_string(bar->colors.binding_mode_border));
301 } else {
302 json_object_object_add(colors, "binding_mode_border",
303 json_object_new_string(bar->colors.urgent_workspace_border));
304 }
305
306 if (bar->colors.binding_mode_bg) {
307 json_object_object_add(colors, "binding_mode_bg",
308 json_object_new_string(bar->colors.binding_mode_bg));
309 } else {
310 json_object_object_add(colors, "binding_mode_bg",
311 json_object_new_string(bar->colors.urgent_workspace_bg));
312 }
313
314 if (bar->colors.binding_mode_text) {
315 json_object_object_add(colors, "binding_mode_text",
316 json_object_new_string(bar->colors.binding_mode_text));
317 } else {
318 json_object_object_add(colors, "binding_mode_text",
319 json_object_new_string(bar->colors.urgent_workspace_text));
320 }
321
322 json_object_object_add(json, "colors", colors);
323
324 // Add outputs if defined
325 if (bar->outputs && bar->outputs->length > 0) {
326 json_object *outputs = json_object_new_array();
327 for (int i = 0; i < bar->outputs->length; ++i) {
328 const char *name = bar->outputs->items[i];
329 json_object_array_add(outputs, json_object_new_string(name));
330 }
331 json_object_object_add(json, "outputs", outputs);
332 }
333 return json;
334}