From ecd36dfdc75bfa17c3c6fbc3936f8f4a2fe59cc7 Mon Sep 17 00:00:00 2001 From: Scott Moreau Date: Mon, 18 Aug 2014 14:42:04 -0600 Subject: [PATCH] wobbly: Fix resizing for wobbly surfaces This problem was due to the fact that rotate changed the surface position when rotating to offset the fact that resize didn't keep the position updated as expected, that is, position.p + 0.5 * size.p = center.p. Wobbly must also make this assumption to sync correctly but the position must be adjusted during resize, not on rotate motion. As a side note, shell_surface_adjust_for_transform should end up in the rotate plugin resize handler, if/when it is ported to a standalone version. --- desktop-shell/shell.c | 55 +++++++++++++++++++++++++++++++++---------- src/compositor.h | 4 ++-- src/wobbly.c | 4 ++-- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index e900a3ad..21d1c2bc 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -4343,7 +4343,7 @@ rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, container_of(grab, struct rotate_grab, base.grab); struct weston_pointer *pointer = grab->pointer; struct shell_surface *shsurf = rotate->base.shsurf; - float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; + float cx, cy, dx, dy, r; weston_pointer_move(pointer, x, y); @@ -4382,18 +4382,6 @@ rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, weston_matrix_init(&rotate->rotation); } - /* We need to adjust the position of the surface - * in case it was resized in a rotated state before */ - cposx = shsurf->view->geometry.x + cx; - cposy = shsurf->view->geometry.y + cy; - dposx = rotate->center.x - cposx; - dposy = rotate->center.y - cposy; - if (dposx != 0.0f || dposy != 0.0f) { - weston_view_set_position(shsurf->view, - shsurf->view->geometry.x + dposx, - shsurf->view->geometry.y + dposy); - } - /* Repaint implies weston_surface_update_transform(), which * lazily applies the damage due to rotation update. */ @@ -5063,6 +5051,44 @@ map(struct desktop_shell *shell, struct shell_surface *shsurf, } } +static void +shell_surface_adjust_for_transform(struct shell_surface *shsurf) +{ + struct weston_matrix *matrix; + float cx, cy, cposx, cposy, dposx, dposy, rcx, rcy; + + /* Adjust for rotation transformation */ + cx = 0.5f * shsurf->surface->width; + cy = 0.5f * shsurf->surface->height; + + wl_list_remove(&shsurf->rotation.transform.link); + weston_view_geometry_dirty(shsurf->view); + + matrix = &shsurf->rotation.transform.matrix; + + weston_matrix_init(matrix); + weston_matrix_translate(matrix, -cx, -cy, 0.0f); + weston_matrix_multiply(matrix, &shsurf->rotation.rotation); + weston_matrix_translate(matrix, cx, cy, 0.0f); + + wl_list_insert( + &shsurf->view->geometry.transformation_list, + &shsurf->rotation.transform.link); + + weston_view_to_global_float(shsurf->view, cx, cy, &rcx, &rcy); + + /* Position surface to maintain expected center coordinates */ + cposx = shsurf->view->geometry.x + cx; + cposy = shsurf->view->geometry.y + cy; + dposx = rcx - cposx; + dposy = rcy - cposy; + if (dposx != 0.0f || dposy != 0.0f) { + weston_view_set_position(shsurf->view, + shsurf->view->geometry.x + dposx, + shsurf->view->geometry.y + dposy); + } +} + static void configure(struct desktop_shell *shell, struct weston_surface *surface, float x, float y) @@ -5097,6 +5123,9 @@ configure(struct desktop_shell *shell, struct weston_surface *surface, if (shsurf->state.maximized) surface->output = shsurf->output; } + + if (!wl_list_empty(&shsurf->rotation.transform.link)) + shell_surface_adjust_for_transform(shsurf); } static void diff --git a/src/compositor.h b/src/compositor.h index e0cbcd8d..e44e88d6 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -628,7 +628,7 @@ struct weston_compositor { }; /* WESTON_PLUGIN_CALL_SINGLE(compositor, weston_plugin, function, arguments to function) - * Call a function for a specific plugin */ + * Call a function for a weston_plugin */ #define WESTON_PLUGIN_CALL_SINGLE(p, f, ...) ({ \ if (p->interface->f) \ p->interface->f(__VA_ARGS__); \ @@ -640,7 +640,7 @@ struct weston_compositor { struct weston_plugin *p; \ \ wl_list_for_each(p, &(c)->plugin_list, link) \ - WESTON_PLUGIN_CALL_SINGLE(p, f, __VA_ARGS__); \ + WESTON_PLUGIN_CALL_SINGLE(p, f, __VA_ARGS__); \ }) struct weston_plugin; diff --git a/src/wobbly.c b/src/wobbly.c index 215cfebc..6faeaaee 100644 --- a/src/wobbly.c +++ b/src/wobbly.c @@ -827,8 +827,8 @@ wobbly_resize_notify(struct weston_view *view) ww = ws->ww; - x = view->geometry.x; - y = view->geometry.y; + x = ws->x = view->geometry.x; + y = ws->y = view->geometry.y; w = ws->width = surface->width; h = ws->height = surface->height;