From 27306a18db00afb3e5e4aced936e4d9ad9ddfdf5 Mon Sep 17 00:00:00 2001 From: reimar Date: Sat, 27 Feb 2010 21:47:45 +0000 Subject: Include getch2.h to get rid of some warnings. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30776 b3059339-0415-0410-9bf9-f77b7e298cf2 --- osdep/getch2-win.c | 1 + 1 file changed, 1 insertion(+) (limited to 'osdep/getch2-win.c') diff --git a/osdep/getch2-win.c b/osdep/getch2-win.c index 3c428834ff..5528680cd8 100644 --- a/osdep/getch2-win.c +++ b/osdep/getch2-win.c @@ -30,6 +30,7 @@ #include "keycodes.h" #include "input/input.h" #include "mp_fifo.h" +#include "getch2.h" // HACK, stdin is used as something else below #undef stdin -- cgit v1.2.3 From 5f25eaf3d2011cfb92d4553b1421c13d98090906 Mon Sep 17 00:00:00 2001 From: reimar Date: Sat, 27 Feb 2010 21:50:59 +0000 Subject: Do not misuse the stdin name. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30777 b3059339-0415-0410-9bf9-f77b7e298cf2 --- osdep/getch2-win.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'osdep/getch2-win.c') diff --git a/osdep/getch2-win.c b/osdep/getch2-win.c index 5528680cd8..45f68e8196 100644 --- a/osdep/getch2-win.c +++ b/osdep/getch2-win.c @@ -31,17 +31,15 @@ #include "input/input.h" #include "mp_fifo.h" #include "getch2.h" -// HACK, stdin is used as something else below -#undef stdin int mp_input_slave_cmd_func(int fd,char* dest,int size){ DWORD retval; - HANDLE stdin = GetStdHandle(STD_INPUT_HANDLE); - if(!PeekNamedPipe(stdin, NULL, size, &retval, NULL, NULL) || !retval){ + HANDLE in = GetStdHandle(STD_INPUT_HANDLE); + if(!PeekNamedPipe(in, NULL, size, &retval, NULL, NULL) || !retval){ return MP_INPUT_NOTHING; } if(retval>size)retval=size; - ReadFile(stdin, dest, retval, &retval, NULL); + ReadFile(in, dest, retval, &retval, NULL); if(retval)return retval; return MP_INPUT_NOTHING; } @@ -53,7 +51,7 @@ char * erase_to_end_of_line = NULL; void get_screen_size(void){ } -static HANDLE stdin; +static HANDLE in; static int getch2_status=0; static int getch2_internal(void) @@ -63,7 +61,7 @@ static int getch2_internal(void) int i=0; if(!getch2_status)return -1; /*check if there are input events*/ - if(!GetNumberOfConsoleInputEvents(stdin,&retval)) + if(!GetNumberOfConsoleInputEvents(in,&retval)) { printf("getch2: can't get number of input events: %i\n",GetLastError()); return -1; @@ -71,7 +69,7 @@ static int getch2_internal(void) if(retval<=0)return -1; /*read all events*/ - if(!ReadConsoleInput(stdin,eventbuffer,128,&retval)) + if(!ReadConsoleInput(in,eventbuffer,128,&retval)) { printf("getch: can't read input events\n"); return -1; @@ -150,8 +148,8 @@ void getch2(void) void getch2_enable(void) { DWORD retval; - stdin = GetStdHandle(STD_INPUT_HANDLE); - if(!GetNumberOfConsoleInputEvents(stdin,&retval)) + in = GetStdHandle(STD_INPUT_HANDLE); + if(!GetNumberOfConsoleInputEvents(in,&retval)) { printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError()); getch2_status = 0; -- cgit v1.2.3 From 490a015043f105f3c80bdbde187166c469f3d63f Mon Sep 17 00:00:00 2001 From: reimar Date: Sat, 27 Feb 2010 23:12:34 +0000 Subject: Make -slave also work with the normal console on Windows. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30780 b3059339-0415-0410-9bf9-f77b7e298cf2 --- osdep/getch2-win.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'osdep/getch2-win.c') diff --git a/osdep/getch2-win.c b/osdep/getch2-win.c index 45f68e8196..dd6268b06a 100644 --- a/osdep/getch2-win.c +++ b/osdep/getch2-win.c @@ -35,11 +35,16 @@ int mp_input_slave_cmd_func(int fd,char* dest,int size){ DWORD retval; HANDLE in = GetStdHandle(STD_INPUT_HANDLE); - if(!PeekNamedPipe(in, NULL, size, &retval, NULL, NULL) || !retval){ + if(PeekNamedPipe(in, NULL, size, &retval, NULL, NULL)){ + if (size > retval) size = retval; + } else { + if (WaitForSingleObject(in, 0)) + size = 0; + } + if(!size){ return MP_INPUT_NOTHING; } - if(retval>size)retval=size; - ReadFile(in, dest, retval, &retval, NULL); + ReadFile(in, dest, size, &retval, NULL); if(retval)return retval; return MP_INPUT_NOTHING; } -- cgit v1.2.3 From 6961b9ef7098440a7e1e31dc9908e3b3b30c23fb Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 28 Feb 2010 00:24:01 +0000 Subject: Add support for reading key events from MinGW xterm. Unfortunately keys only arrive after enter was pressed and SetNamedPipeHandleState does not seem to help. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30784 b3059339-0415-0410-9bf9-f77b7e298cf2 --- osdep/getch2-win.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'osdep/getch2-win.c') diff --git a/osdep/getch2-win.c b/osdep/getch2-win.c index dd6268b06a..7218e81a5a 100644 --- a/osdep/getch2-win.c +++ b/osdep/getch2-win.c @@ -25,6 +25,7 @@ #include "config.h" #include +#include #include #include #include "keycodes.h" @@ -64,7 +65,15 @@ static int getch2_internal(void) INPUT_RECORD eventbuffer[128]; DWORD retval; int i=0; - if(!getch2_status)return -1; + if(!getch2_status){ + // supports e.g. MinGW xterm, unfortunately keys are only received after + // enter was pressed. + uint8_t c; + if (!PeekNamedPipe(in, NULL, 1, &retval, NULL, NULL) || !retval) + return -1; + ReadFile(in, &c, 1, &retval, NULL); + return retval == 1 ? c : -1; + } /*check if there are input events*/ if(!GetNumberOfConsoleInputEvents(in,&retval)) { -- cgit v1.2.3