aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/bar.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-09-02 21:41:11 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-09-04 16:48:50 -1000
commit1fd2c6ba498e61f4fe823bf552f9d2fce8612de4 (patch)
tree8e2d9adab3451f1f05c76340d466a442c840e558 /swaybar/bar.c
parentseatop_default: only focus container on press (diff)
downloadsway-1fd2c6ba498e61f4fe823bf552f9d2fce8612de4.tar.gz
sway-1fd2c6ba498e61f4fe823bf552f9d2fce8612de4.tar.zst
sway-1fd2c6ba498e61f4fe823bf552f9d2fce8612de4.zip
swaybar: complete barconfig_update event handling
This adds complete support for the barconfig_update ipc event. This also changes the bar command and subcommand handlers to correctly emit the event. This makes it so all bar subcommands other than id and swaybar_command are dynamically changeable at runtime. sway-bar.5 has been updated accordingly
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 35e1662b..efd0da4b 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -126,7 +126,7 @@ static void add_layer_surface(struct swaybar_output *output) {
126 } 126 }
127} 127}
128 128
129static void destroy_layer_surface(struct swaybar_output *output) { 129void destroy_layer_surface(struct swaybar_output *output) {
130 if (!output->layer_surface) { 130 if (!output->layer_surface) {
131 return; 131 return;
132 } 132 }
@@ -181,7 +181,7 @@ bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) {
181} 181}
182 182
183static bool bar_uses_output(struct swaybar_output *output) { 183static bool bar_uses_output(struct swaybar_output *output) {
184 if (output->bar->config->all_outputs) { 184 if (wl_list_empty(&output->bar->config->outputs)) {
185 return true; 185 return true;
186 } 186 }
187 char *identifier = output->identifier; 187 char *identifier = output->identifier;
@@ -256,20 +256,27 @@ static void xdg_output_handle_done(void *data,
256 struct swaybar_output *output = data; 256 struct swaybar_output *output = data;
257 struct swaybar *bar = output->bar; 257 struct swaybar *bar = output->bar;
258 258
259 if (!wl_list_empty(&output->link)) {
260 return;
261 }
262
259 assert(output->name != NULL); 263 assert(output->name != NULL);
260 if (!bar_uses_output(output)) { 264 if (!bar_uses_output(output)) {
261 swaybar_output_free(output); 265 wl_list_remove(&output->link);
266 wl_list_insert(&bar->unused_outputs, &output->link);
262 return; 267 return;
263 } 268 }
264 269
265 if (wl_list_empty(&output->link)) { 270 wl_list_remove(&output->link);
266 wl_list_remove(&output->link); 271 wl_list_insert(&bar->outputs, &output->link);
267 wl_list_insert(&bar->outputs, &output->link);
268 272
269 output->surface = wl_compositor_create_surface(bar->compositor); 273 output->surface = wl_compositor_create_surface(bar->compositor);
270 assert(output->surface); 274 assert(output->surface);
271 275
272 determine_bar_visibility(bar, false); 276 determine_bar_visibility(bar, false);
277
278 if (bar->running && bar->config->workspace_buttons) {
279 ipc_get_workspaces(bar);
273 } 280 }
274} 281}
275 282
@@ -373,6 +380,12 @@ static void handle_global_remove(void *data, struct wl_registry *registry,
373 return; 380 return;
374 } 381 }
375 } 382 }
383 wl_list_for_each_safe(output, tmp, &bar->unused_outputs, link) {
384 if (output->wl_name == name) {
385 swaybar_output_free(output);
386 return;
387 }
388 }
376 struct swaybar_seat *seat, *tmp_seat; 389 struct swaybar_seat *seat, *tmp_seat;
377 wl_list_for_each_safe(seat, tmp_seat, &bar->seats, link) { 390 wl_list_for_each_safe(seat, tmp_seat, &bar->seats, link) {
378 if (seat->wl_name == name) { 391 if (seat->wl_name == name) {
@@ -391,6 +404,7 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
391 bar->visible = true; 404 bar->visible = true;
392 bar->config = init_config(); 405 bar->config = init_config();
393 wl_list_init(&bar->outputs); 406 wl_list_init(&bar->outputs);
407 wl_list_init(&bar->unused_outputs);
394 wl_list_init(&bar->seats); 408 wl_list_init(&bar->seats);
395 bar->eventloop = loop_create(); 409 bar->eventloop = loop_create();
396 410
@@ -458,7 +472,7 @@ static void ipc_in(int fd, short mask, void *data) {
458 } 472 }
459} 473}
460 474
461static void status_in(int fd, short mask, void *data) { 475void status_in(int fd, short mask, void *data) {
462 struct swaybar *bar = data; 476 struct swaybar *bar = data;
463 if (mask & (POLLHUP | POLLERR)) { 477 if (mask & (POLLHUP | POLLERR)) {
464 status_error(bar->status, "[error reading from status command]"); 478 status_error(bar->status, "[error reading from status command]");
@@ -510,6 +524,7 @@ void bar_teardown(struct swaybar *bar) {
510 destroy_tray(bar->tray); 524 destroy_tray(bar->tray);
511#endif 525#endif
512 free_outputs(&bar->outputs); 526 free_outputs(&bar->outputs);
527 free_outputs(&bar->unused_outputs);
513 free_seats(&bar->seats); 528 free_seats(&bar->seats);
514 if (bar->config) { 529 if (bar->config) {
515 free_config(bar->config); 530 free_config(bar->config);