]> git.mdlowis.com Git - proto/labwc.git/commitdiff
OSD: Scale OSD to the largest output scale
authorARDiDo <90479315+ARDiDo@users.noreply.github.com>
Sun, 6 Feb 2022 00:23:30 +0000 (19:23 -0500)
committerJohan Malm <johanmalm@users.noreply.github.com>
Wed, 9 Feb 2022 21:57:32 +0000 (21:57 +0000)
include/labwc.h
src/osd.c
src/output.c

index 5efa6392f64392895dd4112235158c536fbec5db..d8303e42c4e27832dc7fe6848b33fb5de82cd66f 100644 (file)
@@ -154,6 +154,7 @@ struct server {
        struct wlr_output_manager_v1 *output_manager;
        struct wl_listener output_manager_apply;
        struct wlr_output_configuration_v1 *pending_output_config;
+       float greatest_scale;
 
        struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager;
 
index 07ff5ada6cb3124813e5ce30badee454b3d7590c..f95ec1dc1bebbcf62b870adddfa2407118a9e355 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
@@ -79,11 +79,13 @@ osd_update(struct server *server)
        struct wlr_renderer *renderer = server->renderer;
        struct theme *theme = server->theme;
 
-       int w = OSD_ITEM_WIDTH + 2 * OSD_BORDER_WIDTH;
-       int h = get_osd_height(&server->views);
+       float scale = server->greatest_scale;
+       int w = (OSD_ITEM_WIDTH + (2 * OSD_BORDER_WIDTH)) * scale;
+       int h = get_osd_height(&server->views) * scale;
 
        cairo_surface_t *surf =
                cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
+       cairo_surface_set_device_scale(surf, scale, scale);
        cairo_t *cairo = cairo_create(surf);
 
        /* background */
index 437cb5c287f2f7a2331b58849f981cc486ae9087..a9356cf8d2c8f9392a8beda2894b0a47a2588384 100644 (file)
@@ -532,15 +532,27 @@ render_osd(struct output *output, pixman_region32_t *damage,
 
                struct wlr_box box = {
                        .x = ol_output->x + o->wlr_output->width
-                               / o->wlr_output->scale / 2,
+                               / 2,
                        .y = ol_output->y + o->wlr_output->height
-                               / o->wlr_output->scale / 2,
-                       .width = server->osd->width,
-                       .height = server->osd->height,
+                               / 2,
+                       .width = server->osd->width * o->wlr_output->scale
+                               / server->greatest_scale,
+                       .height = server->osd->height * o->wlr_output->scale
+                               / server->greatest_scale,
                };
-               box.x -= server->osd->width / 2;
-               box.y -= server->osd->height / 2;
-               render_texture_helper(output, damage, &box, server->osd);
+               box.x -= box.width  / 2;
+               box.y -= box.height / 2;
+
+               double ox = 0, oy = 0;
+               wlr_output_layout_output_coords(output->server->output_layout,
+                       output->wlr_output, &ox, &oy);
+               box.x += ox;
+               box.y += oy;
+               float matrix[9];
+               wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL,
+                       0, output->wlr_output->transform_matrix);
+               render_texture(o->wlr_output, damage, server->osd, NULL, &box,
+                       matrix);
        }
 }
 
@@ -1059,6 +1071,8 @@ output_init(struct server *server)
 
        wl_list_init(&server->outputs);
 
+       server->greatest_scale = 1;
+
        output_manager_init(server);
 }
 
@@ -1153,7 +1167,11 @@ handle_output_manager_apply(struct wl_listener *listener, void *data)
        }
        wlr_output_configuration_v1_destroy(config);
        struct output *output;
+       server->greatest_scale = 0;
        wl_list_for_each(output, &server->outputs, link) {
+               if (output->wlr_output->scale > server->greatest_scale) {
+                       server->greatest_scale = output->wlr_output->scale;
+               }
                wlr_xcursor_manager_load(server->seat.xcursor_manager,
                        output->wlr_output->scale);
        }