1From 59550f4615bbf0a4e8bca23df163abfe37c52636 Mon Sep 17 00:00:00 2001
2From: Michael Forney <mforney@mforney.org>
3Date: Wed, 14 Aug 2024 22:52:17 -0700
4Subject: [PATCH] Revert "wayland: drop buffer scale for cursor as well"
5
6This reverts commit f0a6578259f508a8863afcf9a1487872d7ae1878.
7---
8 video/out/wayland_common.c | 32 +++++++++++++++++++++++---------
9 video/out/wayland_common.h | 1 -
10 2 files changed, 23 insertions(+), 10 deletions(-)
11
12diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
13index edcc922122..4ccd4bda9c 100644
14--- a/video/out/wayland_common.c
15+++ b/video/out/wayland_common.c
16@@ -893,6 +893,7 @@ static void output_handle_done(void *data, struct wl_output *wl_output)
17 * geometry and scaling should be recalculated. */
18 if (wl->current_output && wl->current_output->output == wl_output) {
19 set_surface_scaling(wl);
20+ spawn_cursor(wl);
21 set_geometry(wl, false);
22 prepare_resize(wl);
23 }
24@@ -957,6 +958,23 @@ static void surface_handle_enter(void *data, struct wl_surface *wl_surface,
25 if (outputs == 1)
26 update_output_geometry(wl, old_geometry, old_output_geometry);
27
28+ wl->current_output->has_surface = true;
29+ bool force_resize = false;
30+
31+ if (wl->scaling != wl->current_output->scale) {
32+ set_surface_scaling(wl);
33+ spawn_cursor(wl);
34+ force_resize = true;
35+ }
36+
37+ if (!mp_rect_equals(&old_output_geometry, &wl->current_output->geometry)) {
38+ set_geometry(wl, false);
39+ force_resize = true;
40+ }
41+
42+ if (!mp_rect_equals(&old_geometry, &wl->geometry) || force_resize)
43+ prepare_resize(wl);
44+
45 MP_VERBOSE(wl, "Surface entered output %s %s (0x%x), scale = %f, refresh rate = %f Hz\n",
46 wl->current_output->make, wl->current_output->model,
47 wl->current_output->id, wl->scaling, wl->current_output->refresh_rate);
48@@ -1696,7 +1714,6 @@ static bool create_input(struct vo_wayland_state *wl)
49 static int create_viewports(struct vo_wayland_state *wl)
50 {
51 wl->viewport = wp_viewporter_get_viewport(wl->viewporter, wl->surface);
52- wl->cursor_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->cursor_surface);
53 wl->osd_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->osd_surface);
54 wl->video_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->video_surface);
55
56@@ -2009,8 +2026,7 @@ static int set_cursor_visibility(struct vo_wayland_seat *s, bool on)
57 int scale = MPMAX(wl->scaling, 1);
58 wl_pointer_set_cursor(s->pointer, s->pointer_enter_serial, wl->cursor_surface,
59 img->hotspot_x / scale, img->hotspot_y / scale);
60- wp_viewport_set_destination(wl->cursor_viewport, lround(img->width / scale),
61- img->height / scale);
62+ wl_surface_set_buffer_scale(wl->cursor_surface, scale);
63 wl_surface_attach(wl->cursor_surface, buffer, 0, 0);
64 wl_surface_damage_buffer(wl->cursor_surface, 0, 0, img->width, img->height);
65 }
66@@ -2145,11 +2161,12 @@ static bool single_output_spanned(struct vo_wayland_state *wl)
67
68 static int spawn_cursor(struct vo_wayland_state *wl)
69 {
70- if (wl->allocated_cursor_scale == wl->scaling) {
71+ if (wl->cursor_shape_manager)
72+ return 0;
73+ if (wl->allocated_cursor_scale == wl->scaling)
74 return 0;
75- } else if (wl->cursor_theme) {
76+ else if (wl->cursor_theme)
77 wl_cursor_theme_destroy(wl->cursor_theme);
78- }
79
80 const char *xcursor_theme = getenv("XCURSOR_THEME");
81 const char *size_str = getenv("XCURSOR_SIZE");
82@@ -2801,9 +2818,6 @@ void vo_wayland_uninit(struct vo *vo)
83 if (wl->viewport)
84 wp_viewport_destroy(wl->viewport);
85
86- if (wl->cursor_viewport)
87- wp_viewport_destroy(wl->cursor_viewport);
88-
89 if (wl->osd_viewport)
90 wp_viewport_destroy(wl->osd_viewport);
91
92diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h
93index 7a2f31918e..f5fcb80445 100644
94--- a/video/out/wayland_common.h
95+++ b/video/out/wayland_common.h
96@@ -139,7 +139,6 @@ struct vo_wayland_state {
97 /* viewporter */
98 struct wp_viewporter *viewporter;
99 struct wp_viewport *viewport;
100- struct wp_viewport *cursor_viewport;
101 struct wp_viewport *osd_viewport;
102 struct wp_viewport *video_viewport;
103
104--
1052.44.0
106