diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 15d4321764..2ede81873f 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2849,6 +2849,9 @@ Property list ``focused`` Whether the window has focus. Might not be supported by all VOs. +``ambient-light`` + Ambient lighting condition in lux. (macOS only) + ``display-names`` Names of the displays that the mpv window covers. On X11, these are the xrandr names (LVDS1, HDMI1, DP1, VGA1, etc.). On Windows, these diff --git a/player/command.c b/player/command.c index 6ad82ae6ae..478970bdad 100644 --- a/player/command.c +++ b/player/command.c @@ -2778,6 +2778,18 @@ static void update_hidpi_window_scale(struct MPContext *mpctx, bool hidpi_scale) vo_control(vo, VOCTRL_SET_UNFS_WINDOW_SIZE, s); } +static int mp_property_ambient_light(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + struct vo *vo = mpctx->video_out; + double lux; + if (!vo || vo_control(vo, VOCTRL_GET_AMBIENT_LUX, &lux) < 1) + return M_PROPERTY_UNAVAILABLE; + + return m_property_double_ro(action, arg, lux); +} + static int mp_property_focused(void *ctx, struct m_property *prop, int action, void *arg) { @@ -4373,6 +4385,7 @@ static const struct m_property mp_properties_base[] = { {"estimated-display-fps", mp_property_estimated_display_fps}, {"vsync-jitter", mp_property_vsync_jitter}, {"display-hidpi-scale", mp_property_hidpi_scale}, + {"ambient-light", mp_property_ambient_light}, {"working-directory", mp_property_cwd}, @@ -4460,6 +4473,7 @@ static const char *const *const mp_event_property_change[] = { "display-height"), E(MP_EVENT_WIN_STATE2, "display-hidpi-scale"), E(MP_EVENT_FOCUS, "focused"), + E(MP_EVENT_AMBIENT_LIGHTING_CHANGED, "ambient-light"), 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 31e3b32a78..48b4518553 100644 --- a/player/command.h +++ b/player/command.h @@ -101,6 +101,7 @@ enum { MP_EVENT_WIN_STATE, MP_EVENT_WIN_STATE2, MP_EVENT_FOCUS, + MP_EVENT_AMBIENT_LIGHTING_CHANGED, MP_EVENT_CHANGE_PLAYLIST, MP_EVENT_CORE_IDLE, MP_EVENT_DURATION_UPDATE, diff --git a/player/playloop.c b/player/playloop.c index 8576283b79..9d2656adf0 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -859,6 +859,8 @@ static void handle_vo_events(struct MPContext *mpctx) mp_notify(mpctx, MP_EVENT_WIN_STATE2, NULL); if (events & VO_EVENT_FOCUS) mp_notify(mpctx, MP_EVENT_FOCUS, NULL); + if (events & VO_EVENT_AMBIENT_LIGHTING_CHANGED) + mp_notify(mpctx, MP_EVENT_AMBIENT_LIGHTING_CHANGED, NULL); } static void handle_sstep(struct MPContext *mpctx) diff --git a/video/out/vo.h b/video/out/vo.h index 7bf3483716..a3b2ac1556 100644 --- a/video/out/vo.h +++ b/video/out/vo.h @@ -54,7 +54,7 @@ enum { // Set of events the player core may be interested in. VO_EVENTS_USER = VO_EVENT_RESIZE | VO_EVENT_WIN_STATE | VO_EVENT_DPI | - VO_EVENT_INITIAL_UNBLOCK | VO_EVENT_FOCUS, + VO_EVENT_INITIAL_UNBLOCK | VO_EVENT_FOCUS | VO_EVENT_AMBIENT_LIGHTING_CHANGED, }; enum mp_voctrl {