From f4754ad1a21eaede20f6e9c5d4e0c78294119cc1 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 30 Nov 2017 23:58:12 +0100 Subject: Fix surface transforms --- include/wlr/render/matrix.h | 2 ++ include/wlr/types/wlr_output.h | 2 ++ 2 files changed, 4 insertions(+) (limited to 'include/wlr') diff --git a/include/wlr/render/matrix.h b/include/wlr/render/matrix.h index 177af4b3..0b35aad3 100644 --- a/include/wlr/render/matrix.h +++ b/include/wlr/render/matrix.h @@ -10,6 +10,8 @@ void wlr_matrix_rotate(float (*output)[16], float radians); void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]); enum wl_output_transform; +void wlr_matrix_transform(float mat[static 16], + enum wl_output_transform transform); void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, enum wl_output_transform transform); diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index d382b593..b1b83044 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -106,4 +106,6 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, double x, double y); void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor); +enum wl_output_transform wlr_output_transform_invert(enum wl_output_transform); + #endif -- cgit v1.2.3 From 6a69b4419fa25f4bbcbe3253ed000276cb6ace42 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 1 Dec 2017 09:15:33 +0100 Subject: Make wlr_output_transform_* functions public, refactoring --- backend/drm/drm.c | 5 ++-- backend/wayland/wl_seat.c | 5 ++-- include/wlr/interfaces/wlr_output.h | 4 ---- include/wlr/types/wlr_box.h | 4 ++++ render/matrix.c | 28 +++++++++++----------- types/wlr_box.c | 47 +++++++++++++++++++++++++++++++++++++ types/wlr_output.c | 46 ------------------------------------ 7 files changed, 69 insertions(+), 70 deletions(-) (limited to 'include/wlr') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index dd247998..cf6ad550 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -569,8 +569,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, enum wl_output_transform transform = wlr_output_transform_invert(output->transform); struct wlr_box transformed_hotspot; - wlr_output_transform_apply_to_box(transform, &hotspot, - &transformed_hotspot); + wlr_box_transform(&hotspot, transform, &transformed_hotspot); plane->cursor_hotspot_x = transformed_hotspot.x; plane->cursor_hotspot_y = transformed_hotspot.y; @@ -632,7 +631,7 @@ static bool wlr_drm_connector_move_cursor(struct wlr_output *output, enum wl_output_transform transform = wlr_output_transform_invert(output->transform); struct wlr_box transformed_box; - wlr_output_transform_apply_to_box(transform, &box, &transformed_box); + wlr_box_transform(&box, transform, &transformed_box); transformed_box.x -= plane->cursor_hotspot_x; transformed_box.y -= plane->cursor_hotspot_y; diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index a2da8df5..77c46164 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -55,9 +55,8 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, box.x = wl_fixed_to_int(surface_x); box.y = wl_fixed_to_int(surface_y); struct wlr_box transformed; - wlr_output_transform_apply_to_box( - wlr_wl_pointer->current_output->wlr_output.transform, &box, - &transformed); + wlr_box_transform(&box, + wlr_wl_pointer->current_output->wlr_output.transform, &transformed); struct wlr_event_pointer_motion_absolute wlr_event; wlr_event.device = dev; diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index b4f39d35..8fbb650a 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -32,8 +32,4 @@ struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output, struct wl_display *display); void wlr_output_destroy_global(struct wlr_output *wlr_output); -void wlr_output_transform_apply_to_box(enum wl_output_transform transform, - struct wlr_box *box, struct wlr_box *dest); -enum wl_output_transform wlr_output_transform_invert(enum wl_output_transform); - #endif diff --git a/include/wlr/types/wlr_box.h b/include/wlr/types/wlr_box.h index 5b8b00c9..5290ada5 100644 --- a/include/wlr/types/wlr_box.h +++ b/include/wlr/types/wlr_box.h @@ -18,4 +18,8 @@ bool wlr_box_contains_point(struct wlr_box *box, double x, double y); bool wlr_box_empty(struct wlr_box *box); +enum wl_output_transform; +void wlr_box_transform(struct wlr_box *box, enum wl_output_transform transform, + struct wlr_box *dest); + #endif diff --git a/render/matrix.c b/render/matrix.c index 8a3352e0..6118e6a5 100644 --- a/render/matrix.c +++ b/render/matrix.c @@ -86,35 +86,35 @@ void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product) static const float transforms[][4] = { [WL_OUTPUT_TRANSFORM_NORMAL] = { 1.0f, 0.0f, - 0.0f, -1.0f, + 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_90] = { 0.0f, -1.0f, - -1.0f, 0.0f, + 1.0f, 0.0f, }, [WL_OUTPUT_TRANSFORM_180] = { -1.0f, 0.0f, - 0.0f, 1.0f, + 0.0f, -1.0f, }, [WL_OUTPUT_TRANSFORM_270] = { 0.0f, 1.0f, - 1.0f, 0.0f, + -1.0f, 0.0f, }, [WL_OUTPUT_TRANSFORM_FLIPPED] = { -1.0f, 0.0f, - 0.0f, -1.0f, + 0.0f, 1.0f, }, [WL_OUTPUT_TRANSFORM_FLIPPED_90] = { 0.0f, 1.0f, - -1.0f, 0.0f, + 1.0f, 0.0f, }, [WL_OUTPUT_TRANSFORM_FLIPPED_180] = { 1.0f, 0.0f, - 0.0f, 1.0f, + 0.0f, -1.0f, }, [WL_OUTPUT_TRANSFORM_FLIPPED_270] = { 0.0f, -1.0f, - 1.0f, 0.0f, + -1.0f, 0.0f, }, }; @@ -124,11 +124,11 @@ void wlr_matrix_transform(float mat[static 16], const float *t = transforms[transform]; - // Rotation + relection + // Rotation + reflection mat[0] = t[0]; mat[1] = t[1]; - mat[4] = -t[2]; - mat[5] = -t[3]; + mat[4] = t[2]; + mat[5] = t[3]; // Identity mat[10] = 1.0f; @@ -144,11 +144,11 @@ void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height, float x = 2.0f / width; float y = 2.0f / height; - // Rotation + relection + // Rotation + reflection mat[0] = x * t[0]; mat[1] = x * t[1]; - mat[4] = y * t[2]; - mat[5] = y * t[3]; + mat[4] = y * -t[2]; + mat[5] = y * -t[3]; // Translation mat[3] = -copysign(1.0f, mat[0] + mat[1]); diff --git a/types/wlr_box.c b/types/wlr_box.c index 7e981833..88f4b8ab 100644 --- a/types/wlr_box.c +++ b/types/wlr_box.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -65,3 +66,49 @@ bool wlr_box_contains_point(struct wlr_box *box, double x, double y) { y >= box->y && y <= box->y + box->height; } } + +void wlr_box_transform(struct wlr_box *box, + enum wl_output_transform transform, struct wlr_box *dest) { + if (transform % 2 == 0) { + dest->width = box->width; + dest->height = box->height; + } else { + dest->width = box->height; + dest->height = box->width; + } + + switch (transform) { + case WL_OUTPUT_TRANSFORM_NORMAL: + dest->x = box->x; + dest->y = box->y; + break; + case WL_OUTPUT_TRANSFORM_90: + dest->x = box->y; + dest->y = box->width - box->x; + break; + case WL_OUTPUT_TRANSFORM_180: + dest->x = box->width - box->x; + dest->y = box->height - box->y; + break; + case WL_OUTPUT_TRANSFORM_270: + dest->x = box->height - box->y; + dest->y = box->x; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED: + dest->x = box->width - box->x; + dest->y = box->y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_90: + dest->x = box->y; + dest->y = box->x; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_180: + dest->x = box->x; + dest->y = box->height - box->y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED_270: + dest->x = box->height - box->y; + dest->y = box->width - box->x; + break; + } +} diff --git a/types/wlr_output.c b/types/wlr_output.c index 21d94cfb..aad7dfec 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -626,52 +626,6 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) { free(cursor); } -void wlr_output_transform_apply_to_box(enum wl_output_transform transform, - struct wlr_box *box, struct wlr_box *dest) { - if (transform % 2 == 0) { - dest->width = box->width; - dest->height = box->height; - } else { - dest->width = box->height; - dest->height = box->width; - } - - switch (transform) { - case WL_OUTPUT_TRANSFORM_NORMAL: - dest->x = box->x; - dest->y = box->y; - break; - case WL_OUTPUT_TRANSFORM_90: - dest->x = box->y; - dest->y = box->width - box->x; - break; - case WL_OUTPUT_TRANSFORM_180: - dest->x = box->width - box->x; - dest->y = box->height - box->y; - break; - case WL_OUTPUT_TRANSFORM_270: - dest->x = box->height - box->y; - dest->y = box->x; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED: - dest->x = box->width - box->x; - dest->y = box->y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_90: - dest->x = box->y; - dest->y = box->x; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_180: - dest->x = box->x; - dest->y = box->height - box->y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_270: - dest->x = box->height - box->y; - dest->y = box->width - box->x; - break; - } -} - enum wl_output_transform wlr_output_transform_invert( enum wl_output_transform transform) { if ((transform & WL_OUTPUT_TRANSFORM_90) && -- cgit v1.2.3 From dfe11a2b0ef3806d3c2241e3bc8e69fc93905d8c Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 7 Dec 2017 00:13:06 +0100 Subject: Add display destroy listener in screenshooter, destroy display in rootston --- include/wlr/types/wlr_screenshooter.h | 8 ++++++ rootston/main.c | 2 ++ types/wlr_screenshooter.c | 49 ++++++++++++++++++++++++++++------- 3 files changed, 49 insertions(+), 10 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_screenshooter.h b/include/wlr/types/wlr_screenshooter.h index 4bda3d3c..e8b59669 100644 --- a/include/wlr/types/wlr_screenshooter.h +++ b/include/wlr/types/wlr_screenshooter.h @@ -5,6 +5,13 @@ struct wlr_screenshooter { struct wl_global *wl_global; struct wlr_renderer *renderer; + struct wl_list screenshots; // wlr_screenshot::link + + struct wl_listener display_destroy; + + struct { + struct wl_signal destroy; + } events; void *data; }; @@ -12,6 +19,7 @@ struct wlr_screenshooter { struct wlr_screenshot { struct wl_resource *resource; struct wl_resource *output_resource; + struct wl_list link; struct wlr_output *output; struct wlr_screenshooter *screenshooter; diff --git a/rootston/main.c b/rootston/main.c index 46548094..3b65a067 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -51,6 +51,7 @@ int main(int argc, char **argv) { if (!wlr_backend_start(server.backend)) { wlr_log(L_ERROR, "Failed to start backend"); wlr_backend_destroy(server.backend); + wl_display_destroy(server.wl_display); return 1; } @@ -69,5 +70,6 @@ int main(int argc, char **argv) { wl_display_run(server.wl_display); wlr_backend_destroy(server.backend); + wl_display_destroy(server.wl_display); return 0; } diff --git a/types/wlr_screenshooter.c b/types/wlr_screenshooter.c index 94b45384..d62820e6 100644 --- a/types/wlr_screenshooter.c +++ b/types/wlr_screenshooter.c @@ -26,6 +26,18 @@ struct screenshot_state { struct wl_listener frame_listener; }; +static void screenshot_destroy(struct wlr_screenshot *screenshot) { + wl_list_remove(&screenshot->link); + free(screenshot); +} + +static void handle_screenshot_resource_destroy( + struct wl_resource *screenshot_resource) { + struct wlr_screenshot *screenshot = + wl_resource_get_user_data(screenshot_resource); + screenshot_destroy(screenshot); +} + static void output_frame_notify(struct wl_listener *listener, void *_data) { struct screenshot_state *state = wl_container_of(listener, state, frame_listener); @@ -102,7 +114,8 @@ static void screenshooter_shoot(struct wl_client *client, return; } wl_resource_set_implementation(screenshot->resource, NULL, screenshot, - NULL); + handle_screenshot_resource_destroy); + wl_list_insert(&screenshooter->screenshots, &screenshot->link); wlr_log(L_DEBUG, "new screenshot %p (res %p)", screenshot, screenshot->resource); @@ -144,6 +157,25 @@ static void screenshooter_bind(struct wl_client *wl_client, void *data, screenshooter, NULL); } +void wlr_screenshooter_destroy(struct wlr_screenshooter *screenshooter) { + if (!screenshooter) { + return; + } + wl_signal_emit(&screenshooter->events.destroy, screenshooter); + struct wlr_screenshot *screenshot, *tmp; + wl_list_for_each_safe(screenshot, tmp, &screenshooter->screenshots, link) { + screenshot_destroy(screenshot); + } + wl_global_destroy(screenshooter->wl_global); + free(screenshooter); +} + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_screenshooter *screenshooter = + wl_container_of(listener, screenshooter, display_destroy); + wlr_screenshooter_destroy(screenshooter); +} + struct wlr_screenshooter *wlr_screenshooter_create(struct wl_display *display, struct wlr_renderer *renderer) { struct wlr_screenshooter *screenshooter = @@ -153,6 +185,12 @@ struct wlr_screenshooter *wlr_screenshooter_create(struct wl_display *display, } screenshooter->renderer = renderer; + wl_list_init(&screenshooter->screenshots); + wl_signal_init(&screenshooter->events.destroy); + + screenshooter->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &screenshooter->display_destroy); + screenshooter->wl_global = wl_global_create(display, &orbital_screenshooter_interface, 1, screenshooter, screenshooter_bind); if (screenshooter->wl_global == NULL) { @@ -162,12 +200,3 @@ struct wlr_screenshooter *wlr_screenshooter_create(struct wl_display *display, return screenshooter; } - -void wlr_screenshooter_destroy(struct wlr_screenshooter *screenshooter) { - if (!screenshooter) { - return; - } - // TODO: this segfault (wl_display->registry_resource_list is not init) - // wl_global_destroy(screenshooter->wl_global); - free(screenshooter); -} -- cgit v1.2.3 From 32591d66d61e2a4ef06db89276f8d158d22d81a8 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 7 Dec 2017 00:36:05 +0100 Subject: Add display destroy listener in server decoration --- include/wlr/types/wlr_server_decoration.h | 2 ++ types/wlr_screenshooter.c | 5 +++- types/wlr_server_decoration.c | 46 +++++++++++++++++++------------ 3 files changed, 34 insertions(+), 19 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_server_decoration.h b/include/wlr/types/wlr_server_decoration.h index 474a9386..e457a0aa 100644 --- a/include/wlr/types/wlr_server_decoration.h +++ b/include/wlr/types/wlr_server_decoration.h @@ -33,6 +33,8 @@ struct wlr_server_decoration_manager { uint32_t default_mode; // enum wlr_server_decoration_manager_mode + struct wl_listener display_destroy; + struct { struct wl_signal new_decoration; } events; diff --git a/types/wlr_screenshooter.c b/types/wlr_screenshooter.c index d62820e6..cb831827 100644 --- a/types/wlr_screenshooter.c +++ b/types/wlr_screenshooter.c @@ -28,6 +28,7 @@ struct screenshot_state { static void screenshot_destroy(struct wlr_screenshot *screenshot) { wl_list_remove(&screenshot->link); + wl_resource_set_user_data(screenshot->resource, NULL); free(screenshot); } @@ -35,7 +36,9 @@ static void handle_screenshot_resource_destroy( struct wl_resource *screenshot_resource) { struct wlr_screenshot *screenshot = wl_resource_get_user_data(screenshot_resource); - screenshot_destroy(screenshot); + if (screenshot != NULL) { + screenshot_destroy(screenshot); + } } static void output_frame_notify(struct wl_listener *listener, void *_data) { diff --git a/types/wlr_server_decoration.c b/types/wlr_server_decoration.c index 60cc6369..3531c453 100644 --- a/types/wlr_server_decoration.c +++ b/types/wlr_server_decoration.c @@ -140,6 +140,30 @@ static void server_decoration_manager_bind(struct wl_client *client, void *data, manager->default_mode); } +void wlr_server_decoration_manager_destroy( + struct wlr_server_decoration_manager *manager) { + if (manager == NULL) { + return; + } + struct wlr_server_decoration *decoration, *tmp_decoration; + wl_list_for_each_safe(decoration, tmp_decoration, &manager->decorations, + link) { + server_decoration_destroy(decoration); + } + struct wl_resource *resource, *tmp_resource; + wl_resource_for_each_safe(resource, tmp_resource, &manager->wl_resources) { + server_decoration_manager_destroy_resource(resource); + } + wl_global_destroy(manager->wl_global); + free(manager); +} + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_server_decoration_manager *manager = + wl_container_of(listener, manager, display_destroy); + wlr_server_decoration_manager_destroy(manager); +} + struct wlr_server_decoration_manager *wlr_server_decoration_manager_create( struct wl_display *display) { struct wlr_server_decoration_manager *manager = @@ -158,23 +182,9 @@ struct wlr_server_decoration_manager *wlr_server_decoration_manager_create( wl_list_init(&manager->wl_resources); wl_list_init(&manager->decorations); wl_signal_init(&manager->events.new_decoration); - return manager; -} -void wlr_server_decoration_manager_destroy( - struct wlr_server_decoration_manager *manager) { - if (manager == NULL) { - return; - } - struct wlr_server_decoration *decoration, *tmp_decoration; - wl_list_for_each_safe(decoration, tmp_decoration, &manager->decorations, - link) { - server_decoration_destroy(decoration); - } - struct wl_resource *resource, *tmp_resource; - wl_resource_for_each_safe(resource, tmp_resource, &manager->wl_resources) { - server_decoration_manager_destroy_resource(resource); - } - wl_global_destroy(manager->wl_global); - free(manager); + manager->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &manager->display_destroy); + + return manager; } -- cgit v1.2.3 From e6d2e72401200743ba13e20945dfad9f458a87e1 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 7 Dec 2017 00:44:45 +0100 Subject: Remove display destroy listeners, add compositor listener --- include/wlr/types/wlr_compositor.h | 7 ++----- types/wlr_compositor.c | 16 +++++++++++++++- types/wlr_screenshooter.c | 1 + types/wlr_server_decoration.c | 1 + 4 files changed, 19 insertions(+), 6 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_compositor.h b/include/wlr/types/wlr_compositor.h index b2f5a972..ceeb64ca 100644 --- a/include/wlr/types/wlr_compositor.h +++ b/include/wlr/types/wlr_compositor.h @@ -9,7 +9,8 @@ struct wlr_compositor { struct wl_list wl_resources; struct wlr_renderer *renderer; struct wl_list surfaces; - struct wl_listener destroy_surface_listener; + + struct wl_listener display_destroy; struct { struct wl_signal create_surface; @@ -20,8 +21,4 @@ void wlr_compositor_destroy(struct wlr_compositor *wlr_compositor); struct wlr_compositor *wlr_compositor_create(struct wl_display *display, struct wlr_renderer *renderer); -struct wlr_surface; -void wl_compositor_surface_destroyed(struct wlr_compositor *wlr_compositor, - struct wlr_surface *surface); - #endif diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index 986b7e60..919d0e32 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -78,6 +78,7 @@ static void wl_compositor_bind(struct wl_client *wl_client, void *data, } void wlr_compositor_destroy(struct wlr_compositor *compositor) { + wl_list_remove(&compositor->display_destroy.link); wl_global_destroy(compositor->wl_global); free(compositor); } @@ -151,6 +152,12 @@ static void subcompositor_bind(struct wl_client *client, void *data, compositor, NULL); } +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_compositor *compositor = + wl_container_of(listener, compositor, display_destroy); + wlr_compositor_destroy(compositor); +} + struct wlr_compositor *wlr_compositor_create(struct wl_display *display, struct wlr_renderer *renderer) { struct wlr_compositor *compositor = @@ -162,7 +169,11 @@ struct wlr_compositor *wlr_compositor_create(struct wl_display *display, struct wl_global *compositor_global = wl_global_create(display, &wl_compositor_interface, 4, compositor, wl_compositor_bind); - + if (!compositor_global) { + wlr_log_errno(L_ERROR, "Could not allocate compositor global"); + free(compositor); + return NULL; + } compositor->wl_global = compositor_global; compositor->renderer = renderer; @@ -173,5 +184,8 @@ struct wlr_compositor *wlr_compositor_create(struct wl_display *display, wl_list_init(&compositor->surfaces); wl_signal_init(&compositor->events.create_surface); + compositor->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &compositor->display_destroy); + return compositor; } diff --git a/types/wlr_screenshooter.c b/types/wlr_screenshooter.c index cb831827..8939f073 100644 --- a/types/wlr_screenshooter.c +++ b/types/wlr_screenshooter.c @@ -165,6 +165,7 @@ void wlr_screenshooter_destroy(struct wlr_screenshooter *screenshooter) { return; } wl_signal_emit(&screenshooter->events.destroy, screenshooter); + wl_list_remove(&screenshooter->display_destroy.link); struct wlr_screenshot *screenshot, *tmp; wl_list_for_each_safe(screenshot, tmp, &screenshooter->screenshots, link) { screenshot_destroy(screenshot); diff --git a/types/wlr_server_decoration.c b/types/wlr_server_decoration.c index 3531c453..09909bb6 100644 --- a/types/wlr_server_decoration.c +++ b/types/wlr_server_decoration.c @@ -145,6 +145,7 @@ void wlr_server_decoration_manager_destroy( if (manager == NULL) { return; } + wl_list_remove(&manager->display_destroy.link); struct wlr_server_decoration *decoration, *tmp_decoration; wl_list_for_each_safe(decoration, tmp_decoration, &manager->decorations, link) { -- cgit v1.2.3 From c7900663bc24e575b13a83ce77b7d46e8837d784 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 7 Dec 2017 00:50:55 +0100 Subject: Add display destroy listener to data device --- include/wlr/types/wlr_data_device.h | 2 ++ types/wlr_compositor.c | 3 +++ types/wlr_data_device.c | 26 ++++++++++++++++++-------- 3 files changed, 23 insertions(+), 8 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 12b25e45..70d79a19 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -15,6 +15,8 @@ wlr_touch_grab_interface wlr_data_device_touch_drag_interface; struct wlr_data_device_manager { struct wl_global *global; + + struct wl_listener display_destroy; }; struct wlr_data_offer { diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index 919d0e32..cf8c3f8f 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -78,6 +78,9 @@ static void wl_compositor_bind(struct wl_client *wl_client, void *data, } void wlr_compositor_destroy(struct wlr_compositor *compositor) { + if (compositor == NULL) { + return; + } wl_list_remove(&compositor->display_destroy.link); wl_global_destroy(compositor->wl_global); free(compositor); diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index a8d69cc0..dacb2a45 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -949,6 +949,21 @@ static void data_device_manager_bind(struct wl_client *client, NULL, NULL); } +void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager) { + if (!manager) { + return; + } + wl_list_remove(&manager->display_destroy.link); + wl_global_destroy(manager->global); + free(manager); +} + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_data_device_manager *manager = + wl_container_of(listener, manager, display_destroy); + wlr_data_device_manager_destroy(manager); +} + struct wlr_data_device_manager *wlr_data_device_manager_create( struct wl_display *display) { struct wlr_data_device_manager *manager = @@ -967,13 +982,8 @@ struct wlr_data_device_manager *wlr_data_device_manager_create( return NULL; } - return manager; -} + manager->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &manager->display_destroy); -void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager) { - if (!manager) { - return; - } - wl_global_destroy(manager->global); - free(manager); + return manager; } -- cgit v1.2.3 From 088ff9a614904181f68c861769655fac119bd8a0 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 7 Dec 2017 00:55:50 +0100 Subject: Listen to display destroy in gamma control manager --- include/wlr/types/wlr_gamma_control.h | 4 ++- types/wlr_gamma_control.c | 63 ++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 27 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_gamma_control.h b/include/wlr/types/wlr_gamma_control.h index 59f18494..d3f4b8e5 100644 --- a/include/wlr/types/wlr_gamma_control.h +++ b/include/wlr/types/wlr_gamma_control.h @@ -5,7 +5,9 @@ struct wlr_gamma_control_manager { struct wl_global *wl_global; - struct wl_list controls; // list of wlr_gamma_control + struct wl_list controls; // wlr_gamma_control::link + + struct wl_listener display_destroy; void *data; }; diff --git a/types/wlr_gamma_control.c b/types/wlr_gamma_control.c index 355e56a2..eb154b6b 100644 --- a/types/wlr_gamma_control.c +++ b/types/wlr_gamma_control.c @@ -12,6 +12,9 @@ static void resource_destroy(struct wl_client *client, } static void gamma_control_destroy(struct wlr_gamma_control *gamma_control) { + if (gamma_control == NULL) { + return; + } wl_signal_emit(&gamma_control->events.destroy, gamma_control); wl_list_remove(&gamma_control->output_destroy_listener.link); wl_resource_set_user_data(gamma_control->resource, NULL); @@ -67,7 +70,7 @@ static const struct gamma_control_interface gamma_control_impl = { static void gamma_control_manager_get_gamma_control(struct wl_client *client, struct wl_resource *gamma_control_manager_resource, uint32_t id, struct wl_resource *output_resource) { - struct wlr_gamma_control_manager *gamma_control_manager = + struct wlr_gamma_control_manager *manager = wl_resource_get_user_data(gamma_control_manager_resource); struct wlr_output *output = wl_resource_get_user_data(output_resource); @@ -99,7 +102,7 @@ static void gamma_control_manager_get_gamma_control(struct wl_client *client, gamma_control->output_destroy_listener.notify = gamma_control_handle_output_destroy; - wl_list_insert(&gamma_control_manager->controls, &gamma_control->link); + wl_list_insert(&manager->controls, &gamma_control->link); gamma_control_send_gamma_size(gamma_control->resource, wlr_output_get_gamma_size(output)); @@ -111,8 +114,8 @@ static struct gamma_control_manager_interface gamma_control_manager_impl = { static void gamma_control_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) { - struct wlr_gamma_control_manager *gamma_control_manager = data; - assert(client && gamma_control_manager); + struct wlr_gamma_control_manager *manager = data; + assert(client && manager); struct wl_resource *resource = wl_resource_create(client, &gamma_control_manager_interface, version, id); @@ -121,41 +124,49 @@ static void gamma_control_manager_bind(struct wl_client *client, void *data, return; } wl_resource_set_implementation(resource, &gamma_control_manager_impl, - gamma_control_manager, NULL); + manager, NULL); +} + +void wlr_gamma_control_manager_destroy( + struct wlr_gamma_control_manager *manager) { + if (!manager) { + return; + } + wl_list_remove(&manager->display_destroy.link); + struct wlr_gamma_control *gamma_control, *tmp; + wl_list_for_each_safe(gamma_control, tmp, &manager->controls, link) { + gamma_control_destroy(gamma_control); + } + wl_global_destroy(manager->wl_global); + free(manager); +} + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_gamma_control_manager *manager = + wl_container_of(listener, manager, display_destroy); + wlr_gamma_control_manager_destroy(manager); } struct wlr_gamma_control_manager *wlr_gamma_control_manager_create( struct wl_display *display) { - struct wlr_gamma_control_manager *gamma_control_manager = + struct wlr_gamma_control_manager *manager = calloc(1, sizeof(struct wlr_gamma_control_manager)); - if (!gamma_control_manager) { + if (!manager) { return NULL; } struct wl_global *wl_global = wl_global_create(display, - &gamma_control_manager_interface, 1, gamma_control_manager, + &gamma_control_manager_interface, 1, manager, gamma_control_manager_bind); if (!wl_global) { - free(gamma_control_manager); + free(manager); return NULL; } - gamma_control_manager->wl_global = wl_global; + manager->wl_global = wl_global; - wl_list_init(&gamma_control_manager->controls); + wl_list_init(&manager->controls); - return gamma_control_manager; -} + manager->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &manager->display_destroy); -void wlr_gamma_control_manager_destroy( - struct wlr_gamma_control_manager *gamma_control_manager) { - if (!gamma_control_manager) { - return; - } - struct wlr_gamma_control *gamma_control, *tmp; - wl_list_for_each_safe(gamma_control, tmp, &gamma_control_manager->controls, - link) { - gamma_control_destroy(gamma_control); - } - // TODO: this segfault (wl_display->registry_resource_list is not init) - // wl_global_destroy(gamma_control_manager->wl_global); - free(gamma_control_manager); + return manager; } -- cgit v1.2.3 From 983ea3033fdbf477e0810582501b0bbc1460f1c9 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 7 Dec 2017 01:02:07 +0100 Subject: Listen to display destroy in seat --- include/wlr/types/wlr_seat.h | 1 + types/wlr_seat.c | 51 +++++++++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 20 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 6d59315b..fa2df530 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -183,6 +183,7 @@ struct wlr_seat { struct wlr_seat_keyboard_state keyboard_state; struct wlr_seat_touch_state touch_state; + struct wl_listener display_destroy; struct wl_listener selection_data_source_destroy; struct { diff --git a/types/wlr_seat.c b/types/wlr_seat.c index ff1cbf7f..c64cbef9 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -337,6 +337,34 @@ static const struct wlr_touch_grab_interface default_touch_grab_impl = { }; +void wlr_seat_destroy(struct wlr_seat *wlr_seat) { + if (!wlr_seat) { + return; + } + + wl_list_remove(&wlr_seat->display_destroy.link); + + struct wlr_seat_client *client, *tmp; + wl_list_for_each_safe(client, tmp, &wlr_seat->clients, link) { + // will destroy other resources as well + wl_resource_destroy(client->wl_resource); + } + + wl_global_destroy(wlr_seat->wl_global); + free(wlr_seat->pointer_state.default_grab); + free(wlr_seat->keyboard_state.default_grab); + free(wlr_seat->touch_state.default_grab); + free(wlr_seat->data_device); + free(wlr_seat->name); + free(wlr_seat); +} + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_seat *seat = + wl_container_of(listener, seat, display_destroy); + wlr_seat_destroy(seat); +} + struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) { struct wlr_seat *wlr_seat = calloc(1, sizeof(struct wlr_seat)); if (!wlr_seat) { @@ -418,27 +446,10 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) { wl_signal_init(&wlr_seat->events.touch_grab_begin); wl_signal_init(&wlr_seat->events.touch_grab_end); - return wlr_seat; -} - -void wlr_seat_destroy(struct wlr_seat *wlr_seat) { - if (!wlr_seat) { - return; - } - - struct wlr_seat_client *client, *tmp; - wl_list_for_each_safe(client, tmp, &wlr_seat->clients, link) { - // will destroy other resources as well - wl_resource_destroy(client->wl_resource); - } + wlr_seat->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &wlr_seat->display_destroy); - wl_global_destroy(wlr_seat->wl_global); - free(wlr_seat->pointer_state.default_grab); - free(wlr_seat->keyboard_state.default_grab); - free(wlr_seat->touch_state.default_grab); - free(wlr_seat->data_device); - free(wlr_seat->name); - free(wlr_seat); + return wlr_seat; } struct wlr_seat_client *wlr_seat_client_for_wl_client(struct wlr_seat *wlr_seat, -- cgit v1.2.3 From 9ddaea14a1b24bf755417bffce792b0d4a23a87c Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 7 Dec 2017 01:05:49 +0100 Subject: Listen to display destroy in wl-shell --- include/wlr/types/wlr_wl_shell.h | 2 ++ types/wlr_wl_shell.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_wl_shell.h b/include/wlr/types/wlr_wl_shell.h index 986f92e8..29446b04 100644 --- a/include/wlr/types/wlr_wl_shell.h +++ b/include/wlr/types/wlr_wl_shell.h @@ -12,6 +12,8 @@ struct wlr_wl_shell { struct wl_list popup_grabs; uint32_t ping_timeout; + struct wl_listener display_destroy; + struct { struct wl_signal new_surface; } events; diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index ee72856c..78154245 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -564,6 +564,12 @@ static void shell_bind(struct wl_client *wl_client, void *data, wl_list_insert(&wl_shell->wl_resources, wl_resource_get_link(wl_resource)); } +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_wl_shell *wl_shell = + wl_container_of(listener, wl_shell, display_destroy); + wlr_wl_shell_destroy(wl_shell); +} + struct wlr_wl_shell *wlr_wl_shell_create(struct wl_display *display) { struct wlr_wl_shell *wl_shell = calloc(1, sizeof(struct wlr_wl_shell)); if (!wl_shell) { @@ -581,6 +587,10 @@ struct wlr_wl_shell *wlr_wl_shell_create(struct wl_display *display) { wl_list_init(&wl_shell->surfaces); wl_list_init(&wl_shell->popup_grabs); wl_signal_init(&wl_shell->events.new_surface); + + wl_shell->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &wl_shell->display_destroy); + return wl_shell; } @@ -588,14 +598,14 @@ void wlr_wl_shell_destroy(struct wlr_wl_shell *wlr_wl_shell) { if (!wlr_wl_shell) { return; } + wl_list_remove(&wlr_wl_shell->display_destroy.link); struct wl_resource *resource = NULL, *temp = NULL; wl_resource_for_each_safe(resource, temp, &wlr_wl_shell->wl_resources) { struct wl_list *link = wl_resource_get_link(resource); wl_list_remove(link); } // TODO: destroy surfaces - // TODO: this segfault (wl_display->registry_resource_list is not init) - // wl_global_destroy(wlr_wl_shell->wl_global); + wl_global_destroy(wlr_wl_shell->wl_global); free(wlr_wl_shell); } -- cgit v1.2.3 From cbf5763c226661765fb87dcf30d60b04999c126b Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 7 Dec 2017 01:08:35 +0100 Subject: Listen to display destroy in xdg-shell-v6 --- include/wlr/types/wlr_xdg_shell_v6.h | 2 ++ types/wlr_xdg_shell_v6.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 4eb957be..b723a950 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -11,6 +11,8 @@ struct wlr_xdg_shell_v6 { struct wl_list popup_grabs; uint32_t ping_timeout; + struct wl_listener display_destroy; + struct { struct wl_signal new_surface; } events; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 2627246f..23d36b6f 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -1250,6 +1250,12 @@ static void xdg_shell_bind(struct wl_client *wl_client, void *data, } } +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_xdg_shell_v6 *xdg_shell = + wl_container_of(listener, xdg_shell, display_destroy); + wlr_xdg_shell_v6_destroy(xdg_shell); +} + struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_create(struct wl_display *display) { struct wlr_xdg_shell_v6 *xdg_shell = calloc(1, sizeof(struct wlr_xdg_shell_v6)); @@ -1272,6 +1278,9 @@ struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_create(struct wl_display *display) { wl_signal_init(&xdg_shell->events.new_surface); + xdg_shell->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &xdg_shell->display_destroy); + return xdg_shell; } @@ -1279,8 +1288,8 @@ void wlr_xdg_shell_v6_destroy(struct wlr_xdg_shell_v6 *xdg_shell) { if (!xdg_shell) { return; } - // TODO: this segfault (wl_display->registry_resource_list is not init) - // wl_global_destroy(xdg_shell->wl_global); + wl_list_remove(&xdg_shell->display_destroy.link); + wl_global_destroy(xdg_shell->wl_global); free(xdg_shell); } -- cgit v1.2.3 From 0e066f0d7634b051981fbfb2fb75b2f8a4fe8594 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 7 Dec 2017 01:12:04 +0100 Subject: Listen to display destroy in output --- include/wlr/types/wlr_output.h | 2 ++ types/wlr_output.c | 11 +++++++++++ 2 files changed, 13 insertions(+) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 42c46233..04662820 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -74,6 +74,8 @@ struct wlr_output { // the output position in layout space reported to clients int32_t lx, ly; + struct wl_listener display_destroy; + void *data; }; diff --git a/types/wlr_output.c b/types/wlr_output.c index ed74004d..dda63181 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -112,6 +112,12 @@ static void wl_output_bind(struct wl_client *wl_client, void *data, wl_output_send_to_resource(wl_resource); } +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_output *output = + wl_container_of(listener, output, display_destroy); + wlr_output_destroy_global(output); +} + struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output, struct wl_display *display) { if (wlr_output->wl_global != NULL) { @@ -120,6 +126,10 @@ struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output, struct wl_global *wl_global = wl_global_create(display, &wl_output_interface, 3, wlr_output, wl_output_bind); wlr_output->wl_global = wl_global; + + wlr_output->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &wlr_output->display_destroy); + return wl_global; } @@ -127,6 +137,7 @@ void wlr_output_destroy_global(struct wlr_output *wlr_output) { if (wlr_output->wl_global == NULL) { return; } + wl_list_remove(&wlr_output->display_destroy.link); struct wl_resource *resource, *tmp; wl_resource_for_each_safe(resource, tmp, &wlr_output->wl_resources) { struct wl_list *link = wl_resource_get_link(resource); -- cgit v1.2.3 From bdb6e0b84ce69bea105dc54d3da013da4111f4ae Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 7 Dec 2017 01:19:41 +0100 Subject: Remove destroy event in screenshooter for now --- include/wlr/types/wlr_screenshooter.h | 4 ---- types/wlr_screenshooter.c | 2 -- 2 files changed, 6 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_screenshooter.h b/include/wlr/types/wlr_screenshooter.h index e8b59669..4c66be3f 100644 --- a/include/wlr/types/wlr_screenshooter.h +++ b/include/wlr/types/wlr_screenshooter.h @@ -9,10 +9,6 @@ struct wlr_screenshooter { struct wl_listener display_destroy; - struct { - struct wl_signal destroy; - } events; - void *data; }; diff --git a/types/wlr_screenshooter.c b/types/wlr_screenshooter.c index 8939f073..4d591c45 100644 --- a/types/wlr_screenshooter.c +++ b/types/wlr_screenshooter.c @@ -164,7 +164,6 @@ void wlr_screenshooter_destroy(struct wlr_screenshooter *screenshooter) { if (!screenshooter) { return; } - wl_signal_emit(&screenshooter->events.destroy, screenshooter); wl_list_remove(&screenshooter->display_destroy.link); struct wlr_screenshot *screenshot, *tmp; wl_list_for_each_safe(screenshot, tmp, &screenshooter->screenshots, link) { @@ -190,7 +189,6 @@ struct wlr_screenshooter *wlr_screenshooter_create(struct wl_display *display, screenshooter->renderer = renderer; wl_list_init(&screenshooter->screenshots); - wl_signal_init(&screenshooter->events.destroy); screenshooter->display_destroy.notify = handle_display_destroy; wl_display_add_destroy_listener(display, &screenshooter->display_destroy); -- cgit v1.2.3 From 18eb1eee3f97e169ff5fca67625452cbd81627c5 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 8 Dec 2017 00:59:37 +0100 Subject: Listen to display destroy in xwayland, rename wlr_egl_free --- backend/drm/renderer.c | 4 ++-- backend/wayland/backend.c | 2 +- backend/x11/backend.c | 2 +- include/wlr/render/egl.h | 3 ++- include/wlr/xwayland.h | 1 + render/egl.c | 2 +- types/wlr_wl_shell.c | 4 ++-- xwayland/xwayland.c | 18 ++++++++++++++++-- 8 files changed, 26 insertions(+), 10 deletions(-) (limited to 'include/wlr') diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 87064914..8a8d7d1f 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -39,7 +39,7 @@ bool wlr_drm_renderer_init(struct wlr_drm_backend *drm, return true; error_egl: - wlr_egl_free(&renderer->egl); + wlr_egl_finish(&renderer->egl); error_gbm: gbm_device_destroy(renderer->gbm); return false; @@ -51,7 +51,7 @@ void wlr_drm_renderer_finish(struct wlr_drm_renderer *renderer) { } wlr_renderer_destroy(renderer->wlr_rend); - wlr_egl_free(&renderer->egl); + wlr_egl_finish(&renderer->egl); gbm_device_destroy(renderer->gbm); } diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index cb241490..2bf155a5 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -83,7 +83,7 @@ static void wlr_wl_backend_destroy(struct wlr_backend *_backend) { free(backend->seat_name); wl_event_source_remove(backend->remote_display_src); - wlr_egl_free(&backend->egl); + wlr_egl_finish(&backend->egl); if (backend->seat) wl_seat_destroy(backend->seat); if (backend->shm) wl_shm_destroy(backend->shm); if (backend->shell) zxdg_shell_v6_destroy(backend->shell); diff --git a/backend/x11/backend.c b/backend/x11/backend.c index a4ca55b0..6c75405c 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -247,7 +247,7 @@ static void wlr_x11_backend_destroy(struct wlr_backend *backend) { wl_list_remove(&x11->display_destroy.link); wl_event_source_remove(x11->frame_timer); - wlr_egl_free(&x11->egl); + wlr_egl_finish(&x11->egl); xcb_disconnect(x11->xcb_conn); free(x11); diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h index 9ab4d9ce..67a81f37 100644 --- a/include/wlr/render/egl.h +++ b/include/wlr/render/egl.h @@ -4,6 +4,7 @@ #include #include #include +#include struct wlr_egl { EGLDisplay display; @@ -27,7 +28,7 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, EGLint visual_id, void * Frees all related egl resources, makes the context not-current and * unbinds a bound wayland display. */ -void wlr_egl_free(struct wlr_egl *egl); +void wlr_egl_finish(struct wlr_egl *egl); /** * Binds the given display to the egl instance. diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 792d2b88..455b1026 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -24,6 +24,7 @@ struct wlr_xwayland { struct wl_event_source *sigusr1_source; struct wl_listener destroy_listener; + struct wl_listener display_destroy; struct wlr_xwm *xwm; struct wlr_xwayland_cursor *cursor; diff --git a/render/egl.c b/render/egl.c index 22d58df2..e895df8d 100644 --- a/render/egl.c +++ b/render/egl.c @@ -141,7 +141,7 @@ error: return false; } -void wlr_egl_free(struct wlr_egl *egl) { +void wlr_egl_finish(struct wlr_egl *egl) { eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (egl->wl_display && eglUnbindWaylandDisplayWL) { eglUnbindWaylandDisplayWL(egl->display, egl->wl_display); diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index 78154245..5476ddb6 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -601,8 +601,8 @@ void wlr_wl_shell_destroy(struct wlr_wl_shell *wlr_wl_shell) { wl_list_remove(&wlr_wl_shell->display_destroy.link); struct wl_resource *resource = NULL, *temp = NULL; wl_resource_for_each_safe(resource, temp, &wlr_wl_shell->wl_resources) { - struct wl_list *link = wl_resource_get_link(resource); - wl_list_remove(link); + // shell_destroy will remove the resource from the list + wl_resource_destroy(resource); } // TODO: destroy surfaces wl_global_destroy(wlr_wl_shell->wl_global); diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index ecec785c..778b959d 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -147,6 +147,7 @@ static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { if (!wlr_xwayland || wlr_xwayland->display == -1) { return; } + if (wlr_xwayland->client) { wl_list_remove(&wlr_xwayland->destroy_listener.link); wl_client_destroy(wlr_xwayland->client); @@ -164,6 +165,8 @@ static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { safe_close(wlr_xwayland->wm_fd[0]); safe_close(wlr_xwayland->wm_fd[1]); + wl_list_remove(&wlr_xwayland->display_destroy.link); + unlink_display_sockets(wlr_xwayland->display); wlr_xwayland->display = -1; unsetenv("DISPLAY"); @@ -173,6 +176,12 @@ static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { */ } +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_xwayland *wlr_xwayland = + wl_container_of(listener, wlr_xwayland, display_destroy); + wlr_xwayland_destroy(wlr_xwayland); +} + static int xserver_handle_ready(int signal_number, void *data) { struct wlr_xwayland *wlr_xwayland = data; @@ -227,6 +236,9 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, wl_signal_init(&wlr_xwayland->events.new_surface); wl_signal_init(&wlr_xwayland->events.ready); + wlr_xwayland->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(wl_display, &wlr_xwayland->display_destroy); + wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd); if (wlr_xwayland->display < 0) { wlr_xwayland_finish(wlr_xwayland); @@ -253,10 +265,12 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, wlr_xwayland->wl_fd[0] = -1; /* not ours anymore */ wlr_xwayland->destroy_listener.notify = xwayland_destroy_event; - wl_client_add_destroy_listener(wlr_xwayland->client, &wlr_xwayland->destroy_listener); + wl_client_add_destroy_listener(wlr_xwayland->client, + &wlr_xwayland->destroy_listener); struct wl_event_loop *loop = wl_display_get_event_loop(wl_display); - wlr_xwayland->sigusr1_source = wl_event_loop_add_signal(loop, SIGUSR1, xserver_handle_ready, wlr_xwayland); + wlr_xwayland->sigusr1_source = wl_event_loop_add_signal(loop, SIGUSR1, + xserver_handle_ready, wlr_xwayland); if ((wlr_xwayland->pid = fork()) == 0) { /* Double-fork, but we need to forward SIGUSR1 once Xserver(1) -- cgit v1.2.3 From b06535718dd61d99ca904e4dbb503b8857456c46 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 8 Dec 2017 01:38:45 +0100 Subject: Do not destroy wl_client in wlr_xwayland_finish --- include/wlr/xwayland.h | 2 +- xwayland/xwayland.c | 53 +++++++++++++++++++++++++++----------------------- xwayland/xwm.c | 9 +++++++++ 3 files changed, 39 insertions(+), 25 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 455b1026..f6b43851 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -23,7 +23,7 @@ struct wlr_xwayland { time_t server_start; struct wl_event_source *sigusr1_source; - struct wl_listener destroy_listener; + struct wl_listener client_destroy; struct wl_listener display_destroy; struct wlr_xwm *xwm; struct wlr_xwayland_cursor *cursor; diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index 778b959d..a4b79e73 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -125,39 +125,26 @@ static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) { execvp("Xwayland", argv); } -static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, - struct wl_display *wl_display, struct wlr_compositor *compositor); -static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland); - -static void xwayland_destroy_event(struct wl_listener *listener, void *data) { - struct wlr_xwayland *wlr_xwayland = wl_container_of(listener, wlr_xwayland, destroy_listener); - - /* don't call client destroy */ - wlr_xwayland->client = NULL; - wl_list_remove(&wlr_xwayland->destroy_listener.link); - wlr_xwayland_finish(wlr_xwayland); - - if (time(NULL) - wlr_xwayland->server_start > 5) { - wlr_xwayland_init(wlr_xwayland, wlr_xwayland->wl_display, - wlr_xwayland->compositor); - } -} - static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { if (!wlr_xwayland || wlr_xwayland->display == -1) { return; } + if (wlr_xwayland->cursor != NULL) { + free(wlr_xwayland->cursor); + } + + xwm_destroy(wlr_xwayland->xwm); + if (wlr_xwayland->client) { - wl_list_remove(&wlr_xwayland->destroy_listener.link); - wl_client_destroy(wlr_xwayland->client); + wl_list_remove(&wlr_xwayland->client_destroy.link); + // TODO: this segfaults in /usr/lib/libEGL_mesa.so.0 + //wl_client_destroy(wlr_xwayland->client); } if (wlr_xwayland->sigusr1_source) { wl_event_source_remove(wlr_xwayland->sigusr1_source); } - xwm_destroy(wlr_xwayland->xwm); - safe_close(wlr_xwayland->x_fd[0]); safe_close(wlr_xwayland->x_fd[1]); safe_close(wlr_xwayland->wl_fd[0]); @@ -176,6 +163,24 @@ static void wlr_xwayland_finish(struct wlr_xwayland *wlr_xwayland) { */ } +static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, + struct wl_display *wl_display, struct wlr_compositor *compositor); + +static void handle_client_destroy(struct wl_listener *listener, void *data) { + struct wlr_xwayland *wlr_xwayland = + wl_container_of(listener, wlr_xwayland, client_destroy); + + /* don't call client destroy */ + wlr_xwayland->client = NULL; + wl_list_remove(&wlr_xwayland->client_destroy.link); + wlr_xwayland_finish(wlr_xwayland); + + if (time(NULL) - wlr_xwayland->server_start > 5) { + wlr_xwayland_init(wlr_xwayland, wlr_xwayland->wl_display, + wlr_xwayland->compositor); + } +} + static void handle_display_destroy(struct wl_listener *listener, void *data) { struct wlr_xwayland *wlr_xwayland = wl_container_of(listener, wlr_xwayland, display_destroy); @@ -264,9 +269,9 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland, wlr_xwayland->wl_fd[0] = -1; /* not ours anymore */ - wlr_xwayland->destroy_listener.notify = xwayland_destroy_event; + wlr_xwayland->client_destroy.notify = handle_client_destroy; wl_client_add_destroy_listener(wlr_xwayland->client, - &wlr_xwayland->destroy_listener); + &wlr_xwayland->client_destroy); struct wl_event_loop *loop = wl_display_get_event_loop(wl_display); wlr_xwayland->sigusr1_source = wl_event_loop_add_signal(loop, SIGUSR1, diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 562f2052..3250a97d 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1045,6 +1045,12 @@ void xwm_destroy(struct wlr_xwm *xwm) { if (xwm->cursor) { xcb_free_cursor(xwm->xcb_conn, xwm->cursor); } + if (xwm->colormap) { + xcb_free_colormap(xwm->xcb_conn, xwm->colormap); + } + if (xwm->window) { + xcb_destroy_window(xwm->xcb_conn, xwm->window); + } if (xwm->event_source) { wl_event_source_remove(xwm->event_source); } @@ -1052,6 +1058,9 @@ void xwm_destroy(struct wlr_xwm *xwm) { wl_list_for_each_safe(xsurface, tmp, &xwm->surfaces, link) { wlr_xwayland_surface_destroy(xsurface); } + wl_list_for_each_safe(xsurface, tmp, &xwm->unpaired_surfaces, link) { + wlr_xwayland_surface_destroy(xsurface); + } wl_list_remove(&xwm->compositor_surface_create.link); xcb_disconnect(xwm->xcb_conn); -- cgit v1.2.3 From 6001235b0465ba1961f8abd66a860bcf1f14fc22 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 8 Dec 2017 11:17:56 +0100 Subject: Listen to display destroy in session It's not the backend's responsibility to destroy the session anymore. --- backend/multi/backend.c | 1 - backend/session/session.c | 13 ++++++++++++- include/wlr/backend/session.h | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) (limited to 'include/wlr') diff --git a/backend/multi/backend.c b/backend/multi/backend.c index c35303e0..fc0c5b81 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -35,7 +35,6 @@ static void multi_backend_destroy(struct wlr_backend *_backend) { wlr_backend_destroy(sub->backend); free(sub); } - wlr_session_destroy(backend->session); free(backend); } diff --git a/backend/session/session.c b/backend/session/session.c index 657558fd..0ed54499 100644 --- a/backend/session/session.c +++ b/backend/session/session.c @@ -58,6 +58,12 @@ out: return 1; } +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_session *session = + wl_container_of(listener, session, display_destroy); + wlr_session_destroy(session); +} + struct wlr_session *wlr_session_create(struct wl_display *disp) { struct wlr_session *session = NULL; const struct session_impl **iter; @@ -100,6 +106,9 @@ struct wlr_session *wlr_session_create(struct wl_display *disp) { goto error_mon; } + session->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(disp, &session->display_destroy); + return session; error_mon: @@ -107,7 +116,7 @@ error_mon: error_udev: udev_unref(session->udev); error_session: - wlr_session_destroy(session); + session->impl->destroy(session); return NULL; } @@ -116,6 +125,8 @@ void wlr_session_destroy(struct wlr_session *session) { return; } + wl_list_remove(&session->display_destroy.link); + wl_event_source_remove(session->udev_event); udev_monitor_unref(session->mon); udev_unref(session->udev); diff --git a/include/wlr/backend/session.h b/include/wlr/backend/session.h index 5c822ea9..3242a13f 100644 --- a/include/wlr/backend/session.h +++ b/include/wlr/backend/session.h @@ -33,6 +33,8 @@ struct wlr_session { struct wl_event_source *udev_event; struct wl_list devices; + + struct wl_listener display_destroy; }; /* -- cgit v1.2.3