diff options
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/bar.c | 103 |
1 files changed, 74 insertions, 29 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index 62a7727e..3ae730f7 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "log.h" | 27 | #include "log.h" |
28 | #include "pool-buffer.h" | 28 | #include "pool-buffer.h" |
29 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 29 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
30 | #include "xdg-output-unstable-v1-client-protocol.h" | ||
30 | 31 | ||
31 | static void bar_init(struct swaybar *bar) { | 32 | static void bar_init(struct swaybar *bar) { |
32 | bar->config = init_config(); | 33 | bar->config = init_config(); |
@@ -313,13 +314,48 @@ struct wl_output_listener output_listener = { | |||
313 | .scale = output_scale, | 314 | .scale = output_scale, |
314 | }; | 315 | }; |
315 | 316 | ||
316 | static bool bar_uses_output(struct swaybar *bar, size_t output_index) { | 317 | static void xdg_output_handle_logical_position(void *data, |
318 | struct zxdg_output_v1 *xdg_output, int32_t x, int32_t y) { | ||
319 | // Who cares | ||
320 | } | ||
321 | |||
322 | static void xdg_output_handle_logical_size(void *data, | ||
323 | struct zxdg_output_v1 *xdg_output, int32_t width, int32_t height) { | ||
324 | // Who cares | ||
325 | } | ||
326 | |||
327 | static void xdg_output_handle_done(void *data, | ||
328 | struct zxdg_output_v1 *xdg_output) { | ||
329 | // Who cares | ||
330 | } | ||
331 | |||
332 | static void xdg_output_handle_name(void *data, | ||
333 | struct zxdg_output_v1 *xdg_output, const char *name) { | ||
334 | struct swaybar_output *output = data; | ||
335 | free(output->name); | ||
336 | output->name = strdup(name); | ||
337 | } | ||
338 | |||
339 | static void xdg_output_handle_description(void *data, | ||
340 | struct zxdg_output_v1 *xdg_output, const char *description) { | ||
341 | // Who cares | ||
342 | } | ||
343 | |||
344 | struct zxdg_output_v1_listener xdg_output_listener = { | ||
345 | .logical_position = xdg_output_handle_logical_position, | ||
346 | .logical_size = xdg_output_handle_logical_size, | ||
347 | .done = xdg_output_handle_done, | ||
348 | .name = xdg_output_handle_name, | ||
349 | .description = xdg_output_handle_description, | ||
350 | }; | ||
351 | |||
352 | static bool bar_uses_output(struct swaybar *bar, const char *name) { | ||
317 | if (bar->config->all_outputs) { | 353 | if (bar->config->all_outputs) { |
318 | return true; | 354 | return true; |
319 | } | 355 | } |
320 | struct config_output *coutput; | 356 | struct config_output *coutput; |
321 | wl_list_for_each(coutput, &bar->config->outputs, link) { | 357 | wl_list_for_each(coutput, &bar->config->outputs, link) { |
322 | if (coutput->index == output_index) { | 358 | if (strcmp(coutput->name, name) == 0) { |
323 | return true; | 359 | return true; |
324 | } | 360 | } |
325 | } | 361 | } |
@@ -340,25 +376,23 @@ static void handle_global(void *data, struct wl_registry *registry, | |||
340 | bar->shm = wl_registry_bind(registry, name, | 376 | bar->shm = wl_registry_bind(registry, name, |
341 | &wl_shm_interface, 1); | 377 | &wl_shm_interface, 1); |
342 | } else if (strcmp(interface, wl_output_interface.name) == 0) { | 378 | } else if (strcmp(interface, wl_output_interface.name) == 0) { |
343 | static size_t output_index = 0; | 379 | struct swaybar_output *output = |
344 | if (bar_uses_output(bar, output_index)) { | 380 | calloc(1, sizeof(struct swaybar_output)); |
345 | struct swaybar_output *output = | 381 | output->bar = bar; |
346 | calloc(1, sizeof(struct swaybar_output)); | 382 | output->output = wl_registry_bind(registry, name, |
347 | output->bar = bar; | 383 | &wl_output_interface, 3); |
348 | output->output = wl_registry_bind(registry, name, | 384 | wl_output_add_listener(output->output, &output_listener, output); |
349 | &wl_output_interface, 3); | 385 | output->scale = 1; |
350 | wl_output_add_listener(output->output, &output_listener, output); | 386 | output->wl_name = name; |
351 | output->scale = 1; | 387 | wl_list_init(&output->workspaces); |
352 | output->index = output_index; | 388 | wl_list_init(&output->hotspots); |
353 | output->wl_name = name; | 389 | wl_list_insert(&bar->outputs, &output->link); |
354 | wl_list_init(&output->workspaces); | ||
355 | wl_list_init(&output->hotspots); | ||
356 | wl_list_insert(&bar->outputs, &output->link); | ||
357 | } | ||
358 | ++output_index; | ||
359 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { | 390 | } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { |
360 | bar->layer_shell = wl_registry_bind( | 391 | bar->layer_shell = wl_registry_bind( |
361 | registry, name, &zwlr_layer_shell_v1_interface, 1); | 392 | registry, name, &zwlr_layer_shell_v1_interface, 1); |
393 | } else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) { | ||
394 | bar->xdg_output_manager = wl_registry_bind(registry, name, | ||
395 | &zxdg_output_manager_v1_interface, 2); | ||
362 | } | 396 | } |
363 | } | 397 | } |
364 | 398 | ||
@@ -404,21 +438,39 @@ void bar_setup(struct swaybar *bar, | |||
404 | struct wl_registry *registry = wl_display_get_registry(bar->display); | 438 | struct wl_registry *registry = wl_display_get_registry(bar->display); |
405 | wl_registry_add_listener(registry, ®istry_listener, bar); | 439 | wl_registry_add_listener(registry, ®istry_listener, bar); |
406 | wl_display_roundtrip(bar->display); | 440 | wl_display_roundtrip(bar->display); |
407 | assert(bar->compositor && bar->layer_shell && bar->shm); | 441 | assert(bar->compositor && bar->layer_shell && bar->shm && |
442 | bar->xdg_output_manager); | ||
443 | |||
444 | struct swaybar_output *output; | ||
445 | wl_list_for_each(output, &bar->outputs, link) { | ||
446 | output->xdg_output = zxdg_output_manager_v1_get_xdg_output( | ||
447 | bar->xdg_output_manager, output->output); | ||
448 | zxdg_output_v1_add_listener(output->xdg_output, &xdg_output_listener, | ||
449 | output); | ||
450 | } | ||
408 | wl_display_roundtrip(bar->display); | 451 | wl_display_roundtrip(bar->display); |
409 | 452 | ||
453 | struct swaybar_output *output_tmp; | ||
454 | wl_list_for_each_safe(output, output_tmp, &bar->outputs, link) { | ||
455 | if (!bar_uses_output(bar, output->name)) { | ||
456 | zxdg_output_v1_destroy(output->xdg_output); | ||
457 | wl_output_destroy(output->output); | ||
458 | wl_list_remove(&output->link); | ||
459 | free(output); | ||
460 | } | ||
461 | } | ||
462 | |||
410 | struct swaybar_pointer *pointer = &bar->pointer; | 463 | struct swaybar_pointer *pointer = &bar->pointer; |
411 | 464 | ||
412 | int max_scale = 1; | 465 | int max_scale = 1; |
413 | struct swaybar_output *output; | ||
414 | wl_list_for_each(output, &bar->outputs, link) { | 466 | wl_list_for_each(output, &bar->outputs, link) { |
415 | if (output->scale > max_scale) { | 467 | if (output->scale > max_scale) { |
416 | max_scale = output->scale; | 468 | max_scale = output->scale; |
417 | } | 469 | } |
418 | } | 470 | } |
419 | 471 | ||
420 | pointer->cursor_theme = wl_cursor_theme_load( | 472 | pointer->cursor_theme = |
421 | NULL, 24 * max_scale, bar->shm); | 473 | wl_cursor_theme_load(NULL, 24 * max_scale, bar->shm); |
422 | assert(pointer->cursor_theme); | 474 | assert(pointer->cursor_theme); |
423 | struct wl_cursor *cursor; | 475 | struct wl_cursor *cursor; |
424 | cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr"); | 476 | cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr"); |
@@ -428,13 +480,6 @@ void bar_setup(struct swaybar *bar, | |||
428 | assert(pointer->cursor_surface); | 480 | assert(pointer->cursor_surface); |
429 | 481 | ||
430 | wl_list_for_each(output, &bar->outputs, link) { | 482 | wl_list_for_each(output, &bar->outputs, link) { |
431 | struct config_output *coutput; | ||
432 | wl_list_for_each(coutput, &bar->config->outputs, link) { | ||
433 | if (coutput->index == output->index) { | ||
434 | output->name = strdup(coutput->name); | ||
435 | break; | ||
436 | } | ||
437 | } | ||
438 | output->surface = wl_compositor_create_surface(bar->compositor); | 483 | output->surface = wl_compositor_create_surface(bar->compositor); |
439 | assert(output->surface); | 484 | assert(output->surface); |
440 | output->layer_surface = zwlr_layer_shell_v1_get_layer_surface( | 485 | output->layer_surface = zwlr_layer_shell_v1_get_layer_surface( |