From 3e3209cba22c9a5a562acc5e543946408a36e2f4 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 5 Nov 2017 10:22:42 +0100 Subject: [PATCH 01/11] Fix laggy move-resize in xdg-shell --- include/rootston/view.h | 6 ++++ rootston/xdg_shell_v6.c | 76 ++++++++++++++++++++++++----------------- rootston/xwayland.c | 22 ++++++------ 3 files changed, 62 insertions(+), 42 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 0913b42e..adfbe6e0 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -26,6 +26,12 @@ struct roots_xdg_surface_v6 { struct wl_listener destroy; struct wl_listener request_move; struct wl_listener request_resize; + + struct { + bool needs_move; + double x, y; + uint32_t width, height; + } move_resize; }; struct roots_xwayland_surface { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index ca33c582..38341922 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -12,27 +12,26 @@ static void get_size(struct roots_view *view, struct wlr_box *box) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); - struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; - // TODO: surf->geometry can be NULL - memcpy(box, surf->geometry, sizeof(struct wlr_box)); + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + // TODO: surface->geometry can be NULL + memcpy(box, surface->geometry, sizeof(struct wlr_box)); } static void activate(struct roots_view *view, bool active) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); - struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; - if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { - wlr_xdg_toplevel_v6_set_activated(surf, active); + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + wlr_xdg_toplevel_v6_set_activated(surface, active); } } -static void apply_size_constraints(struct wlr_xdg_surface_v6 *surf, +static void apply_size_constraints(struct wlr_xdg_surface_v6 *surface, uint32_t width, uint32_t height, uint32_t *dest_width, uint32_t *dest_height) { *dest_width = width; *dest_height = height; - struct wlr_xdg_toplevel_v6_state *state = - &surf->toplevel_state->current; + struct wlr_xdg_toplevel_v6_state *state = &surface->toplevel_state->current; if (width < state->min_width) { *dest_width = state->min_width; } else if (state->max_width > 0 && @@ -49,46 +48,50 @@ static void apply_size_constraints(struct wlr_xdg_surface_v6 *surf, static void resize(struct roots_view *view, uint32_t width, uint32_t height) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); - struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; - if (surf->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { return; } - uint32_t contrained_width, contrained_height; - apply_size_constraints(surf, width, height, &contrained_width, - &contrained_height); + uint32_t constrained_width, constrained_height; + apply_size_constraints(surface, width, height, &constrained_width, + &constrained_height); - wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_height); + wlr_xdg_toplevel_v6_set_size(surface, constrained_width, + constrained_height); } static void move_resize(struct roots_view *view, double x, double y, uint32_t width, uint32_t height) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); - struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; - if (surf->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + struct roots_xdg_surface_v6 *roots_surface = view->roots_xdg_surface_v6; + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + if (surface->role != WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { return; } - uint32_t contrained_width, contrained_height; - apply_size_constraints(surf, width, height, &contrained_width, - &contrained_height); + uint32_t constrained_width, constrained_height; + apply_size_constraints(surface, width, height, &constrained_width, + &constrained_height); - x = x + width - contrained_width; - y = y + height - contrained_height; + x = x + width - constrained_width; + y = y + height - constrained_height; - // TODO: we should wait for an ack_configure event before updating the - // position - view->x = x; - view->y = y; + roots_surface->move_resize.needs_move = true; + roots_surface->move_resize.x = x; + roots_surface->move_resize.y = y; + roots_surface->move_resize.width = constrained_width; + roots_surface->move_resize.height = constrained_height; - wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_height); + wlr_xdg_toplevel_v6_set_size(surface, constrained_width, + constrained_height); } static void close(struct roots_view *view) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); - struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; - if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { - wlr_xdg_toplevel_v6_send_close(surf); + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + wlr_xdg_toplevel_v6_send_close(surface); } } @@ -119,7 +122,18 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { } static void handle_commit(struct wl_listener *listener, void *data) { - // TODO is there anything we need to do here? + struct roots_xdg_surface_v6 *roots_surface = + wl_container_of(listener, roots_surface, commit); + struct roots_view *view = roots_surface->view; + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; + + if (roots_surface->move_resize.needs_move) { + view->x = roots_surface->move_resize.x + + roots_surface->move_resize.width - surface->geometry->width; + view->y = roots_surface->move_resize.y + + roots_surface->move_resize.height - surface->geometry->height; + roots_surface->move_resize.needs_move = false; + } } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xwayland.c b/rootston/xwayland.c index e3fc1c84..76cdf05a 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -52,13 +52,13 @@ static void resize(struct roots_view *view, uint32_t width, uint32_t height) { assert(view->type == ROOTS_XWAYLAND_VIEW); struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; - uint32_t contrained_width, contrained_height; - apply_size_constraints(xwayland_surface, width, height, &contrained_width, - &contrained_height); + uint32_t constrained_width, constrained_height; + apply_size_constraints(xwayland_surface, width, height, &constrained_width, + &constrained_height); wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, - xwayland_surface->x, xwayland_surface->y, contrained_width, - contrained_height); + xwayland_surface->x, xwayland_surface->y, constrained_width, + constrained_height); } static void move_resize(struct roots_view *view, double x, double y, @@ -66,18 +66,18 @@ static void move_resize(struct roots_view *view, double x, double y, assert(view->type == ROOTS_XWAYLAND_VIEW); struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; - uint32_t contrained_width, contrained_height; - apply_size_constraints(xwayland_surface, width, height, &contrained_width, - &contrained_height); + uint32_t constrained_width, constrained_height; + apply_size_constraints(xwayland_surface, width, height, &constrained_width, + &constrained_height); - x = x + width - contrained_width; - y = y + height - contrained_height; + x = x + width - constrained_width; + y = y + height - constrained_height; view->x = x; view->y = y; wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, - x, y, contrained_width, contrained_height); + x, y, constrained_width, constrained_height); } static void close(struct roots_view *view) { From e2843d87c868341869cf905f6c77531e78d997ad Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 17 Nov 2017 23:52:42 +0100 Subject: [PATCH 02/11] Ensure to move the view when configured --- include/rootston/view.h | 2 +- include/wlr/types/wlr_xdg_shell_v6.h | 24 ++++++++++------- rootston/xdg_shell_v6.c | 10 +++---- types/wlr_xdg_shell_v6.c | 40 ++++++++++++++-------------- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 9df2ee08..66616207 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -30,7 +30,7 @@ struct roots_xdg_surface_v6 { struct wl_listener request_maximize; struct { - bool needs_move; + uint32_t configure_serial; double x, y; uint32_t width, height; } move_resize; diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index e3982003..d0e7957b 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -107,7 +107,9 @@ struct wlr_xdg_surface_v6 { bool configured; bool added; + uint32_t configure_serial; struct wl_event_source *configure_idle; + uint32_t configure_next_serial; struct wl_list configure_list; char *title; @@ -171,37 +173,38 @@ void wlr_xdg_shell_v6_destroy(struct wlr_xdg_shell_v6 *xdg_shell); void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface); /** - * Request that this toplevel surface be the given size. + * Request that this toplevel surface be the given size. Returns the associated + * configure serial. */ -void wlr_xdg_toplevel_v6_set_size(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); /** * Request that this toplevel surface show itself in an activated or deactivated - * state. + * state. Returns the associated configure serial. */ -void wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, +uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface, bool activated); /** * Request that this toplevel surface consider itself maximized or not - * maximized. + * maximized. Returns the associated configure serial. */ -void wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, +uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface, bool maximized); /** * Request that this toplevel surface consider itself fullscreen or not - * fullscreen. + * fullscreen. Returns the associated configure serial. */ -void wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, +uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, bool fullscreen); /** * Request that this toplevel surface consider itself to be resizing or not - * resizing. + * resizing. Returns the associated configure serial. */ -void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, +uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, bool resizing); /** @@ -223,4 +226,5 @@ void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface, 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); + #endif diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index f9c905dd..d91fc2d9 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -83,14 +83,13 @@ static void move_resize(struct roots_view *view, double x, double y, x = x + width - constrained_width; y = y + height - constrained_height; - roots_surface->move_resize.needs_move = true; roots_surface->move_resize.x = x; roots_surface->move_resize.y = y; roots_surface->move_resize.width = constrained_width; roots_surface->move_resize.height = constrained_height; - wlr_xdg_toplevel_v6_set_size(surface, constrained_width, - constrained_height); + roots_surface->move_resize.configure_serial = wlr_xdg_toplevel_v6_set_size( + surface, constrained_width, constrained_height); } static void maximize(struct roots_view *view, bool maximized) { @@ -159,12 +158,13 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; - if (roots_surface->move_resize.needs_move) { + if (roots_surface->move_resize.configure_serial == + surface->configure_serial) { view->x = roots_surface->move_resize.x + roots_surface->move_resize.width - surface->geometry->width; view->y = roots_surface->move_resize.y + roots_surface->move_resize.height - surface->geometry->height; - roots_surface->move_resize.needs_move = false; + roots_surface->move_resize.configure_serial = 0; } } diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 429baa70..dfe5ddc5 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -812,6 +812,7 @@ static void xdg_surface_ack_configure(struct wl_client *client, } surface->configured = true; + surface->configure_serial = serial; wl_signal_emit(&surface->events.ack_configure, surface); @@ -941,7 +942,6 @@ static void wlr_xdg_toplevel_v6_send_configure( static void wlr_xdg_surface_send_configure(void *user_data) { struct wlr_xdg_surface_v6 *surface = user_data; - struct wl_display *display = wl_client_get_display(surface->client->client); surface->configure_idle = NULL; @@ -953,7 +953,7 @@ static void wlr_xdg_surface_send_configure(void *user_data) { } wl_list_insert(surface->configure_list.prev, &configure->link); - configure->serial = wl_display_next_serial(display); + configure->serial = surface->configure_next_serial; switch (surface->role) { case WLR_XDG_SURFACE_V6_ROLE_NONE: @@ -974,7 +974,7 @@ static void wlr_xdg_surface_send_configure(void *user_data) { zxdg_surface_v6_send_configure(surface->resource, configure->serial); } -static void wlr_xdg_surface_v6_schedule_configure( +static uint32_t wlr_xdg_surface_v6_schedule_configure( struct wlr_xdg_surface_v6 *surface) { struct wl_display *display = wl_client_get_display(surface->client->client); struct wl_event_loop *loop = wl_display_get_event_loop(display); @@ -995,23 +995,23 @@ static void wlr_xdg_surface_v6_schedule_configure( if (surface->configure_idle != NULL) { if (!pending_same) { // configure request already scheduled - return; + 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 (pending_same) { // configure request not necessary - return; + return 0; } - surface->configure_idle = - wl_event_loop_add_idle( - loop, - wlr_xdg_surface_send_configure, - surface); + surface->configure_next_serial = wl_display_next_serial(display); + surface->configure_idle = wl_event_loop_add_idle(loop, + wlr_xdg_surface_send_configure, surface); + return surface->configure_next_serial; } } @@ -1304,45 +1304,45 @@ void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface) { surface->client->ping_serial); } -void wlr_xdg_toplevel_v6_set_size(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_state->pending.width = width; surface->toplevel_state->pending.height = height; - wlr_xdg_surface_v6_schedule_configure(surface); + return wlr_xdg_surface_v6_schedule_configure(surface); } -void wlr_xdg_toplevel_v6_set_activated(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_state->pending.activated = activated; - wlr_xdg_surface_v6_schedule_configure(surface); + return wlr_xdg_surface_v6_schedule_configure(surface); } -void wlr_xdg_toplevel_v6_set_maximized(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_state->pending.maximized = maximized; - wlr_xdg_surface_v6_schedule_configure(surface); + return wlr_xdg_surface_v6_schedule_configure(surface); } -void wlr_xdg_toplevel_v6_set_fullscreen(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_state->pending.fullscreen = fullscreen; - wlr_xdg_surface_v6_schedule_configure(surface); + return wlr_xdg_surface_v6_schedule_configure(surface); } -void wlr_xdg_toplevel_v6_set_resizing(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_state->pending.resizing = resizing; - wlr_xdg_surface_v6_schedule_configure(surface); + return wlr_xdg_surface_v6_schedule_configure(surface); } void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) { From a3a8b7bfd8d1616cdf9f7ba911616ca0baeedc67 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 18 Nov 2017 09:09:23 +0100 Subject: [PATCH 03/11] Fixed a bug with move-resize, removed xdg-shell ack_configure event Fixed move-resizing a view when only one coordinate changes. --- include/rootston/view.h | 1 + include/wlr/types/wlr_xdg_shell_v6.h | 1 - rootston/cursor.c | 8 +------ rootston/desktop.c | 5 +++++ rootston/xdg_shell_v6.c | 31 +++++++++++++++++++++------- types/wlr_xdg_shell_v6.c | 3 --- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 66616207..058dc73e 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -32,6 +32,7 @@ struct roots_xdg_surface_v6 { struct { uint32_t configure_serial; double x, y; + bool update_x, update_y; uint32_t width, height; } move_resize; }; diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index d0e7957b..6ac84cef 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -125,7 +125,6 @@ struct wlr_xdg_surface_v6 { struct { struct wl_signal commit; struct wl_signal destroy; - struct wl_signal ack_configure; struct wl_signal ping_timeout; struct wl_signal request_maximize; diff --git a/rootston/cursor.c b/rootston/cursor.c index 5949a364..d4c4510a 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -98,13 +98,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t t height = 0; } - if (active_x != seat->focus->x || - active_y != seat->focus->y) { - view_move_resize(seat->focus, active_x, active_y, - width, height); - } else { - view_resize(seat->focus, width, height); - } + view_move_resize(seat->focus, active_x, active_y, width, height); } break; case ROOTS_CURSOR_ROTATE: diff --git a/rootston/desktop.c b/rootston/desktop.c index 1695d007..be63d7f5 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -103,6 +103,11 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height) { void view_move_resize(struct roots_view *view, double x, double y, uint32_t width, uint32_t height) { + if (x == view->x == x && y == view->y) { + view_resize(view, width, height); + return; + } + if (view->move_resize) { view->move_resize(view, x, y, width, height); return; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index d91fc2d9..5a55b8c4 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -76,15 +76,24 @@ static void move_resize(struct roots_view *view, double x, double y, return; } + bool update_x = x != view->x; + bool update_y = y != view->y; + uint32_t constrained_width, constrained_height; apply_size_constraints(surface, width, height, &constrained_width, &constrained_height); - x = x + width - constrained_width; - y = y + height - constrained_height; + if (update_x) { + x = x + width - constrained_width; + } + if (update_y) { + y = y + height - constrained_height; + } roots_surface->move_resize.x = x; roots_surface->move_resize.y = y; + roots_surface->move_resize.update_x = update_x; + roots_surface->move_resize.update_y = update_y; roots_surface->move_resize.width = constrained_width; roots_surface->move_resize.height = constrained_height; @@ -158,12 +167,20 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; - if (roots_surface->move_resize.configure_serial == + if (roots_surface->move_resize.configure_serial > 0 && + roots_surface->move_resize.configure_serial == surface->configure_serial) { - view->x = roots_surface->move_resize.x + - roots_surface->move_resize.width - surface->geometry->width; - view->y = roots_surface->move_resize.y + - roots_surface->move_resize.height - surface->geometry->height; + struct wlr_box size; + get_size(view, &size); + + if (roots_surface->move_resize.update_x) { + view->x = roots_surface->move_resize.x + + roots_surface->move_resize.width - size.width; + } + if (roots_surface->move_resize.update_y) { + view->y = roots_surface->move_resize.y + + roots_surface->move_resize.height - size.height; + } roots_surface->move_resize.configure_serial = 0; } } diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index dfe5ddc5..8bb48a24 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -814,8 +814,6 @@ static void xdg_surface_ack_configure(struct wl_client *client, surface->configured = true; surface->configure_serial = serial; - wl_signal_emit(&surface->events.ack_configure, surface); - free(configure); } @@ -1155,7 +1153,6 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, wl_signal_init(&surface->events.request_show_window_menu); wl_signal_init(&surface->events.commit); wl_signal_init(&surface->events.destroy); - wl_signal_init(&surface->events.ack_configure); wl_signal_init(&surface->events.ping_timeout); wl_signal_add(&surface->surface->events.destroy, From 8693bbd6b11b2519747fe3efcd6376a9736aef6f Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 18 Nov 2017 09:13:31 +0100 Subject: [PATCH 04/11] Update view coords when no configure is required --- rootston/xdg_shell_v6.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 5a55b8c4..8819ebdd 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -97,8 +97,14 @@ static void move_resize(struct roots_view *view, double x, double y, roots_surface->move_resize.width = constrained_width; roots_surface->move_resize.height = constrained_height; - roots_surface->move_resize.configure_serial = wlr_xdg_toplevel_v6_set_size( - surface, constrained_width, constrained_height); + uint32_t serial = wlr_xdg_toplevel_v6_set_size(surface, constrained_width, + constrained_height); + if (serial > 0) { + roots_surface->move_resize.configure_serial = serial; + } else { + view->x = x; + view->y = y; + } } static void maximize(struct roots_view *view, bool maximized) { From 7375931686e6a58c08a7727ce2f5d88e0be9adfa Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 18 Nov 2017 09:15:48 +0100 Subject: [PATCH 05/11] Fix typo making GCC build fail --- rootston/desktop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index be63d7f5..fca801bb 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -103,7 +103,7 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height) { void view_move_resize(struct roots_view *view, double x, double y, uint32_t width, uint32_t height) { - if (x == view->x == x && y == view->y) { + if (x == view->x && y == view->y) { view_resize(view, width, height); return; } From 016744ef4d2692c800d613e40fbf5d6267fab2e9 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 19 Nov 2017 00:17:40 +0100 Subject: [PATCH 06/11] Refactor wlr_list inside wlroots --- backend/libinput/backend.c | 15 ++++---- backend/libinput/events.c | 8 ++-- include/backend/drm/drm.h | 1 - include/backend/libinput.h | 2 +- include/wlr/types/wlr_list.h | 71 ++++++++++++++++++++++-------------- include/wlr/xwayland.h | 2 - types/wlr_list.c | 66 +++++++++++++++------------------ types/wlr_output.c | 1 - xwayland/xwm.c | 1 - 9 files changed, 86 insertions(+), 81 deletions(-) diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 45b4e368..1028e238 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -69,9 +69,9 @@ static bool wlr_libinput_backend_start(struct wlr_backend *_backend) { no_devs = NULL; } } - if (!no_devs && backend->wlr_device_lists->length == 0) { + if (!no_devs && backend->wlr_device_lists.length == 0) { wlr_libinput_readable(libinput_fd, WL_EVENT_READABLE, backend); - if (backend->wlr_device_lists->length == 0) { + if (backend->wlr_device_lists.length == 0) { wlr_log(L_ERROR, "libinput initialization failed, no input devices"); wlr_log(L_ERROR, "Set WLR_LIBINPUT_NO_DEVICES=1 to suppress this check"); return false; @@ -97,9 +97,10 @@ static void wlr_libinput_backend_destroy(struct wlr_backend *_backend) { if (!_backend) { return; } - struct wlr_libinput_backend *backend = (struct wlr_libinput_backend *)_backend; - for (size_t i = 0; i < backend->wlr_device_lists->length; i++) { - struct wl_list *wlr_devices = backend->wlr_device_lists->items[i]; + struct wlr_libinput_backend *backend = + (struct wlr_libinput_backend *)_backend; + for (size_t i = 0; i < backend->wlr_device_lists.length; i++) { + struct wl_list *wlr_devices = backend->wlr_device_lists.items[i]; struct wlr_input_device *wlr_dev, *next; wl_list_for_each_safe(wlr_dev, next, wlr_devices, link) { wl_signal_emit(&backend->backend.events.input_remove, wlr_dev); @@ -107,7 +108,7 @@ static void wlr_libinput_backend_destroy(struct wlr_backend *_backend) { } free(wlr_devices); } - wlr_list_free(backend->wlr_device_lists); + wlr_list_finish(&backend->wlr_device_lists); wl_event_source_remove(backend->input_event); libinput_unref(backend->libinput_context); free(backend); @@ -148,7 +149,7 @@ struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display, } wlr_backend_init(&backend->backend, &backend_impl); - if (!(backend->wlr_device_lists = wlr_list_create())) { + if (!wlr_list_init(&backend->wlr_device_lists)) { wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno)); goto error_backend; } diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 3ca41124..c14aef01 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -147,7 +147,7 @@ static void handle_device_added(struct wlr_libinput_backend *backend, if (wl_list_length(wlr_devices) > 0) { libinput_device_set_user_data(libinput_dev, wlr_devices); - wlr_list_add(backend->wlr_device_lists, wlr_devices); + wlr_list_push(&backend->wlr_device_lists, wlr_devices); } else { free(wlr_devices); } @@ -177,9 +177,9 @@ static void handle_device_removed(struct wlr_libinput_backend *backend, wl_signal_emit(&backend->backend.events.input_remove, dev); wlr_input_device_destroy(dev); } - for (size_t i = 0; i < backend->wlr_device_lists->length; i++) { - if (backend->wlr_device_lists->items[i] == wlr_devices) { - wlr_list_del(backend->wlr_device_lists, i); + for (size_t i = 0; i < backend->wlr_device_lists.length; i++) { + if (backend->wlr_device_lists.items[i] == wlr_devices) { + wlr_list_del(&backend->wlr_device_lists, i); break; } } diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index e08965e5..4fad9678 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -14,7 +14,6 @@ #include #include #include -#include #include "iface.h" #include "properties.h" diff --git a/include/backend/libinput.h b/include/backend/libinput.h index 93b859a7..be2557ed 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -18,7 +18,7 @@ struct wlr_libinput_backend { struct wl_listener session_signal; - struct wlr_list *wlr_device_lists; + struct wlr_list wlr_device_lists; // list of struct wl_list }; struct wlr_libinput_input_device { diff --git a/include/wlr/types/wlr_list.h b/include/wlr/types/wlr_list.h index 8ddd30b6..78a30995 100644 --- a/include/wlr/types/wlr_list.h +++ b/include/wlr/types/wlr_list.h @@ -2,6 +2,7 @@ #define WLR_UTIL_LIST_H #include +#include struct wlr_list { size_t capacity; @@ -10,51 +11,65 @@ struct wlr_list { }; /** - * Creates a new list, may return `NULL` on failure + * Initialize a list. Returns true on success, false on failure. */ -struct wlr_list *wlr_list_create(void); -void wlr_list_free(struct wlr_list *list); -void wlr_list_foreach(struct wlr_list *list, void (*callback)(void *item)); +bool wlr_list_init(struct wlr_list *list); + /** - * Add `item` to the end of a list. - * Returns: new list length or `-1` on failure + * Deinitialize a list. */ -int wlr_list_add(struct wlr_list *list, void *item); +void wlr_list_finish(struct wlr_list *list); + +/** + * Executes `callback` on each element in the list. + */ +void wlr_list_for_each(struct wlr_list *list, void (*callback)(void *item)); + /** * Add `item` to the end of a list. - * Returns: new list length or `-1` on failure + * Returns: new list length or `-1` on failure. */ -int wlr_list_push(struct wlr_list *list, void *item); +ssize_t wlr_list_push(struct wlr_list *list, void *item); + /** - * Place `item` into index `index` in the list - * Returns: new list length or `-1` on failure + * Place `item` into index `index` in the list. + * Returns: new list length or `-1` on failure. */ -int wlr_list_insert(struct wlr_list *list, size_t index, void *item); +ssize_t wlr_list_insert(struct wlr_list *list, size_t index, void *item); + /** - * Remove an item from the list + * Remove an item from the list. */ void wlr_list_del(struct wlr_list *list, size_t index); + /** - * Remove and return an item from the end of the list + * Remove and return an item from the end of the list. */ void *wlr_list_pop(struct wlr_list *list); + /** - * Get a reference to the last item of a list without removal + * Get a reference to the last item of a list without removal. */ void *wlr_list_peek(struct wlr_list *list); + +/** + * Append each item in `source` to `list`. + * Does not modify `source`. + * Returns: new list length or `-1` on failure. + */ +ssize_t wlr_list_cat(struct wlr_list *list, const struct wlr_list *source); + /** - * Append each item in `source` to `list` - * Does not modify `source` - * Returns: new list length or `-1` on failure - */ -int wlr_list_cat(struct wlr_list *list, struct wlr_list *source); -// See qsort. Remember to use *_qsort functions as compare functions, -// because they dereference the left and right arguments first! -void wlr_list_qsort(struct wlr_list *list, int compare(const void *left, const void *right)); -// Return index for first item in list that returns 0 for given compare -// function or -1 if none matches. -int wlr_list_seq_find(struct wlr_list *list, - int compare(const void *item, const void *cmp_to), - const void *cmp_to); + * Sort a list using `qsort`. + */ +void wlr_list_qsort(struct wlr_list *list, + int compare(const void *left, const void *right)); + +/** + * Return the index of the first item in the list that returns 0 for the given + * `compare` function, or -1 if none matches. + */ +ssize_t wlr_list_find(struct wlr_list *list, + int compare(const void *item, const void *cmp_to), const void *cmp_to); #endif diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 6518b703..9b493d88 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -5,7 +5,6 @@ #include #include #include -#include #ifdef HAS_XCB_ICCCM #include @@ -86,7 +85,6 @@ struct wlr_xwayland_surface { char *class; char *instance; struct wlr_xwayland_surface *parent; - struct wlr_list *state; // list of xcb_atom_t pid_t pid; xcb_atom_t *window_type; diff --git a/types/wlr_list.c b/types/wlr_list.c index 33e3ea8a..565a155b 100644 --- a/types/wlr_list.c +++ b/types/wlr_list.c @@ -3,26 +3,23 @@ #include #include #include +#include #include -struct wlr_list *wlr_list_create(void) { - struct wlr_list *list = malloc(sizeof(struct wlr_list)); - if (!list) { - return NULL; - } +bool wlr_list_init(struct wlr_list *list) { list->capacity = 10; list->length = 0; - list->items = malloc(sizeof(void*) * list->capacity); - if (!list->items) { - free(list); - return NULL; + list->items = malloc(sizeof(void *) * list->capacity); + if (list->items == NULL) { + return false; } - return list; + return true; } static bool list_resize(struct wlr_list *list) { if (list->length == list->capacity) { - void *new_items = realloc(list->items, sizeof(void*) * (list->capacity + 10)); + void *new_items = realloc(list->items, + sizeof(void *) * (list->capacity + 10)); if (!new_items) { return false; } @@ -32,24 +29,17 @@ static bool list_resize(struct wlr_list *list) { return true; } -void wlr_list_free(struct wlr_list *list) { - if (list == NULL) { - return; - } +void wlr_list_finish(struct wlr_list *list) { free(list->items); - free(list); } -void wlr_list_foreach(struct wlr_list *list, void (*callback)(void *item)) { - if (list == NULL || callback == NULL) { - return; - } +void wlr_list_for_each(struct wlr_list *list, void (*callback)(void *item)) { for (size_t i = 0; i < list->length; i++) { callback(list->items[i]); } } -int wlr_list_add(struct wlr_list *list, void *item) { +ssize_t wlr_list_push(struct wlr_list *list, void *item) { if (!list_resize(list)) { return -1; } @@ -57,15 +47,12 @@ int wlr_list_add(struct wlr_list *list, void *item) { return list->length; } -int wlr_list_push(struct wlr_list *list, void *item) { - return wlr_list_add(list, item); -} - -int wlr_list_insert(struct wlr_list *list, size_t index, void *item) { +ssize_t wlr_list_insert(struct wlr_list *list, size_t index, void *item) { if (!list_resize(list)) { return -1; } - memmove(&list->items[index + 1], &list->items[index], sizeof(void*) * (list->length - index)); + memmove(&list->items[index + 1], &list->items[index], + sizeof(void *) * (list->length - index)); list->length++; list->items[index] = item; return list->length; @@ -73,24 +60,31 @@ int wlr_list_insert(struct wlr_list *list, size_t index, void *item) { void wlr_list_del(struct wlr_list *list, size_t index) { list->length--; - memmove(&list->items[index], &list->items[index + 1], sizeof(void*) * (list->length - index)); + memmove(&list->items[index], &list->items[index + 1], + sizeof(void *) * (list->length - index)); } void *wlr_list_pop(struct wlr_list *list) { - void *_ = list->items[list->length - 1]; + if (list->length == 0) { + return NULL; + } + void *last = list->items[list->length - 1]; wlr_list_del(list, list->length - 1); - return _; + return last; } void *wlr_list_peek(struct wlr_list *list) { + if (list->length == 0) { + return NULL; + } return list->items[list->length - 1]; } -int wlr_list_cat(struct wlr_list *list, struct wlr_list *source) { +ssize_t wlr_list_cat(struct wlr_list *list, const struct wlr_list *source) { size_t old_len = list->length; size_t i; for (i = 0; i < source->length; ++i) { - if (wlr_list_add(list, source->items[i]) == -1) { + if (wlr_list_push(list, source->items[i]) == -1) { list->length = old_len; return -1; } @@ -98,13 +92,13 @@ int wlr_list_cat(struct wlr_list *list, struct wlr_list *source) { return list->length; } -void wlr_list_qsort(struct wlr_list *list, int compare(const void *left, const void *right)) { +void wlr_list_qsort(struct wlr_list *list, + int compare(const void *left, const void *right)) { qsort(list->items, list->length, sizeof(void *), compare); } -int wlr_list_seq_find(struct wlr_list *list, - int compare(const void *item, const void *data), - const void *data) { +ssize_t wlr_list_find(struct wlr_list *list, + int compare(const void *item, const void *data), const void *data) { for (size_t i = 0; i < list->length; i++) { void *item = list->items[i]; if (compare(item, data) == 0) { diff --git a/types/wlr_output.c b/types/wlr_output.c index 411dd404..94fe4c3b 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/xwayland/xwm.c b/xwayland/xwm.c index dff9fac2..3f972e56 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -217,7 +217,6 @@ static void wlr_xwayland_surface_destroy( free(xsurface->title); free(xsurface->class); free(xsurface->instance); - wlr_list_free(xsurface->state); free(xsurface->window_type); free(xsurface->protocols); free(xsurface->hints); From c0e2dc6f7875a3dc5ad7ca49444e068f15c001ed Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 19 Nov 2017 22:55:44 +0100 Subject: [PATCH 07/11] Update view position for previous configure_ack too --- rootston/xdg_shell_v6.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 8819ebdd..ca011d49 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -174,7 +174,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; if (roots_surface->move_resize.configure_serial > 0 && - roots_surface->move_resize.configure_serial == + roots_surface->move_resize.configure_serial >= surface->configure_serial) { struct wlr_box size; get_size(view, &size); @@ -187,7 +187,11 @@ static void handle_commit(struct wl_listener *listener, void *data) { view->y = roots_surface->move_resize.y + roots_surface->move_resize.height - size.height; } - roots_surface->move_resize.configure_serial = 0; + + if (roots_surface->move_resize.configure_serial == + surface->configure_serial) { + roots_surface->move_resize.configure_serial = 0; + } } } From ac6385689f8a4895888f069afeae037edc7c7e19 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 20 Nov 2017 11:10:43 +0100 Subject: [PATCH 08/11] Set min view size to 1x1 --- rootston/cursor.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/rootston/cursor.c b/rootston/cursor.c index db2a414c..93ee03d4 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -69,37 +69,37 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, if (seat->focus) { double dx = cursor->cursor->x - cursor->offs_x; double dy = cursor->cursor->y - cursor->offs_y; - double active_x = seat->focus->x; - double active_y = seat->focus->y; + double x = seat->focus->x; + double y = seat->focus->y; int width = cursor->view_width; int height = cursor->view_height; if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { - active_y = cursor->view_y + dy; + y = cursor->view_y + dy; height -= dy; - if (height < 0) { - active_y += height; + if (height < 1) { + y += height; } } else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) { height += dy; } if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { - active_x = cursor->view_x + dx; + x = cursor->view_x + dx; width -= dx; - if (width < 0) { - active_x += width; + if (width < 1) { + x += width; } } else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { width += dx; } - if (width < 0) { - width = 0; + if (width < 1) { + width = 1; } - if (height < 0) { - height = 0; + if (height < 1) { + height = 1; } - view_move_resize(seat->focus, active_x, active_y, width, height); + view_move_resize(seat->focus, x, y, width, height); } break; case ROOTS_CURSOR_ROTATE: From 0153a0ed8fb934333505ee7793b1c493d8d0cd35 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 20 Nov 2017 12:05:21 +0100 Subject: [PATCH 09/11] Fix laggy move-resize for xwayland views --- include/rootston/view.h | 15 ++++++++----- rootston/xdg_shell_v6.c | 37 +++++++++++++++--------------- rootston/xwayland.c | 50 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 73 insertions(+), 29 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 058dc73e..66fc88bc 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -29,12 +29,7 @@ struct roots_xdg_surface_v6 { struct wl_listener request_resize; struct wl_listener request_maximize; - struct { - uint32_t configure_serial; - double x, y; - bool update_x, update_y; - uint32_t width, height; - } move_resize; + uint32_t pending_move_resize_configure_serial; }; struct roots_xwayland_surface { @@ -48,6 +43,8 @@ struct roots_xwayland_surface { struct wl_listener request_maximize; struct wl_listener map_notify; struct wl_listener unmap_notify; + + struct wl_listener surface_commit; }; enum roots_view_type { @@ -69,6 +66,12 @@ struct roots_view { float rotation; } saved; + struct { + bool update_x, update_y; + double x, y; + uint32_t width, height; + } pending_move_resize; + // TODO: Something for roots-enforced width/height enum roots_view_type type; union { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index ca011d49..95df36a2 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -90,17 +90,17 @@ static void move_resize(struct roots_view *view, double x, double y, y = y + height - constrained_height; } - roots_surface->move_resize.x = x; - roots_surface->move_resize.y = y; - roots_surface->move_resize.update_x = update_x; - roots_surface->move_resize.update_y = update_y; - roots_surface->move_resize.width = constrained_width; - roots_surface->move_resize.height = constrained_height; + view->pending_move_resize.update_x = update_x; + view->pending_move_resize.update_y = update_y; + view->pending_move_resize.x = x; + view->pending_move_resize.y = y; + view->pending_move_resize.width = constrained_width; + view->pending_move_resize.height = constrained_height; uint32_t serial = wlr_xdg_toplevel_v6_set_size(surface, constrained_width, constrained_height); if (serial > 0) { - roots_surface->move_resize.configure_serial = serial; + roots_surface->pending_move_resize_configure_serial = serial; } else { view->x = x; view->y = y; @@ -173,24 +173,23 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; - if (roots_surface->move_resize.configure_serial > 0 && - roots_surface->move_resize.configure_serial >= - surface->configure_serial) { + uint32_t pending_serial = + roots_surface->pending_move_resize_configure_serial; + if (pending_serial > 0 && pending_serial >= surface->configure_serial) { struct wlr_box size; get_size(view, &size); - if (roots_surface->move_resize.update_x) { - view->x = roots_surface->move_resize.x + - roots_surface->move_resize.width - size.width; + if (view->pending_move_resize.update_x) { + view->x = view->pending_move_resize.x + + view->pending_move_resize.width - size.width; } - if (roots_surface->move_resize.update_y) { - view->y = roots_surface->move_resize.y + - roots_surface->move_resize.height - size.height; + if (view->pending_move_resize.update_y) { + view->y = view->pending_move_resize.y + + view->pending_move_resize.height - size.height; } - if (roots_surface->move_resize.configure_serial == - surface->configure_serial) { - roots_surface->move_resize.configure_serial = 0; + if (pending_serial == surface->configure_serial) { + roots_surface->pending_move_resize_configure_serial = 0; } } } diff --git a/rootston/xwayland.c b/rootston/xwayland.c index f1093552..372fd951 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -66,15 +66,26 @@ static void move_resize(struct roots_view *view, double x, double y, assert(view->type == ROOTS_XWAYLAND_VIEW); struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; + bool update_x = x != view->x; + bool update_y = y != view->y; + uint32_t constrained_width, constrained_height; apply_size_constraints(xwayland_surface, width, height, &constrained_width, &constrained_height); - x = x + width - constrained_width; - y = y + height - constrained_height; + if (update_x) { + x = x + width - constrained_width; + } + if (update_y) { + y = y + height - constrained_height; + } - view->x = x; - view->y = y; + view->pending_move_resize.update_x = update_x; + view->pending_move_resize.update_y = update_y; + view->pending_move_resize.x = x; + view->pending_move_resize.y = y; + view->pending_move_resize.width = constrained_width; + view->pending_move_resize.height = constrained_height; wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, x, y, constrained_width, constrained_height); @@ -171,6 +182,27 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) { view_maximize(view, maximized); } +static void handle_surface_commit(struct wl_listener *listener, void *data) { + struct roots_xwayland_surface *roots_surface = + wl_container_of(listener, roots_surface, surface_commit); + struct roots_view *view = roots_surface->view; + struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; + + int width = xwayland_surface->surface->current->width; + int height = xwayland_surface->surface->current->height; + + if (view->pending_move_resize.update_x) { + view->x = view->pending_move_resize.x + + view->pending_move_resize.width - width; + view->pending_move_resize.update_x = false; + } + if (view->pending_move_resize.update_y) { + view->y = view->pending_move_resize.y + + view->pending_move_resize.height - height; + view->pending_move_resize.update_y = false; + } +} + static void handle_map_notify(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, map_notify); @@ -182,6 +214,10 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { view->x = (double)xsurface->x; view->y = (double)xsurface->y; + roots_surface->surface_commit.notify = handle_surface_commit; + wl_signal_add(&xsurface->surface->events.commit, + &roots_surface->surface_commit); + wlr_list_push(desktop->views, roots_surface->view); } @@ -191,6 +227,8 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = roots_surface->view->desktop; roots_surface->view->wlr_surface = NULL; + wl_list_remove(&roots_surface->surface_commit.link); + for (size_t i = 0; i < desktop->views->length; i++) { if (desktop->views->items[i] == roots_surface->view) { wlr_list_del(desktop->views, i); @@ -231,6 +269,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { wl_signal_add(&surface->events.request_maximize, &roots_surface->request_maximize); + roots_surface->surface_commit.notify = handle_surface_commit; + wl_signal_add(&surface->surface->events.commit, + &roots_surface->surface_commit); + struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (view == NULL) { free(roots_surface); From 272e0858e49bf341b363fdbe59a5f669ba678ce2 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 20 Nov 2017 12:16:10 +0100 Subject: [PATCH 10/11] Fix laggy move-resize for wl-shell views --- rootston/desktop.c | 12 ++++++++++-- rootston/wl_shell.c | 19 ++++++++++++++++++- rootston/xwayland.c | 6 +++--- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/rootston/desktop.c b/rootston/desktop.c index b3287ed0..c6a1957c 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -103,7 +103,9 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height) { void view_move_resize(struct roots_view *view, double x, double y, uint32_t width, uint32_t height) { - if (x == view->x && y == view->y) { + bool update_x = x != view->x; + bool update_y = y != view->y; + if (!update_x && !update_y) { view_resize(view, width, height); return; } @@ -113,7 +115,13 @@ void view_move_resize(struct roots_view *view, double x, double y, return; } - view_move(view, x, y); + view->pending_move_resize.update_x = update_x; + view->pending_move_resize.update_y = update_y; + view->pending_move_resize.x = x; + view->pending_move_resize.y = y; + view->pending_move_resize.width = width; + view->pending_move_resize.height = height; + view_resize(view, width, height); } diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 96f461fe..0043219f 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -71,7 +71,24 @@ static void handle_set_state(struct wl_listener *listener, void *data) { } static void handle_surface_commit(struct wl_listener *listener, void *data) { - // TODO do we need to do anything here? + struct roots_wl_shell_surface *roots_surface = + wl_container_of(listener, roots_surface, surface_commit); + struct roots_view *view = roots_surface->view; + struct wlr_surface *wlr_surface = view->wlr_surface; + + int width = wlr_surface->current->width; + int height = wlr_surface->current->height; + + if (view->pending_move_resize.update_x) { + view->x = view->pending_move_resize.x + + view->pending_move_resize.width - width; + view->pending_move_resize.update_x = false; + } + if (view->pending_move_resize.update_y) { + view->y = view->pending_move_resize.y + + view->pending_move_resize.height - height; + view->pending_move_resize.update_y = false; + } } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 372fd951..b2f64879 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -186,10 +186,10 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, surface_commit); struct roots_view *view = roots_surface->view; - struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; + struct wlr_surface *wlr_surface = view->wlr_surface; - int width = xwayland_surface->surface->current->width; - int height = xwayland_surface->surface->current->height; + int width = wlr_surface->current->width; + int height = wlr_surface->current->height; if (view->pending_move_resize.update_x) { view->x = view->pending_move_resize.x + From 64221c6da1a8783ba1e614a1c821b585b1e70ab8 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 20 Nov 2017 21:26:20 +0100 Subject: [PATCH 11/11] Use wl_list for touch points in examples/ --- examples/pointer.c | 33 ++++++++++++++++++--------------- examples/touch.c | 29 ++++++++++++++--------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/examples/pointer.c b/examples/pointer.c index 8fafb3d6..f75e1bce 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -46,7 +46,7 @@ struct sample_state { struct wl_listener touch_up; struct wl_listener touch_down; struct wl_listener touch_cancel; - struct wlr_list *touch_points; + struct wl_list touch_points; struct wl_listener tablet_tool_axis; struct wl_listener tablet_tool_proxmity; @@ -57,22 +57,25 @@ struct sample_state { struct touch_point { int32_t touch_id; double x, y; + struct wl_list link; }; static void warp_to_touch(struct sample_state *sample, struct wlr_input_device *dev) { - if (sample->touch_points->length == 0) { + if (wl_list_empty(&sample->touch_points)) { return; } double x = 0, y = 0; - for (size_t i = 0; i < sample->touch_points->length; ++i) { - struct touch_point *point = sample->touch_points->items[i]; + size_t n = 0; + struct touch_point *point; + wl_list_for_each(point, &sample->touch_points, link) { x += point->x; y += point->y; + n++; } - x /= sample->touch_points->length; - y /= sample->touch_points->length; + x /= n; + y /= n; wlr_cursor_warp_absolute(sample->cursor, dev, x, y); } @@ -197,10 +200,11 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) { static void handle_touch_up(struct wl_listener *listener, void *data) { struct sample_state *sample = wl_container_of(listener, sample, touch_up); struct wlr_event_touch_up *event = data; - for (size_t i = 0; i < sample->touch_points->length; ++i) { - struct touch_point *point = sample->touch_points->items[i]; + + struct touch_point *point, *tmp; + wl_list_for_each_safe(point, tmp, &sample->touch_points, link) { if (point->touch_id == event->touch_id) { - wlr_list_del(sample->touch_points, i); + wl_list_remove(&point->link); break; } } @@ -215,9 +219,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { point->touch_id = event->touch_id; point->x = event->x_mm / event->width_mm; point->y = event->y_mm / event->height_mm; - if (wlr_list_add(sample->touch_points, point) == -1) { - free(point); - } + wl_list_insert(&sample->touch_points, &point->link); warp_to_touch(sample, event->device); } @@ -226,8 +228,9 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { struct sample_state *sample = wl_container_of(listener, sample, touch_motion); struct wlr_event_touch_motion *event = data; - for (size_t i = 0; i < sample->touch_points->length; ++i) { - struct touch_point *point = sample->touch_points->items[i]; + + 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; @@ -257,7 +260,6 @@ int main(int argc, char *argv[]) { struct sample_state state = { .default_color = { 0.25f, 0.25f, 0.25f, 1 }, .clear_color = { 0.25f, 0.25f, 0.25f, 1 }, - .touch_points = wlr_list_create(), }; state.config = parse_args(argc, argv); @@ -266,6 +268,7 @@ int main(int argc, char *argv[]) { wlr_cursor_attach_output_layout(state.cursor, state.layout); wlr_cursor_map_to_region(state.cursor, state.config->cursor.mapped_box); wl_list_init(&state.devices); + wl_list_init(&state.touch_points); // pointer events wl_signal_add(&state.cursor->events.motion, &state.cursor_motion); diff --git a/examples/touch.c b/examples/touch.c index d1891525..f18b5d26 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -24,12 +24,13 @@ struct sample_state { struct wlr_renderer *renderer; struct wlr_texture *cat_texture; - struct wlr_list *touch_points; + struct wl_list touch_points; }; struct touch_point { int32_t touch_id; double x, y; + struct wl_list link; }; static void handle_output_frame(struct output_state *output, struct timespec *ts) { @@ -44,14 +45,14 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_begin(sample->renderer, wlr_output); float matrix[16]; - for (size_t i = 0; i < sample->touch_points->length; ++i) { - struct touch_point *p = sample->touch_points->items[i]; + struct touch_point *p; + wl_list_for_each(p, &sample->touch_points, link) { wlr_texture_get_matrix(sample->cat_texture, &matrix, &wlr_output->transform_matrix, (int)(p->x * width) - sample->cat_texture->width / 2, (int)(p->y * height) - sample->cat_texture->height / 2); wlr_render_with_matrix(sample->renderer, - sample->cat_texture, &matrix); + sample->cat_texture, &matrix); } wlr_renderer_end(sample->renderer); @@ -65,17 +66,15 @@ static void handle_touch_down(struct touch_state *tstate, int32_t touch_id, point->touch_id = touch_id; point->x = x / width; point->y = y / height; - if (wlr_list_add(sample->touch_points, point) == -1) { - free(point); - } + wl_list_insert(&sample->touch_points, &point->link); } static void handle_touch_up(struct touch_state *tstate, int32_t touch_id) { struct sample_state *sample = tstate->compositor->data; - for (size_t i = 0; i < sample->touch_points->length; ++i) { - struct touch_point *point = sample->touch_points->items[i]; + struct touch_point *point, *tmp; + wl_list_for_each_safe(point, tmp, &sample->touch_points, link) { if (point->touch_id == touch_id) { - wlr_list_del(sample->touch_points, i); + wl_list_remove(&point->link); break; } } @@ -84,8 +83,8 @@ 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) { struct sample_state *sample = tstate->compositor->data; - for (size_t i = 0; i < sample->touch_points->length; ++i) { - struct touch_point *point = sample->touch_points->items[i]; + 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; @@ -95,9 +94,9 @@ static void handle_touch_motion(struct touch_state *tstate, int32_t touch_id, } int main(int argc, char *argv[]) { - struct sample_state state = { - .touch_points = wlr_list_create() - }; + struct sample_state state; + wl_list_init(&state.touch_points); + struct compositor_state compositor = { 0, .data = &state, .output_frame_cb = handle_output_frame,