mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-26 06:59:52 -05:00
Merge pull request #387 from emersion/laggy-move-resize
Fix laggy move-resize
This commit is contained in:
commit
1228d0da19
8 changed files with 216 additions and 104 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
x = x + width - contrained_width;
|
||||
y = y + height - contrained_height;
|
||||
uint32_t constrained_width, constrained_height;
|
||||
apply_size_constraints(surface, width, height, &constrained_width,
|
||||
&constrained_height);
|
||||
|
||||
// TODO: we should wait for an ack_configure event before updating the
|
||||
// position
|
||||
view->x = x;
|
||||
view->y = y;
|
||||
if (update_x) {
|
||||
x = x + width - constrained_width;
|
||||
}
|
||||
if (update_y) {
|
||||
y = y + height - constrained_height;
|
||||
}
|
||||
|
||||
wlr_xdg_toplevel_v6_set_size(surf, contrained_width, contrained_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->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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue