summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-05-17 16:13:04 -0500
committerDudemanguy <random342@airmail.cc>2023-05-17 16:13:04 -0500
commitf677f8a5a728f906b2176b3f1622c2c986de58fb (patch)
tree8977fb762b2fab127fa5f9abe5b1e6c82e5d8aec /video
parent1237bf0d739a163c8308af97d7e482c64945dc65 (diff)
downloadmpv-f677f8a5a728f906b2176b3f1622c2c986de58fb.tar.bz2
mpv-f677f8a5a728f906b2176b3f1622c2c986de58fb.tar.xz
wayland: improve guessing when mpv is focused
The current implementation is order dependent and assumes that getting keyboard input happens before the toplevel is activated. This isn't necessarily the case and indeed mutter activates the toplevel first. Improve this by simply spinning off the check to a function and calling it in the three places where it would be needed: the toplevel configuration event, keyboard entering, and keyboard leaving. This fixes #11694.
Diffstat (limited to 'video')
-rw-r--r--video/out/wayland_common.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index 55cf059394..49e0eb0fa4 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -185,6 +185,7 @@ static int spawn_cursor(struct vo_wayland_state *wl);
static void add_feedback(struct vo_wayland_feedback_pool *fback_pool,
struct wp_presentation_feedback *fback);
static void greatest_common_divisor(struct vo_wayland_state *wl, int a, int b);
+static void guess_focus(struct vo_wayland_state *wl);
static void remove_feedback(struct vo_wayland_feedback_pool *fback_pool,
struct wp_presentation_feedback *fback);
static void remove_output(struct vo_wayland_output *out);
@@ -415,6 +416,7 @@ static void keyboard_handle_enter(void *data, struct wl_keyboard *wl_keyboard,
{
struct vo_wayland_state *wl = data;
wl->has_keyboard_input = true;
+ guess_focus(wl);
}
static void keyboard_handle_leave(void *data, struct wl_keyboard *wl_keyboard,
@@ -422,6 +424,7 @@ static void keyboard_handle_leave(void *data, struct wl_keyboard *wl_keyboard,
{
struct vo_wayland_state *wl = data;
wl->has_keyboard_input = false;
+ guess_focus(wl);
}
static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,
@@ -923,12 +926,7 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
if (wl->activated != is_activated) {
wl->activated = is_activated;
- if ((!wl->focused && wl->activated && wl->has_keyboard_input) ||
- (wl->focused && !wl->activated))
- {
- wl->focused = !wl->focused;
- wl->pending_vo_events |= VO_EVENT_FOCUS;
- }
+ guess_focus(wl);
/* Just force a redraw to be on the safe side. */
if (wl->activated) {
wl->hidden = false;
@@ -1582,6 +1580,18 @@ static void greatest_common_divisor(struct vo_wayland_state *wl, int a, int b) {
}
}
+static void guess_focus(struct vo_wayland_state *wl) {
+ // We can't actually know if the window is focused or not in wayland,
+ // so just guess it with some common sense. Obviously won't work if
+ // the user has no keyboard.
+ if ((!wl->focused && wl->activated && wl->has_keyboard_input) ||
+ (wl->focused && !wl->activated))
+ {
+ wl->focused = !wl->focused;
+ wl->pending_vo_events |= VO_EVENT_FOCUS;
+ }
+}
+
static struct vo_wayland_output *find_output(struct vo_wayland_state *wl)
{
int index = 0;