diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-11-21 11:13:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-21 11:13:18 -0500 |
commit | 1228d0da19edbfc1730b6918760aef444fac8887 (patch) | |
tree | 16643d4bf7029657eaf86656bd98c77b98961a0c /rootston | |
parent | 6bde8dd56beebc429445196d7d4a120677289317 (diff) | |
parent | 1d08d317096a80f96d03cd67303381bdedaaac2a (diff) |
Merge pull request #387 from emersion/laggy-move-resize
Fix laggy move-resize
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/cursor.c | 32 | ||||
-rw-r--r-- | rootston/desktop.c | 15 | ||||
-rw-r--r-- | rootston/wl_shell.c | 19 | ||||
-rw-r--r-- | rootston/xdg_shell_v6.c | 108 | ||||
-rw-r--r-- | rootston/xwayland.c | 68 |
5 files changed, 172 insertions, 70 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c index 71075aa9..3cd5da40 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -71,43 +71,37 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, if (view != NULL) { double dx = cursor->cursor->x - cursor->offs_x; double dy = cursor->cursor->y - cursor->offs_y; - double active_x = view->x; - double active_y = view->y; + double x = view->x; + double y = view->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; } - if (active_x != view->x || - active_y != view->y) { - view_move_resize(view, active_x, active_y, - width, height); - } else { - view_resize(view, width, height); - } + view_move_resize(view, x, y, width, height); } break; case ROOTS_CURSOR_ROTATE: diff --git a/rootston/desktop.c b/rootston/desktop.c index 65730807..608bd37d 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -80,12 +80,25 @@ 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) { + bool update_x = x != view->x; + bool update_y = y != view->y; + if (!update_x && !update_y) { + view_resize(view, width, height); + return; + } + if (view->move_resize) { view->move_resize(view, x, y, width, height); 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 d0f5989b..cf42929e 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/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index ea19753b..9ef4fd3b 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -12,11 +12,11 @@ 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 *surf = view->xdg_surface_v6; + struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; - if (surf->geometry->width > 0 && surf->geometry->height > 0) { - box->width = surf->geometry->width; - box->height = surf->geometry->height; + if (surface->geometry->width > 0 && surface->geometry->height > 0) { + box->width = surface->geometry->width; + box->height = surface->geometry->height; } else { box->width = view->wlr_surface->current->width; box->height = view->wlr_surface->current->height; @@ -25,20 +25,19 @@ static void get_size(const struct roots_view *view, struct wlr_box *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 && @@ -55,39 +54,57 @@ 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); + 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 - contrained_width; - y = y + height - contrained_height; + if (update_x) { + x = x + width - constrained_width; + } + if (update_y) { + y = y + height - constrained_height; + } - // TODO: we should wait for an ack_configure event before updating the - // position - 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_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_height); + uint32_t serial = wlr_xdg_toplevel_v6_set_size(surface, constrained_width, + constrained_height); + if (serial > 0) { + roots_surface->pending_move_resize_configure_serial = serial; + } else { + view->x = x; + view->y = y; + } } static void maximize(struct roots_view *view, bool maximized) { @@ -102,9 +119,9 @@ static void maximize(struct roots_view *view, bool maximized) { 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); } } @@ -151,11 +168,30 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) { } static void handle_commit(struct wl_listener *listener, void *data) { - //struct roots_xdg_surface_v6 *roots_xdg_surface = - // wl_container_of(listener, roots_xdg_surface, commit); - //struct roots_view *view = roots_xdg_surface->view; - //struct wlr_xdg_surface_v6 *surface = view->xdg_surface_v6; - // TODO + 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; + + 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 (view->pending_move_resize.update_x) { + view->x = view->pending_move_resize.x + + view->pending_move_resize.width - size.width; + } + if (view->pending_move_resize.update_y) { + view->y = view->pending_move_resize.y + + view->pending_move_resize.height - size.height; + } + + if (pending_serial == surface->configure_serial) { + roots_surface->pending_move_resize_configure_serial = 0; + } + } } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/rootston/xwayland.c b/rootston/xwayland.c index dfa602b1..628c0e07 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,29 @@ 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); + bool update_x = x != view->x; + bool update_y = y != view->y; - x = x + width - contrained_width; - y = y + height - contrained_height; + uint32_t constrained_width, constrained_height; + apply_size_constraints(xwayland_surface, width, height, &constrained_width, + &constrained_height); - view->x = x; - view->y = y; + if (update_x) { + x = x + width - constrained_width; + } + if (update_y) { + y = y + 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; 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) { @@ -175,6 +186,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_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_map_notify(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, map_notify); @@ -186,6 +218,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); + wl_list_insert(&desktop->views, &view->link); } @@ -194,6 +230,8 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { wl_container_of(listener, roots_surface, unmap_notify); roots_surface->view->wlr_surface = NULL; + wl_list_remove(&roots_surface->surface_commit.link); + wl_list_remove(&roots_surface->view->link); } @@ -229,6 +267,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); |