summaryrefslogtreecommitdiffstats
path: root/mpvcore
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-09-20 23:33:38 +0200
committerwm4 <wm4@nowhere>2013-09-21 00:07:42 +0200
commit897d4b58a175bb4383b9df0ff59d908c63a372b4 (patch)
treedd3708c2331d0eca4a37297996c64936ed88f24f /mpvcore
parentf988c6300344492c4a8d8db11c47a4ebed4e858b (diff)
downloadmpv-897d4b58a175bb4383b9df0ff59d908c63a372b4.tar.bz2
mpv-897d4b58a175bb4383b9df0ff59d908c63a372b4.tar.xz
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.
Diffstat (limited to 'mpvcore')
-rw-r--r--mpvcore/command.c73
-rw-r--r--mpvcore/command.h2
-rw-r--r--mpvcore/m_property.c4
-rw-r--r--mpvcore/m_property.h4
4 files changed, 50 insertions, 33 deletions
diff --git a/mpvcore/command.c b/mpvcore/command.c
index 40a8e8cccc..fe1f794e8b 100644
--- a/mpvcore/command.c
+++ b/mpvcore/command.c
@@ -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);
}
-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);
}
@@ -1945,8 +1945,10 @@ static struct property_osd_display {
int osd_id;
// Needs special ways to display the new value (seeks are delayed)
int seek_msg, seek_bar;
- // Separator between option name and value (default: ": ")
- const char *sep;
+ // Free-form message (if NULL, osd_name or the property name is used)
+ const char *msg;
+ // Extra free-from message (just for volume)
+ const char *extra_msg;
} property_osd_display[] = {
// general
{ "loop", _("Loop") },
@@ -1987,8 +1989,8 @@ static struct property_osd_display {
{ "sub-scale", _("Sub Scale")},
{ "ass-vsfilter-aspect-compat", _("Subtitle VSFilter aspect compat")},
{ "ass-style-override", _("ASS subtitle style override")},
- { "vf*", _("Video filters"), .sep = ":\n"},
- { "af*", _("Audio filters"), .sep = ":\n"},
+ { "vf*", _("Video filters"), .msg = "Video filters:\n${vf}"},
+ { "af*", _("Audio filters"), .msg = "Audio filters:\n${af}"},
#ifdef CONFIG_TV
{ "tv-brightness", _("Brightness"), .osd_progbar = OSD_BRIGHTNESS },
{ "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;
const char *osd_name = NULL;
+ const char *msg = NULL;
+ const char *extra_msg = NULL;
// look for the command
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)
p = NULL;
+ if (p) {
+ msg = p->msg;
+ extra_msg = p->extra_msg;
+ }
+
if (osd_mode != MP_ON_OSD_AUTO) {
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;
+ msg = NULL;
+ extra_msg = NULL;
+ }
osd_progbar = osd_progbar ? osd_progbar : ' ';
if (!(osd_mode & MP_ON_OSD_BAR))
osd_progbar = 0;
@@ -2037,6 +2049,12 @@ static void show_property_osd(MPContext *mpctx, const char *pname,
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) {
bool ok = false;
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);
}
if (ok && osd_mode == MP_ON_OSD_AUTO && opts->osd_bar_visible)
- return;
- }
-
- if (osd_name) {
- char *val = NULL;
- int r = mp_property_do(prop.name, M_PROPERTY_PRINT, &val, mpctx);
- if (r == M_PROPERTY_UNAVAILABLE) {
- set_osd_tmsg(mpctx, OSD_MSG_TEXT, 1, opts->osd_duration,
- "%s: (unavailable)", osd_name);
- } else if (r >= 0 && val) {
- int osd_id = 0;
- 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);
+ msg = NULL;
+ }
+
+ void *tmp = talloc_new(NULL);
+ char *osd_msg = NULL;
+ if (msg)
+ osd_msg = talloc_steal(tmp, mp_property_expand_string(mpctx, msg));
+ if (extra_msg) {
+ char *t = talloc_steal(tmp, mp_property_expand_string(mpctx, extra_msg));
+ osd_msg = talloc_asprintf(tmp, "%s%s%s", osd_msg ? osd_msg : "",
+ osd_msg && osd_msg[0] ? " " : "", t);
+ }
+
+ 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)
diff --git a/mpvcore/command.h b/mpvcore/command.h
index dbe1f638e2..5ac8c3a8f0 100644
--- a/mpvcore/command.h
+++ b/mpvcore/command.h
@@ -25,7 +25,7 @@ struct mp_cmd;
void mp_get_osd_mouse_pos(struct MPContext *mpctx, float *x, float *y);
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);
int mp_property_do(const char* name, int action, void* val,
struct MPContext *mpctx);
diff --git a/mpvcore/m_property.c b/mpvcore/m_property.c
index 6e25bf4e43..4ae33c9d1e 100644
--- a/mpvcore/m_property.c
+++ b/mpvcore/m_property.c
@@ -245,8 +245,8 @@ static int expand_property(const m_option_t *prop_list, char **ret, int *ret_len
return skip;
}
-char *m_properties_expand_string(const m_option_t *prop_list, char *str0,
- void *ctx)
+char *m_properties_expand_string(const m_option_t *prop_list,
+ const char *str0, void *ctx)
{
char *ret = NULL;
int ret_len = 0;
diff --git a/mpvcore/m_property.h b/mpvcore/m_property.h
index b471b94ecd..8398ad321f 100644
--- a/mpvcore/m_property.h
+++ b/mpvcore/m_property.h
@@ -124,8 +124,8 @@ void m_properties_print_help_list(const struct m_option* list);
// STR is recursively expanded using the same rules.
// "$$" can be used to escape "$", and "$}" to escape "}".
// "$>" disables parsing of "$" for the rest of the string.
-char* m_properties_expand_string(const struct m_option* prop_list, char *str,
- void *ctx);
+char* m_properties_expand_string(const struct m_option* prop_list,
+ const char *str, void *ctx);
// Trivial helpers for implementing properties.
int m_property_int_ro(const struct m_option* prop, int action, void* arg,