From 290ae87c02abf5070422bb50af948402345ab4e1 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Thu, 2 Nov 2023 11:05:55 +0100 Subject: [PATCH] xwayland: Update the scale based on enter/leave events Recompute the window scale each time the window enters or leaves an output. Signed-off-by: Olivier Fourdan Reviewed-By: Kenny Levinsen Acked-by: Peter Hutterer Part-of: --- hw/xwayland/xwayland-window.c | 30 ++++++++++++++++++++++++++++-- hw/xwayland/xwayland-window.h | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/hw/xwayland/xwayland-window.c b/hw/xwayland/xwayland-window.c index b439c3a47..626a5d22d 100644 --- a/hw/xwayland/xwayland-window.c +++ b/hw/xwayland/xwayland-window.c @@ -794,6 +794,12 @@ static const struct xdg_surface_listener xdg_surface_listener = { xdg_surface_handle_configure, }; +static void +xwl_window_update_surface_scale(struct xwl_window *xwl_window) +{ + xwl_window->surface_scale = xwl_window_get_max_output_scale(xwl_window); +} + static void xwl_window_enter_output(struct xwl_window *xwl_window, struct xwl_output *xwl_output) { @@ -828,6 +834,22 @@ xwl_window_free_outputs(struct xwl_window *xwl_window) } } +int +xwl_window_get_max_output_scale(struct xwl_window *xwl_window) +{ + struct xwl_window_output *window_output; + struct xwl_output *xwl_output; + int scale = 1; + + xorg_list_for_each_entry(window_output, &xwl_window->xwl_output_list, link) { + xwl_output = window_output->xwl_output; + if (xwl_output->scale > scale) + scale = xwl_output->scale; + } + + return scale; +} + static void xwl_window_surface_enter(void *data, struct wl_surface *wl_surface, @@ -837,8 +859,10 @@ xwl_window_surface_enter(void *data, struct xwl_screen *xwl_screen = xwl_window->xwl_screen; struct xwl_output *xwl_output = xwl_output_from_wl_output(xwl_screen, wl_output); - if (xwl_output) + if (xwl_output) { xwl_window_enter_output(xwl_window, xwl_output); + xwl_window_update_surface_scale(xwl_window); + } if (xwl_window->wl_output != wl_output) { xwl_window->wl_output = wl_output; @@ -857,8 +881,10 @@ xwl_window_surface_leave(void *data, struct xwl_screen *xwl_screen = xwl_window->xwl_screen; struct xwl_output *xwl_output = xwl_output_from_wl_output(xwl_screen, wl_output); - if (xwl_output) + if (xwl_output) { xwl_window_leave_output(xwl_window, xwl_output); + xwl_window_update_surface_scale(xwl_window); + } if (xwl_window->wl_output == wl_output) xwl_window->wl_output = NULL; diff --git a/hw/xwayland/xwayland-window.h b/hw/xwayland/xwayland-window.h index 0e45f08d2..03b4ad249 100644 --- a/hw/xwayland/xwayland-window.h +++ b/hw/xwayland/xwayland-window.h @@ -59,6 +59,7 @@ struct xwl_window { struct wl_surface *surface; struct wp_viewport *viewport; float viewport_scale_x, viewport_scale_y; + int surface_scale; struct xdg_surface *xdg_surface; struct xdg_toplevel *xdg_toplevel; WindowPtr window; @@ -100,6 +101,7 @@ void xwl_window_set_window_pixmap(WindowPtr window, PixmapPtr pixmap); void xwl_window_leave_output(struct xwl_window *xwl_window, struct xwl_output *xwl_output); +int xwl_window_get_max_output_scale(struct xwl_window *xwl_window); Bool xwl_realize_window(WindowPtr window); Bool xwl_unrealize_window(WindowPtr window); Bool xwl_change_window_attributes(WindowPtr window, unsigned long mask);