aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/bar.c
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-10-12 20:32:48 +0100
committerLibravatar Ian Fan <ianfan0@gmail.com>2018-10-14 13:33:12 +0100
commitbcc61e5147fb57a3b4bfb9a2a33065a0cf6da67b (patch)
tree873a09eca473242c15299ea1053966e9d163f6c6 /swaybar/bar.c
parentswaybar: streamline ipc handling (diff)
downloadsway-bcc61e5147fb57a3b4bfb9a2a33065a0cf6da67b.tar.gz
sway-bcc61e5147fb57a3b4bfb9a2a33065a0cf6da67b.tar.zst
sway-bcc61e5147fb57a3b4bfb9a2a33065a0cf6da67b.zip
swaybar: handle mode/hidden_state changes
As well as adding the hidden_state property to the bar config struct, this commit handles barconfig_update events when the mode or hidden_state changes, and uses a new function determine_bar_visibility to hide or show the bar as required, using, respectively, destroy_layer_surface, which is also newly added, and add_layer_surface, which has been changed to allow dynamically adding the surface.
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c62
1 files changed, 55 insertions, 7 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 77294136..6894383d 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -32,6 +32,7 @@
32 32
33static void bar_init(struct swaybar *bar) { 33static void bar_init(struct swaybar *bar) {
34 bar->config = init_config(); 34 bar->config = init_config();
35 bar->visible = true;
35 wl_list_init(&bar->outputs); 36 wl_list_init(&bar->outputs);
36} 37}
37 38
@@ -338,21 +339,65 @@ const struct wl_seat_listener seat_listener = {
338}; 339};
339 340
340static void add_layer_surface(struct swaybar_output *output) { 341static void add_layer_surface(struct swaybar_output *output) {
341 if (output->surface != NULL) { 342 if (output->layer_surface) {
342 return; 343 return;
343 } 344 }
344 struct swaybar *bar = output->bar; 345 struct swaybar *bar = output->bar;
345 346
346 output->surface = wl_compositor_create_surface(bar->compositor); 347 struct swaybar_config *config = bar->config;
347 assert(output->surface); 348 bool hidden = strcmp(config->mode, "hide") == 0;
348 output->layer_surface = zwlr_layer_shell_v1_get_layer_surface( 349 output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
349 bar->layer_shell, output->surface, output->output, 350 bar->layer_shell, output->surface, output->output,
351 hidden ? ZWLR_LAYER_SHELL_V1_LAYER_TOP :
350 ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel"); 352 ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel");
351 assert(output->layer_surface); 353 assert(output->layer_surface);
352 zwlr_layer_surface_v1_add_listener(output->layer_surface, 354 zwlr_layer_surface_v1_add_listener(output->layer_surface,
353 &layer_surface_listener, output); 355 &layer_surface_listener, output);
354 zwlr_layer_surface_v1_set_anchor(output->layer_surface, 356
355 bar->config->position); 357 zwlr_layer_surface_v1_set_anchor(output->layer_surface, config->position);
358 if (hidden) {
359 zwlr_layer_surface_v1_set_exclusive_zone(output->layer_surface, -1);
360 }
361}
362
363static void destroy_layer_surface(struct swaybar_output *output) {
364 if (!output->layer_surface) {
365 return;
366 }
367 zwlr_layer_surface_v1_destroy(output->layer_surface);
368 wl_surface_attach(output->surface, NULL, 0, 0); // detach buffer
369 output->layer_surface = NULL;
370 output->height = 0;
371 output->width = 0;
372 output->frame_scheduled = false;
373}
374
375bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) {
376 struct swaybar_config *config = bar->config;
377 bool visible = !(strcmp(config->mode, "invisible") == 0 ||
378 (strcmp(config->mode, config->hidden_state) == 0 // both "hide"
379 && !bar->visible_by_modifier && !bar->visible_by_urgency));
380
381 struct swaybar_output *output;
382 if (visible == bar->visible) {
383 if (visible && moving_layer) {
384 // need to destroy layer surface to move to a different layer
385 wl_list_for_each(output, &bar->outputs, link) {
386 destroy_layer_surface(output);
387 add_layer_surface(output);
388 }
389 }
390 } else {
391 bar->visible = visible;
392 wl_list_for_each(output, &bar->outputs, link) {
393 if (visible) {
394 add_layer_surface(output);
395 } else {
396 destroy_layer_surface(output);
397 }
398 }
399 }
400 return visible;
356} 401}
357 402
358static bool bar_uses_output(struct swaybar *bar, const char *name) { 403static bool bar_uses_output(struct swaybar *bar, const char *name) {
@@ -423,8 +468,11 @@ static void xdg_output_handle_done(void *data,
423 wl_list_remove(&output->link); 468 wl_list_remove(&output->link);
424 wl_list_insert(&bar->outputs, &output->link); 469 wl_list_insert(&bar->outputs, &output->link);
425 470
426 add_layer_surface(output); 471 output->surface = wl_compositor_create_surface(bar->compositor);
427 set_output_dirty(output); 472 assert(output->surface);
473 if (bar->visible) {
474 add_layer_surface(output);
475 }
428 } 476 }
429} 477}
430 478