Assign clients to unoccupied seats

websocket-tls
Andri Yngvason 2023-04-29 20:08:01 +00:00
parent c01e5c6080
commit d50c616127
1 changed files with 29 additions and 13 deletions

View File

@ -255,6 +255,20 @@ static void registry_add(void* data, struct wl_registry* registry,
return; return;
} }
static void disconnect_seat_clients(struct wayvnc* self, struct seat* seat)
{
struct nvnc_client* nvnc_client;
for (nvnc_client = nvnc_client_first(self->nvnc); nvnc_client;
nvnc_client = nvnc_client_next(nvnc_client)) {
struct wayvnc_client* client = nvnc_get_userdata(nvnc_client);
assert(client);
if (client->seat == seat) {
nvnc_client_close(nvnc_client);
}
}
}
static void registry_remove(void* data, struct wl_registry* registry, static void registry_remove(void* data, struct wl_registry* registry,
uint32_t id) uint32_t id)
{ {
@ -283,14 +297,9 @@ static void registry_remove(void* data, struct wl_registry* registry,
struct seat* seat = seat_find_by_id(&self->seats, id); struct seat* seat = seat_find_by_id(&self->seats, id);
if (seat) { if (seat) {
nvnc_log(NVNC_LOG_INFO, "Seat %s went away", seat->name); nvnc_log(NVNC_LOG_INFO, "Seat %s went away", seat->name);
disconnect_seat_clients(self, seat);
wl_list_remove(&seat->link); wl_list_remove(&seat->link);
seat_destroy(seat); seat_destroy(seat);
if (seat == self->selected_seat) {
nvnc_log(NVNC_LOG_ERROR, "Selected seat went away. Exiting...");
wayvnc_exit(self);
}
return; return;
} }
} }
@ -1030,6 +1039,9 @@ static void on_nvnc_client_cleanup(struct nvnc_client* client)
struct nvnc* nvnc = nvnc_client_get_server(client); struct nvnc* nvnc = nvnc_client_get_server(client);
struct wayvnc* self = nvnc_get_userdata(nvnc); struct wayvnc* self = nvnc_get_userdata(nvnc);
if (wayvnc_client->seat)
wayvnc_client->seat->occupancy--;
self->nr_clients--; self->nr_clients--;
nvnc_log(NVNC_LOG_DEBUG, "Client disconnected, new client count: %d", nvnc_log(NVNC_LOG_DEBUG, "Client disconnected, new client count: %d",
self->nr_clients); self->nr_clients);
@ -1126,7 +1138,17 @@ static void client_init_seat(struct wayvnc_client* self)
if (wayvnc->disable_input) if (wayvnc->disable_input)
return; return;
self->seat = wayvnc->selected_seat; if (wayvnc->selected_seat) {
self->seat = wayvnc->selected_seat;
} else {
self->seat = seat_find_unoccupied(&wayvnc->seats);
if (!self->seat) {
self->seat = seat_first(&wayvnc->seats);
}
}
if (self->seat)
self->seat->occupancy++;
} }
static void client_init_keyboard(struct wayvnc_client* self) static void client_init_keyboard(struct wayvnc_client* self)
@ -1426,12 +1448,6 @@ int main(int argc, char* argv[])
nvnc_log(NVNC_LOG_ERROR, "No such seat"); nvnc_log(NVNC_LOG_ERROR, "No such seat");
goto failure; goto failure;
} }
} else if (!self.disable_input) {
seat = seat_first(&self.seats);
if (!seat) {
nvnc_log(NVNC_LOG_ERROR, "No seat found");
goto failure;
}
} }
self.selected_seat = seat; self.selected_seat = seat;