summaryrefslogtreecommitdiffstats
path: root/osdep/getch2-win.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2010-03-10 02:14:30 +0200
committerUoti Urpala <uau@glyph.nonexistent.invalid>2010-03-10 02:35:02 +0200
commitbc1d0ca37d9bdfd69a945043650e0246ffeb5f94 (patch)
tree8269c9cbc1df72afb5715b77669698a0781f6250 /osdep/getch2-win.c
parentf7cc4152f7c55808c5dd6bbd49c216c9345eb686 (diff)
parente9a5e7f667d1b0c0dec0053ad9ec6f7bc3162b60 (diff)
downloadmpv-bc1d0ca37d9bdfd69a945043650e0246ffeb5f94.tar.bz2
mpv-bc1d0ca37d9bdfd69a945043650e0246ffeb5f94.tar.xz
Merge svn changes up to r30798
Diffstat (limited to 'osdep/getch2-win.c')
-rw-r--r--osdep/getch2-win.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/osdep/getch2-win.c b/osdep/getch2-win.c
index 9dae9cd91d..7d0ab8b17d 100644
--- a/osdep/getch2-win.c
+++ b/osdep/getch2-win.c
@@ -25,6 +25,7 @@
#include "config.h"
#include <stdio.h>
+#include <stdint.h>
#include <string.h>
#include <windows.h>
#include "keycodes.h"
@@ -32,17 +33,19 @@
#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)){
+ if (size > retval) size = retval;
+ } else {
+ if (WaitForSingleObject(in, 0))
+ size = 0;
+ }
+ if(!size){
return MP_INPUT_NOTHING;
}
- if(retval>size)retval=size;
- ReadFile(stdin, dest, retval, &retval, NULL);
+ ReadFile(in, dest, size, &retval, NULL);
if(retval)return retval;
return MP_INPUT_NOTHING;
}
@@ -54,7 +57,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)
@@ -62,9 +65,17 @@ 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(stdin,&retval))
+ if(!GetNumberOfConsoleInputEvents(in,&retval))
{
printf("getch2: can't get number of input events: %i\n",GetLastError());
return -1;
@@ -72,7 +83,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;
@@ -151,8 +162,8 @@ void getch2(struct mp_fifo *fifo)
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;