aboutsummaryrefslogtreecommitdiff
path: root/rootston/output.c
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2017-11-17 23:29:47 +0100
committeremersion <contact@emersion.fr>2017-11-17 23:29:47 +0100
commit27937add762bb2594828ac678859bfdde4275f1e (patch)
treeaa9813fd534d019a5e967ffad31d153d30ae7fa1 /rootston/output.c
parent3e3209cba22c9a5a562acc5e543946408a36e2f4 (diff)
parentbf5640db128b930b38ebca2b1d8a79e028ad9f39 (diff)
Merge branch 'master' into laggy-move-resize
Diffstat (limited to 'rootston/output.c')
-rw-r--r--rootston/output.c165
1 files changed, 108 insertions, 57 deletions
diff --git a/rootston/output.c b/rootston/output.c
index baa7b6cc..28312c2c 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -5,6 +5,7 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_wl_shell.h>
+#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/render/matrix.h>
#include <wlr/util/log.h>
@@ -16,37 +17,67 @@ static inline int64_t timespec_to_msec(const struct timespec *a) {
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
}
+/**
+ * Rotate a child's position relative to a parent. The parent size is (pw, ph),
+ * the child position is (*sx, *sy) and its size is (sw, sh).
+ */
+static void rotate_child_position(double *sx, double *sy, double sw, double sh,
+ double pw, double ph, float rotation) {
+ if (rotation != 0.0) {
+ // Coordinates relative to the center of the subsurface
+ double ox = *sx - pw/2 + sw/2,
+ oy = *sy - ph/2 + sh/2;
+ // Rotated coordinates
+ double rx = cos(-rotation)*ox - sin(-rotation)*oy,
+ ry = cos(-rotation)*oy + sin(-rotation)*ox;
+ *sx = rx + pw/2 - sw/2;
+ *sy = ry + ph/2 - sh/2;
+ }
+}
+
static void render_surface(struct wlr_surface *surface,
struct roots_desktop *desktop, struct wlr_output *wlr_output,
struct timespec *when, double lx, double ly, float rotation) {
if (surface->texture->valid) {
- int width = surface->current->buffer_width;
- int height = surface->current->buffer_height;
+ int width = surface->current->width;
+ int height = surface->current->height;
+ int render_width = width * wlr_output->scale;
+ int render_height = height * wlr_output->scale;
double ox = lx, oy = ly;
wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy);
+ ox *= wlr_output->scale;
+ oy *= wlr_output->scale;
if (wlr_output_layout_intersects(desktop->layout, wlr_output,
- lx, ly, lx + width, ly + height)) {
+ lx, ly, lx + render_width, ly + render_height)) {
float matrix[16];
float translate_origin[16];
wlr_matrix_translate(&translate_origin,
- (int)ox + width / 2, (int)oy + height / 2, 0);
+ (int)ox + render_width / 2, (int)oy + render_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);
+ wlr_matrix_translate(&translate_center, -render_width / 2,
+ -render_height / 2, 0);
+
+ float scale[16];
+ wlr_matrix_scale(&scale, render_width, render_height, 1);
+
float transform[16];
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,
- surface->texture, &matrix);
+ wlr_matrix_mul(&transform, &scale, &transform);
+ wlr_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix);
+
+ wlr_render_with_matrix(desktop->server->renderer, surface->texture,
+ &matrix);
struct wlr_frame_callback *cb, *cnext;
wl_list_for_each_safe(cb, cnext,
- &surface->current->frame_callback_list, link) {
+ &surface->current->frame_callback_list, link) {
wl_callback_send_done(cb->resource, timespec_to_msec(when));
wl_resource_destroy(cb->resource);
}
@@ -54,20 +85,12 @@ 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;
- }
+ struct wlr_surface_state *state = subsurface->surface->current;
+ double sx = state->subsurface_position.x;
+ double sy = state->subsurface_position.y;
+ double sw = state->buffer_width / state->scale;
+ double sh = state->buffer_height / state->scale;
+ rotate_child_position(&sx, &sy, sw, sh, width, height, rotation);
render_surface(subsurface->surface, desktop, wlr_output, when,
lx + sx,
@@ -80,35 +103,53 @@ static void render_surface(struct wlr_surface *surface,
static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface,
struct roots_desktop *desktop, struct wlr_output *wlr_output,
struct timespec *when, double base_x, double base_y, float rotation) {
- // TODO: make sure this works with view rotation
+ double width = surface->surface->current->width;
+ double height = surface->surface->current->height;
+
struct wlr_xdg_surface_v6 *popup;
wl_list_for_each(popup, &surface->popups, popup_link) {
if (!popup->configured) {
continue;
}
- double popup_x = base_x + surface->geometry->x +
- popup->popup_state->geometry.x - popup->geometry->x;
- double popup_y = base_y + surface->geometry->y +
- popup->popup_state->geometry.y - popup->geometry->y;
- render_surface(popup->surface, desktop, wlr_output, when, popup_x,
- popup_y, rotation);
- render_xdg_v6_popups(popup, desktop, wlr_output, when, popup_x, popup_y, rotation);
+ double popup_width = popup->surface->current->width;
+ double popup_height = popup->surface->current->height;
+
+ double popup_sx, popup_sy;
+ wlr_xdg_surface_v6_popup_get_position(popup, &popup_sx, &popup_sy);
+ rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height,
+ width, height, rotation);
+
+ render_surface(popup->surface, desktop, wlr_output, when,
+ base_x + popup_sx, base_y + popup_sy, rotation);
+ render_xdg_v6_popups(popup, desktop, wlr_output, when,
+ base_x + popup_sx, base_y + popup_sy, rotation);
}
}
-static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface, struct roots_desktop *desktop,
- struct wlr_output *wlr_output, struct timespec *when, double lx,
- double ly, float rotation, bool is_child) {
+static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface,
+ struct roots_desktop *desktop, struct wlr_output *wlr_output,
+ struct timespec *when, double lx, double ly, float rotation,
+ bool is_child) {
if (is_child || surface->state != WLR_WL_SHELL_SURFACE_STATE_POPUP) {
render_surface(surface->surface, desktop, wlr_output, when,
lx, ly, rotation);
+
+ double width = surface->surface->current->width;
+ double height = surface->surface->current->height;
+
struct wlr_wl_shell_surface *popup;
wl_list_for_each(popup, &surface->popups, popup_link) {
+ double popup_width = popup->surface->current->width;
+ double popup_height = popup->surface->current->height;
+
+ double popup_x = popup->transient_state->x;
+ double popup_y = popup->transient_state->y;
+ rotate_child_position(&popup_x, &popup_y, popup_width, popup_height,
+ width, height, rotation);
+
render_wl_shell_surface(popup, desktop, wlr_output, when,
- lx + popup->transient_state->x,
- ly + popup->transient_state->y,
- rotation, true);
+ lx + popup_x, ly + popup_y, rotation, true);
}
}
}
@@ -151,15 +192,18 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
}
struct roots_drag_icon *drag_icon = NULL;
- wl_list_for_each(drag_icon, &server->input->drag_icons, link) {
- if (!drag_icon->mapped) {
- continue;
+ struct roots_seat *seat = NULL;
+ wl_list_for_each(seat, &server->input->seats, link) {
+ wl_list_for_each(drag_icon, &seat->drag_icons, link) {
+ if (!drag_icon->mapped) {
+ continue;
+ }
+ struct wlr_surface *icon = drag_icon->surface;
+ struct wlr_cursor *cursor = seat->cursor->cursor;
+ double icon_x = cursor->x + drag_icon->sx;
+ double icon_y = cursor->y + drag_icon->sy;
+ render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0);
}
- struct wlr_surface *icon = drag_icon->surface;
- struct wlr_cursor *cursor = server->input->cursor;
- double icon_x = cursor->x + drag_icon->sx;
- double icon_y = cursor->y + drag_icon->sy;
- render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0);
}
wlr_renderer_end(server->renderer);
@@ -168,7 +212,8 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
output->last_frame = desktop->last_frame = now;
}
-static void set_mode(struct wlr_output *output, struct output_config *oc) {
+static void set_mode(struct wlr_output *output,
+ struct roots_output_config *oc) {
struct wlr_output_mode *mode, *best = NULL;
int mhz = (int)(oc->mode.refresh_rate * 1000);
wl_list_for_each(mode, &output->modes, link) {
@@ -196,8 +241,9 @@ void output_add_notify(struct wl_listener *listener, void *data) {
struct roots_config *config = desktop->config;
wlr_log(L_DEBUG, "Output '%s' added", wlr_output->name);
- wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", wlr_output->make,
- wlr_output->model, wlr_output->phys_width, wlr_output->phys_height);
+ wlr_log(L_DEBUG, "%s %s %s %"PRId32"mm x %"PRId32"mm", wlr_output->make,
+ wlr_output->model, wlr_output->serial, wlr_output->phys_width,
+ wlr_output->phys_height);
if (wl_list_length(&wlr_output->modes) > 0) {
struct wlr_output_mode *mode = NULL;
mode = wl_container_of((&wlr_output->modes)->prev, mode, link);
@@ -212,11 +258,13 @@ void output_add_notify(struct wl_listener *listener, void *data) {
wl_signal_add(&wlr_output->events.frame, &output->frame);
wl_list_insert(&desktop->outputs, &output->link);
- struct output_config *output_config = config_get_output(config, wlr_output);
+ struct roots_output_config *output_config =
+ roots_config_get_output(config, wlr_output);
if (output_config) {
if (output_config->mode.width) {
set_mode(wlr_output, output_config);
}
+ wlr_output->scale = output_config->scale;
wlr_output_transform(wlr_output, output_config->transform);
wlr_output_layout_add(desktop->layout,
wlr_output, output_config->x, output_config->y);
@@ -224,14 +272,17 @@ void output_add_notify(struct wl_listener *listener, void *data) {
wlr_output_layout_add_auto(desktop->layout, wlr_output);
}
- cursor_load_config(config, input->cursor, input, desktop);
-
- struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme);
- struct wlr_xcursor_image *image = xcursor->images[0];
- wlr_cursor_set_image(input->cursor, image->buffer, image->width,
- image->width, image->height, image->hotspot_x, image->hotspot_y);
+ struct roots_seat *seat;
+ wl_list_for_each(seat, &input->seats, link) {
+ if (wlr_xcursor_manager_load(seat->cursor->xcursor_manager,
+ wlr_output->scale)) {
+ wlr_log(L_ERROR, "Cannot load xcursor theme for output '%s' "
+ "with scale %d", wlr_output->name, wlr_output->scale);
+ }
- wlr_cursor_warp(input->cursor, NULL, input->cursor->x, input->cursor->y);
+ roots_seat_configure_cursor(seat);
+ roots_seat_configure_xcursor(seat);
+ }
}
void output_remove_notify(struct wl_listener *listener, void *data) {