From c8efb6d5665d3b455ea005da74c51f9e37b1132f Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 25 Feb 2012 15:05:12 +0100 Subject: 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. --- osdep/getch2.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'osdep') 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 #include #include +#include #include #include #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 -- cgit v1.2.3