summaryrefslogtreecommitdiffstats
path: root/osdep/getch2.c
diff options
context:
space:
mode:
authoruau <uau@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-08-25 04:28:08 +0000
committeruau <uau@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-08-25 04:28:08 +0000
commitc51c1fc6681e20465de75436b5435947676fdabb (patch)
tree8e9bf1946a6436dd46e7d694134a5aadb0bf2b8a /osdep/getch2.c
parentdcd9ee6d5ab6c57fec3abd529e8de40a8cc609a0 (diff)
downloadmpv-c51c1fc6681e20465de75436b5435947676fdabb.tar.bz2
mpv-c51c1fc6681e20465de75436b5435947676fdabb.tar.xz
Make terminal input work more like VO key input
The Unix version of getch2() could either return an internally buffered key or do a second-level select() in addition to the input.c one and then read more data. Change getch2() to always add all read keys with mplayer_put_key() (like video output window keyboard input does) and remove the internal select() from the Unix version. Make input.c call mplayer_get_key() directly. The primary motivation for this change is to make combining multiple event sources under one select() easier. Now getch2() only needs to be called when the corresponding fd is readable, and it will be possible to handle events from X-based VOs with the same code. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@24149 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'osdep/getch2.c')
-rw-r--r--osdep/getch2.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/osdep/getch2.c b/osdep/getch2.c
index 0d04de87b5..e204fa4c03 100644
--- a/osdep/getch2.c
+++ b/osdep/getch2.c
@@ -35,6 +35,7 @@
#include <unistd.h>
+#include "mp_fifo.h"
#include "keycodes.h"
#ifdef HAVE_TERMIOS
@@ -133,27 +134,19 @@ void get_screen_size(void){
#endif
}
-int getch2(int time){
+void getch2(void)
+{
int len=0;
int code=0;
int i=0;
- while(!getch2_len || (getch2_len==1 && getch2_buf[0]==27)){
- fd_set rfds;
- struct timeval tv;
int retval;
- /* Watch stdin (fd 0) to see when it has input. */
- FD_ZERO(&rfds); FD_SET(0,&rfds);
- /* Wait up to 'time' microseconds. */
- tv.tv_sec=time/1000; tv.tv_usec = (time%1000)*1000;
- retval=select(1, &rfds, NULL, NULL, &tv);
- if(retval<=0) return -1;
- /* Data is available now. */
retval=read(0,&getch2_buf[getch2_len],BUF_LEN-getch2_len);
- if(retval<1) return -1;
+ if (retval < 1)
+ return;
getch2_len+=retval;
- }
+ while (getch2_len > 0 && (getch2_len > 1 || getch2_buf[0] != 27)) {
/* First find in the TERMCAP database: */
for(i=0;i<getch2_key_db;i++){
if((len=getch2_keys[i].len)<=getch2_len)
@@ -217,7 +210,8 @@ found:
int i;
for(i=0;i<getch2_len;i++) getch2_buf[i]=getch2_buf[len+i];
}
- return code;
+ mplayer_put_key(code);
+ }
}
static int getch2_status=0;