From 0beae99188d7885bed15eef548acf6b2a9fb9f79 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 31 Oct 2017 18:00:33 +0100 Subject: [PATCH 01/25] Apply output transformation to pointer events in Wayland backend --- backend/drm/drm.c | 44 ++++++----------------- backend/wayland/wl_seat.c | 23 ++++++++---- include/wlr/interfaces/wlr_output.h | 4 +++ types/wlr_output.c | 54 +++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 40 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 6cbb0535..cfaaae21 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -558,39 +558,17 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, } } - switch (output->transform) { - case WL_OUTPUT_TRANSFORM_90: - plane->cursor_hotspot_x = hotspot_x; - plane->cursor_hotspot_y = -plane->surf.height + hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_180: - plane->cursor_hotspot_x = plane->surf.width - hotspot_x; - plane->cursor_hotspot_y = plane->surf.height - hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_270: - plane->cursor_hotspot_x = -plane->surf.height + hotspot_x; - plane->cursor_hotspot_y = hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED: - plane->cursor_hotspot_x = plane->surf.width - hotspot_x; - plane->cursor_hotspot_y = hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_90: - plane->cursor_hotspot_x = hotspot_x; - plane->cursor_hotspot_y = -hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_180: - plane->cursor_hotspot_x = hotspot_x; - plane->cursor_hotspot_y = plane->surf.height - hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_270: - plane->cursor_hotspot_x = -plane->surf.height + hotspot_x; - plane->cursor_hotspot_y = plane->surf.width - hotspot_y; - break; - default: // WL_OUTPUT_TRANSFORM_NORMAL - plane->cursor_hotspot_x = hotspot_x; - plane->cursor_hotspot_y = hotspot_y; - } + struct wlr_box hotspot_box = { + .width = plane->surf.width, + .height = plane->surf.height, + .x = hotspot_x, + .y = hotspot_y, + }; + struct wlr_box transformed_hotspot_box; + wlr_output_transform_apply_to_box(output->transform, + &hotspot_box, &transformed_hotspot_box); + plane->cursor_hotspot_x = transformed_hotspot_box.x; + plane->cursor_hotspot_y = transformed_hotspot_box.y; if (!update_pixels) { // Only update the cursor hotspot diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 0d8e5b1f..deed215e 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -42,21 +42,30 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { struct wlr_input_device *dev = data; assert(dev && dev->pointer); - struct wlr_wl_pointer *wlr_wl_pointer = (struct wlr_wl_pointer *)dev->pointer; + struct wlr_wl_pointer *wlr_wl_pointer = + (struct wlr_wl_pointer *)dev->pointer; if (!wlr_wl_pointer->current_output) { wlr_log(L_ERROR, "pointer motion event without current output"); return; } - int width, height; + + struct wlr_box box; wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window, - &width, &height); + &box.width, &box.height); + 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); + struct wlr_event_pointer_motion_absolute wlr_event; wlr_event.device = dev; wlr_event.time_msec = time; - wlr_event.width_mm = width; - wlr_event.height_mm = height; - wlr_event.x_mm = wl_fixed_to_double(surface_x); - wlr_event.y_mm = wl_fixed_to_double(surface_y); + wlr_event.width_mm = transformed.width; + wlr_event.height_mm = transformed.height; + wlr_event.x_mm = transformed.x; + wlr_event.y_mm = transformed.y; wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event); } diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index d365e8f5..1f6c60eb 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -2,6 +2,7 @@ #define WLR_INTERFACES_WLR_OUTPUT_H #include +#include #include #include @@ -31,4 +32,7 @@ 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); + #endif diff --git a/types/wlr_output.c b/types/wlr_output.c index 44d24ae3..15b2f402 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -500,3 +500,57 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) { wl_list_remove(&cursor->link); free(cursor); } + +void wlr_output_transform_apply_to_box(enum wl_output_transform transform, + struct wlr_box *box, struct wlr_box *dest) { + switch (transform) { + case WL_OUTPUT_TRANSFORM_NORMAL: + case WL_OUTPUT_TRANSFORM_180: + case WL_OUTPUT_TRANSFORM_FLIPPED: + case WL_OUTPUT_TRANSFORM_FLIPPED_180: + dest->width = box->width; + dest->height = box->height; + break; + case WL_OUTPUT_TRANSFORM_90: + case WL_OUTPUT_TRANSFORM_270: + case WL_OUTPUT_TRANSFORM_FLIPPED_90: + case WL_OUTPUT_TRANSFORM_FLIPPED_270: + dest->width = box->height; + dest->height = box->width; + break; + } + + 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; + } +} From 510ce27fb75f53cd83d23e660cd45031cf2b937a Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 1 Nov 2017 10:57:24 +0100 Subject: [PATCH 02/25] Re-enable hardware cursors --- types/wlr_output.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index 15b2f402..08d32963 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -503,21 +503,12 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) { void wlr_output_transform_apply_to_box(enum wl_output_transform transform, struct wlr_box *box, struct wlr_box *dest) { - switch (transform) { - case WL_OUTPUT_TRANSFORM_NORMAL: - case WL_OUTPUT_TRANSFORM_180: - case WL_OUTPUT_TRANSFORM_FLIPPED: - case WL_OUTPUT_TRANSFORM_FLIPPED_180: + if (transform % 2 == 0) { dest->width = box->width; dest->height = box->height; - break; - case WL_OUTPUT_TRANSFORM_90: - case WL_OUTPUT_TRANSFORM_270: - case WL_OUTPUT_TRANSFORM_FLIPPED_90: - case WL_OUTPUT_TRANSFORM_FLIPPED_270: + } else { dest->width = box->height; dest->height = box->width; - break; } switch (transform) { @@ -552,5 +543,6 @@ void wlr_output_transform_apply_to_box(enum wl_output_transform transform, case WL_OUTPUT_TRANSFORM_FLIPPED_270: dest->x = box->height - box->y; dest->y = box->width - box->x; + break; } } From b23dd6a6f8b6b720e8354f70ae6c2ea906055b23 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 1 Nov 2017 09:08:35 -0400 Subject: [PATCH 03/25] wlr-seat bug: dont set focus surface to null then clear focus --- types/wlr_seat.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 1563c300..cfa60a6e 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -408,7 +408,6 @@ static void pointer_surface_destroy_notify(struct wl_listener *listener, listener, state, surface_destroy); wl_list_remove(&state->surface_destroy.link); wl_list_init(&state->surface_destroy.link); - state->focused_surface = NULL; wlr_seat_pointer_clear_focus(state->seat); } @@ -418,7 +417,6 @@ static void pointer_resource_destroy_notify(struct wl_listener *listener, listener, state, resource_destroy); wl_list_remove(&state->resource_destroy.link); wl_list_init(&state->resource_destroy.link); - state->focused_surface = NULL; wlr_seat_pointer_clear_focus(state->seat); } @@ -674,7 +672,6 @@ static void keyboard_surface_destroy_notify(struct wl_listener *listener, listener, state, surface_destroy); wl_list_remove(&state->surface_destroy.link); wl_list_init(&state->surface_destroy.link); - state->focused_surface = NULL; wlr_seat_keyboard_clear_focus(state->seat); } @@ -684,7 +681,6 @@ static void keyboard_resource_destroy_notify(struct wl_listener *listener, listener, state, resource_destroy); wl_list_remove(&state->resource_destroy.link); wl_list_init(&state->resource_destroy.link); - state->focused_surface = NULL; wlr_seat_keyboard_clear_focus(state->seat); } From 60c018c01760bef047d156a60e9ab32799a26f14 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 1 Nov 2017 14:25:41 +0100 Subject: [PATCH 04/25] Fix hidden software cursors, fix cursor transformations on DRM backend --- backend/drm/drm.c | 65 ++++++++++++++--------------- backend/wayland/output.c | 1 + include/wlr/interfaces/wlr_output.h | 1 + rootston/config.c | 4 +- types/wlr_output.c | 17 ++++++-- 5 files changed, 50 insertions(+), 38 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index cfaaae21..137ca85e 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -558,17 +558,28 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, } } - struct wlr_box hotspot_box = { - .width = plane->surf.width, - .height = plane->surf.height, - .x = hotspot_x, - .y = hotspot_y, - }; - struct wlr_box transformed_hotspot_box; - wlr_output_transform_apply_to_box(output->transform, - &hotspot_box, &transformed_hotspot_box); - plane->cursor_hotspot_x = transformed_hotspot_box.x; - plane->cursor_hotspot_y = transformed_hotspot_box.y; + switch (output->transform) { + case WL_OUTPUT_TRANSFORM_NORMAL: + case WL_OUTPUT_TRANSFORM_FLIPPED_90: + plane->cursor_hotspot_x = hotspot_x; + plane->cursor_hotspot_y = hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_90: + case WL_OUTPUT_TRANSFORM_FLIPPED_180: + plane->cursor_hotspot_x = hotspot_x; + plane->cursor_hotspot_y = -plane->surf.height + hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_180: + case WL_OUTPUT_TRANSFORM_FLIPPED_270: + plane->cursor_hotspot_x = -plane->surf.width + hotspot_x; + plane->cursor_hotspot_y = -plane->surf.height + hotspot_y; + break; + case WL_OUTPUT_TRANSFORM_FLIPPED: + case WL_OUTPUT_TRANSFORM_270: + plane->cursor_hotspot_x = -plane->surf.width + hotspot_x; + plane->cursor_hotspot_y = hotspot_y; + break; + } if (!update_pixels) { // Only update the cursor hotspot @@ -621,30 +632,18 @@ static bool wlr_drm_connector_move_cursor(struct wlr_output *output, x -= plane->cursor_hotspot_x; y -= plane->cursor_hotspot_y; - int width, height, tmp; - wlr_output_effective_resolution(output, &width, &height); + struct wlr_box box; + box.x = x; + box.y = y; + wlr_output_effective_resolution(output, &box.width, &box.height); - switch (output->transform) { - case WL_OUTPUT_TRANSFORM_NORMAL: - case WL_OUTPUT_TRANSFORM_FLIPPED: - case WL_OUTPUT_TRANSFORM_FLIPPED_180: - // nothing to do - break; - case WL_OUTPUT_TRANSFORM_270: - case WL_OUTPUT_TRANSFORM_FLIPPED_270: - tmp = x; - x = y; - y = -(tmp - width); - break; - case WL_OUTPUT_TRANSFORM_90: - case WL_OUTPUT_TRANSFORM_FLIPPED_90: - tmp = x; - x = -(y - height); - y = tmp; - break; - } + 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); - return drm->iface->crtc_move_cursor(drm, conn->crtc, x, y); + return drm->iface->crtc_move_cursor(drm, conn->crtc, transformed_box.x, + transformed_box.y); } static void wlr_drm_connector_destroy(struct wlr_output *output) { diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 494e0522..fd20b3e3 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -59,6 +59,7 @@ static bool wlr_wl_output_set_cursor(struct wlr_output *_output, (struct wlr_wl_backend_output *)_output; struct wlr_wl_backend *backend = output->backend; + // TODO: use output->wlr_output.transform to transform pixels and hotpot output->cursor.hotspot_x = hotspot_x; output->cursor.hotspot_y = hotspot_y; diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index 1f6c60eb..b4f39d35 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -34,5 +34,6 @@ 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/rootston/config.c b/rootston/config.c index b3fd4f01..d72c1284 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -228,7 +228,9 @@ static int config_ini_handler(void *user, const char *section, const char *name, } else if (strcmp(name, "y") == 0) { oc->y = strtol(value, NULL, 10); } else if (strcmp(name, "rotate") == 0) { - if (strcmp(value, "90") == 0) { + if (strcmp(value, "normal") == 0) { + oc->transform = WL_OUTPUT_TRANSFORM_NORMAL; + } else if (strcmp(value, "90") == 0) { oc->transform = WL_OUTPUT_TRANSFORM_90; } else if (strcmp(value, "180") == 0) { oc->transform = WL_OUTPUT_TRANSFORM_180; diff --git a/types/wlr_output.c b/types/wlr_output.c index 08d32963..6e36ae12 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -267,8 +267,8 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) { struct wlr_box output_box; output_box.x = output_box.y = 0; - output_box.width = cursor->output->width; - output_box.height = cursor->output->height; + wlr_output_effective_resolution(cursor->output, &output_box.width, + &output_box.height); struct wlr_box cursor_box; output_cursor_get_box(cursor, &cursor_box); @@ -294,7 +294,7 @@ void wlr_output_swap_buffers(struct wlr_output *output) { struct wlr_output_cursor *cursor; wl_list_for_each(cursor, &output->cursors, link) { if (output->hardware_cursor == cursor) { - continue; + //continue; // TODO } output_cursor_render(cursor); } @@ -342,7 +342,7 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, stride, width, height, hotspot_x, hotspot_y, true); if (ok) { cursor->output->hardware_cursor = cursor; - return true; + //return true; // TODO } } @@ -546,3 +546,12 @@ void wlr_output_transform_apply_to_box(enum wl_output_transform transform, break; } } + +enum wl_output_transform wlr_output_transform_invert( + enum wl_output_transform transform) { + if ((transform & WL_OUTPUT_TRANSFORM_90) && + !(transform & WL_OUTPUT_TRANSFORM_FLIPPED)) { + transform ^= WL_OUTPUT_TRANSFORM_180; + } + return transform; +} From a15b35aa105048fa01ac76eefcf0919cad29df20 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 1 Nov 2017 14:36:58 +0100 Subject: [PATCH 05/25] Remove mysterious hotspot switch in DRM backend --- backend/drm/drm.c | 57 +++++++++++++++++++++------------------------- types/wlr_output.c | 4 ++-- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 137ca85e..08e6296b 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -533,13 +533,14 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, return false; } - if (!wlr_drm_surface_init(&plane->surf, renderer, w, h, GBM_FORMAT_ARGB8888, 0)) { + if (!wlr_drm_surface_init(&plane->surf, renderer, w, h, + GBM_FORMAT_ARGB8888, 0)) { wlr_log(L_ERROR, "Cannot allocate cursor resources"); return false; } - plane->cursor_bo = gbm_bo_create(renderer->gbm, w, h, GBM_FORMAT_ARGB8888, - GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE); + plane->cursor_bo = gbm_bo_create(renderer->gbm, w, h, + GBM_FORMAT_ARGB8888, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE); if (!plane->cursor_bo) { wlr_log_errno(L_ERROR, "Failed to create cursor bo"); return false; @@ -552,34 +553,26 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, // TODO the image needs to be rotated depending on the output rotation - plane->wlr_tex = wlr_render_texture_create(plane->surf.renderer->wlr_rend); + plane->wlr_tex = + wlr_render_texture_create(plane->surf.renderer->wlr_rend); if (!plane->wlr_tex) { return false; } } - switch (output->transform) { - case WL_OUTPUT_TRANSFORM_NORMAL: - case WL_OUTPUT_TRANSFORM_FLIPPED_90: - plane->cursor_hotspot_x = hotspot_x; - plane->cursor_hotspot_y = hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_90: - case WL_OUTPUT_TRANSFORM_FLIPPED_180: - plane->cursor_hotspot_x = hotspot_x; - plane->cursor_hotspot_y = -plane->surf.height + hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_180: - case WL_OUTPUT_TRANSFORM_FLIPPED_270: - plane->cursor_hotspot_x = -plane->surf.width + hotspot_x; - plane->cursor_hotspot_y = -plane->surf.height + hotspot_y; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED: - case WL_OUTPUT_TRANSFORM_270: - plane->cursor_hotspot_x = -plane->surf.width + hotspot_x; - plane->cursor_hotspot_y = hotspot_y; - break; - } + struct wlr_box hotspot = { + .width = plane->surf.width, + .height = plane->surf.height, + .x = hotspot_x, + .y = hotspot_y, + }; + 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); + plane->cursor_hotspot_x = transformed_hotspot.x; + plane->cursor_hotspot_y = transformed_hotspot.y; if (!update_pixels) { // Only update the cursor hotspot @@ -609,11 +602,13 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, float matrix[16]; wlr_texture_get_matrix(plane->wlr_tex, &matrix, &plane->matrix, 0, 0); - wlr_render_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex, &matrix); + wlr_render_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex, + &matrix); glFinish(); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride); - glReadPixels(0, 0, plane->surf.width, plane->surf.height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, bo_data); + glReadPixels(0, 0, plane->surf.width, plane->surf.height, GL_BGRA_EXT, + GL_UNSIGNED_BYTE, bo_data); glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0); wlr_drm_surface_swap_buffers(&plane->surf); @@ -627,10 +622,7 @@ static bool wlr_drm_connector_move_cursor(struct wlr_output *output, int x, int y) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; - struct wlr_drm_plane *plane = conn->crtc->cursor; - x -= plane->cursor_hotspot_x; - y -= plane->cursor_hotspot_y; struct wlr_box box; box.x = x; @@ -642,6 +634,9 @@ static bool wlr_drm_connector_move_cursor(struct wlr_output *output, struct wlr_box transformed_box; wlr_output_transform_apply_to_box(transform, &box, &transformed_box); + transformed_box.x -= plane->cursor_hotspot_x; + transformed_box.y -= plane->cursor_hotspot_y; + return drm->iface->crtc_move_cursor(drm, conn->crtc, transformed_box.x, transformed_box.y); } diff --git a/types/wlr_output.c b/types/wlr_output.c index 6e36ae12..93d4de93 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -294,7 +294,7 @@ void wlr_output_swap_buffers(struct wlr_output *output) { struct wlr_output_cursor *cursor; wl_list_for_each(cursor, &output->cursors, link) { if (output->hardware_cursor == cursor) { - //continue; // TODO + continue; } output_cursor_render(cursor); } @@ -342,7 +342,7 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, stride, width, height, hotspot_x, hotspot_y, true); if (ok) { cursor->output->hardware_cursor = cursor; - //return true; // TODO + return true; } } From 0df7a3c22d3d6c2bc8969f1c4e4d10e2aa148325 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 1 Nov 2017 18:15:37 +0100 Subject: [PATCH 06/25] Add wlr_seat_pointer_request_set_cursor_event.serial --- include/wlr/types/wlr_seat.h | 1 + types/wlr_seat.c | 1 + 2 files changed, 2 insertions(+) diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index b1872a3d..b8b467d2 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -142,6 +142,7 @@ struct wlr_seat { struct wlr_seat_pointer_request_set_cursor_event { struct wlr_seat_client *seat_client; struct wlr_surface *surface; + uint32_t serial; int32_t hotspot_x, hotspot_y; }; diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 1e01c058..bdea96ac 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -43,6 +43,7 @@ static void wl_pointer_set_cursor(struct wl_client *client, } event->seat_client = seat_client; event->surface = surface; + event->serial = serial; event->hotspot_x = hotspot_x; event->hotspot_y = hotspot_y; From f451ea36393e8cedf29fd9877689b33ae770a8dc Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 1 Nov 2017 19:34:17 +0100 Subject: [PATCH 07/25] rootston exit: fix drm destroy wlr_drm_connector were being freed without removing them from the drm->outputs list, segfaulting on destroy --- backend/drm/backend.c | 4 ++-- backend/drm/drm.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/drm/backend.c b/backend/drm/backend.c index af2619ff..87a4f708 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -29,8 +29,8 @@ static void wlr_drm_backend_destroy(struct wlr_backend *backend) { wlr_drm_restore_outputs(drm); - struct wlr_drm_connector *conn; - wl_list_for_each(conn, &drm->outputs, link) { + struct wlr_drm_connector *conn, *next; + wl_list_for_each_safe(conn, next, &drm->outputs, link) { wlr_output_destroy(&conn->output); } diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 08e6296b..dd247998 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -645,6 +645,7 @@ static void wlr_drm_connector_destroy(struct wlr_output *output) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; wlr_drm_connector_cleanup(conn); wl_event_source_remove(conn->retry_pageflip); + wl_list_remove(&conn->link); free(conn); } @@ -823,6 +824,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { drmModeFreeCrtc(conn->old_crtc); wl_event_source_remove(conn->retry_pageflip); + wl_list_remove(&conn->link); free(conn); } } From e3ee2cd9c7e9abe6614dded927787f8138f739f4 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 1 Nov 2017 19:35:39 +0100 Subject: [PATCH 08/25] rootston exit: fix libinput destroy The wlr_list -> wl_list rework changed 'wlr_devices' to wl_list, but missed its use on destroy. --- backend/libinput/backend.c | 7 +++---- backend/libinput/events.c | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 781314a3..7e4d5700 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -99,13 +99,12 @@ static void wlr_libinput_backend_destroy(struct wlr_backend *_backend) { } struct wlr_libinput_backend *backend = (struct wlr_libinput_backend *)_backend; for (size_t i = 0; i < backend->wlr_device_lists->length; i++) { - struct wlr_list *wlr_devices = backend->wlr_device_lists->items[i]; - for (size_t j = 0; j < wlr_devices->length; j++) { - struct wlr_input_device *wlr_dev = wlr_devices->items[j]; + struct wl_list *wlr_devices = backend->wlr_device_lists->items[i]; + struct wlr_input_device *wlr_dev, *next; + wl_list_for_each_safe(wlr_dev, next, wlr_devices, link) { wl_signal_emit(&backend->backend.events.input_remove, wlr_dev); wlr_input_device_destroy(wlr_dev); } - wlr_list_free(wlr_devices); } wlr_list_free(backend->wlr_device_lists); wl_event_source_remove(backend->input_event); diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 053cab02..5da45c67 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -26,6 +26,7 @@ struct wlr_input_device *get_appropriate_device( static void wlr_libinput_device_destroy(struct wlr_input_device *_dev) { struct wlr_libinput_input_device *dev = (struct wlr_libinput_input_device *)_dev; libinput_device_unref(dev->handle); + wl_list_remove(&dev->wlr_input_device.link); free(dev); } From e18460c9811a8c9b0283aec330500f536747d078 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 1 Nov 2017 20:08:15 +0100 Subject: [PATCH 09/25] Add wlr_output.needs_swap --- include/wlr/types/wlr_output.h | 7 ++++--- types/wlr_output.c | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index f9bce91f..b5523100 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -1,9 +1,9 @@ #ifndef WLR_TYPES_WLR_OUTPUT_H #define WLR_TYPES_WLR_OUTPUT_H +#include #include #include -#include struct wlr_output_mode { uint32_t flags; // enum wl_output_mode @@ -44,8 +44,9 @@ struct wlr_output { uint32_t scale; int32_t width, height; int32_t phys_width, phys_height; // mm - int32_t subpixel; // enum wl_output_subpixel - int32_t transform; // enum wl_output_transform + enum wl_output_subpixel subpixel; + enum wl_output_transform transform; + bool needs_swap; float transform_matrix[16]; diff --git a/types/wlr_output.c b/types/wlr_output.c index 93d4de93..85e3d05e 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -291,6 +291,8 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) { } void wlr_output_swap_buffers(struct wlr_output *output) { + wl_signal_emit(&output->events.swap_buffers, &output); + struct wlr_output_cursor *cursor; wl_list_for_each(cursor, &output->cursors, link) { if (output->hardware_cursor == cursor) { @@ -299,9 +301,8 @@ void wlr_output_swap_buffers(struct wlr_output *output) { output_cursor_render(cursor); } - wl_signal_emit(&output->events.swap_buffers, &output); - output->impl->swap_buffers(output); + output->needs_swap = false; } void wlr_output_set_gamma(struct wlr_output *output, @@ -319,6 +320,9 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) { } static void output_cursor_reset(struct wlr_output_cursor *cursor) { + if (cursor->output->hardware_cursor != cursor) { + cursor->output->needs_swap = true; + } if (cursor->surface != NULL) { wl_list_remove(&cursor->surface_commit.link); wl_list_remove(&cursor->surface_destroy.link); @@ -347,6 +351,7 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, } wlr_log(L_INFO, "Falling back to software cursor"); + cursor->output->needs_swap = true; if (cursor->renderer == NULL) { cursor->renderer = wlr_gles2_renderer_create(cursor->output->backend); @@ -370,7 +375,11 @@ static void output_cursor_commit(struct wlr_output_cursor *cursor) { cursor->width = cursor->surface->current->width; cursor->height = cursor->surface->current->height; - // TODO: if hardware cursor, upload pixels + if (cursor->output->hardware_cursor != cursor) { + cursor->output->needs_swap = true; + } else { + // TODO: upload pixels + } } static inline int64_t timespec_to_msec(const struct timespec *a) { From bf225a60d83f45decf59792f01389f95975a1e0a Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 1 Nov 2017 20:01:22 +0100 Subject: [PATCH 10/25] rootston: flush 'close' command on Xwayland The close would otherwise wait for another xcb event to happen. Flushing helps 'close' feel reactive. --- xwayland/xwm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 15a23797..4930d45c 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1027,6 +1027,8 @@ void wlr_xwayland_surface_close(struct wlr_xwayland *wlr_xwayland, } else { xcb_kill_client(xwm->xcb_conn, xsurface->window_id); } + + xcb_flush(xwm->xcb_conn); } void xwm_destroy(struct wlr_xwm *xwm) { From 43cd3c7aea4c8171412a6822bf2c8308ee890b5e Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 1 Nov 2017 20:14:52 +0100 Subject: [PATCH 11/25] Indentation fix Some space sneaked in. tabtabtab. --- backend/libinput/backend.c | 2 +- backend/wayland/output.c | 2 +- backend/wayland/registry.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 7e4d5700..07c6da13 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -101,7 +101,7 @@ static void wlr_libinput_backend_destroy(struct wlr_backend *_backend) { for (size_t i = 0; i < backend->wlr_device_lists->length; i++) { struct wl_list *wlr_devices = backend->wlr_device_lists->items[i]; struct wlr_input_device *wlr_dev, *next; - wl_list_for_each_safe(wlr_dev, next, wlr_devices, link) { + wl_list_for_each_safe(wlr_dev, next, wlr_devices, link) { wl_signal_emit(&backend->backend.events.input_remove, wlr_dev); wlr_input_device_destroy(wlr_dev); } diff --git a/backend/wayland/output.c b/backend/wayland/output.c index fd20b3e3..90f8b39a 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -223,7 +223,7 @@ static void xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *x static void xdg_toplevel_handle_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel) { struct wlr_wl_backend_output *output = data; - assert(output && output->xdg_toplevel == xdg_toplevel); + assert(output && output->xdg_toplevel == xdg_toplevel); wl_display_terminate(output->backend->local_display); } diff --git a/backend/wayland/registry.c b/backend/wayland/registry.c index d6f61aa7..0dec0ec5 100644 --- a/backend/wayland/registry.c +++ b/backend/wayland/registry.c @@ -9,11 +9,11 @@ static void xdg_shell_handle_ping(void *data, struct zxdg_shell_v6 *shell, uint32_t serial) { - zxdg_shell_v6_pong(shell, serial); + zxdg_shell_v6_pong(shell, serial); } static const struct zxdg_shell_v6_listener xdg_shell_listener = { - xdg_shell_handle_ping, + xdg_shell_handle_ping, }; From 4f73498b78645728ff23adfbf9b650a1b66b66bb Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 1 Nov 2017 15:47:58 -0400 Subject: [PATCH 12/25] Move shared example code --- examples/meson.build | 3 ++- examples/multi-pointer.c | 6 +++--- examples/output-layout.c | 6 +++--- examples/pointer.c | 6 +++--- examples/rotation.c | 6 +++--- examples/simple.c | 2 +- examples/support/README | 2 ++ examples/{ => support}/cat.c | 0 examples/{ => support}/cat.h | 0 examples/{ => support}/config.c | 0 examples/{ => support}/config.h | 0 examples/{ => support}/ini.c | 0 examples/{ => support}/ini.h | 0 examples/{ => support}/shared.c | 0 examples/{ => support}/shared.h | 0 examples/tablet.c | 4 ++-- examples/touch.c | 4 ++-- 17 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 examples/support/README rename examples/{ => support}/cat.c (100%) rename examples/{ => support}/cat.h (100%) rename examples/{ => support}/config.c (100%) rename examples/{ => support}/config.h (100%) rename examples/{ => support}/ini.c (100%) rename examples/{ => support}/ini.h (100%) rename examples/{ => support}/shared.c (100%) rename examples/{ => support}/shared.h (100%) diff --git a/examples/meson.build b/examples/meson.build index 3402441b..89fc6211 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -1,7 +1,8 @@ lib_shared = static_library( 'shared', - ['shared.c', 'cat.c', 'ini.c', 'config.c'], + ['support/shared.c', 'support/cat.c', 'support/ini.c', 'support/config.c'], dependencies: wlroots, + include_directories: include_directories('support') ) executable('simple', 'simple.c', dependencies: wlroots, link_with: lib_shared) diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c index e0993987..e29a69db 100644 --- a/examples/multi-pointer.c +++ b/examples/multi-pointer.c @@ -22,9 +22,9 @@ #include #include #include -#include "shared.h" -#include "config.h" -#include "cat.h" +#include "support/shared.h" +#include "support/config.h" +#include "support/cat.h" struct sample_state; diff --git a/examples/output-layout.c b/examples/output-layout.c index 771ccd77..084bd7df 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -21,9 +21,9 @@ #include #include #include -#include "shared.h" -#include "config.h" -#include "cat.h" +#include "support/shared.h" +#include "support/config.h" +#include "support/cat.h" struct sample_state { struct example_config *config; diff --git a/examples/pointer.c b/examples/pointer.c index 8927314e..1bcd7349 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -22,9 +22,9 @@ #include #include #include -#include "shared.h" -#include "config.h" -#include "cat.h" +#include "support/shared.h" +#include "support/config.h" +#include "support/cat.h" struct sample_state { struct compositor_state *compositor; diff --git a/examples/rotation.c b/examples/rotation.c index d7892723..276b6255 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -18,9 +18,9 @@ #include #include #include -#include "shared.h" -#include "config.h" -#include "cat.h" +#include "support/shared.h" +#include "support/config.h" +#include "support/cat.h" struct sample_state { struct example_config *config; diff --git a/examples/simple.c b/examples/simple.c index ba1ac289..ad1b0792 100644 --- a/examples/simple.c +++ b/examples/simple.c @@ -11,7 +11,7 @@ #include #include #include -#include "shared.h" +#include "support/shared.h" struct sample_state { float color[3]; diff --git a/examples/support/README b/examples/support/README new file mode 100644 index 00000000..c32c873e --- /dev/null +++ b/examples/support/README @@ -0,0 +1,2 @@ +Support code for the examples. Code that's not relevant to the principle each +example demonstrates is largely offloaded to this directory. diff --git a/examples/cat.c b/examples/support/cat.c similarity index 100% rename from examples/cat.c rename to examples/support/cat.c diff --git a/examples/cat.h b/examples/support/cat.h similarity index 100% rename from examples/cat.h rename to examples/support/cat.h diff --git a/examples/config.c b/examples/support/config.c similarity index 100% rename from examples/config.c rename to examples/support/config.c diff --git a/examples/config.h b/examples/support/config.h similarity index 100% rename from examples/config.h rename to examples/support/config.h diff --git a/examples/ini.c b/examples/support/ini.c similarity index 100% rename from examples/ini.c rename to examples/support/ini.c diff --git a/examples/ini.h b/examples/support/ini.h similarity index 100% rename from examples/ini.h rename to examples/support/ini.h diff --git a/examples/shared.c b/examples/support/shared.c similarity index 100% rename from examples/shared.c rename to examples/support/shared.c diff --git a/examples/shared.h b/examples/support/shared.h similarity index 100% rename from examples/shared.h rename to examples/support/shared.h diff --git a/examples/tablet.c b/examples/tablet.c index 4b565d3d..4eaa204a 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -19,8 +19,8 @@ #include #include #include -#include "shared.h" -#include "cat.h" +#include "support/shared.h" +#include "support/cat.h" struct sample_state { struct wlr_renderer *renderer; diff --git a/examples/touch.c b/examples/touch.c index 3f0c4867..df6c6c48 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -18,8 +18,8 @@ #include #include #include -#include "shared.h" -#include "cat.h" +#include "support/shared.h" +#include "support/cat.h" struct sample_state { struct wlr_renderer *renderer; From 844b166c1bed117ef654de3f9ad68eebad67f6be Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 1 Nov 2017 20:59:28 +0100 Subject: [PATCH 13/25] multi_backend_destroy: fix trivial use-after-free --- backend/multi/backend.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/multi/backend.c b/backend/multi/backend.c index a7ee648c..c35303e0 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -30,8 +30,8 @@ static bool multi_backend_start(struct wlr_backend *_backend) { static void multi_backend_destroy(struct wlr_backend *_backend) { struct wlr_multi_backend *backend = (struct wlr_multi_backend *)_backend; - struct subbackend_state *sub; - wl_list_for_each(sub, &backend->backends, link) { + struct subbackend_state *sub, *next; + wl_list_for_each_safe(sub, next, &backend->backends, link) { wlr_backend_destroy(sub->backend); free(sub); } From b53db8c39e33c340214827097e26ccacbbcb5c08 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 1 Nov 2017 21:08:59 +0100 Subject: [PATCH 14/25] libinput backend destroy: fix small leak --- backend/libinput/backend.c | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 07c6da13..45b4e368 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -105,6 +105,7 @@ static void wlr_libinput_backend_destroy(struct wlr_backend *_backend) { wl_signal_emit(&backend->backend.events.input_remove, wlr_dev); wlr_input_device_destroy(wlr_dev); } + free(wlr_devices); } wlr_list_free(backend->wlr_device_lists); wl_event_source_remove(backend->input_event); From bdaf66a292ed77b3589ad5d4c4cf2bbf484df840 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 2 Nov 2017 00:03:55 +0100 Subject: [PATCH 15/25] Set xwayland root cursor --- meson.build | 1 + xwayland/meson.build | 1 + xwayland/xwm.c | 36 +++++++++++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 74bb6dcd..e37250a7 100644 --- a/meson.build +++ b/meson.build @@ -52,6 +52,7 @@ pixman = dependency('pixman-1') xcb = dependency('xcb') xcb_composite = dependency('xcb-composite') xcb_xfixes = dependency('xcb-xfixes') +xcb_image = dependency('xcb-image') xcb_icccm = dependency('xcb-icccm', required: false) x11_xcb = dependency('x11-xcb') libcap = dependency('libcap', required: false) diff --git a/xwayland/meson.build b/xwayland/meson.build index a05ae584..669a0984 100644 --- a/xwayland/meson.build +++ b/xwayland/meson.build @@ -11,6 +11,7 @@ lib_wlr_xwayland = static_library( xcb, xcb_composite, xcb_xfixes, + xcb_image, xcb_icccm, pixman, ], diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 4930d45c..b6a49574 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "wlr/util/log.h" #include "wlr/types/wlr_surface.h" #include "wlr/xwayland.h" @@ -1220,15 +1221,40 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { xwm_get_resources(xwm); xwm_get_visual_and_colormap(xwm); - uint32_t values[1]; - values[0] = + xcb_cursor_t cursor = xcb_generate_id(xwm->xcb_conn); + + { + // Create root cursor + + uint8_t data[] = { + 0x00, 0x00, 0xfe, 0x07, 0xfe, 0x03, 0xfe, 0x01, 0xfe, 0x01, 0xfe, 0x03, + 0xfe, 0x07, 0xfe, 0x0f, 0xfe, 0x1f, 0xe6, 0x0f, 0xc2, 0x07, 0x80, 0x03, + 0x00, 0x01, 0x00, 0x00 + }; + + uint8_t mask[] = { + 0xff, 0x3f, 0xff, 0x1f, 0xff, 0x07, 0xff, 0x03, 0xff, 0x03, 0xff, 0x07, + 0xff, 0x0f, 0xff, 0x1f, 0xff, 0x3f, 0xff, 0x1f, 0xe7, 0x0f, 0xc3, 0x07, + 0x83, 0x03, 0x01, 0x01 + }; + + xcb_pixmap_t cp = xcb_create_pixmap_from_bitmap_data(xwm->xcb_conn, xwm->screen->root, data, 14, 14, 1, 0, 0, 0); + xcb_pixmap_t mp = xcb_create_pixmap_from_bitmap_data(xwm->xcb_conn, xwm->screen->root, mask, 14, 14, 1, 0, 0, 0); + xcb_create_cursor(xwm->xcb_conn, cursor, cp, mp, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0, 0); + xcb_free_pixmap(xwm->xcb_conn, cp); + xcb_free_pixmap(xwm->xcb_conn, mp); + } + + uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | - XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | - XCB_EVENT_MASK_PROPERTY_CHANGE; + XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | + XCB_EVENT_MASK_PROPERTY_CHANGE, + cursor, + }; xcb_change_window_attributes(xwm->xcb_conn, xwm->screen->root, - XCB_CW_EVENT_MASK /* | XCB_CW_CURSOR */, + XCB_CW_EVENT_MASK | XCB_CW_CURSOR, values); xcb_composite_redirect_subwindows(xwm->xcb_conn, From f31fea79779e7ad119a7cd75340f6f51df7cebcf Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 2 Nov 2017 00:19:51 +0100 Subject: [PATCH 16/25] Fix CI build --- .build.yml | 1 + .travis.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.build.yml b/.build.yml index 60412f0e..7ba5559c 100644 --- a/.build.yml +++ b/.build.yml @@ -6,6 +6,7 @@ packages: - mesa - libinput - libxkbcommon + - xcb-util-image - libcap - pixman - clang diff --git a/.travis.yml b/.travis.yml index 52d6eae4..f6bbd7f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ arch: - libinput - pixman - libxkbcommon + - xcb-util-image - libcap script: - "meson build" From 4254c28138e33e0dfc7661f39a08a3be5a6f03a6 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 2 Nov 2017 11:09:14 +0100 Subject: [PATCH 17/25] Free xwm cursor in xwm_destroy --- xwayland/xwm.c | 11 ++++++----- xwayland/xwm.h | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index b6a49574..8f324411 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1036,6 +1036,9 @@ void xwm_destroy(struct wlr_xwm *xwm) { if (!xwm) { return; } + if (xwm->cursor) { + xcb_free_cursor(xwm->xcb_conn, xwm->cursor); + } if (xwm->event_source) { wl_event_source_remove(xwm->event_source); } @@ -1098,7 +1101,6 @@ static void xwm_get_resources(struct wlr_xwm *xwm) { xfixes_reply->major_version, xfixes_reply->minor_version); free(xfixes_reply); - } static void xwm_create_wm_window(struct wlr_xwm *xwm) { @@ -1221,8 +1223,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { xwm_get_resources(xwm); xwm_get_visual_and_colormap(xwm); - xcb_cursor_t cursor = xcb_generate_id(xwm->xcb_conn); - + xwm->cursor = xcb_generate_id(xwm->xcb_conn); { // Create root cursor @@ -1240,7 +1241,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { xcb_pixmap_t cp = xcb_create_pixmap_from_bitmap_data(xwm->xcb_conn, xwm->screen->root, data, 14, 14, 1, 0, 0, 0); xcb_pixmap_t mp = xcb_create_pixmap_from_bitmap_data(xwm->xcb_conn, xwm->screen->root, mask, 14, 14, 1, 0, 0, 0); - xcb_create_cursor(xwm->xcb_conn, cursor, cp, mp, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0, 0); + xcb_create_cursor(xwm->xcb_conn, xwm->cursor, cp, mp, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0, 0); xcb_free_pixmap(xwm->xcb_conn, cp); xcb_free_pixmap(xwm->xcb_conn, mp); } @@ -1249,7 +1250,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_PROPERTY_CHANGE, - cursor, + xwm->cursor, }; xcb_change_window_attributes(xwm->xcb_conn, diff --git a/xwayland/xwm.h b/xwayland/xwm.h index 7d30d278..ba1ed3c2 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -49,6 +49,7 @@ struct wlr_xwm { xcb_window_t window; xcb_visualid_t visual_id; xcb_colormap_t colormap; + xcb_cursor_t cursor; struct wlr_xwayland_surface *focus_surface; From d11973ed7d6881cbef879d505829b16be04b03f4 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 2 Nov 2017 11:37:43 +0100 Subject: [PATCH 18/25] Fix disabled cursors --- include/wlr/types/wlr_output.h | 2 ++ types/wlr_output.c | 28 +++++++++++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index b5523100..e6323f9c 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -15,10 +15,12 @@ struct wlr_output_mode { struct wlr_output_cursor { struct wlr_output *output; int32_t x, y; + bool enabled; uint32_t width, height; int32_t hotspot_x, hotspot_y; struct wl_list link; + // only when using a software cursor without a surface struct wlr_renderer *renderer; struct wlr_texture *texture; diff --git a/types/wlr_output.c b/types/wlr_output.c index 85e3d05e..d4c6b2fe 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -253,10 +253,6 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) { struct wlr_texture *texture = cursor->texture; struct wlr_renderer *renderer = cursor->renderer; if (cursor->surface != NULL) { - // Some clients commit a cursor surface with a NULL buffer to hide it. - if (!wlr_surface_has_buffer(cursor->surface)) { - return; - } texture = cursor->surface->texture; renderer = cursor->surface->renderer; } @@ -295,7 +291,7 @@ void wlr_output_swap_buffers(struct wlr_output *output) { struct wlr_output_cursor *cursor; wl_list_for_each(cursor, &output->cursors, link) { - if (output->hardware_cursor == cursor) { + if (!cursor->enabled || output->hardware_cursor == cursor) { continue; } output_cursor_render(cursor); @@ -353,6 +349,11 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, wlr_log(L_INFO, "Falling back to software cursor"); cursor->output->needs_swap = true; + cursor->enabled = pixels != NULL; + if (!cursor->enabled) { + return true; + } + if (cursor->renderer == NULL) { cursor->renderer = wlr_gles2_renderer_create(cursor->output->backend); if (cursor->renderer == NULL) { @@ -372,6 +373,8 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, } static void output_cursor_commit(struct wlr_output_cursor *cursor) { + // Some clients commit a cursor surface with a NULL buffer to hide it. + cursor->enabled = wlr_surface_has_buffer(cursor->surface); cursor->width = cursor->surface->current->width; cursor->height = cursor->surface->current->height; @@ -418,10 +421,6 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, return; } - if (surface) { - cursor->width = surface->current->width; - cursor->height = surface->current->height; - } cursor->hotspot_x = hotspot_x; cursor->hotspot_y = hotspot_y; @@ -454,6 +453,10 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, wl_signal_add(&surface->events.destroy, &cursor->surface_destroy); output_cursor_commit(cursor); } else { + cursor->enabled = false; + cursor->width = 0; + cursor->height = 0; + // TODO: if hardware cursor, disable cursor } } @@ -463,6 +466,7 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, int x, int y) { cursor->y = y; if (cursor->output->hardware_cursor != cursor) { + cursor->output->needs_swap = true; return true; } @@ -500,12 +504,6 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) { } cursor->output->hardware_cursor = NULL; } - if (cursor->texture != NULL) { - wlr_texture_destroy(cursor->texture); - } - if (cursor->renderer != NULL) { - wlr_renderer_destroy(cursor->renderer); - } wl_list_remove(&cursor->link); free(cursor); } From b46d2a8b33a798b42deee2a822dac004364e8337 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 2 Nov 2017 11:42:42 +0100 Subject: [PATCH 19/25] Fix wlr_output_cursor_destroy --- types/wlr_output.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/types/wlr_output.c b/types/wlr_output.c index d4c6b2fe..c4589487 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -504,6 +504,12 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) { } cursor->output->hardware_cursor = NULL; } + if (cursor->texture != NULL) { + wlr_texture_destroy(cursor->texture); + } + if (cursor->renderer != NULL) { + wlr_renderer_destroy(cursor->renderer); + } wl_list_remove(&cursor->link); free(cursor); } From ddd7b7711cabcabe73db6446bc02965fc645b244 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 2 Nov 2017 15:52:02 +0100 Subject: [PATCH 20/25] Load xwm cursor from theme --- meson.build | 1 + xwayland/meson.build | 1 + xwayland/xwm.c | 91 ++++++++++++++++++++++++++++++++------------ 3 files changed, 68 insertions(+), 25 deletions(-) diff --git a/meson.build b/meson.build index e37250a7..642dc38d 100644 --- a/meson.build +++ b/meson.build @@ -53,6 +53,7 @@ xcb = dependency('xcb') xcb_composite = dependency('xcb-composite') xcb_xfixes = dependency('xcb-xfixes') xcb_image = dependency('xcb-image') +xcb_render = dependency('xcb-render') xcb_icccm = dependency('xcb-icccm', required: false) x11_xcb = dependency('x11-xcb') libcap = dependency('libcap', required: false) diff --git a/xwayland/meson.build b/xwayland/meson.build index 669a0984..e92e042c 100644 --- a/xwayland/meson.build +++ b/xwayland/meson.build @@ -12,6 +12,7 @@ lib_wlr_xwayland = static_library( xcb_composite, xcb_xfixes, xcb_image, + xcb_render, xcb_icccm, pixman, ], diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 8f324411..8b94a199 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -6,9 +6,11 @@ #include #include #include +#include #include "wlr/util/log.h" #include "wlr/types/wlr_surface.h" #include "wlr/xwayland.h" +#include "wlr/xcursor.h" #include "xwm.h" #ifdef HAS_XCB_ICCCM @@ -1186,6 +1188,60 @@ static void xwm_get_visual_and_colormap(struct wlr_xwm *xwm) { xwm->visual_id); } +void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride, + uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y) { + if (xwm->cursor) { + xcb_free_cursor(xwm->xcb_conn, xwm->cursor); + } + + int depth = 32; + + xcb_pixmap_t pix = xcb_generate_id(xwm->xcb_conn); + xcb_create_pixmap(xwm->xcb_conn, depth, pix, xwm->screen->root, width, + height); + + xcb_render_query_pict_formats_cookie_t cookie = + xcb_render_query_pict_formats(xwm->xcb_conn); + xcb_generic_error_t *err = NULL; + xcb_render_query_pict_formats_reply_t *reply = + xcb_render_query_pict_formats_reply(xwm->xcb_conn, cookie, &err); + xcb_render_pictforminfo_t *formats = + xcb_render_query_pict_formats_formats(reply); + int len = xcb_render_query_pict_formats_formats_length(reply); + xcb_render_pictforminfo_t *format = NULL; + for (int i = 0; i < len; ++i) { + if (formats[i].depth == depth) { + format = &formats[i]; + break; + } + // TODO: segfaults when not found + } + if (format == NULL) { + wlr_log(L_ERROR, "Cannot find %d-bit depth render format", depth); + return; + } + + xcb_render_picture_t pic = xcb_generate_id(xwm->xcb_conn); + xcb_render_create_picture(xwm->xcb_conn, pic, pix, format->id, 0, 0); + + xcb_gcontext_t gc = xcb_generate_id(xwm->xcb_conn); + xcb_create_gc(xwm->xcb_conn, gc, pix, 0, NULL); + + xcb_put_image(xwm->xcb_conn, XCB_IMAGE_FORMAT_Z_PIXMAP, pix, gc, + width, height, 0, 0, 0, depth, stride * height * sizeof(uint8_t), + pixels); + xcb_free_gc(xwm->xcb_conn, gc); + + xwm->cursor = xcb_generate_id(xwm->xcb_conn); + xcb_render_create_cursor(xwm->xcb_conn, xwm->cursor, pic, hotspot_x, + hotspot_y); + xcb_free_pixmap(xwm->xcb_conn, pix); + + uint32_t values[] = {xwm->cursor}; + xcb_change_window_attributes(xwm->xcb_conn, xwm->screen->root, + XCB_CW_CURSOR, values); +} + struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { struct wlr_xwm *xwm = calloc(1, sizeof(struct wlr_xwm)); if (xwm == NULL) { @@ -1223,39 +1279,24 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { xwm_get_resources(xwm); xwm_get_visual_and_colormap(xwm); - xwm->cursor = xcb_generate_id(xwm->xcb_conn); - { - // Create root cursor - - uint8_t data[] = { - 0x00, 0x00, 0xfe, 0x07, 0xfe, 0x03, 0xfe, 0x01, 0xfe, 0x01, 0xfe, 0x03, - 0xfe, 0x07, 0xfe, 0x0f, 0xfe, 0x1f, 0xe6, 0x0f, 0xc2, 0x07, 0x80, 0x03, - 0x00, 0x01, 0x00, 0x00 - }; - - uint8_t mask[] = { - 0xff, 0x3f, 0xff, 0x1f, 0xff, 0x07, 0xff, 0x03, 0xff, 0x03, 0xff, 0x07, - 0xff, 0x0f, 0xff, 0x1f, 0xff, 0x3f, 0xff, 0x1f, 0xe7, 0x0f, 0xc3, 0x07, - 0x83, 0x03, 0x01, 0x01 - }; - - xcb_pixmap_t cp = xcb_create_pixmap_from_bitmap_data(xwm->xcb_conn, xwm->screen->root, data, 14, 14, 1, 0, 0, 0); - xcb_pixmap_t mp = xcb_create_pixmap_from_bitmap_data(xwm->xcb_conn, xwm->screen->root, mask, 14, 14, 1, 0, 0, 0); - xcb_create_cursor(xwm->xcb_conn, xwm->cursor, cp, mp, 0, 0, 0, 0xFFFF, 0xFFFF, 0xFFFF, 0, 0); - xcb_free_pixmap(xwm->xcb_conn, cp); - xcb_free_pixmap(xwm->xcb_conn, mp); - } + // TODO + struct wlr_xcursor_theme *xcursor_theme = + wlr_xcursor_theme_load("default", 16); + struct wlr_xcursor *xcursor = + wlr_xcursor_theme_get_cursor(xcursor_theme, "left_ptr"); + struct wlr_xcursor_image *xcursor_image = xcursor->images[0]; + xwm_set_cursor(xwm, xcursor_image->buffer, 4 * xcursor_image->width, + xcursor_image->width, xcursor_image->height, xcursor_image->hotspot_x, + xcursor_image->hotspot_y); uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_PROPERTY_CHANGE, - xwm->cursor, }; - xcb_change_window_attributes(xwm->xcb_conn, xwm->screen->root, - XCB_CW_EVENT_MASK | XCB_CW_CURSOR, + XCB_CW_EVENT_MASK, values); xcb_composite_redirect_subwindows(xwm->xcb_conn, From 3f4ad47421721c5df576e1a99e487a28a6318f82 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 2 Nov 2017 16:49:22 +0100 Subject: [PATCH 21/25] Use compositor theme for xwm cursor --- include/wlr/xwayland.h | 6 ++++++ rootston/input.c | 9 +++++++++ xwayland/xwayland.c | 40 ++++++++++++++++++++++++++++++++++++++++ xwayland/xwm.c | 12 ++---------- xwayland/xwm.h | 7 +++++-- 5 files changed, 62 insertions(+), 12 deletions(-) diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 2d968133..bea97394 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -12,6 +12,7 @@ #endif struct wlr_xwm; +struct wlr_xwayland_cursor; struct wlr_xwayland { pid_t pid; @@ -25,6 +26,7 @@ struct wlr_xwayland { struct wl_event_source *sigusr1_source; struct wl_listener destroy_listener; struct wlr_xwm *xwm; + struct wlr_xwayland_cursor *cursor; struct { struct wl_signal new_surface; @@ -148,6 +150,10 @@ struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display, void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland); +void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland, + uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height, + int32_t hotspot_x, int32_t hotspot_y); + void wlr_xwayland_surface_activate(struct wlr_xwayland *wlr_xwayland, struct wlr_xwayland_surface *surface, bool activated); diff --git a/rootston/input.c b/rootston/input.c index 8109d2b6..5d367a5e 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "rootston/server.h" #include "rootston/config.h" #include "rootston/input.h" @@ -96,6 +97,14 @@ struct roots_input *input_create(struct roots_server *server, return NULL; } + if (server->desktop->xwayland != NULL) { + struct wlr_xcursor_image *xcursor_image = xcursor->images[0]; + wlr_xwayland_set_cursor(server->desktop->xwayland, + xcursor_image->buffer, xcursor_image->width, xcursor_image->width, + xcursor_image->height, xcursor_image->hotspot_x, + xcursor_image->hotspot_y); + } + input->wl_seat = wlr_seat_create(server->wl_display, "seat0"); if (input->wl_seat == NULL) { wlr_log(L_ERROR, "Cannot create seat"); diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index 81bac2ce..0452f04c 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -29,6 +29,15 @@ static inline int clearenv(void) { } #endif +struct wlr_xwayland_cursor { + uint8_t *pixels; + uint32_t stride; + uint32_t width; + uint32_t height; + int32_t hotspot_x; + int32_t hotspot_y; +}; + static void safe_close(int fd) { if (fd >= 0) { close(fd); @@ -190,6 +199,14 @@ static int xserver_handle_ready(int signal_number, void *data) { wl_event_source_remove(wlr_xwayland->sigusr1_source); wlr_xwayland->sigusr1_source = NULL; + if (wlr_xwayland->cursor != NULL) { + struct wlr_xwayland_cursor *cur = wlr_xwayland->cursor; + xwm_set_cursor(wlr_xwayland->xwm, cur->pixels, cur->stride, cur->width, + cur->height, cur->hotspot_x, cur->hotspot_y); + free(cur); + wlr_xwayland->cursor = NULL; + } + char display_name[16]; snprintf(display_name, sizeof(display_name), ":%d", wlr_xwayland->display); setenv("DISPLAY", display_name, true); @@ -298,3 +315,26 @@ struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display, free(wlr_xwayland); return NULL; } + +void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland, + uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height, + int32_t hotspot_x, int32_t hotspot_y) { + if (wlr_xwayland->xwm != NULL) { + xwm_set_cursor(wlr_xwayland->xwm, pixels, stride, width, height, + hotspot_x, hotspot_y); + return; + } + + free(wlr_xwayland->cursor); + + wlr_xwayland->cursor = calloc(1, sizeof(struct wlr_xwayland_cursor)); + if (wlr_xwayland->cursor == NULL) { + return; + } + wlr_xwayland->cursor->pixels = pixels; + wlr_xwayland->cursor->stride = stride; + wlr_xwayland->cursor->width = width; + wlr_xwayland->cursor->height = height; + wlr_xwayland->cursor->hotspot_x = hotspot_x; + wlr_xwayland->cursor->hotspot_y = hotspot_y; +} diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 8b94a199..9d6bc347 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1194,6 +1194,7 @@ void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride, xcb_free_cursor(xwm->xcb_conn, xwm->cursor); } + stride *= 4; int depth = 32; xcb_pixmap_t pix = xcb_generate_id(xwm->xcb_conn); @@ -1240,6 +1241,7 @@ void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride, uint32_t values[] = {xwm->cursor}; xcb_change_window_attributes(xwm->xcb_conn, xwm->screen->root, XCB_CW_CURSOR, values); + xcb_flush(xwm->xcb_conn); } struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { @@ -1279,16 +1281,6 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { xwm_get_resources(xwm); xwm_get_visual_and_colormap(xwm); - // TODO - struct wlr_xcursor_theme *xcursor_theme = - wlr_xcursor_theme_load("default", 16); - struct wlr_xcursor *xcursor = - wlr_xcursor_theme_get_cursor(xcursor_theme, "left_ptr"); - struct wlr_xcursor_image *xcursor_image = xcursor->images[0]; - xwm_set_cursor(xwm, xcursor_image->buffer, 4 * xcursor_image->width, - xcursor_image->width, xcursor_image->height, xcursor_image->hotspot_x, - xcursor_image->hotspot_y); - uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | diff --git a/xwayland/xwm.h b/xwayland/xwm.h index ba1ed3c2..d3911ecd 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -61,8 +61,11 @@ struct wlr_xwm { struct wl_listener compositor_surface_create; }; -void xwm_destroy(struct wlr_xwm *xwm); - struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland); +void xwm_destroy(struct wlr_xwm *xwm); + +void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride, + uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y); + #endif From bb76f5264080be36138ec7c3e4dc3d83ed37d858 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 2 Nov 2017 16:59:57 +0100 Subject: [PATCH 22/25] Fetch xcb_render_pictformat_t at startup --- xwayland/xwm.c | 55 +++++++++++++++++++++++++++++--------------------- xwayland/xwm.h | 3 +++ 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 9d6bc347..9b75879e 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1175,7 +1175,7 @@ static void xwm_get_visual_and_colormap(struct wlr_xwm *xwm) { } if (visualtype == NULL) { - wlr_log(L_DEBUG, "no 32 bit visualtype\n"); + wlr_log(L_DEBUG, "No 32 bit visualtype\n"); return; } @@ -1188,8 +1188,36 @@ static void xwm_get_visual_and_colormap(struct wlr_xwm *xwm) { xwm->visual_id); } +static void xwm_get_render_format(struct wlr_xwm *xwm) { + xcb_render_query_pict_formats_cookie_t cookie = + xcb_render_query_pict_formats(xwm->xcb_conn); + xcb_render_query_pict_formats_reply_t *reply = + xcb_render_query_pict_formats_reply(xwm->xcb_conn, cookie, NULL); + xcb_render_pictforminfo_t *formats = + xcb_render_query_pict_formats_formats(reply); + int len = xcb_render_query_pict_formats_formats_length(reply); + xcb_render_pictforminfo_t *format = NULL; + for (int i = 0; i < len; ++i) { + if (formats[i].depth == 32) { + format = &formats[i]; + break; + } + // TODO: segfaults when not found + } + if (format == NULL) { + wlr_log(L_DEBUG, "No 32 bit render format"); + return; + } + + xwm->render_format_id = format->id; +} + void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y) { + if (!xwm->render_format_id) { + wlr_log(L_ERROR, "Cannot set xwm cursor: no render format available"); + return; + } if (xwm->cursor) { xcb_free_cursor(xwm->xcb_conn, xwm->cursor); } @@ -1201,29 +1229,9 @@ void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride, xcb_create_pixmap(xwm->xcb_conn, depth, pix, xwm->screen->root, width, height); - xcb_render_query_pict_formats_cookie_t cookie = - xcb_render_query_pict_formats(xwm->xcb_conn); - xcb_generic_error_t *err = NULL; - xcb_render_query_pict_formats_reply_t *reply = - xcb_render_query_pict_formats_reply(xwm->xcb_conn, cookie, &err); - xcb_render_pictforminfo_t *formats = - xcb_render_query_pict_formats_formats(reply); - int len = xcb_render_query_pict_formats_formats_length(reply); - xcb_render_pictforminfo_t *format = NULL; - for (int i = 0; i < len; ++i) { - if (formats[i].depth == depth) { - format = &formats[i]; - break; - } - // TODO: segfaults when not found - } - if (format == NULL) { - wlr_log(L_ERROR, "Cannot find %d-bit depth render format", depth); - return; - } - xcb_render_picture_t pic = xcb_generate_id(xwm->xcb_conn); - xcb_render_create_picture(xwm->xcb_conn, pic, pix, format->id, 0, 0); + xcb_render_create_picture(xwm->xcb_conn, pic, pix, xwm->render_format_id, + 0, 0); xcb_gcontext_t gc = xcb_generate_id(xwm->xcb_conn); xcb_create_gc(xwm->xcb_conn, gc, pix, 0, NULL); @@ -1280,6 +1288,7 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland) { xwm_get_resources(xwm); xwm_get_visual_and_colormap(xwm); + xwm_get_render_format(xwm); uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | diff --git a/xwayland/xwm.h b/xwayland/xwm.h index d3911ecd..547cd5eb 100644 --- a/xwayland/xwm.h +++ b/xwayland/xwm.h @@ -1,5 +1,7 @@ #ifndef XWAYLAND_INTERNALS_H #define XWAYLAND_INTERNALS_H + +#include #include #include @@ -49,6 +51,7 @@ struct wlr_xwm { xcb_window_t window; xcb_visualid_t visual_id; xcb_colormap_t colormap; + xcb_render_pictformat_t render_format_id; xcb_cursor_t cursor; struct wlr_xwayland_surface *focus_surface; From 900fb326f7608695a160a2ce645db94f33df7f87 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 2 Nov 2017 17:21:00 +0100 Subject: [PATCH 23/25] Fixes segfault when no xcb_render_pictforminfo_t is available --- xwayland/xwm.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 9b75879e..f011587e 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1193,17 +1193,18 @@ static void xwm_get_render_format(struct wlr_xwm *xwm) { xcb_render_query_pict_formats(xwm->xcb_conn); xcb_render_query_pict_formats_reply_t *reply = xcb_render_query_pict_formats_reply(xwm->xcb_conn, cookie, NULL); - xcb_render_pictforminfo_t *formats = - xcb_render_query_pict_formats_formats(reply); - int len = xcb_render_query_pict_formats_formats_length(reply); + xcb_render_pictforminfo_iterator_t iter = + xcb_render_query_pict_formats_formats_iterator(reply); xcb_render_pictforminfo_t *format = NULL; - for (int i = 0; i < len; ++i) { - if (formats[i].depth == 32) { - format = &formats[i]; + while (iter.rem > 0) { + if (iter.data->depth == 32) { + format = iter.data; break; } - // TODO: segfaults when not found + + xcb_render_pictforminfo_next(&iter); } + if (format == NULL) { wlr_log(L_DEBUG, "No 32 bit render format"); return; From 0384c9c094f923875aa17ea8be8b7574f4c96487 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 2 Nov 2017 19:24:48 +0100 Subject: [PATCH 24/25] Process surface position for software cursor hotspots --- types/wlr_output.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/types/wlr_output.c b/types/wlr_output.c index c4589487..24cc5892 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -279,10 +279,16 @@ static void output_cursor_render(struct wlr_output_cursor *cursor) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + int x = cursor->x - cursor->hotspot_x; + int y = cursor->y - cursor->hotspot_y; + if (cursor->surface != NULL) { + x += cursor->surface->current->sx; + y += cursor->surface->current->sy; + } + float matrix[16]; - wlr_texture_get_matrix(texture, &matrix, - &cursor->output->transform_matrix, cursor->x - cursor->hotspot_x, - cursor->y - cursor->hotspot_y); + wlr_texture_get_matrix(texture, &matrix, &cursor->output->transform_matrix, + x, y); wlr_render_with_matrix(renderer, texture, &matrix); } From f8de7aa0fd9b2e30fa13a22fc91e963c32c7cf7d Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 2 Nov 2017 23:14:24 +0100 Subject: [PATCH 25/25] Add checks for wl_resource_create --- types/wlr_compositor.c | 23 +++++++++++++--- types/wlr_data_device.c | 16 +++++------ types/wlr_gamma_control.c | 9 +++---- types/wlr_output.c | 8 ++++-- types/wlr_screenshooter.c | 50 ++++++++++++++++++++++------------- types/wlr_seat.c | 23 +++++++++++++--- types/wlr_server_decoration.c | 8 +++--- types/wlr_surface.c | 15 +++++++++-- types/wlr_wl_shell.c | 29 +++++++++++++------- types/wlr_xdg_shell_v6.c | 36 ++++++++++++++++++++----- 10 files changed, 154 insertions(+), 63 deletions(-) diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index cbb7f138..986b7e60 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -13,10 +13,21 @@ static void destroy_surface_listener(struct wl_listener *listener, void *data) { static void wl_compositor_create_surface(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct wlr_compositor *compositor = wl_resource_get_user_data(resource); + struct wl_resource *surface_resource = wl_resource_create(client, - &wl_surface_interface, wl_resource_get_version(resource), id); + &wl_surface_interface, wl_resource_get_version(resource), id); + if (surface_resource == NULL) { + wl_resource_post_no_memory(resource); + return; + } + struct wlr_surface *surface = wlr_surface_create(surface_resource, - compositor->renderer); + compositor->renderer); + if (surface == NULL) { + wl_resource_destroy(surface_resource); + wl_resource_post_no_memory(resource); + return; + } surface->compositor_data = compositor; surface->compositor_listener.notify = &destroy_surface_listener; wl_resource_add_destroy_listener(surface_resource, @@ -49,13 +60,17 @@ static void wl_compositor_destroy(struct wl_resource *resource) { } } -static void wl_compositor_bind(struct wl_client *wl_client, void *_compositor, +static void wl_compositor_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { - struct wlr_compositor *compositor = _compositor; + struct wlr_compositor *compositor = data; assert(wl_client && compositor); struct wl_resource *wl_resource = wl_resource_create(wl_client, &wl_compositor_interface, version, id); + if (wl_resource == NULL) { + wl_client_post_no_memory(wl_client); + return; + } wl_resource_set_implementation(wl_resource, &wl_compositor_impl, compositor, wl_compositor_destroy); wl_list_insert(&compositor->wl_resources, diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index 5800c0f3..ee83260e 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -233,6 +233,9 @@ static struct wlr_data_offer *wlr_data_source_send_offer( struct wlr_data_source *source, struct wl_resource *target) { struct wlr_data_offer *offer = calloc(1, sizeof(struct wlr_data_offer)); + if (offer == NULL) { + return NULL; + } offer->resource = wl_resource_create(wl_resource_get_client(target), @@ -781,18 +784,16 @@ data_device_manager_impl = { static void data_device_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) { - struct wl_resource *resource; - - resource = wl_resource_create(client, - &wl_data_device_manager_interface, - version, id); + struct wl_resource *resource = wl_resource_create(client, + &wl_data_device_manager_interface, + version, id); if (resource == NULL) { wl_client_post_no_memory(client); return; } - wl_resource_set_implementation(resource, - &data_device_manager_impl, NULL, NULL); + wl_resource_set_implementation(resource, &data_device_manager_impl, + NULL, NULL); } struct wlr_data_device_manager *wlr_data_device_manager_create( @@ -807,7 +808,6 @@ struct wlr_data_device_manager *wlr_data_device_manager_create( manager->global = wl_global_create(display, &wl_data_device_manager_interface, 3, NULL, data_device_manager_bind); - if (!manager->global) { wlr_log(L_ERROR, "could not create data device manager wl global"); free(manager); diff --git a/types/wlr_gamma_control.c b/types/wlr_gamma_control.c index e765c2a5..355e56a2 100644 --- a/types/wlr_gamma_control.c +++ b/types/wlr_gamma_control.c @@ -83,8 +83,8 @@ static void gamma_control_manager_get_gamma_control(struct wl_client *client, gamma_control->resource = wl_resource_create(client, &gamma_control_interface, version, id); if (gamma_control->resource == NULL) { - wl_client_post_no_memory(client); free(gamma_control); + wl_client_post_no_memory(client); return; } wlr_log(L_DEBUG, "new gamma_control %p (res %p)", gamma_control, @@ -109,10 +109,9 @@ static struct gamma_control_manager_interface gamma_control_manager_impl = { .get_gamma_control = gamma_control_manager_get_gamma_control, }; -static void gamma_control_manager_bind(struct wl_client *client, - void *_gamma_control_manager, uint32_t version, uint32_t id) { - struct wlr_gamma_control_manager *gamma_control_manager = - _gamma_control_manager; +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 wl_resource *resource = wl_resource_create(client, diff --git a/types/wlr_output.c b/types/wlr_output.c index 24cc5892..5456d064 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -91,13 +91,17 @@ static struct wl_output_interface wl_output_impl = { .release = wl_output_release }; -static void wl_output_bind(struct wl_client *wl_client, void *_wlr_output, +static void wl_output_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { - struct wlr_output *wlr_output = _wlr_output; + struct wlr_output *wlr_output = data; assert(wl_client && wlr_output); struct wl_resource *wl_resource = wl_resource_create(wl_client, &wl_output_interface, version, id); + if (wl_resource == NULL) { + wl_client_post_no_memory(wl_client); + return; + } wl_resource_set_implementation(wl_resource, &wl_output_impl, wlr_output, wl_output_destroy); wl_list_insert(&wlr_output->wl_resources, diff --git a/types/wlr_screenshooter.c b/types/wlr_screenshooter.c index c6def691..a78c7ad7 100644 --- a/types/wlr_screenshooter.c +++ b/types/wlr_screenshooter.c @@ -51,16 +51,17 @@ static void output_frame_notify(struct wl_listener *listener, void *_data) { } static void screenshooter_shoot(struct wl_client *client, - struct wl_resource *_screenshooter, uint32_t id, - struct wl_resource *_output, struct wl_resource *_buffer) { + struct wl_resource *screenshooter_resource, uint32_t id, + struct wl_resource *output_resource, + struct wl_resource *buffer_resource) { struct wlr_screenshooter *screenshooter = - wl_resource_get_user_data(_screenshooter); - struct wlr_output *output = wl_resource_get_user_data(_output); - if (!wl_shm_buffer_get(_buffer)) { + wl_resource_get_user_data(screenshooter_resource); + struct wlr_output *output = wl_resource_get_user_data(output_resource); + if (!wl_shm_buffer_get(buffer_resource)) { wlr_log(L_ERROR, "Invalid buffer: not a shared memory buffer"); return; } - struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get(_buffer); + struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get(buffer_resource); int32_t width = wl_shm_buffer_get_width(shm_buffer); int32_t height = wl_shm_buffer_get_height(shm_buffer); int32_t stride = wl_shm_buffer_get_stride(shm_buffer); @@ -84,23 +85,31 @@ static void screenshooter_shoot(struct wl_client *client, struct wlr_screenshot *screenshot = calloc(1, sizeof(struct wlr_screenshot)); if (!screenshot) { - wl_client_post_no_memory(client); + wl_resource_post_no_memory(screenshooter_resource); return; } - screenshot->output_resource = _output; + screenshot->output_resource = output_resource; screenshot->output = output; screenshot->screenshooter = screenshooter; screenshot->resource = wl_resource_create(client, - &orbital_screenshot_interface, wl_resource_get_version(_screenshooter), - id); - wlr_log(L_DEBUG, "new screenshot %p (res %p)", screenshot, - screenshot->resource); + &orbital_screenshot_interface, + wl_resource_get_version(screenshooter_resource), id); + if (screenshot->resource == NULL) { + free(screenshot); + wl_resource_post_no_memory(screenshooter_resource); + return; + } wl_resource_set_implementation(screenshot->resource, NULL, screenshot, NULL); + wlr_log(L_DEBUG, "new screenshot %p (res %p)", screenshot, + screenshot->resource); + struct screenshot_state *state = calloc(1, sizeof(struct screenshot_state)); if (!state) { - wl_client_post_no_memory(client); + wl_resource_destroy(screenshot->resource); + free(screenshot); + wl_resource_post_no_memory(screenshooter_resource); return; } state->width = width; @@ -117,13 +126,17 @@ static struct orbital_screenshooter_interface screenshooter_impl = { .shoot = screenshooter_shoot, }; -static void screenshooter_bind(struct wl_client *wl_client, - void *_screenshooter, uint32_t version, uint32_t id) { - struct wlr_screenshooter *screenshooter = _screenshooter; +static void screenshooter_bind(struct wl_client *wl_client, void *data, + uint32_t version, uint32_t id) { + struct wlr_screenshooter *screenshooter = data; assert(wl_client && screenshooter); struct wl_resource *wl_resource = wl_resource_create(wl_client, &orbital_screenshooter_interface, version, id); + if (wl_resource == NULL) { + wl_client_post_no_memory(wl_client); + return; + } wl_resource_set_implementation(wl_resource, &screenshooter_impl, screenshooter, NULL); } @@ -137,13 +150,12 @@ struct wlr_screenshooter *wlr_screenshooter_create(struct wl_display *display, } screenshooter->renderer = renderer; - struct wl_global *wl_global = wl_global_create(display, + screenshooter->wl_global = wl_global_create(display, &orbital_screenshooter_interface, 1, screenshooter, screenshooter_bind); - if (!wl_global) { + if (screenshooter->wl_global == NULL) { free(screenshooter); return NULL; } - screenshooter->wl_global = wl_global; return screenshooter; } diff --git a/types/wlr_seat.c b/types/wlr_seat.c index bdea96ac..76b34d31 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -65,9 +65,9 @@ static void wl_pointer_destroy(struct wl_resource *resource) { } static void wl_seat_get_pointer(struct wl_client *client, - struct wl_resource *pointer_resource, uint32_t id) { + struct wl_resource *seat_resource, uint32_t id) { struct wlr_seat_client *seat_client = - wl_resource_get_user_data(pointer_resource); + wl_resource_get_user_data(seat_resource); if (!(seat_client->seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) { return; } @@ -78,7 +78,11 @@ static void wl_seat_get_pointer(struct wl_client *client, wl_resource_destroy(seat_client->pointer); } seat_client->pointer = wl_resource_create(client, &wl_pointer_interface, - wl_resource_get_version(pointer_resource), id); + wl_resource_get_version(seat_resource), id); + if (seat_client->pointer == NULL) { + wl_resource_post_no_memory(seat_resource); + return; + } wl_resource_set_implementation(seat_client->pointer, &wl_pointer_impl, seat_client, &wl_pointer_destroy); } @@ -126,6 +130,10 @@ static void wl_seat_get_keyboard(struct wl_client *client, } seat_client->keyboard = wl_resource_create(client, &wl_keyboard_interface, wl_resource_get_version(seat_resource), id); + if (seat_client->keyboard == NULL) { + wl_resource_post_no_memory(seat_resource); + return; + } wl_resource_set_implementation(seat_client->keyboard, &wl_keyboard_impl, seat_client, &wl_keyboard_destroy); @@ -162,6 +170,10 @@ static void wl_seat_get_touch(struct wl_client *client, } seat_client->touch = wl_resource_create(client, &wl_touch_interface, wl_resource_get_version(seat_resource), id); + if (seat_client->touch == NULL) { + wl_resource_post_no_memory(seat_resource); + return; + } wl_resource_set_implementation(seat_client->touch, &wl_touch_impl, seat_client, &wl_touch_destroy); } @@ -213,6 +225,11 @@ static void wl_seat_bind(struct wl_client *client, void *_wlr_seat, } seat_client->wl_resource = wl_resource_create(client, &wl_seat_interface, version, id); + if (seat_client->wl_resource == NULL) { + free(seat_client); + wl_client_post_no_memory(client); + return; + } seat_client->client = client; seat_client->seat = wlr_seat; wl_resource_set_implementation(seat_client->wl_resource, &wl_seat_impl, diff --git a/types/wlr_server_decoration.c b/types/wlr_server_decoration.c index 0664edfb..60cc6369 100644 --- a/types/wlr_server_decoration.c +++ b/types/wlr_server_decoration.c @@ -73,8 +73,8 @@ static void server_decoration_manager_handle_create(struct wl_client *client, decoration->resource = wl_resource_create(client, &org_kde_kwin_server_decoration_interface, version, id); if (decoration->resource == NULL) { - wl_client_post_no_memory(client); free(decoration); + wl_client_post_no_memory(client); return; } wl_resource_set_implementation(decoration->resource, @@ -120,9 +120,9 @@ void server_decoration_manager_destroy_resource(struct wl_resource *resource) { wl_list_remove(wl_resource_get_link(resource)); } -static void server_decoration_manager_bind(struct wl_client *client, - void *_manager, uint32_t version, uint32_t id) { - struct wlr_server_decoration_manager *manager = _manager; +static void server_decoration_manager_bind(struct wl_client *client, void *data, + uint32_t version, uint32_t id) { + struct wlr_server_decoration_manager *manager = data; assert(client && manager); struct wl_resource *resource = wl_resource_create(client, diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 2a8c4d04..48971849 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -819,14 +819,21 @@ static void subsurface_handle_parent_destroy(struct wl_listener *listener, void wlr_surface_make_subsurface(struct wlr_surface *surface, struct wlr_surface *parent, uint32_t id) { + struct wl_client *client = wl_resource_get_client(surface->resource); assert(surface->subsurface == NULL); struct wlr_subsurface *subsurface = calloc(1, sizeof(struct wlr_subsurface)); if (!subsurface) { + wl_client_post_no_memory(client); return; } subsurface->cached = wlr_surface_state_create(); + if (subsurface->cached == NULL) { + free(subsurface); + wl_client_post_no_memory(client); + return; + } subsurface->synchronized = true; subsurface->surface = surface; @@ -840,10 +847,14 @@ void wlr_surface_make_subsurface(struct wlr_surface *surface, wl_list_insert(&parent->subsurface_pending_list, &subsurface->parent_pending_link); - struct wl_client *client = wl_resource_get_client(surface->resource); - subsurface->resource = wl_resource_create(client, &wl_subsurface_interface, 1, id); + if (subsurface->resource == NULL) { + wlr_surface_state_destroy(subsurface->cached); + free(subsurface); + wl_client_post_no_memory(client); + return; + } wl_resource_set_implementation(subsurface->resource, &subsurface_implementation, subsurface, diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index dd1f10b2..fe61075e 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -506,19 +506,19 @@ static int shell_surface_ping_timeout(void *user_data) { } static void shell_protocol_get_shell_surface(struct wl_client *client, - struct wl_resource *resource, uint32_t id, + struct wl_resource *shell_resource, uint32_t id, struct wl_resource *surface_resource) { struct wlr_surface *surface = wl_resource_get_user_data(surface_resource); if (wlr_surface_set_role(surface, wlr_wl_shell_surface_role, - resource, WL_SHELL_ERROR_ROLE)) { + shell_resource, WL_SHELL_ERROR_ROLE)) { return; } - struct wlr_wl_shell *wl_shell = wl_resource_get_user_data(resource); + struct wlr_wl_shell *wl_shell = wl_resource_get_user_data(shell_resource); struct wlr_wl_shell_surface *wl_surface = calloc(1, sizeof(struct wlr_wl_shell_surface)); if (wl_surface == NULL) { - wl_client_post_no_memory(client); + wl_resource_post_no_memory(shell_resource); return; } wl_list_init(&wl_surface->grab_link); @@ -530,13 +530,20 @@ static void shell_protocol_get_shell_surface(struct wl_client *client, wl_surface->surface = surface; wl_surface->resource = wl_resource_create(client, - &wl_shell_surface_interface, wl_resource_get_version(resource), id); - wlr_log(L_DEBUG, "new wl_shell %p (res %p)", wl_surface, - wl_surface->resource); + &wl_shell_surface_interface, wl_resource_get_version(shell_resource), + id); + if (wl_surface->resource == NULL) { + free(wl_surface); + wl_resource_post_no_memory(shell_resource); + return; + } wl_resource_set_implementation(wl_surface->resource, &shell_surface_impl, wl_surface, shell_surface_resource_destroy); + wlr_log(L_DEBUG, "new wl_shell %p (res %p)", wl_surface, + wl_surface->resource); + wl_signal_init(&wl_surface->events.destroy); wl_signal_init(&wl_surface->events.ping_timeout); wl_signal_init(&wl_surface->events.request_move); @@ -574,13 +581,17 @@ static void shell_destroy(struct wl_resource *resource) { wl_list_remove(wl_resource_get_link(resource)); } -static void shell_bind(struct wl_client *wl_client, void *_wl_shell, +static void shell_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { - struct wlr_wl_shell *wl_shell = _wl_shell; + struct wlr_wl_shell *wl_shell = data; assert(wl_client && wl_shell); struct wl_resource *wl_resource = wl_resource_create(wl_client, &wl_shell_interface, version, id); + if (wl_resource == NULL) { + wl_client_post_no_memory(wl_client); + return; + } wl_resource_set_implementation(wl_resource, &shell_impl, wl_shell, shell_destroy); wl_list_insert(&wl_shell->wl_resources, wl_resource_get_link(wl_resource)); diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index af551b10..fc45bc17 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -343,8 +343,8 @@ static void xdg_shell_create_positioner(struct wl_client *wl_client, wl_resource_get_version(resource), id); if (positioner->resource == NULL) { - wl_client_post_no_memory(wl_client); free(positioner); + wl_client_post_no_memory(wl_client); return; } @@ -480,13 +480,13 @@ static void xdg_surface_get_popup(struct wl_client *client, } if (wlr_surface_set_role(surface->surface, wlr_desktop_xdg_popup_role, - resource, ZXDG_SHELL_V6_ERROR_ROLE)) { + resource, ZXDG_SHELL_V6_ERROR_ROLE)) { return; } surface->popup_state = calloc(1, sizeof(struct wlr_xdg_popup_v6)); if (!surface->popup_state) { - wl_client_post_no_memory(client); + wl_resource_post_no_memory(resource); return; } @@ -495,6 +495,7 @@ static void xdg_surface_get_popup(struct wl_client *client, wl_resource_get_version(resource), id); if (surface->popup_state->resource == NULL) { free(surface->popup_state); + wl_resource_post_no_memory(resource); return; } @@ -735,7 +736,7 @@ static void xdg_surface_get_toplevel(struct wl_client *client, surface->toplevel_state = calloc(1, sizeof(struct wlr_xdg_toplevel_v6)); if (surface->toplevel_state == NULL) { - wl_client_post_no_memory(client); + wl_resource_post_no_memory(resource); return; } @@ -744,6 +745,11 @@ static void xdg_surface_get_toplevel(struct wl_client *client, struct wl_resource *toplevel_resource = wl_resource_create(client, &zxdg_toplevel_v6_interface, wl_resource_get_version(resource), id); + if (toplevel_resource == NULL) { + free(surface->toplevel_state); + wl_resource_post_no_memory(resource); + return; + } surface->toplevel_state->resource = toplevel_resource; @@ -1118,9 +1124,20 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, surface->resource = wl_resource_create(wl_client, &zxdg_surface_v6_interface, wl_resource_get_version(client_resource), id); + if (surface->resource == NULL) { + free(surface->next_geometry); + free(surface->geometry); + free(surface); + wl_client_post_no_memory(wl_client); + return; + } if (wlr_surface_has_buffer(surface->surface)) { - wl_resource_post_error(surface->resource, + wl_resource_destroy(surface->resource); + free(surface->next_geometry); + free(surface->geometry); + free(surface); + wl_resource_post_error(surface_resource, ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, "xdg_surface must not have a buffer at creation"); return; @@ -1199,9 +1216,9 @@ static int wlr_xdg_client_v6_ping_timeout(void *user_data) { return 1; } -static void xdg_shell_bind(struct wl_client *wl_client, void *_xdg_shell, +static void xdg_shell_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { - struct wlr_xdg_shell_v6 *xdg_shell = _xdg_shell; + struct wlr_xdg_shell_v6 *xdg_shell = data; assert(wl_client && xdg_shell); struct wlr_xdg_client_v6 *client = @@ -1215,6 +1232,11 @@ static void xdg_shell_bind(struct wl_client *wl_client, void *_xdg_shell, client->resource = wl_resource_create(wl_client, &zxdg_shell_v6_interface, version, id); + if (client->resource == NULL) { + free(client); + wl_client_post_no_memory(wl_client); + return; + } client->client = wl_client; client->shell = xdg_shell;