diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-04-10 13:38:15 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-04-10 13:38:15 +1000 |
commit | c38de1672255e9906623c133598ac7fded10640a (patch) | |
tree | fe82ad7c34fe764fd5419f1d1789a5b3ea08c4b4 /swaybar | |
parent | Merge pull request #1788 from thejan2009/move_auto_back_and_forth (diff) | |
download | sway-c38de1672255e9906623c133598ac7fded10640a.tar.gz sway-c38de1672255e9906623c133598ac7fded10640a.tar.zst sway-c38de1672255e9906623c133598ac7fded10640a.zip |
Fix swaybar output config.
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/bar.c | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index f1a701b9..d51c4ec7 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -264,6 +264,19 @@ struct wl_output_listener output_listener = { | |||
264 | .scale = output_scale, | 264 | .scale = output_scale, |
265 | }; | 265 | }; |
266 | 266 | ||
267 | static bool bar_uses_output(struct swaybar *bar, size_t output_index) { | ||
268 | if (bar->config->all_outputs) { | ||
269 | return true; | ||
270 | } | ||
271 | struct config_output *coutput; | ||
272 | wl_list_for_each(coutput, &bar->config->outputs, link) { | ||
273 | if (coutput->index == output_index) { | ||
274 | return true; | ||
275 | } | ||
276 | } | ||
277 | return false; | ||
278 | } | ||
279 | |||
267 | static void handle_global(void *data, struct wl_registry *registry, | 280 | static void handle_global(void *data, struct wl_registry *registry, |
268 | uint32_t name, const char *interface, uint32_t version) { | 281 | uint32_t name, const char *interface, uint32_t version) { |
269 | struct swaybar *bar = data; | 282 | struct swaybar *bar = data; |
@@ -278,19 +291,22 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
278 | bar->shm = wl_registry_bind(registry, name, | 291 | bar->shm = wl_registry_bind(registry, name, |
279 | &wl_shm_interface, 1); | 292 | &wl_shm_interface, 1); |
280 | } else if (strcmp(interface, wl_output_interface.name) == 0) { | 293 | } else if (strcmp(interface, wl_output_interface.name) == 0) { |
281 | static size_t index = 0; | 294 | static size_t output_index = 0; |
282 | struct swaybar_output *output = | 295 | if (bar_uses_output(bar, output_index)) { |
283 | calloc(1, sizeof(struct swaybar_output)); | 296 | struct swaybar_output *output = |
284 | output->bar = bar; | 297 | calloc(1, sizeof(struct swaybar_output)); |
285 | output->output = wl_registry_bind(registry, name, | 298 | output->bar = bar; |
286 | &wl_output_interface, 3); | 299 | output->output = wl_registry_bind(registry, name, |
287 | wl_output_add_listener(output->output, &output_listener, output); | 300 | &wl_output_interface, 3); |
288 | output->scale = 1; | 301 | wl_output_add_listener(output->output, &output_listener, output); |
289 | output->index = index++; | 302 | output->scale = 1; |
290 | output->wl_name = name; | 303 | output->index = output_index; |
291 | wl_list_init(&output->workspaces); | 304 | output->wl_name = name; |
292 | wl_list_init(&output->hotspots); | 305 | wl_list_init(&output->workspaces); |
293 | wl_list_insert(&bar->outputs, &output->link); | 306 | wl_list_init(&output->hotspots); |
307 | wl_list_insert(&bar->outputs, &output->link); | ||
308 | } | ||
309 | ++output_index; | ||
294 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { | 310 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { |
295 | bar->layer_shell = wl_registry_bind( | 311 | bar->layer_shell = wl_registry_bind( |
296 | registry, name, &zwlr_layer_shell_v1_interface, 1); | 312 | registry, name, &zwlr_layer_shell_v1_interface, 1); |
@@ -362,26 +378,24 @@ void bar_setup(struct swaybar *bar, | |||
362 | pointer->cursor_surface = wl_compositor_create_surface(bar->compositor); | 378 | pointer->cursor_surface = wl_compositor_create_surface(bar->compositor); |
363 | assert(pointer->cursor_surface); | 379 | assert(pointer->cursor_surface); |
364 | 380 | ||
365 | // TODO: we might not necessarily be meant to do all of the outputs | ||
366 | wl_list_for_each(output, &bar->outputs, link) { | 381 | wl_list_for_each(output, &bar->outputs, link) { |
367 | struct config_output *coutput; | 382 | struct config_output *coutput; |
368 | wl_list_for_each(coutput, &bar->config->outputs, link) { | 383 | wl_list_for_each(coutput, &bar->config->outputs, link) { |
369 | if (coutput->index != output->index) { | 384 | if (coutput->index == output->index) { |
370 | continue; | 385 | output->name = strdup(coutput->name); |
386 | break; | ||
371 | } | 387 | } |
372 | output->name = strdup(coutput->name); | ||
373 | output->surface = wl_compositor_create_surface(bar->compositor); | ||
374 | assert(output->surface); | ||
375 | output->layer_surface = zwlr_layer_shell_v1_get_layer_surface( | ||
376 | bar->layer_shell, output->surface, output->output, | ||
377 | ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel"); | ||
378 | assert(output->layer_surface); | ||
379 | zwlr_layer_surface_v1_add_listener(output->layer_surface, | ||
380 | &layer_surface_listener, output); | ||
381 | zwlr_layer_surface_v1_set_anchor(output->layer_surface, | ||
382 | bar->config->position); | ||
383 | break; | ||
384 | } | 388 | } |
389 | output->surface = wl_compositor_create_surface(bar->compositor); | ||
390 | assert(output->surface); | ||
391 | output->layer_surface = zwlr_layer_shell_v1_get_layer_surface( | ||
392 | bar->layer_shell, output->surface, output->output, | ||
393 | ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel"); | ||
394 | assert(output->layer_surface); | ||
395 | zwlr_layer_surface_v1_add_listener(output->layer_surface, | ||
396 | &layer_surface_listener, output); | ||
397 | zwlr_layer_surface_v1_set_anchor(output->layer_surface, | ||
398 | bar->config->position); | ||
385 | } | 399 | } |
386 | ipc_get_workspaces(bar); | 400 | ipc_get_workspaces(bar); |
387 | render_all_frames(bar); | 401 | render_all_frames(bar); |