From a88fdfde0c91c16c84e6057b19bdc2fb9e666e24 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Mon, 12 Apr 2021 12:51:41 -0500 Subject: command: add display-width/display-height property For some reason, this never existed before. Add VOCTRL_GET_DISPLAY_RES and use it to obtain the current display's resolution from each vo/windowing backend if applicable. Users can then access the current display resolution as display-width and display-height as per the client api. Note that macOS/cocoa was not attempted in this commit since the author has no clue how to write swift. --- player/command.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'player') diff --git a/player/command.c b/player/command.c index d1cd1c7010..7e6e5170ef 100644 --- a/player/command.c +++ b/player/command.c @@ -2412,6 +2412,23 @@ static int mp_property_vsync_jitter(void *ctx, struct m_property *prop, return m_property_double_ro(action, arg, stddev); } +static int mp_property_display_resolution(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; + int res[2]; + if (vo_control(vo, VOCTRL_GET_DISPLAY_RES, &res) <= 0) + return M_PROPERTY_UNAVAILABLE; + if (strcmp(prop->name, "display-width") == 0) { + return m_property_int_ro(action, arg, res[0]); + } else { + return m_property_int_ro(action, arg, res[1]); + } +} + static int mp_property_hidpi_scale(void *ctx, struct m_property *prop, int action, void *arg) { @@ -3528,6 +3545,8 @@ static const struct m_property mp_properties_base[] = { {"total-avsync-change", mp_property_total_avsync_change}, {"mistimed-frame-count", mp_property_mistimed_frame_count}, {"vsync-ratio", mp_property_vsync_ratio}, + {"display-width", mp_property_display_resolution}, + {"display-height", mp_property_display_resolution}, {"decoder-frame-drop-count", mp_property_frame_drop_dec}, {"frame-drop-count", mp_property_frame_drop_vo}, {"vo-delayed-frame-count", mp_property_vo_delayed_frame_count}, @@ -3743,7 +3762,8 @@ static const char *const *const mp_event_property_change[] = { "demuxer-cache-state"), E(MP_EVENT_WIN_RESIZE, "current-window-scale", "osd-width", "osd-height", "osd-par", "osd-dimensions"), - E(MP_EVENT_WIN_STATE, "display-names", "display-fps"), + E(MP_EVENT_WIN_STATE, "display-names", "display-fps" "display-width", + "display-height"), E(MP_EVENT_WIN_STATE2, "display-hidpi-scale"), E(MP_EVENT_FOCUS, "focused"), E(MP_EVENT_CHANGE_PLAYLIST, "playlist", "playlist-pos", "playlist-pos-1", -- cgit v1.2.3