diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-10-05 13:12:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-05 13:12:29 -0400 |
commit | d74a6d254fd1934ca6ca9439b66ea65e6b389822 (patch) | |
tree | e09e3e5085053e7c6b368acb2e09f5fd5eb05e05 /rootston/output.c | |
parent | cec012019f6146b1376bb787dc96b73c7de82266 (diff) | |
parent | 1a775adbde0ba81e6dcd2878a660a1386a8f972f (diff) |
Merge pull request #198 from emersion/rootston-move-resize-rotate
rootston: force move, resize and rotate
Diffstat (limited to 'rootston/output.c')
-rw-r--r-- | rootston/output.c | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/rootston/output.c b/rootston/output.c index bbc957aa..1d5ef98b 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -18,7 +18,7 @@ static inline int64_t timespec_to_msec(const struct timespec *a) { static void render_surface(struct wlr_surface *surface, struct roots_desktop *desktop, struct wlr_output *wlr_output, - struct timespec *when, double lx, double ly) { + struct timespec *when, double lx, double ly, float rotation) { wlr_surface_flush_damage(surface); if (surface->texture->valid) { int width = surface->current->buffer_width; @@ -27,10 +27,20 @@ static void render_surface(struct wlr_surface *surface, wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy); if (wlr_output_layout_intersects(desktop->layout, wlr_output, - lx, ly, lx + width, ly + height)) { + lx, ly, lx + width, ly + height)) { float matrix[16]; + + float translate_origin[16]; + wlr_matrix_translate(&translate_origin, + ox + width/2, oy + height/2, 0); + float rotate[16]; + wlr_matrix_rotate(&rotate, rotation); + float translate_center[16]; + wlr_matrix_translate(&translate_center, -width/2, -height/2, 0); float transform[16]; - wlr_matrix_translate(&transform, ox, oy, 0); + wlr_matrix_mul(&translate_origin, &rotate, &transform); + wlr_matrix_mul(&transform, &translate_center, &transform); + wlr_surface_get_matrix(surface, &matrix, &wlr_output->transform_matrix, &transform); wlr_render_with_matrix(desktop->server->renderer, @@ -46,9 +56,25 @@ static void render_surface(struct wlr_surface *surface, struct wlr_subsurface *subsurface; wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { + double sx = subsurface->surface->current->subsurface_position.x, + sy = subsurface->surface->current->subsurface_position.y; + double sw = subsurface->surface->current->buffer_width, + sh = subsurface->surface->current->buffer_height; + if (rotation != 0.0) { + // Coordinates relative to the center of the subsurface + double ox = sx - (double)width/2 + sw/2, + oy = sy - (double)height/2 + sh/2; + // Rotated coordinates + double rx = cos(-rotation)*ox - sin(-rotation)*oy, + ry = cos(-rotation)*oy + sin(-rotation)*ox; + sx = rx + (double)width/2 - sw/2; + sy = ry + (double)height/2 - sh/2; + } + render_surface(subsurface->surface, desktop, wlr_output, when, - lx + subsurface->surface->current->subsurface_position.x, - ly + subsurface->surface->current->subsurface_position.y); + lx + sx, + ly + sy, + rotation); } } } @@ -56,7 +82,7 @@ static void render_surface(struct wlr_surface *surface, static void render_view(struct roots_view *view, struct roots_desktop *desktop, struct wlr_output *wlr_output, struct timespec *when) { render_surface(view->wlr_surface, desktop, wlr_output, when, - view->x, view->y); + view->x, view->y, view->rotation); } static void output_frame_notify(struct wl_listener *listener, void *data) { |