1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-11 08:37:59 +00:00

wayland: don't set mouse pos on state change

Sway 1.5 started sending more pointer motion events to mpv which broke
the autohiding behavior. The cursor would appear again if you
fullscreened. Sway had a good reason to do this because certain
applications had inconsistencies between hardware cursor and software
cursor without rebasing on state changes[1]. So mpv needs to take this
special case into consideration.

Initially, simply checking mouse coordinates for changes was considered,
but this doesn't work. All coordinates are surface-local in wayland so
something can appear to move in the local coordinate space but not
globally. You're not allowed to know global mouse coordinates in
wayland, and we don't care about local coordinate changes in mpv so this
approach isn't viable.

Instead, let's just keep track of a local state change. If the toplevel
surface changes in some way (fullscreen, maximized, etc.), then just set
a bool that lets us ignore the mp_input_set_mouse_pos function. This
keeps the cursor from appearing simply because the state was changed
(i.e. fullscreening). For compositors that don't send pointer motion
events on a state change, this does technically mean that the initial
mp_input_set_mouse_pos is never set. In practice, this isn't a
noticeable difference though because moving a mouse generates a ton of
motion events so you'll immediately see it on the second motion event.

[1] https://github.com/swaywm/sway/issues/5594
This commit is contained in:
Dudemanguy 2020-08-02 16:45:06 -05:00
parent 359261c50c
commit fb55ee99e3
2 changed files with 6 additions and 1 deletions

View File

@ -155,7 +155,10 @@ static void pointer_handle_motion(void *data, struct wl_pointer *pointer,
wl->mouse_unscaled_x = sx;
wl->mouse_unscaled_y = sy;
mp_input_set_mouse_pos(wl->vo->input_ctx, wl->mouse_x, wl->mouse_y);
if (!wl->state_changed) {
mp_input_set_mouse_pos(wl->vo->input_ctx, wl->mouse_x, wl->mouse_y);
}
wl->state_changed = false;
}
static void window_move(struct vo_wayland_state *wl, uint32_t serial)
@ -1030,6 +1033,7 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
mp_rect_w(wl->geometry)*wl->scaling, mp_rect_h(wl->geometry)*wl->scaling);
wl->pending_vo_events |= VO_EVENT_RESIZE;
wl->state_changed = true;
}
static void handle_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel)

View File

@ -75,6 +75,7 @@ struct vo_wayland_state {
int reduced_height;
bool configured;
bool frame_wait;
bool state_changed;
int wakeup_pipe[2];
int pending_vo_events;
int mouse_x;