swaybar: add multiseat support

This just adds multiseat support to swaybar
This commit is contained in:
Brian Ashworth 2019-04-23 23:40:00 -04:00 committed by Drew DeVault
parent 583ceff6f6
commit dc7a3930a7
4 changed files with 131 additions and 57 deletions

View file

@ -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);
}