summarylogtreecommitdiffstats
path: root/hidpi.patch
blob: bd425faba079a9d0e29d6b07c83578a223e529db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
diff --git a/hw/xwayland/xwayland-cursor.c b/hw/xwayland/xwayland-cursor.c
index e3c1aaa50..1c1cef853 100644
--- a/hw/xwayland/xwayland-cursor.c
+++ b/hw/xwayland/xwayland-cursor.c
@@ -164,6 +164,8 @@ xwl_cursor_attach_pixmap(struct xwl_seat *xwl_seat,
     }
 
     wl_surface_attach(xwl_cursor->surface, buffer, 0, 0);
+    wl_surface_set_buffer_scale(xwl_cursor->surface,
+                                xwl_seat->xwl_screen->global_output_scale);
     xwl_surface_damage(xwl_seat->xwl_screen, xwl_cursor->surface, 0, 0,
                        xwl_seat->x_cursor->bits->width,
                        xwl_seat->x_cursor->bits->height);
@@ -195,6 +197,7 @@ xwl_cursor_clear_frame_cb(struct xwl_cursor *xwl_cursor)
 void
 xwl_seat_set_cursor(struct xwl_seat *xwl_seat)
 {
+    struct xwl_screen *xwl_screen = xwl_seat->xwl_screen;
     struct xwl_cursor *xwl_cursor = &xwl_seat->cursor;
     PixmapPtr pixmap;
     CursorPtr cursor;
@@ -225,8 +228,8 @@ xwl_seat_set_cursor(struct xwl_seat *xwl_seat)
     wl_pointer_set_cursor(xwl_seat->wl_pointer,
                           xwl_seat->pointer_enter_serial,
                           xwl_cursor->surface,
-                          xwl_seat->x_cursor->bits->xhot,
-                          xwl_seat->x_cursor->bits->yhot);
+                          xwl_scale_to(xwl_screen, xwl_seat->x_cursor->bits->xhot),
+                          xwl_scale_to(xwl_screen, xwl_seat->x_cursor->bits->yhot));
 
     xwl_cursor_attach_pixmap(xwl_seat, xwl_cursor, pixmap);
 }
@@ -235,6 +238,7 @@ void
 xwl_tablet_tool_set_cursor(struct xwl_tablet_tool *xwl_tablet_tool)
 {
     struct xwl_seat *xwl_seat = xwl_tablet_tool->seat;
+    struct xwl_screen *xwl_screen = xwl_seat->xwl_screen;
     struct xwl_cursor *xwl_cursor = &xwl_tablet_tool->cursor;
     PixmapPtr pixmap;
     CursorPtr cursor;
@@ -263,9 +267,9 @@ xwl_tablet_tool_set_cursor(struct xwl_tablet_tool *xwl_tablet_tool)
     zwp_tablet_tool_v2_set_cursor(xwl_tablet_tool->tool,
                                   xwl_tablet_tool->proximity_in_serial,
                                   xwl_cursor->surface,
-                                  xwl_seat->x_cursor->bits->xhot,
-                                  xwl_seat->x_cursor->bits->yhot);
-
+                                  xwl_scale_to(xwl_screen, xwl_seat->x_cursor->bits->xhot),
+                                  xwl_scale_to(xwl_screen, xwl_seat->x_cursor->bits->yhot));
+    wl_surface_set_buffer_scale(xwl_cursor->surface, xwl_screen->global_output_scale);
     xwl_cursor_attach_pixmap(xwl_seat, xwl_cursor, pixmap);
 }
 
diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index 67c7c151d..eb7b64110 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -511,8 +511,8 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
     DeviceIntPtr dev = get_pointer_device(xwl_seat);
     DeviceIntPtr master;
     int i;
-    int sx = wl_fixed_to_int(sx_w);
-    int sy = wl_fixed_to_int(sy_w);
+    int sx = wl_fixed_to_int(sx_w) * xwl_seat->xwl_screen->global_output_scale;
+    int sy = wl_fixed_to_int(sy_w) * xwl_seat->xwl_screen->global_output_scale;
     int dx, dy;
     ScreenPtr pScreen = xwl_seat->xwl_screen->screen;
     ValuatorMask mask;
@@ -735,13 +735,14 @@ pointer_handle_motion(void *data, struct wl_pointer *pointer,
                       uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
 {
     struct xwl_seat *xwl_seat = data;
+    int32_t scale = xwl_seat->xwl_screen->global_output_scale;
 
     if (!xwl_seat->focus_window)
         return;
 
     xwl_seat->pending_pointer_event.has_absolute = TRUE;
-    xwl_seat->pending_pointer_event.x = sx_w;
-    xwl_seat->pending_pointer_event.y = sy_w;
+    xwl_seat->pending_pointer_event.x = sx_w * scale;
+    xwl_seat->pending_pointer_event.y = sy_w * scale;
 
     if (wl_proxy_get_version((struct wl_proxy *) xwl_seat->wl_pointer) < 5)
         dispatch_pointer_motion_event(xwl_seat);
@@ -891,12 +892,13 @@ relative_pointer_handle_relative_motion(void *data,
                                         wl_fixed_t dy_unaccelf)
 {
     struct xwl_seat *xwl_seat = data;
+    int32_t scale = xwl_seat->xwl_screen->global_output_scale;
 
     xwl_seat->pending_pointer_event.has_relative = TRUE;
-    xwl_seat->pending_pointer_event.dx = wl_fixed_to_double(dxf);
-    xwl_seat->pending_pointer_event.dy = wl_fixed_to_double(dyf);
-    xwl_seat->pending_pointer_event.dx_unaccel = wl_fixed_to_double(dx_unaccelf);
-    xwl_seat->pending_pointer_event.dy_unaccel = wl_fixed_to_double(dy_unaccelf);
+    xwl_seat->pending_pointer_event.dx = wl_fixed_to_double(dxf) * scale;
+    xwl_seat->pending_pointer_event.dy = wl_fixed_to_double(dyf) * scale;
+    xwl_seat->pending_pointer_event.dx_unaccel = wl_fixed_to_double(dx_unaccelf) * scale;
+    xwl_seat->pending_pointer_event.dy_unaccel = wl_fixed_to_double(dy_unaccelf) * scale;
 
     if (!xwl_seat->focus_window)
         return;
@@ -1386,8 +1388,8 @@ touch_handle_down(void *data, struct wl_touch *wl_touch,
 
     xwl_touch->window = wl_surface_get_user_data(surface);
     xwl_touch->id = id;
-    xwl_touch->x = wl_fixed_to_int(sx_w);
-    xwl_touch->y = wl_fixed_to_int(sy_w);
+    xwl_touch->x = wl_fixed_to_int(sx_w) * xwl_seat->xwl_screen->global_output_scale;
+    xwl_touch->y = wl_fixed_to_int(sy_w) * xwl_seat->xwl_screen->global_output_scale;
     xorg_list_add(&xwl_touch->link_touch, &xwl_seat->touches);
 
     xwl_touch_send_event(xwl_touch, xwl_seat, XI_TouchBegin);
@@ -1423,8 +1425,8 @@ touch_handle_motion(void *data, struct wl_touch *wl_touch,
     if (!xwl_touch)
         return;
 
-    xwl_touch->x = wl_fixed_to_int(sx_w);
-    xwl_touch->y = wl_fixed_to_int(sy_w);
+    xwl_touch->x = wl_fixed_to_int(sx_w) * xwl_seat->xwl_screen->global_output_scale;;
+    xwl_touch->y = wl_fixed_to_int(sy_w) * xwl_seat->xwl_screen->global_output_scale;;
     xwl_touch_send_event(xwl_touch, xwl_seat, XI_TouchUpdate);
 }
 
@@ -2114,8 +2116,8 @@ tablet_tool_motion(void *data, struct zwp_tablet_tool_v2 *tool,
     struct xwl_tablet_tool *xwl_tablet_tool = data;
     struct xwl_seat *xwl_seat = xwl_tablet_tool->seat;
     int32_t dx, dy;
-    double sx = wl_fixed_to_double(x);
-    double sy = wl_fixed_to_double(y);
+    double sx = wl_fixed_to_double(x) * xwl_seat->xwl_screen->global_output_scale;
+    double sy = wl_fixed_to_double(y) * xwl_seat->xwl_screen->global_output_scale;
 
     if (!xwl_seat->tablet_focus_window)
         return;
@@ -3156,6 +3158,7 @@ xwl_pointer_warp_emulator_set_fake_pos(struct xwl_pointer_warp_emulator *warp_em
                                        int x,
                                        int y)
 {
+    struct xwl_screen *xwl_screen;
     struct zwp_locked_pointer_v1 *locked_pointer =
         warp_emulator->locked_pointer;
     WindowPtr window;
@@ -3167,6 +3170,7 @@ xwl_pointer_warp_emulator_set_fake_pos(struct xwl_pointer_warp_emulator *warp_em
     if (!warp_emulator->xwl_seat->focus_window)
         return;
 
+    xwl_screen = warp_emulator->xwl_seat->xwl_screen;
     window = warp_emulator->xwl_seat->focus_window->window;
     if (x >= window->drawable.x ||
         y >= window->drawable.y ||
@@ -3175,8 +3179,8 @@ xwl_pointer_warp_emulator_set_fake_pos(struct xwl_pointer_warp_emulator *warp_em
         sx = x - window->drawable.x;
         sy = y - window->drawable.y;
         zwp_locked_pointer_v1_set_cursor_position_hint(locked_pointer,
-                                                       wl_fixed_from_int(sx),
-                                                       wl_fixed_from_int(sy));
+                                                       wl_fixed_from_int(xwl_scale_to(xwl_screen, sx)),
+                                                       wl_fixed_from_int(xwl_scale_to(xwl_screen, sy)));
         wl_surface_commit(warp_emulator->xwl_seat->focus_window->surface);
     }
 }
diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index cf99c6e84..5745a7f6a 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -189,6 +189,9 @@ update_screen_size(struct xwl_screen *xwl_screen, int width, int height)
     xwl_screen->width = width;
     xwl_screen->height = height;
 
+    width *= xwl_screen->global_output_scale;
+    height *= xwl_screen->global_output_scale;
+
     if (xwl_screen->root_clip_mode == ROOT_CLIP_FULL)
         SetRootClip(xwl_screen->screen, ROOT_CLIP_NONE);
 
@@ -597,8 +600,8 @@ xwl_output_set_emulated_mode(struct xwl_output *xwl_output, ClientPtr client,
                                              new_emulated_height);
 }
 
-static void
-apply_output_change(struct xwl_output *xwl_output)
+void
+xwl_output_apply_changes(struct xwl_output *xwl_output)
 {
     struct xwl_screen *xwl_screen = xwl_output->xwl_screen;
     struct xwl_window *xwl_window;
@@ -606,6 +609,7 @@ apply_output_change(struct xwl_output *xwl_output)
     int mode_width, mode_height, count;
     int width = 0, height = 0, has_this_output = 0;
     RRModePtr *randr_modes;
+    int32_t scale = xwl_screen->global_output_scale;
 
     /* Clear out the "done" received flags */
     xwl_output->wl_output_done = FALSE;
@@ -624,10 +628,10 @@ apply_output_change(struct xwl_output *xwl_output)
     }
     if (xwl_output->randr_output) {
         /* Build a fresh modes array using the current refresh rate */
-        randr_modes = output_get_rr_modes(xwl_output, mode_width, mode_height, &count);
+        randr_modes = output_get_rr_modes(xwl_output, mode_width * scale, mode_height * scale, &count);
         RROutputSetModes(xwl_output->randr_output, randr_modes, count, 1);
         RRCrtcNotify(xwl_output->randr_crtc, randr_modes[0],
-                     xwl_output->x, xwl_output->y,
+                     xwl_output->x * scale, xwl_output->y * scale,
                      xwl_output->rotation, NULL, 1, &xwl_output->randr_output);
         /* RROutputSetModes takes ownership of the passed in modes, so we only
          * have to free the pointer array.
@@ -697,7 +701,7 @@ output_handle_done(void *data, struct wl_output *wl_output)
      */
     if (xwl_output->xdg_output_done || !xwl_output->xdg_output ||
         zxdg_output_v1_get_version(xwl_output->xdg_output) >= 3)
-        apply_output_change(xwl_output);
+        xwl_output_apply_changes(xwl_output);
 }
 
 static void
@@ -757,7 +761,7 @@ xdg_output_handle_done(void *data, struct zxdg_output_v1 *xdg_output)
     xwl_output->xdg_output_done = TRUE;
     if (xwl_output->wl_output_done &&
         zxdg_output_v1_get_version(xdg_output) < 3)
-        apply_output_change(xwl_output);
+        xwl_output_apply_changes(xwl_output);
 }
 
 static void
@@ -926,6 +930,8 @@ xwl_output_remove(struct xwl_output *xwl_output)
     if (xwl_output->randr_output) {
         RROutputDestroy(xwl_output->randr_output);
         RRTellChanged(xwl_screen->screen);
+
+        xwl_output->scale = 1;
     }
     xwl_output_destroy(xwl_output);
 }
diff --git a/hw/xwayland/xwayland-output.h b/hw/xwayland/xwayland-output.h
index bcdf25bec..9cfc33f26 100644
--- a/hw/xwayland/xwayland-output.h
+++ b/hw/xwayland/xwayland-output.h
@@ -53,7 +53,7 @@ struct xwl_output {
     struct wl_output *output;
     struct zxdg_output_v1 *xdg_output;
     uint32_t server_output_id;
-    int32_t x, y, width, height, refresh;
+    int32_t x, y, width, height, scale, refresh;
     Rotation rotation;
     Bool wl_output_done;
     Bool xdg_output_done;
@@ -106,6 +106,8 @@ void xwl_output_set_emulated_mode(struct xwl_output *xwl_output,
 void xwl_output_set_window_randr_emu_props(struct xwl_screen *xwl_screen,
                                            WindowPtr window);
 
+void xwl_output_apply_changes(struct xwl_output *xwl_output);
+
 void xwl_screen_init_xdg_output(struct xwl_screen *xwl_screen);
 
 #endif /* XWAYLAND_OUTPUT_H */
diff --git a/hw/xwayland/xwayland-present.c b/hw/xwayland/xwayland-present.c
index 941be06da..392979c86 100644
--- a/hw/xwayland/xwayland-present.c
+++ b/hw/xwayland/xwayland-present.c
@@ -782,6 +782,8 @@ xwl_present_flip(present_vblank_ptr vblank, RegionPtr damage)
 
     /* We can flip directly to the main surface (full screen window without clips) */
     wl_surface_attach(xwl_window->surface, buffer, 0, 0);
+     wl_surface_set_buffer_scale(xwl_window->surface,
+                                 xwl_window->xwl_screen->global_output_scale);
 
     if (xorg_list_is_empty(&xwl_present_window->frame_callback_list)) {
         xorg_list_add(&xwl_present_window->frame_callback_list,
diff --git a/hw/xwayland/xwayland-screen.c b/hw/xwayland/xwayland-screen.c
index cc14e0771..e3f1e1b6e 100644
--- a/hw/xwayland/xwayland-screen.c
+++ b/hw/xwayland/xwayland-screen.c
@@ -42,6 +42,8 @@
 #include <propertyst.h>
 #include <inputstr.h>
 #include <xserver_poll.h>
+#include <xace.h>
+#include <xacestr.h>
 
 #include "xwayland-cursor.h"
 #include "xwayland-screen.h"
@@ -51,6 +53,7 @@
 #include "xwayland-pixmap.h"
 #include "xwayland-present.h"
 #include "xwayland-shm.h"
+#include "xwayland-window-buffers.h"
 #ifdef XWL_HAS_EI
 #include "xwayland-xtest.h"
 #endif
@@ -115,6 +118,12 @@ xwl_screen_has_resolution_change_emulation(struct xwl_screen *xwl_screen)
     return xwl_screen->rootless && xwl_screen_has_viewport_support(xwl_screen);
 }
 
+int
+xwl_scale_to(struct xwl_screen *xwl_screen, int value)
+{
+    return value / (double)xwl_screen->global_output_scale + 0.5;
+}
+
 /* Return the output @ 0x0, falling back to the first output in the list */
 struct xwl_output *
 xwl_screen_get_first_output(struct xwl_screen *xwl_screen)
@@ -141,6 +150,56 @@ xwl_screen_get_fixed_or_first_output(struct xwl_screen *xwl_screen)
     return xwl_screen_get_first_output(xwl_screen);
 }
 
+static void
+xwl_screen_set_global_scale_from_property(struct xwl_screen *screen,
+                                          PropertyPtr prop)
+{
+    CARD32 *propdata;
+
+    if (prop->type != XA_CARDINAL || prop->format != 32 || prop->size != 1) {
+        // TODO: handle warnings more cleanly.
+        LogMessageVerb(X_WARNING, 0, "Bad value for property %s.\n",
+                       NameForAtom(prop->propertyName));
+        return;
+    }
+
+    propdata = prop->data;
+    xwl_screen_set_global_scale(screen, propdata[0]);
+}
+
+static void
+xwl_screen_update_property(struct xwl_screen *screen,
+                           PropertyStateRec *propstate)
+{
+    switch (propstate->state) {
+    case PropertyNewValue:
+        xwl_screen_set_global_scale_from_property(screen, propstate->prop);
+        break;
+    case PropertyDelete:
+        // This seems to be causing a double free for some reason, remove it for now
+        // xwl_screen_set_global_scale(screen, 1);
+        break;
+    }
+}
+
+static void
+xwl_screen_validate_property_access(CallbackListPtr *pcbl,
+                                    void *userdata,
+                                    void *calldata)
+{
+    XacePropertyAccessRec *rec = calldata;
+    struct xwl_screen *xwl_screen = userdata;
+    ATOM name = (*rec->ppProp)->propertyName;
+
+    if (name == xwl_screen->global_output_scale_prop &&
+        rec->client->index != xwl_screen->wm_client_id) {
+        LogMessageVerb(X_WARNING, 0,
+                       "Client %x tried to illegaly set %s on the root window.\n",
+                       rec->client->index, NameForAtom(name));
+        rec->status = BadAccess;
+    }
+}
+
 static void
 xwl_property_callback(CallbackListPtr *pcbl, void *closure,
                       void *calldata)
@@ -148,19 +207,24 @@ xwl_property_callback(CallbackListPtr *pcbl, void *closure,
     ScreenPtr screen = closure;
     PropertyStateRec *rec = calldata;
     struct xwl_screen *xwl_screen;
-    struct xwl_window *xwl_window;
 
     if (rec->win->drawable.pScreen != screen)
         return;
 
-    xwl_window = xwl_window_get(rec->win);
-    if (!xwl_window)
-        return;
-
     xwl_screen = xwl_screen_get(screen);
 
-    if (rec->prop->propertyName == xwl_screen->allow_commits_prop)
+    if (rec->prop->propertyName == xwl_screen->allow_commits_prop) {
+        struct xwl_window *xwl_window;
+
+        xwl_window = xwl_window_get(rec->win);
+        if (!xwl_window)
+            return;
+
         xwl_window_update_property(xwl_window, rec);
+    }
+    else if (rec->prop->propertyName == xwl_screen->global_output_scale_prop) {
+        xwl_screen_update_property(xwl_screen, rec);
+    }
 }
 
 static void
@@ -646,8 +710,14 @@ void xwl_surface_damage(struct xwl_screen *xwl_screen,
 {
     if (wl_surface_get_version(surface) >= WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION)
         wl_surface_damage_buffer(surface, x, y, width, height);
-    else
+    else {
+        x = xwl_scale_to(xwl_screen, x);
+        y = xwl_scale_to(xwl_screen, y);
+        width = xwl_scale_to(xwl_screen, width);
+        height = xwl_scale_to(xwl_screen, height);
+
         wl_surface_damage(surface, x, y, width, height);
+    }
 }
 
 void
@@ -716,10 +786,34 @@ xwl_screen_get_next_output_serial(struct xwl_screen *xwl_screen)
     return xwl_screen->output_name_serial++;
 }
 
+void
+xwl_screen_set_global_scale(struct xwl_screen *xwl_screen, int32_t scale)
+{
+    struct xwl_output *it;
+    struct xwl_window *xwl_window;
+
+    xwl_screen->global_output_scale = scale;
+
+    /* change randr resolutions and positions */
+    xorg_list_for_each_entry(it, &xwl_screen->output_list, link) {
+        xwl_output_apply_changes(it);
+    }
+
+    if (!xwl_screen->rootless && xwl_screen->screen->root) {
+        /* Clear all the buffers, so that they'll be remade with the new sizes
+         * (this doesn't occur automatically because as far as Xorg is
+         *  concerned, the window's size is the same) */
+        xorg_list_for_each_entry(xwl_window, &xwl_screen->window_list, link_window) {
+            xwl_window_buffers_recycle(xwl_window);
+        }
+    }
+}
+
 Bool
 xwl_screen_init(ScreenPtr pScreen, int argc, char **argv)
 {
     static const char allow_commits[] = "_XWAYLAND_ALLOW_COMMITS";
+    static const char global_output_scale[] = "_XWAYLAND_GLOBAL_OUTPUT_SCALE";
     struct xwl_screen *xwl_screen;
     Pixel red_mask, blue_mask, green_mask;
     int ret, bpc, green_bpc, i;
@@ -759,6 +853,7 @@ xwl_screen_init(ScreenPtr pScreen, int argc, char **argv)
 #ifdef XWL_HAS_GLAMOR
     xwl_screen->glamor = 1;
 #endif
+    xwl_screen->global_output_scale = 1;
 
     for (i = 1; i < argc; i++) {
         if (strcmp(argv[i], "-rootless") == 0) {
@@ -1010,9 +1105,17 @@ xwl_screen_init(ScreenPtr pScreen, int argc, char **argv)
     if (xwl_screen->allow_commits_prop == BAD_RESOURCE)
         return FALSE;
 
+    xwl_screen->global_output_scale_prop = MakeAtom(global_output_scale,
+                                                    strlen(global_output_scale),
+                                                    TRUE);
+    if (xwl_screen->global_output_scale_prop == BAD_RESOURCE)
+        return FALSE;
+
     AddCallback(&PropertyStateCallback, xwl_property_callback, pScreen);
     AddCallback(&RootWindowFinalizeCallback, xwl_root_window_finalized_callback, pScreen);
 
+    // XaceRegisterCallback(XACE_PROPERTY_ACCESS, xwl_screen_validate_property_access, xwl_screen);
+
     xwl_screen_setup_custom_vector(xwl_screen);
 
     xwl_screen_roundtrip(xwl_screen);
diff --git a/hw/xwayland/xwayland-screen.h b/hw/xwayland/xwayland-screen.h
index bd66dd681..8fc87dade 100644
--- a/hw/xwayland/xwayland-screen.h
+++ b/hw/xwayland/xwayland-screen.h
@@ -90,6 +90,8 @@ struct xwl_screen {
     struct xorg_list damage_window_list;
     struct xorg_list window_list;
 
+    int32_t global_output_scale;
+
     int wayland_fd;
     struct wl_display *display;
     struct wl_registry *registry;
@@ -138,6 +140,7 @@ struct xwl_screen {
     struct glamor_context *glamor_ctx;
 
     Atom allow_commits_prop;
+    Atom global_output_scale_prop;
 
     /* The preferred GLVND vendor. If NULL, "mesa" is assumed. */
     const char *glvnd_vendor;
@@ -171,5 +174,7 @@ void xwl_surface_damage(struct xwl_screen *xwl_screen,
                         struct wl_surface *surface,
                         int32_t x, int32_t y, int32_t width, int32_t height);
 int xwl_screen_get_next_output_serial(struct xwl_screen * xwl_screen);
+int xwl_scale_to(struct xwl_screen *xwl_screen, int value);
+void xwl_screen_set_global_scale(struct xwl_screen *xwl_screen, int32_t scale);
 
 #endif /* XWAYLAND_SCREEN_H */
diff --git a/hw/xwayland/xwayland-window.c b/hw/xwayland/xwayland-window.c
index 4978f37c7..f8fe2902f 100644
--- a/hw/xwayland/xwayland-window.c
+++ b/hw/xwayland/xwayland-window.c
@@ -871,7 +871,8 @@ xwl_create_root_surface(struct xwl_window *xwl_window)
     }
 
     wl_region_add(region, 0, 0,
-                  window->drawable.width, window->drawable.height);
+                  xwl_scale_to(xwl_screen, window->drawable.width),
+                  xwl_scale_to(xwl_screen, window->drawable.height));
     wl_surface_set_opaque_region(xwl_window->surface, region);
     wl_region_destroy(region);
 
@@ -1411,6 +1412,7 @@ xwl_window_attach_buffer(struct xwl_window *xwl_window)
 #endif
 
     wl_surface_attach(xwl_window->surface, buffer, 0, 0);
+    wl_surface_set_buffer_scale(xwl_window->surface, xwl_screen->global_output_scale);
 
     /* Arbitrary limit to try to avoid flooding the Wayland
      * connection. If we flood it too much anyway, this could