summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mplayer.c5
-rw-r--r--osdep/getch2-win.c3
-rw-r--r--osdep/getch2.c11
-rw-r--r--osdep/getch2.h4
4 files changed, 17 insertions, 6 deletions
diff --git a/mplayer.c b/mplayer.c
index edeffef9e4..26555e3c20 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -3798,8 +3798,9 @@ static void run_playloop(struct MPContext *mpctx)
static int read_keys(void *ctx, int fd)
{
- getch2(ctx);
- return MP_INPUT_NOTHING;
+ if (getch2(ctx))
+ return MP_INPUT_NOTHING;
+ return MP_INPUT_DEAD;
}
static bool attachment_is_font(struct demux_attachment *att)
diff --git a/osdep/getch2-win.c b/osdep/getch2-win.c
index 326cf1a7d0..f1ccea6359 100644
--- a/osdep/getch2-win.c
+++ b/osdep/getch2-win.c
@@ -158,11 +158,12 @@ static int getch2_internal(void)
return -1;
}
-void getch2(struct mp_fifo *fifo)
+bool getch2(struct mp_fifo *fifo)
{
int r = getch2_internal();
if (r >= 0)
mplayer_put_key(fifo, r);
+ return true;
}
void getch2_enable(void)
diff --git a/osdep/getch2.c b/osdep/getch2.c
index 1a92866afd..dcd5b1ad84 100644
--- a/osdep/getch2.c
+++ b/osdep/getch2.c
@@ -158,11 +158,17 @@ void get_screen_size(void){
#endif
}
-void getch2(struct mp_fifo *fifo)
+bool getch2(struct mp_fifo *fifo)
{
int retval = read(0, &getch2_buf[getch2_len], BUF_LEN-getch2_len);
+ /* Return false on EOF to stop running select() on the FD, as it'd
+ * trigger all the time. Note that it's possible to get temporary
+ * EOF on terminal if the user presses ctrl-d, but that shouldn't
+ * happen if the terminal state change done in getch2_enable()
+ * works.
+ */
if (retval < 1)
- return;
+ return retval;
getch2_len += retval;
while (getch2_len > 0 && (getch2_len > 1 || getch2_buf[0] != 27)) {
@@ -279,6 +285,7 @@ void getch2(struct mp_fifo *fifo)
getch2_buf[i] = getch2_buf[len+i];
mplayer_put_key(fifo, code);
}
+ return true;
}
static int getch2_status=0;
diff --git a/osdep/getch2.h b/osdep/getch2.h
index 8fb346d4f7..458881c15f 100644
--- a/osdep/getch2.h
+++ b/osdep/getch2.h
@@ -24,6 +24,8 @@
#ifndef MPLAYER_GETCH2_H
#define MPLAYER_GETCH2_H
+#include <stdbool.h>
+
#include "config.h"
/* Screen size. Initialized by load_termcap() and get_screen_size() */
@@ -45,7 +47,7 @@ void getch2_disable(void);
/* Read a character or a special key code (see keycodes.h) */
struct mp_fifo;
-void getch2(struct mp_fifo *fifo);
+bool getch2(struct mp_fifo *fifo);
#ifdef CONFIG_ICONV
/**