diff --git a/include/seat.h b/include/seat.h index 356358d..97692b2 100644 --- a/include/seat.h +++ b/include/seat.h @@ -23,13 +23,15 @@ struct seat { struct wl_seat* wl_seat; struct wl_list link; + uint32_t id; uint32_t capabilities; char name[256]; }; -struct seat* seat_new(struct wl_seat* wl_seat); +struct seat* seat_new(struct wl_seat* wl_seat, uint32_t id); void seat_destroy(struct seat* self); void seat_list_destroy(struct wl_list* list); struct seat* seat_find_by_name(struct wl_list* list, const char* name); +struct seat* seat_find_by_id(struct wl_list* list, uint32_t id); struct seat* seat_first(struct wl_list* list); diff --git a/src/main.c b/src/main.c index 3f3cd81..8e5d7c6 100644 --- a/src/main.c +++ b/src/main.c @@ -159,7 +159,7 @@ static void registry_add(void* data, struct wl_registry* registry, if (!wl_seat) return; - struct seat* seat = seat_new(wl_seat); + struct seat* seat = seat_new(wl_seat, id); if (!seat) { wl_seat_destroy(wl_seat); return; @@ -189,6 +189,18 @@ static void registry_remove(void* data, struct wl_registry* registry, output_destroy(out); /* TODO: If this is the selected output, exit */ + + return; + } + + struct seat* seat = seat_find_by_id(&self->seats, id); + if (seat) { + wl_list_remove(&seat->link); + seat_destroy(seat); + + /* TODO: If this is the selected seat, exit */ + + return; } } diff --git a/src/seat.c b/src/seat.c index 681334a..d43fc86 100644 --- a/src/seat.c +++ b/src/seat.c @@ -44,13 +44,14 @@ static const struct wl_seat_listener seat_listener = { .name = seat_name, }; -struct seat* seat_new(struct wl_seat* wl_seat) +struct seat* seat_new(struct wl_seat* wl_seat, uint32_t id) { struct seat* self = calloc(1, sizeof(*self)); if (!self) return NULL; self->wl_seat = wl_seat; + self->id = id; wl_seat_add_listener(wl_seat, &seat_listener, self); @@ -85,6 +86,17 @@ struct seat* seat_find_by_name(struct wl_list* list, const char* name) return NULL; } +struct seat* seat_find_by_id(struct wl_list* list, uint32_t id) +{ + struct seat* seat; + + wl_list_for_each(seat, list, link) + if (seat->id == id) + return seat; + + return NULL; +} + struct seat* seat_first(struct wl_list* list) { struct seat* seat;