From dc7a3930a7ffd4435c9215c7cce0afa37d06c91f Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Tue, 23 Apr 2019 23:40:00 -0400 Subject: swaybar: add multiseat support This just adds multiseat support to swaybar --- swaybar/bar.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 9 deletions(-) (limited to 'swaybar/bar.c') diff --git a/swaybar/bar.c b/swaybar/bar.c index a95464f5..35e1662b 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -216,8 +216,16 @@ static void output_scale(void *data, struct wl_output *wl_output, int32_t factor) { struct swaybar_output *output = data; output->scale = factor; - if (output == output->bar->pointer.current) { - update_cursor(output->bar); + + bool render = false; + struct swaybar_seat *seat; + wl_list_for_each(seat, &output->bar->seats, link) { + if (output == seat->pointer.current) { + update_cursor(seat); + render = true; + } + }; + if (render) { render_frame(output); } } @@ -318,9 +326,16 @@ static void handle_global(void *data, struct wl_registry *registry, bar->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 4); } else if (strcmp(interface, wl_seat_interface.name) == 0) { - bar->seat = wl_registry_bind(registry, name, - &wl_seat_interface, 3); - wl_seat_add_listener(bar->seat, &seat_listener, bar); + struct swaybar_seat *seat = calloc(1, sizeof(struct swaybar_seat)); + if (!seat) { + sway_abort("Failed to allocate swaybar_seat"); + return; + } + seat->bar = bar; + seat->wl_name = name; + seat->wl_seat = wl_registry_bind(registry, name, &wl_seat_interface, 3); + wl_seat_add_listener(seat->wl_seat, &seat_listener, seat); + wl_list_insert(&bar->seats, &seat->link); } else if (strcmp(interface, wl_shm_interface.name) == 0) { bar->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); @@ -355,7 +370,14 @@ static void handle_global_remove(void *data, struct wl_registry *registry, wl_list_for_each_safe(output, tmp, &bar->outputs, link) { if (output->wl_name == name) { swaybar_output_free(output); - break; + return; + } + } + struct swaybar_seat *seat, *tmp_seat; + wl_list_for_each_safe(seat, tmp_seat, &bar->seats, link) { + if (seat->wl_name == name) { + swaybar_seat_free(seat); + return; } } } @@ -369,6 +391,7 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) { bar->visible = true; bar->config = init_config(); wl_list_init(&bar->outputs); + wl_list_init(&bar->seats); bar->eventloop = loop_create(); bar->ipc_socketfd = ipc_open_socket(socket_path); @@ -397,9 +420,16 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) { // Second roundtrip for xdg-output wl_display_roundtrip(bar->display); - struct swaybar_pointer *pointer = &bar->pointer; - pointer->cursor_surface = wl_compositor_create_surface(bar->compositor); - assert(pointer->cursor_surface); + struct swaybar_seat *seat; + wl_list_for_each(seat, &bar->seats, link) { + struct swaybar_pointer *pointer = &seat->pointer; + if (!pointer) { + continue; + } + pointer->cursor_surface = + wl_compositor_create_surface(bar->compositor); + assert(pointer->cursor_surface); + } #if HAVE_TRAY if (!bar->config->tray_hidden) { @@ -468,11 +498,19 @@ static void free_outputs(struct wl_list *list) { } } +static void free_seats(struct wl_list *list) { + struct swaybar_seat *seat, *tmp; + wl_list_for_each_safe(seat, tmp, list, link) { + swaybar_seat_free(seat); + } +} + void bar_teardown(struct swaybar *bar) { #if HAVE_TRAY destroy_tray(bar->tray); #endif free_outputs(&bar->outputs); + free_seats(&bar->seats); if (bar->config) { free_config(bar->config); } -- cgit v1.2.3-54-g00ecf