summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-05-25 20:37:37 +0200
committerwm4 <wm4@nowhere>2020-05-25 20:39:37 +0200
commitb1d16a2300c99fd6bf847b6b3374280f9aafa87d (patch)
tree8fcddcfbd8a03f25d462a437fd32edd5b610a4ab
parentb83bdd1d17cc90b4d8cd2a32321cd7c5cc306422 (diff)
downloadmpv-b1d16a2300c99fd6bf847b6b3374280f9aafa87d.tar.bz2
mpv-b1d16a2300c99fd6bf847b6b3374280f9aafa87d.tar.xz
player: add --term-title option
This simply printf()s a concatenation of the provided string and the relevant escape sequences. No idea what exactly defines this escape sequence (is it just a xterm thing that is now supported relatively widely?), and this simply uses information provided on the linked github issue. Not much of an advantage over --term-status-msg, though at least this can have a lower update frequency. Also I may consider setting a default value, and then it shouldn't conflict with the status message. Fixes: #1725
-rw-r--r--DOCS/man/options.rst9
-rw-r--r--common/msg.c10
-rw-r--r--common/msg_control.h1
-rw-r--r--options/options.c1
-rw-r--r--options/options.h1
-rw-r--r--player/core.h1
-rw-r--r--player/osd.c16
7 files changed, 39 insertions, 0 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
index 9410ebd2fa..95cd12a7b3 100644
--- a/DOCS/man/options.rst
+++ b/DOCS/man/options.rst
@@ -4429,6 +4429,15 @@ Terminal
Print out a custom string during playback instead of the standard status
line. Expands properties. See `Property Expansion`_.
+``--term-title=<string>``
+ Set the terminal title. Currently, this simply concatenates the escape
+ sequence setting the window title with the provided (property expanded)
+ string. This will mess up if the expanded string contain bytes that end the
+ escape sequence, or if the terminal does not understand the sequence. The
+ latter probably includes the regrettable win32.
+
+ Expands properties. See `Property Expansion`_.
+
``--msg-module``
Prepend module name to each console message.
diff --git a/common/msg.c b/common/msg.c
index 0d1c165222..7f8754b308 100644
--- a/common/msg.c
+++ b/common/msg.c
@@ -230,6 +230,16 @@ void mp_msg_flush_status_line(struct mp_log *log)
}
}
+void mp_msg_set_term_title(struct mp_log *log, const char *title)
+{
+ if (log->root && title) {
+ // Lock because printf to terminal is not necessarily atomic.
+ pthread_mutex_lock(&log->root->lock);
+ fprintf(stderr, "\e]0;%s\007", title);
+ pthread_mutex_unlock(&log->root->lock);
+ }
+}
+
bool mp_msg_has_status_line(struct mpv_global *global)
{
struct mp_log_root *root = global->log->root;
diff --git a/common/msg_control.h b/common/msg_control.h
index 8d9c9e33d2..2179881a04 100644
--- a/common/msg_control.h
+++ b/common/msg_control.h
@@ -14,6 +14,7 @@ bool mp_msg_has_log_file(struct mpv_global *global);
void mp_msg_set_early_logging(struct mpv_global *global, bool enable);
void mp_msg_flush_status_line(struct mp_log *log);
+void mp_msg_set_term_title(struct mp_log *log, const char *title);
struct mp_log_buffer_entry {
char *prefix;
diff --git a/options/options.c b/options/options.c
index 0194ebed08..22ae8e77e5 100644
--- a/options/options.c
+++ b/options/options.c
@@ -702,6 +702,7 @@ static const m_option_t mp_opts[] = {
{"term-osd-bar", OPT_FLAG(term_osd_bar), .flags = UPDATE_OSD},
{"term-osd-bar-chars", OPT_STRING(term_osd_bar_chars), .flags = UPDATE_OSD},
+ {"term-title", OPT_STRING(term_title), .flags = UPDATE_OSD},
{"term-playing-msg", OPT_STRING(playing_msg)},
{"osd-playing-msg", OPT_STRING(osd_playing_msg)},
diff --git a/options/options.h b/options/options.h
index ce94d766a7..92e0d7c129 100644
--- a/options/options.h
+++ b/options/options.h
@@ -217,6 +217,7 @@ typedef struct MPOpts {
int term_osd;
int term_osd_bar;
char *term_osd_bar_chars;
+ char *term_title;
char *playing_msg;
char *osd_playing_msg;
char *status_msg;
diff --git a/player/core.h b/player/core.h
index 55c8f514db..8bafb707f4 100644
--- a/player/core.h
+++ b/player/core.h
@@ -264,6 +264,7 @@ typedef struct MPContext {
char *term_osd_status;
char *term_osd_subs;
char *term_osd_contents;
+ char *term_osd_title;
char *last_window_title;
struct voctrl_playback_state vo_playback_state;
diff --git a/player/osd.c b/player/osd.c
index 0e8fd2a0e7..5bf7fa699b 100644
--- a/player/osd.c
+++ b/player/osd.c
@@ -96,6 +96,21 @@ static void term_osd_update(struct MPContext *mpctx)
}
}
+static void term_osd_update_title(struct MPContext *mpctx)
+{
+ if (!mpctx->opts->use_terminal)
+ return;
+
+ char *s = mp_property_expand_escaped_string(mpctx, mpctx->opts->term_title);
+ if (bstr_equals(bstr0(s), bstr0(mpctx->term_osd_title))) {
+ talloc_free(s);
+ return;
+ }
+
+ mp_msg_set_term_title(mpctx->statusline, s);
+ mpctx->term_osd_title = talloc_steal(mpctx, s);
+}
+
void term_osd_set_subs(struct MPContext *mpctx, const char *text)
{
if (mpctx->video_out || !text || !mpctx->opts->subs_rend->sub_visibility)
@@ -260,6 +275,7 @@ static void term_osd_print_status_lazy(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;
+ term_osd_update_title(mpctx);
update_window_title(mpctx, false);
update_vo_playback_state(mpctx);