From 8836b167bf0ff152de951f7fdabb1deae85f6e93 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 13 Mar 2018 19:21:08 -0400 Subject: store xdg-positioner properties on the popup --- include/wlr/types/wlr_xdg_shell_v6.h | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (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 7dc746ce..42eb332a 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -32,6 +32,62 @@ struct wlr_xdg_client_v6 { struct wl_event_source *ping_timer; }; +enum wlr_positioner_v6_anchor { + /** + * the center of the anchor rectangle + */ + WLR_POSITIONER_V6_ANCHOR_NONE = 0, + /** + * the top edge of the anchor rectangle + */ + WLR_POSITIONER_V6_ANCHOR_TOP = 1, + /** + * the bottom edge of the anchor rectangle + */ + WLR_POSITIONER_V6_ANCHOR_BOTTOM = 2, + /** + * the left edge of the anchor rectangle + */ + WLR_POSITIONER_V6_ANCHOR_LEFT = 4, + /** + * the right edge of the anchor rectangle + */ + WLR_POSITIONER_V6_ANCHOR_RIGHT = 8, +}; + +enum wlr_positioner_v6_gravity { + /** + * center over the anchor edge + */ + WLR_POSITIONER_V6_GRAVITY_NONE = 0, + /** + * position above the anchor edge + */ + WLR_POSITIONER_V6_GRAVITY_TOP = 1, + /** + * position below the anchor edge + */ + WLR_POSITIONER_V6_GRAVITY_BOTTOM = 2, + /** + * position to the left of the anchor edge + */ + WLR_POSITIONER_V6_GRAVITY_LEFT = 4, + /** + * position to the right of the anchor edge + */ + WLR_POSITIONER_V6_GRAVITY_RIGHT = 8, +}; + +enum wlr_positioner_v6_constraint_adjustment { + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_NONE = 0, + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_X = 1, + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_Y = 2, + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_X = 4, + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_Y = 8, + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_X = 16, + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y = 32, +}; + struct wlr_xdg_popup_v6 { struct wlr_xdg_surface_v6 *base; struct wl_list link; @@ -42,6 +98,10 @@ struct wlr_xdg_popup_v6 { struct wlr_seat *seat; struct wlr_box geometry; + enum wlr_positioner_v6_anchor anchor; + enum wlr_positioner_v6_gravity gravity; + enum wlr_positioner_v6_constraint_adjustment constraint_adjustment; + struct wl_list grab_link; // wlr_xdg_popup_grab_v6::popups }; -- cgit v1.2.3 From c63d94483b1e52817ca01ca82a867a78ebd39fa6 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 24 Mar 2018 18:30:28 -0400 Subject: Redesign wlr_texture - Textures are now immutable (apart from those created from raw pixels), no more invalid textures - Move all wl_drm stuff in wlr_renderer - Most of wlr_texture fields are now private - Remove some duplicated DMA-BUF code in the DRM backend - Add more assertions - Stride is now always given as bytes rather than pixels - Drop wl_shm functions Fun fact: this patch has been written 10,000 meters up in the air. --- backend/drm/drm.c | 23 +- backend/drm/renderer.c | 48 ++-- backend/wayland/output.c | 2 - examples/multi-pointer.c | 2 +- examples/output-layout.c | 6 +- examples/pointer.c | 4 +- examples/rotation.c | 6 +- examples/touch.c | 13 +- include/backend/drm/drm.h | 1 - include/render/gles2.h | 40 ++- include/wlr/render/egl.h | 16 +- include/wlr/render/interface.h | 41 ++-- include/wlr/render/wlr_renderer.h | 15 +- include/wlr/render/wlr_texture.h | 63 ++--- include/wlr/types/wlr_linux_dmabuf.h | 13 +- render/egl.c | 18 -- render/gles2/renderer.c | 124 ++++++---- render/gles2/texture.c | 464 ++++++++++++++--------------------- render/wlr_renderer.c | 43 +++- render/wlr_texture.c | 63 +++-- types/wlr_linux_dmabuf.c | 5 - types/wlr_output.c | 14 +- types/wlr_surface.c | 114 +++++---- types/wlr_xcursor_manager.c | 2 +- 24 files changed, 535 insertions(+), 605 deletions(-) (limited to 'include/wlr') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 524e80bb..94bfbc96 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -181,9 +181,6 @@ void wlr_drm_resources_free(struct wlr_drm_backend *drm) { if (plane->cursor_bo) { gbm_bo_destroy(plane->cursor_bo); } - if (plane->wlr_tex) { - wlr_texture_destroy(plane->wlr_tex); - } } free(drm->crtcs); @@ -586,12 +583,6 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, wlr_output_transform_invert(output->transform); wlr_matrix_projection(plane->matrix, plane->surf.width, plane->surf.height, transform); - - plane->wlr_tex = - wlr_render_texture_create(plane->surf.renderer->wlr_rend); - if (!plane->wlr_tex) { - return false; - } } struct wlr_box hotspot = { .x = hotspot_x, .y = hotspot_y }; @@ -637,13 +628,18 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, wlr_drm_surface_make_current(&plane->surf, NULL); - wlr_texture_upload_pixels(plane->wlr_tex, WL_SHM_FORMAT_ARGB8888, - stride, width, height, buf); - struct wlr_renderer *rend = plane->surf.renderer->wlr_rend; + + struct wlr_texture *texture = wlr_texture_from_pixels(rend, + WL_SHM_FORMAT_ARGB8888, stride, width, height, buf); + if (texture == NULL) { + wlr_log(L_ERROR, "Unable to create texture"); + return false; + } + wlr_renderer_begin(rend, plane->surf.width, plane->surf.height); wlr_renderer_clear(rend, (float[]){ 0.0, 0.0, 0.0, 0.0 }); - wlr_render_texture(rend, plane->wlr_tex, plane->matrix, 0, 0, 1.0f); + wlr_render_texture(rend, texture, plane->matrix, 0, 0, 1.0f); wlr_renderer_end(rend); wlr_renderer_read_pixels(rend, WL_SHM_FORMAT_ARGB8888, bo_stride, @@ -651,6 +647,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, wlr_drm_surface_swap_buffers(&plane->surf, NULL); + wlr_texture_destroy(texture); gbm_bo_unmap(plane->cursor_bo, bo_data); } diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index b2998b5f..2b50bb79 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -178,47 +178,33 @@ static void free_eglimage(struct gbm_bo *bo, void *data) { static struct wlr_texture *get_tex_for_bo(struct wlr_drm_renderer *renderer, struct gbm_bo *bo) { struct tex *tex = gbm_bo_get_user_data(bo); - if (tex) { + if (tex != NULL) { return tex->tex; } - // TODO: use wlr_texture_upload_dmabuf instead - - tex = malloc(sizeof(*tex)); - if (!tex) { - wlr_log_errno(L_ERROR, "Allocation failed"); + tex = calloc(1, sizeof(struct tex)); + if (tex == NULL) { return NULL; } - tex->egl = &renderer->egl; - - int dmabuf_fd = gbm_bo_get_fd(bo); - uint32_t width = gbm_bo_get_width(bo); - uint32_t height = gbm_bo_get_height(bo); - - EGLint attribs[] = { - EGL_WIDTH, width, - EGL_HEIGHT, height, - EGL_LINUX_DRM_FOURCC_EXT, gbm_bo_get_format(bo), - EGL_DMA_BUF_PLANE0_FD_EXT, dmabuf_fd, - EGL_DMA_BUF_PLANE0_OFFSET_EXT, gbm_bo_get_offset(bo, 0), - EGL_DMA_BUF_PLANE0_PITCH_EXT, gbm_bo_get_stride_for_plane(bo, 0), - EGL_IMAGE_PRESERVED_KHR, EGL_FALSE, - EGL_NONE, + struct wlr_dmabuf_buffer_attribs attribs = { + .n_planes = 1, + .width = gbm_bo_get_width(bo), + .height = gbm_bo_get_height(bo), + .format = gbm_bo_get_format(bo), }; - - tex->img = eglCreateImageKHR(renderer->egl.display, EGL_NO_CONTEXT, - EGL_LINUX_DMA_BUF_EXT, NULL, attribs); - if (!tex->img) { - wlr_log(L_ERROR, "Failed to create EGL image"); - abort(); + attribs.offset[0] = 0; + attribs.stride[0] = gbm_bo_get_stride_for_plane(bo, 0); + attribs.modifier[0] = 0; + attribs.fd[0] = gbm_bo_get_fd(bo); + + tex->tex = wlr_texture_from_dmabuf(renderer->wlr_rend, &attribs); + if (tex->tex == NULL) { + free(tex); + return NULL; } - tex->tex = wlr_render_texture_create(renderer->wlr_rend); - wlr_texture_upload_eglimage(tex->tex, tex->img, width, height); - gbm_bo_set_user_data(bo, tex, free_eglimage); - return tex->tex; } diff --git a/backend/wayland/output.c b/backend/wayland/output.c index d528c888..c1fa638a 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -99,8 +99,6 @@ static bool wlr_wl_output_set_cursor(struct wlr_output *_output, return true; } - stride *= 4; // stride is given in pixels, we need it in bytes - if (!backend->shm || !backend->pointer) { wlr_log(L_INFO, "cannot set cursor, no shm or pointer"); return false; diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c index 43ccdb66..1f869f50 100644 --- a/examples/multi-pointer.c +++ b/examples/multi-pointer.c @@ -149,7 +149,7 @@ static void handle_input_add(struct compositor_state *state, sample->compositor); struct wlr_xcursor_image *image = sample->xcursor->images[0]; - wlr_cursor_set_image(cursor->cursor, image->buffer, image->width, + wlr_cursor_set_image(cursor->cursor, image->buffer, image->width * 4, image->width, image->height, image->hotspot_x, image->hotspot_y, 0); wl_list_insert(&sample->cursors, &cursor->link); diff --git a/examples/output-layout.c b/examples/output-layout.c index 45d896b0..c1392a30 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -197,9 +197,9 @@ int main(int argc, char *argv[]) { compositor_init(&compositor); state.renderer = wlr_gles2_renderer_create(compositor.backend); - state.cat_texture = wlr_render_texture_create(state.renderer); - wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ABGR8888, - cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data); + state.cat_texture = wlr_texture_from_pixels(state.renderer, + WL_SHM_FORMAT_ABGR8888, cat_tex.width * 4, cat_tex.width, cat_tex.height, + cat_tex.pixel_data); if (!wlr_backend_start(compositor.backend)) { wlr_log(L_ERROR, "Failed to start backend"); diff --git a/examples/pointer.c b/examples/pointer.c index e8a0e892..9794e6e5 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -112,7 +112,7 @@ static void handle_output_add(struct output_state *ostate) { sample->compositor); struct wlr_xcursor_image *image = sample->xcursor->images[0]; - wlr_cursor_set_image(sample->cursor, image->buffer, image->width, + wlr_cursor_set_image(sample->cursor, image->buffer, image->width * 4, image->width, image->height, image->hotspot_x, image->hotspot_y, 0); wlr_cursor_warp(sample->cursor, NULL, sample->cursor->x, sample->cursor->y); @@ -324,7 +324,7 @@ int main(int argc, char *argv[]) { } struct wlr_xcursor_image *image = state.xcursor->images[0]; - wlr_cursor_set_image(state.cursor, image->buffer, image->width, + wlr_cursor_set_image(state.cursor, image->buffer, image->width * 4, image->width, image->height, image->hotspot_x, image->hotspot_y, 0); compositor_init(&compositor); diff --git a/examples/rotation.c b/examples/rotation.c index cbff09a1..dfafeeca 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -142,13 +142,13 @@ int main(int argc, char *argv[]) { wlr_log(L_ERROR, "Could not start compositor, OOM"); exit(EXIT_FAILURE); } - state.cat_texture = wlr_render_texture_create(state.renderer); + state.cat_texture = wlr_texture_from_pixels(state.renderer, + WL_SHM_FORMAT_ABGR8888, cat_tex.width * 4, cat_tex.width, cat_tex.height, + cat_tex.pixel_data); if (!state.cat_texture) { wlr_log(L_ERROR, "Could not start compositor, OOM"); exit(EXIT_FAILURE); } - wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ABGR8888, - cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data); if (!wlr_backend_start(compositor.backend)) { wlr_log(L_ERROR, "Failed to start backend"); diff --git a/examples/touch.c b/examples/touch.c index f9c496cf..7639165c 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -45,10 +45,13 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); + int tex_width, tex_height; + wlr_texture_get_size(sample->cat_texture, &tex_width, &tex_height); + struct touch_point *p; wl_list_for_each(p, &sample->touch_points, link) { - int x = (int)(p->x * width) - sample->cat_texture->width / 2; - int y = (int)(p->y * height) - sample->cat_texture->height / 2; + int x = (int)(p->x * width) - tex_width / 2; + int y = (int)(p->y * height) - tex_height / 2; wlr_render_texture(sample->renderer, sample->cat_texture, wlr_output->transform_matrix, x, y, 1.0f); } @@ -110,13 +113,13 @@ int main(int argc, char *argv[]) { wlr_log(L_ERROR, "Could not start compositor, OOM"); exit(EXIT_FAILURE); } - state.cat_texture = wlr_render_texture_create(state.renderer); + state.cat_texture = wlr_texture_from_pixels(state.renderer, + WL_SHM_FORMAT_ARGB8888, cat_tex.width * 4, cat_tex.width, cat_tex.height, + cat_tex.pixel_data); if (!state.cat_texture) { wlr_log(L_ERROR, "Could not start compositor, OOM"); exit(EXIT_FAILURE); } - wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ARGB8888, - cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data); if (!wlr_backend_start(compositor.backend)) { wlr_log(L_ERROR, "Failed to start backend"); diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index 26189340..cb10ad20 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -27,7 +27,6 @@ struct wlr_drm_plane { // Only used by cursor float matrix[9]; - struct wlr_texture *wlr_tex; struct gbm_bo *cursor_bo; bool cursor_enabled; int32_t cursor_hotspot_x, cursor_hotspot_y; diff --git a/include/render/gles2.h b/include/render/gles2.h index 43a8d648..09295415 100644 --- a/include/render/gles2.h +++ b/include/render/gles2.h @@ -38,21 +38,49 @@ struct wlr_gles2_renderer { } shaders; }; +enum wlr_gles2_texture_type { + WLR_GLES2_TEXTURE_GLTEX, + WLR_GLES2_TEXTURE_WL_DRM_GL, + WLR_GLES2_TEXTURE_WL_DRM_EXT, + WLR_GLES2_TEXTURE_DMABUF, +}; + struct wlr_gles2_texture { struct wlr_texture wlr_texture; - struct wlr_egl *egl; - GLuint tex_id; - const struct gles2_pixel_format *pixel_format; + struct wlr_gles2_renderer *renderer; + enum wlr_gles2_texture_type type; + int width, height; + bool has_alpha; + bool inverted_y; + + // Not set if WLR_GLES2_TEXTURE_GLTEX EGLImageKHR image; - GLenum target; + GLuint image_tex; + + union { + GLuint gl_tex; + struct wl_resource *wl_drm; + }; }; const struct gles2_pixel_format *gles2_format_from_wl(enum wl_shm_format fmt); const enum wl_shm_format *gles2_formats(size_t *len); -struct wlr_texture *gles2_texture_create(); -struct wlr_gles2_texture *gles2_get_texture(struct wlr_texture *wlr_texture); +struct wlr_gles2_renderer *gles2_get_renderer( + struct wlr_renderer *wlr_renderer); +struct wlr_gles2_renderer *gles2_get_renderer_in_context( + struct wlr_renderer *wlr_renderer); + +struct wlr_gles2_texture *gles2_get_texture_in_context( + struct wlr_texture *wlr_texture); +struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer, + enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height, + const void *data); +struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, + struct wl_resource *data); +struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, + struct wlr_dmabuf_buffer_attribs *attribs); void gles2_push_marker(const char *file, const char *func); void gles2_pop_marker(void); diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h index aa429e8e..c214f127 100644 --- a/include/wlr/render/egl.h +++ b/include/wlr/render/egl.h @@ -46,37 +46,25 @@ void wlr_egl_finish(struct wlr_egl *egl); */ bool wlr_egl_bind_display(struct wlr_egl *egl, struct wl_display *local_display); -/** - * Refer to the eglQueryWaylandBufferWL extension function. - */ -bool wlr_egl_query_buffer(struct wlr_egl *egl, struct wl_resource *buf, - EGLint attrib, EGLint *value); - /** * Returns a surface for the given native window * The window must match the remote display the wlr_egl was created with. */ EGLSurface wlr_egl_create_surface(struct wlr_egl *egl, void *window); -/** - * Creates an egl image from the given client buffer and attributes. - */ -EGLImageKHR wlr_egl_create_image(struct wlr_egl *egl, - EGLenum target, EGLClientBuffer buffer, const EGLint *attribs); - /** * Creates an egl image from the given dmabuf attributes. Check usability * of the dmabuf with wlr_egl_check_import_dmabuf once first. */ EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl, - struct wlr_dmabuf_buffer_attribs *attributes); + struct wlr_dmabuf_buffer_attribs *attributes); /** * Try to import the given dmabuf. On success return true false otherwise. * If this succeeds the dmabuf can be used for rendering on a texture */ bool wlr_egl_check_import_dmabuf(struct wlr_egl *egl, - struct wlr_dmabuf_buffer *dmabuf); + struct wlr_dmabuf_buffer *dmabuf); /** * Get the available dmabuf formats diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index 7f25c0ff..212e4f7a 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -23,7 +23,6 @@ struct wlr_renderer_impl { void (*end)(struct wlr_renderer *renderer); void (*clear)(struct wlr_renderer *renderer, const float color[static 4]); void (*scissor)(struct wlr_renderer *renderer, struct wlr_box *box); - struct wlr_texture *(*texture_create)(struct wlr_renderer *renderer); bool (*render_texture_with_matrix)(struct wlr_renderer *renderer, struct wlr_texture *texture, const float matrix[static 9], float alpha); @@ -33,45 +32,39 @@ struct wlr_renderer_impl { const float color[static 4], const float matrix[static 9]); const enum wl_shm_format *(*formats)( struct wlr_renderer *renderer, size_t *len); - bool (*buffer_is_drm)(struct wlr_renderer *renderer, - struct wl_resource *buffer); + bool (*resource_is_wl_drm_buffer)(struct wlr_renderer *renderer, + struct wl_resource *resource); + void (*wl_drm_buffer_get_size)(struct wlr_renderer *renderer, + struct wl_resource *buffer, int *width, int *height); bool (*read_pixels)(struct wlr_renderer *renderer, enum wl_shm_format fmt, uint32_t stride, uint32_t width, uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, void *data); bool (*format_supported)(struct wlr_renderer *renderer, enum wl_shm_format fmt); + struct wlr_texture *(*texture_from_pixels)(struct wlr_renderer *renderer, + enum wl_shm_format fmt, uint32_t stride, uint32_t width, + uint32_t height, const void *data); + struct wlr_texture *(*texture_from_wl_drm)(struct wlr_renderer *renderer, + struct wl_resource *data); + struct wlr_texture *(*texture_from_dmabuf)(struct wlr_renderer *renderer, + struct wlr_dmabuf_buffer_attribs *attribs); void (*destroy)(struct wlr_renderer *renderer); }; void wlr_renderer_init(struct wlr_renderer *renderer, - const struct wlr_renderer_impl *impl); + const struct wlr_renderer_impl *impl); struct wlr_texture_impl { - bool (*upload_pixels)(struct wlr_texture *texture, - enum wl_shm_format format, int stride, int width, int height, - const unsigned char *pixels); - bool (*update_pixels)(struct wlr_texture *texture, - enum wl_shm_format format, int stride, int x, int y, - int width, int height, const unsigned char *pixels); - bool (*upload_shm)(struct wlr_texture *texture, uint32_t format, - struct wl_shm_buffer *shm); - bool (*update_shm)(struct wlr_texture *texture, uint32_t format, - int x, int y, int width, int height, struct wl_shm_buffer *shm); - bool (*upload_drm)(struct wlr_texture *texture, - struct wl_resource *drm_buf); - bool (*upload_eglimage)(struct wlr_texture *texture, EGLImageKHR image, - uint32_t width, uint32_t height); - bool (*upload_dmabuf)(struct wlr_texture *texture, - struct wl_resource *dmabuf_resource); - void (*get_buffer_size)(struct wlr_texture *texture, - struct wl_resource *resource, int *width, int *height); + void (*get_size)(struct wlr_texture *texture, int *width, int *height); + bool (*write_pixels)(struct wlr_texture *texture, + enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, + uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x, + uint32_t dst_y, const void *data); void (*destroy)(struct wlr_texture *texture); }; void wlr_texture_init(struct wlr_texture *texture, const struct wlr_texture_impl *impl); -void wlr_texture_get_buffer_size(struct wlr_texture *texture, - struct wl_resource *resource, int *width, int *height); #endif diff --git a/include/wlr/render/wlr_renderer.h b/include/wlr/render/wlr_renderer.h index 6f0d2ecc..decd14f5 100644 --- a/include/wlr/render/wlr_renderer.h +++ b/include/wlr/render/wlr_renderer.h @@ -1,8 +1,6 @@ #ifndef WLR_RENDER_WLR_RENDERER_H #define WLR_RENDER_WLR_RENDERER_H -#include -#include #include #include #include @@ -21,10 +19,6 @@ void wlr_renderer_clear(struct wlr_renderer *r, const float color[static 4]); * box. */ void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box); -/** - * Requests a texture handle from this renderer. - */ -struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r); /** * Renders the requested texture. */ @@ -51,10 +45,15 @@ void wlr_render_colored_ellipse(struct wlr_renderer *r, const enum wl_shm_format *wlr_renderer_get_formats(struct wlr_renderer *r, size_t *len); /** - * Returns true if this wl_buffer is a DRM buffer. + * Returns true if this wl_buffer is a wl_drm buffer. */ -bool wlr_renderer_buffer_is_drm(struct wlr_renderer *renderer, +bool wlr_renderer_resource_is_wl_drm_buffer(struct wlr_renderer *renderer, struct wl_resource *buffer); +/** + * Gets the width and height of a wl_drm buffer. + */ +void wlr_renderer_wl_drm_buffer_get_size(struct wlr_renderer *renderer, + struct wl_resource *buffer, int *width, int *height); /** * Reads out of pixels of the currently bound surface into data. `stride` is in * bytes. diff --git a/include/wlr/render/wlr_texture.h b/include/wlr/render/wlr_texture.h index 095097e6..ab361298 100644 --- a/include/wlr/render/wlr_texture.h +++ b/include/wlr/render/wlr_texture.h @@ -5,62 +5,49 @@ #include #include #include +#include +struct wlr_renderer; struct wlr_texture_impl; struct wlr_texture { const struct wlr_texture_impl *impl; - - bool valid; - uint32_t format; - int width, height; - bool inverted_y; - struct wl_signal destroy_signal; - struct wl_resource *resource; }; /** - * Copies pixels to this texture. The buffer is not accessed after this function - * returns. + * Create a new texture from raw pixel data. `stride` is in bytes. The returned + * texture is mutable. */ -bool wlr_texture_upload_pixels(struct wlr_texture *tex, - enum wl_shm_format format, int stride, int width, int height, - const unsigned char *pixels); +struct wlr_texture *wlr_texture_from_pixels(struct wlr_renderer *renderer, + enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height, + const void *data); + /** - * Copies pixels to this texture. The buffer is not accessed after this function - * returns. Under some circumstances, this function may re-upload the entire - * buffer - therefore, the entire buffer must be valid. + * Create a new texture from a wayland DRM resource. The returned texture is + * immutable. */ -bool wlr_texture_update_pixels(struct wlr_texture *surf, - enum wl_shm_format format, int stride, int x, int y, - int width, int height, const unsigned char *pixels); +struct wlr_texture *wlr_texture_from_wl_drm(struct wlr_renderer *renderer, + struct wl_resource *data); + /** - * Copies pixels from a wl_shm_buffer into this texture. The buffer is not - * accessed after this function returns. + * Create a new texture from a DMA-BUF. The returned texture is immutable. */ -bool wlr_texture_upload_shm(struct wlr_texture *tex, uint32_t format, - struct wl_shm_buffer *shm); +struct wlr_texture *wlr_texture_from_dmabuf(struct wlr_renderer *renderer, + struct wlr_dmabuf_buffer_attribs *attribs); + /** - * Attaches the contents from the given wl_drm wl_buffer resource onto the - * texture. The wl_resource is not used after this call. - * Will fail (return false) if the given resource is no drm buffer. + * Get the texture width and height. */ -bool wlr_texture_upload_drm(struct wlr_texture *tex, - struct wl_resource *drm_buffer); - -bool wlr_texture_upload_eglimage(struct wlr_texture *tex, - EGLImageKHR image, uint32_t width, uint32_t height); +void wlr_texture_get_size(struct wlr_texture *texture, int *width, int *height); -bool wlr_texture_upload_dmabuf(struct wlr_texture *tex, - struct wl_resource *dmabuf_resource); /** - * Copies a rectangle of pixels from a wl_shm_buffer onto the texture. The - * buffer is not accessed after this function returns. Under some circumstances, - * this function may re-upload the entire buffer - therefore, the entire buffer - * must be valid. + * Update a texture with raw pixels. The texture must be mutable. */ -bool wlr_texture_update_shm(struct wlr_texture *surf, uint32_t format, - int x, int y, int width, int height, struct wl_shm_buffer *shm); +bool wlr_texture_write_pixels(struct wlr_texture *texture, + enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height, + uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, + const void *data); + /** * Destroys this wlr_texture. */ diff --git a/include/wlr/types/wlr_linux_dmabuf.h b/include/wlr/types/wlr_linux_dmabuf.h index 9d71e598..c06d8a87 100644 --- a/include/wlr/types/wlr_linux_dmabuf.h +++ b/include/wlr/types/wlr_linux_dmabuf.h @@ -11,6 +11,12 @@ #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1) #endif +enum { + WLR_DMABUF_BUFFER_ATTRIBS_FLAGS_Y_INVERT = 1, + WLR_DMABUF_BUFFER_ATTRIBS_FLAGS_INTERLACED = 2, + WLR_DMABUF_BUFFER_ATTRIBS_FLAGS_BOTTOM_FIRST = 4, +}; + struct wlr_dmabuf_buffer_attribs { /* set via params_add */ int n_planes; @@ -22,7 +28,7 @@ struct wlr_dmabuf_buffer_attribs { int32_t width; int32_t height; uint32_t format; - uint32_t flags; /* enum zlinux_buffer_params_flags */ + uint32_t flags; }; struct wlr_dmabuf_buffer { @@ -52,11 +58,6 @@ struct wlr_dmabuf_buffer *wlr_dmabuf_buffer_from_buffer_resource( struct wlr_dmabuf_buffer *wlr_dmabuf_buffer_from_params_resource( struct wl_resource *params_resource); -/** - * Returns true if the given dmabuf has y-axis inverted, false otherwise - */ -bool wlr_dmabuf_buffer_has_inverted_y(struct wlr_dmabuf_buffer *dmabuf); - /* the protocol interface */ struct wlr_linux_dmabuf { struct wl_global *wl_global; diff --git a/render/egl.c b/render/egl.c index e582b6d3..49b41eee 100644 --- a/render/egl.c +++ b/render/egl.c @@ -223,24 +223,6 @@ bool wlr_egl_bind_display(struct wlr_egl *egl, struct wl_display *local_display) return false; } -bool wlr_egl_query_buffer(struct wlr_egl *egl, struct wl_resource *buf, - int attrib, int *value) { - if (!eglQueryWaylandBufferWL) { - return false; - } - return eglQueryWaylandBufferWL(egl->display, buf, attrib, value); -} - -EGLImage wlr_egl_create_image(struct wlr_egl *egl, EGLenum target, - EGLClientBuffer buffer, const EGLint *attribs) { - if (!eglCreateImageKHR) { - return NULL; - } - - return eglCreateImageKHR(egl->display, egl->context, target, - buffer, attribs); -} - bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImage image) { if (!eglDestroyImageKHR) { return false; diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 9403c0ed..dcda45e9 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -12,23 +12,27 @@ #include #include #include -#include "render/gles2.h" #include "glapi.h" +#include "render/gles2.h" static const struct wlr_renderer_impl renderer_impl; -static struct wlr_gles2_renderer *gles2_get_renderer( +struct wlr_gles2_renderer *gles2_get_renderer( struct wlr_renderer *wlr_renderer) { assert(wlr_renderer->impl == &renderer_impl); - struct wlr_gles2_renderer *renderer = - (struct wlr_gles2_renderer *)wlr_renderer; + return (struct wlr_gles2_renderer *)wlr_renderer; +} + +struct wlr_gles2_renderer *gles2_get_renderer_in_context( + struct wlr_renderer *wlr_renderer) { + struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); assert(eglGetCurrentContext() == renderer->egl->context); return renderer; } static void gles2_begin(struct wlr_renderer *wlr_renderer, uint32_t width, uint32_t height) { - gles2_get_renderer(wlr_renderer); + gles2_get_renderer_in_context(wlr_renderer); GLES2_DEBUG_PUSH; @@ -45,13 +49,13 @@ static void gles2_begin(struct wlr_renderer *wlr_renderer, uint32_t width, } static void gles2_end(struct wlr_renderer *wlr_renderer) { - gles2_get_renderer(wlr_renderer); + gles2_get_renderer_in_context(wlr_renderer); // no-op } static void gles2_clear(struct wlr_renderer *wlr_renderer, const float color[static 4]) { - gles2_get_renderer(wlr_renderer); + gles2_get_renderer_in_context(wlr_renderer); GLES2_DEBUG_PUSH; glClearColor(color[0], color[1], color[2], color[3]); @@ -61,7 +65,7 @@ static void gles2_clear(struct wlr_renderer *wlr_renderer, static void gles2_scissor(struct wlr_renderer *wlr_renderer, struct wlr_box *box) { - gles2_get_renderer(wlr_renderer); + gles2_get_renderer_in_context(wlr_renderer); GLES2_DEBUG_PUSH; if (box != NULL) { @@ -73,14 +77,6 @@ static void gles2_scissor(struct wlr_renderer *wlr_renderer, GLES2_DEBUG_POP; } -static struct wlr_texture *gles2_renderer_texture_create( - struct wlr_renderer *wlr_renderer) { - assert(wlr_renderer->impl == &renderer_impl); - struct wlr_gles2_renderer *renderer = - (struct wlr_gles2_renderer *)wlr_renderer; - return gles2_texture_create(renderer->egl); -} - static void draw_quad() { GLfloat verts[] = { 1, 0, // top right @@ -107,21 +103,28 @@ static void draw_quad() { glDisableVertexAttribArray(1); } -static bool gles2_render_texture_with_matrix( - struct wlr_renderer *wlr_renderer, struct wlr_texture *wlr_texture, - const float matrix[static 9], float alpha) { - struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); - struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); - if (!wlr_texture->valid) { - wlr_log(L_ERROR, "attempt to render invalid texture"); - return false; - } - - GLuint prog = renderer->shaders.tex_rgba; - if (texture->target == GL_TEXTURE_EXTERNAL_OES) { +static bool gles2_render_texture_with_matrix(struct wlr_renderer *wlr_renderer, + struct wlr_texture *wlr_texture, const float matrix[static 9], + float alpha) { + struct wlr_gles2_renderer *renderer = + gles2_get_renderer_in_context(wlr_renderer); + struct wlr_gles2_texture *texture = + gles2_get_texture_in_context(wlr_texture); + + GLuint prog; + GLenum target; + switch (texture->type) { + case WLR_GLES2_TEXTURE_GLTEX: + case WLR_GLES2_TEXTURE_WL_DRM_GL: + prog = texture->has_alpha ? renderer->shaders.tex_rgba : + renderer->shaders.tex_rgbx; + target = GL_TEXTURE_2D; + break; + case WLR_GLES2_TEXTURE_WL_DRM_EXT: + case WLR_GLES2_TEXTURE_DMABUF: prog = renderer->shaders.tex_ext; - } else if (!texture->pixel_format->has_alpha) { - prog = renderer->shaders.tex_rgbx; + target = GL_TEXTURE_EXTERNAL_OES; + break; } // OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set @@ -130,15 +133,23 @@ static bool gles2_render_texture_with_matrix( wlr_matrix_transpose(transposition, matrix); GLES2_DEBUG_PUSH; - glBindTexture(texture->target, texture->tex_id); - glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + GLuint tex_id = texture->type == WLR_GLES2_TEXTURE_GLTEX ? + texture->gl_tex : texture->image_tex; + glActiveTexture(GL_TEXTURE0); + glBindTexture(target, tex_id); + + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glUseProgram(prog); glUniformMatrix3fv(0, 1, GL_FALSE, transposition); - glUniform1i(1, wlr_texture->inverted_y); + glUniform1i(1, texture->inverted_y); glUniform1f(3, alpha); + draw_quad(); + GLES2_DEBUG_POP; return true; } @@ -146,7 +157,8 @@ static bool gles2_render_texture_with_matrix( static void gles2_render_quad(struct wlr_renderer *wlr_renderer, const float color[static 4], const float matrix[static 9]) { - struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); + struct wlr_gles2_renderer *renderer = + gles2_get_renderer_in_context(wlr_renderer); // OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set // to GL_FALSE @@ -163,7 +175,8 @@ static void gles2_render_quad(struct wlr_renderer *wlr_renderer, static void gles2_render_ellipse(struct wlr_renderer *wlr_renderer, const float color[static 4], const float matrix[static 9]) { - struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); + struct wlr_gles2_renderer *renderer = + gles2_get_renderer_in_context(wlr_renderer); // OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set // to GL_FALSE @@ -183,20 +196,38 @@ static const enum wl_shm_format *gles2_renderer_formats( return gles2_formats(len); } -static bool gles2_buffer_is_drm(struct wlr_renderer *wlr_renderer, - struct wl_resource *buffer) { - struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); +static bool gles2_resource_is_wl_drm_buffer(struct wlr_renderer *wlr_renderer, + struct wl_resource *resource) { + struct wlr_gles2_renderer *renderer = + gles2_get_renderer_in_context(wlr_renderer); + + if (!eglQueryWaylandBufferWL) { + return false; + } + + EGLint fmt; + return eglQueryWaylandBufferWL(renderer->egl->display, resource, + EGL_TEXTURE_FORMAT, &fmt); +} + +static void gles2_wl_drm_buffer_get_size(struct wlr_renderer *wlr_renderer, + struct wl_resource *buffer, int *width, int *height) { + struct wlr_gles2_renderer *renderer = + gles2_get_renderer_in_context(wlr_renderer); + + if (!eglQueryWaylandBufferWL) { + return; + } - EGLint format; - return wlr_egl_query_buffer(renderer->egl, buffer, EGL_TEXTURE_FORMAT, - &format); + eglQueryWaylandBufferWL(renderer->egl->display, buffer, EGL_WIDTH, width); + eglQueryWaylandBufferWL(renderer->egl->display, buffer, EGL_HEIGHT, height); } static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer, enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, void *data) { - gles2_get_renderer(wlr_renderer); + gles2_get_renderer_in_context(wlr_renderer); const struct gles2_pixel_format *fmt = gles2_format_from_wl(wl_fmt); if (fmt == NULL) { @@ -254,14 +285,17 @@ static const struct wlr_renderer_impl renderer_impl = { .end = gles2_end, .clear = gles2_clear, .scissor = gles2_scissor, - .texture_create = gles2_renderer_texture_create, .render_texture_with_matrix = gles2_render_texture_with_matrix, .render_quad = gles2_render_quad, .render_ellipse = gles2_render_ellipse, .formats = gles2_renderer_formats, - .buffer_is_drm = gles2_buffer_is_drm, + .resource_is_wl_drm_buffer = gles2_resource_is_wl_drm_buffer, + .wl_drm_buffer_get_size = gles2_wl_drm_buffer_get_size, .read_pixels = gles2_read_pixels, .format_supported = gles2_format_supported, + .texture_from_pixels = gles2_texture_from_pixels, + .texture_from_wl_drm = gles2_texture_from_wl_drm, + .texture_from_dmabuf = gles2_texture_from_dmabuf, }; void gles2_push_marker(const char *file, const char *func) { diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 46193c78..82effd71 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -10,366 +10,262 @@ #include #include #include +#include "glapi.h" #include "render/gles2.h" #include "util/signal.h" -static struct gles2_pixel_format external_pixel_format = { - .wl_format = 0, - .depth = 0, - .bpp = 0, - .gl_format = 0, - .gl_type = 0, -}; - -static void gles2_texture_ensure(struct wlr_gles2_texture *texture, - GLenum target) { - if (texture->tex_id) { - return; - } - texture->target = target; - glGenTextures(1, &texture->tex_id); - glBindTexture(target, texture->tex_id); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); -} - static const struct wlr_texture_impl texture_impl; -struct wlr_gles2_texture *gles2_get_texture(struct wlr_texture *wlr_texture) { +static struct wlr_gles2_texture *gles2_get_texture( + struct wlr_texture *wlr_texture) { assert(wlr_texture->impl == &texture_impl); return (struct wlr_gles2_texture *)wlr_texture; } -static bool gles2_texture_upload_pixels(struct wlr_texture *wlr_texture, - enum wl_shm_format format, int stride, int width, int height, - const unsigned char *pixels) { +struct wlr_gles2_texture *gles2_get_texture_in_context( + struct wlr_texture *wlr_texture) { struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); - - const struct gles2_pixel_format *fmt = gles2_format_from_wl(format); - if (!fmt || !fmt->gl_format) { - wlr_log(L_ERROR, "No supported pixel format for this texture"); - return false; - } - texture->wlr_texture.width = width; - texture->wlr_texture.height = height; - texture->wlr_texture.format = format; - texture->pixel_format = fmt; - - GLES2_DEBUG_PUSH; - gles2_texture_ensure(texture, GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texture->tex_id); - glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride); - glTexImage2D(GL_TEXTURE_2D, 0, fmt->gl_format, width, height, 0, - fmt->gl_format, fmt->gl_type, pixels); - GLES2_DEBUG_POP; - - texture->wlr_texture.valid = true; - return true; + assert(eglGetCurrentContext() == texture->renderer->egl->context); + return texture; } -static bool gles2_texture_update_pixels(struct wlr_texture *wlr_texture, - enum wl_shm_format format, int stride, int x, int y, - int width, int height, const unsigned char *pixels) { +static void gles2_texture_get_size(struct wlr_texture *wlr_texture, int *width, + int *height) { struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); - - // TODO: Test if the unpack subimage extension is supported and adjust the - // upload strategy if not - if (!texture->wlr_texture.valid - || texture->wlr_texture.format != format - /* || unpack not supported */) { - return gles2_texture_upload_pixels(&texture->wlr_texture, format, - stride, width, height, pixels); - } - const struct gles2_pixel_format *fmt = texture->pixel_format; - GLES2_DEBUG_PUSH; - glBindTexture(GL_TEXTURE_2D, texture->tex_id); - glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride); - glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, x); - glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, y); - glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, fmt->gl_format, - fmt->gl_type, pixels); - glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, 0); - GLES2_DEBUG_POP; - return true; + *width = texture->width; + *height = texture->height; } -static bool gles2_texture_upload_shm(struct wlr_texture *wlr_texture, - uint32_t format, struct wl_shm_buffer *buffer) { - struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); +static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture, + enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, + uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x, + uint32_t dst_y, const void *data) { + struct wlr_gles2_texture *texture = + gles2_get_texture_in_context(wlr_texture); + + if (texture->type != WLR_GLES2_TEXTURE_GLTEX) { + wlr_log(L_ERROR, "Cannot write pixels to immutable texture"); + return false; + } - const struct gles2_pixel_format *fmt = gles2_format_from_wl(format); - if (!fmt || !fmt->gl_format) { - wlr_log(L_ERROR, "Unsupported pixel format %"PRIu32" for this texture", - format); + const struct gles2_pixel_format *fmt = gles2_format_from_wl(wl_fmt); + if (fmt == NULL) { + wlr_log(L_ERROR, "Unsupported pixel format %"PRIu32, wl_fmt); return false; } - wl_shm_buffer_begin_access(buffer); - uint8_t *pixels = wl_shm_buffer_get_data(buffer); - int width = wl_shm_buffer_get_width(buffer); - int height = wl_shm_buffer_get_height(buffer); - int pitch = wl_shm_buffer_get_stride(buffer) / (fmt->bpp / 8); - texture->wlr_texture.width = width; - texture->wlr_texture.height = height; - texture->wlr_texture.format = format; - texture->pixel_format = fmt; + // TODO: what if the unpack subimage extension isn't supported? GLES2_DEBUG_PUSH; - gles2_texture_ensure(texture, GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texture->tex_id); - glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, pitch); - glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, 0); - glTexImage2D(GL_TEXTURE_2D, 0, fmt->gl_format, width, height, 0, - fmt->gl_format, fmt->gl_type, pixels); - GLES2_DEBUG_POP; - texture->wlr_texture.valid = true; - wl_shm_buffer_end_access(buffer); - return true; -} + glBindTexture(GL_TEXTURE_2D, texture->gl_tex); -static bool gles2_texture_update_shm(struct wlr_texture *wlr_texture, - uint32_t format, int x, int y, int width, int height, - struct wl_shm_buffer *buffer) { - struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); + glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / (fmt->bpp / 8)); + glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, src_x); + glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, src_y); - // TODO: Test if the unpack subimage extension is supported and adjust the - // upload strategy if not - assert(texture); - if (!texture->wlr_texture.valid - || texture->wlr_texture.format != format - /* || unpack not supported */) { - return gles2_texture_upload_shm(&texture->wlr_texture, format, buffer); - } - const struct gles2_pixel_format *fmt = texture->pixel_format; - wl_shm_buffer_begin_access(buffer); - uint8_t *pixels = wl_shm_buffer_get_data(buffer); - int pitch = wl_shm_buffer_get_stride(buffer) / (fmt->bpp / 8); + glTexSubImage2D(GL_TEXTURE_2D, 0, dst_x, dst_y, width, height, + fmt->gl_format, fmt->gl_type, data); - GLES2_DEBUG_PUSH; - glBindTexture(GL_TEXTURE_2D, texture->tex_id); - glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, pitch); - glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, x); - glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, y); - glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, - fmt->gl_format, fmt->gl_type, pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, 0); - GLES2_DEBUG_POP; - - wl_shm_buffer_end_access(buffer); + GLES2_DEBUG_POP; return true; } -static bool gles2_texture_upload_drm(struct wlr_texture *wlr_texture, - struct wl_resource *buf) { - struct wlr_gles2_texture *tex = gles2_get_texture(wlr_texture); - if (!glEGLImageTargetTexture2DOES) { - return false; +static void gles2_texture_destroy(struct wlr_texture *wlr_texture) { + if (wlr_texture == NULL) { + return; } - EGLint format; - if (!wlr_egl_query_buffer(tex->egl, buf, EGL_TEXTURE_FORMAT, &format)) { - wlr_log(L_INFO, "upload_drm called with no drm buffer"); - return false; - } + struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); - wlr_egl_query_buffer(tex->egl, buf, EGL_WIDTH, - (EGLint*)&tex->wlr_texture.width); - wlr_egl_query_buffer(tex->egl, buf, EGL_HEIGHT, - (EGLint*)&tex->wlr_texture.height); + wlr_egl_make_current(texture->renderer->egl, EGL_NO_SURFACE, NULL); - EGLint inverted_y; - if (wlr_egl_query_buffer(tex->egl, buf, EGL_WAYLAND_Y_INVERTED_WL, - &inverted_y)) { - tex->wlr_texture.inverted_y = !!inverted_y; + GLES2_DEBUG_PUSH; + + if (texture->image_tex) { + glDeleteTextures(1, &texture->image_tex); + } + if (texture->image) { + assert(eglDestroyImageKHR); + eglDestroyImageKHR(texture->renderer->egl->display, texture->image); } - GLenum target; - const struct gles2_pixel_format *pf; - switch (format) { - case EGL_TEXTURE_RGB: - case EGL_TEXTURE_RGBA: - target = GL_TEXTURE_2D; - pf = gles2_format_from_wl(WL_SHM_FORMAT_ARGB8888); - break; - case EGL_TEXTURE_EXTERNAL_WL: - target = GL_TEXTURE_EXTERNAL_OES; - pf = &external_pixel_format; - break; - default: - wlr_log(L_ERROR, "invalid/unsupported egl buffer format"); - return false; + if (texture->type == WLR_GLES2_TEXTURE_GLTEX) { + glDeleteTextures(1, &texture->gl_tex); } - GLES2_DEBUG_PUSH; - gles2_texture_ensure(tex, target); - glBindTexture(GL_TEXTURE_2D, tex->tex_id); GLES2_DEBUG_POP; - EGLint attribs[] = { EGL_WAYLAND_PLANE_WL, 0, EGL_NONE }; + free(texture); +} - if (tex->image) { - wlr_egl_destroy_image(tex->egl, tex->image); +static const struct wlr_texture_impl texture_impl = { + .get_size = gles2_texture_get_size, + .write_pixels = gles2_texture_write_pixels, + .destroy = gles2_texture_destroy, +}; + +struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer, + enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, + uint32_t height, const void *data) { + struct wlr_gles2_renderer *renderer = + gles2_get_renderer_in_context(wlr_renderer); + + const struct gles2_pixel_format *fmt = gles2_format_from_wl(wl_fmt); + if (fmt == NULL) { + wlr_log(L_ERROR, "Unsupported pixel format %"PRIu32, wl_fmt); + return NULL; } - tex->image = wlr_egl_create_image(tex->egl, EGL_WAYLAND_BUFFER_WL, - (EGLClientBuffer*) buf, attribs); - if (!tex->image) { - wlr_log(L_ERROR, "failed to create EGL image"); - return false; + struct wlr_gles2_texture *texture = + calloc(1, sizeof(struct wlr_gles2_texture)); + if (texture == NULL) { + wlr_log(L_ERROR, "Allocation failed"); + return NULL; } + wlr_texture_init(&texture->wlr_texture, &texture_impl); + texture->renderer = renderer; + texture->width = width; + texture->height = height; + texture->type = WLR_GLES2_TEXTURE_GLTEX; + texture->has_alpha = fmt->has_alpha; GLES2_DEBUG_PUSH; - glActiveTexture(GL_TEXTURE0); - glBindTexture(target, tex->tex_id); - glEGLImageTargetTexture2DOES(target, tex->image); - GLES2_DEBUG_POP; - tex->wlr_texture.valid = true; - tex->pixel_format = pf; - - return true; -} -static bool gles2_texture_upload_eglimage(struct wlr_texture *wlr_texture, - EGLImageKHR image, uint32_t width, uint32_t height) { - struct wlr_gles2_texture *tex = gles2_get_texture(wlr_texture); + glGenTextures(1, &texture->gl_tex); + glBindTexture(GL_TEXTURE_2D, texture->gl_tex); - tex->image = image; - tex->pixel_format = &external_pixel_format; - tex->wlr_texture.valid = true; - tex->wlr_texture.width = width; - tex->wlr_texture.height = height; + glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride / (fmt->bpp / 8)); + glTexImage2D(GL_TEXTURE_2D, 0, fmt->gl_format, width, height, 0, + fmt->gl_format, fmt->gl_type, data); + glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0); - GLES2_DEBUG_PUSH; - gles2_texture_ensure(tex, GL_TEXTURE_2D); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex->tex_id); - glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, tex->image); GLES2_DEBUG_POP; - - return true; + return (struct wlr_texture *)texture; } -static bool gles2_texture_upload_dmabuf(struct wlr_texture *wlr_texture, - struct wl_resource *dmabuf_resource) { - struct wlr_gles2_texture *tex = gles2_get_texture(wlr_texture); - struct wlr_dmabuf_buffer *dmabuf = - wlr_dmabuf_buffer_from_buffer_resource(dmabuf_resource); +struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, + struct wl_resource *data) { + struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); - if (!tex->egl->egl_exts.dmabuf_import) { - wlr_log(L_ERROR, "Want dmabuf but extension not present"); - return false; + if (!eglQueryWaylandBufferWL || !eglCreateImageKHR || + !glEGLImageTargetTexture2DOES) { + return NULL; } - tex->wlr_texture.width = dmabuf->attributes.width; - tex->wlr_texture.height = dmabuf->attributes.height; + EGLint fmt; + if (!eglQueryWaylandBufferWL(renderer->egl->display, data, + EGL_TEXTURE_FORMAT, &fmt)) { + return NULL; + } - if (tex->image) { - wlr_egl_destroy_image(tex->egl, tex->image); + EGLint width, height; + eglQueryWaylandBufferWL(renderer->egl->display, data, EGL_WIDTH, &width); + eglQueryWaylandBufferWL(renderer->egl->display, data, EGL_HEIGHT, &height); + + EGLint inverted_y; + if (!eglQueryWaylandBufferWL(renderer->egl->display, data, + EGL_WAYLAND_Y_INVERTED_WL, &inverted_y)) { + inverted_y = 0; } - if (wlr_dmabuf_buffer_has_inverted_y(dmabuf)) { - wlr_texture->inverted_y = true; + struct wlr_gles2_texture *texture = + calloc(1, sizeof(struct wlr_gles2_texture)); + if (texture == NULL) { + wlr_log(L_ERROR, "Allocation failed"); + return NULL; } + wlr_texture_init(&texture->wlr_texture, &texture_impl); + texture->renderer = renderer; + texture->width = width; + texture->height = height; + texture->wl_drm = data; + texture->inverted_y = !!inverted_y; GLenum target; - const struct gles2_pixel_format *pf; - if (dmabuf->attributes.n_planes > 1) { - target = GL_TEXTURE_EXTERNAL_OES; - pf = &external_pixel_format; - } else { + switch (fmt) { + case EGL_TEXTURE_RGB: + case EGL_TEXTURE_RGBA: target = GL_TEXTURE_2D; - pf = gles2_format_from_wl(WL_SHM_FORMAT_ARGB8888); + texture->type = WLR_GLES2_TEXTURE_WL_DRM_GL; + texture->has_alpha = fmt == EGL_TEXTURE_RGBA; + break; + case EGL_TEXTURE_EXTERNAL_WL: + target = GL_TEXTURE_EXTERNAL_OES; + texture->type = WLR_GLES2_TEXTURE_WL_DRM_EXT; + texture->has_alpha = true; + break; + default: + wlr_log(L_ERROR, "Invalid or unsupported EGL buffer format"); + free(texture); + return NULL; } - GLES2_DEBUG_PUSH; - gles2_texture_ensure(tex, target); - glBindTexture(target, tex->tex_id); - tex->image = wlr_egl_create_image_from_dmabuf(tex->egl, &dmabuf->attributes); - glActiveTexture(GL_TEXTURE0); - glEGLImageTargetTexture2DOES(target, tex->image); - GLES2_DEBUG_POP; - tex->pixel_format = pf; - tex->wlr_texture.valid = true; - return true; -} -static bool gles2_texture_get_dmabuf_size(struct wlr_texture *texture, struct - wl_resource *resource, int *width, int *height) { - if (!wlr_dmabuf_resource_is_buffer(resource)) { - return false; + EGLint attribs[] = { + EGL_WAYLAND_PLANE_WL, 0, + EGL_NONE, + }; + texture->image = eglCreateImageKHR(renderer->egl->display, + renderer->egl->context, EGL_WAYLAND_BUFFER_WL, data, attribs); + if (texture->image == NULL) { + free(texture); + return NULL; } - struct wlr_dmabuf_buffer *dmabuf = - wlr_dmabuf_buffer_from_buffer_resource(resource); - *width = dmabuf->attributes.width; - *height = dmabuf->attributes.height; - return true; -} - -static void gles2_texture_get_buffer_size(struct wlr_texture *texture, - struct wl_resource *resource, int *width, int *height) { - struct wl_shm_buffer *buffer = wl_shm_buffer_get(resource); - if (!buffer) { - struct wlr_gles2_texture *tex = (struct wlr_gles2_texture *)texture; - if (!glEGLImageTargetTexture2DOES) { - return; - } - if (!wlr_egl_query_buffer(tex->egl, resource, EGL_WIDTH, - (EGLint*)width)) { - if (!gles2_texture_get_dmabuf_size(texture, resource, width, - height)) { - wlr_log(L_ERROR, "could not get size of the buffer"); - return; - } - } - wlr_egl_query_buffer(tex->egl, resource, EGL_HEIGHT, (EGLint*)height); + GLES2_DEBUG_PUSH; - return; - } + glGenTextures(1, &texture->image_tex); + glBindTexture(target, texture->image_tex); + glEGLImageTargetTexture2DOES(target, texture->image); - *width = wl_shm_buffer_get_width(buffer); - *height = wl_shm_buffer_get_height(buffer); + GLES2_DEBUG_POP; + return (struct wlr_texture *)texture; } -static void gles2_texture_destroy(struct wlr_texture *wlr_texture) { - struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); +struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, + struct wlr_dmabuf_buffer_attribs *attribs) { + struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); - wlr_signal_emit_safe(&texture->wlr_texture.destroy_signal, - &texture->wlr_texture); - if (texture->tex_id) { - GLES2_DEBUG_PUSH; - glDeleteTextures(1, &texture->tex_id); - GLES2_DEBUG_POP; + if (!glEGLImageTargetTexture2DOES) { + return NULL; } - if (texture->image) { - wlr_egl_destroy_image(texture->egl, texture->image); + if (!renderer->egl->egl_exts.dmabuf_import) { + wlr_log(L_ERROR, "Cannot create DMA-BUF texture: EGL extension " + "unavailable"); + return NULL; } - free(texture); -} - -static const struct wlr_texture_impl texture_impl = { - .upload_pixels = gles2_texture_upload_pixels, - .update_pixels = gles2_texture_update_pixels, - .upload_shm = gles2_texture_upload_shm, - .update_shm = gles2_texture_update_shm, - .upload_drm = gles2_texture_upload_drm, - .upload_dmabuf = gles2_texture_upload_dmabuf, - .upload_eglimage = gles2_texture_upload_eglimage, - .get_buffer_size = gles2_texture_get_buffer_size, - .destroy = gles2_texture_destroy, -}; - -struct wlr_texture *gles2_texture_create(struct wlr_egl *egl) { - struct wlr_gles2_texture *texture; - if (!(texture = calloc(1, sizeof(struct wlr_gles2_texture)))) { + struct wlr_gles2_texture *texture = + calloc(1, sizeof(struct wlr_gles2_texture)); + if (texture == NULL) { + wlr_log(L_ERROR, "Allocation failed"); return NULL; } wlr_texture_init(&texture->wlr_texture, &texture_impl); - texture->egl = egl; - return &texture->wlr_texture; + texture->renderer = renderer; + texture->width = attribs->width; + texture->height = attribs->height; + texture->type = WLR_GLES2_TEXTURE_DMABUF; + texture->has_alpha = true; + texture->inverted_y = + (attribs->flags & WLR_DMABUF_BUFFER_ATTRIBS_FLAGS_Y_INVERT) != 0; + + texture->image = wlr_egl_create_image_from_dmabuf(renderer->egl, attribs); + if (texture->image == NULL) { + free(texture); + return NULL; + } + + GLES2_DEBUG_PUSH; + + glGenTextures(1, &texture->image_tex); + glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture->image_tex); + glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, texture->image); + + GLES2_DEBUG_POP; + return (struct wlr_texture *)texture; } diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index 622aa1dd..d5a4d19f 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,6 +7,15 @@ void wlr_renderer_init(struct wlr_renderer *renderer, const struct wlr_renderer_impl *impl) { + assert(impl->begin); + assert(impl->clear); + assert(impl->scissor); + assert(impl->render_texture_with_matrix); + assert(impl->render_quad); + assert(impl->render_ellipse); + assert(impl->formats); + assert(impl->format_supported); + assert(impl->texture_from_pixels); renderer->impl = impl; } @@ -22,7 +32,9 @@ void wlr_renderer_begin(struct wlr_renderer *r, int width, int height) { } void wlr_renderer_end(struct wlr_renderer *r) { - r->impl->end(r); + if (r->impl->end) { + r->impl->end(r); + } } void wlr_renderer_clear(struct wlr_renderer *r, const float color[static 4]) { @@ -33,16 +45,15 @@ void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box) { r->impl->scissor(r, box); } -struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) { - return r->impl->texture_create(r); -} - bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture, const float projection[static 9], int x, int y, float alpha) { + int width, height; + wlr_texture_get_size(texture, &width, &height); + float mat[9]; wlr_matrix_identity(mat); wlr_matrix_translate(mat, x, y); - wlr_matrix_scale(mat, texture->width, texture->height); + wlr_matrix_scale(mat, width, height); wlr_matrix_multiply(mat, projection, mat); return wlr_render_texture_with_matrix(r, texture, mat, alpha); @@ -69,15 +80,29 @@ const enum wl_shm_format *wlr_renderer_get_formats( return r->impl->formats(r, len); } -bool wlr_renderer_buffer_is_drm(struct wlr_renderer *r, - struct wl_resource *buffer) { - return r->impl->buffer_is_drm(r, buffer); +bool wlr_renderer_resource_is_wl_drm_buffer(struct wlr_renderer *r, + struct wl_resource *resource) { + if (!r->impl->resource_is_wl_drm_buffer) { + return false; + } + return r->impl->resource_is_wl_drm_buffer(r, resource); +} + +void wlr_renderer_wl_drm_buffer_get_size(struct wlr_renderer *r, + struct wl_resource *buffer, int *width, int *height) { + if (!r->impl->wl_drm_buffer_get_size) { + return; + } + return r->impl->wl_drm_buffer_get_size(r, buffer, width, height); } bool wlr_renderer_read_pixels(struct wlr_renderer *r, enum wl_shm_format fmt, uint32_t stride, uint32_t width, uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y, void *data) { + if (!r->impl->read_pixels) { + return false; + } return r->impl->read_pixels(r, fmt, stride, width, height, src_x, src_y, dst_x, dst_y, data); } diff --git a/render/wlr_texture.c b/render/wlr_texture.c index 33c91822..9aecfd98 100644 --- a/render/wlr_texture.c +++ b/render/wlr_texture.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -5,8 +6,9 @@ void wlr_texture_init(struct wlr_texture *texture, const struct wlr_texture_impl *impl) { + assert(impl->get_size); + assert(impl->write_pixels); texture->impl = impl; - wl_signal_init(&texture->destroy_signal); } void wlr_texture_destroy(struct wlr_texture *texture) { @@ -17,45 +19,38 @@ void wlr_texture_destroy(struct wlr_texture *texture) { } } -bool wlr_texture_upload_pixels(struct wlr_texture *texture, uint32_t format, - int stride, int width, int height, const unsigned char *pixels) { - return texture->impl->upload_pixels(texture, format, stride, - width, height, pixels); +struct wlr_texture *wlr_texture_from_pixels(struct wlr_renderer *renderer, + enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, + uint32_t height, const void *data) { + return renderer->impl->texture_from_pixels(renderer, wl_fmt, stride, width, + height, data); } -bool wlr_texture_update_pixels(struct wlr_texture *texture, - enum wl_shm_format format, int stride, int x, int y, - int width, int height, const unsigned char *pixels) { - return texture->impl->update_pixels(texture, format, stride, x, y, - width, height, pixels); -} - -bool wlr_texture_upload_shm(struct wlr_texture *texture, uint32_t format, - struct wl_shm_buffer *shm) { - return texture->impl->upload_shm(texture, format, shm); -} - -bool wlr_texture_update_shm(struct wlr_texture *texture, uint32_t format, - int x, int y, int width, int height, struct wl_shm_buffer *shm) { - return texture->impl->update_shm(texture, format, x, y, width, height, shm); -} - -bool wlr_texture_upload_drm(struct wlr_texture *texture, - struct wl_resource *drm_buffer) { - return texture->impl->upload_drm(texture, drm_buffer); +struct wlr_texture *wlr_texture_from_wl_drm(struct wlr_renderer *renderer, + struct wl_resource *data) { + if (!renderer->impl->texture_from_wl_drm) { + return NULL; + } + return renderer->impl->texture_from_wl_drm(renderer, data); } -bool wlr_texture_upload_eglimage(struct wlr_texture *texture, - EGLImageKHR image, uint32_t width, uint32_t height) { - return texture->impl->upload_eglimage(texture, image, width, height); +struct wlr_texture *wlr_texture_from_dmabuf(struct wlr_renderer *renderer, + struct wlr_dmabuf_buffer_attribs *attribs) { + if (!renderer->impl->texture_from_dmabuf) { + return NULL; + } + return renderer->impl->texture_from_dmabuf(renderer, attribs); } -bool wlr_texture_upload_dmabuf(struct wlr_texture *texture, - struct wl_resource *dmabuf_resource) { - return texture->impl->upload_dmabuf(texture, dmabuf_resource); +void wlr_texture_get_size(struct wlr_texture *texture, int *width, + int *height) { + return texture->impl->get_size(texture, width, height); } -void wlr_texture_get_buffer_size(struct wlr_texture *texture, struct wl_resource - *resource, int *width, int *height) { - texture->impl->get_buffer_size(texture, resource, width, height); +bool wlr_texture_write_pixels(struct wlr_texture *texture, + enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, + uint32_t height, uint32_t src_x, uint32_t src_y, uint32_t dst_x, + uint32_t dst_y, const void *data) { + return texture->impl->write_pixels(texture, wl_fmt, stride, width, height, + src_x, src_y, dst_x, dst_y, data); } diff --git a/types/wlr_linux_dmabuf.c b/types/wlr_linux_dmabuf.c index a61d0ea5..d2a8bea9 100644 --- a/types/wlr_linux_dmabuf.c +++ b/types/wlr_linux_dmabuf.c @@ -19,11 +19,6 @@ static const struct wl_buffer_interface wl_buffer_impl = { wl_buffer_destroy, }; -bool wlr_dmabuf_buffer_has_inverted_y(struct wlr_dmabuf_buffer *dmabuf) { - return dmabuf->attributes.flags - & ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT; -} - bool wlr_dmabuf_resource_is_buffer(struct wl_resource *buffer_resource) { if (!wl_resource_instance_of(buffer_resource, &wl_buffer_interface, &wl_buffer_impl)) { diff --git a/types/wlr_output.c b/types/wlr_output.c index e30c3b78..f95a7ea0 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -731,15 +731,11 @@ bool wlr_output_cursor_set_image(struct wlr_output_cursor *cursor, return true; } - if (cursor->texture == NULL) { - cursor->texture = wlr_render_texture_create(renderer); - if (cursor->texture == NULL) { - return false; - } - } + wlr_texture_destroy(cursor->texture); - return wlr_texture_upload_pixels(cursor->texture, WL_SHM_FORMAT_ARGB8888, + cursor->texture = wlr_texture_from_pixels(renderer, WL_SHM_FORMAT_ARGB8888, stride, width, height, pixels); + return cursor->texture != NULL; } static void output_cursor_commit(struct wlr_output_cursor *cursor) { @@ -901,9 +897,7 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) { } cursor->output->hardware_cursor = NULL; } - if (cursor->texture != NULL) { - wlr_texture_destroy(cursor->texture); - } + wlr_texture_destroy(cursor->texture); wl_list_remove(&cursor->link); free(cursor); } diff --git a/types/wlr_surface.c b/types/wlr_surface.c index e700853a..3be7bdfc 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -155,8 +155,24 @@ static bool wlr_surface_update_size(struct wlr_surface *surface, int scale = state->scale; enum wl_output_transform transform = state->transform; - wlr_texture_get_buffer_size(surface->texture, state->buffer, - &state->buffer_width, &state->buffer_height); + struct wl_shm_buffer *buf = wl_shm_buffer_get(state->buffer); + if (buf != NULL) { + state->buffer_width = wl_shm_buffer_get_width(buf); + state->buffer_height = wl_shm_buffer_get_height(buf); + } else if (wlr_renderer_resource_is_wl_drm_buffer(surface->renderer, + state->buffer)) { + wlr_renderer_wl_drm_buffer_get_size(surface->renderer, state->buffer, + &state->buffer_width, &state->buffer_height); + } else if (wlr_dmabuf_resource_is_buffer(state->buffer)) { + struct wlr_dmabuf_buffer *dmabuf = + wlr_dmabuf_buffer_from_buffer_resource(state->buffer); + state->buffer_width = dmabuf->attributes.width; + state->buffer_height = dmabuf->attributes.height; + } else { + wlr_log(L_ERROR, "Unknown buffer handle attached"); + state->buffer_width = 0; + state->buffer_height = 0; + } int width = state->buffer_width / scale; int height = state->buffer_height / scale; @@ -316,51 +332,65 @@ static void wlr_surface_damage_subsurfaces(struct wlr_subsurface *subsurface) { static void wlr_surface_apply_damage(struct wlr_surface *surface, bool reupload_buffer) { - if (!surface->current->buffer) { + struct wl_resource *resource = surface->current->buffer; + if (resource == NULL) { return; } - struct wl_shm_buffer *buffer = wl_shm_buffer_get(surface->current->buffer); - if (!buffer) { - if (wlr_renderer_buffer_is_drm(surface->renderer, - surface->current->buffer)) { - wlr_texture_upload_drm(surface->texture, surface->current->buffer); - goto release; - } else if (wlr_dmabuf_resource_is_buffer(surface->current->buffer)) { - wlr_texture_upload_dmabuf(surface->texture, surface->current->buffer); - goto release; - } else { - wlr_log(L_INFO, "Unknown buffer handle attached"); - return; - } - } - uint32_t format = wl_shm_buffer_get_format(buffer); - if (reupload_buffer) { - wlr_texture_upload_shm(surface->texture, format, buffer); - } else { - pixman_region32_t damage; - pixman_region32_init(&damage); - pixman_region32_copy(&damage, &surface->current->buffer_damage); - pixman_region32_intersect_rect(&damage, &damage, 0, 0, - surface->current->buffer_width, surface->current->buffer_height); - - int n; - pixman_box32_t *rects = pixman_region32_rectangles(&damage, &n); - for (int i = 0; i < n; ++i) { - pixman_box32_t rect = rects[i]; - if (!wlr_texture_update_shm(surface->texture, format, - rect.x1, rect.y1, - rect.x2 - rect.x1, - rect.y2 - rect.y1, - buffer)) { - break; + struct wl_shm_buffer *buf = wl_shm_buffer_get(resource); + if (buf != NULL) { + wl_shm_buffer_begin_access(buf); + + enum wl_shm_format fmt = wl_shm_buffer_get_format(buf); + int32_t stride = wl_shm_buffer_get_stride(buf); + int32_t width = wl_shm_buffer_get_width(buf); + int32_t height = wl_shm_buffer_get_height(buf); + void *data = wl_shm_buffer_get_data(buf); + + if (surface->texture == NULL || reupload_buffer) { + wlr_texture_destroy(surface->texture); + surface->texture = wlr_texture_from_pixels(surface->renderer, fmt, + stride, width, height, data); + } else { + pixman_region32_t damage; + pixman_region32_init(&damage); + pixman_region32_copy(&damage, &surface->current->buffer_damage); + pixman_region32_intersect_rect(&damage, &damage, 0, 0, + surface->current->buffer_width, + surface->current->buffer_height); + + int n; + pixman_box32_t *rects = pixman_region32_rectangles(&damage, &n); + for (int i = 0; i < n; ++i) { + pixman_box32_t *r = &rects[i]; + if (!wlr_texture_write_pixels(surface->texture, fmt, stride, + r->x2 - r->x1, r->y2 - r->y1, r->x1, r->y1, + r->x1, r->y1, data)) { + break; + } } + + pixman_region32_fini(&damage); } - pixman_region32_fini(&damage); + wl_shm_buffer_end_access(buf); + } else if (!surface->texture || reupload_buffer) { + wlr_texture_destroy(surface->texture); + + if (wlr_renderer_resource_is_wl_drm_buffer(surface->renderer, resource)) { + surface->texture = + wlr_texture_from_wl_drm(surface->renderer, resource); + } else if (wlr_dmabuf_resource_is_buffer(resource)) { + struct wlr_dmabuf_buffer *dmabuf = + wlr_dmabuf_buffer_from_buffer_resource(resource); + surface->texture = + wlr_texture_from_dmabuf(surface->renderer, &dmabuf->attributes); + } else { + surface->texture = NULL; + wlr_log(L_ERROR, "Unknown buffer handle attached"); + } } -release: wlr_surface_state_release_buffer(surface->current); } @@ -375,7 +405,8 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) { wlr_surface_move_state(surface, surface->pending, surface->current); if (null_buffer_commit) { - surface->texture->valid = false; + wlr_texture_destroy(surface->texture); + surface->texture = NULL; } bool reupload_buffer = oldw != surface->current->buffer_width || @@ -611,7 +642,6 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res, } wlr_log(L_DEBUG, "New wlr_surface %p (res %p)", surface, res); surface->renderer = renderer; - surface->texture = wlr_render_texture_create(renderer); surface->resource = res; surface->current = wlr_surface_state_create(); @@ -628,7 +658,7 @@ struct wlr_surface *wlr_surface_create(struct wl_resource *res, } bool wlr_surface_has_buffer(struct wlr_surface *surface) { - return surface->texture && surface->texture->valid; + return surface->texture != NULL; } int wlr_surface_set_role(struct wlr_surface *surface, const char *role, diff --git a/types/wlr_xcursor_manager.c b/types/wlr_xcursor_manager.c index d81b639d..7333a7a1 100644 --- a/types/wlr_xcursor_manager.c +++ b/types/wlr_xcursor_manager.c @@ -77,7 +77,7 @@ void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, } struct wlr_xcursor_image *image = xcursor->images[0]; - wlr_cursor_set_image(cursor, image->buffer, image->width, + wlr_cursor_set_image(cursor, image->buffer, image->width * 4, image->width, image->height, image->hotspot_x, image->hotspot_y, theme->scale); } -- cgit v1.2.3 From 4da18f7fc361bcde631249268320c9f1e4ef7c7c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 26 Mar 2018 12:46:04 -0400 Subject: xdg-positioner attrs --- include/wlr/types/wlr_xdg_shell_v6.h | 28 ++++++++++++++++-- types/wlr_xdg_shell_v6.c | 55 +++++++++++++++--------------------- 2 files changed, 48 insertions(+), 35 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 75570127..47d78664 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -88,6 +88,21 @@ enum wlr_positioner_v6_constraint_adjustment { WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y = 32, }; +struct wlr_xdg_positioner_v6_attributes { + struct wlr_box anchor_rect; + enum wlr_positioner_v6_anchor anchor; + enum wlr_positioner_v6_gravity gravity; + enum wlr_positioner_v6_constraint_adjustment constraint_adjustment; + + struct { + int32_t width, height; + } size; + + struct { + int32_t x, y; + } offset; +}; + struct wlr_xdg_popup_v6 { struct wlr_xdg_surface_v6 *base; struct wl_list link; @@ -98,9 +113,16 @@ struct wlr_xdg_popup_v6 { struct wlr_seat *seat; struct wlr_box geometry; - enum wlr_positioner_v6_anchor anchor; - enum wlr_positioner_v6_gravity gravity; - enum wlr_positioner_v6_constraint_adjustment constraint_adjustment; + struct wlr_xdg_positioner_v6_attributes positioner; + struct wlr_box anchor_rect; + + struct { + int32_t width, height; + } size; + + struct { + int32_t x, y; + } offset; struct wl_list grab_link; // wlr_xdg_popup_grab_v6::popups }; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 0e9419b4..6fddfdbc 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -18,22 +18,9 @@ static const char *wlr_desktop_xdg_popup_role = "xdg_popup_v6"; struct wlr_xdg_positioner_v6 { struct wl_resource *resource; - - struct wlr_box anchor_rect; - enum zxdg_positioner_v6_anchor anchor; - enum zxdg_positioner_v6_gravity gravity; - enum zxdg_positioner_v6_constraint_adjustment constraint_adjustment; - - struct { - int32_t width, height; - } size; - - struct { - int32_t x, y; - } offset; + struct wlr_xdg_positioner_v6_attributes *attrs; }; - static void resource_handle_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); @@ -279,6 +266,7 @@ static struct wlr_xdg_positioner_v6 *xdg_positioner_from_resource( static void xdg_positioner_destroy(struct wl_resource *resource) { struct wlr_xdg_positioner_v6 *positioner = xdg_positioner_from_resource(resource); + free(positioner->attrs); free(positioner); } @@ -294,8 +282,8 @@ static void xdg_positioner_handle_set_size(struct wl_client *client, return; } - positioner->size.width = width; - positioner->size.height = height; + positioner->attrs->size.width = width; + positioner->attrs->size.height = height; } static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client, @@ -311,10 +299,10 @@ static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client, return; } - positioner->anchor_rect.x = x; - positioner->anchor_rect.y = y; - positioner->anchor_rect.width = width; - positioner->anchor_rect.height = height; + positioner->attrs->anchor_rect.x = x; + positioner->attrs->anchor_rect.y = y; + positioner->attrs->anchor_rect.width = width; + positioner->attrs->anchor_rect.height = height; } static void xdg_positioner_handle_set_anchor(struct wl_client *client, @@ -332,7 +320,7 @@ static void xdg_positioner_handle_set_anchor(struct wl_client *client, return; } - positioner->anchor = anchor; + positioner->attrs->anchor = anchor; } static void xdg_positioner_handle_set_gravity(struct wl_client *client, @@ -350,7 +338,7 @@ static void xdg_positioner_handle_set_gravity(struct wl_client *client, return; } - positioner->gravity = gravity; + positioner->attrs->gravity = gravity; } static void xdg_positioner_handle_set_constraint_adjustment( @@ -359,7 +347,7 @@ static void xdg_positioner_handle_set_constraint_adjustment( struct wlr_xdg_positioner_v6 *positioner = xdg_positioner_from_resource(resource); - positioner->constraint_adjustment = constraint_adjustment; + positioner->attrs->constraint_adjustment = constraint_adjustment; } static void xdg_positioner_handle_set_offset(struct wl_client *client, @@ -367,8 +355,8 @@ static void xdg_positioner_handle_set_offset(struct wl_client *client, struct wlr_xdg_positioner_v6 *positioner = xdg_positioner_from_resource(resource); - positioner->offset.x = x; - positioner->offset.y = y; + positioner->attrs->offset.x = x; + positioner->attrs->offset.y = y; } static const struct zxdg_positioner_v6_interface @@ -392,6 +380,10 @@ static void xdg_shell_handle_create_positioner(struct wl_client *wl_client, return; } + // TODO: allocate the positioner attrs? + positioner->attrs = + calloc(1, sizeof(struct wlr_xdg_positioner_v6_attributes)); + positioner->resource = wl_resource_create(wl_client, &zxdg_positioner_v6_interface, wl_resource_get_version(resource), @@ -408,7 +400,7 @@ static void xdg_shell_handle_create_positioner(struct wl_client *wl_client, } static struct wlr_box xdg_positioner_get_geometry( - struct wlr_xdg_positioner_v6 *positioner, + struct wlr_xdg_positioner_v6_attributes *positioner, struct wlr_xdg_surface_v6 *surface, struct wlr_xdg_surface_v6 *parent) { struct wlr_box geometry = { .x = positioner->offset.x, @@ -453,7 +445,7 @@ static struct wlr_box xdg_positioner_get_geometry( } if (positioner->constraint_adjustment == - ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_NONE) { + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_NONE) { return geometry; } @@ -567,7 +559,7 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, struct wlr_xdg_positioner_v6 *positioner = xdg_positioner_from_resource(positioner_resource); - if (positioner->size.width == 0 || positioner->anchor_rect.width == 0) { + if (positioner->attrs->size.width == 0 || positioner->attrs->anchor_rect.width == 0) { wl_resource_post_error(resource, ZXDG_SHELL_V6_ERROR_INVALID_POSITIONER, "positioner object is not complete"); @@ -598,12 +590,11 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, surface->popup->base = surface; surface->popup->parent = parent; surface->popup->geometry = - xdg_positioner_get_geometry(positioner, surface, parent); + xdg_positioner_get_geometry(positioner->attrs, surface, parent); // positioner properties - surface->popup->anchor = (uint32_t)positioner->anchor; - surface->popup->gravity = (uint32_t)positioner->gravity; - surface->popup->constraint_adjustment = (uint32_t)positioner->constraint_adjustment; + memcpy(&surface->popup->positioner, &positioner->attrs, + sizeof(struct wlr_xdg_positioner_v6_attributes)); wl_list_insert(&parent->popups, &surface->popup->link); -- cgit v1.2.3 From 5233801530c5ccc95699a12ba7da2d7ce58c952c Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 26 Mar 2018 18:35:36 -0400 Subject: xdg-shell-v6: don't destroy role resources on unmap The motivation for this is: - `get_popup` and `get_toplevel` allocate role-specific resources. - On the first non-null commit, the surface gets mapped. - On a null commit, the surface gets unmapped. It can be mapped again with a non-null commit. - When the role object (xdg-toplevel or xdg-popup) is destroyed, the surface is unmapped and role-specific resources are destroyed. The client can call `get_popup` or `get_toplevel` again on that surface. - When the xdg-surface object is destroyed, the surface is unmapped, role-specific resources are destroyed and the surface itself is destroyed. --- include/wlr/types/wlr_xdg_shell.h | 1 + include/wlr/types/wlr_xdg_shell_v6.h | 1 + types/wlr_xdg_shell_v6.c | 79 +++++++++++++++++++++++------------- 3 files changed, 53 insertions(+), 28 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index 410663f7..a40a56f5 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -106,6 +106,7 @@ struct wlr_xdg_surface { uint32_t configure_next_serial; struct wl_list configure_list; + // Only for toplevel char *title; char *app_id; diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 3bfb97a4..97ff4786 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -106,6 +106,7 @@ struct wlr_xdg_surface_v6 { uint32_t configure_next_serial; struct wl_list configure_list; + // Only for toplevel char *title; char *app_id; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 464e0157..3975dd67 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -198,35 +198,24 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { wlr_signal_emit_safe(&surface->events.unmap, surface); } - if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { - wl_resource_set_user_data(surface->toplevel->resource, NULL); - free(surface->toplevel); - surface->toplevel = NULL; - } - - if (surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) { - wl_resource_set_user_data(surface->popup->resource, NULL); - - if (surface->popup->seat) { - struct wlr_xdg_popup_grab_v6 *grab = - xdg_shell_popup_grab_from_seat(surface->client->shell, - surface->popup->seat); + if (surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP && + surface->popup->seat != NULL) { + struct wlr_xdg_popup_grab_v6 *grab = + xdg_shell_popup_grab_from_seat(surface->client->shell, + surface->popup->seat); - wl_list_remove(&surface->popup->grab_link); + wl_list_remove(&surface->popup->grab_link); - if (wl_list_empty(&grab->popups)) { - if (grab->seat->pointer_state.grab == &grab->pointer_grab) { - wlr_seat_pointer_end_grab(grab->seat); - } - if (grab->seat->keyboard_state.grab == &grab->keyboard_grab) { - wlr_seat_keyboard_end_grab(grab->seat); - } + if (wl_list_empty(&grab->popups)) { + if (grab->seat->pointer_state.grab == &grab->pointer_grab) { + wlr_seat_pointer_end_grab(grab->seat); + } + if (grab->seat->keyboard_state.grab == &grab->keyboard_grab) { + wlr_seat_keyboard_end_grab(grab->seat); } } - wl_list_remove(&surface->popup->link); - free(surface->popup); - surface->popup = NULL; + surface->popup->seat = NULL; } struct wlr_xdg_surface_v6_configure *configure, *tmp; @@ -234,13 +223,12 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { xdg_surface_configure_destroy(configure); } - surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE; free(surface->title); surface->title = NULL; free(surface->app_id); surface->app_id = NULL; - surface->added = surface->configured = surface->mapped = false; + surface->configured = surface->mapped = false; surface->configure_serial = 0; if (surface->configure_idle) { wl_event_source_remove(surface->configure_idle); @@ -253,6 +241,29 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { memset(&surface->next_geometry, 0, sizeof(struct wlr_box)); } +static void xdg_toplevel_destroy(struct wlr_xdg_surface_v6 *surface) { + assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); + xdg_surface_unmap(surface); + + wl_resource_set_user_data(surface->toplevel->resource, NULL); + free(surface->toplevel); + surface->toplevel = NULL; + + surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE; +} + +static void xdg_popup_destroy(struct wlr_xdg_surface_v6 *surface) { + assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP); + xdg_surface_unmap(surface); + + wl_resource_set_user_data(surface->popup->resource, NULL); + wl_list_remove(&surface->popup->link); + free(surface->popup); + surface->popup = NULL; + + surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE; +} + static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { if (surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE) { xdg_surface_unmap(surface); @@ -260,6 +271,18 @@ static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { wlr_signal_emit_safe(&surface->events.destroy, surface); + switch (surface->role) { + case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL: + xdg_toplevel_destroy(surface); + break; + case WLR_XDG_SURFACE_V6_ROLE_POPUP: + xdg_popup_destroy(surface); + break; + case WLR_XDG_SURFACE_V6_ROLE_NONE: + // This space is intentionally left blank + break; + } + wl_resource_set_user_data(surface->resource, NULL); wl_list_remove(&surface->link); wl_list_remove(&surface->surface_destroy_listener.link); @@ -545,7 +568,7 @@ static void xdg_popup_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_popup_resource(resource); if (surface != NULL) { - xdg_surface_unmap(surface); + xdg_popup_destroy(surface); } } @@ -856,7 +879,7 @@ static void xdg_toplevel_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); if (surface != NULL) { - xdg_surface_unmap(surface); + xdg_toplevel_destroy(surface); } } -- cgit v1.2.3 From 334bab543d6688769a86374a1ddd3d3b36e619b4 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 26 Mar 2018 19:32:21 -0400 Subject: xdg-shell-v6: move toplevel specific fields in wlr_xdg_toplevel_v6 --- include/wlr/types/wlr_xdg_shell_v6.h | 24 +++++----- rootston/xdg_shell_v6.c | 11 ++--- types/wlr_xdg_shell_v6.c | 85 +++++++++++++++++++----------------- 3 files changed, 65 insertions(+), 55 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 97ff4786..67d937fe 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -74,9 +74,22 @@ struct wlr_xdg_toplevel_v6 { struct wlr_xdg_surface_v6 *base; struct wlr_xdg_surface_v6 *parent; bool added; + struct wlr_xdg_toplevel_v6_state next; // client protocol requests struct wlr_xdg_toplevel_v6_state pending; // user configure requests struct wlr_xdg_toplevel_v6_state current; + + char *title; + char *app_id; + + struct { + struct wl_signal request_maximize; + struct wl_signal request_fullscreen; + struct wl_signal request_minimize; + struct wl_signal request_move; + struct wl_signal request_resize; + struct wl_signal request_show_window_menu; + } events; }; struct wlr_xdg_surface_v6_configure { @@ -106,10 +119,6 @@ struct wlr_xdg_surface_v6 { uint32_t configure_next_serial; struct wl_list configure_list; - // Only for toplevel - char *title; - char *app_id; - bool has_next_geometry; struct wlr_box next_geometry; struct wlr_box geometry; @@ -122,13 +131,6 @@ struct wlr_xdg_surface_v6 { struct wl_signal new_popup; struct wl_signal map; struct wl_signal unmap; - - struct wl_signal request_maximize; - struct wl_signal request_fullscreen; - struct wl_signal request_minimize; - struct wl_signal request_move; - struct wl_signal request_resize; - struct wl_signal request_show_window_menu; } events; void *data; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 001232ab..2be9e00e 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -339,7 +339,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { wl_container_of(listener, desktop, xdg_shell_v6_surface); wlr_log(L_DEBUG, "new xdg toplevel: title=%s, app_id=%s", - surface->title, surface->app_id); + surface->toplevel->title, surface->toplevel->app_id); wlr_xdg_surface_v6_ping(surface); struct roots_xdg_surface_v6 *roots_surface = @@ -357,15 +357,16 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { roots_surface->unmap.notify = handle_unmap; wl_signal_add(&surface->events.unmap, &roots_surface->unmap); roots_surface->request_move.notify = handle_request_move; - wl_signal_add(&surface->events.request_move, &roots_surface->request_move); + wl_signal_add(&surface->toplevel->events.request_move, + &roots_surface->request_move); roots_surface->request_resize.notify = handle_request_resize; - wl_signal_add(&surface->events.request_resize, + wl_signal_add(&surface->toplevel->events.request_resize, &roots_surface->request_resize); roots_surface->request_maximize.notify = handle_request_maximize; - wl_signal_add(&surface->events.request_maximize, + wl_signal_add(&surface->toplevel->events.request_maximize, &roots_surface->request_maximize); roots_surface->request_fullscreen.notify = handle_request_fullscreen; - wl_signal_add(&surface->events.request_fullscreen, + wl_signal_add(&surface->toplevel->events.request_fullscreen, &roots_surface->request_fullscreen); roots_surface->new_popup.notify = handle_new_popup; wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup); diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 3975dd67..4c40e129 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -198,24 +198,35 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { wlr_signal_emit_safe(&surface->events.unmap, surface); } - if (surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP && - surface->popup->seat != NULL) { - struct wlr_xdg_popup_grab_v6 *grab = - xdg_shell_popup_grab_from_seat(surface->client->shell, - surface->popup->seat); - - wl_list_remove(&surface->popup->grab_link); - - if (wl_list_empty(&grab->popups)) { - if (grab->seat->pointer_state.grab == &grab->pointer_grab) { - wlr_seat_pointer_end_grab(grab->seat); - } - if (grab->seat->keyboard_state.grab == &grab->keyboard_grab) { - wlr_seat_keyboard_end_grab(grab->seat); + switch (surface->role) { + case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL: + free(surface->toplevel->title); + surface->toplevel->title = NULL; + free(surface->toplevel->app_id); + surface->toplevel->app_id = NULL; + break; + case WLR_XDG_SURFACE_V6_ROLE_POPUP: + if (surface->popup->seat != NULL) { + struct wlr_xdg_popup_grab_v6 *grab = + xdg_shell_popup_grab_from_seat(surface->client->shell, + surface->popup->seat); + + wl_list_remove(&surface->popup->grab_link); + + if (wl_list_empty(&grab->popups)) { + if (grab->seat->pointer_state.grab == &grab->pointer_grab) { + wlr_seat_pointer_end_grab(grab->seat); + } + if (grab->seat->keyboard_state.grab == &grab->keyboard_grab) { + wlr_seat_keyboard_end_grab(grab->seat); + } } - } - surface->popup->seat = NULL; + surface->popup->seat = NULL; + } + break; + case WLR_XDG_SURFACE_V6_ROLE_NONE: + assert(false && "not reached"); } struct wlr_xdg_surface_v6_configure *configure, *tmp; @@ -223,11 +234,6 @@ static void xdg_surface_unmap(struct wlr_xdg_surface_v6 *surface) { xdg_surface_configure_destroy(configure); } - free(surface->title); - surface->title = NULL; - free(surface->app_id); - surface->app_id = NULL; - surface->configured = surface->mapped = false; surface->configure_serial = 0; if (surface->configure_idle) { @@ -666,8 +672,8 @@ static void xdg_toplevel_handle_set_title(struct wl_client *client, return; } - free(surface->title); - surface->title = tmp; + free(surface->toplevel->title); + surface->toplevel->title = tmp; } static void xdg_toplevel_handle_set_app_id(struct wl_client *client, @@ -680,8 +686,8 @@ static void xdg_toplevel_handle_set_app_id(struct wl_client *client, return; } - free(surface->app_id); - surface->app_id = tmp; + free(surface->toplevel->app_id); + surface->toplevel->app_id = tmp; } static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, @@ -712,7 +718,8 @@ static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, .y = y, }; - wlr_signal_emit_safe(&surface->events.request_show_window_menu, &event); + wlr_signal_emit_safe(&surface->toplevel->events.request_show_window_menu, + &event); } static void xdg_toplevel_handle_move(struct wl_client *client, @@ -741,7 +748,7 @@ static void xdg_toplevel_handle_move(struct wl_client *client, .serial = serial, }; - wlr_signal_emit_safe(&surface->events.request_move, &event); + wlr_signal_emit_safe(&surface->toplevel->events.request_move, &event); } static void xdg_toplevel_handle_resize(struct wl_client *client, @@ -771,7 +778,7 @@ static void xdg_toplevel_handle_resize(struct wl_client *client, .edges = edges, }; - wlr_signal_emit_safe(&surface->events.request_resize, &event); + wlr_signal_emit_safe(&surface->toplevel->events.request_resize, &event); } static void xdg_toplevel_handle_set_max_size(struct wl_client *client, @@ -795,7 +802,7 @@ static void xdg_toplevel_handle_set_maximized(struct wl_client *client, struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); surface->toplevel->next.maximized = true; - wlr_signal_emit_safe(&surface->events.request_maximize, surface); + wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); } static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, @@ -803,7 +810,7 @@ static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); surface->toplevel->next.maximized = false; - wlr_signal_emit_safe(&surface->events.request_maximize, surface); + wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); } static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, @@ -824,7 +831,7 @@ static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, .output = output, }; - wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); + wlr_signal_emit_safe(&surface->toplevel->events.request_fullscreen, &event); } static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, @@ -840,14 +847,14 @@ static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, .output = NULL, }; - wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); + wlr_signal_emit_safe(&surface->toplevel->events.request_fullscreen, &event); } static void xdg_toplevel_handle_set_minimized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - wlr_signal_emit_safe(&surface->events.request_minimize, surface); + wlr_signal_emit_safe(&surface->toplevel->events.request_minimize, surface); } static const struct zxdg_toplevel_v6_interface @@ -897,6 +904,12 @@ static void xdg_surface_handle_get_toplevel(struct wl_client *client, wl_resource_post_no_memory(resource); return; } + wl_signal_init(&surface->toplevel->events.request_maximize); + wl_signal_init(&surface->toplevel->events.request_fullscreen); + wl_signal_init(&surface->toplevel->events.request_minimize); + wl_signal_init(&surface->toplevel->events.request_move); + wl_signal_init(&surface->toplevel->events.request_resize); + wl_signal_init(&surface->toplevel->events.request_show_window_menu); surface->role = WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL; surface->toplevel->base = surface; @@ -1341,12 +1354,6 @@ static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client, wl_list_init(&surface->configure_list); wl_list_init(&surface->popups); - wl_signal_init(&surface->events.request_maximize); - wl_signal_init(&surface->events.request_fullscreen); - wl_signal_init(&surface->events.request_minimize); - wl_signal_init(&surface->events.request_move); - wl_signal_init(&surface->events.request_resize); - wl_signal_init(&surface->events.request_show_window_menu); wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.ping_timeout); wl_signal_init(&surface->events.new_popup); -- cgit v1.2.3 From bbd0e23fa79ec39c872c09e49d09a9ccbda68bcd Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 26 Mar 2018 23:48:32 -0400 Subject: xdg-positioner constraint detection --- include/wlr/types/wlr_xdg_shell_v6.h | 18 ++--- rootston/xdg_shell_v6.c | 49 +++++++++++++ types/wlr_output_layout.c | 8 +- types/wlr_xdg_shell_v6.c | 137 ++++++++++++++++++++++++++++++++++- 4 files changed, 198 insertions(+), 14 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 47d78664..e192d36a 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -114,15 +114,6 @@ struct wlr_xdg_popup_v6 { struct wlr_box geometry; struct wlr_xdg_positioner_v6_attributes positioner; - struct wlr_box anchor_rect; - - struct { - int32_t width, height; - } size; - - struct { - int32_t x, y; - } offset; struct wl_list grab_link; // wlr_xdg_popup_grab_v6::popups }; @@ -305,4 +296,13 @@ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( struct wlr_xdg_surface_v6 *surface, double sx, double sy, double *popup_sx, double *popup_sy); +/** + * Get the anchor point for this popup in the root parent's coordinate system. + */ +void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup, + int *root_sx, int *root_sy); + +void wlr_positioner_v6_invert( + struct wlr_xdg_positioner_v6_attributes *positioner); + #endif diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 13d25331..36ecc897 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -45,6 +45,55 @@ static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, if (popup == NULL) { return NULL; } + + struct wlr_xdg_surface_v6 *parent = wlr_popup->parent; + double popup_lx = wlr_popup->geometry.x; + double popup_ly = wlr_popup->geometry.y; + while (parent->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + popup_lx += parent->popup->geometry.x; + popup_ly += parent->popup->geometry.y; + parent = parent->popup->parent; + } + + popup_lx += view->x + parent->geometry.x; + popup_ly += view->y + parent->geometry.y; + int popup_width = wlr_popup->geometry.width; + int popup_height = wlr_popup->geometry.height; + + int anchor_x, anchor_y; + wlr_xdg_popup_v6_get_anchor_point(wlr_popup, &anchor_x, &anchor_y); + anchor_x += popup_lx; + anchor_y += popup_ly; + + struct wlr_output_layout *layout = view->desktop->layout; + + // get the output that contains (or closest to) the anchor point + struct wlr_output *output = + wlr_output_layout_output_at(layout, anchor_x, anchor_y); + if (output == NULL) { + // TODO find the closest output to the anchor + assert(false); + } + + // does the output completely contain the popup? + struct wlr_box *output_box = wlr_output_layout_get_box(layout, output); + bool output_contains_popup_x = popup_lx >= output_box->x && + popup_lx + popup_width <= output_box->x + output_box->width; + bool output_contains_popup_y = popup_ly >= output_box->y && + popup_ly + popup_height <= output_box->y + output_box->height; + + if (!output_contains_popup_x) { + // TODO flip_x + // TODO slide_x + // TODO resize_x + } + + if (!output_contains_popup_y) { + // TODO flip_y + // TODO slide_y + // TODO resize_y + } + popup->wlr_popup = wlr_popup; popup->view_child.destroy = popup_destroy; view_child_init(&popup->view_child, view, wlr_popup->base->surface); diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index 2462bdd2..8d328c17 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -339,8 +339,12 @@ void wlr_output_layout_closest_point(struct wlr_output_layout *layout, } } - *dest_x = min_x; - *dest_y = min_y; + if (dest_x) { + *dest_x = min_x; + } + if (dest_y) { + *dest_y = min_y; + } } struct wlr_box *wlr_output_layout_get_box( diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 6fddfdbc..fc3a38d4 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -454,7 +454,6 @@ static struct wlr_box xdg_positioner_get_geometry( return geometry; } - static const struct zxdg_popup_v6_interface zxdg_popup_v6_implementation; static struct wlr_xdg_surface_v6 *xdg_surface_from_xdg_popup_resource( @@ -593,7 +592,7 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, xdg_positioner_get_geometry(positioner->attrs, surface, parent); // positioner properties - memcpy(&surface->popup->positioner, &positioner->attrs, + memcpy(&surface->popup->positioner, positioner->attrs, sizeof(struct wlr_xdg_positioner_v6_attributes)); wl_list_insert(&parent->popups, &surface->popup->link); @@ -605,7 +604,6 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, wlr_signal_emit_safe(&parent->events.new_popup, surface->popup); } - static const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation; static struct wlr_xdg_surface_v6 *xdg_surface_from_xdg_toplevel_resource( @@ -1591,3 +1589,136 @@ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( return NULL; } + +void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup, + int *root_sx, int *root_sy) { + struct wlr_box rect = popup->positioner.anchor_rect; + enum wlr_positioner_v6_anchor anchor = popup->positioner.anchor; + int sx = 0, sy = 0; + + if (anchor == WLR_POSITIONER_V6_ANCHOR_NONE) { + sx = (rect.x + rect.width) / 2; + sy = (rect.y + rect.height) / 2; + } else if (anchor == WLR_POSITIONER_V6_ANCHOR_TOP) { + sx = (rect.x + rect.width) / 2; + sy = rect.y; + } else if (anchor == WLR_POSITIONER_V6_ANCHOR_BOTTOM) { + sx = (rect.x + rect.width) / 2; + sy = rect.y + rect.height; + } else if (anchor == WLR_POSITIONER_V6_ANCHOR_LEFT) { + sx = rect.x; + sy = (rect.y + rect.height) / 2; + } else if (anchor == WLR_POSITIONER_V6_ANCHOR_RIGHT) { + sx = rect.x + rect.width; + sy = (rect.y + rect.height) / 2; + } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_TOP | + WLR_POSITIONER_V6_ANCHOR_LEFT)) { + sx = rect.x; + sy = rect.y; + } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_TOP | + WLR_POSITIONER_V6_ANCHOR_RIGHT)) { + sx = rect.x + rect.width; + sy = rect.y; + } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_BOTTOM | + WLR_POSITIONER_V6_ANCHOR_LEFT)) { + sx = rect.x; + sy = rect.y + rect.height; + } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_BOTTOM | + WLR_POSITIONER_V6_ANCHOR_RIGHT)) { + sx = rect.x + rect.width; + sy = rect.y + rect.height; + } + + *root_sx = sx; + *root_sy = sy; + + /* + // XXX: THIS IS WILL WORK WITH XDG SHELL STABLE + switch (popup->positioner.anchor) { + case WLR_POSITIONER_ANCHOR_NONE: + sx = (rect.x + rect.width) / 2; + sy = (rect.y + rect.height) / 2; + break; + case WLR_POSITIONER_ANCHOR_TOP: + sx = (rect.x + rect.width) / 2; + sy = rect.y; + break; + case WLR_POSITIONER_ANCHOR_BOTTOM: + sx = (rect.x + rect.width) / 2; + sy = rect.y + rect.height; + break; + case WLR_POSITIONER_ANCHOR_LEFT: + sx = rect.x; + sy = (rect.y + rect.height) / 2; + break; + case WLR_POSITIONER_ANCHOR_RIGHT: + sx = rect.x + rect.width; + sy = (rect.y + rect.height) / 2; + break; + case WLR_POSITIONER_ANCHOR_TOP_LEFT: + sx = rect.x; + sy = rect.y; + break; + case WLR_POSITIONER_ANCHOR_BOTTOM_LEFT: + sx = rect.x; + sy = rect.y + rect.height; + break; + case WLR_POSITIONER_ANCHOR_TOP_RIGHT: + sx = rect.x + rect.width; + sy = rect.y; + break; + case WLR_POSITIONER_ANCHOR_BOTTOM_RIGHT: + sx = rect.x + rect.width; + sy = rect.y + rect.height; + break; + } + */ +} + +void wlr_positioner_v6_invert( + struct wlr_xdg_positioner_v6_attributes *positioner) { + enum wlr_positioner_v6_anchor anchor = positioner->anchor; + + if (anchor == WLR_POSITIONER_V6_ANCHOR_NONE) { + // already inverted + } else if (anchor == WLR_POSITIONER_V6_ANCHOR_TOP) { + positioner->anchor = WLR_POSITIONER_V6_ANCHOR_BOTTOM; + } else if (anchor == WLR_POSITIONER_V6_ANCHOR_BOTTOM) { + positioner->anchor = WLR_POSITIONER_V6_ANCHOR_TOP; + } else if (anchor == WLR_POSITIONER_V6_ANCHOR_LEFT) { + positioner->anchor = WLR_POSITIONER_V6_ANCHOR_RIGHT; + } else if (anchor == WLR_POSITIONER_V6_ANCHOR_RIGHT) { + positioner->anchor = WLR_POSITIONER_V6_ANCHOR_LEFT; + } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_TOP | + WLR_POSITIONER_V6_ANCHOR_LEFT)) { + positioner->anchor = WLR_POSITIONER_V6_ANCHOR_BOTTOM | WLR_POSITIONER_V6_ANCHOR_RIGHT; + } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_TOP | + WLR_POSITIONER_V6_ANCHOR_RIGHT)) { + positioner->anchor = WLR_POSITIONER_V6_ANCHOR_BOTTOM | WLR_POSITIONER_V6_ANCHOR_LEFT; + } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_BOTTOM | + WLR_POSITIONER_V6_ANCHOR_LEFT)) { + positioner->anchor = WLR_POSITIONER_V6_ANCHOR_TOP | WLR_POSITIONER_V6_ANCHOR_RIGHT; + } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_BOTTOM | + WLR_POSITIONER_V6_ANCHOR_RIGHT)) { + positioner->anchor = WLR_POSITIONER_V6_ANCHOR_TOP | WLR_POSITIONER_V6_ANCHOR_LEFT; + } + + enum wlr_positioner_v6_gravity gravity = positioner->gravity; + switch (gravity) { + case WLR_POSITIONER_V6_GRAVITY_NONE: + // already inverted + break; + case WLR_POSITIONER_V6_GRAVITY_TOP: + positioner->gravity = WLR_POSITIONER_V6_GRAVITY_BOTTOM; + break; + case WLR_POSITIONER_V6_GRAVITY_BOTTOM: + positioner->gravity = WLR_POSITIONER_V6_GRAVITY_TOP; + break; + case WLR_POSITIONER_V6_GRAVITY_LEFT: + positioner->gravity = WLR_POSITIONER_V6_GRAVITY_RIGHT; + break; + case WLR_POSITIONER_V6_GRAVITY_RIGHT: + positioner->gravity = WLR_POSITIONER_V6_GRAVITY_LEFT; + break; + } +} -- cgit v1.2.3 From 171e28eaff6e3699a98b828b6430b844d54f624d Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 27 Mar 2018 10:25:02 -0400 Subject: xdg-shell: don't destroy role resources on unmap, move toplevel fields Ports 5233801530c5ccc95699a12ba7da2d7ce58c952c and 334bab543d6688769a86374a1ddd3d3b36e619b4 to xdg-shell stable. --- include/wlr/types/wlr_xdg_shell.h | 24 +++++---- rootston/xdg_shell.c | 11 ++-- types/wlr_xdg_shell.c | 111 ++++++++++++++++++++++++-------------- 3 files changed, 89 insertions(+), 57 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index a40a56f5..2724e0f7 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -74,9 +74,22 @@ struct wlr_xdg_toplevel { struct wlr_xdg_surface *base; struct wlr_xdg_surface *parent; bool added; + struct wlr_xdg_toplevel_state next; // client protocol requests struct wlr_xdg_toplevel_state pending; // user configure requests struct wlr_xdg_toplevel_state current; + + char *title; + char *app_id; + + struct { + struct wl_signal request_maximize; + struct wl_signal request_fullscreen; + struct wl_signal request_minimize; + struct wl_signal request_move; + struct wl_signal request_resize; + struct wl_signal request_show_window_menu; + } events; }; struct wlr_xdg_surface_configure { @@ -106,10 +119,6 @@ struct wlr_xdg_surface { uint32_t configure_next_serial; struct wl_list configure_list; - // Only for toplevel - char *title; - char *app_id; - bool has_next_geometry; struct wlr_box next_geometry; struct wlr_box geometry; @@ -122,13 +131,6 @@ struct wlr_xdg_surface { struct wl_signal new_popup; struct wl_signal map; struct wl_signal unmap; - - struct wl_signal request_maximize; - struct wl_signal request_fullscreen; - struct wl_signal request_minimize; - struct wl_signal request_move; - struct wl_signal request_resize; - struct wl_signal request_show_window_menu; } events; void *data; diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c index 099e622c..f26aefbd 100644 --- a/rootston/xdg_shell.c +++ b/rootston/xdg_shell.c @@ -339,7 +339,7 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { wl_container_of(listener, desktop, xdg_shell_surface); wlr_log(L_DEBUG, "new xdg toplevel: title=%s, app_id=%s", - surface->title, surface->app_id); + surface->toplevel->title, surface->toplevel->app_id); wlr_xdg_surface_ping(surface); struct roots_xdg_surface *roots_surface = @@ -357,15 +357,16 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { roots_surface->unmap.notify = handle_unmap; wl_signal_add(&surface->events.unmap, &roots_surface->unmap); roots_surface->request_move.notify = handle_request_move; - wl_signal_add(&surface->events.request_move, &roots_surface->request_move); + wl_signal_add(&surface->toplevel->events.request_move, + &roots_surface->request_move); roots_surface->request_resize.notify = handle_request_resize; - wl_signal_add(&surface->events.request_resize, + wl_signal_add(&surface->toplevel->events.request_resize, &roots_surface->request_resize); roots_surface->request_maximize.notify = handle_request_maximize; - wl_signal_add(&surface->events.request_maximize, + wl_signal_add(&surface->toplevel->events.request_maximize, &roots_surface->request_maximize); roots_surface->request_fullscreen.notify = handle_request_fullscreen; - wl_signal_add(&surface->events.request_fullscreen, + wl_signal_add(&surface->toplevel->events.request_fullscreen, &roots_surface->request_fullscreen); roots_surface->new_popup.notify = handle_new_popup; wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup); diff --git a/types/wlr_xdg_shell.c b/types/wlr_xdg_shell.c index cf713eb9..382cf839 100644 --- a/types/wlr_xdg_shell.c +++ b/types/wlr_xdg_shell.c @@ -198,16 +198,15 @@ static void xdg_surface_unmap(struct wlr_xdg_surface *surface) { wlr_signal_emit_safe(&surface->events.unmap, surface); } - if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) { - wl_resource_set_user_data(surface->toplevel->resource, NULL); - free(surface->toplevel); - surface->toplevel = NULL; - } - - if (surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { - wl_resource_set_user_data(surface->popup->resource, NULL); - - if (surface->popup->seat) { + switch (surface->role) { + case WLR_XDG_SURFACE_ROLE_TOPLEVEL: + free(surface->toplevel->title); + surface->toplevel->title = NULL; + free(surface->toplevel->app_id); + surface->toplevel->app_id = NULL; + break; + case WLR_XDG_SURFACE_ROLE_POPUP: + if (surface->popup->seat != NULL) { struct wlr_xdg_popup_grab *grab = xdg_shell_popup_grab_from_seat(surface->client->shell, surface->popup->seat); @@ -222,11 +221,12 @@ static void xdg_surface_unmap(struct wlr_xdg_surface *surface) { wlr_seat_keyboard_end_grab(grab->seat); } } - } - wl_list_remove(&surface->popup->link); - free(surface->popup); - surface->popup = NULL; + surface->popup->seat = NULL; + } + break; + case WLR_XDG_SURFACE_ROLE_NONE: + assert(false && "not reached"); } struct wlr_xdg_surface_configure *configure, *tmp; @@ -234,13 +234,7 @@ static void xdg_surface_unmap(struct wlr_xdg_surface *surface) { xdg_surface_configure_destroy(configure); } - surface->role = WLR_XDG_SURFACE_ROLE_NONE; - free(surface->title); - surface->title = NULL; - free(surface->app_id); - surface->app_id = NULL; - - surface->added = surface->configured = surface->mapped = false; + surface->configured = surface->mapped = false; surface->configure_serial = 0; if (surface->configure_idle) { wl_event_source_remove(surface->configure_idle); @@ -253,6 +247,29 @@ static void xdg_surface_unmap(struct wlr_xdg_surface *surface) { memset(&surface->next_geometry, 0, sizeof(struct wlr_box)); } +static void xdg_toplevel_destroy(struct wlr_xdg_surface *surface) { + assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); + xdg_surface_unmap(surface); + + wl_resource_set_user_data(surface->toplevel->resource, NULL); + free(surface->toplevel); + surface->toplevel = NULL; + + surface->role = WLR_XDG_SURFACE_ROLE_NONE; +} + +static void xdg_popup_destroy(struct wlr_xdg_surface *surface) { + assert(surface->role == WLR_XDG_SURFACE_ROLE_POPUP); + xdg_surface_unmap(surface); + + wl_resource_set_user_data(surface->popup->resource, NULL); + wl_list_remove(&surface->popup->link); + free(surface->popup); + surface->popup = NULL; + + surface->role = WLR_XDG_SURFACE_ROLE_NONE; +} + static void xdg_surface_destroy(struct wlr_xdg_surface *surface) { if (surface->role != WLR_XDG_SURFACE_ROLE_NONE) { xdg_surface_unmap(surface); @@ -260,6 +277,18 @@ static void xdg_surface_destroy(struct wlr_xdg_surface *surface) { wlr_signal_emit_safe(&surface->events.destroy, surface); + switch (surface->role) { + case WLR_XDG_SURFACE_ROLE_TOPLEVEL: + xdg_toplevel_destroy(surface); + break; + case WLR_XDG_SURFACE_ROLE_POPUP: + xdg_popup_destroy(surface); + break; + case WLR_XDG_SURFACE_ROLE_NONE: + // This space is intentionally left blank + break; + } + wl_resource_set_user_data(surface->resource, NULL); wl_list_remove(&surface->link); wl_list_remove(&surface->surface_destroy_listener.link); @@ -574,7 +603,7 @@ static void xdg_popup_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_popup_resource(resource); if (surface != NULL) { - xdg_surface_unmap(surface); + xdg_popup_destroy(surface); } } @@ -673,8 +702,8 @@ static void xdg_toplevel_handle_set_title(struct wl_client *client, return; } - free(surface->title); - surface->title = tmp; + free(surface->toplevel->title); + surface->toplevel->title = tmp; } static void xdg_toplevel_handle_set_app_id(struct wl_client *client, @@ -688,8 +717,8 @@ static void xdg_toplevel_handle_set_app_id(struct wl_client *client, return; } - free(surface->app_id); - surface->app_id = tmp; + free(surface->toplevel->app_id); + surface->toplevel->app_id = tmp; } static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, @@ -720,7 +749,7 @@ static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, .y = y, }; - wlr_signal_emit_safe(&surface->events.request_show_window_menu, &event); + wlr_signal_emit_safe(&surface->toplevel->events.request_show_window_menu, &event); } static void xdg_toplevel_handle_move(struct wl_client *client, @@ -749,7 +778,7 @@ static void xdg_toplevel_handle_move(struct wl_client *client, .serial = serial, }; - wlr_signal_emit_safe(&surface->events.request_move, &event); + wlr_signal_emit_safe(&surface->toplevel->events.request_move, &event); } static void xdg_toplevel_handle_resize(struct wl_client *client, @@ -779,7 +808,7 @@ static void xdg_toplevel_handle_resize(struct wl_client *client, .edges = edges, }; - wlr_signal_emit_safe(&surface->events.request_resize, &event); + wlr_signal_emit_safe(&surface->toplevel->events.request_resize, &event); } static void xdg_toplevel_handle_set_max_size(struct wl_client *client, @@ -803,7 +832,7 @@ static void xdg_toplevel_handle_set_maximized(struct wl_client *client, struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); surface->toplevel->next.maximized = true; - wlr_signal_emit_safe(&surface->events.request_maximize, surface); + wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); } static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, @@ -811,7 +840,7 @@ static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); surface->toplevel->next.maximized = false; - wlr_signal_emit_safe(&surface->events.request_maximize, surface); + wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); } static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, @@ -832,7 +861,7 @@ static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, .output = output, }; - wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); + wlr_signal_emit_safe(&surface->toplevel->events.request_fullscreen, &event); } static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, @@ -848,14 +877,14 @@ static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, .output = NULL, }; - wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); + wlr_signal_emit_safe(&surface->toplevel->events.request_fullscreen, &event); } static void xdg_toplevel_handle_set_minimized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - wlr_signal_emit_safe(&surface->events.request_minimize, surface); + wlr_signal_emit_safe(&surface->toplevel->events.request_minimize, surface); } static const struct xdg_toplevel_interface xdg_toplevel_implementation = { @@ -887,7 +916,7 @@ static void xdg_toplevel_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); if (surface != NULL) { - xdg_surface_unmap(surface); + xdg_toplevel_destroy(surface); } } @@ -905,6 +934,12 @@ static void xdg_surface_handle_get_toplevel(struct wl_client *client, wl_resource_post_no_memory(resource); return; } + wl_signal_init(&surface->toplevel->events.request_maximize); + wl_signal_init(&surface->toplevel->events.request_fullscreen); + wl_signal_init(&surface->toplevel->events.request_minimize); + wl_signal_init(&surface->toplevel->events.request_move); + wl_signal_init(&surface->toplevel->events.request_resize); + wl_signal_init(&surface->toplevel->events.request_show_window_menu); surface->role = WLR_XDG_SURFACE_ROLE_TOPLEVEL; surface->toplevel->base = surface; @@ -1349,12 +1384,6 @@ static void xdg_shell_handle_get_xdg_surface(struct wl_client *wl_client, wl_list_init(&surface->configure_list); wl_list_init(&surface->popups); - wl_signal_init(&surface->events.request_maximize); - wl_signal_init(&surface->events.request_fullscreen); - wl_signal_init(&surface->events.request_minimize); - wl_signal_init(&surface->events.request_move); - wl_signal_init(&surface->events.request_resize); - wl_signal_init(&surface->events.request_show_window_menu); wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.ping_timeout); wl_signal_init(&surface->events.new_popup); -- cgit v1.2.3 From 8371e2f41dbcb8d3ae42a4fb386577d97301ac5a Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 27 Mar 2018 14:49:31 -0400 Subject: implement flip_x --- include/wlr/types/wlr_xdg_shell_v6.h | 8 ++- rootston/xdg_shell_v6.c | 107 +++++++++++++++++++++-------------- types/wlr_xdg_shell_v6.c | 79 +++++++++++--------------- 3 files changed, 106 insertions(+), 88 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 e192d36a..e085c493 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -296,13 +296,19 @@ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( struct wlr_xdg_surface_v6 *surface, double sx, double sy, double *popup_sx, double *popup_sy); +struct wlr_box wlr_xdg_positioner_v6_get_geometry( + struct wlr_xdg_positioner_v6_attributes *positioner); + /** * Get the anchor point for this popup in the root parent's coordinate system. */ void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup, int *root_sx, int *root_sy); -void wlr_positioner_v6_invert( +void wlr_positioner_v6_invert_x( + struct wlr_xdg_positioner_v6_attributes *positioner); + +void wlr_positioner_v6_invert_y( struct wlr_xdg_positioner_v6_attributes *positioner); #endif diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 36ecc897..0a698e50 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -38,62 +38,84 @@ static void popup_handle_new_popup(struct wl_listener *listener, void *data) { popup_create(popup->view_child.view, wlr_popup); } -static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, - struct wlr_xdg_popup_v6 *wlr_popup) { - struct roots_xdg_popup_v6 *popup = - calloc(1, sizeof(struct roots_xdg_popup_v6)); - if (popup == NULL) { - return NULL; - } - - struct wlr_xdg_surface_v6 *parent = wlr_popup->parent; - double popup_lx = wlr_popup->geometry.x; - double popup_ly = wlr_popup->geometry.y; +static void popup_get_coords(struct wlr_xdg_popup_v6 *popup, + double *sx, double *sy) { + struct wlr_xdg_surface_v6 *parent = popup->parent; + double popup_sx = popup->geometry.x; + double popup_sy = popup->geometry.y; while (parent->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { - popup_lx += parent->popup->geometry.x; - popup_ly += parent->popup->geometry.y; + popup_sx += parent->popup->geometry.x; + popup_sy += parent->popup->geometry.y; parent = parent->popup->parent; } - popup_lx += view->x + parent->geometry.x; - popup_ly += view->y + parent->geometry.y; + *sx = popup_sx + parent->geometry.x; + *sy = popup_sy + parent->geometry.y; +} + +static void popup_is_constrained(struct roots_xdg_popup_v6 *popup, + bool *x_constrained, bool *y_constrained) { + struct roots_view *view = popup->view_child.view; + struct wlr_output_layout *layout = view->desktop->layout; + struct wlr_xdg_popup_v6 *wlr_popup = popup->wlr_popup; int popup_width = wlr_popup->geometry.width; int popup_height = wlr_popup->geometry.height; - int anchor_x, anchor_y; - wlr_xdg_popup_v6_get_anchor_point(wlr_popup, &anchor_x, &anchor_y); - anchor_x += popup_lx; - anchor_y += popup_ly; + int anchor_lx, anchor_ly; + wlr_xdg_popup_v6_get_anchor_point(wlr_popup, &anchor_lx, &anchor_ly); - struct wlr_output_layout *layout = view->desktop->layout; + double popup_lx, popup_ly; + popup_get_coords(wlr_popup, &popup_lx, &popup_ly); + popup_lx += view->x; + popup_ly += view->y; + + anchor_lx += popup_lx; + anchor_ly += popup_ly; + + double dest_x = 0, dest_y = 0; + wlr_output_layout_closest_point(layout, NULL, anchor_lx, anchor_ly, + &dest_x, &dest_y); - // get the output that contains (or closest to) the anchor point struct wlr_output *output = - wlr_output_layout_output_at(layout, anchor_x, anchor_y); - if (output == NULL) { - // TODO find the closest output to the anchor - assert(false); - } + wlr_output_layout_output_at(layout, dest_x, dest_y); + // XXX: handle empty output layout + assert(output); - // does the output completely contain the popup? struct wlr_box *output_box = wlr_output_layout_get_box(layout, output); - bool output_contains_popup_x = popup_lx >= output_box->x && - popup_lx + popup_width <= output_box->x + output_box->width; - bool output_contains_popup_y = popup_ly >= output_box->y && - popup_ly + popup_height <= output_box->y + output_box->height; - - if (!output_contains_popup_x) { - // TODO flip_x - // TODO slide_x - // TODO resize_x - } + *x_constrained = popup_lx <= output_box->x || + popup_lx + popup_width >= output_box->x + output_box->width; + *y_constrained = popup_ly <= output_box->y || + popup_ly + popup_height >= output_box->y + output_box->height; +} + +static void popup_unconstrain_flip(struct roots_xdg_popup_v6 *popup) { + bool x_constrained, y_constrained; + popup_is_constrained(popup, &x_constrained, &y_constrained); - if (!output_contains_popup_y) { - // TODO flip_y - // TODO slide_y - // TODO resize_y + if (x_constrained) { + wlr_positioner_v6_invert_x(&popup->wlr_popup->positioner); } + if (y_constrained) { + wlr_positioner_v6_invert_y(&popup->wlr_popup->positioner); + } + + popup->wlr_popup->geometry = + wlr_xdg_positioner_v6_get_geometry(&popup->wlr_popup->positioner); +} + +static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) { + popup_unconstrain_flip(popup); + // TODO popup_unconstrain_slide(popup); + // TODO popup_unconstrain_resize(popup); +} +static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, + struct wlr_xdg_popup_v6 *wlr_popup) { + struct roots_xdg_popup_v6 *popup = + calloc(1, sizeof(struct roots_xdg_popup_v6)); + if (popup == NULL) { + return NULL; + } popup->wlr_popup = wlr_popup; popup->view_child.destroy = popup_destroy; view_child_init(&popup->view_child, view, wlr_popup->base->surface); @@ -101,6 +123,9 @@ static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy); popup->new_popup.notify = popup_handle_new_popup; wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup); + + popup_unconstrain(popup); + return popup; } diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index fc3a38d4..76340a3c 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -399,9 +399,7 @@ static void xdg_shell_handle_create_positioner(struct wl_client *wl_client, positioner, xdg_positioner_destroy); } -static struct wlr_box xdg_positioner_get_geometry( - struct wlr_xdg_positioner_v6_attributes *positioner, - struct wlr_xdg_surface_v6 *surface, struct wlr_xdg_surface_v6 *parent) { +struct wlr_box wlr_xdg_positioner_v6_get_geometry(struct wlr_xdg_positioner_v6_attributes *positioner) { struct wlr_box geometry = { .x = positioner->offset.x, .y = positioner->offset.y, @@ -589,7 +587,7 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, surface->popup->base = surface; surface->popup->parent = parent; surface->popup->geometry = - xdg_positioner_get_geometry(positioner->attrs, surface, parent); + wlr_xdg_positioner_v6_get_geometry(positioner->attrs); // positioner properties memcpy(&surface->popup->positioner, positioner->attrs, @@ -1675,50 +1673,39 @@ void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup, */ } -void wlr_positioner_v6_invert( - struct wlr_xdg_positioner_v6_attributes *positioner) { - enum wlr_positioner_v6_anchor anchor = positioner->anchor; +void wlr_positioner_v6_invert_x(struct wlr_xdg_positioner_v6_attributes *positioner) { + if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_LEFT) { + positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_LEFT; + positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_RIGHT; + } else if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_RIGHT) { + positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_RIGHT; + positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_LEFT; + } - if (anchor == WLR_POSITIONER_V6_ANCHOR_NONE) { - // already inverted - } else if (anchor == WLR_POSITIONER_V6_ANCHOR_TOP) { - positioner->anchor = WLR_POSITIONER_V6_ANCHOR_BOTTOM; - } else if (anchor == WLR_POSITIONER_V6_ANCHOR_BOTTOM) { - positioner->anchor = WLR_POSITIONER_V6_ANCHOR_TOP; - } else if (anchor == WLR_POSITIONER_V6_ANCHOR_LEFT) { - positioner->anchor = WLR_POSITIONER_V6_ANCHOR_RIGHT; - } else if (anchor == WLR_POSITIONER_V6_ANCHOR_RIGHT) { - positioner->anchor = WLR_POSITIONER_V6_ANCHOR_LEFT; - } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_TOP | - WLR_POSITIONER_V6_ANCHOR_LEFT)) { - positioner->anchor = WLR_POSITIONER_V6_ANCHOR_BOTTOM | WLR_POSITIONER_V6_ANCHOR_RIGHT; - } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_TOP | - WLR_POSITIONER_V6_ANCHOR_RIGHT)) { - positioner->anchor = WLR_POSITIONER_V6_ANCHOR_BOTTOM | WLR_POSITIONER_V6_ANCHOR_LEFT; - } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_BOTTOM | - WLR_POSITIONER_V6_ANCHOR_LEFT)) { - positioner->anchor = WLR_POSITIONER_V6_ANCHOR_TOP | WLR_POSITIONER_V6_ANCHOR_RIGHT; - } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_BOTTOM | - WLR_POSITIONER_V6_ANCHOR_RIGHT)) { - positioner->anchor = WLR_POSITIONER_V6_ANCHOR_TOP | WLR_POSITIONER_V6_ANCHOR_LEFT; + if (positioner->gravity & WLR_POSITIONER_V6_GRAVITY_RIGHT) { + positioner->gravity &= ~WLR_POSITIONER_V6_GRAVITY_RIGHT; + positioner->gravity |= WLR_POSITIONER_V6_GRAVITY_LEFT; + } else if (positioner->gravity & WLR_POSITIONER_V6_GRAVITY_LEFT) { + positioner->gravity &= ~WLR_POSITIONER_V6_GRAVITY_LEFT; + positioner->gravity |= WLR_POSITIONER_V6_GRAVITY_RIGHT; } +} - enum wlr_positioner_v6_gravity gravity = positioner->gravity; - switch (gravity) { - case WLR_POSITIONER_V6_GRAVITY_NONE: - // already inverted - break; - case WLR_POSITIONER_V6_GRAVITY_TOP: - positioner->gravity = WLR_POSITIONER_V6_GRAVITY_BOTTOM; - break; - case WLR_POSITIONER_V6_GRAVITY_BOTTOM: - positioner->gravity = WLR_POSITIONER_V6_GRAVITY_TOP; - break; - case WLR_POSITIONER_V6_GRAVITY_LEFT: - positioner->gravity = WLR_POSITIONER_V6_GRAVITY_RIGHT; - break; - case WLR_POSITIONER_V6_GRAVITY_RIGHT: - positioner->gravity = WLR_POSITIONER_V6_GRAVITY_LEFT; - break; +void wlr_positioner_v6_invert_y( + struct wlr_xdg_positioner_v6_attributes *positioner) { + if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_TOP) { + positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_TOP; + positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_BOTTOM; + } else if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_BOTTOM) { + positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_BOTTOM; + positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_TOP; + } + + if (positioner->gravity & WLR_POSITIONER_V6_GRAVITY_TOP) { + positioner->gravity &= ~WLR_POSITIONER_V6_GRAVITY_TOP; + positioner->gravity |= WLR_POSITIONER_V6_GRAVITY_BOTTOM; + } else if (positioner->gravity & WLR_POSITIONER_V6_GRAVITY_BOTTOM) { + positioner->gravity &= ~WLR_POSITIONER_V6_GRAVITY_BOTTOM; + positioner->gravity |= WLR_POSITIONER_V6_GRAVITY_TOP; } } -- cgit v1.2.3 From c42fd1018b037f20c5045fb3cbf39ac35ec980c6 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 27 Mar 2018 17:02:48 -0400 Subject: render: remove GL calls from wlr_egl --- include/render/gles2.h | 1 + include/wlr/render/egl.h | 3 +-- render/egl.c | 23 +++++++++-------------- render/gles2/renderer.c | 5 +++++ 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'include/wlr') diff --git a/include/render/gles2.h b/include/render/gles2.h index 43a8d648..33ad9a48 100644 --- a/include/render/gles2.h +++ b/include/render/gles2.h @@ -28,6 +28,7 @@ struct wlr_gles2_renderer { struct wlr_renderer wlr_renderer; struct wlr_egl *egl; + const char *exts_str; struct { GLuint quad; diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h index aa429e8e..9f4c0334 100644 --- a/include/wlr/render/egl.h +++ b/include/wlr/render/egl.h @@ -13,8 +13,7 @@ struct wlr_egl { EGLConfig config; EGLContext context; - const char *egl_exts_str; - const char *gl_exts_str; + const char *exts_str; struct { bool buffer_age; diff --git a/render/egl.c b/render/egl.c index e582b6d3..f2966774 100644 --- a/render/egl.c +++ b/render/egl.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -155,32 +154,28 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display, } eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, egl->context); - egl->egl_exts_str = eglQueryString(egl->display, EGL_EXTENSIONS); - egl->gl_exts_str = (const char*) glGetString(GL_EXTENSIONS); + egl->exts_str = eglQueryString(egl->display, EGL_EXTENSIONS); wlr_log(L_INFO, "Using EGL %d.%d", (int)major, (int)minor); - wlr_log(L_INFO, "Supported EGL extensions: %s", egl->egl_exts_str); + wlr_log(L_INFO, "Supported EGL extensions: %s", egl->exts_str); wlr_log(L_INFO, "EGL vendor: %s", eglQueryString(egl->display, EGL_VENDOR)); - wlr_log(L_INFO, "Using %s", glGetString(GL_VERSION)); - wlr_log(L_INFO, "GL vendor: %s", glGetString(GL_VENDOR)); - wlr_log(L_INFO, "Supported OpenGL ES extensions: %s", egl->gl_exts_str); - if (!check_egl_ext(egl->egl_exts_str, "EGL_WL_bind_wayland_display") || - !check_egl_ext(egl->egl_exts_str, "EGL_KHR_image_base")) { + if (!check_egl_ext(egl->exts_str, "EGL_WL_bind_wayland_display") || + !check_egl_ext(egl->exts_str, "EGL_KHR_image_base")) { wlr_log(L_ERROR, "Required egl extensions not supported"); goto error; } egl->egl_exts.buffer_age = - check_egl_ext(egl->egl_exts_str, "EGL_EXT_buffer_age"); + check_egl_ext(egl->exts_str, "EGL_EXT_buffer_age"); egl->egl_exts.swap_buffers_with_damage = - check_egl_ext(egl->egl_exts_str, "EGL_EXT_swap_buffers_with_damage") || - check_egl_ext(egl->egl_exts_str, "EGL_KHR_swap_buffers_with_damage"); + check_egl_ext(egl->exts_str, "EGL_EXT_swap_buffers_with_damage") || + check_egl_ext(egl->exts_str, "EGL_KHR_swap_buffers_with_damage"); egl->egl_exts.dmabuf_import = - check_egl_ext(egl->egl_exts_str, "EGL_EXT_image_dma_buf_import"); + check_egl_ext(egl->exts_str, "EGL_EXT_image_dma_buf_import"); egl->egl_exts.dmabuf_import_modifiers = - check_egl_ext(egl->egl_exts_str, "EGL_EXT_image_dma_buf_import_modifiers") + check_egl_ext(egl->exts_str, "EGL_EXT_image_dma_buf_import_modifiers") && eglQueryDmaBufFormatsEXT && eglQueryDmaBufModifiersEXT; print_dmabuf_formats(egl); diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 61665a07..36a62aa7 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -377,6 +377,11 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend) { renderer->egl = wlr_backend_get_egl(backend); wlr_egl_make_current(renderer->egl, EGL_NO_SURFACE, NULL); + renderer->exts_str = (const char*) glGetString(GL_EXTENSIONS); + wlr_log(L_INFO, "Using %s", glGetString(GL_VERSION)); + wlr_log(L_INFO, "GL vendor: %s", glGetString(GL_VENDOR)); + wlr_log(L_INFO, "Supported GLES2 extensions: %s", renderer->exts_str); + if (glDebugMessageCallbackKHR && glDebugMessageControlKHR) { glEnable(GL_DEBUG_OUTPUT_KHR); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR); -- cgit v1.2.3 From f29d8b55aec7c19fd12b81b39e6806d6b996fadc Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 17 Mar 2018 15:07:48 -0400 Subject: Initial scaffolding of layer shell --- include/rootston/desktop.h | 1 + include/wlr/types/wlr_layer_shell.h | 29 ++++ protocol/meson.build | 1 + protocol/wlr-layer-shell-unstable-v1.xml | 277 +++++++++++++++++++++++++++++++ rootston/desktop.c | 6 +- types/meson.build | 2 + types/wlr_layer_shell.c | 104 ++++++++++++ 7 files changed, 419 insertions(+), 1 deletion(-) create mode 100644 include/wlr/types/wlr_layer_shell.h create mode 100644 protocol/wlr-layer-shell-unstable-v1.xml create mode 100644 types/wlr_layer_shell.c (limited to 'include/wlr') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 5986c96f..5ff9f5e2 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -48,6 +48,7 @@ struct roots_desktop { struct wlr_idle *idle; struct wlr_idle_inhibit_manager_v1 *idle_inhibit; struct wlr_linux_dmabuf *linux_dmabuf; + struct wlr_layer_shell *layer_shell; struct wl_listener new_output; struct wl_listener layout_change; diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h new file mode 100644 index 00000000..fbea1334 --- /dev/null +++ b/include/wlr/types/wlr_layer_shell.h @@ -0,0 +1,29 @@ +#ifndef WLR_TYPES_WLR_LAYER_SHELL_H +#define WLR_TYPES_WLR_LAYER_SHELL_H + +struct wlr_layer_shell { + struct wl_global *wl_global; + struct wl_list clients; + + struct wl_listener display_destroy; + + struct { + struct wl_signal new_surface; + } events; + + void *data; +}; + +struct wlr_layer_client { + struct wlr_layer_shell *shell; + struct wl_resource *resource; + struct wl_client *client; + struct wl_list surfaces; + + struct wl_list link; // wlr_layer_shell::clients +}; + +struct wlr_layer_shell *wlr_layer_shell_create(struct wl_display *display); +void wlr_layer_shell_destroy(struct wlr_layer_shell *layer_shell); + +#endif diff --git a/protocol/meson.build b/protocol/meson.build index 638b0c46..8c8a7c0e 100644 --- a/protocol/meson.build +++ b/protocol/meson.build @@ -30,6 +30,7 @@ protocols = [ 'idle.xml', 'screenshooter.xml', 'server-decoration.xml', + 'wlr-layer-shell-unstable-v1.xml', ] client_protocols = [ diff --git a/protocol/wlr-layer-shell-unstable-v1.xml b/protocol/wlr-layer-shell-unstable-v1.xml new file mode 100644 index 00000000..494b29ca --- /dev/null +++ b/protocol/wlr-layer-shell-unstable-v1.xml @@ -0,0 +1,277 @@ + + + + Copyright © 2017 Drew DeVault + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that copyright notice and this permission + notice appear in supporting documentation, and that the name of + the copyright holders not be used in advertising or publicity + pertaining to distribution of the software without specific, + written prior permission. The copyright holders make no + representations about the suitability of this software for any + purpose. It is provided "as is" without express or implied + warranty. + + THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + THIS SOFTWARE. + + + + + Clients can use this interface to assign the surface_layer role to + wl_surfaces. Such surfaces are assigned to a "layer" of the output and + rendered with a defined z-depth respective to each other. They may also be + anchored to the edges and corners of a screen and specify input handling + semantics. This interface should be suitable for the implementation of + many desktop shell components, and a broad number of other applications + that interact with the desktop. + + + + + Create a layer surface for an existing surface. This assigns the role of + layer_surface, or raises a protocol error if another role is already + assigned. + + Creating a layer surface from a wl_surface which has a buffer attached + or committed is a client error, and any attempts by a client to attach + or manipulate a buffer prior to the first layer_surface.configure call + must also be treated as errors. + + Clients can specify a namespace that defines the purpose of the layer + surface. + + + + + + + + + + + + + + + + + + These values indicate which layers a surface can be rendered in. They + are ordered by z depth, bottom-most first. Traditional shell surfaces + will typically be rendered between the bottom and top layers. + Fullscreen shell surfaces are typically rendered at the top layer. + Multiple surfaces can share a single layer, and ordering within a + single layer is undefined. + + + + + + + + + + + + An interface that may be implemented by a wl_surface, for surfaces that + are designed to be rendered as a layer of a stacked desktop-like + environment. + + Layer surface state (anchor, exclusive zone, margin) is double-buffered. + Protocol requests modify the pending state, as opposed to the current + state in use by the compositor. The wl_surface.commit request atomically + applies all pending state, replacing the current state. After commit, the + new pending state is as documented for each related request. + + + + + Requests that the compositor anchor the surface to the specified edges + and corners. If two orthoginal edges are specified (e.g. 'top' and + 'left'), then the anchor point will be the intersection of the edges + (e.g. the top left corner of the output); otherwise the anchor point + will be centered on that edge, or in the center if none is specified. + + Anchor is double-buffered, see wl_surface.commit. + + + + + + + Requests that the compositor avoids occluding an area of the surface + with other surfaces. The compositor's use of this information is + implementation-dependent - do not assume that this region will not + actually be occluded. + + This value is only meaningful if the surface is anchored to an edge, + rather than a corner. The zone is the number of pixels from the edge + that are considered exclusive. + + Exclusive zone is double-buffered, see wl_surface.commit. + + + + + + + Requests that the surface be placed some distance away from the anchor + point on the output, in pixels. Setting this value for edges you are + not anchored to has no effect. + + Margin is double-buffered, see wl_surface.commit. + + + + + + + + + + This assigns an xdg_popup's parent to this layer_surface. This popup + should have been created via xdg_surface::get_popup with the parent set + to NULL, and this request must be invoked before committing the popup's + initial state. + + See the documentation of xdg_popup for more details about what an + xdg_popup is and how it is used. + + + + + + + This creates a layer input for this layer surface. This can be used to + control input semantics for the layer surface on the specified wl_seat. + + + + + + + + When a configure event is received, if a client commits the + surface in response to the configure event, then the client + must make an ack_configure request sometime before the commit + request, passing along the serial of the configure event. + + If the client receives multiple configure events before it + can respond to one, it only has to ack the last configure event. + + A client is not required to commit immediately after sending + an ack_configure request - it may even ack_configure several times + before its next surface commit. + + A client may send multiple ack_configure requests before committing, but + only the last request sent before a commit indicates which configure + event the client really is responding to. + + + + + + + This request destroys the layer surface. + + + + + + The configure event asks the client to resize its surface. + + Clients should arrange their surface for the new states, and then send + an ack_configure request with the serial sent in this configure event at + some point before committing the new surface. + + The client is free to dismiss all but the last configure event it + received. + + The width and height arguments specify the size of the window in + surface-local coordinates. + + The size is a hint, in the sense that the client is free to ignore it if + it doesn't resize, pick a smaller size (to satisfy aspect ratio or + resize in steps of NxM pixels). If the client picks a smaller size and + is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the + surface will be centered on this axis. + + If the width or height arguments are zero, it means the client should + decide its own window dimension. + + + + + + + + + + + + + + + + + + + + + + Clients can use this interface to specify input semantics for a layer + surface on a given seat. By default, layer surfaces are considered + non-interactive by seats, and will not participate in their focus + semantics or receive input events for them. + + Input state is double-buffered. Protocol requests modify the pending + state, as opposed to the current state in use by the compositor. The + wl_surface.commit request for the associated layer surface atomically + applies all pending state, replacing the current state. After commit, the + new pending state is as documented for each related request. + + + + + Requests that the seat send input events for the specified input devices + to this layer surface. + + Positional events (pointer and touch) will only be sent if the layer + surface is the top-most interactive surface, and only when the position + of these events are relative to the surface. Enter and leave events will + be signalled normally in these cases. + + Keyboard events will treat the layer surface as the only focused surface + on the seat. Upon requesting keyboard events, the layer surface will + receive a keyboard enter event. A leave event is signalled when it + invokes set_events again without keyboard events specified. + + Events is double-buffered, see wl_surface.commit. + + + + + + + This request destroys the layer input. + + + + + + + + + + + diff --git a/rootston/desktop.c b/rootston/desktop.c index 65d9a280..dcf0b7b2 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -9,9 +9,10 @@ #include #include #include +#include +#include #include #include -#include #include #include #include @@ -714,6 +715,9 @@ struct roots_desktop *desktop_create(struct roots_server *server, &desktop->wl_shell_surface); desktop->wl_shell_surface.notify = handle_wl_shell_surface; + desktop->layer_shell = wlr_layer_shell_create(server->wl_display); + // TODO: Pick up new surfaces + #ifdef WLR_HAS_XWAYLAND const char *cursor_theme = NULL; const char *cursor_default = ROOTS_XCURSOR_DEFAULT; diff --git a/types/meson.build b/types/meson.build index 94993b52..198563b1 100644 --- a/types/meson.build +++ b/types/meson.build @@ -8,8 +8,10 @@ lib_wlr_types = static_library( 'wlr_gamma_control.c', 'wlr_idle_inhibit_v1.c', 'wlr_idle.c', + 'wlr_idle_inhibit_v1.c', 'wlr_input_device.c', 'wlr_keyboard.c', + 'wlr_layer_shell.c', 'wlr_linux_dmabuf.c', 'wlr_list.c', 'wlr_matrix.c', diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c new file mode 100644 index 00000000..51d50b17 --- /dev/null +++ b/types/wlr_layer_shell.c @@ -0,0 +1,104 @@ +#include +#include +#include +#include +#include "wlr-layer-shell-unstable-v1-protocol.h" + +static void layer_shell_handle_get_layer_surface(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *surface, + struct wl_resource *output, + uint32_t layer, + const char *namespace) { + // TODO +} + +static struct zwlr_layer_shell_v1_interface layer_shell_impl = { + .get_layer_surface = layer_shell_handle_get_layer_surface, +}; + +static struct wlr_layer_client *layer_client_from_resource( + struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, &zwlr_layer_shell_v1_interface, + &layer_shell_impl)); + return wl_resource_get_user_data(resource); +} + +static void wlr_layer_client_destroy(struct wl_resource *resource) { + struct wlr_layer_client *client = layer_client_from_resource(resource); + + // TODO: Destroy surfaces + + wl_list_remove(&client->link); + free(client); +} + +static void layer_shell_bind(struct wl_client *wl_client, void *data, + uint32_t version, uint32_t id) { + struct wlr_layer_shell *layer_shell = data; + assert(wl_client && layer_shell); + + struct wlr_layer_client *client = + calloc(1, sizeof(struct wlr_layer_client)); + if (client == NULL) { + wl_client_post_no_memory(wl_client); + return; + } + + wl_list_init(&client->surfaces); + + client->resource = wl_resource_create( + wl_client, &zwlr_layer_shell_v1_interface, version, id); + if (client->resource == NULL) { + free(client); + wl_client_post_no_memory(wl_client); + return; + } + client->client = wl_client; + client->shell = layer_shell; + + wl_resource_set_implementation(client->resource, &layer_shell_impl, client, + wlr_layer_client_destroy); + wl_list_insert(&layer_shell->clients, &client->link); +} + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_layer_shell *layer_shell = + wl_container_of(listener, layer_shell, display_destroy); + wlr_layer_shell_destroy(layer_shell); +} + +struct wlr_layer_shell *wlr_layer_shell_create(struct wl_display *display) { + struct wlr_layer_shell *layer_shell = + calloc(1, sizeof(struct wlr_layer_shell)); + if (!layer_shell) { + return NULL; + } + + wl_list_init(&layer_shell->clients); + + struct wl_global *wl_global = wl_global_create(display, + &zwlr_layer_shell_v1_interface, 1, layer_shell, layer_shell_bind); + if (!wl_global) { + free(layer_shell); + return NULL; + } + layer_shell->wl_global = wl_global; + + wl_signal_init(&layer_shell->events.new_surface); + + layer_shell->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &layer_shell->display_destroy); + + return layer_shell; +} + +void wlr_layer_shell_destroy(struct wlr_layer_shell *layer_shell) { + if (!layer_shell) { + return; + } + wl_list_remove(&layer_shell->display_destroy.link); + wl_global_destroy(layer_shell->wl_global); + free(layer_shell); +} -- cgit v1.2.3 From 3ba57fccd1f0c66b9cbf3d70e73776b11c405ee8 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 17 Mar 2018 19:03:52 -0400 Subject: Wire up layer surface resources to stubs --- include/wlr/types/wlr_layer_shell.h | 50 +++++++++ include/wlr/types/wlr_xdg_shell.h | 2 +- types/wlr_layer_shell.c | 196 ++++++++++++++++++++++++++++++++++-- 3 files changed, 236 insertions(+), 12 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h index fbea1334..33bda351 100644 --- a/include/wlr/types/wlr_layer_shell.h +++ b/include/wlr/types/wlr_layer_shell.h @@ -1,5 +1,11 @@ #ifndef WLR_TYPES_WLR_LAYER_SHELL_H #define WLR_TYPES_WLR_LAYER_SHELL_H +#include +#include +#include +#include +#include +#include "wlr-layer-shell-unstable-v1-protocol.h" struct wlr_layer_shell { struct wl_global *wl_global; @@ -23,6 +29,50 @@ struct wlr_layer_client { struct wl_list link; // wlr_layer_shell::clients }; +struct wlr_layer_surface_state { + uint32_t anchor; + uint32_t exclusive_zone; + struct { + uint32_t top, right, bottom, left; + } margin; +}; + +struct wlr_layer_surface_configure { + struct wl_list link; // wlr_layer_surface::configure_list + uint32_t serial; + struct wlr_layer_surface_state *state; +}; + +struct wlr_layer_surface { + struct wlr_surface *surface; + struct wlr_layer_client *client; + struct wl_resource *resource; + struct wl_list link; // wlr_layer_client:surfaces + + const char *namespace; + enum zwlr_layer_shell_v1_layer layer; + + bool added, configured, mapped; + uint32_t configure_serial; + struct wl_event_source *configure_idle; + uint32_t configure_next_serial; + struct wl_list configure_list; + + struct wlr_layer_surface_state next; // client protocol requests + struct wlr_layer_surface_state pending; // our configure requests + struct wlr_layer_surface_state current; + + struct wl_listener surface_destroy_listener; + + struct { + struct wl_signal destroy; + struct wl_signal map; + struct wl_signal unmap; + } events; + + void *data; +}; + struct wlr_layer_shell *wlr_layer_shell_create(struct wl_display *display); void wlr_layer_shell_destroy(struct wlr_layer_shell *layer_shell); diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index a5cd3d54..18596462 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -79,7 +79,7 @@ struct wlr_xdg_toplevel { bool added; struct wlr_xdg_toplevel_state next; // client protocol requests - struct wlr_xdg_toplevel_state pending; // user configure requests + struct wlr_xdg_toplevel_state pending; // our configure requests struct wlr_xdg_toplevel_state current; char *title; diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 51d50b17..120f2197 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -1,22 +1,21 @@ +#define _POSIX_C_SOURCE 200809L #include #include +#include #include #include +#include +#include +#include "util/signal.h" #include "wlr-layer-shell-unstable-v1-protocol.h" -static void layer_shell_handle_get_layer_surface(struct wl_client *client, - struct wl_resource *resource, - uint32_t id, - struct wl_resource *surface, - struct wl_resource *output, - uint32_t layer, - const char *namespace) { - // TODO +static void resource_handle_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); } -static struct zwlr_layer_shell_v1_interface layer_shell_impl = { - .get_layer_surface = layer_shell_handle_get_layer_surface, -}; +static struct zwlr_layer_shell_v1_interface layer_shell_impl; +static struct zwlr_layer_surface_v1_interface layer_surface_impl; static struct wlr_layer_client *layer_client_from_resource( struct wl_resource *resource) { @@ -25,6 +24,181 @@ static struct wlr_layer_client *layer_client_from_resource( return wl_resource_get_user_data(resource); } +static struct wlr_layer_surface *layer_surface_from_resource( + struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, &zwlr_layer_surface_v1_interface, + &layer_surface_impl)); + return wl_resource_get_user_data(resource); +} + +static void layer_surface_handle_ack_configure(struct wl_client *client, + struct wl_resource *resource, uint32_t serial) { + // TODO +} + +static void layer_surface_handle_set_anchor(struct wl_client *client, + struct wl_resource *resource, uint32_t anchor) { + // TODO +} + +static void layer_surface_handle_set_exclusive_zone(struct wl_client *client, + struct wl_resource *resource, uint32_t zone) { + // TODO +} + +static void layer_surface_handle_set_margin(struct wl_client *client, + struct wl_resource *resource, int32_t top, int32_t right, + int32_t bottom, int32_t left) { + // TODO +} + +static void layer_surface_handle_get_popup(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *popup) { + // TODO +} + +static void layer_surface_handle_get_input(struct wl_client *client, + struct wl_resource *resource, uint32_t id, struct wl_resource *seat) { + // TODO +} + +static const struct zwlr_layer_surface_v1_interface layer_surface_implementation = { + .destroy = resource_handle_destroy, + .ack_configure = layer_surface_handle_ack_configure, + .set_anchor = layer_surface_handle_set_anchor, + .set_exclusive_zone = layer_surface_handle_set_exclusive_zone, + .set_margin = layer_surface_handle_set_margin, + .get_popup = layer_surface_handle_get_popup, + .get_input = layer_surface_handle_get_input, +}; + +static void layer_surface_configure_destroy( + struct wlr_layer_surface_configure *configure) { + if (configure == NULL) { + return; + } + wl_list_remove(&configure->link); + free(configure->state); + free(configure); +} + +static void layer_surface_unmap(struct wlr_layer_surface *surface) { + // TODO: probably need to ungrab before this event + wlr_signal_emit_safe(&surface->events.unmap, surface); + + struct wlr_layer_surface_configure *configure, *tmp; + wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { + layer_surface_configure_destroy(configure); + } + + surface->added = surface->configured = surface->mapped = false; + surface->configure_serial = 0; + if (surface->configure_idle) { + wl_event_source_remove(surface->configure_idle); + surface->configure_idle = NULL; + } + surface->configure_next_serial = 0; +} + +static void layer_surface_destroy(struct wlr_layer_surface *surface) { + layer_surface_unmap(surface); + wlr_signal_emit_safe(&surface->events.destroy, surface); + wl_resource_set_user_data(surface->resource, NULL); + wl_list_remove(&surface->link); + wl_list_remove(&surface->surface_destroy_listener.link); + wlr_surface_set_role_committed(surface->surface, NULL, NULL); + free(surface); +} + +static void layer_surface_resource_destroy(struct wl_resource *resource) { + struct wlr_layer_surface *surface = + layer_surface_from_resource(resource); + if (surface != NULL) { + layer_surface_destroy(surface); + } +} + +static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, + void *role_data) { + struct wlr_layer_surface *surface = role_data; + + if (wlr_surface_has_buffer(surface->surface) && !surface->configured) { + wl_resource_post_error(surface->resource, + ZWLR_LAYER_SHELL_V1_ERROR_ALREADY_CONSTRUCTED, + "layer_surface has never been configured"); + return; + } + if (!surface->added) { + surface->added = true; + wlr_signal_emit_safe( + &surface->client->shell->events.new_surface, surface); + } + if (surface->configured && wlr_surface_has_buffer(surface->surface) && + !surface->mapped) { + surface->mapped = true; + wlr_signal_emit_safe(&surface->events.map, surface); + } + if (surface->configured && !wlr_surface_has_buffer(surface->surface) && + surface->mapped) { + layer_surface_unmap(surface); + } +} + +static void handle_wlr_surface_destroyed(struct wl_listener *listener, + void *data) { + struct wlr_layer_surface *layer_surface = + wl_container_of(listener, layer_surface, surface_destroy_listener); + layer_surface_destroy(layer_surface); +} + +static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, + struct wl_resource *client_resource, uint32_t id, + struct wl_resource *surface_resource, + struct wl_resource *output_resource, + uint32_t layer, const char *namespace) { + struct wlr_layer_client *client = + layer_client_from_resource(client_resource); + + struct wlr_layer_surface *surface = + calloc(1, sizeof(struct wlr_layer_surface)); + if (surface == NULL) { + wl_client_post_no_memory(wl_client); + return; + } + + surface->client = client; + surface->surface = wlr_surface_from_resource(surface_resource); + surface->resource = wl_resource_create(wl_client, + &zwlr_layer_surface_v1_interface, + wl_resource_get_version(client_resource), + id); + surface->namespace = strdup(namespace); + surface->layer = layer; + if (surface->resource == NULL || surface->namespace == NULL) { + free(surface); + wl_client_post_no_memory(wl_client); + return; + } + + wl_signal_init(&surface->events.destroy); + wl_signal_add(&surface->surface->events.destroy, + &surface->surface_destroy_listener); + surface->surface_destroy_listener.notify = handle_wlr_surface_destroyed; + + wlr_surface_set_role_committed(surface->surface, + handle_wlr_surface_committed, surface); + + wlr_log(L_DEBUG, "new layer_surface %p (res %p)", + surface, surface->resource); + wl_resource_set_implementation(surface->resource, + &layer_surface_implementation, surface, layer_surface_resource_destroy); + wl_list_insert(&client->surfaces, &surface->link); +} + +static struct zwlr_layer_shell_v1_interface layer_shell_impl = { + .get_layer_surface = layer_shell_handle_get_layer_surface, +}; + static void wlr_layer_client_destroy(struct wl_resource *resource) { struct wlr_layer_client *client = layer_client_from_resource(resource); -- cgit v1.2.3 From b06105b564541680ef2feb27eef626aaca4852c0 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 17 Mar 2018 19:11:14 -0400 Subject: Implement layer surface requests --- include/wlr/types/wlr_layer_shell.h | 2 +- protocol/wlr-layer-shell-unstable-v1.xml | 10 +++-- types/wlr_layer_shell.c | 65 ++++++++++++++++++++++++-------- 3 files changed, 56 insertions(+), 21 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h index 33bda351..58c12459 100644 --- a/include/wlr/types/wlr_layer_shell.h +++ b/include/wlr/types/wlr_layer_shell.h @@ -40,7 +40,7 @@ struct wlr_layer_surface_state { struct wlr_layer_surface_configure { struct wl_list link; // wlr_layer_surface::configure_list uint32_t serial; - struct wlr_layer_surface_state *state; + struct wlr_layer_surface_state state; }; struct wlr_layer_surface { diff --git a/protocol/wlr-layer-shell-unstable-v1.xml b/protocol/wlr-layer-shell-unstable-v1.xml index 494b29ca..29ba9dd4 100644 --- a/protocol/wlr-layer-shell-unstable-v1.xml +++ b/protocol/wlr-layer-shell-unstable-v1.xml @@ -131,10 +131,10 @@ Margin is double-buffered, see wl_surface.commit. - - - - + + + + @@ -217,6 +217,8 @@ + diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 120f2197..055578bd 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -31,25 +31,68 @@ static struct wlr_layer_surface *layer_surface_from_resource( return wl_resource_get_user_data(resource); } +static void layer_surface_configure_destroy( + struct wlr_layer_surface_configure *configure) { + if (configure == NULL) { + return; + } + wl_list_remove(&configure->link); + free(configure); +} + static void layer_surface_handle_ack_configure(struct wl_client *client, struct wl_resource *resource, uint32_t serial) { - // TODO + struct wlr_layer_surface *surface = layer_surface_from_resource(resource); + + bool found = false; + struct wlr_layer_surface_configure *configure, *tmp; + wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { + if (configure->serial < serial) { + layer_surface_configure_destroy(configure); + } else if (configure->serial == serial) { + found = true; + break; + } else { + break; + } + } + if (!found) { + wl_resource_post_error(surface->client->resource, + ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SURFACE_STATE, + "wrong configure serial: %u", serial); + return; + } + + surface->configured = true; + surface->configure_serial = serial; + + surface->current.anchor = configure->state.anchor; + surface->current.exclusive_zone = configure->state.exclusive_zone; + surface->current.margin = configure->state.margin; + + layer_surface_configure_destroy(configure); } static void layer_surface_handle_set_anchor(struct wl_client *client, struct wl_resource *resource, uint32_t anchor) { - // TODO + struct wlr_layer_surface *surface = layer_surface_from_resource(resource); + surface->next.anchor = anchor; } static void layer_surface_handle_set_exclusive_zone(struct wl_client *client, struct wl_resource *resource, uint32_t zone) { - // TODO + struct wlr_layer_surface *surface = layer_surface_from_resource(resource); + surface->next.exclusive_zone = zone; } static void layer_surface_handle_set_margin(struct wl_client *client, - struct wl_resource *resource, int32_t top, int32_t right, - int32_t bottom, int32_t left) { - // TODO + struct wl_resource *resource, uint32_t top, + uint32_t right, uint32_t bottom, uint32_t left) { + struct wlr_layer_surface *surface = layer_surface_from_resource(resource); + surface->next.margin.top = top; + surface->next.margin.right = right; + surface->next.margin.bottom = bottom; + surface->next.margin.left = left; } static void layer_surface_handle_get_popup(struct wl_client *client, @@ -72,16 +115,6 @@ static const struct zwlr_layer_surface_v1_interface layer_surface_implementation .get_input = layer_surface_handle_get_input, }; -static void layer_surface_configure_destroy( - struct wlr_layer_surface_configure *configure) { - if (configure == NULL) { - return; - } - wl_list_remove(&configure->link); - free(configure->state); - free(configure); -} - static void layer_surface_unmap(struct wlr_layer_surface *surface) { // TODO: probably need to ungrab before this event wlr_signal_emit_safe(&surface->events.unmap, surface); -- cgit v1.2.3 From 1628730b09448c596c14f948fce53677980337ce Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 17 Mar 2018 21:06:54 -0400 Subject: Add wlr_layer_surface_configure --- include/wlr/types/wlr_layer_shell.h | 23 ++++++++++++ types/wlr_layer_shell.c | 74 ++++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h index 58c12459..46d0b09c 100644 --- a/include/wlr/types/wlr_layer_shell.h +++ b/include/wlr/types/wlr_layer_shell.h @@ -7,6 +7,18 @@ #include #include "wlr-layer-shell-unstable-v1-protocol.h" +/** + * wlr_layer_shell allows clients to arrange themselves in "layers" on the + * desktop in accordance with the wlr-layer-shell protocol. When a client is + * added, the new_surface signal will be raised and passed a reference to our + * wlr_layer_surface. At this time, the client will have configured the surface + * as it desires, including information like desired anchors and margins. The + * compositor should use this information to decide how to arrange the layer + * on-screen, then determine the dimensions of the layer and call + * wlr_layer_surface_configure. The client will then attach a buffer and commit + * the surface, at which point the wlr_layer_surface map signal is raised and + * the compositor should begin rendering the surface. + */ struct wlr_layer_shell { struct wl_global *wl_global; struct wl_list clients; @@ -30,11 +42,14 @@ struct wlr_layer_client { }; struct wlr_layer_surface_state { + // Client uint32_t anchor; uint32_t exclusive_zone; struct { uint32_t top, right, bottom, left; } margin; + // Server + uint32_t width, height; }; struct wlr_layer_surface_configure { @@ -76,4 +91,12 @@ struct wlr_layer_surface { struct wlr_layer_shell *wlr_layer_shell_create(struct wl_display *display); void wlr_layer_shell_destroy(struct wlr_layer_shell *layer_shell); +/** + * Notifies the layer surface to configure itself with this width/height. The + * layer_surface will signal its map event when the surface is ready to assume + * this size. + */ +void wlr_layer_surface_configure(struct wlr_layer_surface *surface, + uint32_t width, uint32_t height); + #endif diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 709d3cbc..242d3b14 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -151,6 +151,76 @@ static void layer_surface_resource_destroy(struct wl_resource *resource) { } } +static bool wlr_layer_surface_state_changed(struct wlr_layer_surface *surface) { + if (!surface->configured) { + return false; + } + + struct wlr_layer_surface_state *state; + if (wl_list_empty(&surface->configure_list)) { + state = &surface->current; + } else { + struct wlr_layer_surface_configure *configure = + wl_container_of(surface->configure_list.prev, configure, link); + state = &configure->state; + } + + return !memcmp(state, &surface->pending, + sizeof(struct wlr_layer_surface_state)); +} + +static void wlr_layer_surface_send_configure(void *user_data) { + struct wlr_layer_surface *surface = user_data; + surface->configure_idle = NULL; + struct wlr_layer_surface_configure *configure = + calloc(1, sizeof(struct wlr_layer_surface_configure)); + if (configure == NULL) { + wl_client_post_no_memory(surface->client->client); + return; + } + + wl_list_insert(surface->configure_list.prev, &configure->link); + configure->serial = surface->configure_next_serial; + configure->state = surface->pending; + + zwlr_layer_surface_v1_send_configure(surface->resource, + configure->serial, configure->state.width, configure->state.height); +} + +static uint32_t wlr_layer_surface_schedule_configure( + struct wlr_layer_surface *surface) { + struct wl_display *display = wl_client_get_display(surface->client->client); + struct wl_event_loop *loop = wl_display_get_event_loop(display); + bool changed = wlr_layer_surface_state_changed(surface); + + if (surface->configure_idle != NULL) { + if (changed) { + // configure request already scheduled + return surface->configure_next_serial; + } + // configure request not necessary anymore + wl_event_source_remove(surface->configure_idle); + surface->configure_idle = NULL; + return 0; + } else { + if (!changed) { + // configure request not necessary + return 0; + } + surface->configure_next_serial = wl_display_next_serial(display); + surface->configure_idle = wl_event_loop_add_idle(loop, + wlr_layer_surface_send_configure, surface); + return surface->configure_next_serial; + } +} + +void wlr_layer_surface_configure(struct wlr_layer_surface *surface, + uint32_t width, uint32_t height) { + surface->pending.width = width; + surface->pending.height = height; + wlr_layer_surface_schedule_configure(surface); +} + static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, void *role_data) { struct wlr_layer_surface *surface = role_data; @@ -163,8 +233,8 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, } if (!surface->added) { surface->added = true; - wlr_signal_emit_safe( - &surface->client->shell->events.new_surface, surface); + wlr_signal_emit_safe(&surface->client->shell->events.new_surface, + surface); } if (surface->configured && wlr_surface_has_buffer(surface->surface) && !surface->mapped) { -- cgit v1.2.3 From 88eec637a44ede8b521c2aa44d0196c99dd5a0e3 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 18 Mar 2018 13:58:01 -0400 Subject: Address feedback --- include/wlr/types/wlr_layer_shell.h | 5 +- include/wlr/types/wlr_xdg_shell.h | 4 +- include/wlr/types/wlr_xdg_shell_v6.h | 4 +- protocol/wlr-layer-shell-unstable-v1.xml | 93 +++++++++----------------------- rootston/xdg_shell.c | 6 +-- rootston/xdg_shell_v6.c | 6 +-- types/wlr_layer_shell.c | 47 +++++++++------- types/wlr_xdg_shell.c | 64 +++++++++++----------- types/wlr_xdg_shell_v6.c | 64 +++++++++++----------- 9 files changed, 131 insertions(+), 162 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h index 46d0b09c..0807fe8d 100644 --- a/include/wlr/types/wlr_layer_shell.h +++ b/include/wlr/types/wlr_layer_shell.h @@ -48,6 +48,7 @@ struct wlr_layer_surface_state { struct { uint32_t top, right, bottom, left; } margin; + bool keyboard_interactive; // Server uint32_t width, height; }; @@ -73,8 +74,8 @@ struct wlr_layer_surface { uint32_t configure_next_serial; struct wl_list configure_list; - struct wlr_layer_surface_state next; // client protocol requests - struct wlr_layer_surface_state pending; // our configure requests + struct wlr_layer_surface_state client_pending; + struct wlr_layer_surface_state server_pending; struct wlr_layer_surface_state current; struct wl_listener surface_destroy_listener; diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index 18596462..9938f4b1 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -78,8 +78,8 @@ struct wlr_xdg_toplevel { struct wlr_xdg_surface *parent; bool added; - struct wlr_xdg_toplevel_state next; // client protocol requests - struct wlr_xdg_toplevel_state pending; // our configure requests + struct wlr_xdg_toplevel_state client_pending; + struct wlr_xdg_toplevel_state server_pending; struct wlr_xdg_toplevel_state current; char *title; diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index c6820f01..0867b2f6 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -78,8 +78,8 @@ struct wlr_xdg_toplevel_v6 { struct wlr_xdg_surface_v6 *parent; bool added; - struct wlr_xdg_toplevel_v6_state next; // client protocol requests - struct wlr_xdg_toplevel_v6_state pending; // user configure requests + struct wlr_xdg_toplevel_v6_state client_pending; + struct wlr_xdg_toplevel_v6_state server_pending; struct wlr_xdg_toplevel_v6_state current; char *title; diff --git a/protocol/wlr-layer-shell-unstable-v1.xml b/protocol/wlr-layer-shell-unstable-v1.xml index 29ba9dd4..285c9b8f 100644 --- a/protocol/wlr-layer-shell-unstable-v1.xml +++ b/protocol/wlr-layer-shell-unstable-v1.xml @@ -61,7 +61,6 @@ - @@ -87,11 +86,9 @@ are designed to be rendered as a layer of a stacked desktop-like environment. - Layer surface state (anchor, exclusive zone, margin) is double-buffered. - Protocol requests modify the pending state, as opposed to the current - state in use by the compositor. The wl_surface.commit request atomically - applies all pending state, replacing the current state. After commit, the - new pending state is as documented for each related request. + Layer surface state (anchor, exclusive zone, margin, interactivity) is + double-buffered, and will be applied at the time wl_surface.commit of the + corresponding wl_surface is called. @@ -129,12 +126,31 @@ point on the output, in pixels. Setting this value for edges you are not anchored to has no effect. + The exclusive zone includes the margin. + Margin is double-buffered, see wl_surface.commit. - - - - + + + + + + + + + Set to 1 to request that the seat send keyboard events to this layer + surface. For layers below the shell surface layer, the seat will use + normal focus semantics. For layers above the shell surface layers, the + seat will always give exclusive keyboard focus to the top-most layer + which has keyboard interactivity set to true. + + Layer surfaces receive pointer, touch, and tablet events normally. If + you do not want to receive them, set the input region on your surface + to an empty region. + + Events is double-buffered, see wl_surface.commit. + + @@ -150,15 +166,6 @@ - - - This creates a layer input for this layer surface. This can be used to - control input semantics for the layer surface on the specified wl_seat. - - - - - When a configure event is received, if a client commits the @@ -228,52 +235,4 @@ - - - - Clients can use this interface to specify input semantics for a layer - surface on a given seat. By default, layer surfaces are considered - non-interactive by seats, and will not participate in their focus - semantics or receive input events for them. - - Input state is double-buffered. Protocol requests modify the pending - state, as opposed to the current state in use by the compositor. The - wl_surface.commit request for the associated layer surface atomically - applies all pending state, replacing the current state. After commit, the - new pending state is as documented for each related request. - - - - - Requests that the seat send input events for the specified input devices - to this layer surface. - - Positional events (pointer and touch) will only be sent if the layer - surface is the top-most interactive surface, and only when the position - of these events are relative to the surface. Enter and leave events will - be signalled normally in these cases. - - Keyboard events will treat the layer surface as the only focused surface - on the seat. Upon requesting keyboard events, the layer surface will - receive a keyboard enter event. A leave event is signalled when it - invokes set_events again without keyboard events specified. - - Events is double-buffered, see wl_surface.commit. - - - - - - - This request destroys the layer input. - - - - - - - - - - diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c index 62b57641..927bd018 100644 --- a/rootston/xdg_shell.c +++ b/rootston/xdg_shell.c @@ -252,7 +252,7 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) { return; } - view_maximize(view, surface->toplevel->next.maximized); + view_maximize(view, surface->toplevel->client_pending.maximized); } static void handle_request_fullscreen(struct wl_listener *listener, @@ -403,10 +403,10 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { view->destroy = destroy; roots_surface->view = view; - if (surface->toplevel->next.maximized) { + if (surface->toplevel->client_pending.maximized) { view_maximize(view, true); } - if (surface->toplevel->next.fullscreen) { + if (surface->toplevel->client_pending.fullscreen) { view_set_fullscreen(view, true, NULL); } } diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 11bc0180..ad33c4b0 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -254,7 +254,7 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) { return; } - view_maximize(view, surface->toplevel->next.maximized); + view_maximize(view, surface->toplevel->client_pending.maximized); } static void handle_request_fullscreen(struct wl_listener *listener, @@ -405,10 +405,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->destroy = destroy; roots_surface->view = view; - if (surface->toplevel->next.maximized) { + if (surface->toplevel->client_pending.maximized) { view_maximize(view, true); } - if (surface->toplevel->next.fullscreen) { + if (surface->toplevel->client_pending.fullscreen) { view_set_fullscreen(view, true, NULL); } } diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 242d3b14..8063b219 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -76,32 +76,34 @@ static void layer_surface_handle_ack_configure(struct wl_client *client, static void layer_surface_handle_set_anchor(struct wl_client *client, struct wl_resource *resource, uint32_t anchor) { struct wlr_layer_surface *surface = layer_surface_from_resource(resource); - surface->next.anchor = anchor; + surface->client_pending.anchor = anchor; } static void layer_surface_handle_set_exclusive_zone(struct wl_client *client, struct wl_resource *resource, uint32_t zone) { struct wlr_layer_surface *surface = layer_surface_from_resource(resource); - surface->next.exclusive_zone = zone; + surface->client_pending.exclusive_zone = zone; } -static void layer_surface_handle_set_margin(struct wl_client *client, - struct wl_resource *resource, uint32_t top, - uint32_t right, uint32_t bottom, uint32_t left) { +static void layer_surface_handle_set_margin( + struct wl_client *client, struct wl_resource *resource, + int32_t top, int32_t right, int32_t bottom, int32_t left) { struct wlr_layer_surface *surface = layer_surface_from_resource(resource); - surface->next.margin.top = top; - surface->next.margin.right = right; - surface->next.margin.bottom = bottom; - surface->next.margin.left = left; + surface->client_pending.margin.top = top; + surface->client_pending.margin.right = right; + surface->client_pending.margin.bottom = bottom; + surface->client_pending.margin.left = left; } -static void layer_surface_handle_get_popup(struct wl_client *client, - struct wl_resource *resource, struct wl_resource *popup) { - // TODO +static void layer_surface_handle_set_keyboard_interactivity( + struct wl_client *client, struct wl_resource *resource, + uint32_t interactive) { + struct wlr_layer_surface *surface = layer_surface_from_resource(resource); + surface->client_pending.keyboard_interactive = interactive == 1; } -static void layer_surface_handle_get_input(struct wl_client *client, - struct wl_resource *resource, uint32_t id, struct wl_resource *seat) { +static void layer_surface_handle_get_popup(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *popup) { // TODO } @@ -111,8 +113,8 @@ static const struct zwlr_layer_surface_v1_interface layer_surface_implementation .set_anchor = layer_surface_handle_set_anchor, .set_exclusive_zone = layer_surface_handle_set_exclusive_zone, .set_margin = layer_surface_handle_set_margin, + .set_keyboard_interactivity = layer_surface_handle_set_keyboard_interactivity, .get_popup = layer_surface_handle_get_popup, - .get_input = layer_surface_handle_get_input, }; static void layer_surface_unmap(struct wlr_layer_surface *surface) { @@ -165,7 +167,7 @@ static bool wlr_layer_surface_state_changed(struct wlr_layer_surface *surface) { state = &configure->state; } - return !memcmp(state, &surface->pending, + return !memcmp(state, &surface->server_pending, sizeof(struct wlr_layer_surface_state)); } @@ -181,7 +183,7 @@ static void wlr_layer_surface_send_configure(void *user_data) { wl_list_insert(surface->configure_list.prev, &configure->link); configure->serial = surface->configure_next_serial; - configure->state = surface->pending; + configure->state = surface->server_pending; zwlr_layer_surface_v1_send_configure(surface->resource, configure->serial, configure->state.width, configure->state.height); @@ -216,8 +218,8 @@ static uint32_t wlr_layer_surface_schedule_configure( void wlr_layer_surface_configure(struct wlr_layer_surface *surface, uint32_t width, uint32_t height) { - surface->pending.width = width; - surface->pending.height = height; + surface->server_pending.width = width; + surface->server_pending.height = height; wlr_layer_surface_schedule_configure(surface); } @@ -231,6 +233,13 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, "layer_surface has never been configured"); return; } + + surface->current.anchor = surface->client_pending.anchor; + surface->current.exclusive_zone = surface->client_pending.exclusive_zone; + surface->current.margin = surface->client_pending.margin; + surface->current.keyboard_interactive = + surface->client_pending.keyboard_interactive; + if (!surface->added) { surface->added = true; wlr_signal_emit_safe(&surface->client->shell->events.new_surface, diff --git a/types/wlr_xdg_shell.c b/types/wlr_xdg_shell.c index 382cf839..d3be2c4f 100644 --- a/types/wlr_xdg_shell.c +++ b/types/wlr_xdg_shell.c @@ -815,23 +815,23 @@ static void xdg_toplevel_handle_set_max_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel->next.max_width = width; - surface->toplevel->next.max_height = height; + surface->toplevel->client_pending.max_width = width; + surface->toplevel->client_pending.max_height = height; } static void xdg_toplevel_handle_set_min_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel->next.min_width = width; - surface->toplevel->next.min_height = height; + surface->toplevel->client_pending.min_width = width; + surface->toplevel->client_pending.min_height = height; } static void xdg_toplevel_handle_set_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel->next.maximized = true; + surface->toplevel->client_pending.maximized = true; wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); } @@ -839,7 +839,7 @@ static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel->next.maximized = false; + surface->toplevel->client_pending.maximized = false; wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); } @@ -853,7 +853,7 @@ static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, output = wlr_output_from_resource(output_resource); } - surface->toplevel->next.fullscreen = true; + surface->toplevel->client_pending.fullscreen = true; struct wlr_xdg_toplevel_set_fullscreen_event event = { .surface = surface, @@ -869,7 +869,7 @@ static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, struct wlr_xdg_surface *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel->next.fullscreen = false; + surface->toplevel->client_pending.fullscreen = false; struct wlr_xdg_toplevel_set_fullscreen_event event = { .surface = surface, @@ -1087,25 +1087,25 @@ static bool wlr_xdg_surface_toplevel_state_compare( configured.height = configure->toplevel_state->height; } - if (state->pending.activated != configured.state.activated) { + if (state->server_pending.activated != configured.state.activated) { return false; } - if (state->pending.fullscreen != configured.state.fullscreen) { + if (state->server_pending.fullscreen != configured.state.fullscreen) { return false; } - if (state->pending.maximized != configured.state.maximized) { + if (state->server_pending.maximized != configured.state.maximized) { return false; } - if (state->pending.resizing != configured.state.resizing) { + if (state->server_pending.resizing != configured.state.resizing) { return false; } - if (state->pending.width == configured.width && - state->pending.height == configured.height) { + if (state->server_pending.width == configured.width && + state->server_pending.height == configured.height) { return true; } - if (state->pending.width == 0 && state->pending.height == 0) { + if (state->server_pending.width == 0 && state->server_pending.height == 0) { return true; } @@ -1123,12 +1123,12 @@ static void wlr_xdg_toplevel_send_configure( wl_resource_post_no_memory(surface->toplevel->resource); return; } - *configure->toplevel_state = surface->toplevel->pending; + *configure->toplevel_state = surface->toplevel->server_pending; uint32_t *s; struct wl_array states; wl_array_init(&states); - if (surface->toplevel->pending.maximized) { + if (surface->toplevel->server_pending.maximized) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel"); @@ -1136,7 +1136,7 @@ static void wlr_xdg_toplevel_send_configure( } *s = XDG_TOPLEVEL_STATE_MAXIMIZED; } - if (surface->toplevel->pending.fullscreen) { + if (surface->toplevel->server_pending.fullscreen) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel"); @@ -1144,7 +1144,7 @@ static void wlr_xdg_toplevel_send_configure( } *s = XDG_TOPLEVEL_STATE_FULLSCREEN; } - if (surface->toplevel->pending.resizing) { + if (surface->toplevel->server_pending.resizing) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel"); @@ -1152,7 +1152,7 @@ static void wlr_xdg_toplevel_send_configure( } *s = XDG_TOPLEVEL_STATE_RESIZING; } - if (surface->toplevel->pending.activated) { + if (surface->toplevel->server_pending.activated) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel"); @@ -1161,8 +1161,8 @@ static void wlr_xdg_toplevel_send_configure( *s = XDG_TOPLEVEL_STATE_ACTIVATED; } - uint32_t width = surface->toplevel->pending.width; - uint32_t height = surface->toplevel->pending.height; + uint32_t width = surface->toplevel->server_pending.width; + uint32_t height = surface->toplevel->server_pending.height; xdg_toplevel_send_configure(surface->toplevel->resource, width, height, &states); @@ -1270,13 +1270,13 @@ static void wlr_xdg_surface_toplevel_committed( // update state that doesn't need compositor approval surface->toplevel->current.max_width = - surface->toplevel->next.max_width; + surface->toplevel->client_pending.max_width; surface->toplevel->current.min_width = - surface->toplevel->next.min_width; + surface->toplevel->client_pending.min_width; surface->toplevel->current.max_height = - surface->toplevel->next.max_height; + surface->toplevel->client_pending.max_height; surface->toplevel->current.min_height = - surface->toplevel->next.min_height; + surface->toplevel->client_pending.min_height; } static void wlr_xdg_surface_popup_committed( @@ -1561,8 +1561,8 @@ void wlr_xdg_surface_ping(struct wlr_xdg_surface *surface) { uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_surface *surface, uint32_t width, uint32_t height) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel->pending.width = width; - surface->toplevel->pending.height = height; + surface->toplevel->server_pending.width = width; + surface->toplevel->server_pending.height = height; return wlr_xdg_surface_schedule_configure(surface); } @@ -1570,7 +1570,7 @@ uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_surface *surface, uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_surface *surface, bool activated) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel->pending.activated = activated; + surface->toplevel->server_pending.activated = activated; return wlr_xdg_surface_schedule_configure(surface); } @@ -1578,7 +1578,7 @@ uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_surface *surface, uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_surface *surface, bool maximized) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel->pending.maximized = maximized; + surface->toplevel->server_pending.maximized = maximized; return wlr_xdg_surface_schedule_configure(surface); } @@ -1586,7 +1586,7 @@ uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_surface *surface, uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_surface *surface, bool fullscreen) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel->pending.fullscreen = fullscreen; + surface->toplevel->server_pending.fullscreen = fullscreen; return wlr_xdg_surface_schedule_configure(surface); } @@ -1594,7 +1594,7 @@ uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_surface *surface, uint32_t wlr_xdg_toplevel_set_resizing(struct wlr_xdg_surface *surface, bool resizing) { assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel->pending.resizing = resizing; + surface->toplevel->server_pending.resizing = resizing; return wlr_xdg_surface_schedule_configure(surface); } diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 4c40e129..65b461b7 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -785,23 +785,23 @@ static void xdg_toplevel_handle_set_max_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel->next.max_width = width; - surface->toplevel->next.max_height = height; + surface->toplevel->client_pending.max_width = width; + surface->toplevel->client_pending.max_height = height; } static void xdg_toplevel_handle_set_min_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel->next.min_width = width; - surface->toplevel->next.min_height = height; + surface->toplevel->client_pending.min_width = width; + surface->toplevel->client_pending.min_height = height; } static void xdg_toplevel_handle_set_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel->next.maximized = true; + surface->toplevel->client_pending.maximized = true; wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); } @@ -809,7 +809,7 @@ static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel->next.maximized = false; + surface->toplevel->client_pending.maximized = false; wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); } @@ -823,7 +823,7 @@ static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, output = wlr_output_from_resource(output_resource); } - surface->toplevel->next.fullscreen = true; + surface->toplevel->client_pending.fullscreen = true; struct wlr_xdg_toplevel_v6_set_fullscreen_event event = { .surface = surface, @@ -839,7 +839,7 @@ static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, struct wlr_xdg_surface_v6 *surface = xdg_surface_from_xdg_toplevel_resource(resource); - surface->toplevel->next.fullscreen = false; + surface->toplevel->client_pending.fullscreen = false; struct wlr_xdg_toplevel_v6_set_fullscreen_event event = { .surface = surface, @@ -1057,25 +1057,25 @@ static bool wlr_xdg_surface_v6_toplevel_state_compare( configured.height = configure->toplevel_state->height; } - if (state->pending.activated != configured.state.activated) { + if (state->server_pending.activated != configured.state.activated) { return false; } - if (state->pending.fullscreen != configured.state.fullscreen) { + if (state->server_pending.fullscreen != configured.state.fullscreen) { return false; } - if (state->pending.maximized != configured.state.maximized) { + if (state->server_pending.maximized != configured.state.maximized) { return false; } - if (state->pending.resizing != configured.state.resizing) { + if (state->server_pending.resizing != configured.state.resizing) { return false; } - if (state->pending.width == configured.width && - state->pending.height == configured.height) { + if (state->server_pending.width == configured.width && + state->server_pending.height == configured.height) { return true; } - if (state->pending.width == 0 && state->pending.height == 0) { + if (state->server_pending.width == 0 && state->server_pending.height == 0) { return true; } @@ -1093,12 +1093,12 @@ static void wlr_xdg_toplevel_v6_send_configure( wl_resource_post_no_memory(surface->toplevel->resource); return; } - *configure->toplevel_state = surface->toplevel->pending; + *configure->toplevel_state = surface->toplevel->server_pending; uint32_t *s; struct wl_array states; wl_array_init(&states); - if (surface->toplevel->pending.maximized) { + if (surface->toplevel->server_pending.maximized) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel"); @@ -1106,7 +1106,7 @@ static void wlr_xdg_toplevel_v6_send_configure( } *s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED; } - if (surface->toplevel->pending.fullscreen) { + if (surface->toplevel->server_pending.fullscreen) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel"); @@ -1114,7 +1114,7 @@ static void wlr_xdg_toplevel_v6_send_configure( } *s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN; } - if (surface->toplevel->pending.resizing) { + if (surface->toplevel->server_pending.resizing) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel"); @@ -1122,7 +1122,7 @@ static void wlr_xdg_toplevel_v6_send_configure( } *s = ZXDG_TOPLEVEL_V6_STATE_RESIZING; } - if (surface->toplevel->pending.activated) { + if (surface->toplevel->server_pending.activated) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel"); @@ -1131,8 +1131,8 @@ static void wlr_xdg_toplevel_v6_send_configure( *s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED; } - uint32_t width = surface->toplevel->pending.width; - uint32_t height = surface->toplevel->pending.height; + uint32_t width = surface->toplevel->server_pending.width; + uint32_t height = surface->toplevel->server_pending.height; zxdg_toplevel_v6_send_configure(surface->toplevel->resource, width, height, &states); @@ -1240,13 +1240,13 @@ static void wlr_xdg_surface_v6_toplevel_committed( // update state that doesn't need compositor approval surface->toplevel->current.max_width = - surface->toplevel->next.max_width; + surface->toplevel->client_pending.max_width; surface->toplevel->current.min_width = - surface->toplevel->next.min_width; + surface->toplevel->client_pending.min_width; surface->toplevel->current.max_height = - surface->toplevel->next.max_height; + surface->toplevel->client_pending.max_height; surface->toplevel->current.min_height = - surface->toplevel->next.min_height; + surface->toplevel->client_pending.min_height; } static void wlr_xdg_surface_v6_popup_committed( @@ -1531,8 +1531,8 @@ void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface) { uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, uint32_t width, uint32_t height) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel->pending.width = width; - surface->toplevel->pending.height = height; + surface->toplevel->server_pending.width = width; + surface->toplevel->server_pending.height = height; return wlr_xdg_surface_v6_schedule_configure(surface); } @@ -1540,7 +1540,7 @@ uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, bool activated) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel->pending.activated = activated; + surface->toplevel->server_pending.activated = activated; return wlr_xdg_surface_v6_schedule_configure(surface); } @@ -1548,7 +1548,7 @@ uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, bool maximized) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel->pending.maximized = maximized; + surface->toplevel->server_pending.maximized = maximized; return wlr_xdg_surface_v6_schedule_configure(surface); } @@ -1556,7 +1556,7 @@ uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, bool fullscreen) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel->pending.fullscreen = fullscreen; + surface->toplevel->server_pending.fullscreen = fullscreen; return wlr_xdg_surface_v6_schedule_configure(surface); } @@ -1564,7 +1564,7 @@ uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, bool resizing) { assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); - surface->toplevel->pending.resizing = resizing; + surface->toplevel->server_pending.resizing = resizing; return wlr_xdg_surface_v6_schedule_configure(surface); } -- cgit v1.2.3 From 4bf936360d42fb5b96a44fd17028ae66fc462362 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 19 Mar 2018 23:11:37 -0400 Subject: Arrange & render layer surfaces --- examples/layer-shell.c | 7 +- include/rootston/desktop.h | 2 - include/rootston/layers.h | 3 + include/rootston/output.h | 3 + include/wlr/types/wlr_layer_shell.h | 3 +- protocol/wlr-layer-shell-unstable-v1.xml | 28 +++++-- render/egl.c | 2 +- rootston/desktop.c | 4 - rootston/layer_shell.c | 135 ++++++++++++++++++++++++++++++- rootston/output.c | 57 ++++++++++--- types/wlr_layer_shell.c | 26 +++++- 11 files changed, 235 insertions(+), 35 deletions(-) (limited to 'include/wlr') diff --git a/examples/layer-shell.c b/examples/layer-shell.c index d2e07a90..b5542f7a 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -23,7 +23,7 @@ struct wl_callback *frame_callback; static uint32_t output = 0; static uint32_t layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; static uint32_t anchor = 0; -static uint32_t width = 256, height = 256; +static int32_t width = 256, height = 256; static void draw(void); @@ -98,7 +98,7 @@ int main(int argc, char **argv) { char *namespace = "wlroots"; bool found; int c; - while ((c = getopt(argc, argv, "w:h:o:")) != -1) { + while ((c = getopt(argc, argv, "w:h:o:l:a:")) != -1) { switch (c) { case 'o': output = atoi(optarg); @@ -190,7 +190,10 @@ int main(int argc, char **argv) { struct zwlr_layer_surface_v1 *layer_surface = zwlr_layer_shell_v1_get_layer_surface(layer_shell, wl_surface, wl_output, layer, namespace); + zwlr_layer_surface_v1_set_size(layer_surface, width, height); zwlr_layer_surface_v1_set_anchor(layer_surface, anchor); + zwlr_layer_surface_v1_add_listener(layer_surface, + &layer_surface_listener, layer_surface); // TODO: margin, interactivity, exclusive zone wl_surface_commit(wl_surface); wl_display_dispatch(display); diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index ad7654a1..92cc6d9d 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -29,8 +29,6 @@ struct roots_desktop { struct wl_list views; // roots_view::link - struct wl_list layers[4]; // layer_surface::link - struct wl_list outputs; // roots_output::link struct timespec last_frame; diff --git a/include/rootston/layers.h b/include/rootston/layers.h index 269056ea..f432d53d 100644 --- a/include/rootston/layers.h +++ b/include/rootston/layers.h @@ -14,6 +14,9 @@ struct roots_layer_surface { struct wl_listener map; struct wl_listener unmap; struct wl_listener surface_commit; + + bool configured; + struct wlr_box geo; }; #endif diff --git a/include/rootston/output.h b/include/rootston/output.h index a852a204..5545d76a 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -14,6 +14,7 @@ struct roots_output { struct wl_list link; // roots_desktop:outputs struct roots_view *fullscreen_view; + struct wl_list layers[4]; // layer_surface::link struct timespec last_frame; struct wlr_output_damage *damage; @@ -35,5 +36,7 @@ void output_damage_from_view(struct roots_output *output, struct roots_view *view); void output_damage_whole_drag_icon(struct roots_output *output, struct roots_drag_icon *icon); +void output_damage_whole_surface(struct wlr_surface *surface, + double lx, double ly, float rotation, void *data); #endif diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h index 0807fe8d..3002345d 100644 --- a/include/wlr/types/wlr_layer_shell.h +++ b/include/wlr/types/wlr_layer_shell.h @@ -42,14 +42,12 @@ struct wlr_layer_client { }; struct wlr_layer_surface_state { - // Client uint32_t anchor; uint32_t exclusive_zone; struct { uint32_t top, right, bottom, left; } margin; bool keyboard_interactive; - // Server uint32_t width, height; }; @@ -61,6 +59,7 @@ struct wlr_layer_surface_configure { struct wlr_layer_surface { struct wlr_surface *surface; + struct wlr_output *output; struct wlr_layer_client *client; struct wl_resource *resource; struct wl_list link; // wlr_layer_client:surfaces diff --git a/protocol/wlr-layer-shell-unstable-v1.xml b/protocol/wlr-layer-shell-unstable-v1.xml index c4f2a7e3..d6de59ab 100644 --- a/protocol/wlr-layer-shell-unstable-v1.xml +++ b/protocol/wlr-layer-shell-unstable-v1.xml @@ -86,11 +86,27 @@ are designed to be rendered as a layer of a stacked desktop-like environment. - Layer surface state (anchor, exclusive zone, margin, interactivity) is - double-buffered, and will be applied at the time wl_surface.commit of the - corresponding wl_surface is called. + Layer surface state (size, anchor, exclusive zone, margin, interactivity) + is double-buffered, and will be applied at the time wl_surface.commit of + the corresponding wl_surface is called. + + + Sets the size of the surface in pixels. The compositor will display the + surface centered with respect to its anchors. + + If you pass -1 for either value, the compositor will assign it and + inform you of the assignment in the configure event. You must set your + anchor to opposite edges in the dimensions you omit; not doing so is a + protocol error. Both values are -1 by default. + + Size is double-buffered, see wl_surface.commit. + + + + + Requests that the compositor anchor the surface to the specified edges @@ -222,9 +238,9 @@ - - + + + diff --git a/render/egl.c b/render/egl.c index f2966774..d230f589 100644 --- a/render/egl.c +++ b/render/egl.c @@ -426,7 +426,7 @@ int wlr_egl_get_dmabuf_formats(struct wlr_egl *egl, int **formats) { if (!egl->egl_exts.dmabuf_import || !egl->egl_exts.dmabuf_import_modifiers) { - wlr_log(L_ERROR, "dmabuf extension not present"); + wlr_log(L_DEBUG, "dmabuf extension not present"); return -1; } diff --git a/rootston/desktop.c b/rootston/desktop.c index f00fc63f..015a8215 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -719,10 +719,6 @@ struct roots_desktop *desktop_create(struct roots_server *server, wl_signal_add(&desktop->layer_shell->events.new_surface, &desktop->layer_shell_surface); desktop->layer_shell_surface.notify = handle_layer_shell_surface; - for (size_t i = 0; - i < sizeof(desktop->layers) / sizeof(desktop->layers[0]); ++i) { - wl_list_init(&desktop->layers[i]); - } #ifdef WLR_HAS_XWAYLAND const char *cursor_theme = NULL; diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 50bf6466..25e683fe 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -8,8 +8,112 @@ #include #include "rootston/desktop.h" #include "rootston/layers.h" +#include "rootston/output.h" #include "rootston/server.h" +static void apply_exclusive(struct wlr_box *output_area, + uint32_t anchor, uint32_t exclusive) { + struct { + uint32_t anchors; + int *value; + int multiplier; + } edges[] = { + { + .anchors = + ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | + ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | + ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP, + .value = &output_area->y, + .multiplier = 1, + }, + { + .anchors = + ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | + ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | + ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, + .value = &output_area->height, + .multiplier = -1, + }, + { + .anchors = + ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | + ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | + ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, + .value = &output_area->x, + .multiplier = 1, + }, + { + .anchors = + ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | + ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | + ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, + .value = &output_area->width, + .multiplier = -1, + }, + }; + for (size_t i = 0; i < sizeof(edges) / sizeof(edges[0]); ++i) { + if ((anchor & edges[i].anchors)) { + edges[i].value += exclusive * edges[i].multiplier; + } + } +} + +static void arrange_layer(struct wlr_output *output, struct wl_list *list) { + struct wlr_box output_area = { .x = 0, .y = 0 }; + wlr_output_effective_resolution(output, + &output_area.width, &output_area.height); + struct roots_layer_surface *roots_surface; + wl_list_for_each(roots_surface, list, link) { + struct wlr_layer_surface *layer = roots_surface->layer_surface; + struct wlr_layer_surface_state *state = &layer->current; + struct wlr_box box = { .width = state->width, .height = state->height }; + // Horizontal axis + const uint32_t both_horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT + | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; + if ((state->anchor & both_horiz) && box.width == -1) { + box.x = 0; + box.width = output_area.width; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) { + box.x = output_area.x; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) { + box.x = output_area.width - box.width; + } else { + box.x = (output_area.width / 2) - (box.width / 2); + } + // Vertical axis + const uint32_t both_vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP + | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; + if ((state->anchor & both_vert) && box.height == -1) { + box.y = 0; + box.height = output_area.height; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) { + box.y = output_area.y; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) { + box.y = output_area.height - box.height; + } else { + box.y = (output_area.height / 2) - (box.height / 2); + } + wlr_log(L_DEBUG, "arranged layer at %dx%d@%d,%d", + box.width, box.height, box.x, box.y); + roots_surface->geo = box; + apply_exclusive(&output_area, state->anchor, state->exclusive_zone); + if (box.width != (int)state->width + || box.height != (int)state->height + || !roots_surface->configured) { + wlr_layer_surface_configure(layer, box.width, box.height); + roots_surface->configured = true; + } + } +} + +static void arrange_layers(struct wlr_output *_output) { + struct roots_output *output = _output->data; + size_t layers = sizeof(output->layers) / sizeof(output->layers[0]); + for (size_t i = 0; i < layers; ++i) { + arrange_layer(output->wlr_output, &output->layers[i]); + } +} + static void handle_destroy(struct wl_listener *listener, void *data) { // TODO } @@ -19,7 +123,13 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { } static void handle_map(struct wl_listener *listener, void *data) { - // TODO + struct wlr_layer_surface *layer_surface = data; + struct roots_layer_surface *layer = layer_surface->data; + struct wlr_output *wlr_output = layer_surface->output; + struct roots_output *output = wlr_output->data; + // TODO: This doesn't play right with output layouts and is also stupid + output_damage_whole_surface(layer_surface->surface, layer->geo.x, + layer->geo.y, 0, output); } static void handle_unmap(struct wl_listener *listener, void *data) { @@ -30,8 +140,14 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { struct wlr_layer_surface *layer_surface = data; struct roots_desktop *desktop = wl_container_of(listener, desktop, layer_shell_surface); - wlr_log(L_DEBUG, "new layer surface: namespace %s layer %d", - layer_surface->namespace, layer_surface->layer); + wlr_log(L_DEBUG, "new layer surface: namespace %s layer %d anchor %d %dx%d %d,%d,%d,%d", + layer_surface->namespace, layer_surface->layer, layer_surface->layer, + layer_surface->client_pending.width, + layer_surface->client_pending.height, + layer_surface->client_pending.margin.top, + layer_surface->client_pending.margin.right, + layer_surface->client_pending.margin.bottom, + layer_surface->client_pending.margin.left); struct roots_layer_surface *roots_surface = calloc(1, sizeof(struct roots_layer_surface)); @@ -49,6 +165,17 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { wl_signal_add(&layer_surface->events.unmap, &roots_surface->unmap); roots_surface->layer_surface = layer_surface; + layer_surface->data = roots_surface; + + struct roots_output *output = layer_surface->output->data; + wl_list_insert(&output->layers[layer_surface->layer], &roots_surface->link); + + // Temporarily set the layer's current state to client_pending + // So that we can easily arrange it + struct wlr_layer_surface_state old_state = layer_surface->current; + layer_surface->current = layer_surface->client_pending; + + arrange_layers(output->wlr_output); - wl_list_insert(&desktop->layers[layer_surface->layer], &roots_surface->link); + layer_surface->current = old_state; } diff --git a/rootston/output.c b/rootston/output.c index 52ece54d..71497608 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -13,6 +13,7 @@ #include #include #include "rootston/config.h" +#include "rootston/layers.h" #include "rootston/output.h" #include "rootston/server.h" @@ -417,6 +418,21 @@ static void surface_send_frame_done(struct wlr_surface *surface, double lx, wlr_surface_send_frame_done(surface, when); } +static void render_layer( + struct roots_output *output, + const struct wlr_box *output_layout_box, + struct render_data *data, + struct wl_list *layer) { + struct roots_layer_surface *roots_surface; + wl_list_for_each(roots_surface, layer, link) { + struct wlr_layer_surface *layer = roots_surface->layer_surface; + render_surface(layer->surface, + roots_surface->geo.x + output_layout_box->x, + roots_surface->geo.y + output_layout_box->y, + 0, data); + } +} + static void render_output(struct roots_output *output) { struct wlr_output *wlr_output = output->wlr_output; struct roots_desktop *desktop = output->desktop; @@ -433,14 +449,15 @@ static void render_output(struct roots_output *output) { float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f}; + const struct wlr_box *output_box = + wlr_output_layout_get_box(desktop->layout, wlr_output); + // Check if we can delegate the fullscreen surface to the output if (output->fullscreen_view != NULL && output->fullscreen_view->wlr_surface != NULL) { struct roots_view *view = output->fullscreen_view; // Make sure the view is centered on screen - const struct wlr_box *output_box = - wlr_output_layout_get_box(desktop->layout, wlr_output); struct wlr_box view_box; view_get_box(view, &view_box); double view_x = (double)(output_box->width - view_box.width) / 2 + @@ -498,6 +515,11 @@ static void render_output(struct roots_output *output) { wlr_renderer_clear(renderer, clear_color); } + render_layer(output, output_box, &data, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]); + render_layer(output, output_box, &data, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]); + // If a view is fullscreen on this output, render it if (output->fullscreen_view != NULL) { struct roots_view *view = output->fullscreen_view; @@ -520,20 +542,23 @@ static void render_output(struct roots_output *output) { render_surface, &data); } #endif - - goto renderer_end; - } - - // Render all views - struct roots_view *view; - wl_list_for_each_reverse(view, &desktop->views, link) { - render_view(view, &data); + } else { + // Render all views + struct roots_view *view; + wl_list_for_each_reverse(view, &desktop->views, link) { + render_view(view, &data); + } } // Render drag icons data.alpha = 1.0; drag_icons_for_each_surface(server->input, render_surface, &data); + render_layer(output, output_box, &data, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); + render_layer(output, output_box, &data, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); + renderer_end: wlr_renderer_scissor(renderer, NULL); wlr_renderer_end(renderer); @@ -603,7 +628,7 @@ static bool view_accept_damage(struct roots_output *output, return false; } -static void damage_whole_surface(struct wlr_surface *surface, +void output_damage_whole_surface(struct wlr_surface *surface, double lx, double ly, float rotation, void *data) { struct roots_output *output = data; @@ -647,13 +672,13 @@ void output_damage_whole_view(struct roots_output *output, } damage_whole_decoration(view, output); - view_for_each_surface(view, damage_whole_surface, output); + view_for_each_surface(view, output_damage_whole_surface, output); } void output_damage_whole_drag_icon(struct roots_output *output, struct roots_drag_icon *icon) { surface_for_each_surface(icon->wlr_drag_icon->surface, icon->x, icon->y, 0, - damage_whole_surface, output); + output_damage_whole_surface, output); } static void damage_from_surface(struct wlr_surface *surface, @@ -781,6 +806,7 @@ void handle_new_output(struct wl_listener *listener, void *data) { clock_gettime(CLOCK_MONOTONIC, &output->last_frame); output->desktop = desktop; output->wlr_output = wlr_output; + wlr_output->data = output; wl_list_insert(&desktop->outputs, &output->link); output->damage = wlr_output_damage_create(wlr_output); @@ -792,6 +818,11 @@ void handle_new_output(struct wl_listener *listener, void *data) { output->damage_destroy.notify = output_damage_handle_destroy; wl_signal_add(&output->damage->events.destroy, &output->damage_destroy); + size_t len = sizeof(output->layers) / sizeof(output->layers[0]); + for (size_t i = 0; i < len; ++i) { + wl_list_init(&output->layers[i]); + } + struct roots_output_config *output_config = roots_config_get_output(config, wlr_output); if (output_config) { diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index aaf9ee84..631b7009 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include "util/signal.h" @@ -69,12 +70,31 @@ static void layer_surface_handle_ack_configure(struct wl_client *client, surface->current.anchor = configure->state.anchor; surface->current.exclusive_zone = configure->state.exclusive_zone; surface->current.margin = configure->state.margin; + surface->current.width = configure->state.width; + surface->current.height = configure->state.height; layer_surface_configure_destroy(configure); } +static void layer_surface_handle_set_size(struct wl_client *client, + struct wl_resource *resource, int32_t width, int32_t height) { + struct wlr_layer_surface *surface = layer_surface_from_resource(resource); + surface->client_pending.width = width; + surface->client_pending.height = height; +} + static void layer_surface_handle_set_anchor(struct wl_client *client, struct wl_resource *resource, uint32_t anchor) { + const uint32_t max_anchor = + ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | + ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | + ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | + ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; + if (anchor > max_anchor) { + wl_resource_post_error(resource, + ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_ANCHOR, + "invalid anchor %d", anchor); + } struct wlr_layer_surface *surface = layer_surface_from_resource(resource); surface->client_pending.anchor = anchor; } @@ -110,6 +130,7 @@ static void layer_surface_handle_get_popup(struct wl_client *client, static const struct zwlr_layer_surface_v1_interface layer_surface_implementation = { .destroy = resource_handle_destroy, .ack_configure = layer_surface_handle_ack_configure, + .set_size = layer_surface_handle_set_size, .set_anchor = layer_surface_handle_set_anchor, .set_exclusive_zone = layer_surface_handle_set_exclusive_zone, .set_margin = layer_surface_handle_set_margin, @@ -155,7 +176,7 @@ static void layer_surface_resource_destroy(struct wl_resource *resource) { static bool wlr_layer_surface_state_changed(struct wlr_layer_surface *surface) { if (!surface->configured) { - return false; + return true; } struct wlr_layer_surface_state *state; @@ -239,6 +260,8 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, surface->current.margin = surface->client_pending.margin; surface->current.keyboard_interactive = surface->client_pending.keyboard_interactive; + surface->current.width = surface->client_pending.width; + surface->current.height = surface->client_pending.height; if (!surface->added) { surface->added = true; @@ -280,6 +303,7 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, surface->client = client; surface->surface = wlr_surface_from_resource(surface_resource); + surface->output = wlr_output_from_resource(output_resource); surface->resource = wl_resource_create(wl_client, &zwlr_layer_surface_v1_interface, wl_resource_get_version(client_resource), -- cgit v1.2.3 From d1c0e6fe2c21b4c7f651a82fb7342b54a4989c39 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 24 Mar 2018 18:00:01 -0400 Subject: Add layer_surface.close --- examples/layer-shell.c | 13 ++++++++++++- include/wlr/types/wlr_layer_shell.h | 7 ++++++- protocol/wlr-layer-shell-unstable-v1.xml | 10 ++++++++++ rootston/layer_shell.c | 6 ++++-- types/wlr_layer_shell.c | 11 +++++++++++ 5 files changed, 43 insertions(+), 4 deletions(-) (limited to 'include/wlr') diff --git a/examples/layer-shell.c b/examples/layer-shell.c index f3b9d3a0..08826251 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -25,6 +25,7 @@ static uint32_t output = 0; static uint32_t layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; static uint32_t anchor = 0; static int32_t width = 256, height = 256; +static bool run_display = true; static struct { struct timespec last_frame; @@ -84,8 +85,18 @@ static void layer_surface_configure(void *data, zwlr_layer_surface_v1_ack_configure(surface, serial); } +static void layer_surface_closed(void *data, + struct zwlr_layer_surface_v1 *surface) { + eglDestroySurface(egl.display, egl_surface); + wl_egl_window_destroy(egl_window); + zwlr_layer_surface_v1_destroy(surface); + wl_surface_destroy(wl_surface); + run_display = false; +} + struct zwlr_layer_surface_v1_listener layer_surface_listener = { .configure = layer_surface_configure, + .closed = layer_surface_closed, }; static void handle_global(void *data, struct wl_registry *registry, @@ -235,7 +246,7 @@ int main(int argc, char **argv) { wl_display_roundtrip(display); draw(); - while (wl_display_dispatch(display) != -1) { + while (wl_display_dispatch(display) != -1 && run_display) { // This space intentionally left blank } return 0; diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h index 3002345d..5d9feb27 100644 --- a/include/wlr/types/wlr_layer_shell.h +++ b/include/wlr/types/wlr_layer_shell.h @@ -67,7 +67,7 @@ struct wlr_layer_surface { const char *namespace; enum zwlr_layer_shell_v1_layer layer; - bool added, configured, mapped; + bool added, configured, mapped, closed; uint32_t configure_serial; struct wl_event_source *configure_idle; uint32_t configure_next_serial; @@ -99,4 +99,9 @@ void wlr_layer_shell_destroy(struct wlr_layer_shell *layer_shell); void wlr_layer_surface_configure(struct wlr_layer_surface *surface, uint32_t width, uint32_t height); +/** + * Unmaps this layer surface and notifies the client that it has been closed. + */ +void wlr_layer_surface_close(struct wlr_layer_surface *surface); + #endif diff --git a/protocol/wlr-layer-shell-unstable-v1.xml b/protocol/wlr-layer-shell-unstable-v1.xml index d6de59ab..b5cb3d3a 100644 --- a/protocol/wlr-layer-shell-unstable-v1.xml +++ b/protocol/wlr-layer-shell-unstable-v1.xml @@ -237,6 +237,16 @@ + + + The closed event is sent by the compositor when the surface will no + longer be shown. The output may have been destroyed or the user may have + asked for it to be removed. Further changes to the surface will be ignored. + The client should destroy the resource after receiving this event, and + create a new surface if they so choose. + + + diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index ac7b2b20..114a5f29 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -118,7 +118,7 @@ static void handle_output_destroy(struct wl_listener *listener, void *data) { struct roots_layer_surface *layer = wl_container_of(listener, layer, output_destroy); layer->layer_surface->output = NULL; - wl_resource_destroy(layer->layer_surface->resource); + wlr_layer_surface_close(layer->layer_surface); } static void handle_surface_commit(struct wl_listener *listener, void *data) { @@ -135,7 +135,9 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { static void unmap(struct wlr_layer_surface *layer_surface) { struct roots_layer_surface *layer = layer_surface->data; - wl_list_remove(&layer->link); + if (layer->link.prev) { + wl_list_remove(&layer->link); + } struct wlr_output *wlr_output = layer_surface->output; if (wlr_output != NULL) { diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 631b7009..59f8d568 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -244,6 +244,12 @@ void wlr_layer_surface_configure(struct wlr_layer_surface *surface, wlr_layer_surface_schedule_configure(surface); } +void wlr_layer_surface_close(struct wlr_layer_surface *surface) { + surface->closed = true; + layer_surface_unmap(surface); + zwlr_layer_surface_v1_send_closed(surface->resource); +} + static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, void *role_data) { struct wlr_layer_surface *surface = role_data; @@ -255,6 +261,11 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, return; } + if (surface->closed) { + // Ignore commits after the compositor has closed it + return; + } + surface->current.anchor = surface->client_pending.anchor; surface->current.exclusive_zone = surface->client_pending.exclusive_zone; surface->current.margin = surface->client_pending.margin; -- cgit v1.2.3 From 86ca4bea6de9b3494235201f5587cb7e00aed84e Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 26 Mar 2018 18:12:31 -0400 Subject: Fix layer rendering/layout bugs --- examples/layer-shell.c | 32 ++++++-- include/rootston/layers.h | 1 + include/wlr/types/wlr_layer_shell.h | 5 +- protocol/wlr-layer-shell-unstable-v1.xml | 31 +++++-- rootston/layer_shell.c | 136 ++++++++++++++++++++++--------- types/wlr_layer_shell.c | 35 ++++---- types/wlr_seat.c | 5 +- 7 files changed, 171 insertions(+), 74 deletions(-) (limited to 'include/wlr') diff --git a/examples/layer-shell.c b/examples/layer-shell.c index 999d948f..3518a56f 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -26,6 +26,7 @@ static uint32_t output = 0; static uint32_t layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; static uint32_t anchor = 0; static uint32_t width = 256, height = 256; +static double alpha = 1.0; static bool run_display = true; static struct { @@ -67,7 +68,7 @@ static void draw(void) { } glViewport(0, 0, width, height); - glClearColor(demo.color[0], demo.color[1], demo.color[2], 1.0); + glClearColor(demo.color[0], demo.color[1], demo.color[2], alpha); glClear(GL_COLOR_BUFFER_BIT); frame_callback = wl_surface_frame(wl_surface); @@ -135,9 +136,11 @@ int main(int argc, char **argv) { wlr_log_init(L_DEBUG, NULL); char *namespace = "wlroots"; int exclusive_zone = 0; + int32_t margin_top = 0, margin_right = 0, + margin_bottom = 0, margin_left = 0; bool found; int c; - while ((c = getopt(argc, argv, "w:h:o:l:a:x:")) != -1) { + while ((c = getopt(argc, argv, "w:h:o:l:a:x:m:t:")) != -1) { switch (c) { case 'o': output = atoi(optarg); @@ -197,6 +200,22 @@ int main(int argc, char **argv) { fprintf(stderr, "invalid anchor %s\n", optarg); return 1; } + break; + } + case 't': + alpha = atof(optarg); + break; + case 'm': { + char *endptr = optarg; + margin_top = strtol(endptr, &endptr, 10); + assert(*endptr == ','); + margin_right = strtol(endptr + 1, &endptr, 10); + assert(*endptr == ','); + margin_bottom = strtol(endptr + 1, &endptr, 10); + assert(*endptr == ','); + margin_left = strtol(endptr + 1, &endptr, 10); + assert(!*endptr); + break; } default: break; @@ -227,8 +246,9 @@ int main(int argc, char **argv) { return 1; } - wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL, - WL_SHM_FORMAT_ARGB8888); + EGLint attribs[] = { EGL_ALPHA_SIZE, 8, EGL_NONE }; + wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, + attribs, WL_SHM_FORMAT_ARGB8888); wl_surface = wl_compositor_create_surface(compositor); assert(wl_surface); @@ -240,9 +260,11 @@ int main(int argc, char **argv) { zwlr_layer_surface_v1_set_size(layer_surface, width, height); zwlr_layer_surface_v1_set_anchor(layer_surface, anchor); zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, exclusive_zone); + zwlr_layer_surface_v1_set_margin(layer_surface, + margin_top, margin_right, margin_bottom, margin_left); zwlr_layer_surface_v1_add_listener(layer_surface, &layer_surface_listener, layer_surface); - // TODO: margin, interactivity + // TODO: interactivity wl_surface_commit(wl_surface); wl_display_roundtrip(display); diff --git a/include/rootston/layers.h b/include/rootston/layers.h index 43041786..cc285fe7 100644 --- a/include/rootston/layers.h +++ b/include/rootston/layers.h @@ -15,6 +15,7 @@ struct roots_layer_surface { struct wl_listener unmap; struct wl_listener surface_commit; struct wl_listener output_destroy; + struct wl_listener output_mode; bool configured; struct wlr_box geo; diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h index 5d9feb27..c24b391e 100644 --- a/include/wlr/types/wlr_layer_shell.h +++ b/include/wlr/types/wlr_layer_shell.h @@ -43,12 +43,13 @@ struct wlr_layer_client { struct wlr_layer_surface_state { uint32_t anchor; - uint32_t exclusive_zone; + int32_t exclusive_zone; struct { uint32_t top, right, bottom, left; } margin; bool keyboard_interactive; - uint32_t width, height; + uint32_t desired_width, desired_height; + uint32_t actual_width, actual_height; }; struct wlr_layer_surface_configure { diff --git a/protocol/wlr-layer-shell-unstable-v1.xml b/protocol/wlr-layer-shell-unstable-v1.xml index b5cb3d3a..fe2c72cd 100644 --- a/protocol/wlr-layer-shell-unstable-v1.xml +++ b/protocol/wlr-layer-shell-unstable-v1.xml @@ -96,15 +96,15 @@ Sets the size of the surface in pixels. The compositor will display the surface centered with respect to its anchors. - If you pass -1 for either value, the compositor will assign it and + If you pass 0 for either value, the compositor will assign it and inform you of the assignment in the configure event. You must set your anchor to opposite edges in the dimensions you omit; not doing so is a - protocol error. Both values are -1 by default. + protocol error. Both values are 0 by default. Size is double-buffered, see wl_surface.commit. - - + + @@ -127,13 +127,28 @@ implementation-dependent - do not assume that this region will not actually be occluded. - This value is only meaningful if the surface is anchored to an edge, - rather than a corner. The zone is the number of pixels from the edge - that are considered exclusive. + A positive value is only meaningful if the surface is anchored to an + edge, rather than a corner. The zone is the number of pixels from the + edge that are considered exclusive. + + Surfaces that do not wish to have an exclusive zone may instead specify + how they should interact with surfaces that do. If set to zero, the + surface indicates that it would like to be moved to avoid occluding + surfaces with a positive excluzive zone. If set to -1, the surface + indicates that it would not like to be moved to accomodate for other + surfaces, and the compositor should extend it all the way to the edges + it is anchored to. + + For example, a panel might set its exclusive zone to 10 pixels, so that + maximized shell surfaces are not shown on top of it. A notification + might set its exclusive zone to zero, so that it is moved to avoid + occluding the panel, but shell surfaces are shown underneath it. A + wallpaper or lock screen might set their exclusive zone to -1, so that + they stretch below or over the panel. Exclusive zone is double-buffered, see wl_surface.commit. - + diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index e7604ec5..e2d5b9f0 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -12,7 +12,10 @@ #include "rootston/server.h" static void apply_exclusive(struct wlr_box *usable_area, - uint32_t anchor, uint32_t exclusive) { + uint32_t anchor, int32_t exclusive) { + if (exclusive <= 0) { + return; + } struct { uint32_t anchors; int *positive_axis; @@ -64,48 +67,80 @@ static void apply_exclusive(struct wlr_box *usable_area, } static void arrange_layer(struct wlr_output *output, struct wl_list *list, - struct wlr_box *usable_area) { + struct wlr_box *usable_area, bool exclusive) { struct roots_layer_surface *roots_surface; + struct wlr_box full_area = { 0 }; + wlr_output_effective_resolution(output, + &full_area.width, &full_area.height); wl_list_for_each(roots_surface, list, link) { struct wlr_layer_surface *layer = roots_surface->layer_surface; struct wlr_layer_surface_state *state = &layer->current; - struct wlr_box box = { .width = state->width, .height = state->height }; + if (exclusive) { + if (state->exclusive_zone <= 0) { + continue; + } + } else { + if (state->exclusive_zone > 0) { + continue; + } + } + struct wlr_box bounds; + if (state->exclusive_zone == -1) { + bounds = full_area; + } else { + bounds = *usable_area; + } + struct wlr_box box = { + .width = state->desired_width, + .height = state->desired_height + }; // Horizontal axis const uint32_t both_horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; if ((state->anchor & both_horiz) && box.width == 0) { - box.x = 0; - box.width = usable_area->width; + box.x = bounds.x; + box.width = bounds.width; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) { - box.x = usable_area->x; + box.x = bounds.x; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) { - box.x = usable_area->x + (usable_area->width - box.width); + box.x = bounds.x + (bounds.width - box.width); } else { - box.x = usable_area->x + ((usable_area->width / 2) - (box.width / 2)); + box.x = bounds.x + ((bounds.width / 2) - (box.width / 2)); } // Vertical axis const uint32_t both_vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; if ((state->anchor & both_vert) && box.height == 0) { - box.y = 0; - box.height = usable_area->height; + box.y = bounds.y; + box.height = bounds.height; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) { - box.y = usable_area->y; + box.y = bounds.y; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) { - box.y = usable_area->y + (usable_area->height - box.height); + box.y = bounds.y + (bounds.height - box.height); } else { - box.y = usable_area->y + ((usable_area->height / 2) - (box.height / 2)); + box.y = bounds.y + ((bounds.height / 2) - (box.height / 2)); + } + // Margin + if ((state->anchor & both_horiz)) { + box.x += state->margin.left; + box.width -= state->margin.left + state->margin.right; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) { + box.x += state->margin.bottom; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) { + box.x -= state->margin.right; } - wlr_log(L_DEBUG, "arranged layer at %dx%d@%d,%d", - box.width, box.height, box.x, box.y); + if ((state->anchor & both_vert)) { + box.y += state->margin.top; + box.height -= state->margin.top + state->margin.bottom; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) { + box.y += state->margin.top; + } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) { + box.y -= state->margin.bottom; + } + // Apply roots_surface->geo = box; apply_exclusive(usable_area, state->anchor, state->exclusive_zone); - if (!roots_surface->configured || - box.width != (int)state->width || - box.height != (int)state->height) { - wlr_layer_surface_configure(layer, box.width, box.height); - roots_surface->configured = true; - } + wlr_layer_surface_configure(layer, box.width, box.height); } } @@ -116,25 +151,20 @@ static void arrange_layers(struct wlr_output *_output) { wlr_output_effective_resolution(output->wlr_output, &usable_area.width, &usable_area.height); + // Arrange exclusive surfaces from top->bottom arrange_layer(output->wlr_output, - &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], - &usable_area); - arrange_layer(output->wlr_output, - &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], - &usable_area); - memcpy(&output->usable_area, &usable_area, sizeof(struct wlr_box)); - + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], + &usable_area, true); arrange_layer(output->wlr_output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], - &usable_area); - - memset(&usable_area, 0, sizeof(struct wlr_box)); - wlr_output_effective_resolution(output->wlr_output, - &usable_area.width, &usable_area.height); - + &usable_area, true); arrange_layer(output->wlr_output, - &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], - &usable_area); + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], + &usable_area, true); + arrange_layer(output->wlr_output, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], + &usable_area, true); + memcpy(&output->usable_area, &usable_area, sizeof(struct wlr_box)); struct roots_view *view; wl_list_for_each(view, &output->desktop->views, link) { @@ -142,15 +172,37 @@ static void arrange_layers(struct wlr_output *_output) { view_arrange_maximized(view); } } + + // Arrange non-exlusive surfaces from top->bottom + wlr_output_effective_resolution(output->wlr_output, + &usable_area.width, &usable_area.height); + arrange_layer(output->wlr_output, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], + &usable_area, false); + arrange_layer(output->wlr_output, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], + &usable_area, false); + arrange_layer(output->wlr_output, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], + &usable_area, false); + arrange_layer(output->wlr_output, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], + &usable_area, false); } static void handle_output_destroy(struct wl_listener *listener, void *data) { struct roots_layer_surface *layer = wl_container_of(listener, layer, output_destroy); layer->layer_surface->output = NULL; + wl_list_remove(&layer->output_destroy.link); + wl_list_remove(&layer->output_mode.link); wlr_layer_surface_close(layer->layer_surface); } +static void handle_output_mode(struct wl_listener *listener, void *data) { + arrange_layers((struct wlr_output *)data); +} + static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_layer_surface *layer = wl_container_of(listener, layer, surface_commit); @@ -183,6 +235,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { unmap(layer->layer_surface); } wl_list_remove(&layer->output_destroy.link); + wl_list_remove(&layer->output_mode.link); arrange_layers(layer->layer_surface->output); free(layer); } @@ -205,10 +258,11 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { struct wlr_layer_surface *layer_surface = data; struct roots_desktop *desktop = wl_container_of(listener, desktop, layer_shell_surface); - wlr_log(L_DEBUG, "new layer surface: namespace %s layer %d anchor %d %dx%d %d,%d,%d,%d", + wlr_log(L_DEBUG, "new layer surface: namespace %s layer %d anchor %d " + "size %dx%d margin %d,%d,%d,%d", layer_surface->namespace, layer_surface->layer, layer_surface->layer, - layer_surface->client_pending.width, - layer_surface->client_pending.height, + layer_surface->client_pending.desired_width, + layer_surface->client_pending.desired_height, layer_surface->client_pending.margin.top, layer_surface->client_pending.margin.right, layer_surface->client_pending.margin.bottom, @@ -228,6 +282,10 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { wl_signal_add(&layer_surface->output->events.destroy, &roots_surface->output_destroy); + roots_surface->output_mode.notify = handle_output_mode; + wl_signal_add(&layer_surface->output->events.mode, + &roots_surface->output_mode); + roots_surface->destroy.notify = handle_destroy; wl_signal_add(&layer_surface->events.destroy, &roots_surface->destroy); roots_surface->map.notify = handle_map; diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 59f8d568..04c8fbd5 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -66,21 +66,17 @@ static void layer_surface_handle_ack_configure(struct wl_client *client, surface->configured = true; surface->configure_serial = serial; - - surface->current.anchor = configure->state.anchor; - surface->current.exclusive_zone = configure->state.exclusive_zone; - surface->current.margin = configure->state.margin; - surface->current.width = configure->state.width; - surface->current.height = configure->state.height; + surface->current.actual_width = configure->state.actual_width; + surface->current.actual_height = configure->state.actual_height; layer_surface_configure_destroy(configure); } static void layer_surface_handle_set_size(struct wl_client *client, - struct wl_resource *resource, int32_t width, int32_t height) { + struct wl_resource *resource, uint32_t width, uint32_t height) { struct wlr_layer_surface *surface = layer_surface_from_resource(resource); - surface->client_pending.width = width; - surface->client_pending.height = height; + surface->client_pending.desired_width = width; + surface->client_pending.desired_height = height; } static void layer_surface_handle_set_anchor(struct wl_client *client, @@ -100,7 +96,7 @@ static void layer_surface_handle_set_anchor(struct wl_client *client, } static void layer_surface_handle_set_exclusive_zone(struct wl_client *client, - struct wl_resource *resource, uint32_t zone) { + struct wl_resource *resource, int32_t zone) { struct wlr_layer_surface *surface = layer_surface_from_resource(resource); surface->client_pending.exclusive_zone = zone; } @@ -188,8 +184,9 @@ static bool wlr_layer_surface_state_changed(struct wlr_layer_surface *surface) { state = &configure->state; } - return !memcmp(state, &surface->server_pending, - sizeof(struct wlr_layer_surface_state)); + bool changed = state->actual_width != surface->server_pending.actual_width + || state->actual_height != surface->server_pending.actual_height; + return changed; } static void wlr_layer_surface_send_configure(void *user_data) { @@ -204,10 +201,12 @@ static void wlr_layer_surface_send_configure(void *user_data) { wl_list_insert(surface->configure_list.prev, &configure->link); configure->serial = surface->configure_next_serial; - configure->state = surface->server_pending; + configure->state.actual_width = surface->server_pending.actual_width; + configure->state.actual_height = surface->server_pending.actual_height; zwlr_layer_surface_v1_send_configure(surface->resource, - configure->serial, configure->state.width, configure->state.height); + configure->serial, configure->state.actual_width, + configure->state.actual_height); } static uint32_t wlr_layer_surface_schedule_configure( @@ -239,8 +238,8 @@ static uint32_t wlr_layer_surface_schedule_configure( void wlr_layer_surface_configure(struct wlr_layer_surface *surface, uint32_t width, uint32_t height) { - surface->server_pending.width = width; - surface->server_pending.height = height; + surface->server_pending.actual_width = width; + surface->server_pending.actual_height = height; wlr_layer_surface_schedule_configure(surface); } @@ -271,8 +270,8 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, surface->current.margin = surface->client_pending.margin; surface->current.keyboard_interactive = surface->client_pending.keyboard_interactive; - surface->current.width = surface->client_pending.width; - surface->current.height = surface->client_pending.height; + surface->current.desired_width = surface->client_pending.desired_width; + surface->current.desired_height = surface->client_pending.desired_height; if (!surface->added) { surface->added = true; diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 93f6d872..9793df74 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -1257,8 +1257,9 @@ bool wlr_seat_touch_has_grab(struct wlr_seat *seat) { } bool wlr_seat_validate_grab_serial(struct wlr_seat *seat, uint32_t serial) { - return serial == seat->pointer_state.grab_serial || - serial == seat->touch_state.grab_serial; + return true; + //return serial == seat->pointer_state.grab_serial || + // serial == seat->touch_state.grab_serial; } struct wlr_seat_client *wlr_seat_client_from_resource( -- cgit v1.2.3 From 13edb19a6ca89da3fcbafd3be01d89251658178d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 27 Mar 2018 15:49:44 -0400 Subject: Fix issue starting up client EGL on X11 backend --- examples/layer-shell.c | 1 - include/wlr/render/egl.h | 1 + render/egl.c | 6 ++++-- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'include/wlr') diff --git a/examples/layer-shell.c b/examples/layer-shell.c index e559121e..70407888 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -247,7 +247,6 @@ int main(int argc, char **argv) { struct wl_registry *registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener, NULL); - wl_display_dispatch(display); wl_display_roundtrip(display); if (compositor == NULL) { diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h index 9f4c0334..b5f2d67c 100644 --- a/include/wlr/render/egl.h +++ b/include/wlr/render/egl.h @@ -20,6 +20,7 @@ struct wlr_egl { bool swap_buffers_with_damage; bool dmabuf_import; bool dmabuf_import_modifiers; + bool bind_wayland_display; } egl_exts; struct wl_display *wl_display; diff --git a/render/egl.c b/render/egl.c index 315eb098..7201ac9f 100644 --- a/render/egl.c +++ b/render/egl.c @@ -160,8 +160,7 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display, wlr_log(L_INFO, "Supported EGL extensions: %s", egl->exts_str); wlr_log(L_INFO, "EGL vendor: %s", eglQueryString(egl->display, EGL_VENDOR)); - if (!check_egl_ext(egl->exts_str, "EGL_WL_bind_wayland_display") || - !check_egl_ext(egl->exts_str, "EGL_KHR_image_base")) { + if (!check_egl_ext(egl->exts_str, "EGL_KHR_image_base")) { wlr_log(L_ERROR, "Required egl extensions not supported"); goto error; } @@ -177,6 +176,9 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display, egl->egl_exts.dmabuf_import_modifiers = check_egl_ext(egl->exts_str, "EGL_EXT_image_dma_buf_import_modifiers") && eglQueryDmaBufFormatsEXT && eglQueryDmaBufModifiersEXT; + + egl->egl_exts.bind_wayland_display = + check_egl_ext(egl->exts_str, "EGL_WL_bind_wayland_display"); print_dmabuf_formats(egl); return true; -- cgit v1.2.3 From 52fe2688ea1068d5cd0801ead4fc078c3a37dea1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 27 Mar 2018 17:18:16 -0400 Subject: Address @emersion's feedback --- include/rootston/layers.h | 1 + include/wlr/types/wlr_layer_shell.h | 14 ++------- rootston/desktop.c | 6 ---- rootston/layer_shell.c | 19 +++++++----- types/wlr_layer_shell.c | 60 +++++++++++++------------------------ 5 files changed, 35 insertions(+), 65 deletions(-) (limited to 'include/wlr') diff --git a/include/rootston/layers.h b/include/rootston/layers.h index cc285fe7..35f5399e 100644 --- a/include/rootston/layers.h +++ b/include/rootston/layers.h @@ -16,6 +16,7 @@ struct roots_layer_surface { struct wl_listener surface_commit; struct wl_listener output_destroy; struct wl_listener output_mode; + struct wl_listener output_transform; bool configured; struct wlr_box geo; diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h index c24b391e..e8da8e0f 100644 --- a/include/wlr/types/wlr_layer_shell.h +++ b/include/wlr/types/wlr_layer_shell.h @@ -21,7 +21,7 @@ */ struct wlr_layer_shell { struct wl_global *wl_global; - struct wl_list clients; + struct wl_list client_resources; // wl_resource struct wl_listener display_destroy; @@ -32,15 +32,6 @@ struct wlr_layer_shell { void *data; }; -struct wlr_layer_client { - struct wlr_layer_shell *shell; - struct wl_resource *resource; - struct wl_client *client; - struct wl_list surfaces; - - struct wl_list link; // wlr_layer_shell::clients -}; - struct wlr_layer_surface_state { uint32_t anchor; int32_t exclusive_zone; @@ -61,9 +52,8 @@ struct wlr_layer_surface_configure { struct wlr_layer_surface { struct wlr_surface *surface; struct wlr_output *output; - struct wlr_layer_client *client; struct wl_resource *resource; - struct wl_list link; // wlr_layer_client:surfaces + struct wlr_layer_shell *shell; const char *namespace; enum zwlr_layer_shell_v1_layer layer; diff --git a/rootston/desktop.c b/rootston/desktop.c index a0659250..9ea392f6 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -209,12 +209,6 @@ void view_arrange_maximized(struct roots_view *view) { usable_area.x += output_box->x; usable_area.y += output_box->y; - wlr_log(L_DEBUG, "output area: %dx%d@%d,%d", - output_box->width, output_box->height, - output_box->x, output_box->y); - wlr_log(L_DEBUG, "usable area: %dx%d@%d,%d", - usable_area.width, usable_area.height, - usable_area.x, usable_area.y); view_move_resize(view, usable_area.x, usable_area.y, usable_area.width, usable_area.height); view_rotate(view, 0); diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 5efdf3c9..809ddbf3 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -82,14 +82,8 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list, wl_list_for_each(roots_surface, list, link) { struct wlr_layer_surface *layer = roots_surface->layer_surface; struct wlr_layer_surface_state *state = &layer->current; - if (exclusive) { - if (state->exclusive_zone <= 0) { - continue; - } - } else { - if (state->exclusive_zone > 0) { - continue; - } + if (exclusive != (state->exclusive_zone >0)) { + continue; } struct wlr_box bounds; if (state->exclusive_zone == -1) { @@ -212,6 +206,10 @@ static void handle_output_mode(struct wl_listener *listener, void *data) { arrange_layers((struct wlr_output *)data); } +static void handle_output_transform(struct wl_listener *listener, void *data) { + arrange_layers((struct wlr_output *)data); +} + static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_layer_surface *layer = wl_container_of(listener, layer, surface_commit); @@ -254,6 +252,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { } wl_list_remove(&layer->output_destroy.link); wl_list_remove(&layer->output_mode.link); + wl_list_remove(&layer->output_transform.link); arrange_layers(layer->layer_surface->output); free(layer); } @@ -304,6 +303,10 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { wl_signal_add(&layer_surface->output->events.mode, &roots_surface->output_mode); + roots_surface->output_transform.notify = handle_output_transform; + wl_signal_add(&layer_surface->output->events.transform, + &roots_surface->output_transform); + roots_surface->destroy.notify = handle_destroy; wl_signal_add(&layer_surface->events.destroy, &roots_surface->destroy); roots_surface->map.notify = handle_map; diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 761d2413..532309a3 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -18,7 +18,7 @@ static void resource_handle_destroy(struct wl_client *client, static const struct zwlr_layer_shell_v1_interface layer_shell_implementation; static const struct zwlr_layer_surface_v1_interface layer_surface_implementation; -static struct wlr_layer_client *layer_client_from_resource( +static struct wlr_layer_shell *layer_shell_from_resource( struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &zwlr_layer_shell_v1_interface, &layer_shell_implementation)); @@ -58,7 +58,7 @@ static void layer_surface_handle_ack_configure(struct wl_client *client, } } if (!found) { - wl_resource_post_error(surface->client->resource, + wl_resource_post_error(resource, ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SURFACE_STATE, "wrong configure serial: %u", serial); return; @@ -156,7 +156,6 @@ static void layer_surface_destroy(struct wlr_layer_surface *surface) { layer_surface_unmap(surface); wlr_signal_emit_safe(&surface->events.destroy, surface); wl_resource_set_user_data(surface->resource, NULL); - wl_list_remove(&surface->link); wl_list_remove(&surface->surface_destroy_listener.link); wlr_surface_set_role_committed(surface->surface, NULL, NULL); free(surface); @@ -195,11 +194,11 @@ void wlr_layer_surface_configure(struct wlr_layer_surface *surface, surface->server_pending.actual_height = height; if (wlr_layer_surface_state_changed(surface)) { struct wl_display *display = - wl_client_get_display(surface->client->client); + wl_client_get_display(wl_resource_get_client(surface->resource)); struct wlr_layer_surface_configure *configure = calloc(1, sizeof(struct wlr_layer_surface_configure)); if (configure == NULL) { - wl_client_post_no_memory(surface->client->client); + wl_client_post_no_memory(wl_resource_get_client(surface->resource)); return; } surface->configure_next_serial = wl_display_next_serial(display); @@ -248,7 +247,7 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, if (!surface->added) { surface->added = true; - wlr_signal_emit_safe(&surface->client->shell->events.new_surface, + wlr_signal_emit_safe(&surface->shell->events.new_surface, surface); } if (surface->configured && wlr_surface_has_buffer(surface->surface) && @@ -274,8 +273,8 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, struct wl_resource *surface_resource, struct wl_resource *output_resource, uint32_t layer, const char *namespace) { - struct wlr_layer_client *client = - layer_client_from_resource(client_resource); + struct wlr_layer_shell *shell = + layer_shell_from_resource(client_resource); struct wlr_layer_surface *surface = calloc(1, sizeof(struct wlr_layer_surface)); @@ -284,7 +283,7 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, return; } - surface->client = client; + surface->shell = shell; surface->surface = wlr_surface_from_resource(surface_resource); surface->output = wlr_output_from_resource(output_resource); surface->resource = wl_resource_create(wl_client, @@ -322,23 +321,14 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, surface, surface->resource); wl_resource_set_implementation(surface->resource, &layer_surface_implementation, surface, layer_surface_resource_destroy); - wl_list_insert(&client->surfaces, &surface->link); } static const struct zwlr_layer_shell_v1_interface layer_shell_implementation = { .get_layer_surface = layer_shell_handle_get_layer_surface, }; -static void wlr_layer_client_destroy(struct wl_resource *resource) { - struct wlr_layer_client *client = layer_client_from_resource(resource); - - struct wlr_layer_surface *surface, *tmp = NULL; - wl_list_for_each_safe(surface, tmp, &client->surfaces, link) { - layer_surface_destroy(surface); - } - - wl_list_remove(&client->link); - free(client); +static void client_handle_destroy(struct wl_resource *resource) { + wl_list_remove(wl_resource_get_link(resource)); } static void layer_shell_bind(struct wl_client *wl_client, void *data, @@ -346,28 +336,16 @@ static void layer_shell_bind(struct wl_client *wl_client, void *data, struct wlr_layer_shell *layer_shell = data; assert(wl_client && layer_shell); - struct wlr_layer_client *client = - calloc(1, sizeof(struct wlr_layer_client)); - if (client == NULL) { - wl_client_post_no_memory(wl_client); - return; - } - - wl_list_init(&client->surfaces); - - client->resource = wl_resource_create( + struct wl_resource *resource = wl_resource_create( wl_client, &zwlr_layer_shell_v1_interface, version, id); - if (client->resource == NULL) { - free(client); + if (resource == NULL) { wl_client_post_no_memory(wl_client); return; } - client->client = wl_client; - client->shell = layer_shell; - - wl_resource_set_implementation(client->resource, - &layer_shell_implementation, client, wlr_layer_client_destroy); - wl_list_insert(&layer_shell->clients, &client->link); + wl_resource_set_implementation(resource, + &layer_shell_implementation, layer_shell, client_handle_destroy); + wl_list_insert(&layer_shell->client_resources, + wl_resource_get_link(resource)); } static void handle_display_destroy(struct wl_listener *listener, void *data) { @@ -383,7 +361,7 @@ struct wlr_layer_shell *wlr_layer_shell_create(struct wl_display *display) { return NULL; } - wl_list_init(&layer_shell->clients); + wl_list_init(&layer_shell->client_resources); struct wl_global *wl_global = wl_global_create(display, &zwlr_layer_shell_v1_interface, 1, layer_shell, layer_shell_bind); @@ -405,6 +383,10 @@ void wlr_layer_shell_destroy(struct wlr_layer_shell *layer_shell) { if (!layer_shell) { return; } + struct wl_resource *client, *tmp; + wl_resource_for_each_safe(client, tmp, &layer_shell->client_resources) { + wl_resource_destroy(client); + } wl_list_remove(&layer_shell->display_destroy.link); wl_global_destroy(layer_shell->wl_global); free(layer_shell); -- cgit v1.2.3 From 96a8df2f9a1cf1d24b6c901ece844c620ed9ee1b Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 27 Mar 2018 22:50:55 -0400 Subject: Fix ack configure/configure flow Prevents FOUC/improves frame perfect rendering goal --- include/wlr/types/wlr_layer_shell.h | 2 ++ types/wlr_layer_shell.c | 45 ++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 16 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h index e8da8e0f..8cc7782f 100644 --- a/include/wlr/types/wlr_layer_shell.h +++ b/include/wlr/types/wlr_layer_shell.h @@ -64,6 +64,8 @@ struct wlr_layer_surface { uint32_t configure_next_serial; struct wl_list configure_list; + struct wlr_layer_surface_configure *acked_configure; + struct wlr_layer_surface_state client_pending; struct wlr_layer_surface_state server_pending; struct wlr_layer_surface_state current; diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 532309a3..99344ed3 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -64,12 +64,12 @@ static void layer_surface_handle_ack_configure(struct wl_client *client, return; } - surface->configured = true; - surface->configure_serial = serial; - surface->current.actual_width = configure->state.actual_width; - surface->current.actual_height = configure->state.actual_height; - - layer_surface_configure_destroy(configure); + if (surface->acked_configure) { + layer_surface_configure_destroy(surface->acked_configure); + } + surface->acked_configure = configure; + wl_list_remove(&configure->link); + wl_list_init(&configure->link); } static void layer_surface_handle_set_size(struct wl_client *client, @@ -170,13 +170,15 @@ static void layer_surface_resource_destroy(struct wl_resource *resource) { } static bool wlr_layer_surface_state_changed(struct wlr_layer_surface *surface) { - if (!surface->configured) { - return true; - } - struct wlr_layer_surface_state *state; if (wl_list_empty(&surface->configure_list)) { - state = &surface->current; + if (surface->acked_configure) { + state = &surface->acked_configure->state; + } else if (!surface->configured) { + return true; + } else { + state = &surface->current; + } } else { struct wlr_layer_surface_configure *configure = wl_container_of(surface->configure_list.prev, configure, link); @@ -225,6 +227,22 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, void *role_data) { struct wlr_layer_surface *surface = role_data; + if (surface->closed) { + // Ignore commits after the compositor has closed it + return; + } + + if (surface->acked_configure) { + struct wlr_layer_surface_configure *configure = + surface->acked_configure; + surface->configured = true; + surface->configure_serial = configure->serial; + surface->current.actual_width = configure->state.actual_width; + surface->current.actual_height = configure->state.actual_height; + layer_surface_configure_destroy(configure); + surface->acked_configure = NULL; + } + if (wlr_surface_has_buffer(surface->surface) && !surface->configured) { wl_resource_post_error(surface->resource, ZWLR_LAYER_SHELL_V1_ERROR_ALREADY_CONSTRUCTED, @@ -232,11 +250,6 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, return; } - if (surface->closed) { - // Ignore commits after the compositor has closed it - return; - } - surface->current.anchor = surface->client_pending.anchor; surface->current.exclusive_zone = surface->client_pending.exclusive_zone; surface->current.margin = surface->client_pending.margin; -- cgit v1.2.3 From a35a5786b0e40cb1ffa87344d3cb21dff9fd99f4 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Mar 2018 10:46:50 -0400 Subject: Remove width_mm from wlr_pointer events --- backend/libinput/pointer.c | 5 ++--- backend/wayland/wl_seat.c | 6 ++---- backend/x11/backend.c | 12 ++++-------- examples/multi-pointer.c | 3 +-- examples/pointer.c | 6 +++--- examples/support/shared.c | 4 ++-- include/wlr/types/wlr_cursor.h | 2 +- include/wlr/types/wlr_pointer.h | 4 ++-- rootston/cursor.c | 4 ++-- types/wlr_cursor.c | 6 +++--- 10 files changed, 22 insertions(+), 30 deletions(-) (limited to 'include/wlr') diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index 8a31d312..9ccda634 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -53,9 +53,8 @@ void handle_pointer_motion_abs(struct libinput_event *event, wlr_event.device = wlr_dev; wlr_event.time_msec = usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); - wlr_event.x_mm = libinput_event_pointer_get_absolute_x(pevent); - wlr_event.y_mm = libinput_event_pointer_get_absolute_y(pevent); - libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); + wlr_event.x = libinput_event_pointer_get_absolute_x_transformed(pevent, 1); + wlr_event.y = libinput_event_pointer_get_absolute_y_transformed(pevent, 1); wlr_signal_emit_safe(&wlr_dev->pointer->events.motion_absolute, &wlr_event); } diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 6ca59130..2d4f76de 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -80,10 +80,8 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, struct wlr_event_pointer_motion_absolute wlr_event; wlr_event.device = dev; wlr_event.time_msec = time; - wlr_event.width_mm = layout_box.width; - wlr_event.height_mm = layout_box.height; - wlr_event.x_mm = transformed.x + wlr_output->lx - layout_box.x; - wlr_event.y_mm = transformed.y + wlr_output->ly - layout_box.y; + wlr_event.x = transformed.x / layout_box.width; + wlr_event.y = transformed.y / layout_box.height; wlr_signal_emit_safe(&dev->pointer->events.motion_absolute, &wlr_event); } diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 36d72d9e..f534676d 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -108,10 +108,8 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e struct wlr_event_pointer_motion_absolute abs = { .device = &x11->pointer_dev, .time_msec = ev->time, - .x_mm = ev->event_x, - .y_mm = ev->event_y, - .width_mm = output->wlr_output.width, - .height_mm = output->wlr_output.height, + .x = (double)ev->event_x / output->wlr_output.width, + .y = (double)ev->event_y / output->wlr_output.height, }; wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &abs); @@ -136,10 +134,8 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e struct wlr_event_pointer_motion_absolute abs = { .device = &x11->pointer_dev, .time_msec = x11->time, - .x_mm = pointer->root_x, - .y_mm = pointer->root_y, - .width_mm = output->wlr_output.width, - .height_mm = output->wlr_output.height, + .x = (double)pointer->root_x / output->wlr_output.width, + .y = (double)pointer->root_y / output->wlr_output.height, }; wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &abs); diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c index 1f869f50..46f0e78f 100644 --- a/examples/multi-pointer.c +++ b/examples/multi-pointer.c @@ -118,8 +118,7 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener, struct sample_cursor *cursor = wl_container_of(listener, cursor, cursor_motion_absolute); struct wlr_event_pointer_motion_absolute *event = data; - wlr_cursor_warp_absolute(cursor->cursor, event->device, - event->x_mm / event->width_mm, event->y_mm / event->height_mm); + wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); } static void handle_input_add(struct compositor_state *state, diff --git a/examples/pointer.c b/examples/pointer.c index 9794e6e5..12312092 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -154,8 +154,8 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener, wl_container_of(listener, sample, cursor_motion_absolute); struct wlr_event_pointer_motion_absolute *event = data; - sample->cur_x = event->x_mm; - sample->cur_y = event->y_mm; + sample->cur_x = event->x; + sample->cur_y = event->y; wlr_cursor_warp_absolute(sample->cursor, event->device, sample->cur_x, sample->cur_y); @@ -252,7 +252,7 @@ static void handle_tablet_tool_axis(struct wl_listener *listener, void *data) { if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { wlr_cursor_warp_absolute(sample->cursor, event->device, - event->x_mm / event->width_mm, event->y_mm / event->height_mm); + event->x_mm / event->width_mm, event->y_mm / event->height_mm); } } diff --git a/examples/support/shared.c b/examples/support/shared.c index e6233206..c6460374 100644 --- a/examples/support/shared.c +++ b/examples/support/shared.c @@ -108,8 +108,8 @@ static void pointer_motion_absolute_notify(struct wl_listener *listener, void *d struct wlr_event_pointer_motion_absolute *event = data; struct pointer_state *pstate = wl_container_of(listener, pstate, motion_absolute); if (pstate->compositor->pointer_motion_absolute_cb) { - pstate->compositor->pointer_motion_absolute_cb(pstate, - event->x_mm, event->y_mm); + pstate->compositor->pointer_motion_absolute_cb( + pstate, event->x, event->y); } } diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index 70dca9f7..ffe149c9 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -73,7 +73,7 @@ bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev, double x, double y); void wlr_cursor_warp_absolute(struct wlr_cursor *cur, - struct wlr_input_device *dev, double x_mm, double y_mm); + struct wlr_input_device *dev, double x, double y); /** * Move the cursor in the direction of the given x and y coordinates. diff --git a/include/wlr/types/wlr_pointer.h b/include/wlr/types/wlr_pointer.h index e7ac9b46..a8969b9e 100644 --- a/include/wlr/types/wlr_pointer.h +++ b/include/wlr/types/wlr_pointer.h @@ -29,8 +29,8 @@ struct wlr_event_pointer_motion { struct wlr_event_pointer_motion_absolute { struct wlr_input_device *device; uint32_t time_msec; - double x_mm, y_mm; - double width_mm, height_mm; + // From 0..1 + double x, y; }; struct wlr_event_pointer_button { diff --git a/rootston/cursor.c b/rootston/cursor.c index 52439dff..c1fd7d31 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -288,8 +288,8 @@ void roots_cursor_handle_motion(struct roots_cursor *cursor, void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor, struct wlr_event_pointer_motion_absolute *event) { - wlr_cursor_warp_absolute(cursor->cursor, event->device, - event->x_mm / event->width_mm, event->y_mm / event->height_mm); + wlr_cursor_warp_absolute(cursor->cursor, + event->device, event->x, event->y); roots_cursor_update_position(cursor, event->time_msec); } diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index 20acebf1..ed1a67da 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -254,7 +254,7 @@ bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev, } void wlr_cursor_warp_absolute(struct wlr_cursor *cur, - struct wlr_input_device *dev, double x_mm, double y_mm) { + struct wlr_input_device *dev, double x, double y) { assert(cur->state->layout); struct wlr_box *mapping = get_mapping(cur, dev); @@ -262,8 +262,8 @@ void wlr_cursor_warp_absolute(struct wlr_cursor *cur, mapping = wlr_output_layout_get_box(cur->state->layout, NULL); } - double x = x_mm > 0 ? mapping->width * x_mm + mapping->x : cur->x; - double y = y_mm > 0 ? mapping->height * y_mm + mapping->y : cur->y; + x = x > 0 ? mapping->width * x + mapping->x : cur->x; + y = y > 0 ? mapping->height * y + mapping->y : cur->y; wlr_cursor_warp_unchecked(cur, x, y); } -- cgit v1.2.3 From 324b9d910dc237151fd71c01bef015d0080be191 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Mar 2018 11:04:40 -0400 Subject: Remove width_mm from wlr_touch events --- backend/drm/legacy.c | 2 +- backend/libinput/touch.c | 10 ++++------ examples/pointer.c | 8 ++++---- examples/support/shared.c | 8 ++++---- examples/support/shared.h | 8 ++++---- examples/touch.c | 16 ++++++++-------- include/wlr/types/wlr_cursor.h | 2 +- include/wlr/types/wlr_touch.h | 8 ++++---- rootston/cursor.c | 9 +++------ types/wlr_cursor.c | 12 ++++-------- 10 files changed, 37 insertions(+), 46 deletions(-) (limited to 'include/wlr') diff --git a/backend/drm/legacy.c b/backend/drm/legacy.c index 88a01b89..7c45ae21 100644 --- a/backend/drm/legacy.c +++ b/backend/drm/legacy.c @@ -47,7 +47,7 @@ bool legacy_crtc_set_cursor(struct wlr_drm_backend *drm, if (drmModeSetCursor(drm->fd, crtc->id, gbm_bo_get_handle(bo).u32, plane->surf.width, plane->surf.height)) { - wlr_log_errno(L_ERROR, "Failed to set hardware cursor"); + wlr_log_errno(L_DEBUG, "Failed to set hardware cursor"); return false; } diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c index 2b87f9cd..419c11ea 100644 --- a/backend/libinput/touch.c +++ b/backend/libinput/touch.c @@ -35,9 +35,8 @@ void handle_touch_down(struct libinput_event *event, wlr_event.time_msec = usec_to_msec(libinput_event_touch_get_time_usec(tevent)); wlr_event.touch_id = libinput_event_touch_get_slot(tevent); - wlr_event.x_mm = libinput_event_touch_get_x(tevent); - wlr_event.y_mm = libinput_event_touch_get_y(tevent); - libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); + wlr_event.x = libinput_event_touch_get_x_transformed(tevent, 1); + wlr_event.y = libinput_event_touch_get_y_transformed(tevent, 1); wlr_signal_emit_safe(&wlr_dev->touch->events.down, &wlr_event); } @@ -74,9 +73,8 @@ void handle_touch_motion(struct libinput_event *event, wlr_event.time_msec = usec_to_msec(libinput_event_touch_get_time_usec(tevent)); wlr_event.touch_id = libinput_event_touch_get_slot(tevent); - wlr_event.x_mm = libinput_event_touch_get_x(tevent); - wlr_event.y_mm = libinput_event_touch_get_y(tevent); - libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); + wlr_event.x = libinput_event_touch_get_x_transformed(tevent, 1); + wlr_event.y = libinput_event_touch_get_y_transformed(tevent, 1); wlr_signal_emit_safe(&wlr_dev->touch->events.motion, &wlr_event); } diff --git a/examples/pointer.c b/examples/pointer.c index 12312092..2c598b9a 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -217,8 +217,8 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { struct wlr_event_touch_down *event = data; struct touch_point *point = calloc(1, sizeof(struct touch_point)); point->touch_id = event->touch_id; - point->x = event->x_mm / event->width_mm; - point->y = event->y_mm / event->height_mm; + point->x = event->x; + point->y = event->y; wl_list_insert(&sample->touch_points, &point->link); warp_to_touch(sample, event->device); @@ -232,8 +232,8 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { struct touch_point *point; wl_list_for_each(point, &sample->touch_points, link) { if (point->touch_id == event->touch_id) { - point->x = event->x_mm / event->width_mm; - point->y = event->y_mm / event->height_mm; + point->x = event->x; + point->y = event->y; break; } } diff --git a/examples/support/shared.c b/examples/support/shared.c index c6460374..02b324f5 100644 --- a/examples/support/shared.c +++ b/examples/support/shared.c @@ -167,8 +167,8 @@ static void touch_down_notify(struct wl_listener *listener, void *data) { struct wlr_event_touch_down *event = data; struct touch_state *tstate = wl_container_of(listener, tstate, down); if (tstate->compositor->touch_down_cb) { - tstate->compositor->touch_down_cb(tstate, event->touch_id, - event->x_mm, event->y_mm, event->width_mm, event->height_mm); + tstate->compositor->touch_down_cb(tstate, + event->touch_id, event->x, event->y); } } @@ -176,8 +176,8 @@ static void touch_motion_notify(struct wl_listener *listener, void *data) { struct wlr_event_touch_motion *event = data; struct touch_state *tstate = wl_container_of(listener, tstate, motion); if (tstate->compositor->touch_motion_cb) { - tstate->compositor->touch_motion_cb(tstate, event->touch_id, - event->x_mm, event->y_mm, event->width_mm, event->height_mm); + tstate->compositor->touch_motion_cb(tstate, + event->touch_id, event->x, event->y); } } diff --git a/examples/support/shared.h b/examples/support/shared.h index d00e75b3..2079a9ef 100644 --- a/examples/support/shared.h +++ b/examples/support/shared.h @@ -102,10 +102,10 @@ struct compositor_state { enum wlr_axis_source source, enum wlr_axis_orientation orientation, double delta); - void (*touch_down_cb)(struct touch_state *s, int32_t touch_id, - double x, double y, double width, double height); - void (*touch_motion_cb)(struct touch_state *s, int32_t touch_id, - double x, double y, double width, double height); + void (*touch_down_cb)(struct touch_state *s, + int32_t touch_id, double x, double y); + void (*touch_motion_cb)(struct touch_state *s, + int32_t touch_id, double x, double y); void (*touch_up_cb)(struct touch_state *s, int32_t touch_id); void (*touch_cancel_cb)(struct touch_state *s, int32_t touch_id); void (*tool_axis_cb)(struct tablet_tool_state *s, diff --git a/examples/touch.c b/examples/touch.c index 7639165c..e9dcf29c 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -60,13 +60,13 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_swap_buffers(wlr_output, NULL, NULL); } -static void handle_touch_down(struct touch_state *tstate, int32_t touch_id, - double x, double y, double width, double height) { +static void handle_touch_down(struct touch_state *tstate, + int32_t touch_id, double x, double y) { struct sample_state *sample = tstate->compositor->data; struct touch_point *point = calloc(1, sizeof(struct touch_point)); point->touch_id = touch_id; - point->x = x / width; - point->y = y / height; + point->x = x; + point->y = y; wl_list_insert(&sample->touch_points, &point->link); } @@ -81,14 +81,14 @@ static void handle_touch_up(struct touch_state *tstate, int32_t touch_id) { } } -static void handle_touch_motion(struct touch_state *tstate, int32_t touch_id, - double x, double y, double width, double height) { +static void handle_touch_motion(struct touch_state *tstate, + int32_t touch_id, double x, double y) { struct sample_state *sample = tstate->compositor->data; struct touch_point *point; wl_list_for_each(point, &sample->touch_points, link) { if (point->touch_id == touch_id) { - point->x = x / width; - point->y = y / height; + point->x = x; + point->y = y; break; } } diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index ffe149c9..fc541271 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -156,6 +156,6 @@ void wlr_cursor_map_input_to_region(struct wlr_cursor *cur, */ bool wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur, struct wlr_input_device *device, double x_mm, double y_mm, - double width_mm, double height_mm, double *lx, double *ly); + double *lx, double *ly); #endif diff --git a/include/wlr/types/wlr_touch.h b/include/wlr/types/wlr_touch.h index 8ea293eb..70070f84 100644 --- a/include/wlr/types/wlr_touch.h +++ b/include/wlr/types/wlr_touch.h @@ -23,8 +23,8 @@ struct wlr_event_touch_down { struct wlr_input_device *device; uint32_t time_msec; int32_t touch_id; - double x_mm, y_mm; - double width_mm, height_mm; + // From 0..1 + double x, y; }; struct wlr_event_touch_up { @@ -37,8 +37,8 @@ struct wlr_event_touch_motion { struct wlr_input_device *device; uint32_t time_msec; int32_t touch_id; - double x_mm, y_mm; - double width_mm, height_mm; + // From 0..1 + double x, y; }; struct wlr_event_touch_cancel { diff --git a/rootston/cursor.c b/rootston/cursor.c index c1fd7d31..786dff0e 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -310,10 +310,8 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor, struct roots_desktop *desktop = cursor->seat->input->server->desktop; struct wlr_surface *surface = NULL; double lx, ly; - bool result = - wlr_cursor_absolute_to_layout_coords(cursor->cursor, - event->device, event->x_mm, event->y_mm, event->width_mm, - event->height_mm, &lx, &ly); + bool result = wlr_cursor_absolute_to_layout_coords(cursor->cursor, + event->device, event->x, event->y, &lx, &ly); if (!result) { return; } @@ -365,8 +363,7 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, double lx, ly; bool result = wlr_cursor_absolute_to_layout_coords(cursor->cursor, - event->device, event->x_mm, event->y_mm, event->width_mm, - event->height_mm, &lx, &ly); + event->device, event->x, event->y, &lx, &ly); if (!result) { return; } diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index ed1a67da..5142513b 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -640,19 +640,15 @@ void wlr_cursor_map_input_to_region(struct wlr_cursor *cur, } bool wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur, - struct wlr_input_device *device, double x_mm, double y_mm, - double width_mm, double height_mm, double *lx, double *ly) { - if (width_mm <= 0 || height_mm <= 0) { - return false; - } - + struct wlr_input_device *device, double x, double y, + double *lx, double *ly) { struct wlr_box *mapping = get_mapping(cur, device); if (!mapping) { mapping = wlr_output_layout_get_box(cur->state->layout, NULL); } - *lx = x_mm > 0 ? mapping->width * (x_mm / width_mm) + mapping->x : cur->x; - *ly = y_mm > 0 ? mapping->height * (y_mm / height_mm) + mapping->y : cur->y; + *lx = x > 0 ? mapping->width * x + mapping->x : cur->x; + *ly = y > 0 ? mapping->height * y + mapping->y : cur->y; return true; } -- cgit v1.2.3 From ac219cbda6dc3122fcc7f1bfa89b7e8fbb03b8ce Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Mar 2018 11:40:35 -0400 Subject: Remove width_mm from tablet events --- backend/libinput/events.c | 2 ++ backend/libinput/tablet_tool.c | 5 ++--- examples/pointer.c | 4 ++-- examples/tablet.c | 27 +++++++++++++++++++-------- include/wlr/types/wlr_input_device.h | 2 ++ include/wlr/types/wlr_tablet_tool.h | 12 ++++++------ rootston/cursor.c | 8 +++----- 7 files changed, 36 insertions(+), 24 deletions(-) (limited to 'include/wlr') diff --git a/backend/libinput/events.c b/backend/libinput/events.c index d92de830..da7b2be4 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -46,6 +46,8 @@ static struct wlr_input_device *allocate_device( return NULL; } struct wlr_input_device *wlr_dev = &wlr_libinput_dev->wlr_input_device; + libinput_device_get_size(libinput_dev, + &wlr_dev->width_mm, &wlr_dev->height_mm); wl_list_insert(wlr_devices, &wlr_dev->link); wlr_libinput_dev->handle = libinput_dev; libinput_device_ref(libinput_dev); diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 27cf7c81..815c4daf 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -34,14 +34,13 @@ void handle_tablet_tool_axis(struct libinput_event *event, wlr_event.device = wlr_dev; wlr_event.time_msec = usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)); - libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); if (libinput_event_tablet_tool_x_has_changed(tevent)) { wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_X; - wlr_event.x_mm = libinput_event_tablet_tool_get_x(tevent); + wlr_event.x = libinput_event_tablet_tool_get_x_transformed(tevent, 1); } if (libinput_event_tablet_tool_y_has_changed(tevent)) { wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_Y; - wlr_event.y_mm = libinput_event_tablet_tool_get_y(tevent); + wlr_event.y = libinput_event_tablet_tool_get_y_transformed(tevent, 1); } if (libinput_event_tablet_tool_pressure_has_changed(tevent)) { wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_PRESSURE; diff --git a/examples/pointer.c b/examples/pointer.c index 2c598b9a..aaaad841 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -251,8 +251,8 @@ static void handle_tablet_tool_axis(struct wl_listener *listener, void *data) { struct wlr_event_tablet_tool_axis *event = data; if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { - wlr_cursor_warp_absolute(sample->cursor, event->device, - event->x_mm / event->width_mm, event->y_mm / event->height_mm); + wlr_cursor_warp_absolute(sample->cursor, + event->device, event->x, event->y); } } diff --git a/examples/tablet.c b/examples/tablet.c index 9379fac3..be428f86 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -28,7 +28,7 @@ struct sample_state { bool proximity, tap, button; double distance; double pressure; - double x_mm, y_mm; + double x, y; double x_tilt, y_tilt; double width_mm, height_mm; double ring; @@ -69,8 +69,8 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts if (sample->proximity) { struct wlr_box box = { - .x = sample->x_mm * scale - 8 * (sample->pressure + 1) + left, - .y = sample->y_mm * scale - 8 * (sample->pressure + 1) + top, + .x = (sample->x * pad_width) - 8 * (sample->pressure + 1) + left, + .y = (sample->y * pad_height) - 8 * (sample->pressure + 1) + top, .width = 16 * (sample->pressure + 1), .height = 16 * (sample->pressure + 1), }; @@ -94,13 +94,11 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts static void handle_tool_axis(struct tablet_tool_state *tstate, struct wlr_event_tablet_tool_axis *event) { struct sample_state *sample = tstate->compositor->data; - sample->width_mm = event->width_mm; - sample->height_mm = event->height_mm; if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { - sample->x_mm = event->x_mm; + sample->x = event->x; } if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { - sample->y_mm = event->y_mm; + sample->y = event->y; } if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE)) { sample->distance = event->distance; @@ -164,13 +162,24 @@ static void handle_pad_ring(struct tablet_pad_state *pstate, } } +static void handle_input_add(struct compositor_state *cstate, + struct wlr_input_device *inputdev) { + struct sample_state *sample = cstate->data; + if (inputdev->type == WLR_INPUT_DEVICE_TABLET_TOOL) { + sample->width_mm = inputdev->width_mm == 0 ? + 20 : inputdev->width_mm; + sample->height_mm = inputdev->height_mm == 0 ? + 10 : inputdev->height_mm; + } +} + int main(int argc, char *argv[]) { wlr_log_init(L_DEBUG, NULL); struct sample_state state = { .tool_color = { 1, 1, 1, 1 }, .pad_color = { 0.5, 0.5, 0.5, 1.0 } }; - struct compositor_state compositor = { 0, + struct compositor_state compositor = { .data = &state, .output_frame_cb = handle_output_frame, .tool_axis_cb = handle_tool_axis, @@ -178,6 +187,8 @@ int main(int argc, char *argv[]) { .tool_button_cb = handle_tool_button, .pad_button_cb = handle_pad_button, .pad_ring_cb = handle_pad_ring, + .input_add_cb = handle_input_add, + 0 }; compositor_init(&compositor); diff --git a/include/wlr/types/wlr_input_device.h b/include/wlr/types/wlr_input_device.h index 6d8e3631..d65172c1 100644 --- a/include/wlr/types/wlr_input_device.h +++ b/include/wlr/types/wlr_input_device.h @@ -29,6 +29,8 @@ struct wlr_input_device { enum wlr_input_device_type type; int vendor, product; char *name; + // Or 0 if not applicable to this device + double width_mm, height_mm; /* wlr_input_device.type determines which of these is valid */ union { diff --git a/include/wlr/types/wlr_tablet_tool.h b/include/wlr/types/wlr_tablet_tool.h index 59e49ef8..22bf2649 100644 --- a/include/wlr/types/wlr_tablet_tool.h +++ b/include/wlr/types/wlr_tablet_tool.h @@ -36,8 +36,8 @@ struct wlr_event_tablet_tool_axis { struct wlr_input_device *device; uint32_t time_msec; uint32_t updated_axes; - double x_mm, y_mm; - double width_mm, height_mm; + // From 0..1 + double x, y; double pressure; double distance; double tilt_x, tilt_y; @@ -54,8 +54,8 @@ enum wlr_tablet_tool_proximity_state { struct wlr_event_tablet_tool_proximity { struct wlr_input_device *device; uint32_t time_msec; - double x_mm, y_mm; - double width_mm, height_mm; + // From 0..1 + double x, y; enum wlr_tablet_tool_proximity_state state; }; @@ -67,8 +67,8 @@ enum wlr_tablet_tool_tip_state { struct wlr_event_tablet_tool_tip { struct wlr_input_device *device; uint32_t time_msec; - double x_mm, y_mm; - double width_mm, height_mm; + // From 0..1 + double x, y; enum wlr_tablet_tool_tip_state state; }; diff --git a/rootston/cursor.c b/rootston/cursor.c index 786dff0e..a5953e4a 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -392,15 +392,13 @@ void roots_cursor_handle_tool_axis(struct roots_cursor *cursor, if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { wlr_cursor_warp_absolute(cursor->cursor, event->device, - event->x_mm / event->width_mm, event->y_mm / event->height_mm); + event->x, event->y); roots_cursor_update_position(cursor, event->time_msec); } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { - wlr_cursor_warp_absolute(cursor->cursor, event->device, - event->x_mm / event->width_mm, -1); + wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1); roots_cursor_update_position(cursor, event->time_msec); } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { - wlr_cursor_warp_absolute(cursor->cursor, event->device, - -1, event->y_mm / event->height_mm); + wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y); roots_cursor_update_position(cursor, event->time_msec); } } -- cgit v1.2.3 From 32bdcdf7191be40a4ad74ece7e152a264358220a Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Mar 2018 12:33:17 -0400 Subject: Address review feedback --- include/wlr/types/wlr_cursor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index fc541271..0883f3ca 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -155,7 +155,7 @@ void wlr_cursor_map_input_to_region(struct wlr_cursor *cur, * Convert absolute coordinates to layout coordinates for the device. */ bool wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur, - struct wlr_input_device *device, double x_mm, double y_mm, + struct wlr_input_device *device, double x, double y, double *lx, double *ly); #endif -- cgit v1.2.3 From dbffda7549de4dba6b595e9bcaaef1628463315f Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 16:27:08 -0400 Subject: xdg-positioner wlr abstractions --- include/wlr/types/wlr_xdg_shell_v6.h | 31 ++++++- rootston/xdg_shell_v6.c | 134 +++------------------------- types/wlr_xdg_shell_v6.c | 165 ++++++++++++++++++++++++++--------- 3 files changed, 167 insertions(+), 163 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 e2a58669..0ab57108 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -302,18 +302,45 @@ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( struct wlr_xdg_surface_v6 *surface, double sx, double sy, double *popup_sx, double *popup_sy); +/** + * Get the geometry for this positioner based on the anchor rect, gravity, and + * size of this positioner. + */ struct wlr_box wlr_xdg_positioner_v6_get_geometry( struct wlr_xdg_positioner_v6_attributes *positioner); /** - * Get the anchor point for this popup in the root parent's coordinate system. + * Get the anchor point for this popup in the toplevel parent's coordinate system. */ void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup, - int *root_sx, int *root_sy); + int *toplevel_sx, int *toplevel_sy); + +/** + * Convert the given coordinates in the popup coordinate system to the toplevel + * surface coordinate system. + */ +void wlr_xdg_popup_v6_get_toplevel_coords(struct wlr_xdg_popup_v6 *popup, + int popup_sx, int popup_sy, int *toplevel_sx, int *toplevel_sy); + +/** + * Set the geometry of this popup to unconstrain it according to its + * xdg-positioner rules. The box should be in the popup's toplevel + * parent surface coordinate system. + */ +void wlr_xdg_popup_v6_unconstrain_from_box(struct wlr_xdg_popup_v6 *popup, + struct wlr_box *toplevel_box); +/** + Invert the right/left anchor and gravity for this positioner. This can be + used to "flip" the positioner around the anchor rect in the x direction. + */ void wlr_positioner_v6_invert_x( struct wlr_xdg_positioner_v6_attributes *positioner); +/** + Invert the top/bottom anchor and gravity for this positioner. This can be + used to "flip" the positioner around the anchor rect in the y direction. + */ void wlr_positioner_v6_invert_y( struct wlr_xdg_positioner_v6_attributes *positioner); diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 9bcdb4c9..22309e8e 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -50,34 +50,17 @@ static void popup_handle_new_popup(struct wl_listener *listener, void *data) { popup_create(popup->view_child.view, wlr_popup); } -static void popup_get_coords(struct wlr_xdg_popup_v6 *popup, - double *sx, double *sy) { - struct wlr_xdg_surface_v6 *parent = popup->parent; - double popup_sx = popup->geometry.x; - double popup_sy = popup->geometry.y; - while (parent->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { - popup_sx += parent->popup->geometry.x; - popup_sy += parent->popup->geometry.y; - parent = parent->popup->parent; - } - - *sx = popup_sx + parent->geometry.x; - *sy = popup_sy + parent->geometry.y; -} - -static void popup_constraint_offset(struct roots_xdg_popup_v6 *popup, - int *offset_x, int *offset_y) { +static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) { struct roots_view *view = popup->view_child.view; struct wlr_output_layout *layout = view->desktop->layout; struct wlr_xdg_popup_v6 *wlr_popup = popup->wlr_popup; - int popup_width = wlr_popup->geometry.width; - int popup_height = wlr_popup->geometry.height; int anchor_lx, anchor_ly; wlr_xdg_popup_v6_get_anchor_point(wlr_popup, &anchor_lx, &anchor_ly); - double popup_lx, popup_ly; - popup_get_coords(wlr_popup, &popup_lx, &popup_ly); + int popup_lx, popup_ly; + wlr_xdg_popup_v6_get_toplevel_coords(wlr_popup, wlr_popup->geometry.x, + wlr_popup->geometry.y, &popup_lx, &popup_ly); popup_lx += view->x; popup_ly += view->y; @@ -93,108 +76,17 @@ static void popup_constraint_offset(struct roots_xdg_popup_v6 *popup, // XXX: handle empty output layout assert(output); - struct wlr_box *output_box = wlr_output_layout_get_box(layout, output); - - *offset_x = *offset_y = 0; - - if (popup_lx < output_box->x) { - *offset_x = output_box->x - popup_lx; - } else if (popup_lx + popup_width > output_box->x + output_box->width) { - *offset_x = output_box->x + output_box->width - (popup_lx + popup_width); - } - - if (popup_ly < output_box->y) { - *offset_y = output_box->y - popup_ly; - } else if (popup_ly + popup_height > output_box->y + output_box->height) { - *offset_y = output_box->y + output_box->height - (popup_ly + popup_height); - } -} - -static bool popup_unconstrain_flip(struct roots_xdg_popup_v6 *popup) { - int offset_x, offset_y; - popup_constraint_offset(popup, &offset_y, &offset_y); - - if (!offset_x && !offset_y) { - return true; - } - - if (offset_x) { - wlr_positioner_v6_invert_x(&popup->wlr_popup->positioner); - } - if (offset_y) { - wlr_positioner_v6_invert_y(&popup->wlr_popup->positioner); - } - - popup->wlr_popup->geometry = - wlr_xdg_positioner_v6_get_geometry(&popup->wlr_popup->positioner); - - popup_constraint_offset(popup, &offset_x, &offset_y); - - if (!offset_x && !offset_y) { - // no longer constrained - return true; - } - - // revert the positioner back if it didn't fix it and go to the next part - if (offset_x) { - wlr_positioner_v6_invert_x(&popup->wlr_popup->positioner); - } - if (offset_y) { - wlr_positioner_v6_invert_y(&popup->wlr_popup->positioner); - } + int width = 0, height = 0; + wlr_output_effective_resolution(output, &width, &height); - popup->wlr_popup->geometry = - wlr_xdg_positioner_v6_get_geometry(&popup->wlr_popup->positioner); + struct wlr_box toplevel_box = { + .x = output->lx - view->x, + .y = output->ly - view->y, + .width = width, + .height = height + }; - return false; -} - -static bool popup_unconstrain_slide(struct roots_xdg_popup_v6 *popup) { - int offset_x, offset_y; - popup_constraint_offset(popup, &offset_x, &offset_y); - - if (!offset_x && !offset_y) { - return true; - } - - if (offset_x) { - popup->wlr_popup->geometry.x += offset_x; - } - - if (offset_y) { - popup->wlr_popup->geometry.y += offset_y; - } - - popup_constraint_offset(popup, &offset_y, &offset_y); - - return !offset_x && !offset_y; -} - -static bool popup_unconstrain_resize(struct roots_xdg_popup_v6 *popup) { - int offset_x, offset_y; - popup_constraint_offset(popup, &offset_x, &offset_y); - - if (!offset_x && !offset_y) { - return true; - } - - if (offset_x) { - popup->wlr_popup->geometry.width -= offset_x; - } - if (offset_y) { - popup->wlr_popup->geometry.height -= offset_y; - } - - popup_constraint_offset(popup, &offset_y, &offset_y); - - return !offset_x && !offset_y; - -} - -static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) { - popup_unconstrain_flip(popup); - popup_unconstrain_slide(popup); - popup_unconstrain_resize(popup); + wlr_xdg_popup_v6_unconstrain_from_box(popup->wlr_popup, &toplevel_box); } static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 0a8bbadf..0cf215ab 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -1674,48 +1674,133 @@ void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup, *root_sx = sx; *root_sy = sy; +} - /* - // XXX: THIS IS WILL WORK WITH XDG SHELL STABLE - switch (popup->positioner.anchor) { - case WLR_POSITIONER_ANCHOR_NONE: - sx = (rect.x + rect.width) / 2; - sy = (rect.y + rect.height) / 2; - break; - case WLR_POSITIONER_ANCHOR_TOP: - sx = (rect.x + rect.width) / 2; - sy = rect.y; - break; - case WLR_POSITIONER_ANCHOR_BOTTOM: - sx = (rect.x + rect.width) / 2; - sy = rect.y + rect.height; - break; - case WLR_POSITIONER_ANCHOR_LEFT: - sx = rect.x; - sy = (rect.y + rect.height) / 2; - break; - case WLR_POSITIONER_ANCHOR_RIGHT: - sx = rect.x + rect.width; - sy = (rect.y + rect.height) / 2; - break; - case WLR_POSITIONER_ANCHOR_TOP_LEFT: - sx = rect.x; - sy = rect.y; - break; - case WLR_POSITIONER_ANCHOR_BOTTOM_LEFT: - sx = rect.x; - sy = rect.y + rect.height; - break; - case WLR_POSITIONER_ANCHOR_TOP_RIGHT: - sx = rect.x + rect.width; - sy = rect.y; - break; - case WLR_POSITIONER_ANCHOR_BOTTOM_RIGHT: - sx = rect.x + rect.width; - sy = rect.y + rect.height; - break; +void wlr_xdg_popup_v6_get_toplevel_coords(struct wlr_xdg_popup_v6 *popup, + int popup_sx, int popup_sy, int *toplevel_sx, int *toplevel_sy) { + struct wlr_xdg_surface_v6 *parent = popup->parent; + while (parent->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + popup_sx += parent->popup->geometry.x; + popup_sy += parent->popup->geometry.y; + parent = parent->popup->parent; + } + + *toplevel_sx = popup_sx + parent->geometry.x; + *toplevel_sy = popup_sy + parent->geometry.y; + +} + +static void wlr_xdg_popup_v6_box_constraints(struct wlr_xdg_popup_v6 *popup, + struct wlr_box *toplevel_box, int *offset_x, int *offset_y) { + int popup_width = popup->geometry.width; + int popup_height = popup->geometry.height; + int anchor_sx = 0, anchor_sy = 0; + wlr_xdg_popup_v6_get_anchor_point(popup, &anchor_sx, &anchor_sy); + int popup_sx = 0, popup_sy = 0; + wlr_xdg_popup_v6_get_toplevel_coords(popup, popup->geometry.x, + popup->geometry.y, &popup_sx, &popup_sy); + *offset_x = 0, *offset_y = 0; + + if (popup_sx < toplevel_box->x) { + *offset_x = toplevel_box->x - popup_sx; + } else if (popup_sx + popup_width > toplevel_box->x + toplevel_box->width) { + *offset_x = toplevel_box->x + toplevel_box->width - (popup_sx + popup_width); + } + + if (popup_sy < toplevel_box->y) { + *offset_y = toplevel_box->y - popup_sy; + } else if (popup_sy + popup_height > toplevel_box->y + toplevel_box->height) { + *offset_y = toplevel_box->y + toplevel_box->height - (popup_sy + popup_height); + } +} + +static bool wlr_xdg_popup_v6_unconstrain_flip(struct wlr_xdg_popup_v6 *popup, + struct wlr_box *toplevel_box) { + int offset_x = 0, offset_y = 0; + wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_y, &offset_y); + + if (!offset_x && !offset_y) { + return true; + } + + if (offset_x) { + wlr_positioner_v6_invert_x(&popup->positioner); + } + if (offset_y) { + wlr_positioner_v6_invert_y(&popup->positioner); + } + + popup->geometry = + wlr_xdg_positioner_v6_get_geometry(&popup->positioner); + + wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_x, &offset_y); + + if (!offset_x && !offset_y) { + // no longer constrained + return true; } - */ + + // revert the positioner back if it didn't fix it and go to the next part + if (offset_x) { + wlr_positioner_v6_invert_x(&popup->positioner); + } + if (offset_y) { + wlr_positioner_v6_invert_y(&popup->positioner); + } + + popup->geometry = + wlr_xdg_positioner_v6_get_geometry(&popup->positioner); + + return false; +} + +static bool wlr_xdg_popup_v6_unconstrain_slide(struct wlr_xdg_popup_v6 *popup, + struct wlr_box *toplevel_box) { + int offset_x, offset_y; + wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_x, &offset_y); + + if (!offset_x && !offset_y) { + return true; + } + + if (offset_x) { + popup->geometry.x += offset_x; + } + + if (offset_y) { + popup->geometry.y += offset_y; + } + + wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_x, &offset_y); + + return !offset_x && !offset_y; +} + +static bool wlr_xdg_popup_v6_unconstrain_resize(struct wlr_xdg_popup_v6 *popup, + struct wlr_box *toplevel_box) { + int offset_x, offset_y; + wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_x, &offset_y); + + if (!offset_x && !offset_y) { + return true; + } + + if (offset_x) { + popup->geometry.width -= offset_x; + } + if (offset_y) { + popup->geometry.height -= offset_y; + } + + wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_y, &offset_y); + + return !offset_x && !offset_y; +} + +void wlr_xdg_popup_v6_unconstrain_from_box(struct wlr_xdg_popup_v6 *popup, + struct wlr_box *toplevel_box) { + wlr_xdg_popup_v6_unconstrain_flip(popup, toplevel_box); + wlr_xdg_popup_v6_unconstrain_slide(popup, toplevel_box); } void wlr_positioner_v6_invert_x(struct wlr_xdg_positioner_v6_attributes *positioner) { -- cgit v1.2.3 From 376d1cc0da0a7cd2bbcb6fcb500caaddd9561a50 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 18:30:38 -0400 Subject: rename xdg-positioner structs --- include/wlr/types/wlr_xdg_shell_v6.h | 10 ++++----- types/wlr_xdg_shell_v6.c | 40 +++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 24 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 0ab57108..72d1850e 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -88,7 +88,7 @@ enum wlr_positioner_v6_constraint_adjustment { WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y = 32, }; -struct wlr_xdg_positioner_v6_attributes { +struct wlr_xdg_positioner_v6 { struct wlr_box anchor_rect; enum wlr_positioner_v6_anchor anchor; enum wlr_positioner_v6_gravity gravity; @@ -116,7 +116,7 @@ struct wlr_xdg_popup_v6 { // geometry of the parent surface struct wlr_box geometry; - struct wlr_xdg_positioner_v6_attributes positioner; + struct wlr_xdg_positioner_v6 positioner; struct wl_list grab_link; // wlr_xdg_popup_grab_v6::popups }; @@ -307,7 +307,7 @@ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( * size of this positioner. */ struct wlr_box wlr_xdg_positioner_v6_get_geometry( - struct wlr_xdg_positioner_v6_attributes *positioner); + struct wlr_xdg_positioner_v6 *positioner); /** * Get the anchor point for this popup in the toplevel parent's coordinate system. @@ -335,13 +335,13 @@ void wlr_xdg_popup_v6_unconstrain_from_box(struct wlr_xdg_popup_v6 *popup, used to "flip" the positioner around the anchor rect in the x direction. */ void wlr_positioner_v6_invert_x( - struct wlr_xdg_positioner_v6_attributes *positioner); + struct wlr_xdg_positioner_v6 *positioner); /** Invert the top/bottom anchor and gravity for this positioner. This can be used to "flip" the positioner around the anchor rect in the y direction. */ void wlr_positioner_v6_invert_y( - struct wlr_xdg_positioner_v6_attributes *positioner); + struct wlr_xdg_positioner_v6 *positioner); #endif diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 4b2cfc23..a78546ae 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -16,9 +16,9 @@ static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel_v6"; static const char *wlr_desktop_xdg_popup_role = "xdg_popup_v6"; -struct wlr_xdg_positioner_v6 { +struct wlr_xdg_positioner_v6_resource { struct wl_resource *resource; - struct wlr_xdg_positioner_v6_attributes *attrs; + struct wlr_xdg_positioner_v6 *attrs; }; static void resource_handle_destroy(struct wl_client *client, @@ -287,7 +287,7 @@ static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { static const struct zxdg_positioner_v6_interface zxdg_positioner_v6_implementation; -static struct wlr_xdg_positioner_v6 *xdg_positioner_from_resource( +static struct wlr_xdg_positioner_v6_resource *xdg_positioner_from_resource( struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &zxdg_positioner_v6_interface, &zxdg_positioner_v6_implementation)); @@ -295,7 +295,7 @@ static struct wlr_xdg_positioner_v6 *xdg_positioner_from_resource( } static void xdg_positioner_destroy(struct wl_resource *resource) { - struct wlr_xdg_positioner_v6 *positioner = + struct wlr_xdg_positioner_v6_resource *positioner = xdg_positioner_from_resource(resource); free(positioner->attrs); free(positioner); @@ -303,7 +303,7 @@ static void xdg_positioner_destroy(struct wl_resource *resource) { static void xdg_positioner_handle_set_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { - struct wlr_xdg_positioner_v6 *positioner = + struct wlr_xdg_positioner_v6_resource *positioner = xdg_positioner_from_resource(resource); if (width < 1 || height < 1) { @@ -320,7 +320,7 @@ static void xdg_positioner_handle_set_size(struct wl_client *client, static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) { - struct wlr_xdg_positioner_v6 *positioner = + struct wlr_xdg_positioner_v6_resource *positioner = xdg_positioner_from_resource(resource); if (width < 1 || height < 1) { @@ -338,7 +338,7 @@ static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client, static void xdg_positioner_handle_set_anchor(struct wl_client *client, struct wl_resource *resource, uint32_t anchor) { - struct wlr_xdg_positioner_v6 *positioner = + struct wlr_xdg_positioner_v6_resource *positioner = xdg_positioner_from_resource(resource); if (((anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP ) && @@ -356,7 +356,7 @@ static void xdg_positioner_handle_set_anchor(struct wl_client *client, static void xdg_positioner_handle_set_gravity(struct wl_client *client, struct wl_resource *resource, uint32_t gravity) { - struct wlr_xdg_positioner_v6 *positioner = + struct wlr_xdg_positioner_v6_resource *positioner = xdg_positioner_from_resource(resource); if (((gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) && @@ -375,7 +375,7 @@ static void xdg_positioner_handle_set_gravity(struct wl_client *client, static void xdg_positioner_handle_set_constraint_adjustment( struct wl_client *client, struct wl_resource *resource, uint32_t constraint_adjustment) { - struct wlr_xdg_positioner_v6 *positioner = + struct wlr_xdg_positioner_v6_resource *positioner = xdg_positioner_from_resource(resource); positioner->attrs->constraint_adjustment = constraint_adjustment; @@ -383,7 +383,7 @@ static void xdg_positioner_handle_set_constraint_adjustment( static void xdg_positioner_handle_set_offset(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y) { - struct wlr_xdg_positioner_v6 *positioner = + struct wlr_xdg_positioner_v6_resource *positioner = xdg_positioner_from_resource(resource); positioner->attrs->offset.x = x; @@ -404,8 +404,8 @@ static const struct zxdg_positioner_v6_interface static void xdg_shell_handle_create_positioner(struct wl_client *wl_client, struct wl_resource *resource, uint32_t id) { - struct wlr_xdg_positioner_v6 *positioner = - calloc(1, sizeof(struct wlr_xdg_positioner_v6)); + struct wlr_xdg_positioner_v6_resource *positioner = + calloc(1, sizeof(struct wlr_xdg_positioner_v6_resource)); if (positioner == NULL) { wl_client_post_no_memory(wl_client); return; @@ -413,7 +413,7 @@ static void xdg_shell_handle_create_positioner(struct wl_client *wl_client, // TODO: allocate the positioner attrs? positioner->attrs = - calloc(1, sizeof(struct wlr_xdg_positioner_v6_attributes)); + calloc(1, sizeof(struct wlr_xdg_positioner_v6)); positioner->resource = wl_resource_create(wl_client, &zxdg_positioner_v6_interface, @@ -430,7 +430,7 @@ static void xdg_shell_handle_create_positioner(struct wl_client *wl_client, positioner, xdg_positioner_destroy); } -struct wlr_box wlr_xdg_positioner_v6_get_geometry(struct wlr_xdg_positioner_v6_attributes *positioner) { +struct wlr_box wlr_xdg_positioner_v6_get_geometry(struct wlr_xdg_positioner_v6 *positioner) { struct wlr_box geometry = { .x = positioner->offset.x, .y = positioner->offset.y, @@ -584,7 +584,7 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, xdg_surface_from_resource(resource); struct wlr_xdg_surface_v6 *parent = xdg_surface_from_resource(parent_resource); - struct wlr_xdg_positioner_v6 *positioner = + struct wlr_xdg_positioner_v6_resource *positioner = xdg_positioner_from_resource(positioner_resource); if (positioner->attrs->size.width == 0 || positioner->attrs->anchor_rect.width == 0) { @@ -622,7 +622,7 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, // positioner properties memcpy(&surface->popup->positioner, positioner->attrs, - sizeof(struct wlr_xdg_positioner_v6_attributes)); + sizeof(struct wlr_xdg_positioner_v6)); wl_list_insert(&parent->popups, &surface->popup->link); @@ -1679,12 +1679,14 @@ void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup, void wlr_xdg_popup_v6_get_toplevel_coords(struct wlr_xdg_popup_v6 *popup, int popup_sx, int popup_sy, int *toplevel_sx, int *toplevel_sy) { struct wlr_xdg_surface_v6 *parent = popup->parent; - while (parent->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + while (parent && parent->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { popup_sx += parent->popup->geometry.x; popup_sy += parent->popup->geometry.y; parent = parent->popup->parent; } + assert(parent); + *toplevel_sx = popup_sx + parent->geometry.x; *toplevel_sy = popup_sy + parent->geometry.y; @@ -1834,7 +1836,7 @@ void wlr_xdg_popup_v6_unconstrain_from_box(struct wlr_xdg_popup_v6 *popup, } } -void wlr_positioner_v6_invert_x(struct wlr_xdg_positioner_v6_attributes *positioner) { +void wlr_positioner_v6_invert_x(struct wlr_xdg_positioner_v6 *positioner) { if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_LEFT) { positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_LEFT; positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_RIGHT; @@ -1853,7 +1855,7 @@ void wlr_positioner_v6_invert_x(struct wlr_xdg_positioner_v6_attributes *positio } void wlr_positioner_v6_invert_y( - struct wlr_xdg_positioner_v6_attributes *positioner) { + struct wlr_xdg_positioner_v6 *positioner) { if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_TOP) { positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_TOP; positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_BOTTOM; -- cgit v1.2.3 From 967bccffcd634a6ba2d13185c530f64b4d1eb613 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 19:42:17 -0400 Subject: remove xdg-positioner wlr wrappers --- include/wlr/types/wlr_xdg_shell_v6.h | 63 ++---------------------- types/wlr_xdg_shell_v6.c | 94 ++++++++++++++++++------------------ 2 files changed, 51 insertions(+), 106 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 72d1850e..04c7e450 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -4,6 +4,7 @@ #include #include #include +#include "xdg-shell-unstable-v6-protocol.h" struct wlr_xdg_shell_v6 { struct wl_global *wl_global; @@ -32,67 +33,11 @@ struct wlr_xdg_client_v6 { struct wl_event_source *ping_timer; }; -enum wlr_positioner_v6_anchor { - /** - * the center of the anchor rectangle - */ - WLR_POSITIONER_V6_ANCHOR_NONE = 0, - /** - * the top edge of the anchor rectangle - */ - WLR_POSITIONER_V6_ANCHOR_TOP = 1, - /** - * the bottom edge of the anchor rectangle - */ - WLR_POSITIONER_V6_ANCHOR_BOTTOM = 2, - /** - * the left edge of the anchor rectangle - */ - WLR_POSITIONER_V6_ANCHOR_LEFT = 4, - /** - * the right edge of the anchor rectangle - */ - WLR_POSITIONER_V6_ANCHOR_RIGHT = 8, -}; - -enum wlr_positioner_v6_gravity { - /** - * center over the anchor edge - */ - WLR_POSITIONER_V6_GRAVITY_NONE = 0, - /** - * position above the anchor edge - */ - WLR_POSITIONER_V6_GRAVITY_TOP = 1, - /** - * position below the anchor edge - */ - WLR_POSITIONER_V6_GRAVITY_BOTTOM = 2, - /** - * position to the left of the anchor edge - */ - WLR_POSITIONER_V6_GRAVITY_LEFT = 4, - /** - * position to the right of the anchor edge - */ - WLR_POSITIONER_V6_GRAVITY_RIGHT = 8, -}; - -enum wlr_positioner_v6_constraint_adjustment { - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_NONE = 0, - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_X = 1, - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_Y = 2, - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_X = 4, - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_Y = 8, - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_X = 16, - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y = 32, -}; - struct wlr_xdg_positioner_v6 { struct wlr_box anchor_rect; - enum wlr_positioner_v6_anchor anchor; - enum wlr_positioner_v6_gravity gravity; - enum wlr_positioner_v6_constraint_adjustment constraint_adjustment; + enum zxdg_positioner_v6_anchor anchor; + enum zxdg_positioner_v6_gravity gravity; + enum zxdg_positioner_v6_constraint_adjustment constraint_adjustment; struct { int32_t width, height; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 85ced7bd..2a780a37 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -469,7 +469,7 @@ struct wlr_box wlr_xdg_positioner_v6_get_geometry(struct wlr_xdg_positioner_v6 * } if (positioner->constraint_adjustment == - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_NONE) { + ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_NONE) { return geometry; } @@ -1631,38 +1631,38 @@ struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup, int *root_sx, int *root_sy) { struct wlr_box rect = popup->positioner.anchor_rect; - enum wlr_positioner_v6_anchor anchor = popup->positioner.anchor; + enum zxdg_positioner_v6_anchor anchor = popup->positioner.anchor; int sx = 0, sy = 0; - if (anchor == WLR_POSITIONER_V6_ANCHOR_NONE) { + if (anchor == ZXDG_POSITIONER_V6_ANCHOR_NONE) { sx = (rect.x + rect.width) / 2; sy = (rect.y + rect.height) / 2; - } else if (anchor == WLR_POSITIONER_V6_ANCHOR_TOP) { + } else if (anchor == ZXDG_POSITIONER_V6_ANCHOR_TOP) { sx = (rect.x + rect.width) / 2; sy = rect.y; - } else if (anchor == WLR_POSITIONER_V6_ANCHOR_BOTTOM) { + } else if (anchor == ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) { sx = (rect.x + rect.width) / 2; sy = rect.y + rect.height; - } else if (anchor == WLR_POSITIONER_V6_ANCHOR_LEFT) { + } else if (anchor == ZXDG_POSITIONER_V6_ANCHOR_LEFT) { sx = rect.x; sy = (rect.y + rect.height) / 2; - } else if (anchor == WLR_POSITIONER_V6_ANCHOR_RIGHT) { + } else if (anchor == ZXDG_POSITIONER_V6_ANCHOR_RIGHT) { sx = rect.x + rect.width; sy = (rect.y + rect.height) / 2; - } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_TOP | - WLR_POSITIONER_V6_ANCHOR_LEFT)) { + } else if (anchor == (ZXDG_POSITIONER_V6_ANCHOR_TOP | + ZXDG_POSITIONER_V6_ANCHOR_LEFT)) { sx = rect.x; sy = rect.y; - } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_TOP | - WLR_POSITIONER_V6_ANCHOR_RIGHT)) { + } else if (anchor == (ZXDG_POSITIONER_V6_ANCHOR_TOP | + ZXDG_POSITIONER_V6_ANCHOR_RIGHT)) { sx = rect.x + rect.width; sy = rect.y; - } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_BOTTOM | - WLR_POSITIONER_V6_ANCHOR_LEFT)) { + } else if (anchor == (ZXDG_POSITIONER_V6_ANCHOR_BOTTOM | + ZXDG_POSITIONER_V6_ANCHOR_LEFT)) { sx = rect.x; sy = rect.y + rect.height; - } else if (anchor == (WLR_POSITIONER_V6_ANCHOR_BOTTOM | - WLR_POSITIONER_V6_ANCHOR_RIGHT)) { + } else if (anchor == (ZXDG_POSITIONER_V6_ANCHOR_BOTTOM | + ZXDG_POSITIONER_V6_ANCHOR_RIGHT)) { sx = rect.x + rect.width; sy = rect.y + rect.height; } @@ -1722,11 +1722,11 @@ static bool wlr_xdg_popup_v6_unconstrain_flip(struct wlr_xdg_popup_v6 *popup, bool flip_x = offset_x && (popup->positioner.constraint_adjustment & - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_X); + ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_X); bool flip_y = offset_y && (popup->positioner.constraint_adjustment & - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_Y); + ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_Y); if (flip_x) { wlr_positioner_v6_invert_x(&popup->positioner); @@ -1770,11 +1770,11 @@ static bool wlr_xdg_popup_v6_unconstrain_slide(struct wlr_xdg_popup_v6 *popup, bool slide_x = offset_x && (popup->positioner.constraint_adjustment & - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_X); + ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_X); bool slide_y = offset_x && (popup->positioner.constraint_adjustment & - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_Y); + ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_Y); if (slide_x) { popup->geometry.x += offset_x; @@ -1811,11 +1811,11 @@ static bool wlr_xdg_popup_v6_unconstrain_resize(struct wlr_xdg_popup_v6 *popup, bool resize_x = offset_x && (popup->positioner.constraint_adjustment & - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_X); + ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_X); bool resize_y = offset_x && (popup->positioner.constraint_adjustment & - WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y); + ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y); if (resize_x) { popup->geometry.width -= offset_x; @@ -1843,38 +1843,38 @@ void wlr_xdg_popup_v6_unconstrain_from_box(struct wlr_xdg_popup_v6 *popup, } void wlr_positioner_v6_invert_x(struct wlr_xdg_positioner_v6 *positioner) { - if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_LEFT) { - positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_LEFT; - positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_RIGHT; - } else if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_RIGHT) { - positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_RIGHT; - positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_LEFT; + if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) { + positioner->anchor &= ~ZXDG_POSITIONER_V6_ANCHOR_LEFT; + positioner->anchor |= ZXDG_POSITIONER_V6_ANCHOR_RIGHT; + } else if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT) { + positioner->anchor &= ~ZXDG_POSITIONER_V6_ANCHOR_RIGHT; + positioner->anchor |= ZXDG_POSITIONER_V6_ANCHOR_LEFT; } - if (positioner->gravity & WLR_POSITIONER_V6_GRAVITY_RIGHT) { - positioner->gravity &= ~WLR_POSITIONER_V6_GRAVITY_RIGHT; - positioner->gravity |= WLR_POSITIONER_V6_GRAVITY_LEFT; - } else if (positioner->gravity & WLR_POSITIONER_V6_GRAVITY_LEFT) { - positioner->gravity &= ~WLR_POSITIONER_V6_GRAVITY_LEFT; - positioner->gravity |= WLR_POSITIONER_V6_GRAVITY_RIGHT; + if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT) { + positioner->gravity &= ~ZXDG_POSITIONER_V6_GRAVITY_RIGHT; + positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_LEFT; + } else if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) { + positioner->gravity &= ~ZXDG_POSITIONER_V6_GRAVITY_LEFT; + positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_RIGHT; } } void wlr_positioner_v6_invert_y( struct wlr_xdg_positioner_v6 *positioner) { - if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_TOP) { - positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_TOP; - positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_BOTTOM; - } else if (positioner->anchor & WLR_POSITIONER_V6_ANCHOR_BOTTOM) { - positioner->anchor &= ~WLR_POSITIONER_V6_ANCHOR_BOTTOM; - positioner->anchor |= WLR_POSITIONER_V6_ANCHOR_TOP; - } - - if (positioner->gravity & WLR_POSITIONER_V6_GRAVITY_TOP) { - positioner->gravity &= ~WLR_POSITIONER_V6_GRAVITY_TOP; - positioner->gravity |= WLR_POSITIONER_V6_GRAVITY_BOTTOM; - } else if (positioner->gravity & WLR_POSITIONER_V6_GRAVITY_BOTTOM) { - positioner->gravity &= ~WLR_POSITIONER_V6_GRAVITY_BOTTOM; - positioner->gravity |= WLR_POSITIONER_V6_GRAVITY_TOP; + if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP) { + positioner->anchor &= ~ZXDG_POSITIONER_V6_ANCHOR_TOP; + positioner->anchor |= ZXDG_POSITIONER_V6_ANCHOR_BOTTOM; + } else if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) { + positioner->anchor &= ~ZXDG_POSITIONER_V6_ANCHOR_BOTTOM; + positioner->anchor |= ZXDG_POSITIONER_V6_ANCHOR_TOP; + } + + if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) { + positioner->gravity &= ~ZXDG_POSITIONER_V6_GRAVITY_TOP; + positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_BOTTOM; + } else if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM) { + positioner->gravity &= ~ZXDG_POSITIONER_V6_GRAVITY_BOTTOM; + positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_TOP; } } -- cgit v1.2.3 From 2e63d1a0ca01d71de58988593860741b835ba8bb Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 23:24:39 -0400 Subject: toplevel_box to toplevel_sx_box --- include/wlr/types/wlr_xdg_shell_v6.h | 6 +-- rootston/xdg_shell_v6.c | 4 +- types/wlr_xdg_shell_v6.c | 84 +++++++++++++++++++++--------------- 3 files changed, 55 insertions(+), 39 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 04c7e450..d01240eb 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -269,11 +269,11 @@ void wlr_xdg_popup_v6_get_toplevel_coords(struct wlr_xdg_popup_v6 *popup, /** * Set the geometry of this popup to unconstrain it according to its - * xdg-positioner rules. The box should be in the popup's toplevel - * parent surface coordinate system. + * xdg-positioner rules. The box should be in the popup's root toplevel parent + * surface coordinate system. */ void wlr_xdg_popup_v6_unconstrain_from_box(struct wlr_xdg_popup_v6 *popup, - struct wlr_box *toplevel_box); + struct wlr_box *toplevel_sx_box); /** Invert the right/left anchor and gravity for this positioner. This can be diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 0aca9638..39e8a4b7 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -92,14 +92,14 @@ static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) { // the output box expressed in the coordinate system of the toplevel parent // of the popup - struct wlr_box output_box_toplevel = { + struct wlr_box output_toplevel_sx_box = { .x = output->lx - view->x, .y = output->ly - view->y, .width = width, .height = height }; - wlr_xdg_popup_v6_unconstrain_from_box(popup->wlr_popup, &output_box_toplevel); + wlr_xdg_popup_v6_unconstrain_from_box(popup->wlr_popup, &output_toplevel_sx_box); } static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 44bd8d9a..64d44f22 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -97,8 +97,8 @@ static void xdg_keyboard_grab_enter(struct wlr_seat_keyboard_grab *grab, // keyboard focus should remain on the popup } -static void xdg_keyboard_grab_key(struct wlr_seat_keyboard_grab *grab, uint32_t time, - uint32_t key, uint32_t state) { +static void xdg_keyboard_grab_key(struct wlr_seat_keyboard_grab *grab, + uint32_t time, uint32_t key, uint32_t state) { wlr_seat_keyboard_send_key(grab->seat, time, key, state); } @@ -425,7 +425,8 @@ static void xdg_shell_handle_create_positioner(struct wl_client *wl_client, positioner, xdg_positioner_destroy); } -struct wlr_box wlr_xdg_positioner_v6_get_geometry(struct wlr_xdg_positioner_v6 *positioner) { +struct wlr_box wlr_xdg_positioner_v6_get_geometry( + struct wlr_xdg_positioner_v6 *positioner) { struct wlr_box geometry = { .x = positioner->offset.x, .y = positioner->offset.y, @@ -582,7 +583,8 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, struct wlr_xdg_positioner_v6_resource *positioner = xdg_positioner_from_resource(positioner_resource); - if (positioner->attrs.size.width == 0 || positioner->attrs.anchor_rect.width == 0) { + if (positioner->attrs.size.width == 0 || + positioner->attrs.anchor_rect.width == 0) { wl_resource_post_error(resource, ZXDG_SHELL_V6_ERROR_INVALID_POSITIONER, "positioner object is not complete"); @@ -1089,7 +1091,8 @@ static void wlr_xdg_toplevel_v6_send_configure( if (surface->toplevel->server_pending.maximized) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { - wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel"); + wlr_log(L_ERROR, + "Could not allocate state for maximized xdg_toplevel"); goto error_out; } *s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED; @@ -1097,7 +1100,8 @@ static void wlr_xdg_toplevel_v6_send_configure( if (surface->toplevel->server_pending.fullscreen) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { - wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel"); + wlr_log(L_ERROR, + "Could not allocate state for fullscreen xdg_toplevel"); goto error_out; } *s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN; @@ -1105,7 +1109,8 @@ static void wlr_xdg_toplevel_v6_send_configure( if (surface->toplevel->server_pending.resizing) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { - wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel"); + wlr_log(L_ERROR, + "Could not allocate state for resizing xdg_toplevel"); goto error_out; } *s = ZXDG_TOPLEVEL_V6_STATE_RESIZING; @@ -1113,7 +1118,8 @@ static void wlr_xdg_toplevel_v6_send_configure( if (surface->toplevel->server_pending.activated) { s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { - wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel"); + wlr_log(L_ERROR, + "Could not allocate state for activated xdg_toplevel"); goto error_out; } *s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED; @@ -1688,7 +1694,7 @@ void wlr_xdg_popup_v6_get_toplevel_coords(struct wlr_xdg_popup_v6 *popup, } static void wlr_xdg_popup_v6_box_constraints(struct wlr_xdg_popup_v6 *popup, - struct wlr_box *toplevel_box, int *offset_x, int *offset_y) { + struct wlr_box *toplevel_sx_box, int *offset_x, int *offset_y) { int popup_width = popup->geometry.width; int popup_height = popup->geometry.height; int anchor_sx = 0, anchor_sy = 0; @@ -1698,23 +1704,28 @@ static void wlr_xdg_popup_v6_box_constraints(struct wlr_xdg_popup_v6 *popup, popup->geometry.y, &popup_sx, &popup_sy); *offset_x = 0, *offset_y = 0; - if (popup_sx < toplevel_box->x) { - *offset_x = toplevel_box->x - popup_sx; - } else if (popup_sx + popup_width > toplevel_box->x + toplevel_box->width) { - *offset_x = toplevel_box->x + toplevel_box->width - (popup_sx + popup_width); + if (popup_sx < toplevel_sx_box->x) { + *offset_x = toplevel_sx_box->x - popup_sx; + } else if (popup_sx + popup_width > + toplevel_sx_box->x + toplevel_sx_box->width) { + *offset_x = toplevel_sx_box->x + toplevel_sx_box->width - + (popup_sx + popup_width); } - if (popup_sy < toplevel_box->y) { - *offset_y = toplevel_box->y - popup_sy; - } else if (popup_sy + popup_height > toplevel_box->y + toplevel_box->height) { - *offset_y = toplevel_box->y + toplevel_box->height - (popup_sy + popup_height); + if (popup_sy < toplevel_sx_box->y) { + *offset_y = toplevel_sx_box->y - popup_sy; + } else if (popup_sy + popup_height > + toplevel_sx_box->y + toplevel_sx_box->height) { + *offset_y = toplevel_sx_box->y + toplevel_sx_box->height - + (popup_sy + popup_height); } } static bool wlr_xdg_popup_v6_unconstrain_flip(struct wlr_xdg_popup_v6 *popup, - struct wlr_box *toplevel_box) { + struct wlr_box *toplevel_sx_box) { int offset_x = 0, offset_y = 0; - wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_x, &offset_y); + wlr_xdg_popup_v6_box_constraints(popup, toplevel_sx_box, + &offset_x, &offset_y); if (!offset_x && !offset_y) { return true; @@ -1738,7 +1749,8 @@ static bool wlr_xdg_popup_v6_unconstrain_flip(struct wlr_xdg_popup_v6 *popup, popup->geometry = wlr_xdg_positioner_v6_get_geometry(&popup->positioner); - wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_x, &offset_y); + wlr_xdg_popup_v6_box_constraints(popup, toplevel_sx_box, + &offset_x, &offset_y); if (!offset_x && !offset_y) { // no longer constrained @@ -1760,9 +1772,10 @@ static bool wlr_xdg_popup_v6_unconstrain_flip(struct wlr_xdg_popup_v6 *popup, } static bool wlr_xdg_popup_v6_unconstrain_slide(struct wlr_xdg_popup_v6 *popup, - struct wlr_box *toplevel_box) { + struct wlr_box *toplevel_sx_box) { int offset_x = 0, offset_y = 0; - wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_x, &offset_y); + wlr_xdg_popup_v6_box_constraints(popup, toplevel_sx_box, + &offset_x, &offset_y); if (!offset_x && !offset_y) { return true; @@ -1788,22 +1801,24 @@ static bool wlr_xdg_popup_v6_unconstrain_slide(struct wlr_xdg_popup_v6 *popup, wlr_xdg_popup_v6_get_toplevel_coords(popup, popup->geometry.x, popup->geometry.y, &toplevel_x, &toplevel_y); - if (slide_x && toplevel_x < toplevel_box->x) { - popup->geometry.x += toplevel_box->x - toplevel_x; + if (slide_x && toplevel_x < toplevel_sx_box->x) { + popup->geometry.x += toplevel_sx_box->x - toplevel_x; } - if (slide_y && toplevel_y < toplevel_box->y) { - popup->geometry.y += toplevel_box->y - toplevel_y; + if (slide_y && toplevel_y < toplevel_sx_box->y) { + popup->geometry.y += toplevel_sx_box->y - toplevel_y; } - wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_x, &offset_y); + wlr_xdg_popup_v6_box_constraints(popup, toplevel_sx_box, + &offset_x, &offset_y); return !offset_x && !offset_y; } static bool wlr_xdg_popup_v6_unconstrain_resize(struct wlr_xdg_popup_v6 *popup, - struct wlr_box *toplevel_box) { + struct wlr_box *toplevel_sx_box) { int offset_x, offset_y; - wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_x, &offset_y); + wlr_xdg_popup_v6_box_constraints(popup, toplevel_sx_box, + &offset_x, &offset_y); if (!offset_x && !offset_y) { return true; @@ -1824,20 +1839,21 @@ static bool wlr_xdg_popup_v6_unconstrain_resize(struct wlr_xdg_popup_v6 *popup, popup->geometry.height -= offset_y; } - wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_y, &offset_y); + wlr_xdg_popup_v6_box_constraints(popup, toplevel_sx_box, + &offset_y, &offset_y); return !offset_x && !offset_y; } void wlr_xdg_popup_v6_unconstrain_from_box(struct wlr_xdg_popup_v6 *popup, - struct wlr_box *toplevel_box) { - if (wlr_xdg_popup_v6_unconstrain_flip(popup, toplevel_box)) { + struct wlr_box *toplevel_sx_box) { + if (wlr_xdg_popup_v6_unconstrain_flip(popup, toplevel_sx_box)) { return; } - if (wlr_xdg_popup_v6_unconstrain_slide(popup, toplevel_box)) { + if (wlr_xdg_popup_v6_unconstrain_slide(popup, toplevel_sx_box)) { return; } - if (wlr_xdg_popup_v6_unconstrain_resize(popup, toplevel_box)) { + if (wlr_xdg_popup_v6_unconstrain_resize(popup, toplevel_sx_box)) { return; } } -- cgit v1.2.3 From 4137d9fc80fdf2ef03ff69a0b75ab52123517408 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 29 Mar 2018 16:30:09 -0400 Subject: Destroy layer surfaces on client destroyed --- include/wlr/types/wlr_layer_shell.h | 2 ++ types/wlr_layer_shell.c | 9 +++++++++ 2 files changed, 11 insertions(+) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h index 8cc7782f..8d093ada 100644 --- a/include/wlr/types/wlr_layer_shell.h +++ b/include/wlr/types/wlr_layer_shell.h @@ -22,6 +22,7 @@ struct wlr_layer_shell { struct wl_global *wl_global; struct wl_list client_resources; // wl_resource + struct wl_list surfaces; // wl_layer_surface struct wl_listener display_destroy; @@ -50,6 +51,7 @@ struct wlr_layer_surface_configure { }; struct wlr_layer_surface { + struct wl_list link; // wlr_layer_shell::surfaces struct wlr_surface *surface; struct wlr_output *output; struct wl_resource *resource; diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 39a3af80..cbf21f4a 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -159,7 +159,9 @@ static void layer_surface_destroy(struct wlr_layer_surface *surface) { wlr_signal_emit_safe(&surface->events.destroy, surface); wl_resource_set_user_data(surface->resource, NULL); wl_list_remove(&surface->surface_destroy_listener.link); + wl_list_init(&surface->surface_destroy_listener.link); wlr_surface_set_role_committed(surface->surface, NULL, NULL); + wl_list_remove(&surface->link); free(surface); } @@ -343,6 +345,7 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, surface, surface->resource); wl_resource_set_implementation(surface->resource, &layer_surface_implementation, surface, layer_surface_resource_destroy); + wl_list_insert(&shell->surfaces, &surface->link); } static const struct zwlr_layer_shell_v1_interface layer_shell_implementation = { @@ -350,6 +353,11 @@ static const struct zwlr_layer_shell_v1_interface layer_shell_implementation = { }; static void client_handle_destroy(struct wl_resource *resource) { + struct wlr_layer_shell *shell = layer_shell_from_resource(resource); + struct wlr_layer_surface *surface, *tmp = NULL; + wl_list_for_each_safe(surface, tmp, &shell->surfaces, link) { + layer_surface_destroy(surface); + } wl_list_remove(wl_resource_get_link(resource)); } @@ -384,6 +392,7 @@ struct wlr_layer_shell *wlr_layer_shell_create(struct wl_display *display) { } wl_list_init(&layer_shell->client_resources); + wl_list_init(&layer_shell->surfaces); struct wl_global *wl_global = wl_global_create(display, &zwlr_layer_shell_v1_interface, 1, layer_shell, layer_shell_bind); -- cgit v1.2.3 From 865b0aa123172852b49df4178437e6e8a020bc60 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 30 Mar 2018 11:01:23 -0400 Subject: xwayland: rename map_notify to map for consistency --- include/rootston/view.h | 4 ++-- include/wlr/xwayland.h | 4 ++-- rootston/cursor.c | 1 - rootston/xwayland.c | 20 ++++++++++---------- xwayland/xwm.c | 9 ++++----- 5 files changed, 18 insertions(+), 20 deletions(-) (limited to 'include/wlr') diff --git a/include/rootston/view.h b/include/rootston/view.h index 6e746e8c..4e3859d5 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -64,8 +64,8 @@ struct roots_xwayland_surface { struct wl_listener request_resize; struct wl_listener request_maximize; struct wl_listener request_fullscreen; - struct wl_listener map_notify; - struct wl_listener unmap_notify; + struct wl_listener map; + struct wl_listener unmap; struct wl_listener surface_commit; }; diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index f34860aa..1ee310ea 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -126,8 +126,8 @@ struct wlr_xwayland_surface { struct wl_signal request_maximize; struct wl_signal request_fullscreen; - struct wl_signal map_notify; - struct wl_signal unmap_notify; + struct wl_signal map; + struct wl_signal unmap; struct wl_signal set_title; struct wl_signal set_class; struct wl_signal set_parent; diff --git a/rootston/cursor.c b/rootston/cursor.c index a5953e4a..c794cbce 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -426,7 +426,6 @@ void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor, return; } - wlr_log(L_DEBUG, "Setting client cursor"); wlr_cursor_set_surface(cursor->cursor, event->surface, event->hotspot_x, event->hotspot_y); cursor->cursor_client = event->seat_client->client; diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 53331b1f..92f37362 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -114,8 +114,8 @@ static void destroy(struct roots_view *view) { wl_list_remove(&roots_surface->request_move.link); wl_list_remove(&roots_surface->request_resize.link); wl_list_remove(&roots_surface->request_maximize.link); - wl_list_remove(&roots_surface->map_notify.link); - wl_list_remove(&roots_surface->unmap_notify.link); + wl_list_remove(&roots_surface->map.link); + wl_list_remove(&roots_surface->unmap.link); free(roots_surface); } @@ -225,9 +225,9 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { view_update_position(view, x, y); } -static void handle_map_notify(struct wl_listener *listener, void *data) { +static void handle_map(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = - wl_container_of(listener, roots_surface, map_notify); + wl_container_of(listener, roots_surface, map); struct wlr_xwayland_surface *xsurface = data; struct roots_view *view = roots_surface->view; @@ -243,9 +243,9 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { &roots_surface->surface_commit); } -static void handle_unmap_notify(struct wl_listener *listener, void *data) { +static void handle_unmap(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = - wl_container_of(listener, roots_surface, unmap_notify); + wl_container_of(listener, roots_surface, unmap); struct roots_view *view = roots_surface->view; wl_list_remove(&roots_surface->surface_commit.link); @@ -272,10 +272,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { roots_surface->request_configure.notify = handle_request_configure; wl_signal_add(&surface->events.request_configure, &roots_surface->request_configure); - roots_surface->map_notify.notify = handle_map_notify; - wl_signal_add(&surface->events.map_notify, &roots_surface->map_notify); - roots_surface->unmap_notify.notify = handle_unmap_notify; - wl_signal_add(&surface->events.unmap_notify, &roots_surface->unmap_notify); + roots_surface->map.notify = handle_map; + wl_signal_add(&surface->events.map, &roots_surface->map); + roots_surface->unmap.notify = handle_unmap; + wl_signal_add(&surface->events.unmap, &roots_surface->unmap); roots_surface->request_move.notify = handle_request_move; wl_signal_add(&surface->events.request_move, &roots_surface->request_move); roots_surface->request_resize.notify = handle_request_resize; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 8911c553..2743cc53 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -107,8 +107,8 @@ static struct wlr_xwayland_surface *wlr_xwayland_surface_create( wl_signal_init(&surface->events.request_resize); wl_signal_init(&surface->events.request_maximize); wl_signal_init(&surface->events.request_fullscreen); - wl_signal_init(&surface->events.map_notify); - wl_signal_init(&surface->events.unmap_notify); + wl_signal_init(&surface->events.map); + wl_signal_init(&surface->events.unmap); wl_signal_init(&surface->events.set_class); wl_signal_init(&surface->events.set_title); wl_signal_init(&surface->events.set_parent); @@ -581,7 +581,7 @@ static void xwm_map_shell_surface(struct wlr_xwm *xwm, wl_signal_add(&surface->events.destroy, &xsurface->surface_destroy); xsurface->mapped = true; - wlr_signal_emit_safe(&xsurface->events.map_notify, xsurface); + wlr_signal_emit_safe(&xsurface->events.map, xsurface); } static void xwm_handle_create_notify(struct wlr_xwm *xwm, @@ -713,7 +713,7 @@ static void xwm_handle_unmap_notify(struct wlr_xwm *xwm, if (xsurface->mapped) { xsurface->mapped = false; - wlr_signal_emit_safe(&xsurface->events.unmap_notify, xsurface); + wlr_signal_emit_safe(&xsurface->events.unmap, xsurface); } xsurface_set_wm_state(xsurface, ICCCM_WITHDRAWN_STATE); @@ -1531,4 +1531,3 @@ bool xwm_atoms_contains(struct wlr_xwm *xwm, xcb_atom_t *atoms, return false; } - -- cgit v1.2.3 From 47a529a69c410e494fba46a4e6932a117728ba23 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 30 Mar 2018 12:31:16 -0400 Subject: output-damage: fix missing wlr_box include --- include/wlr/types/wlr_output_damage.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_output_damage.h b/include/wlr/types/wlr_output_damage.h index 6682f942..beba2f6c 100644 --- a/include/wlr/types/wlr_output_damage.h +++ b/include/wlr/types/wlr_output_damage.h @@ -3,6 +3,7 @@ #include #include +#include #include /** -- cgit v1.2.3 From e19ee6d469a98d2957e614243ea30674be1977f7 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Mar 2018 22:19:33 -0400 Subject: Add wlr_surface_point_accepts_input Ref https://github.com/swaywm/sway/pull/1674 --- include/wlr/types/wlr_surface.h | 3 +++ rootston/desktop.c | 14 ++------------ types/wlr_surface.c | 7 +++++++ 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index 5c5b012f..4d03df73 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -134,6 +134,9 @@ struct wlr_surface *wlr_surface_get_main_surface(struct wlr_surface *surface); struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface, double sx, double sy, double *sub_x, double *sub_y); +bool wlr_surface_point_accepts_input( + struct wlr_surface *surface, double sx, double sy); + void wlr_surface_send_enter(struct wlr_surface *surface, struct wlr_output *output); diff --git a/rootston/desktop.c b/rootston/desktop.c index 7ee2c69a..1d2e9549 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -622,9 +622,7 @@ static bool view_at(struct roots_view *view, double lx, double ly, return true; } - if (wlr_box_contains_point(&box, view_sx, view_sy) && - pixman_region32_contains_point(&view->wlr_surface->current->input, - view_sx, view_sy, NULL)) { + if (wlr_surface_point_accepts_input(view->wlr_surface, view_sx, view_sy)) { *sx = view_sx; *sy = view_sy; *surface = view->wlr_surface; @@ -668,16 +666,8 @@ static struct wlr_surface *layer_surface_at(struct roots_output *output, roots_surface->layer_surface->surface; double _sx = ox - roots_surface->geo.x; double _sy = oy - roots_surface->geo.y; - struct wlr_box box = { - .x = roots_surface->geo.x, - .y = roots_surface->geo.y, - .width = wlr_surface->current->width, - .height = wlr_surface->current->height, - }; // TODO: Test popups/subsurfaces - if (wlr_box_contains_point(&box, ox, oy) && - pixman_region32_contains_point(&wlr_surface->current->input, - _sx, _sy, NULL)) { + if (wlr_surface_point_accepts_input(wlr_surface, _sx, _sy)) { *sx = _sx; *sy = _sy; return wlr_surface; diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 672e6fea..e9bd6a66 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -952,3 +952,10 @@ void wlr_surface_set_role_committed(struct wlr_surface *surface, surface->role_committed = role_committed; surface->role_data = role_data; } + +bool wlr_surface_point_accepts_input( + struct wlr_surface *surface, double sx, double sy) { + return sx >= 0 && sx <= surface->current->width && + sy >= 0 && sy <= surface->current->height && + pixman_region32_contains_point(&surface->current->input, sx, sy, NULL); +} -- cgit v1.2.3 From 0a7a8cbd1c64e50978e846d8cf1bf8b1f6868655 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 30 Mar 2018 22:09:06 -0400 Subject: backend/x11: add WLR_X11_OUTPUTS support --- backend/backend.c | 67 ++++++++++++++++++++++++++++++++--------------- backend/x11/backend.c | 3 ++- backend/x11/output.c | 20 +++++++++++--- include/backend/x11.h | 7 ++--- include/wlr/backend/x11.h | 1 + 5 files changed, 69 insertions(+), 29 deletions(-) (limited to 'include/wlr') diff --git a/backend/backend.c b/backend/backend.c index 52344dac..ff5603bd 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -61,26 +61,48 @@ struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend) { return NULL; } +static int parse_outputs_env(const char *name) { + const char *outputs_str = getenv(name); + if (outputs_str == NULL) { + return 1; + } + + char *end; + int outputs = (int)strtol(outputs_str, &end, 10); + if (*end || outputs < 0) { + wlr_log(L_ERROR, "%s specified with invalid integer, ignoring", name); + return 1; + } + + return outputs; +} + static struct wlr_backend *attempt_wl_backend(struct wl_display *display) { struct wlr_backend *backend = wlr_wl_backend_create(display, NULL); - if (backend) { - int outputs = 1; - const char *_outputs = getenv("WLR_WL_OUTPUTS"); - if (_outputs) { - char *end; - outputs = (int)strtol(_outputs, &end, 10); - if (*end) { - wlr_log(L_ERROR, "WLR_WL_OUTPUTS specified with invalid integer, ignoring"); - outputs = 1; - } else if (outputs < 0) { - wlr_log(L_ERROR, "WLR_WL_OUTPUTS specified with negative outputs, ignoring"); - outputs = 1; - } - } - while (outputs--) { - wlr_wl_output_create(backend); - } + if (backend == NULL) { + return NULL; + } + + int outputs = parse_outputs_env("WLR_WL_OUTPUTS"); + for (int i = 0; i < outputs; ++i) { + wlr_wl_output_create(backend); } + + return backend; +} + +static struct wlr_backend *attempt_x11_backend(struct wl_display *display, + const char *x11_display) { + struct wlr_backend *backend = wlr_x11_backend_create(display, x11_display); + if (backend == NULL) { + return NULL; + } + + int outputs = parse_outputs_env("WLR_X11_OUTPUTS"); + for (int i = 0; i < outputs; ++i) { + wlr_x11_output_create(backend); + } + return backend; } @@ -91,7 +113,8 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { return NULL; } - if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY")) { + if (getenv("WAYLAND_DISPLAY") || getenv("_WAYLAND_DISPLAY") || + getenv("WAYLAND_SOCKET")) { struct wlr_backend *wl_backend = attempt_wl_backend(display); if (wl_backend) { wlr_multi_backend_add(backend, wl_backend); @@ -103,9 +126,11 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) { const char *x11_display = getenv("DISPLAY"); if (x11_display) { struct wlr_backend *x11_backend = - wlr_x11_backend_create(display, x11_display); - wlr_multi_backend_add(backend, x11_backend); - return backend; + attempt_x11_backend(display, x11_display); + if (x11_backend) { + wlr_multi_backend_add(backend, x11_backend); + return backend; + } } #endif diff --git a/backend/x11/backend.c b/backend/x11/backend.c index c72cdcac..80998f3f 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -96,6 +96,7 @@ static int x11_event(int fd, uint32_t mask, void *data) { static bool wlr_x11_backend_start(struct wlr_backend *backend) { struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; + x11->started = true; struct { const char *name; @@ -167,7 +168,7 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { wlr_signal_emit_safe(&x11->backend.events.new_input, &x11->pointer_dev); for (size_t i = 0; i < x11->requested_outputs; ++i) { - x11_output_create(x11); + wlr_x11_output_create(&x11->backend); } return true; diff --git a/backend/x11/output.c b/backend/x11/output.c index f039baad..9e7424d8 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -77,18 +78,29 @@ static const struct wlr_output_impl output_impl = { .swap_buffers = output_swap_buffers, }; -struct wlr_x11_output *x11_output_create(struct wlr_x11_backend *x11) { +struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) { + assert(wlr_backend_is_x11(backend)); + struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; + + if (!x11->started) { + ++x11->requested_outputs; + return NULL; + } + struct wlr_x11_output *output = calloc(1, sizeof(struct wlr_x11_output)); if (output == NULL) { return NULL; } output->x11 = x11; - output->frame_delay = 16; // 60 Hz struct wlr_output *wlr_output = &output->wlr_output; wlr_output_init(wlr_output, &x11->backend, &output_impl, x11->wl_display); - snprintf(wlr_output->name, sizeof(wlr_output->name), "X11-1"); + wlr_output->refresh = 60 * 1000000; + output->frame_delay = 16; // 60 Hz + + snprintf(wlr_output->name, sizeof(wlr_output->name), "X11-%d", + wl_list_length(&x11->outputs) + 1); parse_xcb_setup(wlr_output, x11->xcb_conn); uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; @@ -135,7 +147,7 @@ struct wlr_x11_output *x11_output_create(struct wlr_x11_backend *x11) { wl_list_insert(&x11->outputs, &output->link); wlr_signal_emit_safe(&x11->backend.events.new_output, wlr_output); - return output; + return wlr_output; } void x11_output_handle_configure_notify(struct wlr_x11_output *output, diff --git a/include/backend/x11.h b/include/backend/x11.h index 92a29725..aa058882 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -3,11 +3,12 @@ #include #include +#include +#include +#include #include #include #include -#include -#include #define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f @@ -28,6 +29,7 @@ struct wlr_x11_output { struct wlr_x11_backend { struct wlr_backend backend; struct wl_display *wl_display; + bool started; Display *xlib_conn; xcb_connection_t *xcb_conn; @@ -73,7 +75,6 @@ const struct wlr_input_device_impl input_device_impl; bool x11_handle_input_event(struct wlr_x11_backend *x11, xcb_generic_event_t *event); -struct wlr_x11_output *x11_output_create(struct wlr_x11_backend *x11); void x11_output_handle_configure_notify(struct wlr_x11_output *output, xcb_configure_notify_event_t *event); diff --git a/include/wlr/backend/x11.h b/include/wlr/backend/x11.h index b22d7f68..7bc1f891 100644 --- a/include/wlr/backend/x11.h +++ b/include/wlr/backend/x11.h @@ -9,6 +9,7 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, const char *x11_display); +struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend); bool wlr_backend_is_x11(struct wlr_backend *backend); bool wlr_input_device_is_x11(struct wlr_input_device *device); -- cgit v1.2.3 From 90fbab6f390da0e8f2b7f4b39b6766e4534467b7 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 00:35:08 -0400 Subject: xwyaland: fix style issues --- include/wlr/xwayland.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 1ee310ea..9b9d9cf9 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -166,21 +166,23 @@ void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland, int32_t hotspot_x, int32_t hotspot_y); void wlr_xwayland_surface_activate(struct wlr_xwayland_surface *surface, - bool activated); + bool activated); void wlr_xwayland_surface_configure(struct wlr_xwayland_surface *surface, - int16_t x, int16_t y, uint16_t width, uint16_t height); + int16_t x, int16_t y, uint16_t width, uint16_t height); void wlr_xwayland_surface_close(struct wlr_xwayland_surface *surface); void wlr_xwayland_surface_set_maximized(struct wlr_xwayland_surface *surface, - bool maximized); + bool maximized); void wlr_xwayland_surface_set_fullscreen(struct wlr_xwayland_surface *surface, - bool fullscreen); + bool fullscreen); void wlr_xwayland_set_seat(struct wlr_xwayland *xwayland, - struct wlr_seat *seat); + struct wlr_seat *seat); + +bool wlr_xwayland_surface_is_unmanaged( + const struct wlr_xwayland_surface *surface); -bool wlr_xwayland_surface_is_unmanaged(const struct wlr_xwayland_surface *surface); #endif -- cgit v1.2.3 From 33a2eb4b7775d1a3ab2b767739c1f1f054683d22 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 18:49:43 -0400 Subject: Untie wlr_backend from wlr_renderer --- backend/drm/renderer.c | 2 +- backend/headless/backend.c | 2 +- backend/wayland/backend.c | 2 +- backend/x11/backend.c | 2 +- examples/output-layout.c | 3 ++- examples/rotation.c | 3 ++- examples/tablet.c | 3 ++- examples/touch.c | 3 ++- include/wlr/render/gles2.h | 3 ++- render/gles2/renderer.c | 5 ++--- 10 files changed, 16 insertions(+), 12 deletions(-) (limited to 'include/wlr') diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index c1531ce3..f06de1ee 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -31,7 +31,7 @@ bool wlr_drm_renderer_init(struct wlr_drm_backend *drm, goto error_gbm; } - renderer->wlr_rend = wlr_gles2_renderer_create(&drm->backend); + renderer->wlr_rend = wlr_gles2_renderer_create(&renderer->egl); if (!renderer->wlr_rend) { wlr_log(L_ERROR, "Failed to create WLR renderer"); goto error_egl; diff --git a/backend/headless/backend.c b/backend/headless/backend.c index 663bc13b..5bc48240 100644 --- a/backend/headless/backend.c +++ b/backend/headless/backend.c @@ -114,7 +114,7 @@ struct wlr_backend *wlr_headless_backend_create(struct wl_display *display) { return NULL; } - backend->renderer = wlr_gles2_renderer_create(&backend->backend); + backend->renderer = wlr_gles2_renderer_create(&backend->egl); if (backend->renderer == NULL) { wlr_log(L_ERROR, "Failed to create renderer"); } diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index abb25df5..0135f7c5 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -212,7 +212,7 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_display *display, const char backend->remote_display, NULL, WL_SHM_FORMAT_ARGB8888); wlr_egl_bind_display(&backend->egl, backend->local_display); - backend->renderer = wlr_gles2_renderer_create(&backend->backend); + backend->renderer = wlr_gles2_renderer_create(&backend->egl); if (backend->renderer == NULL) { wlr_log_errno(L_ERROR, "Could not create renderer"); } diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 90658f26..f598aea1 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -314,7 +314,7 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, goto error_event; } - x11->renderer = wlr_gles2_renderer_create(&x11->backend); + x11->renderer = wlr_gles2_renderer_create(&x11->egl); if (x11->renderer == NULL) { wlr_log(L_ERROR, "Failed to create renderer"); goto error_egl; diff --git a/examples/output-layout.c b/examples/output-layout.c index c1392a30..53aae7f0 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -196,7 +196,8 @@ int main(int argc, char *argv[]) { compositor.keyboard_key_cb = handle_keyboard_key; compositor_init(&compositor); - state.renderer = wlr_gles2_renderer_create(compositor.backend); + struct wlr_egl *egl = wlr_backend_get_egl(compositor.backend); + state.renderer = wlr_gles2_renderer_create(egl); state.cat_texture = wlr_texture_from_pixels(state.renderer, WL_SHM_FORMAT_ABGR8888, cat_tex.width * 4, cat_tex.width, cat_tex.height, cat_tex.pixel_data); diff --git a/examples/rotation.c b/examples/rotation.c index dfafeeca..37873797 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -137,7 +137,8 @@ int main(int argc, char *argv[]) { compositor.keyboard_key_cb = handle_keyboard_key; compositor_init(&compositor); - state.renderer = wlr_gles2_renderer_create(compositor.backend); + struct wlr_egl *egl = wlr_backend_get_egl(compositor.backend); + state.renderer = wlr_gles2_renderer_create(egl); if (!state.renderer) { wlr_log(L_ERROR, "Could not start compositor, OOM"); exit(EXIT_FAILURE); diff --git a/examples/tablet.c b/examples/tablet.c index be428f86..d80b4b2f 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -192,7 +192,8 @@ int main(int argc, char *argv[]) { }; compositor_init(&compositor); - state.renderer = wlr_gles2_renderer_create(compositor.backend); + struct wlr_egl *egl = wlr_backend_get_egl(compositor.backend); + state.renderer = wlr_gles2_renderer_create(egl); if (!state.renderer) { wlr_log(L_ERROR, "Could not start compositor, OOM"); exit(EXIT_FAILURE); diff --git a/examples/touch.c b/examples/touch.c index e9dcf29c..16024fc8 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -108,7 +108,8 @@ int main(int argc, char *argv[]) { }; compositor_init(&compositor); - state.renderer = wlr_gles2_renderer_create(compositor.backend); + struct wlr_egl *egl = wlr_backend_get_egl(compositor.backend); + state.renderer = wlr_gles2_renderer_create(egl); if (!state.renderer) { wlr_log(L_ERROR, "Could not start compositor, OOM"); exit(EXIT_FAILURE); diff --git a/include/wlr/render/gles2.h b/include/wlr/render/gles2.h index b3b43ab2..a59956bd 100644 --- a/include/wlr/render/gles2.h +++ b/include/wlr/render/gles2.h @@ -5,6 +5,7 @@ #include struct wlr_egl; -struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend); + +struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl); #endif diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index c8094847..77af0ab7 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -400,7 +399,7 @@ extern const GLchar tex_fragment_src_rgba[]; extern const GLchar tex_fragment_src_rgbx[]; extern const GLchar tex_fragment_src_external[]; -struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend) { +struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) { struct wlr_gles2_renderer *renderer = calloc(1, sizeof(struct wlr_gles2_renderer)); if (renderer == NULL) { @@ -408,7 +407,7 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend) { } wlr_renderer_init(&renderer->wlr_renderer, &renderer_impl); - renderer->egl = wlr_backend_get_egl(backend); + renderer->egl = egl; wlr_egl_make_current(renderer->egl, EGL_NO_SURFACE, NULL); renderer->exts_str = (const char*) glGetString(GL_EXTENSIONS); -- cgit v1.2.3 From a7bb48b404b4809532e81a5daa981c81279c863a Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 23:20:00 -0400 Subject: render/egl: add wlr_egl_create_image_from_wl_drm This allows external renderers and potential future GL-based renderers to re-use this function. --- include/wlr/render/egl.h | 20 +++++++++++----- include/wlr/render/wlr_texture.h | 2 +- render/egl.c | 40 ++++++++++++++++++++++++++++---- render/gles2/texture.c | 49 +++++++++++----------------------------- 4 files changed, 64 insertions(+), 47 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h index 20127e38..cca77870 100644 --- a/include/wlr/render/egl.h +++ b/include/wlr/render/egl.h @@ -28,21 +28,22 @@ struct wlr_egl { // TODO: Allocate and return a wlr_egl /** - * Initializes an egl context for the given platform and remote display. + * Initializes an EGL context for the given platform and remote display. * Will attempt to load all possibly required api functions. */ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display, EGLint *config_attribs, EGLint visual_id); /** - * Frees all related egl resources, makes the context not-current and + * Frees all related EGL resources, makes the context not-current and * unbinds a bound wayland display. */ void wlr_egl_finish(struct wlr_egl *egl); /** - * Binds the given display to the egl instance. - * This will allow clients to create egl surfaces from wayland ones and render to it. + * Binds the given display to the EGL instance. + * This will allow clients to create EGL surfaces from wayland ones and render + * to it. */ bool wlr_egl_bind_display(struct wlr_egl *egl, struct wl_display *local_display); @@ -53,7 +54,14 @@ bool wlr_egl_bind_display(struct wlr_egl *egl, struct wl_display *local_display) EGLSurface wlr_egl_create_surface(struct wlr_egl *egl, void *window); /** - * Creates an egl image from the given dmabuf attributes. Check usability + * Creates an EGL image from the given wl_drm buffer resource. + */ +EGLImageKHR wlr_egl_create_image_from_wl_drm(struct wlr_egl *egl, + struct wl_resource *data, EGLint *fmt, int *width, int *height, + bool *inverted_y); + +/** + * Creates an EGL image from the given dmabuf attributes. Check usability * of the dmabuf with wlr_egl_check_import_dmabuf once first. */ EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl, @@ -78,7 +86,7 @@ int wlr_egl_get_dmabuf_modifiers(struct wlr_egl *egl, int format, uint64_t **modifiers); /** - * Destroys an egl image created with the given wlr_egl. + * Destroys an EGL image created with the given wlr_egl. */ bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image); diff --git a/include/wlr/render/wlr_texture.h b/include/wlr/render/wlr_texture.h index ab361298..239fc51b 100644 --- a/include/wlr/render/wlr_texture.h +++ b/include/wlr/render/wlr_texture.h @@ -23,7 +23,7 @@ struct wlr_texture *wlr_texture_from_pixels(struct wlr_renderer *renderer, const void *data); /** - * Create a new texture from a wayland DRM resource. The returned texture is + * Create a new texture from a wl_drm resource. The returned texture is * immutable. */ struct wlr_texture *wlr_texture_from_wl_drm(struct wlr_renderer *renderer, diff --git a/render/egl.c b/render/egl.c index 3c005b24..a424e8e9 100644 --- a/render/egl.c +++ b/render/egl.c @@ -93,7 +93,8 @@ static void print_dmabuf_formats(struct wlr_egl *egl) { char str_formats[num * 5 + 1]; for (int i = 0; i < num; i++) { - snprintf(&str_formats[i*5], (num - i) * 5 + 1, "%.4s ", (char*)&formats[i]); + snprintf(&str_formats[i*5], (num - i) * 5 + 1, "%.4s ", + (char*)&formats[i]); } wlr_log(L_DEBUG, "Supported dmabuf buffer formats: %s", str_formats); free(formats); @@ -230,8 +231,9 @@ bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImage image) { } EGLSurface wlr_egl_create_surface(struct wlr_egl *egl, void *window) { - EGLSurface surf = eglCreatePlatformWindowSurfaceEXT(egl->display, egl->config, - window, NULL); + assert(eglCreatePlatformWindowSurfaceEXT); + EGLSurface surf = eglCreatePlatformWindowSurfaceEXT(egl->display, + egl->config, window, NULL); if (surf == EGL_NO_SURFACE) { wlr_log(L_ERROR, "Failed to create EGL surface"); return EGL_NO_SURFACE; @@ -302,7 +304,37 @@ bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface, return true; } -EGLImage wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl, +EGLImageKHR wlr_egl_create_image_from_wl_drm(struct wlr_egl *egl, + struct wl_resource *data, EGLint *fmt, int *width, int *height, + bool *inverted_y) { + if (!eglQueryWaylandBufferWL || !eglCreateImageKHR) { + return NULL; + } + + if (!eglQueryWaylandBufferWL(egl->display, data, EGL_TEXTURE_FORMAT, fmt)) { + return NULL; + } + + eglQueryWaylandBufferWL(egl->display, data, EGL_WIDTH, width); + eglQueryWaylandBufferWL(egl->display, data, EGL_HEIGHT, height); + + EGLint _inverted_y; + if (eglQueryWaylandBufferWL(egl->display, data, EGL_WAYLAND_Y_INVERTED_WL, + &_inverted_y)) { + *inverted_y = !!_inverted_y; + } else { + *inverted_y = false; + } + + const EGLint attribs[] = { + EGL_WAYLAND_PLANE_WL, 0, + EGL_NONE, + }; + return eglCreateImageKHR(egl->display, egl->context, EGL_WAYLAND_BUFFER_WL, + data, attribs); +} + +EGLImageKHR wlr_egl_create_image_from_dmabuf(struct wlr_egl *egl, struct wlr_dmabuf_buffer_attribs *attributes) { bool has_modifier = false; if (attributes->modifier[0] != DRM_FORMAT_MOD_INVALID) { diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 82effd71..e4936d71 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -90,7 +90,7 @@ static void gles2_texture_destroy(struct wlr_texture *wlr_texture) { } if (texture->image) { assert(eglDestroyImageKHR); - eglDestroyImageKHR(texture->renderer->egl->display, texture->image); + wlr_egl_destroy_image(texture->renderer->egl, texture->image); } if (texture->type == WLR_GLES2_TEXTURE_GLTEX) { @@ -144,34 +144,17 @@ struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer, glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0); GLES2_DEBUG_POP; - return (struct wlr_texture *)texture; + return &texture->wlr_texture; } struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, struct wl_resource *data) { struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); - if (!eglQueryWaylandBufferWL || !eglCreateImageKHR || - !glEGLImageTargetTexture2DOES) { - return NULL; - } - - EGLint fmt; - if (!eglQueryWaylandBufferWL(renderer->egl->display, data, - EGL_TEXTURE_FORMAT, &fmt)) { + if (!glEGLImageTargetTexture2DOES) { return NULL; } - EGLint width, height; - eglQueryWaylandBufferWL(renderer->egl->display, data, EGL_WIDTH, &width); - eglQueryWaylandBufferWL(renderer->egl->display, data, EGL_HEIGHT, &height); - - EGLint inverted_y; - if (!eglQueryWaylandBufferWL(renderer->egl->display, data, - EGL_WAYLAND_Y_INVERTED_WL, &inverted_y)) { - inverted_y = 0; - } - struct wlr_gles2_texture *texture = calloc(1, sizeof(struct wlr_gles2_texture)); if (texture == NULL) { @@ -180,10 +163,15 @@ struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, } wlr_texture_init(&texture->wlr_texture, &texture_impl); texture->renderer = renderer; - texture->width = width; - texture->height = height; texture->wl_drm = data; - texture->inverted_y = !!inverted_y; + + EGLint fmt; + texture->image = wlr_egl_create_image_from_wl_drm(renderer->egl, data, &fmt, + &texture->width, &texture->height, &texture->inverted_y); + if (texture->image == NULL) { + free(texture); + return NULL; + } GLenum target; switch (fmt) { @@ -204,17 +192,6 @@ struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, return NULL; } - EGLint attribs[] = { - EGL_WAYLAND_PLANE_WL, 0, - EGL_NONE, - }; - texture->image = eglCreateImageKHR(renderer->egl->display, - renderer->egl->context, EGL_WAYLAND_BUFFER_WL, data, attribs); - if (texture->image == NULL) { - free(texture); - return NULL; - } - GLES2_DEBUG_PUSH; glGenTextures(1, &texture->image_tex); @@ -222,7 +199,7 @@ struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, glEGLImageTargetTexture2DOES(target, texture->image); GLES2_DEBUG_POP; - return (struct wlr_texture *)texture; + return &texture->wlr_texture; } struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, @@ -267,5 +244,5 @@ struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, texture->image); GLES2_DEBUG_POP; - return (struct wlr_texture *)texture; + return &texture->wlr_texture; } -- cgit v1.2.3 From 5a47da1ea6aa2227b82fb12a89c68aa8c9c2cbc9 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 1 Apr 2018 00:17:27 -0400 Subject: annotate wlr-output-layout coord variables --- include/wlr/types/wlr_output_layout.h | 25 +++++++------- types/wlr_output_layout.c | 62 +++++++++++++++++------------------ 2 files changed, 44 insertions(+), 43 deletions(-) (limited to 'include/wlr') diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h index 4d10720e..3c150fc0 100644 --- a/include/wlr/types/wlr_output_layout.h +++ b/include/wlr/types/wlr_output_layout.h @@ -40,41 +40,42 @@ struct wlr_output_layout_output *wlr_output_layout_get( struct wlr_output_layout *layout, struct wlr_output *reference); struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout, - double x, double y); + double lx, double ly); void wlr_output_layout_add(struct wlr_output_layout *layout, - struct wlr_output *output, int x, int y); + struct wlr_output *output, int lx, int ly); void wlr_output_layout_move(struct wlr_output_layout *layout, - struct wlr_output *output, int x, int y); + struct wlr_output *output, int lx, int ly); void wlr_output_layout_remove(struct wlr_output_layout *layout, struct wlr_output *output); /** - * Given x and y as pointers to global coordinates, adjusts them to local output + * Given x and y in layout coordinates, adjusts them to local output * coordinates relative to the given reference output. */ void wlr_output_layout_output_coords(struct wlr_output_layout *layout, - struct wlr_output *reference, double *x, double *y); + struct wlr_output *reference, double *lx, double *ly); bool wlr_output_layout_contains_point(struct wlr_output_layout *layout, - struct wlr_output *reference, int x, int y); + struct wlr_output *reference, int lx, int ly); bool wlr_output_layout_intersects(struct wlr_output_layout *layout, - struct wlr_output *reference, const struct wlr_box *target_box); + struct wlr_output *reference, const struct wlr_box *target_lbox); /** * Get the closest point on this layout from the given point from the reference * output. If reference is NULL, gets the closest point from the entire layout. */ void wlr_output_layout_closest_point(struct wlr_output_layout *layout, - struct wlr_output *reference, double x, double y, double *dest_x, - double *dest_y); + struct wlr_output *reference, double lx, double ly, double *dest_lx, + double *dest_ly); /** - * Get the box of the layout for the given reference output. If `reference` - * is NULL, the box will be for the extents of the entire layout. + * Get the box of the layout for the given reference output in layout + * coordinates. If `reference` is NULL, the box will be for the extents of the + * entire layout. */ struct wlr_box *wlr_output_layout_get_box( struct wlr_output_layout *layout, struct wlr_output *reference); @@ -109,6 +110,6 @@ enum wlr_direction { */ struct wlr_output *wlr_output_layout_adjacent_output( struct wlr_output_layout *layout, enum wlr_direction direction, - struct wlr_output *reference, double ref_x, double ref_y); + struct wlr_output *reference, double ref_lx, double ref_ly); #endif diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index fdeef387..1a06f71e 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -191,7 +191,7 @@ static struct wlr_output_layout_output *wlr_output_layout_output_create( } void wlr_output_layout_add(struct wlr_output_layout *layout, - struct wlr_output *output, int x, int y) { + struct wlr_output *output, int lx, int ly) { struct wlr_output_layout_output *l_output = wlr_output_layout_get(layout, output); if (!l_output) { @@ -201,8 +201,8 @@ void wlr_output_layout_add(struct wlr_output_layout *layout, return; } } - l_output->x = x; - l_output->y = y; + l_output->x = lx; + l_output->y = ly; l_output->state->auto_configured = false; wlr_output_layout_reconfigure(layout); wlr_output_create_global(output); @@ -221,19 +221,19 @@ struct wlr_output_layout_output *wlr_output_layout_get( } bool wlr_output_layout_contains_point(struct wlr_output_layout *layout, - struct wlr_output *reference, int x, int y) { + struct wlr_output *reference, int lx, int ly) { if (reference) { struct wlr_output_layout_output *l_output = wlr_output_layout_get(layout, reference); struct wlr_box *box = wlr_output_layout_output_get_box(l_output); - return wlr_box_contains_point(box, x, y); + return wlr_box_contains_point(box, lx, ly); } else { - return !!wlr_output_layout_output_at(layout, x, y); + return !!wlr_output_layout_output_at(layout, lx, ly); } } bool wlr_output_layout_intersects(struct wlr_output_layout *layout, - struct wlr_output *reference, const struct wlr_box *target_box) { + struct wlr_output *reference, const struct wlr_box *target_lbox) { struct wlr_box out_box; if (reference == NULL) { @@ -241,7 +241,7 @@ bool wlr_output_layout_intersects(struct wlr_output_layout *layout, wl_list_for_each(l_output, &layout->outputs, link) { struct wlr_box *output_box = wlr_output_layout_output_get_box(l_output); - if (wlr_box_intersection(output_box, target_box, &out_box)) { + if (wlr_box_intersection(output_box, target_lbox, &out_box)) { return true; } } @@ -254,16 +254,16 @@ bool wlr_output_layout_intersects(struct wlr_output_layout *layout, } struct wlr_box *output_box = wlr_output_layout_output_get_box(l_output); - return wlr_box_intersection(output_box, target_box, &out_box); + return wlr_box_intersection(output_box, target_lbox, &out_box); } } struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout, - double x, double y) { + double lx, double ly) { struct wlr_output_layout_output *l_output; wl_list_for_each(l_output, &layout->outputs, link) { struct wlr_box *box = wlr_output_layout_output_get_box(l_output); - if (wlr_box_contains_point(box, x, y)) { + if (wlr_box_contains_point(box, lx, ly)) { return l_output->output; } } @@ -271,12 +271,12 @@ struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout, } void wlr_output_layout_move(struct wlr_output_layout *layout, - struct wlr_output *output, int x, int y) { + struct wlr_output *output, int lx, int ly) { struct wlr_output_layout_output *l_output = wlr_output_layout_get(layout, output); if (l_output) { - l_output->x = x; - l_output->y = y; + l_output->x = lx; + l_output->y = ly; l_output->state->auto_configured = false; wlr_output_layout_reconfigure(layout); } else { @@ -295,25 +295,25 @@ void wlr_output_layout_remove(struct wlr_output_layout *layout, } void wlr_output_layout_output_coords(struct wlr_output_layout *layout, - struct wlr_output *reference, double *x, double *y) { + struct wlr_output *reference, double *lx, double *ly) { assert(layout && reference); - double src_x = *x; - double src_y = *y; + double src_x = *lx; + double src_y = *ly; struct wlr_output_layout_output *l_output; wl_list_for_each(l_output, &layout->outputs, link) { if (l_output->output == reference) { - *x = src_x - (double)l_output->x; - *y = src_y - (double)l_output->y; + *lx = src_x - (double)l_output->x; + *ly = src_y - (double)l_output->y; return; } } } void wlr_output_layout_closest_point(struct wlr_output_layout *layout, - struct wlr_output *reference, double x, double y, double *dest_x, - double *dest_y) { - if (dest_x == NULL && dest_y == NULL) { + struct wlr_output *reference, double lx, double ly, double *dest_lx, + double *dest_ly) { + if (dest_lx == NULL && dest_ly == NULL) { return; } @@ -326,11 +326,11 @@ void wlr_output_layout_closest_point(struct wlr_output_layout *layout, double output_x, output_y, output_distance; struct wlr_box *box = wlr_output_layout_output_get_box(l_output); - wlr_box_closest_point(box, x, y, &output_x, &output_y); + wlr_box_closest_point(box, lx, ly, &output_x, &output_y); // calculate squared distance suitable for comparison output_distance = - (x - output_x) * (x - output_x) + (y - output_y) * (y - output_y); + (lx - output_x) * (lx - output_x) + (ly - output_y) * (ly - output_y); if (!isfinite(output_distance)) { output_distance = DBL_MAX; @@ -343,11 +343,11 @@ void wlr_output_layout_closest_point(struct wlr_output_layout *layout, } } - if (dest_x) { - *dest_x = min_x; + if (dest_lx) { + *dest_lx = min_x; } - if (dest_y) { - *dest_y = min_y; + if (dest_ly) { + *dest_ly = min_y; } } @@ -433,7 +433,7 @@ struct wlr_output *wlr_output_layout_get_center_output( struct wlr_output *wlr_output_layout_adjacent_output( struct wlr_output_layout *layout, enum wlr_direction direction, - struct wlr_output *reference, double ref_x, double ref_y) { + struct wlr_output *reference, double ref_lx, double ref_ly) { assert(reference); struct wlr_box *ref_box = wlr_output_layout_get_box(layout, reference); @@ -468,9 +468,9 @@ struct wlr_output *wlr_output_layout_adjacent_output( // calculate distance from the given reference point double x, y; wlr_output_layout_closest_point(layout, l_output->output, - ref_x, ref_y, &x, &y); + ref_lx, ref_ly, &x, &y); double distance = - (x - ref_x) * (x - ref_x) + (y - ref_y) * (y - ref_y); + (x - ref_lx) * (x - ref_lx) + (y - ref_ly) * (y - ref_ly); if (distance < min_distance) { min_distance = distance; closest_output = l_output->output; -- cgit v1.2.3 From f3f61bed3e055e7032466723afda33a56f585dc5 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 1 Apr 2018 16:07:50 -0400 Subject: Untie wlr_gles2_renderer and wlr_gles2_texture --- include/render/gles2.h | 15 ++------------- include/wlr/render/egl.h | 2 ++ include/wlr/render/gles2.h | 8 ++++++++ render/egl.c | 4 ++++ render/gles2/renderer.c | 33 +++++++++++++++++++++++++++++---- render/gles2/texture.c | 31 +++++++++++++++---------------- 6 files changed, 60 insertions(+), 33 deletions(-) (limited to 'include/wlr') diff --git a/include/render/gles2.h b/include/render/gles2.h index 32cb3221..50252027 100644 --- a/include/render/gles2.h +++ b/include/render/gles2.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -49,7 +50,7 @@ enum wlr_gles2_texture_type { struct wlr_gles2_texture { struct wlr_texture wlr_texture; - struct wlr_gles2_renderer *renderer; + struct wlr_egl *egl; enum wlr_gles2_texture_type type; int width, height; bool has_alpha; @@ -68,20 +69,8 @@ struct wlr_gles2_texture { const struct gles2_pixel_format *gles2_format_from_wl(enum wl_shm_format fmt); const enum wl_shm_format *gles2_formats(size_t *len); -struct wlr_gles2_renderer *gles2_get_renderer( - struct wlr_renderer *wlr_renderer); -struct wlr_gles2_renderer *gles2_get_renderer_in_context( - struct wlr_renderer *wlr_renderer); - struct wlr_gles2_texture *gles2_get_texture_in_context( struct wlr_texture *wlr_texture); -struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer, - enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height, - const void *data); -struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, - struct wl_resource *data); -struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, - struct wlr_dmabuf_buffer_attribs *attribs); void gles2_push_marker(const char *file, const char *func); void gles2_pop_marker(void); diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h index cca77870..51f63b20 100644 --- a/include/wlr/render/egl.h +++ b/include/wlr/render/egl.h @@ -93,6 +93,8 @@ bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image); bool wlr_egl_make_current(struct wlr_egl *egl, EGLSurface surface, int *buffer_age); +bool wlr_egl_is_current(struct wlr_egl *egl); + bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface, pixman_region32_t *damage); diff --git a/include/wlr/render/gles2.h b/include/wlr/render/gles2.h index a59956bd..65bb36c1 100644 --- a/include/wlr/render/gles2.h +++ b/include/wlr/render/gles2.h @@ -8,4 +8,12 @@ struct wlr_egl; struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl); +struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl, + enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height, + const void *data); +struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl, + struct wl_resource *data); +struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl, + struct wlr_dmabuf_buffer_attribs *attribs); + #endif diff --git a/render/egl.c b/render/egl.c index a424e8e9..473d1319 100644 --- a/render/egl.c +++ b/render/egl.c @@ -270,6 +270,10 @@ bool wlr_egl_make_current(struct wlr_egl *egl, EGLSurface surface, return true; } +bool wlr_egl_is_current(struct wlr_egl *egl) { + return eglGetCurrentContext() == egl->context; +} + bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface, pixman_region32_t *damage) { EGLBoolean ret; diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 77af0ab7..b8bce98d 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -16,16 +16,16 @@ static const struct wlr_renderer_impl renderer_impl; -struct wlr_gles2_renderer *gles2_get_renderer( +static struct wlr_gles2_renderer *gles2_get_renderer( struct wlr_renderer *wlr_renderer) { assert(wlr_renderer->impl == &renderer_impl); return (struct wlr_gles2_renderer *)wlr_renderer; } -struct wlr_gles2_renderer *gles2_get_renderer_in_context( +static struct wlr_gles2_renderer *gles2_get_renderer_in_context( struct wlr_renderer *wlr_renderer) { struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); - assert(eglGetCurrentContext() == renderer->egl->context); + assert(wlr_egl_is_current(renderer->egl)); return renderer; } @@ -252,11 +252,32 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer, return true; } -static bool gles2_format_supported(struct wlr_renderer *r, +static bool gles2_format_supported(struct wlr_renderer *wlr_renderer, enum wl_shm_format wl_fmt) { return gles2_format_from_wl(wl_fmt) != NULL; } +static struct wlr_texture *gles2_texture_from_pixels( + struct wlr_renderer *wlr_renderer, enum wl_shm_format wl_fmt, + uint32_t stride, uint32_t width, uint32_t height, const void *data) { + struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); + return wlr_gles2_texture_from_pixels(renderer->egl, wl_fmt, stride, width, + height, data); +} + +static struct wlr_texture *gles2_texture_from_wl_drm( + struct wlr_renderer *wlr_renderer, struct wl_resource *data) { + struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); + return wlr_gles2_texture_from_wl_drm(renderer->egl, data); +} + +static struct wlr_texture *gles2_texture_from_dmabuf( + struct wlr_renderer *wlr_renderer, + struct wlr_dmabuf_buffer_attribs *attribs) { + struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); + return wlr_gles2_texture_from_dmabuf(renderer->egl, attribs); +} + static void gles2_destroy(struct wlr_renderer *wlr_renderer) { struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); @@ -400,6 +421,10 @@ extern const GLchar tex_fragment_src_rgbx[]; extern const GLchar tex_fragment_src_external[]; struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) { + if (!load_glapi()) { + return NULL; + } + struct wlr_gles2_renderer *renderer = calloc(1, sizeof(struct wlr_gles2_renderer)); if (renderer == NULL) { diff --git a/render/gles2/texture.c b/render/gles2/texture.c index e4936d71..45169daf 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -25,7 +25,7 @@ static struct wlr_gles2_texture *gles2_get_texture( struct wlr_gles2_texture *gles2_get_texture_in_context( struct wlr_texture *wlr_texture) { struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); - assert(eglGetCurrentContext() == texture->renderer->egl->context); + assert(wlr_egl_is_current(texture->egl)); return texture; } @@ -81,7 +81,7 @@ static void gles2_texture_destroy(struct wlr_texture *wlr_texture) { struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); - wlr_egl_make_current(texture->renderer->egl, EGL_NO_SURFACE, NULL); + wlr_egl_make_current(texture->egl, EGL_NO_SURFACE, NULL); GLES2_DEBUG_PUSH; @@ -90,7 +90,7 @@ static void gles2_texture_destroy(struct wlr_texture *wlr_texture) { } if (texture->image) { assert(eglDestroyImageKHR); - wlr_egl_destroy_image(texture->renderer->egl, texture->image); + wlr_egl_destroy_image(texture->egl, texture->image); } if (texture->type == WLR_GLES2_TEXTURE_GLTEX) { @@ -108,11 +108,10 @@ static const struct wlr_texture_impl texture_impl = { .destroy = gles2_texture_destroy, }; -struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer, +struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl, enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height, const void *data) { - struct wlr_gles2_renderer *renderer = - gles2_get_renderer_in_context(wlr_renderer); + assert(wlr_egl_is_current(egl)); const struct gles2_pixel_format *fmt = gles2_format_from_wl(wl_fmt); if (fmt == NULL) { @@ -127,7 +126,7 @@ struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer, return NULL; } wlr_texture_init(&texture->wlr_texture, &texture_impl); - texture->renderer = renderer; + texture->egl = egl; texture->width = width; texture->height = height; texture->type = WLR_GLES2_TEXTURE_GLTEX; @@ -147,9 +146,9 @@ struct wlr_texture *gles2_texture_from_pixels(struct wlr_renderer *wlr_renderer, return &texture->wlr_texture; } -struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, +struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl, struct wl_resource *data) { - struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); + assert(wlr_egl_is_current(egl)); if (!glEGLImageTargetTexture2DOES) { return NULL; @@ -162,11 +161,11 @@ struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, return NULL; } wlr_texture_init(&texture->wlr_texture, &texture_impl); - texture->renderer = renderer; + texture->egl = egl; texture->wl_drm = data; EGLint fmt; - texture->image = wlr_egl_create_image_from_wl_drm(renderer->egl, data, &fmt, + texture->image = wlr_egl_create_image_from_wl_drm(egl, data, &fmt, &texture->width, &texture->height, &texture->inverted_y); if (texture->image == NULL) { free(texture); @@ -202,15 +201,15 @@ struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer, return &texture->wlr_texture; } -struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, +struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl, struct wlr_dmabuf_buffer_attribs *attribs) { - struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); + assert(wlr_egl_is_current(egl)); if (!glEGLImageTargetTexture2DOES) { return NULL; } - if (!renderer->egl->egl_exts.dmabuf_import) { + if (!egl->egl_exts.dmabuf_import) { wlr_log(L_ERROR, "Cannot create DMA-BUF texture: EGL extension " "unavailable"); return NULL; @@ -223,7 +222,7 @@ struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, return NULL; } wlr_texture_init(&texture->wlr_texture, &texture_impl); - texture->renderer = renderer; + texture->egl = egl; texture->width = attribs->width; texture->height = attribs->height; texture->type = WLR_GLES2_TEXTURE_DMABUF; @@ -231,7 +230,7 @@ struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, texture->inverted_y = (attribs->flags & WLR_DMABUF_BUFFER_ATTRIBS_FLAGS_Y_INVERT) != 0; - texture->image = wlr_egl_create_image_from_dmabuf(renderer->egl, attribs); + texture->image = wlr_egl_create_image_from_dmabuf(egl, attribs); if (texture->image == NULL) { free(texture); return NULL; -- cgit v1.2.3