diff options
author | Simon Ser <contact@emersion.fr> | 2023-02-08 15:00:08 +0100 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-04-30 21:20:18 +0000 |
commit | 6234a709202282d8a8bfffd0ee4f9d80561dd4b9 (patch) | |
tree | ea9aff17f59808ae205938fa0abff63d8ebd84a5 /video | |
parent | 6d422b3edc00a36dde5e1b073a07938d98720f3a (diff) | |
download | mpv-6234a709202282d8a8bfffd0ee4f9d80561dd4b9.tar.bz2 mpv-6234a709202282d8a8bfffd0ee4f9d80561dd4b9.tar.xz |
wayland: add support for wl_surface.preferred_buffer_scale
See [1] for the motivation. Very similar to the fractional scale,
except it's in core and integer-only.
[1]: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/220
Diffstat (limited to 'video')
-rw-r--r-- | video/out/wayland_common.c | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index e6ec7d90ad..55cf059394 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -55,6 +55,10 @@ #define HAVE_WAYLAND_1_20 #endif +#if WAYLAND_VERSION_MAJOR > 1 || WAYLAND_VERSION_MINOR >= 22 +#define HAVE_WAYLAND_1_22 +#endif + #ifndef CLOCK_MONOTONIC_RAW #define CLOCK_MONOTONIC_RAW 4 #endif @@ -756,7 +760,9 @@ static void surface_handle_enter(void *data, struct wl_surface *wl_surface, wl->current_output->has_surface = true; bool force_resize = false; - if (!wl->fractional_scale_manager && wl->scaling != wl->current_output->scale) { + if (!wl->fractional_scale_manager && wl_surface_get_version(wl_surface) < 6 && + wl->scaling != wl->current_output->scale) + { set_surface_scaling(wl); spawn_cursor(wl); force_resize = true; @@ -792,9 +798,45 @@ static void surface_handle_leave(void *data, struct wl_surface *wl_surface, } } +#ifdef HAVE_WAYLAND_1_22 + +static void surface_handle_preferred_buffer_scale(void *data, + struct wl_surface *wl_surface, + int32_t scale) +{ + struct vo_wayland_state *wl = data; + double old_scale = wl->scaling; + + if (wl->fractional_scale_manager) + return; + + // dmabuf_wayland is always wl->scaling = 1 + wl->scaling = !wl->using_dmabuf_wayland ? scale : 1; + MP_VERBOSE(wl, "Obtained preferred scale, %f, from the compositor.\n", + wl->scaling); + wl->pending_vo_events |= VO_EVENT_DPI; + if (wl->current_output) { + rescale_geometry(wl, old_scale); + set_geometry(wl, false); + wl->pending_vo_events |= VO_EVENT_RESIZE; + } +} + +static void surface_handle_preferred_buffer_transform(void *data, + struct wl_surface *wl_surface, + uint32_t transform) +{ +} + +#endif + static const struct wl_surface_listener surface_listener = { surface_handle_enter, surface_handle_leave, +#ifdef HAVE_WAYLAND_1_22 + surface_handle_preferred_buffer_scale, + surface_handle_preferred_buffer_transform, +#endif }; static void xdg_wm_base_ping(void *data, struct xdg_wm_base *wm_base, uint32_t serial) @@ -1207,7 +1249,12 @@ static void registry_handle_add(void *data, struct wl_registry *reg, uint32_t id struct vo_wayland_state *wl = data; if (!strcmp(interface, wl_compositor_interface.name) && (ver >= 4) && found++) { - wl->compositor = wl_registry_bind(reg, id, &wl_compositor_interface, 4); +#ifdef HAVE_WAYLAND_1_22 + ver = MPMIN(ver, 6); /* Cap at 6 in case new events are added later. */ +#else + ver = 4; +#endif + wl->compositor = wl_registry_bind(reg, id, &wl_compositor_interface, ver); wl->surface = wl_compositor_create_surface(wl->compositor); wl->video_surface = wl_compositor_create_surface(wl->compositor); /* never accept input events on the video surface */ |