From be3a0ad065a946c8dfe753368757f3d5744059e6 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 11 Aug 2017 22:46:50 +0200 Subject: [PATCH 1/6] libinput backend: fill in handle_device_removed And fix input_remove_notify accordingly --- backend/libinput/events.c | 17 +++++++++++++++-- examples/shared.c | 5 ++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 0cdf26ec..9afdab21 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -111,8 +111,21 @@ static void handle_device_added(struct wlr_backend_state *state, static void handle_device_removed(struct wlr_backend_state *state, struct libinput_device *device) { - wlr_log(L_DEBUG, "libinput device removed"); - // TODO + list_t *devices = libinput_device_get_user_data(device); + for (size_t i = 0; i < devices->length; i++) { + struct wlr_input_device *wlr_device = devices->items[i]; + wlr_log(L_DEBUG, "Removing %s [%d:%d]", wlr_device->name, + wlr_device->vendor, wlr_device->product); + wl_signal_emit(&state->backend->events.input_remove, wlr_device); + wlr_input_device_destroy(wlr_device); + } + for (size_t i = 0; i < state->devices->length; i++) { + if (state->devices->items[i] == devices) { + list_del(state->devices, i); + break; + } + } + list_free(devices); } void wlr_libinput_event(struct wlr_backend_state *state, diff --git a/examples/shared.c b/examples/shared.c index 6efa1bef..0605dd72 100644 --- a/examples/shared.c +++ b/examples/shared.c @@ -384,14 +384,13 @@ static void tablet_pad_remove(struct wlr_input_device *device, struct compositor if (!pstate) { return; } - // TODO probably missing more actions + wl_list_remove(&pstate->button.link); free(pstate); } -// TODO missing something that calls this on teardown static void input_remove_notify(struct wl_listener *listener, void *data) { struct wlr_input_device *device = data; - struct compositor_state *state = wl_container_of(listener, state, input_add); + struct compositor_state *state = wl_container_of(listener, state, input_remove); switch (device->type) { case WLR_INPUT_DEVICE_KEYBOARD: keyboard_remove(device, state); From e1293a78530a5de9280ee76e83488a2a04c95c79 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 11 Aug 2017 22:55:36 +0200 Subject: [PATCH 2/6] libinput: signal input remove on libinput backend destroy This lets the upper crust cleanup and free their own states --- backend/libinput/backend.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 19fe8fe7..58bd62f2 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -84,7 +84,9 @@ static void wlr_libinput_backend_destroy(struct wlr_backend_state *state) { for (size_t i = 0; i < state->devices->length; i++) { list_t *wlr_devices = state->devices->items[i]; for (size_t j = 0; j < wlr_devices->length; j++) { - wlr_input_device_destroy(wlr_devices->items[j]); + struct wlr_input_device *wlr_device = wlr_devices->items[j]; + wl_signal_emit(&state->backend->events.input_remove, wlr_device); + wlr_input_device_destroy(wlr_device); } list_free(wlr_devices); } From de86965174a5ccb6c204c52d6e57812c1fa64a24 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 12 Aug 2017 00:02:04 +0200 Subject: [PATCH 3/6] Use libinput_event_destroy/xkb_*_unref Also sneak in a missing drmModeFreePlaneResources --- backend/drm/drm.c | 1 + backend/libinput/backend.c | 1 + examples/shared.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 8062a478..04822040 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -104,6 +104,7 @@ static bool init_planes(struct wlr_backend_state *drm) { drm->primary_planes = drm->overlay_planes + drm->num_overlay_planes; drm->cursor_planes = drm->primary_planes + drm->num_primary_planes; + drmModeFreePlaneResources(plane_res); return true; error_planes: diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 58bd62f2..42c1eac9 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -33,6 +33,7 @@ static int wlr_libinput_readable(int fd, uint32_t mask, void *_state) { struct libinput_event *event; while ((event = libinput_get_event(state->libinput))) { wlr_libinput_event(state, event); + libinput_event_destroy(event); } return 0; } diff --git a/examples/shared.c b/examples/shared.c index 0605dd72..0738a548 100644 --- a/examples/shared.c +++ b/examples/shared.c @@ -311,6 +311,8 @@ static void keyboard_remove(struct wlr_input_device *device, struct compositor_s if (!kbstate) { return; } + xkb_state_unref(kbstate->xkb_state); + xkb_map_unref(kbstate->keymap); wl_list_remove(&kbstate->link); wl_list_remove(&kbstate->key.link); free(kbstate); From c323bfc6a0016076e3a27a639da23f6c176c68fa Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 12 Aug 2017 00:02:33 +0200 Subject: [PATCH 4/6] GLES2: detach and delete shaders after LinkProgram Also make sure program linked correctly! --- render/gles2/renderer.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 237dc67b..c1bf4815 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -30,7 +30,7 @@ static bool compile_shader(GLuint type, const GLchar *src, GLuint *shader) { GL_CALL(glGetShaderInfoLog(*shader, loglen, &loglen, msg)); wlr_log(L_ERROR, "Shader compilation failed"); wlr_log(L_ERROR, "%s", msg); - exit(1); + glDeleteShader(*shader); return false; } return true; @@ -43,13 +43,32 @@ static bool compile_program(const GLchar *vert_src, return false; } if (!compile_shader(GL_FRAGMENT_SHADER, frag_src, &fragment)) { - glDeleteProgram(vertex); + glDeleteShader(vertex); return false; } *program = GL_CALL(glCreateProgram()); GL_CALL(glAttachShader(*program, vertex)); GL_CALL(glAttachShader(*program, fragment)); GL_CALL(glLinkProgram(*program)); + GLint success; + GL_CALL(glGetProgramiv(*program, GL_LINK_STATUS, &success)); + if (success == GL_FALSE) { + GLint loglen; + GL_CALL(glGetProgramiv(*program, GL_INFO_LOG_LENGTH, &loglen)); + GLchar msg[loglen]; + GL_CALL(glGetProgramInfoLog(*program, loglen, &loglen, msg)); + wlr_log(L_ERROR, "Program link failed"); + wlr_log(L_ERROR, "%s", msg); + glDeleteProgram(*program); + glDeleteShader(vertex); + glDeleteShader(fragment); + return false; + } + glDetachShader(*program, vertex); + glDetachShader(*program, fragment); + glDeleteShader(vertex); + glDeleteShader(fragment); + return true; } From 8427749dd06b52bd8e53539f264a784beca9bb6f Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 12 Aug 2017 01:16:12 +0200 Subject: [PATCH 5/6] wayland backend: emit signal for input/output removal --- backend/wayland/output.c | 1 + backend/wayland/wl_seat.c | 3 ++- include/backend/wayland.h | 7 ++++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 2c7086e2..318f1f05 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -46,6 +46,7 @@ static void wlr_wl_output_transform(struct wlr_output_state *output, } static void wlr_wl_output_destroy(struct wlr_output_state *output) { + wl_signal_emit(&output->backend->backend->events.output_remove, output->wlr_output); if(output->frame_callback) wl_callback_destroy(output->frame_callback); eglDestroySurface(output->backend->egl.display, output->surface); wl_egl_window_destroy(output->egl_window); diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index ab3de74d..88784828 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -169,6 +169,7 @@ static struct wl_keyboard_listener keyboard_listener = { }; static void input_device_destroy(struct wlr_input_device_state *state) { + wl_signal_emit(&state->backend->backend->events.input_remove, state->wlr_device); if (state->resource) wl_proxy_destroy(state->resource); free(state); @@ -206,7 +207,7 @@ static struct wlr_input_device *allocate_device(struct wlr_backend_state *state, free(devstate); return NULL; } - + devstate->wlr_device = wlr_device; list_add(state->devices, wlr_device); return wlr_device; } diff --git a/include/backend/wayland.h b/include/backend/wayland.h index e6339a23..1ce4e135 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -33,13 +33,14 @@ struct wlr_output_state { struct wlr_output *wlr_output; struct wl_surface *surface; struct wl_shell_surface *shell_surface; - struct wl_egl_window* egl_window; - struct wl_callback* frame_callback; + struct wl_egl_window *egl_window; + struct wl_callback *frame_callback; void *egl_surface; }; struct wlr_input_device_state { - struct wlr_backend_state* backend; + struct wlr_backend_state *backend; + struct wlr_input_device *wlr_device; void *resource; }; From 3ea878b76e7cf63caf9cddaaabe2faca053d9085 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 12 Aug 2017 01:19:45 +0200 Subject: [PATCH 6/6] wayland backend: free seatName --- backend/wayland/backend.c | 1 + backend/wayland/wl_seat.c | 1 + include/backend/wayland.h | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 1a156802..ddad1418 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -85,6 +85,7 @@ static void wlr_wl_backend_destroy(struct wlr_backend_state *state) { list_free(state->devices); list_free(state->outputs); + free(state->seatName); wlr_egl_free(&state->egl); if (state->seat) wl_seat_destroy(state->seat); diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 88784828..7fb63cbe 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -258,6 +258,7 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, static void seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) { struct wlr_backend_state *state = data; assert(state->seat == wl_seat); + // Do we need to check if seatName was previously set for name change? state->seatName = strdup(name); } diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 1ce4e135..be96128e 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -25,7 +25,7 @@ struct wlr_backend_state { struct wl_shell *shell; struct wl_shm *shm; struct wl_seat *seat; - const char *seatName; + char *seatName; }; struct wlr_output_state {