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.
This commit is contained in:
wm4 2012-02-25 15:05:12 +01:00
parent 3022129d85
commit c8efb6d566
1 changed files with 21 additions and 6 deletions

View File

@ -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