summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorGuido Cella <guidocella91@gmail.com>2020-09-07 18:22:25 +0200
committerwm4 <1387750+wm4@users.noreply.github.com>2020-09-08 20:09:17 +0200
commit9b9ce74afaafb29045fe3ab975eaaa9290eb3b7d (patch)
tree3a9e096c411bb00bcc2591ef8ef03e5b5f58dbc7 /player
parent5a4fc8684eaad79ab22d44cf27c0a16a34c07123 (diff)
downloadmpv-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 'player')
-rw-r--r--player/command.c17
-rw-r--r--player/command.h1
-rw-r--r--player/playloop.c2
3 files changed, 20 insertions, 0 deletions
diff --git a/player/command.c b/player/command.c
index 5b9e8bcbb4..723996d9be 100644
--- a/player/command.c
+++ b/player/command.c
@@ -2410,6 +2410,21 @@ static int mp_property_hidpi_scale(void *ctx, struct m_property *prop,
return m_property_double_ro(action, arg, cmd->cached_window_scale);
}
+static int mp_property_focused(void *ctx, struct m_property *prop,
+ int action, void *arg)
+{
+ MPContext *mpctx = ctx;
+ struct vo *vo = mpctx->video_out;
+ if (!vo)
+ return M_PROPERTY_UNAVAILABLE;
+
+ bool focused;
+ if (vo_control(vo, VOCTRL_GET_FOCUSED, &focused) < 1)
+ return M_PROPERTY_UNAVAILABLE;
+
+ return m_property_flag_ro(action, arg, focused);
+}
+
static int mp_property_display_names(void *ctx, struct m_property *prop,
int action, void *arg)
{
@@ -3593,6 +3608,7 @@ static const struct m_property mp_properties_base[] = {
PROPERTY_BITRATE("audio-bitrate", false, STREAM_AUDIO),
PROPERTY_BITRATE("sub-bitrate", false, STREAM_SUB),
+ {"focused", mp_property_focused},
{"display-names", mp_property_display_names},
{"display-fps", mp_property_display_fps},
{"estimated-display-fps", mp_property_estimated_display_fps},
@@ -3676,6 +3692,7 @@ static const char *const *const mp_event_property_change[] = {
"osd-par", "osd-dimensions"),
E(MP_EVENT_WIN_STATE, "display-names", "display-fps"),
E(MP_EVENT_WIN_STATE2, "display-hidpi-scale"),
+ E(MP_EVENT_FOCUS, "focused"),
E(MP_EVENT_CHANGE_PLAYLIST, "playlist", "playlist-pos", "playlist-pos-1",
"playlist-count", "playlist/count", "playlist-current-pos",
"playlist-playing-pos"),
diff --git a/player/command.h b/player/command.h
index 17e0726b0b..c47ed40f1d 100644
--- a/player/command.h
+++ b/player/command.h
@@ -98,6 +98,7 @@ enum {
MP_EVENT_WIN_RESIZE,
MP_EVENT_WIN_STATE,
MP_EVENT_WIN_STATE2,
+ MP_EVENT_FOCUS,
MP_EVENT_CHANGE_PLAYLIST,
MP_EVENT_CORE_IDLE,
MP_EVENT_DURATION_UPDATE,
diff --git a/player/playloop.c b/player/playloop.c
index ddd3f6dbdb..44ccb4819b 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -844,6 +844,8 @@ static void handle_vo_events(struct MPContext *mpctx)
mp_notify(mpctx, MP_EVENT_WIN_STATE, NULL);
if (events & VO_EVENT_DPI)
mp_notify(mpctx, MP_EVENT_WIN_STATE2, NULL);
+ if (events & VO_EVENT_FOCUS)
+ mp_notify(mpctx, MP_EVENT_FOCUS, NULL);
}
static void handle_sstep(struct MPContext *mpctx)