Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track seats to free them on exit #10

Merged
merged 2 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/slurp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct slurp_state {
struct zwlr_layer_shell_v1 *layer_shell;
struct wl_list outputs; // slurp_output::link
struct wl_list pointers; // slurp_pointer::link
struct wl_list seats; // slurp_seat::link

struct {
uint32_t background;
Expand Down Expand Up @@ -71,6 +72,11 @@ struct slurp_pointer {
struct wl_surface *cursor_surface;
};

struct slurp_seat {
struct wl_seat *wl_seat;
struct wl_list link; // slurp_state::seats
};

void pointer_get_box(struct slurp_pointer *pointer, int *x, int *y,
int *width, int *height);

Expand Down
26 changes: 24 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@ static const struct wl_seat_listener seat_listener = {
.capabilities = seat_handle_capabilities,
};

static void create_seat(struct slurp_state *state, struct wl_seat *wl_seat) {
struct slurp_seat *seat = calloc(1, sizeof(struct slurp_seat));
if (seat == NULL) {
fprintf(stderr, "allocation failed\n");
return;
}
seat->wl_seat = wl_seat;
wl_list_insert(&state->seats, &seat->link);
wl_seat_add_listener(wl_seat, &seat_listener, state);
}

static void destroy_seat(struct slurp_seat *seat) {
wl_list_remove(&seat->link);
wl_seat_destroy(seat->wl_seat);
free(seat);
}

static void output_handle_geometry(void *data, struct wl_output *wl_output,
int32_t x, int32_t y, int32_t physical_width, int32_t physical_height,
Expand Down Expand Up @@ -195,6 +211,7 @@ static void destroy_output(struct slurp_output *output) {
if (output == NULL) {
return;
}
wl_list_remove(&output->link);
finish_buffer(&output->buffers[0]);
finish_buffer(&output->buffers[1]);
wl_cursor_theme_destroy(output->cursor_theme);
Expand Down Expand Up @@ -315,9 +332,9 @@ static void handle_global(void *data, struct wl_registry *registry,
state->layer_shell = wl_registry_bind(registry, name,
&zwlr_layer_shell_v1_interface, 1);
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
struct wl_seat *seat =
struct wl_seat *wl_seat =
wl_registry_bind(registry, name, &wl_seat_interface, 1);
wl_seat_add_listener(seat, &seat_listener, state);
create_seat(state, wl_seat);
} else if (strcmp(interface, wl_output_interface.name) == 0) {
struct wl_output *wl_output =
wl_registry_bind(registry, name, &wl_output_interface, 3);
Expand Down Expand Up @@ -405,6 +422,7 @@ int main(int argc, char *argv[]) {

wl_list_init(&state.outputs);
wl_list_init(&state.pointers);
wl_list_init(&state.seats);

state.display = wl_display_connect(NULL);
if (state.display == NULL) {
Expand Down Expand Up @@ -481,6 +499,10 @@ int main(int argc, char *argv[]) {
wl_list_for_each_safe(output, output_tmp, &state.outputs, link) {
destroy_output(output);
}
struct slurp_seat *seat, *seat_tmp;
wl_list_for_each_safe(seat, seat_tmp, &state.seats, link) {
destroy_seat(seat);
}

// Make sure the compositor has unmapped our surfaces by the time we exit
wl_display_roundtrip(state.display);
Expand Down