mirror of https://github.com/mpv-player/mpv
command: when changing a property, allow showing an extra OSD message
This is for properties that normally show a bar, and thus do not show an OSD message (as per classic mplayer behavior). Setting an extra_msg allows showing an OSD message anyway, except if OSD messages are explicitly suppressed. This refactors the whole show_property_osd() function a bit, and replaces the weird sep field with a more general method.
This commit is contained in:
parent
f988c63003
commit
897d4b58a1
|
@ -1916,7 +1916,7 @@ int mp_property_do(const char *name, int action, void *val,
|
||||||
return m_property_do(mp_properties, name, action, val, ctx);
|
return m_property_do(mp_properties, name, action, val, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *mp_property_expand_string(struct MPContext *mpctx, char *str)
|
char *mp_property_expand_string(struct MPContext *mpctx, const char *str)
|
||||||
{
|
{
|
||||||
return m_properties_expand_string(mp_properties, str, mpctx);
|
return m_properties_expand_string(mp_properties, str, mpctx);
|
||||||
}
|
}
|
||||||
|
@ -1945,8 +1945,10 @@ static struct property_osd_display {
|
||||||
int osd_id;
|
int osd_id;
|
||||||
// Needs special ways to display the new value (seeks are delayed)
|
// Needs special ways to display the new value (seeks are delayed)
|
||||||
int seek_msg, seek_bar;
|
int seek_msg, seek_bar;
|
||||||
// Separator between option name and value (default: ": ")
|
// Free-form message (if NULL, osd_name or the property name is used)
|
||||||
const char *sep;
|
const char *msg;
|
||||||
|
// Extra free-from message (just for volume)
|
||||||
|
const char *extra_msg;
|
||||||
} property_osd_display[] = {
|
} property_osd_display[] = {
|
||||||
// general
|
// general
|
||||||
{ "loop", _("Loop") },
|
{ "loop", _("Loop") },
|
||||||
|
@ -1987,8 +1989,8 @@ static struct property_osd_display {
|
||||||
{ "sub-scale", _("Sub Scale")},
|
{ "sub-scale", _("Sub Scale")},
|
||||||
{ "ass-vsfilter-aspect-compat", _("Subtitle VSFilter aspect compat")},
|
{ "ass-vsfilter-aspect-compat", _("Subtitle VSFilter aspect compat")},
|
||||||
{ "ass-style-override", _("ASS subtitle style override")},
|
{ "ass-style-override", _("ASS subtitle style override")},
|
||||||
{ "vf*", _("Video filters"), .sep = ":\n"},
|
{ "vf*", _("Video filters"), .msg = "Video filters:\n${vf}"},
|
||||||
{ "af*", _("Audio filters"), .sep = ":\n"},
|
{ "af*", _("Audio filters"), .msg = "Audio filters:\n${af}"},
|
||||||
#ifdef CONFIG_TV
|
#ifdef CONFIG_TV
|
||||||
{ "tv-brightness", _("Brightness"), .osd_progbar = OSD_BRIGHTNESS },
|
{ "tv-brightness", _("Brightness"), .osd_progbar = OSD_BRIGHTNESS },
|
||||||
{ "tv-hue", _("Hue"), .osd_progbar = OSD_HUE},
|
{ "tv-hue", _("Hue"), .osd_progbar = OSD_HUE},
|
||||||
|
@ -2010,6 +2012,8 @@ static void show_property_osd(MPContext *mpctx, const char *pname,
|
||||||
|
|
||||||
int osd_progbar = 0;
|
int osd_progbar = 0;
|
||||||
const char *osd_name = NULL;
|
const char *osd_name = NULL;
|
||||||
|
const char *msg = NULL;
|
||||||
|
const char *extra_msg = NULL;
|
||||||
|
|
||||||
// look for the command
|
// look for the command
|
||||||
for (p = property_osd_display; p->name; p++) {
|
for (p = property_osd_display; p->name; p++) {
|
||||||
|
@ -2022,10 +2026,18 @@ static void show_property_osd(MPContext *mpctx, const char *pname,
|
||||||
if (!p->name)
|
if (!p->name)
|
||||||
p = NULL;
|
p = NULL;
|
||||||
|
|
||||||
|
if (p) {
|
||||||
|
msg = p->msg;
|
||||||
|
extra_msg = p->extra_msg;
|
||||||
|
}
|
||||||
|
|
||||||
if (osd_mode != MP_ON_OSD_AUTO) {
|
if (osd_mode != MP_ON_OSD_AUTO) {
|
||||||
osd_name = osd_name ? osd_name : prop.name;
|
osd_name = osd_name ? osd_name : prop.name;
|
||||||
if (!(osd_mode & MP_ON_OSD_MSG))
|
if (!(osd_mode & MP_ON_OSD_MSG)) {
|
||||||
osd_name = NULL;
|
osd_name = NULL;
|
||||||
|
msg = NULL;
|
||||||
|
extra_msg = NULL;
|
||||||
|
}
|
||||||
osd_progbar = osd_progbar ? osd_progbar : ' ';
|
osd_progbar = osd_progbar ? osd_progbar : ' ';
|
||||||
if (!(osd_mode & MP_ON_OSD_BAR))
|
if (!(osd_mode & MP_ON_OSD_BAR))
|
||||||
osd_progbar = 0;
|
osd_progbar = 0;
|
||||||
|
@ -2037,6 +2049,12 @@ static void show_property_osd(MPContext *mpctx, const char *pname,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char buf[40] = {0};
|
||||||
|
if (!msg && osd_name) {
|
||||||
|
snprintf(buf, sizeof(buf), "%s: ${%s}", osd_name, prop.name);
|
||||||
|
msg = buf;
|
||||||
|
}
|
||||||
|
|
||||||
if (osd_progbar && (prop.flags & CONF_RANGE) == CONF_RANGE) {
|
if (osd_progbar && (prop.flags & CONF_RANGE) == CONF_RANGE) {
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
if (prop.type == CONF_TYPE_INT) {
|
if (prop.type == CONF_TYPE_INT) {
|
||||||
|
@ -2051,30 +2069,29 @@ static void show_property_osd(MPContext *mpctx, const char *pname,
|
||||||
set_osd_bar(mpctx, osd_progbar, osd_name, prop.min, prop.max, f);
|
set_osd_bar(mpctx, osd_progbar, osd_name, prop.min, prop.max, f);
|
||||||
}
|
}
|
||||||
if (ok && osd_mode == MP_ON_OSD_AUTO && opts->osd_bar_visible)
|
if (ok && osd_mode == MP_ON_OSD_AUTO && opts->osd_bar_visible)
|
||||||
return;
|
msg = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (osd_name) {
|
void *tmp = talloc_new(NULL);
|
||||||
char *val = NULL;
|
char *osd_msg = NULL;
|
||||||
int r = mp_property_do(prop.name, M_PROPERTY_PRINT, &val, mpctx);
|
if (msg)
|
||||||
if (r == M_PROPERTY_UNAVAILABLE) {
|
osd_msg = talloc_steal(tmp, mp_property_expand_string(mpctx, msg));
|
||||||
set_osd_tmsg(mpctx, OSD_MSG_TEXT, 1, opts->osd_duration,
|
if (extra_msg) {
|
||||||
"%s: (unavailable)", osd_name);
|
char *t = talloc_steal(tmp, mp_property_expand_string(mpctx, extra_msg));
|
||||||
} else if (r >= 0 && val) {
|
osd_msg = talloc_asprintf(tmp, "%s%s%s", osd_msg ? osd_msg : "",
|
||||||
int osd_id = 0;
|
osd_msg && osd_msg[0] ? " " : "", t);
|
||||||
const char *sep = NULL;
|
|
||||||
if (p) {
|
|
||||||
int index = p - property_osd_display;
|
|
||||||
osd_id = p->osd_id ? p->osd_id : OSD_MSG_PROPERTY + index;
|
|
||||||
sep = p->sep;
|
|
||||||
}
|
|
||||||
if (!sep)
|
|
||||||
sep = ": ";
|
|
||||||
set_osd_tmsg(mpctx, osd_id, 1, opts->osd_duration,
|
|
||||||
"%s%s%s", osd_name, sep, val);
|
|
||||||
talloc_free(val);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (osd_msg && osd_msg[0]) {
|
||||||
|
int osd_id = 0;
|
||||||
|
if (p) {
|
||||||
|
int index = p - property_osd_display;
|
||||||
|
osd_id = p->osd_id ? p->osd_id : OSD_MSG_PROPERTY + index;
|
||||||
|
}
|
||||||
|
set_osd_tmsg(mpctx, osd_id, 1, opts->osd_duration, "%s", osd_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
talloc_free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *property_error_string(int error_value)
|
static const char *property_error_string(int error_value)
|
||||||
|
|
|
@ -25,7 +25,7 @@ struct mp_cmd;
|
||||||
void mp_get_osd_mouse_pos(struct MPContext *mpctx, float *x, float *y);
|
void mp_get_osd_mouse_pos(struct MPContext *mpctx, float *x, float *y);
|
||||||
|
|
||||||
void run_command(struct MPContext *mpctx, struct mp_cmd *cmd);
|
void run_command(struct MPContext *mpctx, struct mp_cmd *cmd);
|
||||||
char *mp_property_expand_string(struct MPContext *mpctx, char *str);
|
char *mp_property_expand_string(struct MPContext *mpctx, const char *str);
|
||||||
void property_print_help(void);
|
void property_print_help(void);
|
||||||
int mp_property_do(const char* name, int action, void* val,
|
int mp_property_do(const char* name, int action, void* val,
|
||||||
struct MPContext *mpctx);
|
struct MPContext *mpctx);
|
||||||
|
|
|
@ -245,8 +245,8 @@ static int expand_property(const m_option_t *prop_list, char **ret, int *ret_len
|
||||||
return skip;
|
return skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *m_properties_expand_string(const m_option_t *prop_list, char *str0,
|
char *m_properties_expand_string(const m_option_t *prop_list,
|
||||||
void *ctx)
|
const char *str0, void *ctx)
|
||||||
{
|
{
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
int ret_len = 0;
|
int ret_len = 0;
|
||||||
|
|
|
@ -124,8 +124,8 @@ void m_properties_print_help_list(const struct m_option* list);
|
||||||
// STR is recursively expanded using the same rules.
|
// STR is recursively expanded using the same rules.
|
||||||
// "$$" can be used to escape "$", and "$}" to escape "}".
|
// "$$" can be used to escape "$", and "$}" to escape "}".
|
||||||
// "$>" disables parsing of "$" for the rest of the string.
|
// "$>" disables parsing of "$" for the rest of the string.
|
||||||
char* m_properties_expand_string(const struct m_option* prop_list, char *str,
|
char* m_properties_expand_string(const struct m_option* prop_list,
|
||||||
void *ctx);
|
const char *str, void *ctx);
|
||||||
|
|
||||||
// Trivial helpers for implementing properties.
|
// Trivial helpers for implementing properties.
|
||||||
int m_property_int_ro(const struct m_option* prop, int action, void* arg,
|
int m_property_int_ro(const struct m_option* prop, int action, void* arg,
|
||||||
|
|
Loading…
Reference in New Issue