mirror of
https://github.com/mpv-player/mpv
synced 2025-01-18 13:14:36 +00:00
command: simplify OSD property display code
Probably not many user-visible changes. One notable change is that the terminal OSD code for OSD bar fallback handling is removed with no replacement. Instead, terminal OSD gets the same text message as normal OSD. For volume, this is ok, because the text message is reasonable. Other properties will look worse, but could be adjusted, and there are in fact no other such properties that would be useful in audio-only mode. The fallback message for seeking falls away as well, but that message was useless anyway - the terminal status line provides all information anyway. I believe the show_property_osd() code is now much easier to follow.
This commit is contained in:
parent
4a0bbe256e
commit
903bd1d893
@ -3069,81 +3069,74 @@ static const struct property_osd_display {
|
||||
{0}
|
||||
};
|
||||
|
||||
static void show_property_osd(MPContext *mpctx, const char *pname, int osd_mode)
|
||||
static void show_property_osd(MPContext *mpctx, const char *name, int osd_mode)
|
||||
{
|
||||
struct MPOpts *opts = mpctx->opts;
|
||||
const struct property_osd_display *p;
|
||||
const char *name = pname;
|
||||
struct property_osd_display disp = { .name = name };
|
||||
|
||||
int osd_progbar = 0;
|
||||
const char *osd_name = NULL;
|
||||
const char *msg = NULL;
|
||||
if (!osd_mode)
|
||||
return;
|
||||
|
||||
// look for the command
|
||||
for (p = property_osd_display; p->name; p++) {
|
||||
for (const struct property_osd_display *p = property_osd_display; p->name; p++)
|
||||
{
|
||||
if (!strcmp(p->name, name)) {
|
||||
osd_progbar = p->seek_bar ? 1 : p->osd_progbar;
|
||||
osd_name = p->seek_msg ? "" : p->osd_name;
|
||||
disp = *p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!p->name)
|
||||
p = NULL;
|
||||
|
||||
if (p)
|
||||
msg = p->msg;
|
||||
|
||||
if (osd_mode != MP_ON_OSD_AUTO) {
|
||||
osd_name = osd_name ? osd_name : name;
|
||||
if (!(osd_mode & MP_ON_OSD_MSG)) {
|
||||
osd_name = NULL;
|
||||
msg = NULL;
|
||||
}
|
||||
osd_progbar = osd_progbar ? osd_progbar : ' ';
|
||||
if (!(osd_mode & MP_ON_OSD_BAR))
|
||||
osd_progbar = 0;
|
||||
if (osd_mode == MP_ON_OSD_AUTO) {
|
||||
osd_mode =
|
||||
((disp.msg || disp.osd_name || disp.seek_msg) ? MP_ON_OSD_MSG : 0) |
|
||||
((disp.osd_progbar || disp.seek_bar) ? MP_ON_OSD_BAR : 0);
|
||||
}
|
||||
|
||||
if (p && (p->seek_msg || p->seek_bar)) {
|
||||
if (!disp.osd_progbar)
|
||||
disp.osd_progbar = ' ';
|
||||
|
||||
if (!disp.osd_name)
|
||||
disp.osd_name = name;
|
||||
|
||||
if (disp.seek_msg || disp.seek_bar) {
|
||||
mpctx->add_osd_seek_info |=
|
||||
(osd_name ? p->seek_msg : 0) | (osd_progbar ? p->seek_bar : 0);
|
||||
(osd_mode & MP_ON_OSD_MSG ? disp.seek_msg : 0) |
|
||||
(osd_mode & MP_ON_OSD_BAR ? disp.seek_bar : 0);
|
||||
return;
|
||||
}
|
||||
|
||||
void *tmp = talloc_new(NULL);
|
||||
|
||||
if (!msg && osd_name)
|
||||
msg = talloc_asprintf(tmp, "%s: ${%s}", osd_name, name);
|
||||
|
||||
struct m_option prop = {0};
|
||||
mp_property_do(pname, M_PROPERTY_GET_TYPE, &prop, mpctx);
|
||||
if (osd_progbar && (prop.flags & CONF_RANGE) == CONF_RANGE) {
|
||||
bool ok = false;
|
||||
mp_property_do(name, M_PROPERTY_GET_TYPE, &prop, mpctx);
|
||||
if ((osd_mode & MP_ON_OSD_BAR) && (prop.flags & CONF_RANGE) == CONF_RANGE) {
|
||||
if (prop.type == CONF_TYPE_INT) {
|
||||
int n = prop.min;
|
||||
mp_property_do(name, M_PROPERTY_GET_NEUTRAL, &n, mpctx);
|
||||
int i;
|
||||
ok = mp_property_do(name, M_PROPERTY_GET, &i, mpctx) > 0;
|
||||
if (ok)
|
||||
set_osd_bar(mpctx, osd_progbar, osd_name, prop.min, prop.max, n, i);
|
||||
if (mp_property_do(name, M_PROPERTY_GET, &i, mpctx) > 0)
|
||||
set_osd_bar(mpctx, disp.osd_progbar, prop.min, prop.max, n, i);
|
||||
} else if (prop.type == CONF_TYPE_FLOAT) {
|
||||
float n = prop.min;
|
||||
mp_property_do(name, M_PROPERTY_GET_NEUTRAL, &n, mpctx);
|
||||
float f;
|
||||
ok = mp_property_do(name, M_PROPERTY_GET, &f, mpctx) > 0;
|
||||
if (ok)
|
||||
set_osd_bar(mpctx, osd_progbar, osd_name, prop.min, prop.max, n, f);
|
||||
if (mp_property_do(name, M_PROPERTY_GET, &f, mpctx) > 0)
|
||||
set_osd_bar(mpctx, disp.osd_progbar, prop.min, prop.max, n, f);
|
||||
}
|
||||
}
|
||||
|
||||
char *osd_msg = NULL;
|
||||
if (msg)
|
||||
osd_msg = talloc_steal(tmp, mp_property_expand_string(mpctx, msg));
|
||||
if (osd_mode & MP_ON_OSD_MSG) {
|
||||
void *tmp = talloc_new(NULL);
|
||||
|
||||
if (osd_msg && osd_msg[0])
|
||||
set_osd_msg(mpctx, 1, opts->osd_duration, "%s", osd_msg);
|
||||
const char *msg = disp.msg;
|
||||
if (!msg)
|
||||
msg = talloc_asprintf(tmp, "%s: ${%s}", disp.osd_name, name);
|
||||
|
||||
talloc_free(tmp);
|
||||
char *osd_msg = talloc_steal(tmp, mp_property_expand_string(mpctx, msg));
|
||||
|
||||
if (osd_msg && osd_msg[0])
|
||||
set_osd_msg(mpctx, 1, opts->osd_duration, "%s", osd_msg);
|
||||
|
||||
talloc_free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static const char *property_error_string(int error_value)
|
||||
|
@ -428,7 +428,7 @@ void update_window_title(struct MPContext *mpctx, bool force);
|
||||
void stream_dump(struct MPContext *mpctx);
|
||||
|
||||
// osd.c
|
||||
void set_osd_bar(struct MPContext *mpctx, int type, const char* name,
|
||||
void set_osd_bar(struct MPContext *mpctx, int type,
|
||||
double min, double max, double neutral, double val);
|
||||
void set_osd_msg(struct MPContext *mpctx, int level, int time,
|
||||
const char* fmt, ...) PRINTF_ATTRIBUTE(4,5);
|
||||
|
11
player/osd.c
11
player/osd.c
@ -364,15 +364,14 @@ static mp_osd_msg_t *get_osd_msg(struct MPContext *mpctx)
|
||||
}
|
||||
|
||||
// type: mp_osd_font_codepoints, ASCII, or OSD_BAR_*
|
||||
// name: fallback for terminal OSD
|
||||
void set_osd_bar(struct MPContext *mpctx, int type, const char* name,
|
||||
void set_osd_bar(struct MPContext *mpctx, int type,
|
||||
double min, double max, double neutral, double val)
|
||||
{
|
||||
struct MPOpts *opts = mpctx->opts;
|
||||
if (opts->osd_level < 1 || !opts->osd_bar_visible)
|
||||
return;
|
||||
|
||||
if (mpctx->video_out && opts->term_osd != 1) {
|
||||
if (mpctx->video_out) {
|
||||
mpctx->osd_visible = mp_time_sec() + opts->osd_duration / 1000.0;
|
||||
mpctx->sleeptime = 0;
|
||||
mpctx->osd_progbar.type = type;
|
||||
@ -384,11 +383,7 @@ void set_osd_bar(struct MPContext *mpctx, int type, const char* name,
|
||||
mpctx->osd_progbar.num_stops, pos);
|
||||
}
|
||||
osd_set_progbar(mpctx->osd, &mpctx->osd_progbar);
|
||||
return;
|
||||
}
|
||||
|
||||
set_osd_msg(mpctx, 1, opts->osd_duration, "%s: %d %%",
|
||||
name, ROUND(100 * (val - min) / (max - min)));
|
||||
}
|
||||
|
||||
// Update a currently displayed bar of the same type, without resetting the
|
||||
@ -496,7 +491,7 @@ static void add_seek_osd_messages(struct MPContext *mpctx)
|
||||
{
|
||||
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_BAR) {
|
||||
double pos = get_current_pos_ratio(mpctx, false);
|
||||
set_osd_bar(mpctx, OSD_BAR_SEEK, "Position", 0, 1, 0, MPCLAMP(pos, 0, 1));
|
||||
set_osd_bar(mpctx, OSD_BAR_SEEK, 0, 1, 0, MPCLAMP(pos, 0, 1));
|
||||
set_osd_bar_chapters(mpctx, OSD_BAR_SEEK);
|
||||
}
|
||||
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_TEXT) {
|
||||
|
Loading…
Reference in New Issue
Block a user