summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2021-04-12 12:51:41 -0500
committerDudemanguy <random342@airmail.cc>2021-05-06 17:36:55 +0000
commita88fdfde0c91c16c84e6057b19bdc2fb9e666e24 (patch)
tree64bb28b8c231040510adfef3630a62bac592e5ae
parent8edfe70b83acba3de91d41bf1c46921e969ea265 (diff)
downloadmpv-a88fdfde0c91c16c84e6057b19bdc2fb9e666e24.tar.bz2
mpv-a88fdfde0c91c16c84e6057b19bdc2fb9e666e24.tar.xz
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.
-rw-r--r--DOCS/man/input.rst5
-rw-r--r--player/command.c22
-rw-r--r--video/out/opengl/context_drm_egl.c5
-rw-r--r--video/out/vo.h1
-rw-r--r--video/out/vo_drm.c5
-rw-r--r--video/out/vo_rpi.c4
-rw-r--r--video/out/w32_common.c5
-rw-r--r--video/out/wayland_common.c7
-rw-r--r--video/out/x11_common.c7
9 files changed, 60 insertions, 1 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst
index 6d396e12e2..8c17468a78 100644
--- a/DOCS/man/input.rst
+++ b/DOCS/man/input.rst
@@ -2534,6 +2534,11 @@ Property list
``vsync-jitter``
Estimated deviation factor of the vsync duration.
+``display-width``, ``display-height``
+ The current display's horizontal and vertical resolution in pixels. Whether
+ or not these values update as the mpv window changes displays depends on
+ the windowing backend. It may not be available on all platforms.
+
``display-hidpi-scale``
The HiDPI scale factor as reported by the windowing backend. If no VO is
active, or if the VO does not report a value, this property is unavailable.
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",
diff --git a/video/out/opengl/context_drm_egl.c b/video/out/opengl/context_drm_egl.c
index 86ce57122c..4bae27f1a7 100644
--- a/video/out/opengl/context_drm_egl.c
+++ b/video/out/opengl/context_drm_egl.c
@@ -880,6 +880,11 @@ static int drm_egl_control(struct ra_ctx *ctx, int *events, int request,
*(double*)arg = fps;
return VO_TRUE;
}
+ case VOCTRL_GET_DISPLAY_RES: {
+ ((int *)arg)[0] = p->kms->mode.mode.hdisplay;
+ ((int *)arg)[1] = p->kms->mode.mode.vdisplay;
+ return VO_TRUE;
+ }
case VOCTRL_PAUSE:
ctx->vo->want_redraw = true;
p->paused = true;
diff --git a/video/out/vo.h b/video/out/vo.h
index 7efec53ba0..8e17b3cf42 100644
--- a/video/out/vo.h
+++ b/video/out/vo.h
@@ -120,6 +120,7 @@ enum mp_voctrl {
VOCTRL_GET_AMBIENT_LUX, // int*
VOCTRL_GET_DISPLAY_FPS, // double*
VOCTRL_GET_HIDPI_SCALE, // double*
+ VOCTRL_GET_DISPLAY_RES, // int[2]
/* private to vo_gpu */
VOCTRL_EXTERNAL_RESIZE,
diff --git a/video/out/vo_drm.c b/video/out/vo_drm.c
index a2c6fc8652..a2fada99d1 100644
--- a/video/out/vo_drm.c
+++ b/video/out/vo_drm.c
@@ -654,6 +654,11 @@ static int control(struct vo *vo, uint32_t request, void *arg)
*(double*)arg = fps;
return VO_TRUE;
}
+ case VOCTRL_GET_DISPLAY_RES: {
+ ((int *)arg)[0] = p->kms->mode.mode.hdisplay;
+ ((int *)arg)[1] = p->kms->mode.mode.vdisplay;
+ return VO_TRUE;
+ }
case VOCTRL_PAUSE:
vo->want_redraw = true;
p->paused = true;
diff --git a/video/out/vo_rpi.c b/video/out/vo_rpi.c
index 4d5de1d84d..8d921e83e3 100644
--- a/video/out/vo_rpi.c
+++ b/video/out/vo_rpi.c
@@ -748,6 +748,10 @@ static int control(struct vo *vo, uint32_t request, void *data)
case VOCTRL_GET_DISPLAY_FPS:
*(double *)data = p->display_fps;
return VO_TRUE;
+ case VOCTRL_GET_DISPLAY_RES:
+ ((int *)arg)[0] = p->w;
+ ((int *)arg)[1] = p->h;
+ return VO_TRUE;
}
return VO_NOTIMPL;
diff --git a/video/out/w32_common.c b/video/out/w32_common.c
index 59cfd6199d..c819803a63 100644
--- a/video/out/w32_common.c
+++ b/video/out/w32_common.c
@@ -1768,6 +1768,11 @@ static int gui_thread_control(struct vo_w32_state *w32, int request, void *arg)
update_display_info(w32);
*(double*) arg = w32->display_fps;
return VO_TRUE;
+ case VOCTRL_GET_DISPLAY_RES: ;
+ RECT r = get_screen_area(w32);
+ ((int *)arg)[0] = r.right;
+ ((int *)arg)[1] = r.bottom;
+ return VO_TRUE;
case VOCTRL_GET_DISPLAY_NAMES:
*(char ***)arg = get_disp_names(w32);
return VO_TRUE;
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index 94e839ef34..1902475ead 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -1754,6 +1754,13 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
*(double *)arg = wl->current_output->refresh_rate;
return VO_TRUE;
}
+ case VOCTRL_GET_DISPLAY_RES: {
+ if (!wl->current_output)
+ return VO_NOTAVAIL;
+ ((int *)arg)[0] = wl->current_output->geometry.x1;
+ ((int *)arg)[1] = wl->current_output->geometry.y1;
+ return VO_TRUE;
+ }
case VOCTRL_GET_HIDPI_SCALE: {
if (!wl->scaling)
return VO_NOTAVAIL;
diff --git a/video/out/x11_common.c b/video/out/x11_common.c
index ac551fae8e..12d2648d4e 100644
--- a/video/out/x11_common.c
+++ b/video/out/x11_common.c
@@ -1982,6 +1982,13 @@ int vo_x11_control(struct vo *vo, int *events, int request, void *arg)
*(double *)arg = fps;
return VO_TRUE;
}
+ case VOCTRL_GET_DISPLAY_RES: {
+ if (!x11->window || x11->parent)
+ return VO_NOTAVAIL;
+ ((int *)arg)[0] = x11->screenrc.x1;
+ ((int *)arg)[1] = x11->screenrc.y1;
+ return VO_TRUE;
+ }
case VOCTRL_GET_HIDPI_SCALE:
*(double *)arg = x11->dpi_scale;
return VO_TRUE;