summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2020-11-26 11:54:43 +0100
committeravih <avih@users.noreply.github.com>2020-11-26 23:55:59 +0200
commit9867f218307241961f9e7220085a9e3c23cab0af (patch)
tree9ffed73aff187743ed7c691df8ddd60b37d17f3a
parentfa7afc3e19acffd3198fdc8fddb671013a337b05 (diff)
downloadmpv-9867f218307241961f9e7220085a9e3c23cab0af.tar.bz2
mpv-9867f218307241961f9e7220085a9e3c23cab0af.tar.xz
terminal: process input when foregrounded
When mpv is in the background because it was started with `mpv foo.mp3 &`, or the user did ctrl+z bg, and is then brought to the foreground with fg, it buffers input until you press enter. This makes it accept input almost immediately. Having a short interval isn't important, since input is buffered until the next loop iteration. Closes #8120.
-rw-r--r--osdep/terminal-unix.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c
index 78eb4c4618..86c3030cdd 100644
--- a/osdep/terminal-unix.c
+++ b/osdep/terminal-unix.c
@@ -45,6 +45,14 @@
// Timeout in ms after which the (normally ambiguous) ESC key is detected.
#define ESC_TIMEOUT 100
+// Timeout in ms after which the poll for input is aborted. The FG/BG state is
+// tested before every wait, and a positive value allows reactivating input
+// processing when mpv is brought to the foreground while it was running in the
+// background. In such a situation, an infinite timeout (-1) will keep mpv
+// waiting for input without realizing the terminal state changed - and thus
+// buffer all keypresses until ENTER is pressed.
+#define INPUT_TIMEOUT 1000
+
static volatile struct termios tio_orig;
static volatile int tio_orig_set;
@@ -397,7 +405,7 @@ static void *terminal_thread(void *ptr)
{ .events = POLLIN, .fd = death_pipe[0] },
{ .events = POLLIN, .fd = tty_in }
};
- int r = polldev(fds, stdin_ok ? 2 : 1, buf.len ? ESC_TIMEOUT : -1);
+ int r = polldev(fds, stdin_ok ? 2 : 1, buf.len ? ESC_TIMEOUT : INPUT_TIMEOUT);
if (fds[0].revents)
break;
if (fds[1].revents) {