diff options
author | wm4 <wm4@mplayer2.org> | 2012-02-25 15:05:12 +0100 |
---|---|---|
committer | wm4 <wm4@mplayer2.org> | 2012-02-25 16:40:14 +0100 |
commit | c8efb6d5665d3b455ea005da74c51f9e37b1132f (patch) | |
tree | 574d48eccac3430c5d178e8b60499d1a79579ae3 | |
parent | 3022129d85785fa0095e3bbf8df24988a21b1ee9 (diff) | |
download | mpv-c8efb6d5665d3b455ea005da74c51f9e37b1132f.tar.bz2 mpv-c8efb6d5665d3b455ea005da74c51f9e37b1132f.tar.xz |
input: restore terminal attributes after resume
Install a signal handler on SIGCONT, and restore the terminal
attributes with tcsetattr() if it happens. This is needed with some
shells (such as tcsh) that don't restore the terminal attributes set
by mplayer. Without this, terminal I/O doesn't work as intended after
resume with these shells.
Fixes #155.
-rw-r--r-- | osdep/getch2.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/osdep/getch2.c b/osdep/getch2.c index 1a92866afd..78e60b2373 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -34,6 +34,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <signal.h> #include <sys/time.h> #include <sys/types.h> #ifdef CONFIG_IOCTL @@ -281,27 +282,41 @@ void getch2(struct mp_fifo *fifo) } } -static int getch2_status=0; +static volatile int getch2_status=0; -void getch2_enable(void){ +static void do_enable_getch2(void) +{ #ifdef HAVE_TERMIOS -struct termios tio_new; - tcgetattr(0,&tio_orig); - tio_new=tio_orig; + struct termios tio_new; + tcgetattr(0,&tio_new); tio_new.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */ tio_new.c_cc[VMIN] = 0; tio_new.c_cc[VTIME] = 0; tcsetattr(0,TCSANOW,&tio_new); #endif +} + +static void continue_sighandler(int signum) +{ + if (getch2_status) + do_enable_getch2(); +} + +void getch2_enable(void){ +#ifdef HAVE_TERMIOS + tcgetattr(0,&tio_orig); + do_enable_getch2(); +#endif getch2_status=1; + signal(SIGCONT,continue_sighandler); } void getch2_disable(void){ if(!getch2_status) return; // already disabled / never enabled + getch2_status=0; #ifdef HAVE_TERMIOS tcsetattr(0,TCSANOW,&tio_orig); #endif - getch2_status=0; } #ifdef CONFIG_ICONV |