Skip to content

Commit

Permalink
command: add ambient-light property
Browse files Browse the repository at this point in the history
make it observable to make it usable as a replacement for --gamma-auto.
  • Loading branch information
Akemi committed Dec 21, 2024
1 parent 8110622 commit 2b06728
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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},

Expand Down Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions player/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions player/playloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion video/out/vo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2b06728

Please sign in to comment.