aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/main.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-12-15 22:22:22 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-12-15 22:22:22 -0500
commit473ac4531fdd954764f7199792b09fe28f62ff36 (patch)
tree8d161b41282218eff59f8081d95092ef97158460 /swaybar/main.c
parentParse command line in swaybar (diff)
downloadsway-473ac4531fdd954764f7199792b09fe28f62ff36.tar.gz
sway-473ac4531fdd954764f7199792b09fe28f62ff36.tar.zst
sway-473ac4531fdd954764f7199792b09fe28f62ff36.zip
[swaybar] Get bar config via IPC
Diffstat (limited to 'swaybar/main.c')
-rw-r--r--swaybar/main.c58
1 files changed, 41 insertions, 17 deletions
diff --git a/swaybar/main.c b/swaybar/main.c
index 79635de1..5a16be93 100644
--- a/swaybar/main.c
+++ b/swaybar/main.c
@@ -48,7 +48,7 @@ struct workspace {
48list_t *workspaces = NULL; 48list_t *workspaces = NULL;
49int socketfd; 49int socketfd;
50FILE *command; 50FILE *command;
51char *line, *output; 51char *line, *output, *status_command;
52struct registry *registry; 52struct registry *registry;
53struct window *window; 53struct window *window;
54 54
@@ -143,7 +143,7 @@ void ipc_update_workspaces() {
143 free(res); 143 free(res);
144} 144}
145 145
146void bar_ipc_init(int outputi) { 146void bar_ipc_init(int outputi, const char *bar_id) {
147 uint32_t len = 0; 147 uint32_t len = 0;
148 char *res = ipc_single_command(socketfd, IPC_GET_OUTPUTS, NULL, &len); 148 char *res = ipc_single_command(socketfd, IPC_GET_OUTPUTS, NULL, &len);
149 json_object *outputs = json_tokener_parse(res); 149 json_object *outputs = json_tokener_parse(res);
@@ -155,6 +155,29 @@ void bar_ipc_init(int outputi) {
155 json_object_put(outputs); 155 json_object_put(outputs);
156 sway_log(L_INFO, "Running on output %s", output); 156 sway_log(L_INFO, "Running on output %s", output);
157 157
158 len = strlen(bar_id);
159 res = ipc_single_command(socketfd, IPC_GET_BAR_CONFIG, bar_id, &len);
160
161 json_object *bar_config = json_tokener_parse(res);
162 json_object *tray_output, *mode, *hidden_state, *position, *_status_command;
163 json_object *font, *bar_height, *workspace_buttons, *strip_workspace_numbers;
164 json_object *binding_mode_indicator, *verbose, *colors;
165 json_object_object_get_ex(bar_config, "tray_output", &tray_output);
166 json_object_object_get_ex(bar_config, "mode", &mode);
167 json_object_object_get_ex(bar_config, "hidden_state", &hidden_state);
168 json_object_object_get_ex(bar_config, "position", &position);
169 json_object_object_get_ex(bar_config, "status_command", &_status_command);
170 json_object_object_get_ex(bar_config, "font", &font);
171 json_object_object_get_ex(bar_config, "bar_height", &bar_height);
172 json_object_object_get_ex(bar_config, "workspace_buttons", &workspace_buttons);
173 json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers);
174 json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator);
175 json_object_object_get_ex(bar_config, "verbose", &verbose);
176 json_object_object_get_ex(bar_config, "colors", &colors);
177 if (_status_command) status_command = strdup(json_object_get_string(_status_command));
178 json_object_put(bar_config);
179 free(res);
180
158 const char *subscribe_json = "[ \"workspace\" ]"; 181 const char *subscribe_json = "[ \"workspace\" ]";
159 len = strlen(subscribe_json); 182 len = strlen(subscribe_json);
160 res = ipc_single_command(socketfd, IPC_SUBSCRIBE, subscribe_json, &len); 183 res = ipc_single_command(socketfd, IPC_SUBSCRIBE, subscribe_json, &len);
@@ -281,10 +304,24 @@ int main(int argc, char **argv) {
281 sway_abort("swaybar requires the compositor to support the desktop-shell extension."); 304 sway_abort("swaybar requires the compositor to support the desktop-shell extension.");
282 } 305 }
283 306
284 int desired_output = atoi(argv[1]); 307 if (!socket_path) {
285 sway_log(L_INFO, "Using output %d of %d", desired_output, registry->outputs->length); 308 socket_path = get_socketpath();
309 if (!socket_path) {
310 sway_abort("Unable to retrieve socket path");
311 }
312 }
313 socketfd = ipc_open_socket(socket_path);
286 314
315 int desired_output = atoi(argv[optind]);
316 sway_log(L_INFO, "Using output %d of %d", desired_output, registry->outputs->length);
287 struct output_state *output = registry->outputs->items[desired_output]; 317 struct output_state *output = registry->outputs->items[desired_output];
318
319 bar_ipc_init(desired_output, bar_id);
320
321 command = popen(status_command, "r");
322 line = malloc(1024);
323 line[0] = '\0';
324
288 window = window_setup(registry, output->width, 30, false); 325 window = window_setup(registry, output->width, 30, false);
289 if (!window) { 326 if (!window) {
290 sway_abort("Failed to create window."); 327 sway_abort("Failed to create window.");
@@ -296,19 +333,6 @@ int main(int argc, char **argv) {
296 get_text_size(window, &width, &height, "Test string for measuring purposes"); 333 get_text_size(window, &width, &height, "Test string for measuring purposes");
297 window->height = height + MARGIN * 2; 334 window->height = height + MARGIN * 2;
298 335
299 command = popen(argv[2], "r");
300 line = malloc(1024);
301 line[0] = '\0';
302
303 if (!socket_path) {
304 char *socket_path = get_socketpath();
305 if (!socket_path) {
306 sway_abort("Unable to retrieve socket path");
307 }
308 }
309 socketfd = ipc_open_socket(socket_path);
310 bar_ipc_init(desired_output);
311
312 do { 336 do {
313 if (window_prerender(window) && window->cairo) { 337 if (window_prerender(window) && window->cairo) {
314 update(); 338 update();