mirror of https://github.com/mpv-player/mpv
player: don't use OSD message stack for term OSD subs
Showing subtitles on terminal used the OSD message stack (which uses a stack to "pile up" messages that were displayed at the same time). This had a bunch of weird and annoying consequences. This accessed a certain osd_state field, which is a minor annoyance since I want to make that struct opaque. Implement this differently.
This commit is contained in:
parent
7e1bc6be00
commit
c47c59f2df
|
@ -162,6 +162,7 @@ typedef struct MPContext {
|
|||
struct mp_osd_msg *osd_msg_stack;
|
||||
char *term_osd_text;
|
||||
char *term_osd_status;
|
||||
char *term_osd_subs;
|
||||
char *term_osd_contents;
|
||||
char *last_window_title;
|
||||
|
||||
|
|
29
player/osd.c
29
player/osd.c
|
@ -68,8 +68,10 @@ static char *join_lines(void *ta_ctx, char **parts, int num_parts)
|
|||
static void term_osd_update(struct MPContext *mpctx)
|
||||
{
|
||||
int num_parts = 0;
|
||||
char *parts[2] = {0};
|
||||
char *parts[3] = {0};
|
||||
|
||||
if (mpctx->term_osd_subs && mpctx->term_osd_subs[0])
|
||||
parts[num_parts++] = mpctx->term_osd_subs;
|
||||
if (mpctx->term_osd_text && mpctx->term_osd_text[0])
|
||||
parts[num_parts++] = mpctx->term_osd_text;
|
||||
if (mpctx->term_osd_status && mpctx->term_osd_status[0])
|
||||
|
@ -88,6 +90,17 @@ static void term_osd_update(struct MPContext *mpctx)
|
|||
}
|
||||
}
|
||||
|
||||
static void term_osd_set_subs(struct MPContext *mpctx, const char *text)
|
||||
{
|
||||
if (mpctx->video_out || !text)
|
||||
text = ""; // disable
|
||||
if (strcmp(mpctx->term_osd_subs ? mpctx->term_osd_subs : "", text) == 0)
|
||||
return;
|
||||
talloc_free(mpctx->term_osd_subs);
|
||||
mpctx->term_osd_subs = talloc_strdup(mpctx, text);
|
||||
term_osd_update(mpctx);
|
||||
}
|
||||
|
||||
static void term_osd_set_text(struct MPContext *mpctx, const char *text)
|
||||
{
|
||||
if (mpctx->video_out && mpctx->opts->term_osd != 1)
|
||||
|
@ -425,18 +438,8 @@ void set_osd_function(struct MPContext *mpctx, int osd_function)
|
|||
*/
|
||||
void set_osd_subtitle(struct MPContext *mpctx, const char *text)
|
||||
{
|
||||
if (!text)
|
||||
text = "";
|
||||
if (strcmp(mpctx->osd->objs[OSDTYPE_SUB]->sub_text, text) != 0) {
|
||||
osd_set_sub(mpctx->osd, mpctx->osd->objs[OSDTYPE_SUB], text);
|
||||
if (!mpctx->video_out) {
|
||||
rm_osd_msg(mpctx, OSD_MSG_SUB_BASE);
|
||||
if (text && text[0])
|
||||
set_osd_msg(mpctx, OSD_MSG_SUB_BASE, 1, INT_MAX, "%s", text);
|
||||
}
|
||||
}
|
||||
if (!text[0])
|
||||
rm_osd_msg(mpctx, OSD_MSG_SUB_BASE);
|
||||
osd_set_sub(mpctx->osd, mpctx->osd->objs[OSDTYPE_SUB], text);
|
||||
term_osd_set_subs(mpctx, text);
|
||||
}
|
||||
|
||||
// sym == mpctx->osd_function
|
||||
|
|
Loading…
Reference in New Issue