From 5841685e09dd1ae92de6adf20f3dc1f23fcda750 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 18 May 2014 00:03:47 +0200 Subject: command: add a disc-menu-active property Returns whether a DVD/BD menu is active. As requested by #788. --- DOCS/man/en/input.rst | 6 ++++++ player/command.c | 11 +++++++++++ player/core.h | 1 + player/discnav.c | 18 ++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/DOCS/man/en/input.rst b/DOCS/man/en/input.rst index c7ddf3dfd7..122fc679ec 100644 --- a/DOCS/man/en/input.rst +++ b/DOCS/man/en/input.rst @@ -661,6 +661,12 @@ Property list Current BD/DVD title number. Writing works only for ``dvdnav://`` and ``bd://`` (and aliases for these). +``disc-menu-active`` + Return ``yes`` if the BD/DVD menu is active, or ``no`` on normal video + playback. The property is unavailable when playing something that is not + a BD or DVD. Use the ``discnav menu`` command to actually enter or leave + menu mode. + ``chapters`` Number of chapters. diff --git a/player/command.c b/player/command.c index 512f2b478a..fd0f589053 100644 --- a/player/command.c +++ b/player/command.c @@ -512,6 +512,15 @@ static int mp_property_disc_title(m_option_t *prop, int action, void *arg, } } +static int mp_property_disc_menu(m_option_t *prop, int action, void *arg, + MPContext *mpctx) +{ + int state = mp_nav_in_menu(mpctx); + if (state < 0) + return M_PROPERTY_UNAVAILABLE; + return m_property_int_ro(prop, action, arg, !!state); +} + /// Current chapter (RW) static int mp_property_chapter(m_option_t *prop, int action, void *arg, MPContext *mpctx) @@ -2359,6 +2368,8 @@ static const m_option_t mp_properties[] = { { "time-remaining", mp_property_remaining, CONF_TYPE_TIME }, { "playtime-remaining", mp_property_playtime_remaining, CONF_TYPE_TIME }, { "disc-title", mp_property_disc_title, CONF_TYPE_INT, M_OPT_MIN, -1, 0, NULL }, + { "disc-menu-active", mp_property_disc_menu, CONF_TYPE_FLAG, + M_OPT_RANGE, 0, 1, NULL }, { "chapter", mp_property_chapter, CONF_TYPE_INT, M_OPT_MIN, -1, 0, NULL }, M_OPTION_PROPERTY_CUSTOM("edition", mp_property_edition), diff --git a/player/core.h b/player/core.h index 891c14792d..b107edc7e4 100644 --- a/player/core.h +++ b/player/core.h @@ -375,6 +375,7 @@ void mp_nav_reset(struct MPContext *mpctx); void mp_nav_destroy(struct MPContext *mpctx); void mp_nav_user_input(struct MPContext *mpctx, char *command); void mp_handle_nav(struct MPContext *mpctx); +int mp_nav_in_menu(struct MPContext *mpctx); // loadfile.c void uninit_player(struct MPContext *mpctx, unsigned int mask); diff --git a/player/discnav.c b/player/discnav.c index 990f882d87..60b83bcd3c 100644 --- a/player/discnav.c +++ b/player/discnav.c @@ -19,6 +19,7 @@ #include #include "core.h" +#include "command.h" #include "common/msg.h" #include "common/common.h" @@ -69,6 +70,18 @@ static void update_resolution(struct MPContext *mpctx) { } } +// Send update events and such. +static void update_state(struct MPContext *mpctx) +{ + mp_notify_property(mpctx, "disc-menu-active"); +} + +// Return 1 if in menu, 0 if in video, or <0 if no navigation possible. +int mp_nav_in_menu(struct MPContext *mpctx) +{ + return mpctx->nav_state ? mpctx->nav_state->nav_menu : -1; +} + // Allocate state and enable navigation features. Must happen before // initializing cache, because the cache would read data. Since stream_dvdnav is // in a mode which skips all transitions on reading data (before enabling @@ -93,6 +106,8 @@ void mp_nav_init(struct MPContext *mpctx) mp_input_enable_section(mpctx->input, "discnav", 0); mp_input_set_section_mouse_area(mpctx->input, "discnav-menu", INT_MIN, INT_MIN, INT_MAX, INT_MAX); + + update_state(mpctx); } void mp_nav_reset(struct MPContext *mpctx) @@ -111,6 +126,7 @@ void mp_nav_reset(struct MPContext *mpctx) // Prevent demuxer init code to seek to the "start" mpctx->stream->start_pos = stream_tell(mpctx->stream); stream_control(mpctx->stream, STREAM_CTRL_RESUME_CACHE, NULL); + update_state(mpctx); } void mp_nav_destroy(struct MPContext *mpctx) @@ -122,6 +138,7 @@ void mp_nav_destroy(struct MPContext *mpctx) mp_input_disable_section(mpctx->input, "discnav-menu"); talloc_free(mpctx->nav_state); mpctx->nav_state = NULL; + update_state(mpctx); } void mp_nav_user_input(struct MPContext *mpctx, char *command) @@ -193,6 +210,7 @@ void mp_handle_nav(struct MPContext *mpctx) } else { mp_input_disable_section(mpctx->input, "discnav-menu"); } + update_state(mpctx); break; case MP_NAV_EVENT_HIGHLIGHT: { MP_VERBOSE(nav, "highlight: %d %d %d - %d %d\n", -- cgit v1.2.3