From 24357cb7b5a1a8ca4407c2e6d9316f07a7a5ef0d Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Mon, 2 Aug 2021 16:49:48 -0500 Subject: wayland: cleanup handle_toplevel_config The source of many geometry woes. There's some loosely related toplevel things that should be cleaned up/fixed. First of all, VO_EVENT_LIVE_RESIZING is actually completely useless. It might have been useful sometime in the past, but there's no point. It doesn't "speed up" resizing in any way and appears to be originally for cocoa. Just remove it. Way back in the day, toplevel_width/height was added as a workaround for when we got uncoorperative (i.e. wrong) width/height coordinates from the compositor in this event. Basically it could happen due to numerous reasons but a lack of atomic commits was part of the reason and also mpv's geometry handling then was a lot rougher. We *shouldn't* need this workaround anymore. The width/height values are only used exactly when we need them. If mpv sets geometry on its own, it should still be the right dimensions. Related to the above, mpv never actually propertly handled the case where width or height was equal to 0. According to the xdg-shell spec, "If the width or height arguments are zero, it means the client should decided its own window dimension." An example of a compositor doing this is weston. It's, unsurprisingly, broken. Getting out of fullscreen or a maximized state does not restore the old window size like it should. The right way to handle this is to just return near the end of the function if we have a 0 for either argument and before any geometry is set (wl->geometry's width or height can never be zero). Luckily, state changes are already being detected so they just trigger the goto when needed. Finally, e2c24ad mistakenly removed the VO_EVENT_EXPOSE. There are edge cases where this is needed and it's safer to just force a redraw here when the window gets activated again. Just force wl->hidden to false first and then trigger the expose. --- video/out/wayland_common.c | 18 +++++++----------- video/out/wayland_common.h | 2 -- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 3b6019d941..8abe34b5dd 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -796,7 +796,6 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel, is_fullscreen = true; break; case XDG_TOPLEVEL_STATE_RESIZING: - wl->pending_vo_events |= VO_EVENT_LIVE_RESIZING; break; case XDG_TOPLEVEL_STATE_ACTIVATED: is_activated = true; @@ -839,16 +838,13 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel, wl->focused = !wl->focused; wl->pending_vo_events |= VO_EVENT_FOCUS; } + /* Just force a redraw to be on the safe side. */ + if (wl->activated) { + wl->hidden = false; + wl->pending_vo_events |= VO_EVENT_EXPOSE; + } } - if (!(wl->pending_vo_events & VO_EVENT_LIVE_RESIZING)) - vo_query_and_reset_events(wl->vo, VO_EVENT_LIVE_RESIZING); - - int old_toplevel_width = wl->toplevel_width; - int old_toplevel_height = wl->toplevel_height; - wl->toplevel_width = width; - wl->toplevel_height = height; - if (wl->scale_change) { wl_surface_set_buffer_scale(wl->surface, wl->scaling); wl->scale_change = false; @@ -862,12 +858,12 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel, } } - if (old_toplevel_width == wl->toplevel_width && old_toplevel_height == wl->toplevel_height) + if (width == 0 || height == 0) return; if (!is_fullscreen && !is_maximized) { if (vo_opts->keepaspect && vo_opts->keepaspect_window) { - if (abs(wl->toplevel_width - old_toplevel_width) > abs(wl->toplevel_height - old_toplevel_height)) { + if (width > height) { double scale_factor = (double)width / wl->reduced_width; width = wl->reduced_width * scale_factor; } else { diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h index b77bab462b..23dfd81294 100644 --- a/video/out/wayland_common.h +++ b/video/out/wayland_common.h @@ -50,8 +50,6 @@ struct vo_wayland_state { int gcd; int reduced_height; int reduced_width; - int toplevel_width; - int toplevel_height; /* State */ bool activated; -- cgit v1.2.3