1
mirror of https://github.com/mpv-player/mpv synced 2024-11-18 21:16:10 +01:00

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.
This commit is contained in:
Dudemanguy 2021-04-12 12:51:41 -05:00
parent 8edfe70b83
commit a88fdfde0c
9 changed files with 60 additions and 1 deletions

View File

@ -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.

View File

@ -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",

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;