diff options
author | Guido Cella <guidocella91@gmail.com> | 2020-09-07 18:22:25 +0200 |
---|---|---|
committer | wm4 <1387750+wm4@users.noreply.github.com> | 2020-09-08 20:09:17 +0200 |
commit | 9b9ce74afaafb29045fe3ab975eaaa9290eb3b7d (patch) | |
tree | 3a9e096c411bb00bcc2591ef8ef03e5b5f58dbc7 /video/out/wayland_common.c | |
parent | 5a4fc8684eaad79ab22d44cf27c0a16a34c07123 (diff) | |
download | mpv-9b9ce74afaafb29045fe3ab975eaaa9290eb3b7d.tar.bz2 mpv-9b9ce74afaafb29045fe3ab975eaaa9290eb3b7d.tar.xz |
command: add read-only focused property
Add a property that returns whether the window is focused, currently
only for X11 and Wayland.
My use cause for this is having an equivalent of pause-when-minimize.lua
for tiling window managers: make mpv play only while it's in the current
workspace or is focused (I'm fine with either one but prefer focus).
On X I do this by observing display-names, which is empty when the
rectangles of the display and mpv don't intersect, but on Wayland its
value doesn't change when mpv leaves the current workspace (and the same
check doesn't work since the geometries still intersect).
This could later be made writable as requested in #6252.
Note that on Wayland se shouldn't consider an unactivated window with
keyboard input focused.
The wlroots compositors I tested set activated after changing the
keyboard focus, so if you set wl->focused only in
keyboard_handle_enter() and keyboard_handle_leave() to avoid adding the
"has_keyboard_input" member, focused isn't set to true when first
opening mpv until you focus another window and focus mpv again.
Conversely, if that order can't be assumed for all compositors, we
should toggle wl->focused when necessary in keyboard_handle_enter() and
keyboard_handle_leave() as well as in handle_toplevel_config().
Diffstat (limited to 'video/out/wayland_common.c')
-rw-r--r-- | video/out/wayland_common.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index a79c8aa8ca..c6c0e342c9 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -447,11 +447,15 @@ static void keyboard_handle_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys) { + struct vo_wayland_state *wl = data; + wl->has_keyboard_input = true; } static void keyboard_handle_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface) { + struct vo_wayland_state *wl = data; + wl->has_keyboard_input = false; } static bool create_input(struct vo_wayland_state *wl) @@ -951,6 +955,7 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel, bool is_maximized = false; bool is_fullscreen = false; + bool is_activated = false; enum xdg_toplevel_state *state; wl_array_for_each(state, states) { switch (*state) { @@ -961,6 +966,7 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel, wl->pending_vo_events |= VO_EVENT_LIVE_RESIZING; break; case XDG_TOPLEVEL_STATE_ACTIVATED: + is_activated = true; /* * If we get an ACTIVATED state, we know it cannot be * minimized, but it may not have been minimized @@ -992,6 +998,16 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel, m_config_cache_write_opt(wl->vo_opts_cache, &vo_opts->window_maximized); } + 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; + } + } + if (!(wl->pending_vo_events & VO_EVENT_LIVE_RESIZING)) vo_query_and_reset_events(wl->vo, VO_EVENT_LIVE_RESIZING); @@ -1544,6 +1560,10 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) } return VO_TRUE; } + case VOCTRL_GET_FOCUSED: { + *(bool *)arg = wl->focused; + return VO_TRUE; + } case VOCTRL_GET_DISPLAY_NAMES: { *(char ***)arg = get_displays_spanned(wl); return VO_TRUE; |