From 8836b167bf0ff152de951f7fdabb1deae85f6e93 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 13 Mar 2018 19:21:08 -0400 Subject: [PATCH 01/99] store xdg-positioner properties on the popup --- include/wlr/types/wlr_xdg_shell_v6.h | 60 ++++++++++++++++++++++++++++ types/wlr_xdg_shell_v6.c | 6 +++ 2 files changed, 66 insertions(+) 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 }; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index e07d78a1..c75e5857 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -537,6 +537,12 @@ static void xdg_surface_get_popup(struct wl_client *client, surface->popup_state->parent = parent; surface->popup_state->geometry = xdg_positioner_get_geometry(positioner, surface, parent); + + // positioner properties + surface->popup_state->anchor = (uint32_t)positioner->anchor; + surface->popup_state->gravity = (uint32_t)positioner->gravity; + surface->popup_state->constraint_adjustment = (uint32_t)positioner->constraint_adjustment; + wl_list_insert(&parent->popups, &surface->popup_state->link); wl_resource_set_implementation(surface->popup_state->resource, From c63d94483b1e52817ca01ca82a867a78ebd39fa6 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 24 Mar 2018 18:30:28 -0400 Subject: [PATCH 02/99] 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 | 46 +-- 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 | 75 ++-- include/wlr/types/wlr_linux_dmabuf.h | 13 +- render/egl.c | 18 - render/gles2/renderer.c | 122 +++--- render/gles2/texture.c | 542 +++++++++++---------------- 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 | 112 ++++-- types/wlr_xcursor_manager.c | 2 +- 24 files changed, 577 insertions(+), 647 deletions(-) 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), }; + 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->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(); + 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); -/** - * 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. - */ -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); -/** - * Copies pixels from a wl_shm_buffer into this texture. The buffer is not - * accessed after this function returns. - */ -bool wlr_texture_upload_shm(struct wlr_texture *tex, uint32_t format, - struct wl_shm_buffer *shm); -/** - * 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. - */ -bool wlr_texture_upload_drm(struct wlr_texture *tex, - struct wl_resource *drm_buffer); +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); -bool wlr_texture_upload_eglimage(struct wlr_texture *tex, - EGLImageKHR image, uint32_t width, uint32_t 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. + * Create a new texture from a wayland DRM resource. The returned texture is + * immutable. */ -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); +struct wlr_texture *wlr_texture_from_wl_drm(struct wlr_renderer *renderer, + struct wl_resource *data); + +/** + * Create a new texture from a DMA-BUF. The returned texture is immutable. + */ +struct wlr_texture *wlr_texture_from_dmabuf(struct wlr_renderer *renderer, + struct wlr_dmabuf_buffer_attribs *attribs); + +/** + * Get the texture width and height. + */ +void wlr_texture_get_size(struct wlr_texture *texture, int *width, int *height); + +/** + * Update a texture with raw pixels. The texture must be mutable. + */ +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; - } +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 = renderer->shaders.tex_rgba; - if (texture->target == GL_TEXTURE_EXTERNAL_OES) { + 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); - EGLint format; - return wlr_egl_query_buffer(renderer->egl, buffer, EGL_TEXTURE_FORMAT, - &format); + 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; + } + + 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); + *width = texture->width; + *height = texture->height; +} - // 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); +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 = texture->pixel_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; + } + + // TODO: what if the unpack subimage extension isn't supported? 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); + + glBindTexture(GL_TEXTURE_2D, texture->gl_tex); + + 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); + + glTexSubImage2D(GL_TEXTURE_2D, 0, dst_x, dst_y, width, height, + fmt->gl_format, fmt->gl_type, data); + + glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS_EXT, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, 0); + GLES2_DEBUG_POP; return true; } -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); - - 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); - 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; - - 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; -} - -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); - - // 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); - - 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_SKIP_PIXELS_EXT, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS_EXT, 0); - GLES2_DEBUG_POP; - - wl_shm_buffer_end_access(buffer); - - 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; - } - - 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; - } - - 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); - - 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; - } - - 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; - } - - 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 }; - - if (tex->image) { - wlr_egl_destroy_image(tex->egl, tex->image); - } - - 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; - } - - 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); - - tex->image = image; - tex->pixel_format = &external_pixel_format; - tex->wlr_texture.valid = true; - tex->wlr_texture.width = width; - tex->wlr_texture.height = height; - - 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; -} - -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); - - if (!tex->egl->egl_exts.dmabuf_import) { - wlr_log(L_ERROR, "Want dmabuf but extension not present"); - return false; - } - - tex->wlr_texture.width = dmabuf->attributes.width; - tex->wlr_texture.height = dmabuf->attributes.height; - - if (tex->image) { - wlr_egl_destroy_image(tex->egl, tex->image); - } - - if (wlr_dmabuf_buffer_has_inverted_y(dmabuf)) { - wlr_texture->inverted_y = true; - } - - GLenum target; - const struct gles2_pixel_format *pf; - if (dmabuf->attributes.n_planes > 1) { - target = GL_TEXTURE_EXTERNAL_OES; - pf = &external_pixel_format; - } else { - target = GL_TEXTURE_2D; - pf = gles2_format_from_wl(WL_SHM_FORMAT_ARGB8888); - } - 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; - } - - 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); - - return; - } - - *width = wl_shm_buffer_get_width(buffer); - *height = wl_shm_buffer_get_height(buffer); -} - static void gles2_texture_destroy(struct wlr_texture *wlr_texture) { + if (wlr_texture == NULL) { + return; + } + struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); - 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; + wlr_egl_make_current(texture->renderer->egl, EGL_NO_SURFACE, NULL); + + GLES2_DEBUG_PUSH; + + if (texture->image_tex) { + glDeleteTextures(1, &texture->image_tex); + } + if (texture->image) { + assert(eglDestroyImageKHR); + eglDestroyImageKHR(texture->renderer->egl->display, texture->image); } - if (texture->image) { - wlr_egl_destroy_image(texture->egl, texture->image); + if (texture->type == WLR_GLES2_TEXTURE_GLTEX) { + glDeleteTextures(1, &texture->gl_tex); } + GLES2_DEBUG_POP; + 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, + .get_size = gles2_texture_get_size, + .write_pixels = gles2_texture_write_pixels, .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_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; + } + + 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 = width; + texture->height = height; + texture->type = WLR_GLES2_TEXTURE_GLTEX; + texture->has_alpha = fmt->has_alpha; + + GLES2_DEBUG_PUSH; + + glGenTextures(1, &texture->gl_tex); + glBindTexture(GL_TEXTURE_2D, texture->gl_tex); + + 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_POP; + return (struct wlr_texture *)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)) { + 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) { + 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; + switch (fmt) { + case EGL_TEXTURE_RGB: + case EGL_TEXTURE_RGBA: + target = GL_TEXTURE_2D; + 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; + } + + 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); + glBindTexture(target, texture->image_tex); + glEGLImageTargetTexture2DOES(target, texture->image); + + GLES2_DEBUG_POP; + return (struct wlr_texture *)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); + + if (!glEGLImageTargetTexture2DOES) { + return NULL; + } + + if (!renderer->egl->egl_exts.dmabuf_import) { + wlr_log(L_ERROR, "Cannot create DMA-BUF texture: EGL extension " + "unavailable"); + return NULL; + } + + 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 = 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); +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_shm(struct wlr_texture *texture, uint32_t format, - struct wl_shm_buffer *shm) { - return texture->impl->upload_shm(texture, format, shm); +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_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); +void wlr_texture_get_size(struct wlr_texture *texture, int *width, + int *height) { + return texture->impl->get_size(texture, width, height); } -bool wlr_texture_upload_drm(struct wlr_texture *texture, - struct wl_resource *drm_buffer) { - return texture->impl->upload_drm(texture, drm_buffer); -} - -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); -} - -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_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; + + 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 { - wlr_log(L_INFO, "Unknown buffer handle attached"); - return; - } - } + 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); - 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; + 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); } From 3bda7e2ef8db955bb56e9dbf700974de06a2836b Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 26 Mar 2018 12:00:08 -0400 Subject: [PATCH 03/99] Use DRM_FORMAT_MOD_LINEAR instead of a hardcoded constant --- backend/drm/renderer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 2b50bb79..c1531ce3 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -14,6 +14,10 @@ #include "backend/drm/drm.h" #include "glapi.h" +#ifndef DRM_FORMAT_MOD_LINEAR +#define DRM_FORMAT_MOD_LINEAR 0 +#endif + bool wlr_drm_renderer_init(struct wlr_drm_backend *drm, struct wlr_drm_renderer *renderer) { renderer->gbm = gbm_create_device(drm->fd); @@ -195,7 +199,7 @@ static struct wlr_texture *get_tex_for_bo(struct wlr_drm_renderer *renderer, }; attribs.offset[0] = 0; attribs.stride[0] = gbm_bo_get_stride_for_plane(bo, 0); - attribs.modifier[0] = 0; + attribs.modifier[0] = DRM_FORMAT_MOD_LINEAR; attribs.fd[0] = gbm_bo_get_fd(bo); tex->tex = wlr_texture_from_dmabuf(renderer->wlr_rend, &attribs); From 4da18f7fc361bcde631249268320c9f1e4ef7c7c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 26 Mar 2018 12:46:04 -0400 Subject: [PATCH 04/99] 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(-) 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); From 5233801530c5ccc95699a12ba7da2d7ce58c952c Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 26 Mar 2018 18:35:36 -0400 Subject: [PATCH 05/99] 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(-) 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 && + surface->popup->seat != NULL) { + 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) { - wl_resource_set_user_data(surface->popup->resource, NULL); + wl_list_remove(&surface->popup->grab_link); - if (surface->popup->seat) { - 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); - } + 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); } } From 334bab543d6688769a86374a1ddd3d3b36e619b4 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 26 Mar 2018 19:32:21 -0400 Subject: [PATCH 06/99] 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 | 81 +++++++++++++++------------- 3 files changed, 63 insertions(+), 53 deletions(-) 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); + 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); + 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); + } } + + 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); From bbd0e23fa79ec39c872c09e49d09a9ccbda68bcd Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 26 Mar 2018 23:48:32 -0400 Subject: [PATCH 07/99] 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(-) 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; + } +} From 171e28eaff6e3699a98b828b6430b844d54f624d Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 27 Mar 2018 10:25:02 -0400 Subject: [PATCH 08/99] 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(-) 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); From 8371e2f41dbcb8d3ae42a4fb386577d97301ac5a Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 27 Mar 2018 14:49:31 -0400 Subject: [PATCH 09/99] implement flip_x --- include/wlr/types/wlr_xdg_shell_v6.h | 8 +- rootston/xdg_shell_v6.c | 123 ++++++++++++++++----------- types/wlr_xdg_shell_v6.c | 81 ++++++++---------- 3 files changed, 115 insertions(+), 97 deletions(-) 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,6 +38,77 @@ 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_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_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); + 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); + + struct wlr_output *output = + wlr_output_layout_output_at(layout, dest_x, dest_y); + // XXX: handle empty output layout + assert(output); + + struct wlr_box *output_box = wlr_output_layout_get_box(layout, output); + *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 (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 = @@ -45,55 +116,6 @@ 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); @@ -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; - - 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; +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; } - 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; + 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; + } +} + +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; } } From 9ff84db06d44aed7188cb574a6e877d93a12e8df Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 27 Mar 2018 15:13:35 -0400 Subject: [PATCH 10/99] unconstrain stubs --- rootston/xdg_shell_v6.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 0a698e50..60e2b541 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -103,10 +103,34 @@ static void popup_unconstrain_flip(struct roots_xdg_popup_v6 *popup) { wlr_xdg_positioner_v6_get_geometry(&popup->wlr_popup->positioner); } +static void popup_unconstrain_slide(struct roots_xdg_popup_v6 *popup) { + bool x_constrained, y_constrained; + popup_is_constrained(popup, &x_constrained, &y_constrained); + + if (x_constrained) { + // TODO slide_x + } + if (y_constrained) { + // TODO slide_y + } +} + +static void popup_unconstrain_resize(struct roots_xdg_popup_v6 *popup) { + bool x_constrained, y_constrained; + popup_is_constrained(popup, &x_constrained, &y_constrained); + + if (x_constrained) { + // TODO resize_x + } + if (y_constrained) { + // TODO resize_y + } +} + static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) { popup_unconstrain_flip(popup); - // TODO popup_unconstrain_slide(popup); - // TODO popup_unconstrain_resize(popup); + popup_unconstrain_slide(popup); + popup_unconstrain_resize(popup); } static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, From c42fd1018b037f20c5045fb3cbf39ac35ec980c6 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 27 Mar 2018 17:02:48 -0400 Subject: [PATCH 11/99] 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(-) 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); From edb643fc6c55b47dd766b4e516b16108719d1ecd Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 27 Mar 2018 17:16:08 -0400 Subject: [PATCH 12/99] basic xdg-positioner --- rootston/xdg_shell_v6.c | 101 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 8 deletions(-) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 60e2b541..f5cb2cd7 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -92,6 +92,26 @@ 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 (!x_constrained && !y_constrained) { + return; + } + + 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); + + popup_is_constrained(popup, &x_constrained, &y_constrained); + + if (!x_constrained && !y_constrained) { + return; + } + if (x_constrained) { wlr_positioner_v6_invert_x(&popup->wlr_popup->positioner); } @@ -104,26 +124,91 @@ static void popup_unconstrain_flip(struct roots_xdg_popup_v6 *popup) { } static void popup_unconstrain_slide(struct roots_xdg_popup_v6 *popup) { - bool x_constrained, y_constrained; - popup_is_constrained(popup, &x_constrained, &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_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); + 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); + + struct wlr_output *output = + wlr_output_layout_output_at(layout, dest_x, dest_y); + // XXX: handle empty output layout + assert(output); + + struct wlr_box *output_box = wlr_output_layout_get_box(layout, output); + + bool x_constrained = popup_lx <= output_box->x || + popup_lx + popup_width >= output_box->x + output_box->width; + bool y_constrained = popup_ly <= output_box->y || + popup_ly + popup_height >= output_box->y + output_box->height; + + double popup_ox = popup_lx - output_box->x, + popup_oy = popup_ly - output_box->y; if (x_constrained) { - // TODO slide_x + wlr_popup->geometry.x -= popup_width - (output_box->width - popup_ox); } if (y_constrained) { - // TODO slide_y + wlr_popup->geometry.y -= popup_height - (output_box->height - popup_oy); } } static void popup_unconstrain_resize(struct roots_xdg_popup_v6 *popup) { - bool x_constrained, y_constrained; - popup_is_constrained(popup, &x_constrained, &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_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); + 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); + + struct wlr_output *output = + wlr_output_layout_output_at(layout, dest_x, dest_y); + // XXX: handle empty output layout + assert(output); + + struct wlr_box *output_box = wlr_output_layout_get_box(layout, output); + + bool x_constrained = popup_lx <= output_box->x || + popup_lx + popup_width >= output_box->x + output_box->width; + bool y_constrained = popup_ly <= output_box->y || + popup_ly + popup_height >= output_box->y + output_box->height; + + double popup_ox = popup_lx - output_box->x, popup_oy = popup_ly - output_box->y; if (x_constrained) { - // TODO resize_x + wlr_popup->geometry.width = output_box->x + output_box->width - popup_ox; } if (y_constrained) { - // TODO resize_y + wlr_popup->geometry.height = output_box->y + output_box->height - popup_oy; } } From 19a525f3b51ed16d400d92fe27553967833f85d9 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 26 Mar 2018 19:02:28 -0400 Subject: [PATCH 13/99] rootston: damage view when zxdg-popup-v6 is mapped/unmapped --- include/rootston/view.h | 2 ++ rootston/xdg_shell_v6.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/rootston/view.h b/include/rootston/view.h index 775f3d11..1fd7353a 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -177,6 +177,8 @@ struct roots_xdg_popup_v6 { struct roots_view_child view_child; struct wlr_xdg_popup_v6 *wlr_popup; struct wl_listener destroy; + struct wl_listener map; + struct wl_listener unmap; struct wl_listener new_popup; }; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 001232ab..8d1a340e 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -28,6 +28,18 @@ static void popup_handle_destroy(struct wl_listener *listener, void *data) { popup_destroy((struct roots_view_child *)popup); } +static void popup_handle_map(struct wl_listener *listener, void *data) { + struct roots_xdg_popup_v6 *popup = + wl_container_of(listener, popup, map); + view_damage_whole(popup->view_child.view); +} + +static void popup_handle_unmap(struct wl_listener *listener, void *data) { + struct roots_xdg_popup_v6 *popup = + wl_container_of(listener, popup, unmap); + view_damage_whole(popup->view_child.view); +} + static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, struct wlr_xdg_popup_v6 *wlr_popup); @@ -50,6 +62,10 @@ static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, view_child_init(&popup->view_child, view, wlr_popup->base->surface); popup->destroy.notify = popup_handle_destroy; wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy); + popup->map.notify = popup_handle_map; + wl_signal_add(&wlr_popup->base->events.map, &popup->map); + popup->unmap.notify = popup_handle_unmap; + wl_signal_add(&wlr_popup->base->events.unmap, &popup->unmap); popup->new_popup.notify = popup_handle_new_popup; wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup); return popup; From 4abca435cc1ca9d89c077f0d06419696213a36c4 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 27 Mar 2018 17:27:58 -0400 Subject: [PATCH 14/99] rootston: damage view when xdg-popup is mapped/unmapped --- include/rootston/view.h | 2 ++ rootston/xdg_shell.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/rootston/view.h b/include/rootston/view.h index 1fd7353a..1397a8d2 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -186,6 +186,8 @@ struct roots_xdg_popup { struct roots_view_child view_child; struct wlr_xdg_popup *wlr_popup; struct wl_listener destroy; + struct wl_listener map; + struct wl_listener unmap; struct wl_listener new_popup; }; diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c index 099e622c..923fbeb4 100644 --- a/rootston/xdg_shell.c +++ b/rootston/xdg_shell.c @@ -28,6 +28,16 @@ static void popup_handle_destroy(struct wl_listener *listener, void *data) { popup_destroy((struct roots_view_child *)popup); } +static void popup_handle_map(struct wl_listener *listener, void *data) { + struct roots_xdg_popup *popup = wl_container_of(listener, popup, map); + view_damage_whole(popup->view_child.view); +} + +static void popup_handle_unmap(struct wl_listener *listener, void *data) { + struct roots_xdg_popup *popup = wl_container_of(listener, popup, unmap); + view_damage_whole(popup->view_child.view); +} + static struct roots_xdg_popup *popup_create(struct roots_view *view, struct wlr_xdg_popup *wlr_popup); @@ -50,6 +60,10 @@ static struct roots_xdg_popup *popup_create(struct roots_view *view, view_child_init(&popup->view_child, view, wlr_popup->base->surface); popup->destroy.notify = popup_handle_destroy; wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy); + popup->map.notify = popup_handle_map; + wl_signal_add(&wlr_popup->base->events.map, &popup->map); + popup->unmap.notify = popup_handle_unmap; + wl_signal_add(&wlr_popup->base->events.unmap, &popup->unmap); popup->new_popup.notify = popup_handle_new_popup; wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup); return popup; From f29d8b55aec7c19fd12b81b39e6806d6b996fadc Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 17 Mar 2018 15:07:48 -0400 Subject: [PATCH 15/99] 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 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); +} From 3ba57fccd1f0c66b9cbf3d70e73776b11c405ee8 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 17 Mar 2018 19:03:52 -0400 Subject: [PATCH 16/99] 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(-) 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); From b06105b564541680ef2feb27eef626aaca4852c0 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 17 Mar 2018 19:11:14 -0400 Subject: [PATCH 17/99] 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(-) 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); From 4a8c0c078445184a5d14725a0fb6df0cfc7ca5c9 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 17 Mar 2018 19:17:28 -0400 Subject: [PATCH 18/99] Destroy layer surfaces when client is destroyed --- types/wlr_layer_shell.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 055578bd..709d3cbc 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -235,7 +235,10 @@ static struct zwlr_layer_shell_v1_interface layer_shell_impl = { static void wlr_layer_client_destroy(struct wl_resource *resource) { struct wlr_layer_client *client = layer_client_from_resource(resource); - // TODO: Destroy surfaces + 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); From 1628730b09448c596c14f948fce53677980337ce Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 17 Mar 2018 21:06:54 -0400 Subject: [PATCH 19/99] 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(-) 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) { From 88eec637a44ede8b521c2aa44d0196c99dd5a0e3 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 18 Mar 2018 13:58:01 -0400 Subject: [PATCH 20/99] 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(-) 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,23 +76,30 @@ 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_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_popup(struct wl_client *client, @@ -100,19 +107,14 @@ static void layer_surface_handle_get_popup(struct wl_client *client, // 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, + .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); } From b31ce4220cea6acede2ae2af1b19a3a7d4b81fc6 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 18 Mar 2018 15:09:37 -0400 Subject: [PATCH 21/99] Add broken test client and rootston stubs --- examples/layer-shell.c | 211 +++++++++++++++++++++++ examples/meson.build | 6 + include/rootston/desktop.h | 5 + include/rootston/layers.h | 19 ++ include/rootston/view.h | 1 - protocol/meson.build | 1 + protocol/wlr-layer-shell-unstable-v1.xml | 5 +- rootston/desktop.c | 4 +- rootston/layer_shell.c | 54 ++++++ rootston/meson.build | 1 + 10 files changed, 302 insertions(+), 5 deletions(-) create mode 100644 examples/layer-shell.c create mode 100644 include/rootston/layers.h create mode 100644 rootston/layer_shell.c diff --git a/examples/layer-shell.c b/examples/layer-shell.c new file mode 100644 index 00000000..285bec5a --- /dev/null +++ b/examples/layer-shell.c @@ -0,0 +1,211 @@ +#define _POSIX_C_SOURCE 2 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "wlr-layer-shell-unstable-v1-client-protocol.h" + +static struct wl_compositor *compositor = NULL; +static struct zwlr_layer_shell_v1 *layer_shell = NULL; +static struct wl_output *wl_output = NULL; + +struct wl_surface *wl_surface; +struct wlr_egl egl; +struct wl_egl_window *egl_window; +struct wlr_egl_surface *egl_surface; +struct wl_callback *frame_callback; + +static uint32_t output = 0; +static uint32_t layer = -1; +static uint32_t anchor = 0; +static uint32_t width = 256, height = 256; + +static void draw(void); + +static void surface_frame_callback( + void *data, struct wl_callback *cb, uint32_t time) { + wl_callback_destroy(cb); + frame_callback = NULL; + draw(); +} + +static struct wl_callback_listener frame_listener = { + .done = surface_frame_callback +}; + +static void draw(void) { + eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context); + wlr_log(L_DEBUG, "Drawing frame"); + + float color[] = {1.0, 0.0, 0.0, 1.0}; + glViewport(0, 0, width, height); + glClearColor(color[0], color[1], color[2], 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + eglSwapBuffers(egl.display, egl_surface); + + frame_callback = wl_surface_frame(wl_surface); + wl_callback_add_listener(frame_callback, &frame_listener, NULL); +} + +static void layer_surface_configure(void *data, + struct zwlr_layer_surface_v1 *surface, + uint32_t serial, uint32_t w, uint32_t h) { + width = w; + height = h; + zwlr_layer_surface_v1_ack_configure(surface, serial); +} + +struct zwlr_layer_surface_v1_listener layer_surface_listener = { + .configure = layer_surface_configure, +}; + +static void handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) { + if (strcmp(interface, "wl_compositor") == 0) { + compositor = wl_registry_bind(registry, name, + &wl_compositor_interface, 1); + } else if (strcmp(interface, "wl_output") == 0) { + if (output == 0) { + wl_output = wl_registry_bind(registry, name, + &wl_output_interface, 1); + } else { + output--; + } + } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { + layer_shell = wl_registry_bind( + registry, name, &zwlr_layer_shell_v1_interface, 1); + } +} + +static void handle_global_remove(void *data, struct wl_registry *registry, + uint32_t name) { + // who cares +} + +static const struct wl_registry_listener registry_listener = { + .global = handle_global, + .global_remove = handle_global_remove, +}; + +int main(int argc, char **argv) { + wlr_log_init(L_DEBUG, NULL); + char *namespace = "wlroots"; + bool found; + int c; + while ((c = getopt(argc, argv, "w:h:o:"))) { + switch (c) { + case 'o': + output = atoi(optarg); + break; + case 'w': + width = atoi(optarg); + break; + case 'h': + height = atoi(optarg); + break; + case 'l': { + struct { + char *name; + enum zwlr_layer_shell_v1_layer value; + } layers[] = { + { "background", ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND }, + { "bottom", ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM }, + { "top", ZWLR_LAYER_SHELL_V1_LAYER_TOP }, + { "overlay", ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY }, + }; + found = false; + for (size_t i = 0; i < sizeof(layers) / sizeof(layers[0]); ++i) { + if (strcmp(optarg, layers[i].name)) { + layer = layers[i].value; + found = true; + break; + } + } + if (!found) { + fprintf(stderr, "invalid layer %s\n", optarg); + return 1; + } + break; + } + case 'a': { + struct { + char *name; + uint32_t value; + } anchors[] = { + { "top", ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP }, + { "bottom", ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM }, + { "left", ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT }, + { "right", ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT }, + }; + found = false; + for (size_t i = 0; i < sizeof(anchors) / sizeof(anchors[0]); ++i) { + if (strcmp(optarg, anchors[i].name)) { + anchor |= anchors[i].value; + found = true; + break; + } + } + if (!found) { + fprintf(stderr, "invalid anchor %s\n", optarg); + return 1; + } + } + default: + break; + } + } + + struct wl_display *display = wl_display_connect(NULL); + if (display == NULL) { + fprintf(stderr, "Failed to create display\n"); + return 1; + } + + 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) { + fprintf(stderr, "wl-compositor not available\n"); + return 1; + } + if (layer_shell == NULL) { + fprintf(stderr, "layer-shell not available\n"); + return 1; + } + if (wl_output == NULL) { + fprintf(stderr, "wl_output not available\n"); + return 1; + } + + wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL, + WL_SHM_FORMAT_ARGB8888); + + wl_surface = wl_compositor_create_surface(compositor); + + 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_anchor(layer_surface, anchor); + // TODO: margin, interactivity, exclusive zone + + wl_surface_commit(wl_surface); + + egl_window = wl_egl_window_create(wl_surface, width, height); + egl_surface = wlr_egl_create_surface(&egl, egl_window); + + wl_display_roundtrip(display); + draw(); + + while (wl_display_dispatch(display) != -1) { + // This space intentionally left blank + } + return 0; +} diff --git a/examples/meson.build b/examples/meson.build index a83def8f..558af4ac 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -48,3 +48,9 @@ executable( dependencies: [wayland_client, wlr_protos, wlroots, threads], link_with: lib_shared, ) + +executable( + 'layer-shell', + 'layer-shell.c', + dependencies: [wayland_client, wlr_protos, wlroots] +) diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 5ff9f5e2..ad7654a1 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,8 @@ 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; @@ -55,6 +58,7 @@ struct roots_desktop { struct wl_listener xdg_shell_v6_surface; struct wl_listener xdg_shell_surface; struct wl_listener wl_shell_surface; + struct wl_listener layer_shell_surface; struct wl_listener decoration_new; #ifdef WLR_HAS_XWAYLAND @@ -88,6 +92,7 @@ void view_unmap(struct roots_view *view); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); void handle_xdg_shell_surface(struct wl_listener *listener, void *data); void handle_wl_shell_surface(struct wl_listener *listener, void *data); +void handle_layer_shell_surface(struct wl_listener *listener, void *data); void handle_xwayland_surface(struct wl_listener *listener, void *data); #endif diff --git a/include/rootston/layers.h b/include/rootston/layers.h new file mode 100644 index 00000000..269056ea --- /dev/null +++ b/include/rootston/layers.h @@ -0,0 +1,19 @@ +#ifndef ROOTSTON_LAYERS_H +#define ROOTSTON_LAYERS_H +#include +#include +#include +#include +#include + +struct roots_layer_surface { + struct wlr_layer_surface *layer_surface; + struct wl_list link; + + struct wl_listener destroy; + struct wl_listener map; + struct wl_listener unmap; + struct wl_listener surface_commit; +}; + +#endif diff --git a/include/rootston/view.h b/include/rootston/view.h index 1397a8d2..6e746e8c 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -1,6 +1,5 @@ #ifndef ROOTSTON_VIEW_H #define ROOTSTON_VIEW_H - #include #include #include diff --git a/protocol/meson.build b/protocol/meson.build index 8c8a7c0e..a41fdec3 100644 --- a/protocol/meson.build +++ b/protocol/meson.build @@ -39,6 +39,7 @@ client_protocols = [ [wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'], 'idle.xml', 'screenshooter.xml', + 'wlr-layer-shell-unstable-v1.xml', ] wl_protos_src = [] diff --git a/protocol/wlr-layer-shell-unstable-v1.xml b/protocol/wlr-layer-shell-unstable-v1.xml index 285c9b8f..c4f2a7e3 100644 --- a/protocol/wlr-layer-shell-unstable-v1.xml +++ b/protocol/wlr-layer-shell-unstable-v1.xml @@ -222,9 +222,8 @@ - - - + diff --git a/rootston/desktop.c b/rootston/desktop.c index dcf0b7b2..015a8215 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -716,7 +716,9 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->wl_shell_surface.notify = handle_wl_shell_surface; desktop->layer_shell = wlr_layer_shell_create(server->wl_display); - // TODO: Pick up new surfaces + wl_signal_add(&desktop->layer_shell->events.new_surface, + &desktop->layer_shell_surface); + desktop->layer_shell_surface.notify = handle_layer_shell_surface; #ifdef WLR_HAS_XWAYLAND const char *cursor_theme = NULL; diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c new file mode 100644 index 00000000..50bf6466 --- /dev/null +++ b/rootston/layer_shell.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "rootston/desktop.h" +#include "rootston/layers.h" +#include "rootston/server.h" + +static void handle_destroy(struct wl_listener *listener, void *data) { + // TODO +} + +static void handle_surface_commit(struct wl_listener *listener, void *data) { + // TODO +} + +static void handle_map(struct wl_listener *listener, void *data) { + // TODO +} + +static void handle_unmap(struct wl_listener *listener, void *data) { + // TODO +} + +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); + + struct roots_layer_surface *roots_surface = + calloc(1, sizeof(struct roots_layer_surface)); + if (!roots_surface) { + return; + } + roots_surface->surface_commit.notify = handle_surface_commit; + wl_signal_add(&layer_surface->surface->events.commit, + &roots_surface->surface_commit); + roots_surface->destroy.notify = handle_destroy; + wl_signal_add(&layer_surface->events.destroy, &roots_surface->destroy); + roots_surface->map.notify = handle_map; + wl_signal_add(&layer_surface->events.map, &roots_surface->map); + roots_surface->unmap.notify = handle_unmap; + wl_signal_add(&layer_surface->events.unmap, &roots_surface->unmap); + + roots_surface->layer_surface = layer_surface; + + wl_list_insert(&desktop->layers[layer_surface->layer], &roots_surface->link); +} diff --git a/rootston/meson.build b/rootston/meson.build index 9dbe37c2..1b78c7c8 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -5,6 +5,7 @@ sources = [ 'ini.c', 'input.c', 'keyboard.c', + 'layer_shell.c', 'main.c', 'output.c', 'seat.c', From 4bc1cc49d5b8007145774214bc9126577b56b53c Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 18 Mar 2018 17:17:28 -0400 Subject: [PATCH 22/99] Fix strcmp use --- examples/layer-shell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index 285bec5a..9b26386d 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -121,7 +121,7 @@ int main(int argc, char **argv) { }; found = false; for (size_t i = 0; i < sizeof(layers) / sizeof(layers[0]); ++i) { - if (strcmp(optarg, layers[i].name)) { + if (strcmp(optarg, layers[i].name) == 0) { layer = layers[i].value; found = true; break; @@ -145,7 +145,7 @@ int main(int argc, char **argv) { }; found = false; for (size_t i = 0; i < sizeof(anchors) / sizeof(anchors[0]); ++i) { - if (strcmp(optarg, anchors[i].name)) { + if (strcmp(optarg, anchors[i].name) == 0) { anchor |= anchors[i].value; found = true; break; From fcf8c6c8a29e3ce0a17bcf7ce1ca92fed8493502 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 19 Mar 2018 20:24:16 -0400 Subject: [PATCH 23/99] Fix issues preventing layer from getting allocated Now all of the steps to get rootston a reference to the layer surface are correctly wired up. --- examples/layer-shell.c | 13 +++++++------ rootston/desktop.c | 4 ++++ types/wlr_layer_shell.c | 25 ++++++++++++++++++------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index 9b26386d..d2e07a90 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -21,7 +21,7 @@ struct wlr_egl_surface *egl_surface; struct wl_callback *frame_callback; static uint32_t output = 0; -static uint32_t layer = -1; +static uint32_t layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; static uint32_t anchor = 0; static uint32_t width = 256, height = 256; @@ -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:"))) { + while ((c = getopt(argc, argv, "w:h:o:")) != -1) { switch (c) { case 'o': output = atoi(optarg); @@ -185,9 +185,6 @@ int main(int argc, char **argv) { return 1; } - wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL, - WL_SHM_FORMAT_ARGB8888); - wl_surface = wl_compositor_create_surface(compositor); struct zwlr_layer_surface_v1 *layer_surface = @@ -195,8 +192,12 @@ int main(int argc, char **argv) { wl_surface, wl_output, layer, namespace); zwlr_layer_surface_v1_set_anchor(layer_surface, anchor); // TODO: margin, interactivity, exclusive zone - wl_surface_commit(wl_surface); + wl_display_dispatch(display); + wl_display_roundtrip(display); + + wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL, + WL_SHM_FORMAT_ARGB8888); egl_window = wl_egl_window_create(wl_surface, width, height); egl_surface = wlr_egl_create_surface(&egl, egl_window); diff --git a/rootston/desktop.c b/rootston/desktop.c index 015a8215..f00fc63f 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -719,6 +719,10 @@ 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/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 8063b219..aaf9ee84 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -14,20 +14,20 @@ static void resource_handle_destroy(struct wl_client *client, wl_resource_destroy(resource); } -static struct zwlr_layer_shell_v1_interface layer_shell_impl; -static struct zwlr_layer_surface_v1_interface layer_surface_impl; +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( struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &zwlr_layer_shell_v1_interface, - &layer_shell_impl)); + &layer_shell_implementation)); 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)); + &layer_surface_implementation)); return wl_resource_get_user_data(resource); } @@ -291,11 +291,22 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, wl_client_post_no_memory(wl_client); return; } + if (layer > ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY) { + wl_resource_post_error(surface->resource, + ZWLR_LAYER_SHELL_V1_ERROR_INVALID_LAYER, + "Invalid layer %d", layer); + free(surface); + return; + } + + wl_list_init(&surface->configure_list); 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; + wl_signal_init(&surface->events.map); + wl_signal_init(&surface->events.unmap); wlr_surface_set_role_committed(surface->surface, handle_wlr_surface_committed, surface); @@ -307,7 +318,7 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, wl_list_insert(&client->surfaces, &surface->link); } -static struct zwlr_layer_shell_v1_interface layer_shell_impl = { +static const struct zwlr_layer_shell_v1_interface layer_shell_implementation = { .get_layer_surface = layer_shell_handle_get_layer_surface, }; @@ -347,8 +358,8 @@ static void layer_shell_bind(struct wl_client *wl_client, void *data, client->client = wl_client; client->shell = layer_shell; - wl_resource_set_implementation(client->resource, &layer_shell_impl, client, - wlr_layer_client_destroy); + wl_resource_set_implementation(client->resource, + &layer_shell_implementation, client, wlr_layer_client_destroy); wl_list_insert(&layer_shell->clients, &client->link); } From 4bf936360d42fb5b96a44fd17028ae66fc462362 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 19 Mar 2018 23:11:37 -0400 Subject: [PATCH 24/99] 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(-) 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; - wl_list_insert(&desktop->layers[layer_surface->layer], &roots_surface->link); + 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); + + 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), From f444a0d14c046b7df5a63f34a6f958cb175eb851 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 20 Mar 2018 21:13:39 -0400 Subject: [PATCH 25/99] Implement layer surface damage --- examples/layer-shell.c | 36 +++++++++++++++++++++++++++++------- include/rootston/output.h | 4 ++-- render/egl.c | 2 +- rootston/layer_shell.c | 32 ++++++++++++++++++++++++++------ rootston/output.c | 27 ++++++++++++++++++++++++--- 5 files changed, 82 insertions(+), 19 deletions(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index b5542f7a..91c509f6 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -1,8 +1,9 @@ -#define _POSIX_C_SOURCE 2 +#define _POSIX_C_SOURCE 199309L #include #include #include #include +#include #include #include #include @@ -25,6 +26,12 @@ static uint32_t layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; static uint32_t anchor = 0; static int32_t width = 256, height = 256; +static struct { + struct timespec last_frame; + float color[3]; + int dec; +} demo; + static void draw(void); static void surface_frame_callback( @@ -40,17 +47,33 @@ static struct wl_callback_listener frame_listener = { static void draw(void) { eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context); - wlr_log(L_DEBUG, "Drawing frame"); - float color[] = {1.0, 0.0, 0.0, 1.0}; + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + + long ms = (ts.tv_sec - demo.last_frame.tv_sec) * 1000 + + (ts.tv_nsec - demo.last_frame.tv_nsec) / 1000000; + int inc = (demo.dec + 1) % 3; + + demo.color[inc] += ms / 2000.0f; + demo.color[demo.dec] -= ms / 2000.0f; + + if (demo.color[demo.dec] < 0.0f) { + demo.color[inc] = 1.0f; + demo.color[demo.dec] = 0.0f; + demo.dec = inc; + } + glViewport(0, 0, width, height); - glClearColor(color[0], color[1], color[2], 1.0); + glClearColor(demo.color[0], demo.color[1], demo.color[2], 1.0); glClear(GL_COLOR_BUFFER_BIT); - eglSwapBuffers(egl.display, egl_surface); - frame_callback = wl_surface_frame(wl_surface); wl_callback_add_listener(frame_callback, &frame_listener, NULL); + + eglSwapBuffers(egl.display, egl_surface); + + demo.last_frame = ts; } static void layer_surface_configure(void *data, @@ -196,7 +219,6 @@ int main(int argc, char **argv) { &layer_surface_listener, layer_surface); // TODO: margin, interactivity, exclusive zone wl_surface_commit(wl_surface); - wl_display_dispatch(display); wl_display_roundtrip(display); wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL, diff --git a/include/rootston/output.h b/include/rootston/output.h index 5545d76a..5cdbcb32 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -36,7 +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); +void output_damage_from_local_surface(struct roots_output *output, + struct wlr_surface *surface, double ox, double oy, float rotation); #endif diff --git a/render/egl.c b/render/egl.c index d230f589..315eb098 100644 --- a/render/egl.c +++ b/render/egl.c @@ -95,7 +95,7 @@ static void print_dmabuf_formats(struct wlr_egl *egl) { for (int i = 0; i < num; i++) { snprintf(&str_formats[i*5], (num - i) * 5 + 1, "%.4s ", (char*)&formats[i]); } - wlr_log(L_INFO, "Supported dmabuf buffer formats: %s", str_formats); + wlr_log(L_DEBUG, "Supported dmabuf buffer formats: %s", str_formats); free(formats); } diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 25e683fe..73addb7a 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -114,12 +114,32 @@ static void arrange_layers(struct wlr_output *_output) { } } +static void unmap(struct wlr_layer_surface *layer_surface) { + struct roots_layer_surface *layer = layer_surface->data; + wl_list_remove(&layer->link); + + struct wlr_output *wlr_output = layer_surface->output; + struct roots_output *output = wlr_output->data; + wlr_output_damage_add_box(output->damage, &layer->geo); +} + static void handle_destroy(struct wl_listener *listener, void *data) { - // TODO + struct roots_layer_surface *layer = wl_container_of( + listener, layer, destroy); + if (layer->layer_surface->mapped) { + unmap(layer->layer_surface); + } + free(layer); } static void handle_surface_commit(struct wl_listener *listener, void *data) { - // TODO + struct roots_layer_surface *layer = + wl_container_of(listener, layer, surface_commit); + struct wlr_layer_surface *layer_surface = layer->layer_surface; + struct wlr_output *wlr_output = layer_surface->output; + struct roots_output *output = wlr_output->data; + output_damage_from_local_surface(output, layer_surface->surface, + layer->geo.x, layer->geo.y, 0); } static void handle_map(struct wl_listener *listener, void *data) { @@ -127,13 +147,13 @@ static void handle_map(struct wl_listener *listener, void *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); + wlr_output_damage_add_box(output->damage, &layer->geo); } static void handle_unmap(struct wl_listener *listener, void *data) { - // TODO + struct roots_layer_surface *layer = wl_container_of( + listener, layer, unmap); + unmap(layer->layer_surface); } void handle_layer_shell_surface(struct wl_listener *listener, void *data) { diff --git a/rootston/output.c b/rootston/output.c index 71497608..7c2c6d44 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -433,6 +433,18 @@ static void render_layer( } } +static void layers_send_done( + struct roots_output *output, struct timespec *when) { + size_t len = sizeof(output->layers) / sizeof(output->layers[0]); + for (size_t i = 0; i < len; ++i) { + struct roots_layer_surface *roots_surface; + wl_list_for_each(roots_surface, &output->layers[i], link) { + struct wlr_layer_surface *layer = roots_surface->layer_surface; + wlr_surface_send_frame_done(layer->surface, when); + } + } +} + static void render_output(struct roots_output *output) { struct wlr_output *wlr_output = output->wlr_output; struct roots_desktop *desktop = output->desktop; @@ -595,6 +607,7 @@ damage_finish: drag_icons_for_each_surface(server->input, surface_send_frame_done, &data); } + layers_send_done(output, data.when); } void output_damage_whole(struct roots_output *output) { @@ -628,7 +641,7 @@ static bool view_accept_damage(struct roots_output *output, return false; } -void output_damage_whole_surface(struct wlr_surface *surface, +static void damage_whole_surface(struct wlr_surface *surface, double lx, double ly, float rotation, void *data) { struct roots_output *output = data; @@ -672,13 +685,13 @@ void output_damage_whole_view(struct roots_output *output, } damage_whole_decoration(view, output); - view_for_each_surface(view, output_damage_whole_surface, output); + view_for_each_surface(view, 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, - output_damage_whole_surface, output); + damage_whole_surface, output); } static void damage_from_surface(struct wlr_surface *surface, @@ -716,6 +729,14 @@ static void damage_from_surface(struct wlr_surface *surface, pixman_region32_fini(&damage); } +void output_damage_from_local_surface(struct roots_output *output, + struct wlr_surface *surface, double ox, double oy, float rotation) { + struct wlr_output_layout_output *layout = wlr_output_layout_get( + output->desktop->layout, output->wlr_output); + damage_from_surface(surface, ox + layout->x, oy + layout->y, + rotation, output); +} + void output_damage_from_view(struct roots_output *output, struct roots_view *view) { if (!view_accept_damage(output, view)) { From 8c98c188808e16f18349a89eb534e2bbf7ea65d8 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 20 Mar 2018 21:41:18 -0400 Subject: [PATCH 26/99] Gracefully deal with outputs being removed --- include/rootston/layers.h | 1 + rootston/layer_shell.c | 42 ++++++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/rootston/layers.h b/include/rootston/layers.h index f432d53d..43041786 100644 --- a/include/rootston/layers.h +++ b/include/rootston/layers.h @@ -14,6 +14,7 @@ struct roots_layer_surface { struct wl_listener map; struct wl_listener unmap; struct wl_listener surface_commit; + struct wl_listener output_destroy; bool configured; struct wlr_box geo; diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 73addb7a..c0dff85a 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -114,13 +114,34 @@ static void arrange_layers(struct wlr_output *_output) { } } +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); +} + +static void handle_surface_commit(struct wl_listener *listener, void *data) { + struct roots_layer_surface *layer = + wl_container_of(listener, layer, surface_commit); + struct wlr_layer_surface *layer_surface = layer->layer_surface; + struct wlr_output *wlr_output = layer_surface->output; + if (wlr_output != NULL) { + struct roots_output *output = wlr_output->data; + output_damage_from_local_surface(output, layer_surface->surface, + layer->geo.x, layer->geo.y, 0); + } +} + static void unmap(struct wlr_layer_surface *layer_surface) { struct roots_layer_surface *layer = layer_surface->data; wl_list_remove(&layer->link); struct wlr_output *wlr_output = layer_surface->output; - struct roots_output *output = wlr_output->data; - wlr_output_damage_add_box(output->damage, &layer->geo); + if (wlr_output != NULL) { + struct roots_output *output = wlr_output->data; + wlr_output_damage_add_box(output->damage, &layer->geo); + } } static void handle_destroy(struct wl_listener *listener, void *data) { @@ -129,19 +150,10 @@ static void handle_destroy(struct wl_listener *listener, void *data) { if (layer->layer_surface->mapped) { unmap(layer->layer_surface); } + wl_list_remove(&layer->output_destroy.link); free(layer); } -static void handle_surface_commit(struct wl_listener *listener, void *data) { - struct roots_layer_surface *layer = - wl_container_of(listener, layer, surface_commit); - struct wlr_layer_surface *layer_surface = layer->layer_surface; - struct wlr_output *wlr_output = layer_surface->output; - struct roots_output *output = wlr_output->data; - output_damage_from_local_surface(output, layer_surface->surface, - layer->geo.x, layer->geo.y, 0); -} - static void handle_map(struct wl_listener *listener, void *data) { struct wlr_layer_surface *layer_surface = data; struct roots_layer_surface *layer = layer_surface->data; @@ -174,9 +186,15 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { if (!roots_surface) { return; } + roots_surface->surface_commit.notify = handle_surface_commit; wl_signal_add(&layer_surface->surface->events.commit, &roots_surface->surface_commit); + + roots_surface->output_destroy.notify = handle_output_destroy; + wl_signal_add(&layer_surface->output->events.destroy, + &roots_surface->output_destroy); + roots_surface->destroy.notify = handle_destroy; wl_signal_add(&layer_surface->events.destroy, &roots_surface->destroy); roots_surface->map.notify = handle_map; From 0f7e78f6aa8530adc0dcc74a760b6478720e2ded Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 20 Mar 2018 21:45:50 -0400 Subject: [PATCH 27/99] Fix issue with multiple outputs in layer example --- examples/layer-shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index 91c509f6..f006a1b7 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -94,7 +94,7 @@ static void handle_global(void *data, struct wl_registry *registry, compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1); } else if (strcmp(interface, "wl_output") == 0) { - if (output == 0) { + if (output == 0 && !wl_output) { wl_output = wl_registry_bind(registry, name, &wl_output_interface, 1); } else { From b73c4f48c10ae79a33d1611fb641d22b8b619c39 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 20 Mar 2018 21:57:16 -0400 Subject: [PATCH 28/99] Fix exclusive zone among other layers --- examples/layer-shell.c | 9 +++++++-- rootston/layer_shell.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index f006a1b7..f3b9d3a0 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -119,9 +119,10 @@ static const struct wl_registry_listener registry_listener = { int main(int argc, char **argv) { wlr_log_init(L_DEBUG, NULL); char *namespace = "wlroots"; + int exclusive_zone = 0; bool found; int c; - while ((c = getopt(argc, argv, "w:h:o:l:a:")) != -1) { + while ((c = getopt(argc, argv, "w:h:o:l:a:x:")) != -1) { switch (c) { case 'o': output = atoi(optarg); @@ -132,6 +133,9 @@ int main(int argc, char **argv) { case 'h': height = atoi(optarg); break; + case 'x': + exclusive_zone = atoi(optarg); + break; case 'l': { struct { char *name; @@ -215,9 +219,10 @@ int main(int argc, char **argv) { 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_set_exclusive_zone(layer_surface, exclusive_zone); zwlr_layer_surface_v1_add_listener(layer_surface, &layer_surface_listener, layer_surface); - // TODO: margin, interactivity, exclusive zone + // TODO: margin, interactivity wl_surface_commit(wl_surface); wl_display_roundtrip(display); diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index c0dff85a..ac7b2b20 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -53,7 +53,7 @@ static void apply_exclusive(struct wlr_box *output_area, }; for (size_t i = 0; i < sizeof(edges) / sizeof(edges[0]); ++i) { if ((anchor & edges[i].anchors)) { - edges[i].value += exclusive * edges[i].multiplier; + *edges[i].value += exclusive * edges[i].multiplier; } } } From d1c0e6fe2c21b4c7f651a82fb7342b54a4989c39 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 24 Mar 2018 18:00:01 -0400 Subject: [PATCH 29/99] 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(-) 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; From 11c57d22b0d7c24ee69d4c43cb08f03c7f35f0d4 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 24 Mar 2018 18:02:42 -0400 Subject: [PATCH 30/99] Use 0 for default width/height (rather than -1) --- rootston/layer_shell.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 114a5f29..c4e82535 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -70,7 +70,7 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list) { // 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) { + if ((state->anchor & both_horiz) && box.width == 0) { box.x = 0; box.width = output_area.width; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) { @@ -83,7 +83,7 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list) { // 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) { + if ((state->anchor & both_vert) && box.height == 0) { box.y = 0; box.height = output_area.height; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) { @@ -97,9 +97,9 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list) { 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) { + 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; } From df9dbf31706254887652b54214e2c9ee2346f0e8 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 26 Mar 2018 12:01:13 -0400 Subject: [PATCH 31/99] Fix rebase issues; rearrange layers on destroy --- examples/layer-shell.c | 16 ++++++++++++---- rootston/layer_shell.c | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index 08826251..999d948f 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -1,4 +1,5 @@ #define _POSIX_C_SOURCE 199309L +#include #include #include #include @@ -24,7 +25,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 int32_t width = 256, height = 256; +static uint32_t width = 256, height = 256; static bool run_display = true; static struct { @@ -82,6 +83,9 @@ static void layer_surface_configure(void *data, uint32_t serial, uint32_t w, uint32_t h) { width = w; height = h; + if (egl_window) { + wl_egl_window_resize(egl_window, width, height, 0, 0); + } zwlr_layer_surface_v1_ack_configure(surface, serial); } @@ -223,11 +227,16 @@ int main(int argc, char **argv) { return 1; } + wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL, + WL_SHM_FORMAT_ARGB8888); + wl_surface = wl_compositor_create_surface(compositor); + assert(wl_surface); struct zwlr_layer_surface_v1 *layer_surface = zwlr_layer_shell_v1_get_layer_surface(layer_shell, wl_surface, wl_output, layer, namespace); + assert(layer_surface); 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); @@ -237,11 +246,10 @@ int main(int argc, char **argv) { wl_surface_commit(wl_surface); wl_display_roundtrip(display); - wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL, - WL_SHM_FORMAT_ARGB8888); - egl_window = wl_egl_window_create(wl_surface, width, height); + assert(egl_window); egl_surface = wlr_egl_create_surface(&egl, egl_window); + assert(egl_surface); wl_display_roundtrip(display); draw(); diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index c4e82535..ccea4f8d 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -153,6 +153,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { unmap(layer->layer_surface); } wl_list_remove(&layer->output_destroy.link); + arrange_layers(layer->layer_surface->output); free(layer); } From ab6c2bf5849a83cea0b6cb0e78d17d054ff07b19 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 26 Mar 2018 12:22:17 -0400 Subject: [PATCH 32/99] Reset exclusivity after shell layer Also fixes an issue which was applying exclusivity to all edges --- include/rootston/output.h | 3 ++ rootston/layer_shell.c | 63 +++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/include/rootston/output.h b/include/rootston/output.h index 5cdbcb32..535c07d8 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -4,6 +4,7 @@ #include #include #include +#include #include struct roots_desktop; @@ -19,6 +20,8 @@ struct roots_output { struct timespec last_frame; struct wlr_output_damage *damage; + struct wlr_box usable_area; + struct wl_listener destroy; struct wl_listener damage_frame; struct wl_listener damage_destroy; diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index ccea4f8d..38ddda23 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -11,7 +11,7 @@ #include "rootston/output.h" #include "rootston/server.h" -static void apply_exclusive(struct wlr_box *output_area, +static void apply_exclusive(struct wlr_box *usable_area, uint32_t anchor, uint32_t exclusive) { struct { uint32_t anchors; @@ -23,7 +23,7 @@ static void apply_exclusive(struct wlr_box *output_area, ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP, - .value = &output_area->y, + .value = &usable_area->y, .multiplier = 1, }, { @@ -31,7 +31,7 @@ static void apply_exclusive(struct wlr_box *output_area, ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, - .value = &output_area->height, + .value = &usable_area->height, .multiplier = -1, }, { @@ -39,7 +39,7 @@ static void apply_exclusive(struct wlr_box *output_area, ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, - .value = &output_area->x, + .value = &usable_area->x, .multiplier = 1, }, { @@ -47,21 +47,19 @@ static void apply_exclusive(struct wlr_box *output_area, ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, - .value = &output_area->width, + .value = &usable_area->width, .multiplier = -1, }, }; for (size_t i = 0; i < sizeof(edges) / sizeof(edges[0]); ++i) { - if ((anchor & edges[i].anchors)) { + if ((anchor & edges[i].anchors) == 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); +static void arrange_layer(struct wlr_output *output, struct wl_list *list, + struct wlr_box *usable_area) { struct roots_layer_surface *roots_surface; wl_list_for_each(roots_surface, list, link) { struct wlr_layer_surface *layer = roots_surface->layer_surface; @@ -72,31 +70,31 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list) { | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; if ((state->anchor & both_horiz) && box.width == 0) { box.x = 0; - box.width = output_area.width; + box.width = usable_area->width; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) { - box.x = output_area.x; + box.x = usable_area->x; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) { - box.x = output_area.width - box.width; + box.x = usable_area->width - box.width; } else { - box.x = (output_area.width / 2) - (box.width / 2); + box.x = (usable_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 == 0) { box.y = 0; - box.height = output_area.height; + box.height = usable_area->height; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) { - box.y = output_area.y; + box.y = usable_area->y; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) { - box.y = output_area.height - box.height; + box.y = usable_area->height - box.height; } else { - box.y = (output_area.height / 2) - (box.height / 2); + box.y = (usable_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); + apply_exclusive(usable_area, state->anchor, state->exclusive_zone); if (!roots_surface->configured || box.width != (int)state->width || box.height != (int)state->height) { @@ -108,10 +106,29 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list) { 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]); - } + + struct wlr_box usable_area = { 0 }; + 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_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)); + + memset(&usable_area, 0, sizeof(struct wlr_box)); + 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_TOP], + &usable_area); + arrange_layer(output->wlr_output, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], + &usable_area); } static void handle_output_destroy(struct wl_listener *listener, void *data) { From 097e87ca9ff34e0d17dced154ee8a860b6d86060 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 26 Mar 2018 14:14:23 -0400 Subject: [PATCH 33/99] Handle usable area for maximized windows Also fixes some bugs --- include/rootston/desktop.h | 1 + rootston/desktop.c | 50 +++++++++++++++++++++++++------------- rootston/layer_shell.c | 49 +++++++++++++++++++++++-------------- 3 files changed, 65 insertions(+), 35 deletions(-) diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 92cc6d9d..5714aa0a 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -86,6 +86,7 @@ void view_update_size(struct roots_view *view, uint32_t width, uint32_t height); void view_initial_focus(struct roots_view *view); void view_map(struct roots_view *view, struct wlr_surface *surface); void view_unmap(struct roots_view *view); +void view_arrange_maximized(struct roots_view *view); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); void handle_xdg_shell_surface(struct wl_listener *listener, void *data); diff --git a/rootston/desktop.c b/rootston/desktop.c index 015a8215..a0659250 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -188,6 +188,38 @@ static struct wlr_output *view_get_output(struct roots_view *view) { output_y); } +void view_arrange_maximized(struct roots_view *view) { + struct wlr_box view_box; + view_get_box(view, &view_box); + + view->maximized = true; + view->saved.x = view->x; + view->saved.y = view->y; + view->saved.rotation = view->rotation; + view->saved.width = view_box.width; + view->saved.height = view_box.height; + + struct wlr_output *output = view_get_output(view); + struct roots_output *roots_output = output->data; + struct wlr_box *output_box = + wlr_output_layout_get_box(view->desktop->layout, output); + struct wlr_box usable_area; + memcpy(&usable_area, &roots_output->usable_area, + sizeof(struct wlr_box)); + 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); +} + void view_maximize(struct roots_view *view, bool maximized) { if (view->maximized == maximized) { return; @@ -198,23 +230,7 @@ void view_maximize(struct roots_view *view, bool maximized) { } if (!view->maximized && maximized) { - struct wlr_box view_box; - view_get_box(view, &view_box); - - view->maximized = true; - view->saved.x = view->x; - view->saved.y = view->y; - view->saved.rotation = view->rotation; - view->saved.width = view_box.width; - view->saved.height = view_box.height; - - struct wlr_output *output = view_get_output(view); - struct wlr_box *output_box = - wlr_output_layout_get_box(view->desktop->layout, output); - - view_move_resize(view, output_box->x, output_box->y, output_box->width, - output_box->height); - view_rotate(view, 0); + view_arrange_maximized(view); } if (view->maximized && !maximized) { diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 38ddda23..e7604ec5 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -15,45 +15,50 @@ static void apply_exclusive(struct wlr_box *usable_area, uint32_t anchor, uint32_t exclusive) { struct { uint32_t anchors; - int *value; - int multiplier; + int *positive_axis; + int *negative_axis; } edges[] = { { .anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP, - .value = &usable_area->y, - .multiplier = 1, + .positive_axis = &usable_area->y, + .negative_axis = &usable_area->height, }, { .anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, - .value = &usable_area->height, - .multiplier = -1, + .positive_axis = NULL, + .negative_axis = &usable_area->height, }, { .anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, - .value = &usable_area->x, - .multiplier = 1, + .positive_axis = &usable_area->x, + .negative_axis = &usable_area->width, }, { .anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, - .value = &usable_area->width, - .multiplier = -1, + .positive_axis = NULL, + .negative_axis = &usable_area->width, }, }; for (size_t i = 0; i < sizeof(edges) / sizeof(edges[0]); ++i) { if ((anchor & edges[i].anchors) == edges[i].anchors) { - *edges[i].value += exclusive * edges[i].multiplier; + if (edges[i].positive_axis) { + *edges[i].positive_axis += exclusive; + } + if (edges[i].negative_axis) { + *edges[i].negative_axis -= exclusive; + } } } } @@ -74,9 +79,9 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list, } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT)) { box.x = usable_area->x; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) { - box.x = usable_area->width - box.width; + box.x = usable_area->x + (usable_area->width - box.width); } else { - box.x = (usable_area->width / 2) - (box.width / 2); + box.x = usable_area->x + ((usable_area->width / 2) - (box.width / 2)); } // Vertical axis const uint32_t both_vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP @@ -87,9 +92,9 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list, } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)) { box.y = usable_area->y; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) { - box.y = usable_area->height - box.height; + box.y = usable_area->y + (usable_area->height - box.height); } else { - box.y = (usable_area->height / 2) - (box.height / 2); + box.y = usable_area->y + ((usable_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); @@ -119,16 +124,24 @@ static void arrange_layers(struct wlr_output *_output) { &usable_area); memcpy(&output->usable_area, &usable_area, sizeof(struct wlr_box)); + 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); - arrange_layer(output->wlr_output, - &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], - &usable_area); arrange_layer(output->wlr_output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &usable_area); + + struct roots_view *view; + wl_list_for_each(view, &output->desktop->views, link) { + if (view->maximized) { + view_arrange_maximized(view); + } + } } static void handle_output_destroy(struct wl_listener *listener, void *data) { From 86ca4bea6de9b3494235201f5587cb7e00aed84e Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 26 Mar 2018 18:12:31 -0400 Subject: [PATCH 34/99] 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 | 140 ++++++++++++++++------- types/wlr_layer_shell.c | 35 +++--- types/wlr_seat.c | 5 +- 7 files changed, 173 insertions(+), 76 deletions(-) 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)); } - wlr_log(L_DEBUG, "arranged layer at %dx%d@%d,%d", - box.width, box.height, box.x, box.y); + // 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; + } + 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_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)); - - 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); - + // Arrange exclusive surfaces from top->bottom arrange_layer(output->wlr_output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], - &usable_area); + &usable_area, true); + arrange_layer(output->wlr_output, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], + &usable_area, true); + arrange_layer(output->wlr_output, + &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( From 0e318df13d4d98ffc69f2390562fc03aeca36f3b Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 26 Mar 2018 18:44:36 -0400 Subject: [PATCH 35/99] Add margin animation to the example demo --- examples/layer-shell.c | 27 ++++++++++++++++++++++----- rootston/layer_shell.c | 28 +++++++++++++++++++++------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index 3518a56f..4c501d3d 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -14,6 +14,7 @@ static struct wl_compositor *compositor = NULL; static struct zwlr_layer_shell_v1 *layer_shell = NULL; +struct zwlr_layer_surface_v1 *layer_surface; static struct wl_output *wl_output = NULL; struct wl_surface *wl_surface; @@ -26,8 +27,11 @@ 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 margin_top = 0; static double alpha = 1.0; static bool run_display = true; +static bool animate = false; +static double frame = 0; static struct { struct timespec last_frame; @@ -67,6 +71,18 @@ static void draw(void) { demo.dec = inc; } + if (animate) { + frame += ms / 50.0; + int32_t old_top = margin_top; + margin_top = -(20 - ((int)frame % 20)); + if (old_top != margin_top) { + wlr_log(L_DEBUG, "setting margin to %d", margin_top); + zwlr_layer_surface_v1_set_margin(layer_surface, + margin_top, 0, 0, 0); + wl_surface_commit(wl_surface); + } + } + glViewport(0, 0, width, height); glClearColor(demo.color[0], demo.color[1], demo.color[2], alpha); glClear(GL_COLOR_BUFFER_BIT); @@ -136,11 +152,10 @@ 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; + int32_t margin_right = 0, margin_bottom = 0, margin_left = 0; bool found; int c; - while ((c = getopt(argc, argv, "w:h:o:l:a:x:m:t:")) != -1) { + while ((c = getopt(argc, argv, "nw:h:o:l:a:x:m:t:")) != -1) { switch (c) { case 'o': output = atoi(optarg); @@ -217,6 +232,9 @@ int main(int argc, char **argv) { assert(!*endptr); break; } + case 'n': + animate = true; + break; default: break; } @@ -253,8 +271,7 @@ int main(int argc, char **argv) { wl_surface = wl_compositor_create_surface(compositor); assert(wl_surface); - struct zwlr_layer_surface_v1 *layer_surface = - zwlr_layer_shell_v1_get_layer_surface(layer_shell, + layer_surface = zwlr_layer_shell_v1_get_layer_surface(layer_shell, wl_surface, wl_output, layer, namespace); assert(layer_surface); zwlr_layer_surface_v1_set_size(layer_surface, width, height); diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index e2d5b9f0..35896228 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -12,7 +12,9 @@ #include "rootston/server.h" static void apply_exclusive(struct wlr_box *usable_area, - uint32_t anchor, int32_t exclusive) { + uint32_t anchor, int32_t exclusive, + int32_t margin_top, int32_t margin_right, + int32_t margin_bottom, int32_t margin_left) { if (exclusive <= 0) { return; } @@ -20,6 +22,7 @@ static void apply_exclusive(struct wlr_box *usable_area, uint32_t anchors; int *positive_axis; int *negative_axis; + int margin; } edges[] = { { .anchors = @@ -28,6 +31,7 @@ static void apply_exclusive(struct wlr_box *usable_area, ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP, .positive_axis = &usable_area->y, .negative_axis = &usable_area->height, + .margin = margin_top, }, { .anchors = @@ -36,6 +40,7 @@ static void apply_exclusive(struct wlr_box *usable_area, ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, .positive_axis = NULL, .negative_axis = &usable_area->height, + .margin = margin_bottom, }, { .anchors = @@ -44,6 +49,7 @@ static void apply_exclusive(struct wlr_box *usable_area, ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, .positive_axis = &usable_area->x, .negative_axis = &usable_area->width, + .margin = margin_left, }, { .anchors = @@ -52,15 +58,16 @@ static void apply_exclusive(struct wlr_box *usable_area, ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, .positive_axis = NULL, .negative_axis = &usable_area->width, + .margin = margin_right, }, }; for (size_t i = 0; i < sizeof(edges) / sizeof(edges[0]); ++i) { if ((anchor & edges[i].anchors) == edges[i].anchors) { if (edges[i].positive_axis) { - *edges[i].positive_axis += exclusive; + *edges[i].positive_axis += exclusive + edges[i].margin; } if (edges[i].negative_axis) { - *edges[i].negative_axis -= exclusive; + *edges[i].negative_axis -= exclusive + edges[i].margin; } } } @@ -121,15 +128,15 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list, box.y = bounds.y + ((bounds.height / 2) - (box.height / 2)); } // Margin - if ((state->anchor & both_horiz)) { + if ((state->anchor & both_horiz) == 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; + box.x += state->margin.left; } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) { box.x -= state->margin.right; } - if ((state->anchor & both_vert)) { + if ((state->anchor & both_vert) == 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)) { @@ -139,7 +146,11 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list, } // Apply roots_surface->geo = box; - apply_exclusive(usable_area, state->anchor, state->exclusive_zone); + apply_exclusive(usable_area, state->anchor, state->exclusive_zone, + state->margin.top, state->margin.right, + state->margin.bottom, state->margin.left); + wlr_log(L_DEBUG, "arranged layer at %dx%d@%d,%d", + box.width, box.height, box.x, box.y); wlr_layer_surface_configure(layer, box.width, box.height); } } @@ -212,6 +223,9 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_output *output = wlr_output->data; output_damage_from_local_surface(output, layer_surface->surface, layer->geo.x, layer->geo.y, 0); + arrange_layers(wlr_output); + output_damage_from_local_surface(output, layer_surface->surface, + layer->geo.x, layer->geo.y, 0); } } From e841e5602b9fb7447564f75fc9d1e835a215e51a Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 26 Mar 2018 22:08:34 -0400 Subject: [PATCH 36/99] Address @emersion's feedback --- protocol/wlr-layer-shell-unstable-v1.xml | 29 +++++----- types/wlr_layer_shell.c | 73 ++++++++---------------- 2 files changed, 39 insertions(+), 63 deletions(-) diff --git a/protocol/wlr-layer-shell-unstable-v1.xml b/protocol/wlr-layer-shell-unstable-v1.xml index fe2c72cd..3181c0bb 100644 --- a/protocol/wlr-layer-shell-unstable-v1.xml +++ b/protocol/wlr-layer-shell-unstable-v1.xml @@ -93,8 +93,9 @@ - Sets the size of the surface in pixels. The compositor will display the - surface centered with respect to its anchors. + Sets the size of the surface in surface-local coordinates. The + compositor will display the surface centered with respect to its + anchors. 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 @@ -128,8 +129,8 @@ actually be occluded. 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. + edge, rather than a corner. The zone is the number of surface-local + coordinates 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 @@ -139,13 +140,15 @@ 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 + For example, a panel might set its exclusive zone to 10, 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 + might set its exclusive zone to 0, 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. + The default value is 0. + Exclusive zone is double-buffered, see wl_surface.commit. @@ -154,8 +157,8 @@ 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. + point on the output, in surface-local coordinates. Setting this value + for edges you are not anchored to has no effect. The exclusive zone includes the margin. @@ -254,11 +257,11 @@ - 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. + 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/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 04c8fbd5..761d2413 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -115,7 +115,7 @@ 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; + surface->client_pending.keyboard_interactive = !!interactive; } static void layer_surface_handle_get_popup(struct wl_client *client, @@ -143,7 +143,7 @@ static void layer_surface_unmap(struct wlr_layer_surface *surface) { layer_surface_configure_destroy(configure); } - 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); @@ -189,61 +189,34 @@ static bool wlr_layer_surface_state_changed(struct wlr_layer_surface *surface) { return changed; } -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.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.actual_width, - configure->state.actual_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->server_pending.actual_width = width; surface->server_pending.actual_height = height; - wlr_layer_surface_schedule_configure(surface); + if (wlr_layer_surface_state_changed(surface)) { + struct wl_display *display = + wl_client_get_display(surface->client->client); + 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; + } + surface->configure_next_serial = wl_display_next_serial(display); + wl_list_insert(surface->configure_list.prev, &configure->link); + configure->state.actual_width = width; + configure->state.actual_height = height; + configure->serial = surface->configure_next_serial; + zwlr_layer_surface_v1_send_configure(surface->resource, + configure->serial, configure->state.actual_width, + configure->state.actual_height); + } } void wlr_layer_surface_close(struct wlr_layer_surface *surface) { + if (surface->closed) { + return; + } surface->closed = true; layer_surface_unmap(surface); zwlr_layer_surface_v1_send_closed(surface->resource); From 776b81d499ae4430c0ebe5421b119c6b3355a1ce Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 26 Mar 2018 23:13:09 -0400 Subject: [PATCH 37/99] Fix surface layer damage tracking --- examples/layer-shell.c | 1 - include/rootston/output.h | 4 +++- rootston/layer_shell.c | 16 ++++++++++------ rootston/output.c | 8 ++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index 4c501d3d..e559121e 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -76,7 +76,6 @@ static void draw(void) { int32_t old_top = margin_top; margin_top = -(20 - ((int)frame % 20)); if (old_top != margin_top) { - wlr_log(L_DEBUG, "setting margin to %d", margin_top); zwlr_layer_surface_v1_set_margin(layer_surface, margin_top, 0, 0, 0); wl_surface_commit(wl_surface); diff --git a/include/rootston/output.h b/include/rootston/output.h index 535c07d8..e40ad776 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -40,6 +40,8 @@ void output_damage_from_view(struct roots_output *output, void output_damage_whole_drag_icon(struct roots_output *output, struct roots_drag_icon *icon); void output_damage_from_local_surface(struct roots_output *output, - struct wlr_surface *surface, double ox, double oy, float rotation); + struct wlr_surface *surface, double ox, double oy, float rotation); +void output_damage_whole_local_surface(struct roots_output *output, + struct wlr_surface *surface, double ox, double oy, float rotation); #endif diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 35896228..5efdf3c9 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -149,8 +149,6 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list, apply_exclusive(usable_area, state->anchor, state->exclusive_zone, state->margin.top, state->margin.right, state->margin.bottom, state->margin.left); - wlr_log(L_DEBUG, "arranged layer at %dx%d@%d,%d", - box.width, box.height, box.x, box.y); wlr_layer_surface_configure(layer, box.width, box.height); } } @@ -221,11 +219,17 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { struct wlr_output *wlr_output = layer_surface->output; if (wlr_output != NULL) { struct roots_output *output = wlr_output->data; - output_damage_from_local_surface(output, layer_surface->surface, - layer->geo.x, layer->geo.y, 0); + struct wlr_box old_geo = layer->geo; arrange_layers(wlr_output); - output_damage_from_local_surface(output, layer_surface->surface, - layer->geo.x, layer->geo.y, 0); + if (memcmp(&old_geo, &layer->geo, sizeof(struct wlr_box)) != 0) { + output_damage_whole_local_surface(output, layer_surface->surface, + old_geo.x, old_geo.y, 0); + output_damage_whole_local_surface(output, layer_surface->surface, + layer->geo.x, layer->geo.y, 0); + } else { + output_damage_from_local_surface(output, layer_surface->surface, + layer->geo.x, layer->geo.y, 0); + } } } diff --git a/rootston/output.c b/rootston/output.c index 7c2c6d44..aa74c8d7 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -664,6 +664,14 @@ static void damage_whole_surface(struct wlr_surface *surface, wlr_output_damage_add_box(output->damage, &box); } +void output_damage_whole_local_surface(struct roots_output *output, + struct wlr_surface *surface, double ox, double oy, float rotation) { + struct wlr_output_layout_output *layout = wlr_output_layout_get( + output->desktop->layout, output->wlr_output); + damage_whole_surface(surface, ox + layout->x, oy + layout->y, + rotation, output); +} + static void damage_whole_decoration(struct roots_view *view, struct roots_output *output) { if (!view->decorated || view->wlr_surface == NULL) { From 13edb19a6ca89da3fcbafd3be01d89251658178d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 27 Mar 2018 15:49:44 -0400 Subject: [PATCH 38/99] 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(-) 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; From 52fe2688ea1068d5cd0801ead4fc078c3a37dea1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 27 Mar 2018 17:18:16 -0400 Subject: [PATCH 39/99] 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(-) 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); From a1d5d20914b25ef2d9820f04d885f22d6488d5e1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 27 Mar 2018 17:36:35 -0400 Subject: [PATCH 40/99] Address some more feedback --- rootston/layer_shell.c | 7 +++++++ rootston/output.c | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 809ddbf3..d6428c51 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -138,6 +138,11 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list, } else if ((state->anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM)) { box.y -= state->margin.bottom; } + if (box.width < 0 || box.height < 0) { + // TODO: Bubble up a protocol error? + wlr_layer_surface_close(layer); + continue; + } // Apply roots_surface->geo = box; apply_exclusive(usable_area, state->anchor, state->exclusive_zone, @@ -177,6 +182,7 @@ static void arrange_layers(struct wlr_output *_output) { } // Arrange non-exlusive surfaces from top->bottom + usable_area.x = usable_area.y = 0; wlr_output_effective_resolution(output->wlr_output, &usable_area.width, &usable_area.height); arrange_layer(output->wlr_output, @@ -313,6 +319,7 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { wl_signal_add(&layer_surface->events.map, &roots_surface->map); roots_surface->unmap.notify = handle_unmap; wl_signal_add(&layer_surface->events.unmap, &roots_surface->unmap); + // TODO: Listen for subsurfaces roots_surface->layer_surface = layer_surface; layer_surface->data = roots_surface; diff --git a/rootston/output.c b/rootston/output.c index aa74c8d7..d903963e 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -560,14 +560,15 @@ static void render_output(struct roots_output *output) { wl_list_for_each_reverse(view, &desktop->views, link) { render_view(view, &data); } + // Render top layer above shell views + render_layer(output, output_box, &data, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); } // 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]); @@ -670,6 +671,7 @@ void output_damage_whole_local_surface(struct roots_output *output, output->desktop->layout, output->wlr_output); damage_whole_surface(surface, ox + layout->x, oy + layout->y, rotation, output); + // TODO: subsurfaces } static void damage_whole_decoration(struct roots_view *view, @@ -743,6 +745,7 @@ void output_damage_from_local_surface(struct roots_output *output, output->desktop->layout, output->wlr_output); damage_from_surface(surface, ox + layout->x, oy + layout->y, rotation, output); + // TODO: Subsurfaces } void output_damage_from_view(struct roots_output *output, From 3e5131e664c605f406756bae51d1276a67b5fa38 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 27 Mar 2018 21:25:40 -0400 Subject: [PATCH 41/99] Address further review feedback --- rootston/desktop.c | 14 +++++++------- rootston/layer_shell.c | 9 +++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index 9ea392f6..15e0e336 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -192,13 +192,6 @@ void view_arrange_maximized(struct roots_view *view) { struct wlr_box view_box; view_get_box(view, &view_box); - view->maximized = true; - view->saved.x = view->x; - view->saved.y = view->y; - view->saved.rotation = view->rotation; - view->saved.width = view_box.width; - view->saved.height = view_box.height; - struct wlr_output *output = view_get_output(view); struct roots_output *roots_output = output->data; struct wlr_box *output_box = @@ -224,6 +217,13 @@ void view_maximize(struct roots_view *view, bool maximized) { } if (!view->maximized && maximized) { + view->maximized = true; + view->saved.x = view->x; + view->saved.y = view->y; + view->saved.rotation = view->rotation; + view->saved.width = view->width; + view->saved.height = view->height; + view_arrange_maximized(view); } diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index d6428c51..06ab15c3 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -239,10 +239,6 @@ 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; - if (layer->link.prev) { - wl_list_remove(&layer->link); - } - struct wlr_output *wlr_output = layer_surface->output; if (wlr_output != NULL) { struct roots_output *output = wlr_output->data; @@ -256,6 +252,11 @@ static void handle_destroy(struct wl_listener *listener, void *data) { if (layer->layer_surface->mapped) { unmap(layer->layer_surface); } + wl_list_remove(&layer->link); + wl_list_remove(&layer->destroy.link); + wl_list_remove(&layer->map.link); + wl_list_remove(&layer->unmap.link); + wl_list_remove(&layer->surface_commit.link); wl_list_remove(&layer->output_destroy.link); wl_list_remove(&layer->output_mode.link); wl_list_remove(&layer->output_transform.link); From 96a8df2f9a1cf1d24b6c901ece844c620ed9ee1b Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 27 Mar 2018 22:50:55 -0400 Subject: [PATCH 42/99] 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(-) 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; From 7d89e7e58dc6d3a2d40baf91ae3f5aaa87d58a8b Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 27 Mar 2018 23:08:41 -0400 Subject: [PATCH 43/99] Assign layer surface role --- types/wlr_layer_shell.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 99344ed3..39a3af80 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -10,6 +10,8 @@ #include "util/signal.h" #include "wlr-layer-shell-unstable-v1-protocol.h" +static const char *zwlr_layer_surface_role = "zwlr_layer_surface"; + static void resource_handle_destroy(struct wl_client *client, struct wl_resource *resource) { wl_resource_destroy(resource); @@ -288,6 +290,13 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, uint32_t layer, const char *namespace) { struct wlr_layer_shell *shell = layer_shell_from_resource(client_resource); + struct wlr_surface *wlr_surface = + wlr_surface_from_resource(surface_resource); + + if (wlr_surface_set_role(wlr_surface, zwlr_layer_surface_role, + client_resource, ZWLR_LAYER_SHELL_V1_ERROR_ROLE)) { + return; + } struct wlr_layer_surface *surface = calloc(1, sizeof(struct wlr_layer_surface)); @@ -297,7 +306,7 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, } surface->shell = shell; - surface->surface = wlr_surface_from_resource(surface_resource); + surface->surface = wlr_surface; surface->output = wlr_output_from_resource(output_resource); surface->resource = wl_resource_create(wl_client, &zwlr_layer_surface_v1_interface, From 8d1b5c760098961501d3ece510a417a44fecd212 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 28 Mar 2018 00:04:32 -0400 Subject: [PATCH 44/99] backend/x11: correctly update keyboard modifiers --- backend/meson.build | 1 + backend/x11/backend.c | 33 +++++++++++++++++++++++++++++++++ meson.build | 43 ++++++++++++++++++++++--------------------- 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/backend/meson.build b/backend/meson.build index a74ea024..df12d703 100644 --- a/backend/meson.build +++ b/backend/meson.build @@ -51,6 +51,7 @@ endif if conf_data.get('WLR_HAS_X11_BACKEND', false) backend_files += files('x11/backend.c') + backend_deps += xcb_xkb endif if conf_data.get('WLR_HAS_ELOGIND', false) diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 36d72d9e..79b896fe 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -16,6 +16,7 @@ #include #include #include +#include #ifdef __linux__ #include #elif __FreeBSD__ @@ -30,6 +31,10 @@ static const struct wlr_backend_impl backend_impl; static const struct wlr_output_impl output_impl; static const struct wlr_input_device_impl input_device_impl = { 0 }; +// TODO: remove global state +static uint8_t xkb_base_event; +static uint8_t xkb_base_error; + static uint32_t xcb_button_to_wl(uint32_t button) { switch (button) { case XCB_BUTTON_INDEX_1: return BTN_LEFT; @@ -157,6 +162,12 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e break; } default: + if (event->response_type == xkb_base_event) { + xcb_xkb_state_notify_event_t *ev = + (xcb_xkb_state_notify_event_t *)event; + wlr_keyboard_notify_modifiers(&x11->keyboard, ev->baseMods, + ev->latchedMods, ev->lockedMods, ev->lockedGroup); + } break; } @@ -225,6 +236,28 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { x11->screen->root, 0, 0, 1024, 768, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, x11->screen->root_visual, mask, values); + const xcb_query_extension_reply_t *reply = + xcb_get_extension_data(x11->xcb_conn, &xcb_xkb_id); + if (reply->present) { + xkb_base_event = reply->first_event; + xkb_base_error = reply->first_error; + + xcb_xkb_use_extension_cookie_t cookie = xcb_xkb_use_extension( + x11->xcb_conn, XCB_XKB_MAJOR_VERSION, XCB_XKB_MINOR_VERSION); + xcb_xkb_use_extension_reply_t *reply = + xcb_xkb_use_extension_reply(x11->xcb_conn, cookie, NULL); + if (reply && reply->supported) { + xcb_xkb_select_events(x11->xcb_conn, + XCB_XKB_ID_USE_CORE_KBD, + XCB_XKB_EVENT_TYPE_STATE_NOTIFY, + 0, + XCB_XKB_EVENT_TYPE_STATE_NOTIFY, + 0, + 0, + 0); + } + } + output->surf = wlr_egl_create_surface(&x11->egl, &output->win); if (!output->surf) { wlr_log(L_ERROR, "Failed to create EGL surface"); diff --git a/meson.build b/meson.build index 7740b416..a48984c1 100644 --- a/meson.build +++ b/meson.build @@ -82,35 +82,36 @@ if elogind.found() and get_option('enable_elogind') != 'false' endif if get_option('enable_x11_backend') or get_option('enable_xwayland') - xcb = dependency('xcb') - xcb_composite = dependency('xcb-composite') - xcb_xfixes = dependency('xcb-xfixes') - xcb_image = dependency('xcb-image') - xcb_render = dependency('xcb-render') - x11_xcb = dependency('x11-xcb') + xcb = dependency('xcb') + xcb_composite = dependency('xcb-composite') + xcb_xfixes = dependency('xcb-xfixes') + xcb_xkb = dependency('xcb-xkb') # TODO: make this optional + xcb_image = dependency('xcb-image') + xcb_render = dependency('xcb-render') + x11_xcb = dependency('x11-xcb') - xcb_icccm = dependency('xcb-icccm', required: false) - xcb_errors = dependency('xcb-errors', required: get_option('enable_xcb_errors') == 'true') + xcb_icccm = dependency('xcb-icccm', required: false) + xcb_errors = dependency('xcb-errors', required: get_option('enable_xcb_errors') == 'true') - if xcb_icccm.found() - conf_data.set('WLR_HAS_XCB_ICCCM', true) - endif + if xcb_icccm.found() + conf_data.set('WLR_HAS_XCB_ICCCM', true) + endif - if xcb_errors.found() and get_option('enable_xcb_errors') != 'false' - conf_data.set('WLR_HAS_XCB_ERRORS', true) - endif + if xcb_errors.found() and get_option('enable_xcb_errors') != 'false' + conf_data.set('WLR_HAS_XCB_ERRORS', true) + endif - wlr_deps += [ - xcb, - xcb_composite, - x11_xcb, - ] + wlr_deps += [ + xcb, + xcb_composite, + x11_xcb, + ] else - add_project_arguments('-DMESA_EGL_NO_X11_HEADERS', language: 'c') + add_project_arguments('-DMESA_EGL_NO_X11_HEADERS', language: 'c') endif if get_option('enable_x11_backend') - conf_data.set('WLR_HAS_X11_BACKEND', true) + conf_data.set('WLR_HAS_X11_BACKEND', true) endif if get_option('enable_xwayland') From f033f717a27b1ea0974db43118312c8b05587fec Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 28 Mar 2018 00:26:15 -0400 Subject: [PATCH 45/99] backend/x11: make xcb-xkb optional, remove global state --- backend/x11/backend.c | 61 +++++++++++++++++++++++-------------------- include/backend/x11.h | 6 +++++ meson.build | 6 ++++- 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 79b896fe..7d560d97 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -16,12 +17,14 @@ #include #include #include -#include #ifdef __linux__ #include #elif __FreeBSD__ #include #endif +#ifdef WLR_HAS_XCB_XKB +#include +#endif #include "backend/x11.h" #include "util/signal.h" @@ -31,10 +34,6 @@ static const struct wlr_backend_impl backend_impl; static const struct wlr_output_impl output_impl; static const struct wlr_input_device_impl input_device_impl = { 0 }; -// TODO: remove global state -static uint8_t xkb_base_event; -static uint8_t xkb_base_error; - static uint32_t xcb_button_to_wl(uint32_t button) { switch (button) { case XCB_BUTTON_INDEX_1: return BTN_LEFT; @@ -162,12 +161,14 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e break; } default: - if (event->response_type == xkb_base_event) { +#ifdef WLR_HAS_XCB_XKB + if (x11->xkb_supported && event->response_type == x11->xkb_base_event) { xcb_xkb_state_notify_event_t *ev = (xcb_xkb_state_notify_event_t *)event; wlr_keyboard_notify_modifiers(&x11->keyboard, ev->baseMods, ev->latchedMods, ev->lockedMods, ev->lockedGroup); } +#endif break; } @@ -236,28 +237,6 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { x11->screen->root, 0, 0, 1024, 768, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, x11->screen->root_visual, mask, values); - const xcb_query_extension_reply_t *reply = - xcb_get_extension_data(x11->xcb_conn, &xcb_xkb_id); - if (reply->present) { - xkb_base_event = reply->first_event; - xkb_base_error = reply->first_error; - - xcb_xkb_use_extension_cookie_t cookie = xcb_xkb_use_extension( - x11->xcb_conn, XCB_XKB_MAJOR_VERSION, XCB_XKB_MINOR_VERSION); - xcb_xkb_use_extension_reply_t *reply = - xcb_xkb_use_extension_reply(x11->xcb_conn, cookie, NULL); - if (reply && reply->supported) { - xcb_xkb_select_events(x11->xcb_conn, - XCB_XKB_ID_USE_CORE_KBD, - XCB_XKB_EVENT_TYPE_STATE_NOTIFY, - 0, - XCB_XKB_EVENT_TYPE_STATE_NOTIFY, - 0, - 0, - 0); - } - } - output->surf = wlr_egl_create_surface(&x11->egl, &output->win); if (!output->surf) { wlr_log(L_ERROR, "Failed to create EGL surface"); @@ -315,6 +294,32 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { strlen(title), title); } +#ifdef WLR_HAS_XCB_XKB + const xcb_query_extension_reply_t *reply = + xcb_get_extension_data(x11->xcb_conn, &xcb_xkb_id); + if (reply != NULL && reply->present) { + x11->xkb_base_event = reply->first_event; + x11->xkb_base_error = reply->first_error; + + xcb_xkb_use_extension_cookie_t cookie = xcb_xkb_use_extension( + x11->xcb_conn, XCB_XKB_MAJOR_VERSION, XCB_XKB_MINOR_VERSION); + xcb_xkb_use_extension_reply_t *reply = + xcb_xkb_use_extension_reply(x11->xcb_conn, cookie, NULL); + if (reply != NULL && reply->supported) { + x11->xkb_supported = true; + + xcb_xkb_select_events(x11->xcb_conn, + XCB_XKB_ID_USE_CORE_KBD, + XCB_XKB_EVENT_TYPE_STATE_NOTIFY, + 0, + XCB_XKB_EVENT_TYPE_STATE_NOTIFY, + 0, + 0, + 0); + } + } +#endif + xcb_map_window(x11->xcb_conn, output->win); xcb_flush(x11->xcb_conn); wlr_output_update_enabled(&output->wlr_output, true); diff --git a/include/backend/x11.h b/include/backend/x11.h index 840509bf..72710f6c 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -48,6 +48,12 @@ struct wlr_x11_backend { // The time we last received an event xcb_timestamp_t time; +#ifdef WLR_HAS_XCB_XKB + bool xkb_supported; + uint8_t xkb_base_event; + uint8_t xkb_base_error; +#endif + struct wl_listener display_destroy; }; diff --git a/meson.build b/meson.build index a48984c1..04c93817 100644 --- a/meson.build +++ b/meson.build @@ -85,18 +85,22 @@ if get_option('enable_x11_backend') or get_option('enable_xwayland') xcb = dependency('xcb') xcb_composite = dependency('xcb-composite') xcb_xfixes = dependency('xcb-xfixes') - xcb_xkb = dependency('xcb-xkb') # TODO: make this optional xcb_image = dependency('xcb-image') xcb_render = dependency('xcb-render') x11_xcb = dependency('x11-xcb') xcb_icccm = dependency('xcb-icccm', required: false) + xcb_xkb = dependency('xcb-xkb', required: false) xcb_errors = dependency('xcb-errors', required: get_option('enable_xcb_errors') == 'true') if xcb_icccm.found() conf_data.set('WLR_HAS_XCB_ICCCM', true) endif + if xcb_xkb.found() + conf_data.set('WLR_HAS_XCB_XKB', true) + endif + if xcb_errors.found() and get_option('enable_xcb_errors') != 'false' conf_data.set('WLR_HAS_XCB_ERRORS', true) endif From a35a5786b0e40cb1ffa87344d3cb21dff9fd99f4 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Mar 2018 10:46:50 -0400 Subject: [PATCH 46/99] 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(-) 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); } From 324b9d910dc237151fd71c01bef015d0080be191 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Mar 2018 11:04:40 -0400 Subject: [PATCH 47/99] 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(-) 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; } From 738f5e33440eac4f1619c639784b9815f451285a Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 11:42:01 -0400 Subject: [PATCH 48/99] cleanup xdg-positioner rootston code --- rootston/xdg_shell_v6.c | 161 ++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 96 deletions(-) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index e3c70e96..5fa016a0 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -65,8 +65,8 @@ static void popup_get_coords(struct wlr_xdg_popup_v6 *popup, *sy = popup_sy + parent->geometry.y; } -static void popup_is_constrained(struct roots_xdg_popup_v6 *popup, - bool *x_constrained, bool *y_constrained) { +static void popup_constraint_offset(struct roots_xdg_popup_v6 *popup, + int *offset_x, int *offset_y) { 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; @@ -94,134 +94,103 @@ static void popup_is_constrained(struct roots_xdg_popup_v6 *popup, assert(output); struct wlr_box *output_box = wlr_output_layout_get_box(layout, output); - *x_constrained = popup_lx <= output_box->x || + bool x_constrained = popup_lx <= output_box->x || popup_lx + popup_width >= output_box->x + output_box->width; - *y_constrained = popup_ly <= output_box->y || + bool 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); + *offset_x = *offset_y = 0; - if (!x_constrained && !y_constrained) { - return; - } + double popup_ox = popup_lx - output_box->x; + double popup_oy = popup_ly - output_box->y; if (x_constrained) { + *offset_x = popup_width - (output_box->width - popup_ox); + } + + if (y_constrained) { + *offset_y = popup_height - (output_box->height - popup_oy); + } +} + +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 (y_constrained) { + 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_is_constrained(popup, &x_constrained, &y_constrained); + popup_constraint_offset(popup, &offset_x, &offset_y); - if (!x_constrained && !y_constrained) { - return; + if (!offset_x && !offset_y) { + // no longer constrained + return true; } - if (x_constrained) { + // 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 (y_constrained) { + 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); + + return false; } -static void popup_unconstrain_slide(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; +static bool popup_unconstrain_slide(struct roots_xdg_popup_v6 *popup) { + int offset_x, offset_y; + popup_constraint_offset(popup, &offset_x, &offset_y); - 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); - 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); - - struct wlr_output *output = - wlr_output_layout_output_at(layout, dest_x, dest_y); - // XXX: handle empty output layout - assert(output); - - struct wlr_box *output_box = wlr_output_layout_get_box(layout, output); - - bool x_constrained = popup_lx <= output_box->x || - popup_lx + popup_width >= output_box->x + output_box->width; - bool y_constrained = popup_ly <= output_box->y || - popup_ly + popup_height >= output_box->y + output_box->height; - - double popup_ox = popup_lx - output_box->x, - popup_oy = popup_ly - output_box->y; - - if (x_constrained) { - wlr_popup->geometry.x -= popup_width - (output_box->width - popup_ox); + if (!offset_x && !offset_y) { + return true; } - if (y_constrained) { - wlr_popup->geometry.y -= popup_height - (output_box->height - popup_oy); + + if (offset_x) { + popup->wlr_popup->geometry.x -= offset_x; } + if (offset_y) { + popup->wlr_popup->geometry.y -= abs(offset_y); + } + + popup_constraint_offset(popup, &offset_y, &offset_y); + + return !offset_x && !offset_y; } -static void popup_unconstrain_resize(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; +static bool popup_unconstrain_resize(struct roots_xdg_popup_v6 *popup) { + int offset_x, offset_y; + popup_constraint_offset(popup, &offset_x, &offset_y); - 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); - 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); - - struct wlr_output *output = - wlr_output_layout_output_at(layout, dest_x, dest_y); - // XXX: handle empty output layout - assert(output); - - struct wlr_box *output_box = wlr_output_layout_get_box(layout, output); - - bool x_constrained = popup_lx <= output_box->x || - popup_lx + popup_width >= output_box->x + output_box->width; - bool y_constrained = popup_ly <= output_box->y || - popup_ly + popup_height >= output_box->y + output_box->height; - - double popup_ox = popup_lx - output_box->x, popup_oy = popup_ly - output_box->y; - - if (x_constrained) { - wlr_popup->geometry.width = output_box->x + output_box->width - popup_ox; + if (!offset_x && !offset_y) { + return true; } - if (y_constrained) { - wlr_popup->geometry.height = output_box->y + output_box->height - popup_oy; + + 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) { From ac219cbda6dc3122fcc7f1bfa89b7e8fbb03b8ce Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Mar 2018 11:40:35 -0400 Subject: [PATCH 49/99] 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(-) 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); } } From e2c4e1ef541f825eeb804d0873d305213c3fbb82 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 12:12:00 -0400 Subject: [PATCH 50/99] fix xdg-positioner left constrain bug --- rootston/xdg_shell_v6.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 5fa016a0..1e85a933 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -94,21 +94,21 @@ static void popup_constraint_offset(struct roots_xdg_popup_v6 *popup, assert(output); struct wlr_box *output_box = wlr_output_layout_get_box(layout, output); - bool x_constrained = popup_lx <= output_box->x || - popup_lx + popup_width >= output_box->x + output_box->width; - bool y_constrained = popup_ly <= output_box->y || - popup_ly + popup_height >= output_box->y + output_box->height; *offset_x = *offset_y = 0; double popup_ox = popup_lx - output_box->x; double popup_oy = popup_ly - output_box->y; - if (x_constrained) { + 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 = popup_width - (output_box->width - popup_ox); } - if (y_constrained) { + 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 = popup_height - (output_box->height - popup_oy); } } @@ -161,10 +161,10 @@ static bool popup_unconstrain_slide(struct roots_xdg_popup_v6 *popup) { } if (offset_x) { - popup->wlr_popup->geometry.x -= offset_x; + popup->wlr_popup->geometry.x += offset_x; } if (offset_y) { - popup->wlr_popup->geometry.y -= abs(offset_y); + popup->wlr_popup->geometry.y += offset_y; } popup_constraint_offset(popup, &offset_y, &offset_y); From 32bdcdf7191be40a4ad74ece7e152a264358220a Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Mar 2018 12:33:17 -0400 Subject: [PATCH 51/99] Address review feedback --- include/wlr/types/wlr_cursor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From c5cd8050986ad71e954e054445c42120e5868700 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 12:46:41 -0400 Subject: [PATCH 52/99] positioner rootston cleanup and bugfix --- rootston/xdg_shell_v6.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 1e85a933..9bcdb4c9 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -97,19 +97,16 @@ static void popup_constraint_offset(struct roots_xdg_popup_v6 *popup, *offset_x = *offset_y = 0; - double popup_ox = popup_lx - output_box->x; - double popup_oy = popup_ly - output_box->y; - 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 = popup_width - (output_box->width - popup_ox); + *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 = popup_height - (output_box->height - popup_oy); + *offset_y = output_box->y + output_box->height - (popup_ly + popup_height); } } @@ -163,6 +160,7 @@ static bool popup_unconstrain_slide(struct roots_xdg_popup_v6 *popup) { if (offset_x) { popup->wlr_popup->geometry.x += offset_x; } + if (offset_y) { popup->wlr_popup->geometry.y += offset_y; } From 3813121fefb1734ed2c2537759e6eead1c0d9a74 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Mar 2018 14:04:23 -0400 Subject: [PATCH 53/99] Fix wayland output absolute input handling --- backend/wayland/wl_seat.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 2d4f76de..a5821311 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -64,6 +64,9 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window, &width, &height); + int owidth, oheight; + wlr_output_effective_resolution(wlr_output, &owidth, &oheight); + struct wlr_box box = { .x = wl_fixed_to_int(surface_x), .y = wl_fixed_to_int(surface_y), @@ -80,8 +83,15 @@ 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.x = transformed.x / layout_box.width; - wlr_event.y = transformed.y / layout_box.height; + + double tx = transformed.x / (double)owidth; + double ty = transformed.y / (double)oheight; + double ox = wlr_output->lx / (double)layout_box.width; + double oy = wlr_output->ly / (double)layout_box.height; + + wlr_event.x = tx * ((double)owidth / layout_box.width) + ox; + wlr_event.y = ty * ((double)oheight / layout_box.height) + oy; + wlr_signal_emit_safe(&dev->pointer->events.motion_absolute, &wlr_event); } From dbffda7549de4dba6b595e9bcaaef1628463315f Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 16:27:08 -0400 Subject: [PATCH 54/99] 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(-) 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); + int width = 0, height = 0; + wlr_output_effective_resolution(output, &width, &height); - *offset_x = *offset_y = 0; + struct wlr_box toplevel_box = { + .x = output->lx - view->x, + .y = output->ly - view->y, + .width = width, + .height = height + }; - 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); - } - - popup->wlr_popup->geometry = - wlr_xdg_positioner_v6_get_geometry(&popup->wlr_popup->positioner); - - 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) { From 0bfcce50a9e3fe8e06d225c69a686041311ae484 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 16:55:16 -0400 Subject: [PATCH 55/99] xdg-positioner: honor constraint flags --- rootston/xdg_shell_v6.c | 3 +++ types/wlr_xdg_shell_v6.c | 53 +++++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 22309e8e..9062995d 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -51,6 +51,9 @@ static void popup_handle_new_popup(struct wl_listener *listener, void *data) { } static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) { + // get the output of the popup's positioner anchor point and convert it to + // the toplevel parent's coordinate system and then pass it to + // wlr_xdg_popup_v6_unconstrain_from_box 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; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 0cf215ab..9b700b55 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -1723,28 +1723,34 @@ static bool wlr_xdg_popup_v6_unconstrain_flip(struct wlr_xdg_popup_v6 *popup, return true; } - if (offset_x) { + bool flip_x = offset_x && + (popup->positioner.constraint_adjustment & + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_X); + + bool flip_y = offset_x && + (popup->positioner.constraint_adjustment & + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_Y); + + if (flip_x) { wlr_positioner_v6_invert_x(&popup->positioner); } - if (offset_y) { + if (flip_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) { + if (flip_x) { wlr_positioner_v6_invert_x(&popup->positioner); } - if (offset_y) { + if (flip_y) { wlr_positioner_v6_invert_y(&popup->positioner); } @@ -1763,11 +1769,19 @@ static bool wlr_xdg_popup_v6_unconstrain_slide(struct wlr_xdg_popup_v6 *popup, return true; } - if (offset_x) { + bool slide_x = offset_x && + (popup->positioner.constraint_adjustment & + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_X); + + bool slide_y = offset_x && + (popup->positioner.constraint_adjustment & + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_Y); + + if (slide_x) { popup->geometry.x += offset_x; } - if (offset_y) { + if (slide_y) { popup->geometry.y += offset_y; } @@ -1785,10 +1799,18 @@ static bool wlr_xdg_popup_v6_unconstrain_resize(struct wlr_xdg_popup_v6 *popup, return true; } - if (offset_x) { + bool resize_x = offset_x && + (popup->positioner.constraint_adjustment & + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_X); + + bool resize_y = offset_x && + (popup->positioner.constraint_adjustment & + WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y); + + if (resize_x) { popup->geometry.width -= offset_x; } - if (offset_y) { + if (resize_y) { popup->geometry.height -= offset_y; } @@ -1799,8 +1821,15 @@ static bool wlr_xdg_popup_v6_unconstrain_resize(struct wlr_xdg_popup_v6 *popup, 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); + if (wlr_xdg_popup_v6_unconstrain_flip(popup, toplevel_box)) { + return; + } + if (wlr_xdg_popup_v6_unconstrain_slide(popup, toplevel_box)) { + return; + } + if (wlr_xdg_popup_v6_unconstrain_resize(popup, toplevel_box)) { + return; + } } void wlr_positioner_v6_invert_x(struct wlr_xdg_positioner_v6_attributes *positioner) { From 4ab88a533098ee22d2bcd037e07d0c3ede9464fd Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 17:04:55 -0400 Subject: [PATCH 56/99] xdg-positioner bugfix --- types/wlr_xdg_shell_v6.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 9b700b55..4b2cfc23 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -1717,7 +1717,7 @@ static void wlr_xdg_popup_v6_box_constraints(struct wlr_xdg_popup_v6 *popup, 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); + wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_x, &offset_y); if (!offset_x && !offset_y) { return true; @@ -1727,7 +1727,7 @@ static bool wlr_xdg_popup_v6_unconstrain_flip(struct wlr_xdg_popup_v6 *popup, (popup->positioner.constraint_adjustment & WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_X); - bool flip_y = offset_x && + bool flip_y = offset_y && (popup->positioner.constraint_adjustment & WLR_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_Y); @@ -1741,6 +1741,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); + if (!offset_x && !offset_y) { // no longer constrained return true; From 376d1cc0da0a7cd2bbcb6fcb500caaddd9561a50 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 18:30:38 -0400 Subject: [PATCH 57/99] 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(-) 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; From bd828e23de77789a05ca6972ed3c41402732d19c Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 18:33:21 -0400 Subject: [PATCH 58/99] dont allocate xdg-positioner attrs --- types/wlr_xdg_shell_v6.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index a78546ae..aaacbf29 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -18,7 +18,7 @@ static const char *wlr_desktop_xdg_popup_role = "xdg_popup_v6"; struct wlr_xdg_positioner_v6_resource { struct wl_resource *resource; - struct wlr_xdg_positioner_v6 *attrs; + struct wlr_xdg_positioner_v6 attrs; }; static void resource_handle_destroy(struct wl_client *client, @@ -297,7 +297,6 @@ static struct wlr_xdg_positioner_v6_resource *xdg_positioner_from_resource( static void xdg_positioner_destroy(struct wl_resource *resource) { struct wlr_xdg_positioner_v6_resource *positioner = xdg_positioner_from_resource(resource); - free(positioner->attrs); free(positioner); } @@ -313,8 +312,8 @@ static void xdg_positioner_handle_set_size(struct wl_client *client, return; } - positioner->attrs->size.width = width; - positioner->attrs->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, @@ -330,10 +329,10 @@ static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client, return; } - positioner->attrs->anchor_rect.x = x; - positioner->attrs->anchor_rect.y = y; - positioner->attrs->anchor_rect.width = width; - positioner->attrs->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, @@ -351,7 +350,7 @@ static void xdg_positioner_handle_set_anchor(struct wl_client *client, return; } - positioner->attrs->anchor = anchor; + positioner->attrs.anchor = anchor; } static void xdg_positioner_handle_set_gravity(struct wl_client *client, @@ -369,7 +368,7 @@ static void xdg_positioner_handle_set_gravity(struct wl_client *client, return; } - positioner->attrs->gravity = gravity; + positioner->attrs.gravity = gravity; } static void xdg_positioner_handle_set_constraint_adjustment( @@ -378,7 +377,7 @@ static void xdg_positioner_handle_set_constraint_adjustment( struct wlr_xdg_positioner_v6_resource *positioner = xdg_positioner_from_resource(resource); - positioner->attrs->constraint_adjustment = constraint_adjustment; + positioner->attrs.constraint_adjustment = constraint_adjustment; } static void xdg_positioner_handle_set_offset(struct wl_client *client, @@ -386,8 +385,8 @@ static void xdg_positioner_handle_set_offset(struct wl_client *client, struct wlr_xdg_positioner_v6_resource *positioner = xdg_positioner_from_resource(resource); - positioner->attrs->offset.x = x; - positioner->attrs->offset.y = y; + positioner->attrs.offset.x = x; + positioner->attrs.offset.y = y; } static const struct zxdg_positioner_v6_interface @@ -411,10 +410,6 @@ 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)); - positioner->resource = wl_resource_create(wl_client, &zxdg_positioner_v6_interface, wl_resource_get_version(resource), @@ -587,7 +582,7 @@ 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"); @@ -618,10 +613,10 @@ static void xdg_surface_handle_get_popup(struct wl_client *client, surface->popup->base = surface; surface->popup->parent = parent; surface->popup->geometry = - wlr_xdg_positioner_v6_get_geometry(positioner->attrs); + wlr_xdg_positioner_v6_get_geometry(&positioner->attrs); // positioner properties - memcpy(&surface->popup->positioner, positioner->attrs, + memcpy(&surface->popup->positioner, &positioner->attrs, sizeof(struct wlr_xdg_positioner_v6)); wl_list_insert(&parent->popups, &surface->popup->link); From 67c8aec77f27aa08528a69894a045a48d67bd658 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 18:36:48 -0400 Subject: [PATCH 59/99] popup constraint handle empty output layout --- rootston/xdg_shell_v6.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 9062995d..fe63e697 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -76,8 +76,10 @@ static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) { struct wlr_output *output = wlr_output_layout_output_at(layout, dest_x, dest_y); - // XXX: handle empty output layout - assert(output); + + if (output == NULL) { + return; + } int width = 0, height = 0; wlr_output_effective_resolution(output, &width, &height); From bf5ae85683963a03b9291dd7ab184ab97abc0fd4 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 18:40:55 -0400 Subject: [PATCH 60/99] return early when no dest_x/y in output layout closest point --- types/wlr_output_layout.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index 8d328c17..fdeef387 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -313,6 +313,10 @@ void wlr_output_layout_output_coords(struct wlr_output_layout *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) { + if (dest_x == NULL && dest_y == NULL) { + return; + } + double min_x = DBL_MAX, min_y = DBL_MAX, min_distance = DBL_MAX; struct wlr_output_layout_output *l_output; wl_list_for_each(l_output, &layout->outputs, link) { From 8b967fc573b2a4d53c59a4cace75434c4b6c94db Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 19:00:49 -0400 Subject: [PATCH 61/99] bug: dont slide over too far --- types/wlr_xdg_shell_v6.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index aaacbf29..85ced7bd 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -1761,7 +1761,7 @@ 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) { - int offset_x, offset_y; + int offset_x = 0, offset_y = 0; wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_x, &offset_y); if (!offset_x && !offset_y) { @@ -1784,6 +1784,17 @@ static bool wlr_xdg_popup_v6_unconstrain_slide(struct wlr_xdg_popup_v6 *popup, popup->geometry.y += offset_y; } + int toplevel_x = 0, toplevel_y = 0; + 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_y && toplevel_y < toplevel_box->y) { + popup->geometry.y += toplevel_box->y - toplevel_y; + } + wlr_xdg_popup_v6_box_constraints(popup, toplevel_box, &offset_x, &offset_y); return !offset_x && !offset_y; From 967bccffcd634a6ba2d13185c530f64b4d1eb613 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 19:42:17 -0400 Subject: [PATCH 62/99] remove xdg-positioner wlr wrappers --- include/wlr/types/wlr_xdg_shell_v6.h | 63 ++----------------- types/wlr_xdg_shell_v6.c | 90 ++++++++++++++-------------- 2 files changed, 49 insertions(+), 104 deletions(-) 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->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 & 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->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; } } From cf13a6d9c6f4f9a2d97284236131e4b713aa02c8 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 20:09:20 -0400 Subject: [PATCH 63/99] address toplevel coords issue --- types/wlr_xdg_shell_v6.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 2a780a37..44bd8d9a 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -1674,7 +1674,7 @@ 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 && parent->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + while (parent != NULL && parent->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) { popup_sx += parent->popup->geometry.x; popup_sy += parent->popup->geometry.y; parent = parent->popup->parent; From 71da20dbdefd137d53bbbdb7bfd6f242c1698548 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 20:51:25 -0400 Subject: [PATCH 64/99] add comment for output box in toplevel coords --- rootston/xdg_shell_v6.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index fe63e697..295d9ff4 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -84,14 +84,16 @@ static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) { int width = 0, height = 0; wlr_output_effective_resolution(output, &width, &height); - struct wlr_box toplevel_box = { + // the output box expressed in the coordinate system of the toplevel parent + // of the popup + struct wlr_box output_box_toplevel = { .x = output->lx - view->x, .y = output->ly - view->y, .width = width, .height = height }; - wlr_xdg_popup_v6_unconstrain_from_box(popup->wlr_popup, &toplevel_box); + wlr_xdg_popup_v6_unconstrain_from_box(popup->wlr_popup, &output_box_toplevel); } static struct roots_xdg_popup_v6 *popup_create(struct roots_view *view, From 27f450ac0eb254dad03c11b14d4785c16dac0c51 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 22:26:56 -0400 Subject: [PATCH 65/99] add todo for rotated unconstrained popup --- rootston/xdg_shell_v6.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 295d9ff4..0aca9638 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -54,6 +54,12 @@ static void popup_unconstrain(struct roots_xdg_popup_v6 *popup) { // get the output of the popup's positioner anchor point and convert it to // the toplevel parent's coordinate system and then pass it to // wlr_xdg_popup_v6_unconstrain_from_box + + // TODO: unconstrain popups for rotated windows + if (popup->view_child.view->rotation != 0.0) { + return; + } + 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; From 2e63d1a0ca01d71de58988593860741b835ba8bb Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 28 Mar 2018 23:24:39 -0400 Subject: [PATCH 66/99] 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(-) 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; } } From b887af9a6013ea0466b6152e74f69659d7d45711 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 29 Mar 2018 12:18:13 -0400 Subject: [PATCH 67/99] Fix maximized windows interaction with layer shell If there were no layer surfaces the usable area of the output would be an empty box. --- include/rootston/layers.h | 6 +++--- include/rootston/output.h | 2 ++ rootston/layer_shell.c | 31 +++++-------------------------- rootston/output.c | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/include/rootston/layers.h b/include/rootston/layers.h index 35f5399e..0e5164bb 100644 --- a/include/rootston/layers.h +++ b/include/rootston/layers.h @@ -1,7 +1,6 @@ #ifndef ROOTSTON_LAYERS_H #define ROOTSTON_LAYERS_H #include -#include #include #include #include @@ -15,11 +14,12 @@ struct roots_layer_surface { struct wl_listener unmap; 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; }; +struct roots_output; +void arrange_layers(struct roots_output *output); + #endif diff --git a/include/rootston/output.h b/include/rootston/output.h index e40ad776..bf152038 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -23,6 +23,8 @@ struct roots_output { struct wlr_box usable_area; struct wl_listener destroy; + struct wl_listener mode; + struct wl_listener transform; struct wl_listener damage_frame; struct wl_listener damage_destroy; }; diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 06ab15c3..edfaf5ea 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -82,7 +82,7 @@ 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 != (state->exclusive_zone >0)) { + if (exclusive != (state->exclusive_zone > 0)) { continue; } struct wlr_box bounds; @@ -152,9 +152,7 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list, } } -static void arrange_layers(struct wlr_output *_output) { - struct roots_output *output = _output->data; - +void arrange_layers(struct roots_output *output) { struct wlr_box usable_area = { 0 }; wlr_output_effective_resolution(output->wlr_output, &usable_area.width, &usable_area.height); @@ -204,18 +202,9 @@ static void handle_output_destroy(struct wl_listener *listener, void *data) { 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_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); @@ -224,7 +213,7 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { if (wlr_output != NULL) { struct roots_output *output = wlr_output->data; struct wlr_box old_geo = layer->geo; - arrange_layers(wlr_output); + arrange_layers(output); if (memcmp(&old_geo, &layer->geo, sizeof(struct wlr_box)) != 0) { output_damage_whole_local_surface(output, layer_surface->surface, old_geo.x, old_geo.y, 0); @@ -258,9 +247,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_list_remove(&layer->unmap.link); wl_list_remove(&layer->surface_commit.link); 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); + arrange_layers((struct roots_output *)layer->layer_surface->output->data); free(layer); } @@ -306,14 +293,6 @@ 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->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; @@ -333,7 +312,7 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { struct wlr_layer_surface_state old_state = layer_surface->current; layer_surface->current = layer_surface->client_pending; - arrange_layers(output->wlr_output); + arrange_layers(output); layer_surface->current = old_state; } diff --git a/rootston/output.c b/rootston/output.c index d903963e..bf2bbdc2 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -816,6 +816,18 @@ static void output_damage_handle_destroy(struct wl_listener *listener, output_destroy(output); } +static void output_handle_mode(struct wl_listener *listener, void *data) { + struct roots_output *output = + wl_container_of(listener, output, mode); + arrange_layers(output); +} + +static void output_handle_transform(struct wl_listener *listener, void *data) { + struct roots_output *output = + wl_container_of(listener, output, transform); + arrange_layers(output); +} + void handle_new_output(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = wl_container_of(listener, desktop, new_output); @@ -845,6 +857,11 @@ void handle_new_output(struct wl_listener *listener, void *data) { output->destroy.notify = output_handle_destroy; wl_signal_add(&wlr_output->events.destroy, &output->destroy); + output->mode.notify = output_handle_mode; + wl_signal_add(&wlr_output->events.mode, &output->mode); + output->transform.notify = output_handle_transform; + wl_signal_add(&wlr_output->events.transform, &output->transform); + output->damage_frame.notify = output_damage_handle_frame; wl_signal_add(&output->damage->events.frame, &output->damage_frame); output->damage_destroy.notify = output_damage_handle_destroy; @@ -879,5 +896,6 @@ void handle_new_output(struct wl_listener *listener, void *data) { roots_seat_configure_xcursor(seat); } + arrange_layers(output); output_damage_whole(output); } From 4137d9fc80fdf2ef03ff69a0b75ab52123517408 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 29 Mar 2018 16:30:09 -0400 Subject: [PATCH 68/99] 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(+) 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); From 6bbf50708263dbda2a61a7c882d841f0b7b65ad6 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 29 Mar 2018 19:44:57 -0400 Subject: [PATCH 69/99] surface: fix texture not updated on commit When a client attaches a wl_drm or a linux_dmabuf buffer, we only update it if the size is different from the one of the old buffer. This means that if the client attaches a new, updated buffer with the same size as the old buffer, the texture won't get updated. This commit changes this behavior and re-creates the texture if the client attaches a new buffer, without requiring the size to be different. --- types/wlr_surface.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 3be7bdfc..672e6fea 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -331,7 +331,7 @@ static void wlr_surface_damage_subsurfaces(struct wlr_subsurface *subsurface) { } static void wlr_surface_apply_damage(struct wlr_surface *surface, - bool reupload_buffer) { + bool invalid_buffer, bool reupload_buffer) { struct wl_resource *resource = surface->current->buffer; if (resource == NULL) { return; @@ -374,7 +374,7 @@ static void wlr_surface_apply_damage(struct wlr_surface *surface, } wl_shm_buffer_end_access(buf); - } else if (!surface->texture || reupload_buffer) { + } else if (invalid_buffer || reupload_buffer) { wlr_texture_destroy(surface->texture); if (wlr_renderer_resource_is_wl_drm_buffer(surface->renderer, resource)) { @@ -398,9 +398,8 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) { int32_t oldw = surface->current->buffer_width; int32_t oldh = surface->current->buffer_height; - bool null_buffer_commit = - (surface->pending->invalid & WLR_SURFACE_INVALID_BUFFER && - surface->pending->buffer == NULL); + bool invalid_buffer = surface->pending->invalid & WLR_SURFACE_INVALID_BUFFER; + bool null_buffer_commit = invalid_buffer && surface->pending->buffer == NULL; wlr_surface_move_state(surface, surface->pending, surface->current); @@ -411,7 +410,7 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) { bool reupload_buffer = oldw != surface->current->buffer_width || oldh != surface->current->buffer_height; - wlr_surface_apply_damage(surface, reupload_buffer); + wlr_surface_apply_damage(surface, invalid_buffer, reupload_buffer); // commit subsurface order struct wlr_subsurface *subsurface; From 865b0aa123172852b49df4178437e6e8a020bc60 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 30 Mar 2018 11:01:23 -0400 Subject: [PATCH 70/99] 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(-) 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; } - From 47a529a69c410e494fba46a4e6932a117728ba23 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 30 Mar 2018 12:31:16 -0400 Subject: [PATCH 71/99] output-damage: fix missing wlr_box include --- include/wlr/types/wlr_output_damage.h | 1 + 1 file changed, 1 insertion(+) 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 /** From 662f40b8ae2ccb449b13074317b59f0e53c1ccc5 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Mar 2018 15:19:33 -0400 Subject: [PATCH 72/99] Refactor cursor event passhtrough --- include/rootston/desktop.h | 4 ++ rootston/cursor.c | 117 ++++++++++++++++++------------------- rootston/desktop.c | 19 ++++++ 3 files changed, 80 insertions(+), 60 deletions(-) diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 5714aa0a..5816df48 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -73,8 +73,12 @@ struct roots_desktop *desktop_create(struct roots_server *server, void desktop_destroy(struct roots_desktop *desktop); struct roots_output *desktop_output_from_wlr_output( struct roots_desktop *desktop, struct wlr_output *output); + struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy); +struct wlr_surface *desktop_surface_at(struct roots_desktop *desktop, + double lx, double ly, double *sx, double *sy, + struct roots_view **view); struct roots_view *view_create(struct roots_desktop *desktop); void view_destroy(struct roots_view *view); diff --git a/rootston/cursor.c b/rootston/cursor.c index c794cbce..1a7526d1 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -10,6 +10,7 @@ #include #endif #include "rootston/cursor.h" +#include "rootston/desktop.h" #include "rootston/xcursor.h" struct roots_cursor *roots_cursor_create(struct roots_seat *seat) { @@ -98,51 +99,56 @@ static void seat_view_deco_button(struct roots_seat_view *view, double sx, } } -static void roots_cursor_update_position(struct roots_cursor *cursor, +static void roots_passthrough_cursor(struct roots_cursor *cursor, uint32_t time) { - struct roots_desktop *desktop = cursor->seat->input->server->desktop; - struct roots_seat *seat = cursor->seat; struct roots_view *view; - struct wlr_surface *surface = NULL; double sx, sy; - switch (cursor->mode) { - case ROOTS_CURSOR_PASSTHROUGH: - view = desktop_view_at(desktop, cursor->cursor->x, cursor->cursor->y, - &surface, &sx, &sy); + + struct roots_seat *seat = cursor->seat; + struct roots_desktop *desktop = seat->input->server->desktop; + struct wlr_surface *surface = desktop_surface_at(desktop, + cursor->cursor->x, cursor->cursor->y, &sx, &sy, &view); + + if (!surface && cursor->cursor_client) { + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, + cursor->default_xcursor, cursor->cursor); + cursor->cursor_client = NULL; + } + + if (view) { struct roots_seat_view *seat_view = roots_seat_view_from_view(seat, view); - if (cursor->pointer_view && (surface || seat_view != cursor->pointer_view)) { + if (cursor->pointer_view && (surface || + seat_view != cursor->pointer_view)) { seat_view_deco_leave(cursor->pointer_view); cursor->pointer_view = NULL; } - bool set_compositor_cursor = !view && !surface && cursor->cursor_client; - if (view && surface) { - struct wl_client *view_client = - wl_resource_get_client(view->wlr_surface->resource); - set_compositor_cursor = view_client != cursor->cursor_client; - } - if (set_compositor_cursor) { - wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, - cursor->default_xcursor, cursor->cursor); - cursor->cursor_client = NULL; - } - if (view && !surface) { - if (seat_view) { - cursor->pointer_view = seat_view; - seat_view_deco_motion(seat_view, sx, sy); - } - } if (view && surface) { - // motion over a view surface - wlr_seat_pointer_notify_enter(seat->seat, surface, sx, sy); - wlr_seat_pointer_notify_motion(seat->seat, time, sx, sy); - } else { - wlr_seat_pointer_clear_focus(seat->seat); + if (!surface) { + cursor->pointer_view = seat_view; + seat_view_deco_motion(seat_view, sx, sy); } + } - struct roots_drag_icon *drag_icon; - wl_list_for_each(drag_icon, &seat->drag_icons, link) { - roots_drag_icon_update_position(drag_icon); - } + if (surface) { + wlr_seat_pointer_notify_enter(seat->seat, surface, sx, sy); + wlr_seat_pointer_notify_motion(seat->seat, time, sx, sy); + } else { + wlr_seat_pointer_clear_focus(seat->seat); + } + + struct roots_drag_icon *drag_icon; + wl_list_for_each(drag_icon, &seat->drag_icons, link) { + roots_drag_icon_update_position(drag_icon); + } +} + +static void roots_cursor_update_position( + struct roots_cursor *cursor, uint32_t time) { + struct roots_seat *seat = cursor->seat; + struct roots_view *view; + switch (cursor->mode) { + case ROOTS_CURSOR_PASSTHROUGH: + roots_passthrough_cursor(cursor, time); break; case ROOTS_CURSOR_MOVE: view = roots_seat_get_focus(seat); @@ -180,15 +186,9 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, } else if (cursor->resize_edges & WLR_EDGE_RIGHT) { width += dx; } - - if (width < 1) { - width = 1; - } - if (height < 1) { - height = 1; - } - - view_move_resize(view, x, y, width, height); + view_move_resize(view, x, y, + width < 1 ? 1 : width, + height < 1 ? 1 : height); } break; case ROOTS_CURSOR_ROTATE: @@ -214,15 +214,15 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, uint32_t state, double lx, double ly) { struct roots_seat *seat = cursor->seat; struct roots_desktop *desktop = seat->input->server->desktop; + bool is_touch = device->type == WLR_INPUT_DEVICE_TOUCH; - struct wlr_surface *surface = NULL; double sx, sy; - struct roots_view *view = - desktop_view_at(desktop, lx, ly, &surface, &sx, &sy); + struct roots_view *view; + struct wlr_surface *surface = desktop_surface_at(desktop, + lx, ly, &sx, &sy, &view); - if (state == WLR_BUTTON_PRESSED && - view && + if (state == WLR_BUTTON_PRESSED && view && roots_seat_has_meta_pressed(seat)) { roots_seat_set_focus(seat, view); @@ -250,11 +250,9 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, break; } } else { - - if (view && !surface) { - if (cursor->pointer_view) { - seat_view_deco_button(cursor->pointer_view, sx, sy, button, state); - } + if (view && !surface && cursor->pointer_view) { + seat_view_deco_button(cursor->pointer_view, + sx, sy, button, state); } if (state == WLR_BUTTON_RELEASED && @@ -308,7 +306,6 @@ void roots_cursor_handle_axis(struct roots_cursor *cursor, void roots_cursor_handle_touch_down(struct roots_cursor *cursor, struct wlr_event_touch_down *event) { 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, event->y, &lx, &ly); @@ -316,7 +313,8 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor, return; } double sx, sy; - desktop_view_at(desktop, lx, ly, &surface, &sx, &sy); + struct wlr_surface *surface = desktop_surface_at( + desktop, lx, ly, &sx, &sy, NULL); uint32_t serial = 0; if (surface) { @@ -359,17 +357,16 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, return; } - struct wlr_surface *surface = NULL; double lx, ly; - bool result = - wlr_cursor_absolute_to_layout_coords(cursor->cursor, + bool result = wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device, event->x, event->y, &lx, &ly); if (!result) { return; } double sx, sy; - desktop_view_at(desktop, lx, ly, &surface, &sx, &sy); + struct wlr_surface *surface = desktop_surface_at( + desktop, lx, ly, &sx, &sy, NULL); if (surface) { wlr_seat_touch_point_focus(cursor->seat->seat, surface, diff --git a/rootston/desktop.c b/rootston/desktop.c index 15e0e336..532e720b 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -657,6 +657,25 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, return NULL; } +struct wlr_surface *desktop_surface_at(struct roots_desktop *desktop, + double lx, double ly, double *sx, double *sy, + struct roots_view **view) { + //struct wlr_output *wlr_output = + // wlr_output_layout_output_at(desktop->layout, lx, ly); + // TODO: Iterate over layers + *view = NULL; + struct roots_view *_view; + struct wlr_surface *surface = NULL; + if ((_view = desktop_view_at(desktop, lx, ly, &surface, sx, sy))) { + if (view) { + *view = _view; + } + return surface; + } + // TODO: Iterate over layers + return NULL; +} + static void handle_layout_change(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = wl_container_of(listener, desktop, layout_change); From dc412c514b88d253dc86cf72a574530e12b7dcb7 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Mar 2018 16:54:37 -0400 Subject: [PATCH 73/99] Find layer surfaces for input events --- include/rootston/desktop.h | 3 -- include/rootston/output.h | 1 - rootston/desktop.c | 71 ++++++++++++++++++++++++++++++++++---- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 5816df48..c1dcad56 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -1,6 +1,5 @@ #ifndef ROOTSTON_DESKTOP_H #define ROOTSTON_DESKTOP_H - #include #include #include @@ -74,8 +73,6 @@ void desktop_destroy(struct roots_desktop *desktop); struct roots_output *desktop_output_from_wlr_output( struct roots_desktop *desktop, struct wlr_output *output); -struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, - double ly, struct wlr_surface **surface, double *sx, double *sy); struct wlr_surface *desktop_surface_at(struct roots_desktop *desktop, double lx, double ly, double *sx, double *sy, struct roots_view **view); diff --git a/include/rootston/output.h b/include/rootston/output.h index bf152038..f78ee81d 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -1,6 +1,5 @@ #ifndef ROOTSTON_OUTPUT_H #define ROOTSTON_OUTPUT_H - #include #include #include diff --git a/rootston/desktop.c b/rootston/desktop.c index 532e720b..aa06000c 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -20,10 +20,12 @@ #include #include #include +#include "rootston/layers.h" #include "rootston/seat.h" #include "rootston/server.h" #include "rootston/view.h" #include "rootston/xcursor.h" +#include "wlr-layer-shell-unstable-v1-protocol.h" struct roots_view *view_create(struct roots_desktop *desktop) { struct roots_view *view = calloc(1, sizeof(struct roots_view)); @@ -632,8 +634,9 @@ static bool view_at(struct roots_view *view, double lx, double ly, return false; } -struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, - double ly, struct wlr_surface **surface, double *sx, double *sy) { +static struct roots_view *desktop_view_at(struct roots_desktop *desktop, + double lx, double ly, struct wlr_surface **surface, + double *sx, double *sy) { struct wlr_output *wlr_output = wlr_output_layout_output_at(desktop->layout, lx, ly); if (wlr_output != NULL) { @@ -657,22 +660,76 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, return NULL; } +static struct wlr_surface *layer_surface_at(struct roots_output *output, + struct wl_list *layer, double ox, double oy, double *sx, double *sy) { + struct roots_layer_surface *roots_surface; + wl_list_for_each_reverse(roots_surface, layer, link) { + struct wlr_surface *wlr_surface = + roots_surface->layer_surface->surface; + double _sx = ox - roots_surface->geo.x; + double _sy = oy - roots_surface->geo.y; + struct wlr_box box = { + .x = 0, .y = 0, + .width = roots_surface->geo.width, + .height = roots_surface->geo.height, + }; + // TODO: Test popups/subsurfaces + if (wlr_box_contains_point(&box, _sx, _sy) && + pixman_region32_contains_point(&wlr_surface->current->input, + _sx, _sy, NULL)) { + *sx = _sx; + *sy = _sy; + return wlr_surface; + } + } + return NULL; +} + struct wlr_surface *desktop_surface_at(struct roots_desktop *desktop, double lx, double ly, double *sx, double *sy, struct roots_view **view) { - //struct wlr_output *wlr_output = - // wlr_output_layout_output_at(desktop->layout, lx, ly); - // TODO: Iterate over layers + struct wlr_surface *surface = NULL; + struct wlr_output *wlr_output = + wlr_output_layout_output_at(desktop->layout, lx, ly); + struct roots_output *roots_output; + double ox, oy; + if (wlr_output) { + roots_output = wlr_output->data; + wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy); + + if ((surface = layer_surface_at(roots_output, + &roots_output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], + ox, oy, sx, sy))) { + return surface; + } + if ((surface = layer_surface_at(roots_output, + &roots_output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], + ox, oy, sx, sy))) { + return surface; + } + } + *view = NULL; struct roots_view *_view; - struct wlr_surface *surface = NULL; if ((_view = desktop_view_at(desktop, lx, ly, &surface, sx, sy))) { if (view) { *view = _view; } return surface; } - // TODO: Iterate over layers + + if (wlr_output) { + if ((surface = layer_surface_at(roots_output, + &roots_output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], + ox, oy, sx, sy))) { + return surface; + } + if ((surface = layer_surface_at(roots_output, + &roots_output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], + ox, oy, sx, sy))) { + return surface; + } + } return NULL; } From c9ed6fed59bb297d1393fdca790ae433bc6f09f9 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Fri, 30 Mar 2018 23:43:16 +0300 Subject: [PATCH 74/99] Fix build error with -O2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ../render/gles2/renderer.c: In function ‘gles2_render_texture_with_matrix’: ../render/gles2/renderer.c:140:2: error: ‘target’ may be used uninitialized in this function [-Werror=maybe-uninitialized] glBindTexture(target, tex_id); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../render/gles2/renderer.c:145:2: error: ‘prog’ may be used uninitialized in this function [-Werror=maybe-uninitialized] glUseProgram(prog); --- render/gles2/renderer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index f96f468b..8f3ce7f7 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -111,8 +111,8 @@ static bool gles2_render_texture_with_matrix(struct wlr_renderer *wlr_renderer, struct wlr_gles2_texture *texture = gles2_get_texture_in_context(wlr_texture); - GLuint prog; - GLenum target; + GLuint prog = 0; + GLenum target = 0; switch (texture->type) { case WLR_GLES2_TEXTURE_GLTEX: case WLR_GLES2_TEXTURE_WL_DRM_GL: From e3eb487dc2c3ed51b974212ddb15ce839289eba2 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Mar 2018 17:26:58 -0400 Subject: [PATCH 75/99] Add pointer support to layer shell example --- examples/layer-shell.c | 149 ++++++++++++++++++++++++++++++++++++++--- examples/meson.build | 3 +- rootston/desktop.c | 11 +-- 3 files changed, 148 insertions(+), 15 deletions(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index 70407888..6e293f55 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -7,12 +7,17 @@ #include #include #include +#include #include #include #include #include "wlr-layer-shell-unstable-v1-client-protocol.h" static struct wl_compositor *compositor = NULL; +static struct wl_seat *seat = NULL; +static struct wl_shm *shm = NULL; +static struct wl_pointer *pointer = NULL; +//static struct wl_keyboard *keyboard = NULL; static struct zwlr_layer_shell_v1 *layer_shell = NULL; struct zwlr_layer_surface_v1 *layer_surface; static struct wl_output *wl_output = NULL; @@ -32,6 +37,12 @@ static double alpha = 1.0; static bool run_display = true; static bool animate = false; static double frame = 0; +static int cur_x = -1, cur_y = -1; +static int buttons = 0; + +struct wl_cursor_theme *cursor_theme; +struct wl_cursor_image *cursor_image; +struct wl_surface *cursor_surface; static struct { struct timespec last_frame; @@ -62,13 +73,15 @@ static void draw(void) { (ts.tv_nsec - demo.last_frame.tv_nsec) / 1000000; int inc = (demo.dec + 1) % 3; - demo.color[inc] += ms / 2000.0f; - demo.color[demo.dec] -= ms / 2000.0f; + if (!buttons) { + demo.color[inc] += ms / 2000.0f; + demo.color[demo.dec] -= ms / 2000.0f; - if (demo.color[demo.dec] < 0.0f) { - demo.color[inc] = 1.0f; - demo.color[demo.dec] = 0.0f; - demo.dec = inc; + if (demo.color[demo.dec] < 0.0f) { + demo.color[inc] = 1.0f; + demo.color[demo.dec] = 0.0f; + demo.dec = inc; + } } if (animate) { @@ -83,9 +96,21 @@ static void draw(void) { } glViewport(0, 0, width, height); - glClearColor(demo.color[0], demo.color[1], demo.color[2], alpha); + if (buttons) { + glClearColor(1, 1, 1, alpha); + } else { + glClearColor(demo.color[0], demo.color[1], demo.color[2], alpha); + } glClear(GL_COLOR_BUFFER_BIT); + if (cur_x != -1 && cur_y != -1) { + glEnable(GL_SCISSOR_TEST); + glScissor(cur_x, height - cur_y, 5, 5); + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT); + glDisable(GL_SCISSOR_TEST); + } + frame_callback = wl_surface_frame(wl_surface); wl_callback_add_listener(frame_callback, &frame_listener, NULL); @@ -119,11 +144,101 @@ struct zwlr_layer_surface_v1_listener layer_surface_listener = { .closed = layer_surface_closed, }; +static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, + uint32_t serial, struct wl_surface *surface, + wl_fixed_t surface_x, wl_fixed_t surface_y) { + wl_surface_attach(cursor_surface, + wl_cursor_image_get_buffer(cursor_image), 0, 0); + wl_pointer_set_cursor(wl_pointer, serial, cursor_surface, + cursor_image->hotspot_x, cursor_image->hotspot_y); + wl_surface_commit(cursor_surface); +} + +static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, + uint32_t serial, struct wl_surface *surface) { + cur_x = cur_y = -1; +} + +static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, + uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { + cur_x = (int)wl_fixed_to_double(surface_x); + cur_y = (int)wl_fixed_to_double(surface_y); +} + +static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, + uint32_t serial, uint32_t time, uint32_t button, uint32_t state) { + if (state == WL_POINTER_BUTTON_STATE_PRESSED) { + buttons++; + } else { + buttons--; + } +} + +static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, + uint32_t time, uint32_t axis, wl_fixed_t value) { + // Who cares +} + +static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) { + // Who cares +} + +static void wl_pointer_axis_source(void *data, struct wl_pointer *wl_pointer, + uint32_t axis_source) { + // Who cares +} + +static void wl_pointer_axis_stop(void *data, struct wl_pointer *wl_pointer, + uint32_t time, uint32_t axis) { + // Who cares +} + +static void wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer, + uint32_t axis, int32_t discrete) { + // Who cares +} + +struct wl_pointer_listener pointer_listener = { + .enter = wl_pointer_enter, + .leave = wl_pointer_leave, + .motion = wl_pointer_motion, + .button = wl_pointer_button, + .axis = wl_pointer_axis, + .frame = wl_pointer_frame, + .axis_source = wl_pointer_axis_source, + .axis_stop = wl_pointer_axis_stop, + .axis_discrete = wl_pointer_axis_discrete, +}; + +static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, + enum wl_seat_capability caps) { + if ((caps & WL_SEAT_CAPABILITY_POINTER)) { + pointer = wl_seat_get_pointer(wl_seat); + wl_pointer_add_listener(pointer, &pointer_listener, NULL); + } + if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) { + // TODO + } +} + +static void seat_handle_name(void *data, struct wl_seat *wl_seat, + const char *name) { + // Who cares +} + +const struct wl_seat_listener seat_listener = { + .capabilities = seat_handle_capabilities, + .name = seat_handle_name, +}; + static void handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { if (strcmp(interface, "wl_compositor") == 0) { compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1); + } else if (strcmp(interface, wl_shm_interface.name) == 0) { + shm = wl_registry_bind(registry, name, + &wl_shm_interface, 1); } else if (strcmp(interface, "wl_output") == 0) { if (output == 0 && !wl_output) { wl_output = wl_registry_bind(registry, name, @@ -131,6 +246,10 @@ static void handle_global(void *data, struct wl_registry *registry, } else { output--; } + } else if (strcmp(interface, wl_seat_interface.name) == 0) { + seat = wl_registry_bind(registry, name, + &wl_seat_interface, 1); + wl_seat_add_listener(seat, &seat_listener, NULL); } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { layer_shell = wl_registry_bind( registry, name, &zwlr_layer_shell_v1_interface, 1); @@ -250,11 +369,15 @@ int main(int argc, char **argv) { wl_display_roundtrip(display); if (compositor == NULL) { - fprintf(stderr, "wl-compositor not available\n"); + fprintf(stderr, "wl_compositor not available\n"); + return 1; + } + if (shm == NULL) { + fprintf(stderr, "wl_shm not available\n"); return 1; } if (layer_shell == NULL) { - fprintf(stderr, "layer-shell not available\n"); + fprintf(stderr, "layer_shell not available\n"); return 1; } if (wl_output == NULL) { @@ -262,6 +385,12 @@ int main(int argc, char **argv) { return 1; } + assert(cursor_theme = wl_cursor_theme_load(NULL, 16, shm)); + struct wl_cursor *cursor; + assert(cursor = wl_cursor_theme_get_cursor(cursor_theme, "left_ptr")); + cursor_image = cursor->images[0]; + assert(cursor_surface = wl_compositor_create_surface(compositor)); + EGLint attribs[] = { EGL_ALPHA_SIZE, 8, EGL_NONE }; wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, attribs, WL_SHM_FORMAT_ARGB8888); @@ -294,5 +423,7 @@ int main(int argc, char **argv) { while (wl_display_dispatch(display) != -1 && run_display) { // This space intentionally left blank } + + wl_cursor_theme_destroy(cursor_theme); return 0; } diff --git a/examples/meson.build b/examples/meson.build index 558af4ac..9e60c37a 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -6,6 +6,7 @@ lib_shared = static_library( ) threads = dependency('threads') +wayland_cursor = dependency('wayland-cursor') executable('simple', 'simple.c', dependencies: wlroots, link_with: lib_shared) executable('pointer', 'pointer.c', dependencies: wlroots, link_with: lib_shared) @@ -52,5 +53,5 @@ executable( executable( 'layer-shell', 'layer-shell.c', - dependencies: [wayland_client, wlr_protos, wlroots] + dependencies: [wayland_cursor, wayland_client, wlr_protos, wlroots] ) diff --git a/rootston/desktop.c b/rootston/desktop.c index aa06000c..45bf8105 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -669,12 +669,13 @@ static struct wlr_surface *layer_surface_at(struct roots_output *output, double _sx = ox - roots_surface->geo.x; double _sy = oy - roots_surface->geo.y; struct wlr_box box = { - .x = 0, .y = 0, - .width = roots_surface->geo.width, - .height = roots_surface->geo.height, + .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, _sx, _sy) && + if (wlr_box_contains_point(&box, ox, oy) && pixman_region32_contains_point(&wlr_surface->current->input, _sx, _sy, NULL)) { *sx = _sx; @@ -692,7 +693,7 @@ struct wlr_surface *desktop_surface_at(struct roots_desktop *desktop, struct wlr_output *wlr_output = wlr_output_layout_output_at(desktop->layout, lx, ly); struct roots_output *roots_output; - double ox, oy; + double ox = lx, oy = ly; if (wlr_output) { roots_output = wlr_output->data; wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy); From 168f65fb7a336c7f7067bfd56413b2d19556c8bf Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Mar 2018 18:28:21 -0400 Subject: [PATCH 76/99] Minor bugfixes --- examples/layer-shell.c | 1 + rootston/desktop.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index 6e293f55..3f955be4 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -157,6 +157,7 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface) { cur_x = cur_y = -1; + buttons = 0; } static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, diff --git a/rootston/desktop.c b/rootston/desktop.c index 45bf8105..7ee2c69a 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -694,6 +694,8 @@ struct wlr_surface *desktop_surface_at(struct roots_desktop *desktop, wlr_output_layout_output_at(desktop->layout, lx, ly); struct roots_output *roots_output; double ox = lx, oy = ly; + *view = NULL; + if (wlr_output) { roots_output = wlr_output->data; wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy); @@ -710,7 +712,6 @@ struct wlr_surface *desktop_surface_at(struct roots_desktop *desktop, } } - *view = NULL; struct roots_view *_view; if ((_view = desktop_view_at(desktop, lx, ly, &surface, sx, sy))) { if (view) { From 746e3759b7a350a5e9124f365cac0279810781d1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Mar 2018 19:33:57 -0400 Subject: [PATCH 77/99] Address review feedback --- examples/layer-shell.c | 4 ++-- rootston/cursor.c | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index 3f955be4..89fa9ea9 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -162,8 +162,8 @@ static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { - cur_x = (int)wl_fixed_to_double(surface_x); - cur_y = (int)wl_fixed_to_double(surface_y); + cur_x = wl_fixed_to_int(surface_x); + cur_y = wl_fixed_to_int(surface_y); } static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, diff --git a/rootston/cursor.c b/rootston/cursor.c index 1a7526d1..1ee195c2 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -101,18 +101,21 @@ static void seat_view_deco_button(struct roots_seat_view *view, double sx, static void roots_passthrough_cursor(struct roots_cursor *cursor, uint32_t time) { - struct roots_view *view; double sx, sy; - + struct roots_view *view = NULL; struct roots_seat *seat = cursor->seat; struct roots_desktop *desktop = seat->input->server->desktop; struct wlr_surface *surface = desktop_surface_at(desktop, cursor->cursor->x, cursor->cursor->y, &sx, &sy, &view); + struct wl_client *client = NULL; + if (surface) { + client = wl_resource_get_client(surface->resource); + } - if (!surface && cursor->cursor_client) { + if (cursor->cursor_client != client) { wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, cursor->default_xcursor, cursor->cursor); - cursor->cursor_client = NULL; + cursor->cursor_client = client; } if (view) { From 2053a4c144bdde2df5cb7b6b7036cde008372493 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Mar 2018 21:02:28 -0400 Subject: [PATCH 78/99] Add more exotic cursor for layer shell example So it's more obvious that it's being set --- examples/layer-shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/layer-shell.c b/examples/layer-shell.c index 89fa9ea9..f084d10f 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -388,7 +388,7 @@ int main(int argc, char **argv) { assert(cursor_theme = wl_cursor_theme_load(NULL, 16, shm)); struct wl_cursor *cursor; - assert(cursor = wl_cursor_theme_get_cursor(cursor_theme, "left_ptr")); + assert(cursor = wl_cursor_theme_get_cursor(cursor_theme, "crosshair")); cursor_image = cursor->images[0]; assert(cursor_surface = wl_compositor_create_surface(compositor)); From e19ee6d469a98d2957e614243ea30674be1977f7 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Mar 2018 22:19:33 -0400 Subject: [PATCH 79/99] 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(-) 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); +} From d4f7ced6e260961f701f73f672fffa87ee333c3d Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 30 Mar 2018 21:40:43 -0400 Subject: [PATCH 80/99] backend/x11: refactor, prepare support for multiple outputs --- backend/meson.build | 6 +- backend/x11/backend.c | 300 ++++++------------------------------- backend/x11/input_device.c | 122 +++++++++++++++ backend/x11/output.c | 170 +++++++++++++++++++++ include/backend/x11.h | 24 ++- 5 files changed, 365 insertions(+), 257 deletions(-) create mode 100644 backend/x11/input_device.c create mode 100644 backend/x11/output.c diff --git a/backend/meson.build b/backend/meson.build index df12d703..52abe64d 100644 --- a/backend/meson.build +++ b/backend/meson.build @@ -50,7 +50,11 @@ if conf_data.get('WLR_HAS_SYSTEMD', false) endif if conf_data.get('WLR_HAS_X11_BACKEND', false) - backend_files += files('x11/backend.c') + backend_files += files( + 'x11/backend.c', + 'x11/input_device.c', + 'x11/output.c', + ) backend_deps += xcb_xkb endif diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 8abc5d84..c72cdcac 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -1,5 +1,4 @@ #define _POSIX_C_SOURCE 200112L -#include #include #include #include @@ -10,162 +9,66 @@ #include #include #include -#include #include #include #include #include #include #include -#ifdef __linux__ -#include -#elif __FreeBSD__ -#include -#endif #ifdef WLR_HAS_XCB_XKB #include #endif #include "backend/x11.h" #include "util/signal.h" -#define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f - -static const struct wlr_backend_impl backend_impl; -static const struct wlr_output_impl output_impl; -static const struct wlr_input_device_impl input_device_impl = { 0 }; - -static uint32_t xcb_button_to_wl(uint32_t button) { - switch (button) { - case XCB_BUTTON_INDEX_1: return BTN_LEFT; - case XCB_BUTTON_INDEX_2: return BTN_MIDDLE; - case XCB_BUTTON_INDEX_3: return BTN_RIGHT; - // XXX: I'm not sure the scroll-wheel direction is right - case XCB_BUTTON_INDEX_4: return BTN_GEAR_UP; - case XCB_BUTTON_INDEX_5: return BTN_GEAR_DOWN; - default: return 0; +struct wlr_x11_output *x11_output_from_window_id(struct wlr_x11_backend *x11, + xcb_window_t window) { + struct wlr_x11_output *output; + wl_list_for_each(output, &x11->outputs, link) { + if (output->win == window) { + return output; + } } + return NULL; } -static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *event) { - struct wlr_x11_output *output = &x11->output; +static bool handle_x11_event(struct wlr_x11_backend *x11, + xcb_generic_event_t *event) { + if (x11_handle_input_event(x11, event)) { + return false; + } switch (event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK) { case XCB_EXPOSE: { - wlr_output_send_frame(&output->wlr_output); - break; - } - case XCB_KEY_PRESS: - case XCB_KEY_RELEASE: { - xcb_key_press_event_t *ev = (xcb_key_press_event_t *)event; - struct wlr_event_keyboard_key key = { - .time_msec = ev->time, - .keycode = ev->detail - 8, - .state = event->response_type == XCB_KEY_PRESS ? - WLR_KEY_PRESSED : WLR_KEY_RELEASED, - .update_state = true, - }; - - // TODO use xcb-xkb for more precise modifiers state? - wlr_keyboard_notify_key(&x11->keyboard, &key); - x11->time = ev->time; - break; - } - case XCB_BUTTON_PRESS: { - xcb_button_press_event_t *ev = (xcb_button_press_event_t *)event; - - if (ev->detail == XCB_BUTTON_INDEX_4 || - ev->detail == XCB_BUTTON_INDEX_5) { - double delta = (ev->detail == XCB_BUTTON_INDEX_4 ? -15 : 15); - struct wlr_event_pointer_axis axis = { - .device = &x11->pointer_dev, - .time_msec = ev->time, - .source = WLR_AXIS_SOURCE_WHEEL, - .orientation = WLR_AXIS_ORIENTATION_VERTICAL, - .delta = delta, - }; - wlr_signal_emit_safe(&x11->pointer.events.axis, &axis); - x11->time = ev->time; - break; + xcb_expose_event_t *ev = (xcb_expose_event_t *)event; + struct wlr_x11_output *output = + x11_output_from_window_id(x11, ev->window); + if (output != NULL) { + wlr_output_send_frame(&output->wlr_output); } - } - /* fallthrough */ - case XCB_BUTTON_RELEASE: { - xcb_button_press_event_t *ev = (xcb_button_press_event_t *)event; - - if (ev->detail != XCB_BUTTON_INDEX_4 && - ev->detail != XCB_BUTTON_INDEX_5) { - struct wlr_event_pointer_button button = { - .device = &x11->pointer_dev, - .time_msec = ev->time, - .button = xcb_button_to_wl(ev->detail), - .state = event->response_type == XCB_BUTTON_PRESS ? - WLR_BUTTON_PRESSED : WLR_BUTTON_RELEASED, - }; - - wlr_signal_emit_safe(&x11->pointer.events.button, &button); - } - x11->time = ev->time; - break; - } - case XCB_MOTION_NOTIFY: { - xcb_motion_notify_event_t *ev = (xcb_motion_notify_event_t *)event; - struct wlr_event_pointer_motion_absolute abs = { - .device = &x11->pointer_dev, - .time_msec = ev->time, - .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); - x11->time = ev->time; break; } case XCB_CONFIGURE_NOTIFY: { - xcb_configure_notify_event_t *ev = (xcb_configure_notify_event_t *)event; - - wlr_output_update_custom_mode(&output->wlr_output, ev->width, - ev->height, 0); - - // Move the pointer to its new location - xcb_query_pointer_cookie_t cookie = - xcb_query_pointer(x11->xcb_conn, output->win); - xcb_query_pointer_reply_t *pointer = - xcb_query_pointer_reply(x11->xcb_conn, cookie, NULL); - if (!pointer) { - break; + xcb_configure_notify_event_t *ev = + (xcb_configure_notify_event_t *)event; + struct wlr_x11_output *output = + x11_output_from_window_id(x11, ev->window); + if (output != NULL) { + x11_output_handle_configure_notify(output, ev); } - - struct wlr_event_pointer_motion_absolute abs = { - .device = &x11->pointer_dev, - .time_msec = x11->time, - .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); - free(pointer); break; } case XCB_CLIENT_MESSAGE: { xcb_client_message_event_t *ev = (xcb_client_message_event_t *)event; - if (ev->data.data32[0] == x11->atoms.wm_delete_window) { - wl_display_terminate(x11->wl_display); - return true; + struct wlr_x11_output *output = + x11_output_from_window_id(x11, ev->window); + if (output != NULL) { + wlr_output_destroy(&output->wlr_output); + } } - break; } - default: -#ifdef WLR_HAS_XCB_XKB - if (x11->xkb_supported && event->response_type == x11->xkb_base_event) { - xcb_xkb_state_notify_event_t *ev = - (xcb_xkb_state_notify_event_t *)event; - wlr_keyboard_notify_modifiers(&x11->keyboard, ev->baseMods, - ev->latchedMods, ev->lockedMods, ev->lockedGroup); - } -#endif - break; } return false; @@ -180,64 +83,19 @@ static int x11_event(int fd, uint32_t mask, void *data) { } xcb_generic_event_t *e; - bool quit = false; - while (!quit && (e = xcb_poll_for_event(x11->xcb_conn))) { - quit = handle_x11_event(x11, e); + while ((e = xcb_poll_for_event(x11->xcb_conn))) { + bool quit = handle_x11_event(x11, e); free(e); + if (quit) { + break; + } } return 0; } -static int signal_frame(void *data) { - struct wlr_x11_backend *x11 = data; - wlr_output_send_frame(&x11->output.wlr_output); - wl_event_source_timer_update(x11->frame_timer, 16); - return 0; -} - -static void parse_xcb_setup(struct wlr_output *output, xcb_connection_t *xcb_conn) { - const xcb_setup_t *xcb_setup = xcb_get_setup(xcb_conn); - - snprintf(output->make, sizeof(output->make), "%.*s", - xcb_setup_vendor_length(xcb_setup), - xcb_setup_vendor(xcb_setup)); - snprintf(output->model, sizeof(output->model), "%"PRIu16".%"PRIu16, - xcb_setup->protocol_major_version, - xcb_setup->protocol_minor_version); -} - static bool wlr_x11_backend_start(struct wlr_backend *backend) { struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; - struct wlr_x11_output *output = &x11->output; - - uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; - uint32_t values[2] = { - x11->screen->white_pixel, - XCB_EVENT_MASK_EXPOSURE | - XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE | - XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | - XCB_EVENT_MASK_POINTER_MOTION | - XCB_EVENT_MASK_STRUCTURE_NOTIFY - }; - - output->x11 = x11; - - wlr_output_init(&output->wlr_output, &x11->backend, &output_impl, - x11->wl_display); - snprintf(output->wlr_output.name, sizeof(output->wlr_output.name), "X11-1"); - parse_xcb_setup(&output->wlr_output, x11->xcb_conn); - - output->win = xcb_generate_id(x11->xcb_conn); - xcb_create_window(x11->xcb_conn, XCB_COPY_FROM_PARENT, output->win, - x11->screen->root, 0, 0, 1024, 768, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, - x11->screen->root_visual, mask, values); - - output->surf = wlr_egl_create_surface(&x11->egl, &output->win); - if (!output->surf) { - wlr_log(L_ERROR, "Failed to create EGL surface"); - return false; - } struct { const char *name; @@ -279,17 +137,6 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { } } - xcb_change_property(x11->xcb_conn, XCB_PROP_MODE_REPLACE, output->win, - x11->atoms.wm_protocols, XCB_ATOM_ATOM, 32, 1, - &x11->atoms.wm_delete_window); - - char title[32]; - if (snprintf(title, sizeof(title), "wlroots - %s", output->wlr_output.name)) { - xcb_change_property(x11->xcb_conn, XCB_PROP_MODE_REPLACE, output->win, - x11->atoms.net_wm_name, x11->atoms.utf8_string, 8, - strlen(title), title); - } - #ifdef WLR_HAS_XCB_XKB const xcb_query_extension_reply_t *reply = xcb_get_extension_data(x11->xcb_conn, &xcb_xkb_id); @@ -316,15 +163,12 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { } #endif - xcb_map_window(x11->xcb_conn, output->win); - xcb_flush(x11->xcb_conn); - wlr_output_update_enabled(&output->wlr_output, true); - - wlr_signal_emit_safe(&x11->backend.events.new_output, output); wlr_signal_emit_safe(&x11->backend.events.new_input, &x11->keyboard_dev); wlr_signal_emit_safe(&x11->backend.events.new_input, &x11->pointer_dev); - wl_event_source_timer_update(x11->frame_timer, 16); + for (size_t i = 0; i < x11->requested_outputs; ++i) { + x11_output_create(x11); + } return true; } @@ -336,8 +180,10 @@ static void wlr_x11_backend_destroy(struct wlr_backend *backend) { struct wlr_x11_backend *x11 = (struct wlr_x11_backend *)backend; - struct wlr_x11_output *output = &x11->output; - wlr_output_destroy(&output->wlr_output); + struct wlr_x11_output *output, *tmp; + wl_list_for_each_safe(output, tmp, &x11->outputs, link) { + wlr_output_destroy(&output->wlr_output); + } wlr_signal_emit_safe(&x11->pointer_dev.events.destroy, &x11->pointer_dev); wlr_signal_emit_safe(&x11->keyboard_dev.events.destroy, &x11->keyboard_dev); @@ -357,7 +203,6 @@ static void wlr_x11_backend_destroy(struct wlr_backend *backend) { } wl_list_remove(&x11->display_destroy.link); - wl_event_source_remove(x11->frame_timer); wlr_egl_finish(&x11->egl); if (x11->xlib_conn) { @@ -403,6 +248,8 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, wlr_backend_init(&x11->backend, &backend_impl); x11->wl_display = display; + x11->requested_outputs = 1; + wl_list_init(&x11->outputs); x11->xlib_conn = XOpenDisplay(x11_display); if (!x11->xlib_conn) { @@ -427,8 +274,6 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, goto error_x11; } - x11->frame_timer = wl_event_loop_add_timer(ev, signal_frame, x11); - x11->screen = xcb_setup_roots_iterator(xcb_get_setup(x11->xcb_conn)).data; if (!wlr_egl_init(&x11->egl, EGL_PLATFORM_X11_KHR, x11->xlib_conn, NULL, @@ -439,6 +284,7 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, x11->renderer = wlr_gles2_renderer_create(&x11->backend); if (x11->renderer == NULL) { wlr_log(L_ERROR, "Failed to create renderer"); + goto error_egl; } wlr_input_device_init(&x11->keyboard_dev, WLR_INPUT_DEVICE_KEYBOARD, @@ -456,6 +302,8 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, return &x11->backend; +error_egl: + wlr_egl_finish(&x11->egl); error_event: wl_event_source_remove(x11->event_source); error_x11: @@ -463,59 +311,3 @@ error_x11: free(x11); return NULL; } - -static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width, - int32_t height, int32_t refresh) { - struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; - struct wlr_x11_backend *x11 = output->x11; - - const uint32_t values[] = { width, height }; - xcb_configure_window(x11->xcb_conn, output->win, - XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); - return true; -} - -static void output_transform(struct wlr_output *wlr_output, enum wl_output_transform transform) { - struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; - output->wlr_output.transform = transform; -} - -static void output_destroy(struct wlr_output *wlr_output) { - struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; - struct wlr_x11_backend *x11 = output->x11; - - eglDestroySurface(x11->egl.display, output->surf); - xcb_destroy_window(x11->xcb_conn, output->win); - // output has been allocated on the stack, do not free it -} - -static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) { - struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; - struct wlr_x11_backend *x11 = output->x11; - - return wlr_egl_make_current(&x11->egl, output->surf, buffer_age); -} - -static bool output_swap_buffers(struct wlr_output *wlr_output, - pixman_region32_t *damage) { - struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; - struct wlr_x11_backend *x11 = output->x11; - - return wlr_egl_swap_buffers(&x11->egl, output->surf, damage); -} - -static const struct wlr_output_impl output_impl = { - .set_custom_mode = output_set_custom_mode, - .transform = output_transform, - .destroy = output_destroy, - .make_current = output_make_current, - .swap_buffers = output_swap_buffers, -}; - -bool wlr_output_is_x11(struct wlr_output *wlr_output) { - return wlr_output->impl == &output_impl; -} - -bool wlr_input_device_is_x11(struct wlr_input_device *wlr_dev) { - return wlr_dev->impl == &input_device_impl; -} diff --git a/backend/x11/input_device.c b/backend/x11/input_device.c new file mode 100644 index 00000000..fb7f8b85 --- /dev/null +++ b/backend/x11/input_device.c @@ -0,0 +1,122 @@ +#include +#include +#include +#include +#include +#ifdef __linux__ +#include +#elif __FreeBSD__ +#include +#endif +#include "backend/x11.h" +#include "util/signal.h" + +static uint32_t xcb_button_to_wl(uint32_t button) { + switch (button) { + case XCB_BUTTON_INDEX_1: return BTN_LEFT; + case XCB_BUTTON_INDEX_2: return BTN_MIDDLE; + case XCB_BUTTON_INDEX_3: return BTN_RIGHT; + // XXX: I'm not sure the scroll-wheel direction is right + case XCB_BUTTON_INDEX_4: return BTN_GEAR_UP; + case XCB_BUTTON_INDEX_5: return BTN_GEAR_DOWN; + default: return 0; + } +} + +bool x11_handle_input_event(struct wlr_x11_backend *x11, + xcb_generic_event_t *event) { + switch (event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK) { + case XCB_KEY_PRESS: + case XCB_KEY_RELEASE: { + xcb_key_press_event_t *ev = (xcb_key_press_event_t *)event; + struct wlr_event_keyboard_key key = { + .time_msec = ev->time, + .keycode = ev->detail - 8, + .state = event->response_type == XCB_KEY_PRESS ? + WLR_KEY_PRESSED : WLR_KEY_RELEASED, + .update_state = true, + }; + + // TODO use xcb-xkb for more precise modifiers state? + wlr_keyboard_notify_key(&x11->keyboard, &key); + x11->time = ev->time; + return true; + } + case XCB_BUTTON_PRESS: { + xcb_button_press_event_t *ev = (xcb_button_press_event_t *)event; + + if (ev->detail == XCB_BUTTON_INDEX_4 || + ev->detail == XCB_BUTTON_INDEX_5) { + double delta = (ev->detail == XCB_BUTTON_INDEX_4 ? -15 : 15); + struct wlr_event_pointer_axis axis = { + .device = &x11->pointer_dev, + .time_msec = ev->time, + .source = WLR_AXIS_SOURCE_WHEEL, + .orientation = WLR_AXIS_ORIENTATION_VERTICAL, + .delta = delta, + }; + wlr_signal_emit_safe(&x11->pointer.events.axis, &axis); + x11->time = ev->time; + break; + } + } + /* fallthrough */ + case XCB_BUTTON_RELEASE: { + xcb_button_press_event_t *ev = (xcb_button_press_event_t *)event; + + if (ev->detail != XCB_BUTTON_INDEX_4 && + ev->detail != XCB_BUTTON_INDEX_5) { + struct wlr_event_pointer_button button = { + .device = &x11->pointer_dev, + .time_msec = ev->time, + .button = xcb_button_to_wl(ev->detail), + .state = event->response_type == XCB_BUTTON_PRESS ? + WLR_BUTTON_PRESSED : WLR_BUTTON_RELEASED, + }; + + wlr_signal_emit_safe(&x11->pointer.events.button, &button); + } + x11->time = ev->time; + return true; + } + case XCB_MOTION_NOTIFY: { + xcb_motion_notify_event_t *ev = (xcb_motion_notify_event_t *)event; + + struct wlr_x11_output *output = + x11_output_from_window_id(x11, ev->event); + if (output == NULL) { + return false; + } + + struct wlr_event_pointer_motion_absolute abs = { + .device = &x11->pointer_dev, + .time_msec = ev->time, + .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); + x11->time = ev->time; + return true; + } + default: +#ifdef WLR_HAS_XCB_XKB + if (x11->xkb_supported && event->response_type == x11->xkb_base_event) { + xcb_xkb_state_notify_event_t *ev = + (xcb_xkb_state_notify_event_t *)event; + wlr_keyboard_notify_modifiers(&x11->keyboard, ev->baseMods, + ev->latchedMods, ev->lockedMods, ev->lockedGroup); + return true; + } +#endif + break; + } + + return false; +} + +const struct wlr_input_device_impl input_device_impl = { 0 }; + +bool wlr_input_device_is_x11(struct wlr_input_device *wlr_dev) { + return wlr_dev->impl == &input_device_impl; +} diff --git a/backend/x11/output.c b/backend/x11/output.c new file mode 100644 index 00000000..f039baad --- /dev/null +++ b/backend/x11/output.c @@ -0,0 +1,170 @@ +#include +#include +#include +#include "backend/x11.h" +#include "util/signal.h" + +static int signal_frame(void *data) { + struct wlr_x11_output *output = data; + wlr_output_send_frame(&output->wlr_output); + wl_event_source_timer_update(output->frame_timer, output->frame_delay); + return 0; +} + +static void parse_xcb_setup(struct wlr_output *output, xcb_connection_t *xcb_conn) { + const xcb_setup_t *xcb_setup = xcb_get_setup(xcb_conn); + + snprintf(output->make, sizeof(output->make), "%.*s", + xcb_setup_vendor_length(xcb_setup), + xcb_setup_vendor(xcb_setup)); + snprintf(output->model, sizeof(output->model), "%"PRIu16".%"PRIu16, + xcb_setup->protocol_major_version, + xcb_setup->protocol_minor_version); +} + +static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width, + int32_t height, int32_t refresh) { + struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; + struct wlr_x11_backend *x11 = output->x11; + + wlr_output_update_custom_mode(&output->wlr_output, wlr_output->width, + wlr_output->height, refresh); + output->frame_delay = 1000000 / refresh; + + const uint32_t values[] = { width, height }; + xcb_configure_window(x11->xcb_conn, output->win, + XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values); + return true; +} + +static void output_transform(struct wlr_output *wlr_output, + enum wl_output_transform transform) { + struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; + output->wlr_output.transform = transform; +} + +static void output_destroy(struct wlr_output *wlr_output) { + struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; + struct wlr_x11_backend *x11 = output->x11; + + wl_list_remove(&output->link); + wl_event_source_remove(output->frame_timer); + eglDestroySurface(x11->egl.display, output->surf); + xcb_destroy_window(x11->xcb_conn, output->win); + free(output); +} + +static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) { + struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; + struct wlr_x11_backend *x11 = output->x11; + + return wlr_egl_make_current(&x11->egl, output->surf, buffer_age); +} + +static bool output_swap_buffers(struct wlr_output *wlr_output, + pixman_region32_t *damage) { + struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; + struct wlr_x11_backend *x11 = output->x11; + + return wlr_egl_swap_buffers(&x11->egl, output->surf, damage); +} + +static const struct wlr_output_impl output_impl = { + .set_custom_mode = output_set_custom_mode, + .transform = output_transform, + .destroy = output_destroy, + .make_current = output_make_current, + .swap_buffers = output_swap_buffers, +}; + +struct wlr_x11_output *x11_output_create(struct wlr_x11_backend *x11) { + 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"); + parse_xcb_setup(wlr_output, x11->xcb_conn); + + uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; + uint32_t values[2] = { + x11->screen->white_pixel, + XCB_EVENT_MASK_EXPOSURE | + XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE | + XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | + XCB_EVENT_MASK_POINTER_MOTION | + XCB_EVENT_MASK_STRUCTURE_NOTIFY + }; + output->win = xcb_generate_id(x11->xcb_conn); + xcb_create_window(x11->xcb_conn, XCB_COPY_FROM_PARENT, output->win, + x11->screen->root, 0, 0, 1024, 768, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, + x11->screen->root_visual, mask, values); + + output->surf = wlr_egl_create_surface(&x11->egl, &output->win); + if (!output->surf) { + wlr_log(L_ERROR, "Failed to create EGL surface"); + free(output); + return NULL; + } + + xcb_change_property(x11->xcb_conn, XCB_PROP_MODE_REPLACE, output->win, + x11->atoms.wm_protocols, XCB_ATOM_ATOM, 32, 1, + &x11->atoms.wm_delete_window); + + char title[32]; + if (snprintf(title, sizeof(title), "wlroots - %s", wlr_output->name)) { + xcb_change_property(x11->xcb_conn, XCB_PROP_MODE_REPLACE, output->win, + x11->atoms.net_wm_name, x11->atoms.utf8_string, 8, + strlen(title), title); + } + + xcb_map_window(x11->xcb_conn, output->win); + xcb_flush(x11->xcb_conn); + + struct wl_event_loop *ev = wl_display_get_event_loop(x11->wl_display); + output->frame_timer = wl_event_loop_add_timer(ev, signal_frame, output); + + wl_event_source_timer_update(output->frame_timer, output->frame_delay); + wlr_output_update_enabled(wlr_output, true); + + wl_list_insert(&x11->outputs, &output->link); + wlr_signal_emit_safe(&x11->backend.events.new_output, wlr_output); + + return output; +} + +void x11_output_handle_configure_notify(struct wlr_x11_output *output, + xcb_configure_notify_event_t *ev) { + struct wlr_x11_backend *x11 = output->x11; + + wlr_output_update_custom_mode(&output->wlr_output, ev->width, + ev->height, output->wlr_output.refresh); + + // Move the pointer to its new location + xcb_query_pointer_cookie_t cookie = + xcb_query_pointer(x11->xcb_conn, output->win); + xcb_query_pointer_reply_t *pointer = + xcb_query_pointer_reply(x11->xcb_conn, cookie, NULL); + if (!pointer) { + return; + } + + struct wlr_event_pointer_motion_absolute abs = { + .device = &x11->pointer_dev, + .time_msec = x11->time, + .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); + free(pointer); +} + +bool wlr_output_is_x11(struct wlr_output *wlr_output) { + return wlr_output->impl == &output_impl; +} diff --git a/include/backend/x11.h b/include/backend/x11.h index 72710f6c..92a29725 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -6,15 +6,23 @@ #include #include #include +#include +#include + +#define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f struct wlr_x11_backend; struct wlr_x11_output { struct wlr_output wlr_output; struct wlr_x11_backend *x11; + struct wl_list link; // wlr_x11_backend::outputs xcb_window_t win; EGLSurface surf; + + struct wl_event_source *frame_timer; + int frame_delay; }; struct wlr_x11_backend { @@ -25,7 +33,8 @@ struct wlr_x11_backend { xcb_connection_t *xcb_conn; xcb_screen_t *screen; - struct wlr_x11_output output; + size_t requested_outputs; + struct wl_list outputs; // wlr_x11_output::link struct wlr_keyboard keyboard; struct wlr_input_device keyboard_dev; @@ -36,7 +45,6 @@ struct wlr_x11_backend { struct wlr_egl egl; struct wlr_renderer *renderer; struct wl_event_source *event_source; - struct wl_event_source *frame_timer; struct { xcb_atom_t wm_protocols; @@ -57,4 +65,16 @@ struct wlr_x11_backend { struct wl_listener display_destroy; }; +struct wlr_x11_output *x11_output_from_window_id(struct wlr_x11_backend *x11, + xcb_window_t window); + +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); + #endif From 0a7a8cbd1c64e50978e846d8cf1bf8b1f6868655 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 30 Mar 2018 22:09:06 -0400 Subject: [PATCH 81/99] 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(-) 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); From aa6ae710f70a1b57a71c8a900b0ef4268f60bb4b Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 30 Mar 2018 22:36:04 -0400 Subject: [PATCH 82/99] backend/x11: fix input events --- backend/x11/backend.c | 33 +++++++++++++++++++++++++++++++++ backend/x11/input_device.c | 22 ++++++++++++++++++---- include/backend/x11.h | 2 ++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 80998f3f..82004058 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -1,4 +1,5 @@ #define _POSIX_C_SOURCE 200112L +#include #include #include #include @@ -32,6 +33,38 @@ struct wlr_x11_output *x11_output_from_window_id(struct wlr_x11_backend *x11, return NULL; } +void x11_output_layout_get_box(struct wlr_x11_backend *backend, + struct wlr_box *box) { + int min_x = INT_MAX, min_y = INT_MAX; + int max_x = INT_MIN, max_y = INT_MIN; + + struct wlr_x11_output *output; + wl_list_for_each(output, &backend->outputs, link) { + struct wlr_output *wlr_output = &output->wlr_output; + + int width, height; + wlr_output_effective_resolution(wlr_output, &width, &height); + + if (wlr_output->lx < min_x) { + min_x = wlr_output->lx; + } + if (wlr_output->ly < min_y) { + min_y = wlr_output->ly; + } + if (wlr_output->lx + width > max_x) { + max_x = wlr_output->lx + width; + } + if (wlr_output->ly + height > max_y) { + max_y = wlr_output->ly + height; + } + } + + box->x = min_x; + box->y = min_y; + box->width = max_x - min_x; + box->height = max_y - min_y; +} + static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *event) { if (x11_handle_input_event(x11, event)) { diff --git a/backend/x11/input_device.c b/backend/x11/input_device.c index fb7f8b85..32b1a1ac 100644 --- a/backend/x11/input_device.c +++ b/backend/x11/input_device.c @@ -87,15 +87,29 @@ bool x11_handle_input_event(struct wlr_x11_backend *x11, if (output == NULL) { return false; } + struct wlr_output *wlr_output = &output->wlr_output; - struct wlr_event_pointer_motion_absolute abs = { + struct wlr_box box = { .x = ev->event_x, .y = ev->event_y }; + wlr_box_transform(&box, wlr_output->transform, wlr_output->width, + wlr_output->height, &box); + box.x /= wlr_output->scale; + box.y /= wlr_output->scale; + + struct wlr_box layout_box; + x11_output_layout_get_box(x11, &layout_box); + + double ox = wlr_output->lx / (double)layout_box.width; + double oy = wlr_output->ly / (double)layout_box.height; + + struct wlr_event_pointer_motion_absolute wlr_event = { .device = &x11->pointer_dev, .time_msec = ev->time, - .x = (double)ev->event_x / output->wlr_output.width, - .y = (double)ev->event_y / output->wlr_output.height, + .x = box.x / (double)layout_box.width + ox, + .y = box.y / (double)layout_box.height + oy, }; - wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &abs); + wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &wlr_event); + x11->time = ev->time; return true; } diff --git a/include/backend/x11.h b/include/backend/x11.h index aa058882..0426e481 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -69,6 +69,8 @@ struct wlr_x11_backend { struct wlr_x11_output *x11_output_from_window_id(struct wlr_x11_backend *x11, xcb_window_t window); +void x11_output_layout_get_box(struct wlr_x11_backend *backend, + struct wlr_box *box); const struct wlr_input_device_impl input_device_impl; From f37e8c5b6e554a358a3bf32b1cc08bb5d52e1bf7 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 30 Mar 2018 22:38:09 -0400 Subject: [PATCH 83/99] backend/wayland: cleanup input transform code --- backend/wayland/wl_seat.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index a5821311..c6982fce 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -60,37 +60,28 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, struct wlr_output *wlr_output = &wlr_wl_pointer->current_output->wlr_output; - int width, height; - wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window, - &width, &height); - - int owidth, oheight; - wlr_output_effective_resolution(wlr_output, &owidth, &oheight); - struct wlr_box box = { .x = wl_fixed_to_int(surface_x), .y = wl_fixed_to_int(surface_y), }; - struct wlr_box transformed; - wlr_box_transform(&box, wlr_output->transform, width, height, &transformed); - transformed.x /= wlr_output->scale; - transformed.y /= wlr_output->scale; + wlr_box_transform(&box, wlr_output->transform, wlr_output->width, + wlr_output->height, &box); + box.x /= wlr_output->scale; + box.y /= wlr_output->scale; struct wlr_box layout_box; wlr_wl_output_layout_get_box(wlr_wl_pointer->current_output->backend, &layout_box); - struct wlr_event_pointer_motion_absolute wlr_event; - wlr_event.device = dev; - wlr_event.time_msec = time; - - double tx = transformed.x / (double)owidth; - double ty = transformed.y / (double)oheight; double ox = wlr_output->lx / (double)layout_box.width; double oy = wlr_output->ly / (double)layout_box.height; - wlr_event.x = tx * ((double)owidth / layout_box.width) + ox; - wlr_event.y = ty * ((double)oheight / layout_box.height) + oy; + struct wlr_event_pointer_motion_absolute wlr_event = { + .device = dev, + .time_msec = time, + .x = box.x / (double)layout_box.width + ox, + .y = box.y / (double)layout_box.height + oy, + }; wlr_signal_emit_safe(&dev->pointer->events.motion_absolute, &wlr_event); } From 5111f7df84cea46e1e30cc5b460568e5d46e584a Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 30 Mar 2018 23:36:05 -0400 Subject: [PATCH 84/99] backend/x11: fix extra output --- backend/backend.c | 10 +++++----- backend/x11/backend.c | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/backend.c b/backend/backend.c index ff5603bd..93d7e0df 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -61,7 +61,7 @@ struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend) { return NULL; } -static int parse_outputs_env(const char *name) { +static size_t parse_outputs_env(const char *name) { const char *outputs_str = getenv(name); if (outputs_str == NULL) { return 1; @@ -83,8 +83,8 @@ static struct wlr_backend *attempt_wl_backend(struct wl_display *display) { return NULL; } - int outputs = parse_outputs_env("WLR_WL_OUTPUTS"); - for (int i = 0; i < outputs; ++i) { + size_t outputs = parse_outputs_env("WLR_WL_OUTPUTS"); + for (size_t i = 0; i < outputs; ++i) { wlr_wl_output_create(backend); } @@ -98,8 +98,8 @@ static struct wlr_backend *attempt_x11_backend(struct wl_display *display, return NULL; } - int outputs = parse_outputs_env("WLR_X11_OUTPUTS"); - for (int i = 0; i < outputs; ++i) { + size_t outputs = parse_outputs_env("WLR_X11_OUTPUTS"); + for (size_t i = 0; i < outputs; ++i) { wlr_x11_output_create(backend); } diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 82004058..90658f26 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -282,7 +282,6 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display, wlr_backend_init(&x11->backend, &backend_impl); x11->wl_display = display; - x11->requested_outputs = 1; wl_list_init(&x11->outputs); x11->xlib_conn = XOpenDisplay(x11_display); From 1778818a50037f52b5b7fd58138b035b82c2aa4f Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 31 Mar 2018 00:22:09 -0400 Subject: [PATCH 85/99] Don't destroying all layer surfaces on client d/c --- types/wlr_layer_shell.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index cbf21f4a..b81fb4c6 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -353,10 +353,13 @@ static const struct zwlr_layer_shell_v1_interface layer_shell_implementation = { }; static void client_handle_destroy(struct wl_resource *resource) { + struct wl_client *client = wl_resource_get_client(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); + if (wl_resource_get_client(surface->resource) == client) { + layer_surface_destroy(surface); + } } wl_list_remove(wl_resource_get_link(resource)); } From 692f1746cff0377393011f698484dc4f6cf030b8 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 00:22:58 -0400 Subject: [PATCH 86/99] xwayland: specify xwm cursor stride in bytes --- rootston/desktop.c | 2 +- xwayland/xwm.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index 1d2e9549..0668d8cb 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -834,7 +834,7 @@ struct roots_desktop *desktop_create(struct roots_server *server, if (xcursor != NULL) { struct wlr_xcursor_image *image = xcursor->images[0]; wlr_xwayland_set_cursor(desktop->xwayland, image->buffer, - image->width, image->width, image->height, image->hotspot_x, + image->width * 4, image->width, image->height, image->hotspot_x, image->hotspot_y); } } diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 2743cc53..6702c3c9 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1378,7 +1378,6 @@ void xwm_set_cursor(struct wlr_xwm *xwm, const uint8_t *pixels, uint32_t stride, xcb_free_cursor(xwm->xcb_conn, xwm->cursor); } - stride *= 4; int depth = 32; xcb_pixmap_t pix = xcb_generate_id(xwm->xcb_conn); From 23d357e371fd49243a6f2989058b25c599888505 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 31 Mar 2018 00:27:30 -0400 Subject: [PATCH 87/99] Downgrade gles2 messages to L_DEBUG L_INFO is for stuff that's useful to the user --- render/gles2/renderer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 8f3ce7f7..c8094847 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -322,11 +322,11 @@ static log_importance_t gles2_log_importance_to_wlr(GLenum type) { case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_KHR: return L_ERROR; case GL_DEBUG_TYPE_PORTABILITY_KHR: return L_DEBUG; case GL_DEBUG_TYPE_PERFORMANCE_KHR: return L_DEBUG; - case GL_DEBUG_TYPE_OTHER_KHR: return L_INFO; + case GL_DEBUG_TYPE_OTHER_KHR: return L_DEBUG; case GL_DEBUG_TYPE_MARKER_KHR: return L_DEBUG; case GL_DEBUG_TYPE_PUSH_GROUP_KHR: return L_DEBUG; case GL_DEBUG_TYPE_POP_GROUP_KHR: return L_DEBUG; - default: return L_INFO; + default: return L_DEBUG; } } From 90fbab6f390da0e8f2b7f4b39b6766e4534467b7 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 00:35:08 -0400 Subject: [PATCH 88/99] xwyaland: fix style issues --- include/wlr/xwayland.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 From 3f6823092ad9bfa1def3c33e5d3c2d3cdbc676fa Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sat, 31 Mar 2018 12:55:36 +0300 Subject: [PATCH 89/99] Initialize roots_output to fix -Wmaybe-uninitialized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With -O2: ../rootston/desktop.c: In function ‘desktop_surface_at’: ../rootston/desktop.c:714:18: error: ‘roots_output’ may be used uninitialized in this function [-Werror=maybe-uninitialized] if ((surface = layer_surface_at(roots_output, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ &roots_output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ox, oy, sx, sy))) { ~~~~~~~~~~~~~~~ --- rootston/desktop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index 0668d8cb..c2e424cf 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -682,7 +682,7 @@ struct wlr_surface *desktop_surface_at(struct roots_desktop *desktop, struct wlr_surface *surface = NULL; struct wlr_output *wlr_output = wlr_output_layout_output_at(desktop->layout, lx, ly); - struct roots_output *roots_output; + struct roots_output *roots_output = NULL; double ox = lx, oy = ly; *view = NULL; From 937362b5521fe501d3fb060c5c73e6ae18cc0826 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 31 Mar 2018 09:55:41 -0400 Subject: [PATCH 90/99] FIx crash on touch down --- rootston/desktop.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index c2e424cf..ab16ed3d 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -684,7 +684,9 @@ struct wlr_surface *desktop_surface_at(struct roots_desktop *desktop, wlr_output_layout_output_at(desktop->layout, lx, ly); struct roots_output *roots_output = NULL; double ox = lx, oy = ly; - *view = NULL; + if (view) { + *view = NULL; + } if (wlr_output) { roots_output = wlr_output->data; From 7b88ace557f6aae4b7aa41b72263c628e637a892 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 12:07:58 -0400 Subject: [PATCH 91/99] backend/x11: hide cursor --- backend/x11/backend.c | 12 ++++++++++++ backend/x11/output.c | 4 ++++ include/backend/x11.h | 3 +++ 3 files changed, 19 insertions(+) diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 90658f26..225fc49d 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -171,6 +171,15 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { } } + // create a blank cursor + xcb_pixmap_t pix = xcb_generate_id(x11->xcb_conn); + xcb_create_pixmap(x11->xcb_conn, 1, pix, x11->screen->root, 1, 1); + + x11->cursor = xcb_generate_id(x11->xcb_conn); + xcb_create_cursor(x11->xcb_conn, x11->cursor, pix, pix, 0, 0, 0, 0, 0, 0, + 0, 0); + xcb_free_pixmap(x11->xcb_conn, pix); + #ifdef WLR_HAS_XCB_XKB const xcb_query_extension_reply_t *reply = xcb_get_extension_data(x11->xcb_conn, &xcb_xkb_id); @@ -239,6 +248,9 @@ static void wlr_x11_backend_destroy(struct wlr_backend *backend) { wlr_egl_finish(&x11->egl); + if (x11->cursor) { + xcb_free_cursor(x11->xcb_conn, x11->cursor); + } if (x11->xlib_conn) { XCloseDisplay(x11->xlib_conn); } diff --git a/backend/x11/output.c b/backend/x11/output.c index 9e7424d8..2220bc2e 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -135,6 +135,10 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) { strlen(title), title); } + uint32_t cursor_values[] = { x11->cursor }; + xcb_change_window_attributes(x11->xcb_conn, output->win, XCB_CW_CURSOR, + cursor_values); + xcb_map_window(x11->xcb_conn, output->win); xcb_flush(x11->xcb_conn); diff --git a/include/backend/x11.h b/include/backend/x11.h index 0426e481..33c9a427 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -58,6 +58,9 @@ struct wlr_x11_backend { // The time we last received an event xcb_timestamp_t time; + // A blank cursor + xcb_cursor_t cursor; + #ifdef WLR_HAS_XCB_XKB bool xkb_supported; uint8_t xkb_base_event; From 37aae0b2cdebeba10f141b8646886614e1646530 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 13:28:50 -0400 Subject: [PATCH 92/99] backend/x11: flush after destroying window Otherwise the destroy message is kept buffered and never reaches the X11 server. Thanks X11. --- backend/x11/output.c | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/x11/output.c b/backend/x11/output.c index 9e7424d8..4ccabd51 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -52,6 +52,7 @@ static void output_destroy(struct wlr_output *wlr_output) { wl_event_source_remove(output->frame_timer); eglDestroySurface(x11->egl.display, output->surf); xcb_destroy_window(x11->xcb_conn, output->win); + xcb_flush(x11->xcb_conn); free(output); } From 33a2eb4b7775d1a3ab2b767739c1f1f054683d22 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 18:49:43 -0400 Subject: [PATCH 93/99] 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(-) 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); From a2391a6047baa6c3755b8be95af540ab6d8846c9 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 20:55:31 -0400 Subject: [PATCH 94/99] Fix cursor transform on DRM backend --- backend/drm/drm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 94bfbc96..187db368 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -579,8 +579,7 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, return false; } - enum wl_output_transform transform = - wlr_output_transform_invert(output->transform); + enum wl_output_transform transform = output->transform; wlr_matrix_projection(plane->matrix, plane->surf.width, plane->surf.height, transform); } From a7bb48b404b4809532e81a5daa981c81279c863a Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 23:20:00 -0400 Subject: [PATCH 95/99] 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(-) 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) { + if (!glEGLImageTargetTexture2DOES) { return NULL; } - EGLint fmt; - if (!eglQueryWaylandBufferWL(renderer->egl->display, data, - EGL_TEXTURE_FORMAT, &fmt)) { - 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; } From 5a47da1ea6aa2227b82fb12a89c68aa8c9c2cbc9 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 1 Apr 2018 00:17:27 -0400 Subject: [PATCH 96/99] 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(-) 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; From f3f61bed3e055e7032466723afda33a56f585dc5 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 1 Apr 2018 16:07:50 -0400 Subject: [PATCH 97/99] 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(-) 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; From f63a5d881d7662ced11057e7d2c38435f40310d6 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 1 Apr 2018 16:57:29 -0400 Subject: [PATCH 98/99] examples: get wlr_renderer from the backend --- examples/output-layout.c | 4 +--- examples/rotation.c | 4 +--- examples/tablet.c | 4 +--- examples/touch.c | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/examples/output-layout.c b/examples/output-layout.c index 53aae7f0..b04e86b7 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -196,8 +195,7 @@ int main(int argc, char *argv[]) { compositor.keyboard_key_cb = handle_keyboard_key; compositor_init(&compositor); - struct wlr_egl *egl = wlr_backend_get_egl(compositor.backend); - state.renderer = wlr_gles2_renderer_create(egl); + state.renderer = wlr_backend_get_renderer(compositor.backend); 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 37873797..c7bbc99a 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -137,8 +136,7 @@ int main(int argc, char *argv[]) { compositor.keyboard_key_cb = handle_keyboard_key; compositor_init(&compositor); - struct wlr_egl *egl = wlr_backend_get_egl(compositor.backend); - state.renderer = wlr_gles2_renderer_create(egl); + state.renderer = wlr_backend_get_renderer(compositor.backend); 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 d80b4b2f..ca9d782c 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -192,8 +191,7 @@ int main(int argc, char *argv[]) { }; compositor_init(&compositor); - struct wlr_egl *egl = wlr_backend_get_egl(compositor.backend); - state.renderer = wlr_gles2_renderer_create(egl); + state.renderer = wlr_backend_get_renderer(compositor.backend); 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 16024fc8..949d209d 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -108,8 +107,7 @@ int main(int argc, char *argv[]) { }; compositor_init(&compositor); - struct wlr_egl *egl = wlr_backend_get_egl(compositor.backend); - state.renderer = wlr_gles2_renderer_create(egl); + state.renderer = wlr_backend_get_renderer(compositor.backend); if (!state.renderer) { wlr_log(L_ERROR, "Could not start compositor, OOM"); exit(EXIT_FAILURE); From d466cc117f95d34e239049a5af701b7ba696d336 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 2 Apr 2018 14:55:17 -0400 Subject: [PATCH 99/99] Don't reset exclusive between layer shell passes This is not the intended behavior of exclusive zones, the second pass is meant to respect the usable area. --- rootston/layer_shell.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index edfaf5ea..d3a91659 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -180,9 +180,6 @@ void arrange_layers(struct roots_output *output) { } // Arrange non-exlusive surfaces from top->bottom - usable_area.x = usable_area.y = 0; - 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);