From 4f869c6eda2e3566ecf2ec850301518beb739fe2 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Fri, 11 Aug 2023 17:18:08 +0200 Subject: [PATCH] xwayland: Make xwl_window_libdecor_resize reusable The upcoming handling of plain xdg_toplevel.configure events will need to use the xwl_window resize helper. Move it outside XWL_HAS_LIBDECOR, move the remaining dimension logic from handle_libdecor_configure into it and update the name accordingly. Signed-off-by: Kenny Levinsen --- hw/xwayland/xwayland-window.c | 48 ++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/hw/xwayland/xwayland-window.c b/hw/xwayland/xwayland-window.c index 3ecb99da2..c50b5c179 100644 --- a/hw/xwayland/xwayland-window.c +++ b/hw/xwayland/xwayland-window.c @@ -608,6 +608,30 @@ xwl_window_rootful_set_app_id(struct xwl_window *xwl_window) xdg_toplevel_set_app_id(xwl_window->xdg_toplevel, app_id); } +static void +xwl_window_maybe_resize(struct xwl_window *xwl_window, int width, int height) +{ + struct xwl_screen *xwl_screen = xwl_window->xwl_screen; + struct xwl_output *xwl_output; + RRModePtr mode; + + /* Clamp the size */ + width = min(max(width, MIN_ROOTFUL_WIDTH), MAX_ROOTFUL_WIDTH); + height = min(max(height, MIN_ROOTFUL_HEIGHT), MAX_ROOTFUL_HEIGHT); + + if (width == xwl_screen->width && height == xwl_screen->height) + return; + + xwl_output = xwl_screen_get_fixed_or_first_output(xwl_screen); + if (!xwl_randr_add_modes_fixed(xwl_output, width, height)) + return; + + mode = xwl_output_find_mode(xwl_output, width, height); + xwl_output_set_mode_fixed(xwl_output, mode); + + xwl_window_attach_buffer(xwl_window); +} + #ifdef XWL_HAS_LIBDECOR static void xwl_window_libdecor_set_size_limits(struct xwl_window *xwl_window) @@ -632,23 +656,6 @@ xwl_window_update_libdecor_size(struct xwl_window *xwl_window, } } -static void -xwl_window_libdecor_resize(struct xwl_window *xwl_window, int width, int height) -{ - struct xwl_screen *xwl_screen = xwl_window->xwl_screen; - struct xwl_output *xwl_output; - RRModePtr mode; - - xwl_output = xwl_screen_get_fixed_or_first_output(xwl_screen); - if (!xwl_randr_add_modes_fixed(xwl_output, width, height)) - return; - - mode = xwl_output_find_mode(xwl_output, width, height); - xwl_output_set_mode_fixed(xwl_output, mode); - - xwl_window_attach_buffer(xwl_window); -} - static void handle_libdecor_configure(struct libdecor_frame *frame, struct libdecor_configuration *configuration, @@ -662,13 +669,8 @@ handle_libdecor_configure(struct libdecor_frame *frame, width = xwl_screen->width; height = xwl_screen->height; } - /* Clamp the size */ - width = min(max(width, MIN_ROOTFUL_WIDTH), MAX_ROOTFUL_WIDTH); - height = min(max(height, MIN_ROOTFUL_HEIGHT), MAX_ROOTFUL_HEIGHT) ; - - if (xwl_screen->width != width || xwl_screen->height != height) - xwl_window_libdecor_resize(xwl_window, width, height); + xwl_window_maybe_resize(xwl_window, width, height); xwl_window_update_libdecor_size(xwl_window, configuration, xwl_screen->width, xwl_screen->height); wl_surface_commit(xwl_window->surface);