diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-03-10 02:14:30 +0200 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-03-10 02:35:02 +0200 |
commit | bc1d0ca37d9bdfd69a945043650e0246ffeb5f94 (patch) | |
tree | 8269c9cbc1df72afb5715b77669698a0781f6250 /osdep | |
parent | f7cc4152f7c55808c5dd6bbd49c216c9345eb686 (diff) | |
parent | e9a5e7f667d1b0c0dec0053ad9ec6f7bc3162b60 (diff) |
Merge svn changes up to r30798
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/getch2-win.c | 37 | ||||
-rw-r--r-- | osdep/osdep.h | 33 |
2 files changed, 57 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; diff --git a/osdep/osdep.h b/osdep/osdep.h new file mode 100644 index 0000000000..0a64c31120 --- /dev/null +++ b/osdep/osdep.h @@ -0,0 +1,33 @@ +/* + * Header in order to include OS-specific headers, macros, types and so on + * + * Copyright (c) 2010 by KO Myung-Hun (komh@chollian.net) + * + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPLAYER_OSDEP_H +#define MPLAYER_OSDEP_H + +#ifdef __OS2__ +#define INCL_DOS +#define INCL_DOSDEVIOCTL +#include <os2.h> +#endif + +#endif /* MPLAYER_OSDEP_H */ + |