Skip to content

Commit

Permalink
wobbly: Fix resizing for wobbly surfaces
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
soreau committed Aug 18, 2014
1 parent 746f1d7 commit ecd36df
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
55 changes: 42 additions & 13 deletions desktop-shell/shell.c
Expand Up @@ -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);

Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/compositor.h
Expand Up @@ -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__); \
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/wobbly.c
Expand Up @@ -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;

Expand Down

0 comments on commit ecd36df

Please sign in to comment.