From cd6c9c1246af2779dc24b32a51ed4af61608cedd Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 2 May 2020 03:52:55 +0200 Subject: [PATCH] xwayland: Add XWAYLAND protocol extension to configure a global hidpi scaling factor for all xwayland windows. This puts the extension scaffolding in place, in order to implement the actual scaling in a next commit. [Jan Beich: merged xwayland-ext.[ch] into xwayland.c after 2700bc604] --- hw/xwayland/xwayland-screen.c | 8 ++++++++ hw/xwayland/xwayland-screen.h | 3 +++ hw/xwayland/xwayland.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/hw/xwayland/xwayland-screen.c b/hw/xwayland/xwayland-screen.c index 0e38c1cdf..e1abaefda 100644 --- a/hw/xwayland/xwayland-screen.c +++ b/hw/xwayland/xwayland-screen.c @@ -706,6 +706,13 @@ 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; + xwl_screen->global_output_scale = scale; +} + Bool xwl_screen_init(ScreenPtr pScreen, int argc, char **argv) { @@ -744,6 +751,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) { diff --git a/hw/xwayland/xwayland-screen.h b/hw/xwayland/xwayland-screen.h index 8ccfc9b4d..ff93331e7 100644 --- a/hw/xwayland/xwayland-screen.h +++ b/hw/xwayland/xwayland-screen.h @@ -86,6 +86,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; @@ -164,5 +166,6 @@ 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); +void xwl_screen_set_global_scale( struct xwl_screen *xwl_screen, int32_t scale); #endif /* XWAYLAND_SCREEN_H */ diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c index 9a1f4a6da..c25251d6d 100644 --- a/hw/xwayland/xwayland.c +++ b/hw/xwayland/xwayland.c @@ -355,6 +355,39 @@ SProcXwlQueryVersion(ClientPtr client) return ProcXwlQueryVersion(client); } +// Not defined in yet +#define X_XwlSetScale 1 +typedef struct { + CARD8 reqType; /* always XwlReqCode */ + CARD8 xwlReqType; /* always X_XwlSetScale */ + CARD16 length; + CARD16 screen; + CARD16 scale; +} xXwlSetScaleReq; +#define sz_xXwlSetScaleReq 8 + +static int +ProcXwlSetScale(ClientPtr client) +{ + REQUEST(xXwlSetScaleReq); + REQUEST_SIZE_MATCH(xXwlSetScaleReq); + + if (stuff->screen >= screenInfo.numScreens) + return BadValue; + ScreenPtr pScreen = screenInfo.screens[stuff->screen]; + + struct xwl_screen* xwl_screen = xwl_screen_get(pScreen); + if (xwl_screen == NULL) + return BadImplementation; + + if(stuff->scale < 1) + return BadValue; + + xwl_screen_set_global_scale(xwl_screen, stuff->scale); + + return Success; +} + static int ProcXWaylandDispatch(ClientPtr client) { @@ -363,6 +396,8 @@ ProcXWaylandDispatch(ClientPtr client) switch (stuff->data) { case X_XwlQueryVersion: return ProcXwlQueryVersion(client); + case X_XwlSetScale: + return ProcXwlSetScale(client); } return BadRequest; }