From ea33d52a4a89d673b922e0f38d96f592ece57d98 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:03:46 -0400 Subject: [PATCH] wayland_common: always use the current geometry for prepare_resize In the xdg_toplevel_configure handler, in some cases the geometry is not equal to the width and height in the event. This can happen when runtime geometry change is requested (a new size is set), or in the case of wl->state_change || width == 0 || height == 0 (the old size is used). However, prepare_resize always uses the width and height in the event and not the corrected geometry here. This causes xdg_surface_set_window_geometry using the wrong value resulting in wrong size of window decoration. Amusingly, the debug message right above it uses the correct size. Fix this by using the updated geometry size instead. Since now all prepare_resize have parameters of 0, the width and height parameters are no longer needed. Fixes: 828dd65ef84b4d8e95e70752b9eb0833909d1d23 --- video/out/wayland_common.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index cab1245ff4..5646c84bb7 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -225,7 +225,7 @@ static void add_feedback(struct vo_wayland_feedback_pool *fback_pool, static void get_shape_device(struct vo_wayland_state *wl, struct vo_wayland_seat *s); static int greatest_common_divisor(int a, int b); static void guess_focus(struct vo_wayland_state *wl); -static void prepare_resize(struct vo_wayland_state *wl, int width, int height); +static void prepare_resize(struct vo_wayland_state *wl); static void remove_feedback(struct vo_wayland_feedback_pool *fback_pool, struct wp_presentation_feedback *fback); static void remove_output(struct vo_wayland_output *out); @@ -880,7 +880,7 @@ static void output_handle_done(void *data, struct wl_output *wl_output) if (wl->current_output && wl->current_output->output == wl_output) { set_surface_scaling(wl); set_geometry(wl, false); - prepare_resize(wl, 0, 0); + prepare_resize(wl); } wl->pending_vo_events |= VO_EVENT_WIN_STATE; @@ -951,7 +951,7 @@ static void surface_handle_enter(void *data, struct wl_surface *wl_surface, } if (!mp_rect_equals(&old_geometry, &wl->geometry) || force_resize) - prepare_resize(wl, 0, 0); + prepare_resize(wl); MP_VERBOSE(wl, "Surface entered output %s %s (0x%x), scale = %f, refresh rate = %f Hz\n", o->make, o->model, o->id, wl->scaling, o->refresh_rate); @@ -993,7 +993,7 @@ static void surface_handle_preferred_buffer_scale(void *data, if (wl->current_output) { rescale_geometry(wl, old_scale); set_geometry(wl, false); - prepare_resize(wl, 0, 0); + prepare_resize(wl); } } @@ -1168,7 +1168,7 @@ resize: mp_rect_w(old_geometry), mp_rect_h(old_geometry), mp_rect_w(wl->geometry), mp_rect_h(wl->geometry)); - prepare_resize(wl, width, height); + prepare_resize(wl); wl->toplevel_configured = true; } @@ -1218,7 +1218,7 @@ static void preferred_scale(void *data, if (wl->current_output) { rescale_geometry(wl, old_scale); set_geometry(wl, false); - prepare_resize(wl, 0, 0); + prepare_resize(wl); } } @@ -1847,12 +1847,10 @@ static int lookupkey(int key) return mpkey; } -static void prepare_resize(struct vo_wayland_state *wl, int width, int height) +static void prepare_resize(struct vo_wayland_state *wl) { - if (!width) - width = mp_rect_w(wl->geometry) / wl->scaling; - if (!height) - height = mp_rect_h(wl->geometry) / wl->scaling; + int32_t width = mp_rect_w(wl->geometry) / wl->scaling; + int32_t height = mp_rect_h(wl->geometry) / wl->scaling; xdg_surface_set_window_geometry(wl->xdg_surface, 0, 0, width, height); wl->pending_vo_events |= VO_EVENT_RESIZE; } @@ -2039,7 +2037,7 @@ static void set_geometry(struct vo_wayland_state *wl, bool resize) if (resize) { if (!wl->locked_size) wl->geometry = wl->window_size; - prepare_resize(wl, 0, 0); + prepare_resize(wl); } } @@ -2362,7 +2360,7 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) return VO_TRUE; } wl->geometry = wl->window_size; - prepare_resize(wl, 0, 0); + prepare_resize(wl); } return VO_TRUE; } @@ -2623,7 +2621,7 @@ bool vo_wayland_reconfig(struct vo *vo) if (wl->vo_opts->window_minimized) do_minimize(wl); - prepare_resize(wl, 0, 0); + prepare_resize(wl); return true; }