Skip to content

Commit

Permalink
wayland: drop buffer scale for cursor as well
Browse files Browse the repository at this point in the history
Could have been done in e32554c, but I
skipped it there. However, using viewporter is actually a win here.
There's been a longstanding issue in upstream wayland* exactly related
to this. I even forgot about cd7a7a1
which was made for this exactly problem and explains the random
spawn_cursor calls. Anyways, just not using buffer scale and instead
scaling the cursor surface via viewporter works just fine and completely
sidesteps this problem. This means we can drop the random looking
spawn_cursor calls and some additional checks.

*: https://gitlab.freedesktop.org/wayland/wayland/-/issues/194
  • Loading branch information
Dudemanguy committed Feb 27, 2024
1 parent 34c0a67 commit f0a6578
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 9 additions & 7 deletions video/out/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,6 @@ static void output_handle_done(void *data, struct wl_output *wl_output)
* geometry and scaling should be recalculated. */
if (wl->current_output && wl->current_output->output == wl_output) {
set_surface_scaling(wl);
spawn_cursor(wl);
set_geometry(wl, false);
prepare_resize(wl, 0, 0);
}
Expand Down Expand Up @@ -934,7 +933,6 @@ static void surface_handle_enter(void *data, struct wl_surface *wl_surface,

if (wl->scaling != wl->current_output->scale) {
set_surface_scaling(wl);
spawn_cursor(wl);
force_resize = true;
}

Expand Down Expand Up @@ -1656,6 +1654,7 @@ static bool create_input(struct vo_wayland_state *wl)
static int create_viewports(struct vo_wayland_state *wl)
{
wl->viewport = wp_viewporter_get_viewport(wl->viewporter, wl->surface);
wl->cursor_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->cursor_surface);
wl->osd_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->osd_surface);
wl->video_viewport = wp_viewporter_get_viewport(wl->viewporter, wl->video_surface);

Expand Down Expand Up @@ -1968,7 +1967,8 @@ static int set_cursor_visibility(struct vo_wayland_seat *s, bool on)
int scale = MPMAX(wl->scaling, 1);
wl_pointer_set_cursor(s->pointer, s->pointer_serial, wl->cursor_surface,
img->hotspot_x / scale, img->hotspot_y / scale);
wl_surface_set_buffer_scale(wl->cursor_surface, scale);
wp_viewport_set_destination(wl->cursor_viewport, lround(img->width / scale),
img->height / scale);
wl_surface_attach(wl->cursor_surface, buffer, 0, 0);
wl_surface_damage_buffer(wl->cursor_surface, 0, 0, img->width, img->height);
}
Expand Down Expand Up @@ -2085,12 +2085,11 @@ static void set_window_bounds(struct vo_wayland_state *wl)

static int spawn_cursor(struct vo_wayland_state *wl)
{
if (wl->cursor_shape_manager)
return 0;
if (wl->allocated_cursor_scale == wl->scaling)
if (wl->allocated_cursor_scale == wl->scaling) {
return 0;
else if (wl->cursor_theme)
} else if (wl->cursor_theme) {
wl_cursor_theme_destroy(wl->cursor_theme);
}

const char *xcursor_theme = getenv("XCURSOR_THEME");
const char *size_str = getenv("XCURSOR_SIZE");
Expand Down Expand Up @@ -2669,6 +2668,9 @@ void vo_wayland_uninit(struct vo *vo)
if (wl->viewport)
wp_viewport_destroy(wl->viewport);

if (wl->cursor_viewport)
wp_viewport_destroy(wl->cursor_viewport);

if (wl->osd_viewport)
wp_viewport_destroy(wl->osd_viewport);

Expand Down
1 change: 1 addition & 0 deletions video/out/wayland_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ struct vo_wayland_state {
/* viewporter */
struct wp_viewporter *viewporter;
struct wp_viewport *viewport;
struct wp_viewport *cursor_viewport;
struct wp_viewport *osd_viewport;
struct wp_viewport *video_viewport;

Expand Down

0 comments on commit f0a6578

Please sign in to comment.