From 3994762ae05d18f2ec0fe9509e4dd41224cde56e Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Fri, 1 Jun 2018 13:27:10 +0200 Subject: Add wlr_surface_get_geometry This function defaults and clips the xdg-surface geometry to the bounding box of the surface + its subsurfaces, as specified by the protocol spec. --- rootston/xdg_shell.c | 12 ++++-------- rootston/xdg_shell_v6.c | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) (limited to 'rootston') diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c index 03ae1dc6..805fb874 100644 --- a/rootston/xdg_shell.c +++ b/rootston/xdg_shell.c @@ -132,14 +132,10 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) { assert(view->type == ROOTS_XDG_SHELL_VIEW); struct wlr_xdg_surface *surface = view->xdg_surface; - if (surface->geometry.width > 0 && surface->geometry.height > 0) { - box->width = surface->geometry.width; - box->height = surface->geometry.height; - } else { - assert(surface->surface); - box->width = surface->surface->current->width; - box->height = surface->surface->current->height; - } + struct wlr_box geo_box; + wlr_xdg_surface_get_geometry(surface, &geo_box); + box->width = geo_box.width; + box->height = geo_box.height; } static void activate(struct roots_view *view, bool active) { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 90b11690..02ad867d 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -133,14 +133,10 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; - if (surface->geometry.width > 0 && surface->geometry.height > 0) { - box->width = surface->geometry.width; - box->height = surface->geometry.height; - } else { - assert(surface->surface); - box->width = surface->surface->current->width; - box->height = surface->surface->current->height; - } + struct wlr_box geo_box; + wlr_xdg_surface_v6_get_geometry(surface, &geo_box); + box->width = geo_box.width; + box->height = geo_box.height; } static void activate(struct roots_view *view, bool active) { -- cgit v1.2.3 From 1c75d4e54a877bb1918afb5bf23c2c142ca30b78 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 5 Jun 2018 18:17:42 -0400 Subject: rename drag-icon map to unmap --- include/rootston/seat.h | 2 +- include/wlr/types/wlr_data_device.h | 2 +- rootston/seat.c | 10 +++++----- types/data_device/wlr_drag.c | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'rootston') diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 7b09f339..bed81c88 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -58,7 +58,7 @@ struct roots_drag_icon { double x, y; struct wl_listener surface_commit; - struct wl_listener map; + struct wl_listener unmap; struct wl_listener destroy; }; diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 5581373d..33fbf525 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -88,7 +88,7 @@ struct wlr_drag_icon { int32_t sx, sy; struct { - struct wl_signal map; // emitted when mapped or unmapped + struct wl_signal unmap; struct wl_signal destroy; } events; diff --git a/rootston/seat.c b/rootston/seat.c index b137ff11..81cedc5a 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -263,10 +263,10 @@ static void roots_drag_icon_handle_surface_commit(struct wl_listener *listener, roots_drag_icon_damage_whole(icon); } -static void roots_drag_icon_handle_map(struct wl_listener *listener, +static void roots_drag_icon_handle_unmap(struct wl_listener *listener, void *data) { struct roots_drag_icon *icon = - wl_container_of(listener, icon, map); + wl_container_of(listener, icon, unmap); roots_drag_icon_damage_whole(icon); } @@ -278,7 +278,7 @@ static void roots_drag_icon_handle_destroy(struct wl_listener *listener, wl_list_remove(&icon->link); wl_list_remove(&icon->surface_commit.link); - wl_list_remove(&icon->map.link); + wl_list_remove(&icon->unmap.link); wl_list_remove(&icon->destroy.link); free(icon); } @@ -297,8 +297,8 @@ static void roots_seat_handle_new_drag_icon(struct wl_listener *listener, icon->surface_commit.notify = roots_drag_icon_handle_surface_commit; wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit); - icon->map.notify = roots_drag_icon_handle_map; - wl_signal_add(&wlr_drag_icon->events.map, &icon->map); + icon->unmap.notify = roots_drag_icon_handle_unmap; + wl_signal_add(&wlr_drag_icon->events.unmap, &icon->unmap); icon->destroy.notify = roots_drag_icon_handle_destroy; wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy); diff --git a/types/data_device/wlr_drag.c b/types/data_device/wlr_drag.c index 1429d4dd..b4857956 100644 --- a/types/data_device/wlr_drag.c +++ b/types/data_device/wlr_drag.c @@ -117,7 +117,7 @@ static void drag_end(struct wlr_drag *drag) { if (drag->icon) { drag->icon->mapped = false; wl_list_remove(&drag->icon_destroy.link); - wlr_signal_emit_safe(&drag->icon->events.map, drag->icon); + wlr_signal_emit_safe(&drag->icon->events.unmap, drag->icon); } wlr_signal_emit_safe(&drag->events.destroy, drag); @@ -357,7 +357,7 @@ static struct wlr_drag_icon *drag_icon_create( icon->touch_id = touch_id; icon->mapped = true; - wl_signal_init(&icon->events.map); + wl_signal_init(&icon->events.unmap); wl_signal_init(&icon->events.destroy); wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy); -- cgit v1.2.3 From 9333acd68e468d409cbcc30fb742fdf57c631cb9 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 5 Jun 2018 23:01:43 -0400 Subject: handle drag icon map in rootston --- include/rootston/seat.h | 1 + rootston/seat.c | 9 +++++++++ 2 files changed, 10 insertions(+) (limited to 'rootston') diff --git a/include/rootston/seat.h b/include/rootston/seat.h index bed81c88..0e3043dd 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -58,6 +58,7 @@ struct roots_drag_icon { double x, y; struct wl_listener surface_commit; + struct wl_listener map; struct wl_listener unmap; struct wl_listener destroy; }; diff --git a/rootston/seat.c b/rootston/seat.c index 81cedc5a..132b0f35 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -263,6 +263,13 @@ static void roots_drag_icon_handle_surface_commit(struct wl_listener *listener, roots_drag_icon_damage_whole(icon); } +static void roots_drag_icon_handle_map(struct wl_listener *listener, + void *data) { + struct roots_drag_icon *icon = + wl_container_of(listener, icon, map); + roots_drag_icon_damage_whole(icon); +} + static void roots_drag_icon_handle_unmap(struct wl_listener *listener, void *data) { struct roots_drag_icon *icon = @@ -299,6 +306,8 @@ static void roots_seat_handle_new_drag_icon(struct wl_listener *listener, wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit); icon->unmap.notify = roots_drag_icon_handle_unmap; wl_signal_add(&wlr_drag_icon->events.unmap, &icon->unmap); + icon->map.notify = roots_drag_icon_handle_map; + wl_signal_add(&wlr_drag_icon->events.map, &icon->map); icon->destroy.notify = roots_drag_icon_handle_destroy; wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy); -- cgit v1.2.3 From 7c888a39c6d08e9301032625987a6015fac17c6f Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 5 Jun 2018 23:45:03 -0400 Subject: update drag position at the right times --- rootston/seat.c | 3 +++ types/data_device/wlr_drag.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'rootston') diff --git a/rootston/seat.c b/rootston/seat.c index 132b0f35..33dff741 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -260,6 +260,7 @@ static void roots_drag_icon_handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_drag_icon *icon = wl_container_of(listener, icon, surface_commit); + roots_drag_icon_update_position(icon); roots_drag_icon_damage_whole(icon); } @@ -312,6 +313,8 @@ static void roots_seat_handle_new_drag_icon(struct wl_listener *listener, wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy); wl_list_insert(&seat->drag_icons, &icon->link); + + roots_drag_icon_update_position(icon); } void roots_drag_icon_update_position(struct roots_drag_icon *icon) { diff --git a/types/data_device/wlr_drag.c b/types/data_device/wlr_drag.c index 4b42307e..4f0b2521 100644 --- a/types/data_device/wlr_drag.c +++ b/types/data_device/wlr_drag.c @@ -100,12 +100,12 @@ static void drag_set_focus(struct wlr_drag *drag, static void drag_icon_set_mapped(struct wlr_drag_icon *icon, bool mapped) { if (mapped && !icon->mapped) { + icon->mapped = true; wlr_signal_emit_safe(&icon->events.map, icon); } else if (!mapped && icon->mapped) { + icon->mapped = false; wlr_signal_emit_safe(&icon->events.unmap, icon); } - - icon->mapped = mapped; } static void drag_end(struct wlr_drag *drag) { -- cgit v1.2.3 From 5d3e95f833ae562bf6926ddfb9f1bdb0492c1674 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 6 Jun 2018 12:02:01 -0400 Subject: dont damage drag icon after update_position --- rootston/seat.c | 1 - 1 file changed, 1 deletion(-) (limited to 'rootston') diff --git a/rootston/seat.c b/rootston/seat.c index 33dff741..91561567 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -261,7 +261,6 @@ static void roots_drag_icon_handle_surface_commit(struct wl_listener *listener, struct roots_drag_icon *icon = wl_container_of(listener, icon, surface_commit); roots_drag_icon_update_position(icon); - roots_drag_icon_damage_whole(icon); } static void roots_drag_icon_handle_map(struct wl_listener *listener, -- cgit v1.2.3 From 3a81afed0e21a515f5694204beb0438407fc1313 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 8 Jun 2018 09:29:55 +0100 Subject: rootston: destroy xwayland before all clients Destroying all clients disconnects the xwayland client, and xwayland automatically restarts when disconnected. --- rootston/main.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'rootston') diff --git a/rootston/main.c b/rootston/main.c index 07a41d5d..8a0205f2 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -72,6 +72,9 @@ int main(int argc, char **argv) { } wl_display_run(server.wl_display); +#ifdef WLR_HAS_XWAYLAND + wlr_xwayland_destroy(server.desktop->xwayland); +#endif wl_display_destroy_clients(server.wl_display); wl_display_destroy(server.wl_display); return 0; -- cgit v1.2.3 From 0378d143d9517c7508b64b81e9267a29ab1951aa Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 13 Jun 2018 19:38:10 +0100 Subject: surface: remove wlr_surface.texture The texture is managed by the surface's wlr_buffer now. In particular, the buffer can destroy the texture early if it becomes invalid. --- include/wlr/types/wlr_buffer.h | 11 +++++++++-- include/wlr/types/wlr_surface.h | 14 +++++++++++++- rootston/output.c | 6 +++--- types/wlr_output.c | 10 +++++----- types/wlr_surface.c | 12 ++++++++---- 5 files changed, 38 insertions(+), 15 deletions(-) (limited to 'rootston') diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h index fc348a1c..eabc8b51 100644 --- a/include/wlr/types/wlr_buffer.h +++ b/include/wlr/types/wlr_buffer.h @@ -8,8 +8,15 @@ * A client buffer. */ struct wlr_buffer { - struct wl_resource *resource; // can be NULL - struct wlr_texture *texture; // can be NULL + /** + * The buffer resource, if any. Will be NULL if the client destroys it. + */ + struct wl_resource *resource; + /** + * The buffer's texture, if any. A buffer will not have a texture if the + * client destroys the buffer before it has been released. + */ + struct wlr_texture *texture; bool released; size_t n_refs; diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index 64503e78..8517934a 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -69,8 +69,13 @@ struct wlr_subsurface { struct wlr_surface { struct wl_resource *resource; struct wlr_renderer *renderer; + /** + * The surface's buffer, if any. A surface has an attached buffer when it + * commits with a non-null buffer in its pending state. A surface will not + * have a buffer if it has never committed one, has committed a null buffer, + * or something went wrong with uploading the buffer. + */ struct wlr_buffer *buffer; - struct wlr_texture *texture; struct wlr_surface_state *current, *pending; const char *role; // the lifetime-bound role or null @@ -125,6 +130,13 @@ int wlr_surface_set_role(struct wlr_surface *surface, const char *role, */ bool wlr_surface_has_buffer(struct wlr_surface *surface); +/** + * Get the texture of the buffer currently attached to this surface. Returns + * NULL if no buffer is currently attached or if something went wrong with + * uploading the buffer. + */ +struct wlr_texture *wlr_surface_get_texture(struct wlr_surface *surface); + /** * Create a new subsurface resource with the provided new ID. If `resource_list` * is non-NULL, adds the subsurface's resource to the list. diff --git a/rootston/output.c b/rootston/output.c index faa808d1..353d431f 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -189,7 +189,8 @@ static void render_surface(struct wlr_surface *surface, int sx, int sy, struct roots_output *output = data->output; float rotation = data->layout.rotation; - if (!wlr_surface_has_buffer(surface)) { + struct wlr_texture *texture = wlr_surface_get_texture(surface); + if (texture == NULL) { return; } @@ -230,8 +231,7 @@ static void render_surface(struct wlr_surface *surface, int sx, int sy, pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(output, &rects[i]); - wlr_render_texture_with_matrix(renderer, surface->texture, matrix, - data->alpha); + wlr_render_texture_with_matrix(renderer, texture, matrix, data->alpha); } damage_finish: diff --git a/types/wlr_output.c b/types/wlr_output.c index a5a6d0eb..7befb651 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -367,7 +367,8 @@ static void output_fullscreen_surface_render(struct wlr_output *output, struct wlr_renderer *renderer = wlr_backend_get_renderer(output->backend); assert(renderer); - if (!wlr_surface_has_buffer(surface)) { + struct wlr_texture *texture = wlr_surface_get_texture(surface); + if (texture == NULL) { wlr_renderer_clear(renderer, (float[]){0, 0, 0, 1}); return; } @@ -386,8 +387,7 @@ static void output_fullscreen_surface_render(struct wlr_output *output, for (int i = 0; i < nrects; ++i) { output_scissor(output, &rects[i]); wlr_renderer_clear(renderer, (float[]){0, 0, 0, 1}); - wlr_render_texture_with_matrix(surface->renderer, surface->texture, - matrix, 1.0f); + wlr_render_texture_with_matrix(surface->renderer, texture, matrix, 1.0f); } wlr_renderer_scissor(renderer, NULL); @@ -418,7 +418,7 @@ static void output_cursor_render(struct wlr_output_cursor *cursor, struct wlr_texture *texture = cursor->texture; if (cursor->surface != NULL) { - texture = cursor->surface->texture; + texture = wlr_surface_get_texture(cursor->surface); } if (texture == NULL) { return; @@ -700,7 +700,7 @@ static bool output_cursor_attempt_hardware(struct wlr_output_cursor *cursor) { enum wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL; struct wlr_texture *texture = cursor->texture; if (cursor->surface != NULL) { - texture = cursor->surface->texture; + texture = wlr_surface_get_texture(cursor->surface); scale = cursor->surface->current->scale; transform = cursor->surface->current->transform; } diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 7d8da02f..af1e9446 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -332,7 +332,6 @@ static void surface_apply_damage(struct wlr_surface *surface, // NULL commit wlr_buffer_unref(surface->buffer); surface->buffer = NULL; - surface->texture = NULL; return; } @@ -362,7 +361,6 @@ static void surface_apply_damage(struct wlr_surface *surface, wlr_buffer_unref(surface->buffer); surface->buffer = NULL; - surface->texture = NULL; struct wlr_buffer *buffer = wlr_buffer_create(surface->renderer, resource); if (buffer == NULL) { @@ -371,7 +369,6 @@ static void surface_apply_damage(struct wlr_surface *surface, } surface->buffer = buffer; - surface->texture = buffer->texture; } static void surface_commit_pending(struct wlr_surface *surface) { @@ -660,8 +657,15 @@ struct wlr_surface *wlr_surface_create(struct wl_client *client, return surface; } +struct wlr_texture *wlr_surface_get_texture(struct wlr_surface *surface) { + if (surface->buffer == NULL) { + return NULL; + } + return surface->buffer->texture; +} + bool wlr_surface_has_buffer(struct wlr_surface *surface) { - return surface->texture != NULL; + return wlr_surface_get_texture(surface) != NULL; } int wlr_surface_set_role(struct wlr_surface *surface, const char *role, -- cgit v1.2.3