]> git.mdlowis.com Git - proto/labwc.git/commitdiff
src/buffer: Automatically adapt to scale attribute
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Sun, 12 Jun 2022 19:11:25 +0000 (21:11 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 14 Jun 2022 21:03:08 +0000 (22:03 +0100)
Based on discussion in PR #389

include/buffer.h
src/buffer.c
src/osd.c

index af833f004a070d4da2f824e17c7651fdf77656db..59ec3f12c1677ca37105511e2f967b161fe8e4a4 100644 (file)
@@ -37,6 +37,8 @@ struct lab_data_buffer {
        uint32_t format;
        size_t stride;
        bool free_on_destroy;
+       uint32_t unscaled_width;
+       uint32_t unscaled_height;
 };
 
 /* Create a buffer which creates a new cairo CAIRO_FORMAT_ARGB32 surface */
index 44891005a74ab568952dfab8db26004cc1d588d3..1c64276a38ed1f13462aa4bbfaca54a0625b8726 100644 (file)
@@ -92,10 +92,23 @@ buffer_create_cairo(uint32_t width, uint32_t height, float scale,
        if (!buffer) {
                return NULL;
        }
-       wlr_buffer_init(&buffer->base, &data_buffer_impl, width, height);
+       buffer->unscaled_width = width;
+       buffer->unscaled_height = height;
+       width *= scale;
+       height *= scale;
 
+       /* Allocate the buffer with the scaled size */
+       wlr_buffer_init(&buffer->base, &data_buffer_impl, width, height);
        cairo_surface_t *surf =
                cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
+
+       /**
+        * Tell cairo about the device scale so we can keep drawing in unscaled
+        * coordinate space. Pango will automatically use the cairo scale attribute
+        * as well when creating text on this surface.
+        *
+        * For a more complete explanation see PR #389
+        */
        cairo_surface_set_device_scale(surf, scale, scale);
 
        buffer->cairo = cairo_create(surf);
index b057d01fb880414273ac6d741e48cfd89214fac3..153f53796bf10e52f451c92573eb2acc53d64372 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
@@ -129,13 +129,11 @@ osd_update(struct server *server)
                float scale = output->wlr_output->scale;
                int w = (OSD_ITEM_WIDTH + (2 * OSD_BORDER_WIDTH));
                int h = get_osd_height(&server->views);
-               int scaled_w = w * scale;
-               int scaled_h = h * scale;
 
                if (output->osd_buffer) {
                        wlr_buffer_drop(&output->osd_buffer->base);
                }
-               output->osd_buffer = buffer_create_cairo(scaled_w, scaled_h, scale, true);
+               output->osd_buffer = buffer_create_cairo(w, h, scale, true);
 
                cairo_t *cairo = output->osd_buffer->cairo;
                cairo_surface_t *surf = cairo_get_target(cairo);