[PATCH xserver 2/2] xwayland: apply output scale to monitor resolution

Olivier Fourdan ofourdan at redhat.com
Thu Sep 7 15:43:17 UTC 2017


Weston scales Xwayland surfaces by the output scale, meaning that an
X11 client mapping a window on size (W x H) will actually be:

   (W x size) x (H x size)

However, Xwayland ignores the output scale factor when advertising the
monitor size and resolution meaning that an X11 client trying to size
its window based on the Xrandr reported monitor size will end up with
the wrong size for any scale different from 1.

Downscale each output size by its output scale so that the reported
monitor resolution in both Xrandr and Xvidmode can be used as a size for
X11 clients (since those will be scaled up by the compositor).

Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
---
 hw/xwayland/xwayland-output.c | 8 ++++++--
 hw/xwayland/xwayland.h        | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index a504d2595..ee9a29f4a 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -113,8 +113,8 @@ output_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags,
 
     /* Apply the change from wl_output only if xdg-output is not supported */
     if (!xwl_output->xdg_output) {
-        xwl_output->width = width;
-        xwl_output->height = height;
+        xwl_output->width = width / xwl_output->scale;
+        xwl_output->height = height / xwl_output->scale;
     }
     xwl_output->refresh = refresh;
 }
@@ -268,6 +268,9 @@ output_handle_done(void *data, struct wl_output *wl_output)
 static void
 output_handle_scale(void *data, struct wl_output *wl_output, int32_t factor)
 {
+    struct xwl_output *xwl_output = data;
+
+    xwl_output->scale = factor;
 }
 
 static const struct wl_output_listener output_listener = {
@@ -339,6 +342,7 @@ xwl_output_create(struct xwl_screen *xwl_screen, uint32_t id)
     snprintf(name, sizeof name, "XWAYLAND%d", serial++);
 
     xwl_output->xwl_screen = xwl_screen;
+    xwl_output->scale = 1;
     xwl_output->randr_crtc = RRCrtcCreate(xwl_screen->screen, xwl_output);
     if (!xwl_output->randr_crtc) {
         ErrorF("Failed creating RandR CRTC\n");
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
index 510d65e3c..f0cec07da 100644
--- a/hw/xwayland/xwayland.h
+++ b/hw/xwayland/xwayland.h
@@ -265,7 +265,7 @@ struct xwl_output {
     struct xwl_screen *xwl_screen;
     RROutputPtr randr_output;
     RRCrtcPtr randr_crtc;
-    int32_t x, y, width, height, refresh;
+    int32_t x, y, width, height, refresh, scale;
     Rotation rotation;
     Bool wl_output_done;
     Bool xdg_output_done;
-- 
2.13.5



More information about the wayland-devel mailing list