aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/bar.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-10-21 17:46:40 +0200
committerLibravatar emersion <contact@emersion.fr>2018-10-21 17:46:40 +0200
commit2a32701b78ac6a6bbba5f6ae64f92c0a22e2df60 (patch)
treeb80233e6dc6c4f6b0e81febb9f403a0d9a132cec /swaybar/bar.c
parentMerge pull request #2901 from ianyfan/swaybar (diff)
downloadsway-2a32701b78ac6a6bbba5f6ae64f92c0a22e2df60.tar.gz
sway-2a32701b78ac6a6bbba5f6ae64f92c0a22e2df60.tar.zst
sway-2a32701b78ac6a6bbba5f6ae64f92c0a22e2df60.zip
swaybar: fix hotplug
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 71aff691..a34e4ad5 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -124,35 +124,43 @@ static void destroy_layer_surface(struct swaybar_output *output) {
124 output->frame_scheduled = false; 124 output->frame_scheduled = false;
125} 125}
126 126
127static void set_bar_dirty(struct swaybar *bar) {
128 struct swaybar_output *output;
129 wl_list_for_each(output, &bar->outputs, link) {
130 set_output_dirty(output);
131 }
132}
133
127bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) { 134bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) {
128 struct swaybar_config *config = bar->config; 135 struct swaybar_config *config = bar->config;
129 bool visible = !(strcmp(config->mode, "invisible") == 0 || 136 bool visible = !(strcmp(config->mode, "invisible") == 0 ||
130 (strcmp(config->mode, config->hidden_state) == 0 // both "hide" 137 (strcmp(config->mode, config->hidden_state) == 0 // both "hide"
131 && !bar->visible_by_modifier && !bar->visible_by_urgency)); 138 && !bar->visible_by_modifier && !bar->visible_by_urgency));
132 139
140 // Create/destroy layer surfaces as needed
133 struct swaybar_output *output; 141 struct swaybar_output *output;
134 if (visible == bar->visible) { 142 wl_list_for_each(output, &bar->outputs, link) {
135 if (visible && moving_layer) { 143 // When moving to a different layer, we need to destroy and re-create
136 // need to destroy layer surface to move to a different layer 144 // the layer surface
137 wl_list_for_each(output, &bar->outputs, link) { 145 if (!visible || moving_layer) {
138 destroy_layer_surface(output); 146 destroy_layer_surface(output);
139 add_layer_surface(output);
140 }
141 } 147 }
142 } else { 148
143 bar->visible = visible; 149 if (visible) {
144 wl_list_for_each(output, &bar->outputs, link) { 150 add_layer_surface(output);
145 if (visible) {
146 add_layer_surface(output);
147 } else {
148 destroy_layer_surface(output);
149 }
150 } 151 }
152 }
153 set_bar_dirty(bar);
154
155 if (visible != bar->visible) {
156 bar->visible = visible;
157
151 wlr_log(WLR_DEBUG, "Sending %s signal to status command", 158 wlr_log(WLR_DEBUG, "Sending %s signal to status command",
152 visible ? "cont" : "stop"); 159 visible ? "cont" : "stop");
153 kill(bar->status->pid, 160 kill(bar->status->pid,
154 visible ? bar->status->cont_signal : bar->status->stop_signal); 161 visible ? bar->status->cont_signal : bar->status->stop_signal);
155 } 162 }
163
156 return visible; 164 return visible;
157} 165}
158 166
@@ -226,6 +234,8 @@ static void xdg_output_handle_done(void *data,
226 234
227 output->surface = wl_compositor_create_surface(bar->compositor); 235 output->surface = wl_compositor_create_surface(bar->compositor);
228 assert(output->surface); 236 assert(output->surface);
237
238 determine_bar_visibility(bar, false);
229 } 239 }
230} 240}
231 241
@@ -314,13 +324,6 @@ static const struct wl_registry_listener registry_listener = {
314 .global_remove = handle_global_remove, 324 .global_remove = handle_global_remove,
315}; 325};
316 326
317static void set_bar_dirty(struct swaybar *bar) {
318 struct swaybar_output *output;
319 wl_list_for_each(output, &bar->outputs, link) {
320 set_output_dirty(output);
321 }
322}
323
324bool bar_setup(struct swaybar *bar, const char *socket_path) { 327bool bar_setup(struct swaybar *bar, const char *socket_path) {
325 bar_init(bar); 328 bar_init(bar);
326 bar->eventloop = loop_create(); 329 bar->eventloop = loop_create();
@@ -348,15 +351,13 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
348 assert(bar->compositor && bar->layer_shell && bar->shm && 351 assert(bar->compositor && bar->layer_shell && bar->shm &&
349 bar->xdg_output_manager); 352 bar->xdg_output_manager);
350 353
351 struct swaybar_output *output; 354 // Second roundtrip for xdg-output
352 wl_list_for_each(output, &bar->outputs, link) {
353 add_xdg_output(output);
354 }
355 wl_display_roundtrip(bar->display); 355 wl_display_roundtrip(bar->display);
356 356
357 struct swaybar_pointer *pointer = &bar->pointer; 357 struct swaybar_pointer *pointer = &bar->pointer;
358 358
359 int max_scale = 1; 359 int max_scale = 1;
360 struct swaybar_output *output;
360 wl_list_for_each(output, &bar->outputs, link) { 361 wl_list_for_each(output, &bar->outputs, link) {
361 if (output->scale > max_scale) { 362 if (output->scale > max_scale) {
362 max_scale = output->scale; 363 max_scale = output->scale;
@@ -377,12 +378,7 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
377 if (bar->config->workspace_buttons) { 378 if (bar->config->workspace_buttons) {
378 ipc_get_workspaces(bar); 379 ipc_get_workspaces(bar);
379 } 380 }
380 if (determine_bar_visibility(bar, false)) { 381 determine_bar_visibility(bar, false);
381 wl_list_for_each(output, &bar->outputs, link) {
382 add_layer_surface(output);
383 }
384 set_bar_dirty(bar);
385 }
386 return true; 382 return true;
387} 383}
388 384