swaybar: implement tray config

This commit is contained in:
Ian Fan 2018-12-09 15:10:41 +00:00
parent 74655f835a
commit 6b03c68775
18 changed files with 271 additions and 55 deletions

View file

@ -1,6 +1,7 @@
#include <json-c/json.h>
#include <stdio.h>
#include <ctype.h>
#include "config.h"
#include "log.h"
#include "sway/config.h"
#include "sway/ipc-json.h"
@ -785,5 +786,41 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
}
json_object_object_add(json, "outputs", outputs);
}
#if HAVE_TRAY
// Add tray outputs if defined
if (bar->tray_outputs && bar->tray_outputs->length > 0) {
json_object *tray_outputs = json_object_new_array();
for (int i = 0; i < bar->tray_outputs->length; ++i) {
const char *name = bar->tray_outputs->items[i];
json_object_array_add(tray_outputs, json_object_new_string(name));
}
json_object_object_add(json, "tray_outputs", tray_outputs);
}
json_object *tray_bindings = json_object_new_array();
for (int i = 0; i < 10; ++i) {
if (bar->tray_bindings[i]) {
json_object *bind = json_object_new_object();
json_object_object_add(bind, "input_code",
json_object_new_int(i));
json_object_object_add(bind, "command",
json_object_new_string(bar->tray_bindings[i]));
json_object_array_add(tray_bindings, bind);
}
}
if (json_object_array_length(tray_bindings) > 0) {
json_object_object_add(json, "tray_bindings", tray_bindings);
} else {
json_object_put(tray_bindings);
}
if (bar->icon_theme) {
json_object_object_add(json, "icon_theme",
json_object_new_string(bar->icon_theme));
}
json_object_object_add(json, "tray_padding",
json_object_new_int(bar->tray_padding));
#endif
return json;
}