From a7446792a1a0fd9fe3391f041d7bbfe9e2b11255 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 22 Oct 2017 23:19:21 -0400 Subject: [PATCH] Consider scale factor when rendering views --- include/rootston/config.h | 1 + include/rootston/view.h | 1 + include/wlr/types/wlr_surface.h | 6 +++++- rootston/config.c | 4 ++++ rootston/output.c | 3 +++ types/wlr_output.c | 4 ++-- types/wlr_surface.c | 19 ++++++++++++++++--- 7 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/rootston/config.h b/include/rootston/config.h index 75c04619..e0466117 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -8,6 +8,7 @@ struct output_config { char *name; enum wl_output_transform transform; int x, y; + int scale; struct wl_list link; struct { int width, height; diff --git a/include/rootston/view.h b/include/rootston/view.h index 993ff654..4a5e8d08 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -48,6 +48,7 @@ enum roots_view_type { struct roots_view { struct roots_desktop *desktop; + struct roots_output *output; double x, y; float rotation; // TODO: Something for roots-enforced width/height diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index ea4184aa..e1a07566 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -1,10 +1,10 @@ #ifndef WLR_TYPES_WLR_SURFACE_H #define WLR_TYPES_WLR_SURFACE_H - #include #include #include #include +#include struct wlr_frame_callback { struct wl_resource *resource; @@ -135,4 +135,8 @@ struct wlr_surface *wlr_surface_get_main_surface(struct wlr_surface *surface); */ struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface, double sx, double sy, double *sub_x, double *sub_y); + +void wlr_surface_send_enter(struct wlr_surface *surface, + struct wlr_output *output); + #endif diff --git a/rootston/config.c b/rootston/config.c index 18138ab0..983117ba 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -220,6 +220,7 @@ static int config_ini_handler(void *user, const char *section, const char *name, oc = calloc(1, sizeof(struct output_config)); oc->name = strdup(output_name); oc->transform = WL_OUTPUT_TRANSFORM_NORMAL; + oc->scale = 1; wl_list_insert(&config->outputs, &oc->link); } @@ -227,6 +228,9 @@ static int config_ini_handler(void *user, const char *section, const char *name, oc->x = strtol(value, NULL, 10); } else if (strcmp(name, "y") == 0) { oc->y = strtol(value, NULL, 10); + } else if (strcmp(name, "scale") == 0) { + oc->scale = strtol(value, NULL, 10); + assert(oc->scale >= 1); } else if (strcmp(name, "rotate") == 0) { if (strcmp(value, "90") == 0) { oc->transform = WL_OUTPUT_TRANSFORM_90; diff --git a/rootston/output.c b/rootston/output.c index baa7b6cc..faf39e74 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -27,6 +27,8 @@ static void render_surface(struct wlr_surface *surface, if (wlr_output_layout_intersects(desktop->layout, wlr_output, lx, ly, lx + width, ly + height)) { + // TODO: accomodate for mismatched scale, which can happen, for + // example, when a view is rendered over two outputs float matrix[16]; float translate_origin[16]; @@ -217,6 +219,7 @@ void output_add_notify(struct wl_listener *listener, void *data) { 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); diff --git a/types/wlr_output.c b/types/wlr_output.c index 44d24ae3..2f5e3086 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -29,8 +29,7 @@ static void wl_output_send_to_resource(struct wl_resource *resource) { if (version >= WL_OUTPUT_MODE_SINCE_VERSION) { struct wlr_output_mode *mode; wl_list_for_each(mode, &output->modes, link) { - // TODO: mode->flags should just be preferred - uint32_t flags = mode->flags; + uint32_t flags = mode->flags & ~WL_OUTPUT_MODE_PREFERRED; if (output->current_mode == mode) { flags |= WL_OUTPUT_MODE_CURRENT; } @@ -45,6 +44,7 @@ static void wl_output_send_to_resource(struct wl_resource *resource) { } } if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) { + wlr_log(L_DEBUG, "Sending scale"); wl_output_send_scale(resource, output->scale); } if (version >= WL_OUTPUT_DONE_SINCE_VERSION) { diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 2a8c4d04..28f3d05b 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -649,14 +649,14 @@ void wlr_surface_get_matrix(struct wlr_surface *surface, float (*matrix)[16], const float (*projection)[16], const float (*transform)[16]) { - int width = surface->texture->width / surface->current->scale; - int height = surface->texture->height / surface->current->scale; + int width = surface->texture->width; + int height = surface->texture->height; float scale[16]; wlr_matrix_identity(matrix); if (transform) { wlr_matrix_mul(matrix, transform, matrix); } - wlr_matrix_scale(&scale, width, height, 1); + wlr_matrix_scale(&scale, width, height, surface->current->scale); wlr_matrix_mul(matrix, &scale, matrix); wlr_matrix_mul(projection, matrix, matrix); } @@ -894,3 +894,16 @@ struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface, return NULL; } + +void wlr_surface_send_enter(struct wlr_surface *surface, + struct wlr_output *output) { + struct wl_client *client = wl_resource_get_client(surface->resource); + struct wl_resource *resource; + wl_resource_for_each(resource, &output->wl_resources) { + if (client == wl_resource_get_client(resource)) { + wlr_log(L_DEBUG, "sending output enter"); + wl_surface_send_enter(surface->resource, resource); + break; + } + } +}