diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-10-21 18:35:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-21 18:35:02 +0200 |
commit | a918844e52a94d949f7db6181263e0186c52eb29 (patch) | |
tree | 4221a3d09fc6b4943b3ac89ad9c2f7147e51a072 | |
parent | Merge pull request #2909 from makepanic/issues/2906 (diff) | |
parent | swaybar: fix hotplug (diff) | |
download | sway-a918844e52a94d949f7db6181263e0186c52eb29.tar.gz sway-a918844e52a94d949f7db6181263e0186c52eb29.tar.zst sway-a918844e52a94d949f7db6181263e0186c52eb29.zip |
Merge pull request #2913 from emersion/fix-swaybar-hotplug
swaybar: fix hotplug
-rw-r--r-- | swaybar/bar.c | 60 |
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 | ||
127 | static 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 | |||
127 | bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) { | 134 | bool 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 | ||
317 | static 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 | |||
324 | bool bar_setup(struct swaybar *bar, const char *socket_path) { | 327 | bool 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 | ||