Commit 267d38e1 authored by Alexandre Julliard's avatar Alexandre Julliard

wineconsole: Don't use a Win32 wait on a Unix file descriptor.

parent 2e3287bc
...@@ -35,6 +35,9 @@ ...@@ -35,6 +35,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_POLL_H
# include <poll.h>
#endif
#ifdef HAVE_NCURSES_H #ifdef HAVE_NCURSES_H
# include <ncurses.h> # include <ncurses.h>
#elif defined(HAVE_CURSES_H) #elif defined(HAVE_CURSES_H)
...@@ -53,7 +56,6 @@ ...@@ -53,7 +56,6 @@
#include "winecon_private.h" #include "winecon_private.h"
#include "wine/library.h" #include "wine/library.h"
#include "wine/server.h"
#include "wine/debug.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(curses); WINE_DEFAULT_DEBUG_CHANNEL(curses);
...@@ -71,7 +73,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(curses); ...@@ -71,7 +73,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(curses);
struct inner_data_curse struct inner_data_curse
{ {
unsigned long initial_mouse_mask; unsigned long initial_mouse_mask;
HANDLE hInput; int sync_pipe[2];
HANDLE input_thread;
WINDOW* pad; WINDOW* pad;
chtype* line; chtype* line;
int allow_scroll; int allow_scroll;
...@@ -846,31 +849,43 @@ static unsigned WCCURSES_FillCode(struct inner_data* data, INPUT_RECORD* ir, int ...@@ -846,31 +849,43 @@ static unsigned WCCURSES_FillCode(struct inner_data* data, INPUT_RECORD* ir, int
} }
/****************************************************************** /******************************************************************
* WCCURSES_GetEvents * input_thread
*
*
*/ */
static void WCCURSES_GetEvents(struct inner_data* data) static DWORD CALLBACK input_thread( void *arg )
{ {
struct inner_data* data = arg;
int inchar; int inchar;
INPUT_RECORD ir[8]; INPUT_RECORD ir[8];
unsigned numEvent; unsigned numEvent;
DWORD n; DWORD n;
struct pollfd pfd[2];
if ((inchar = wgetch(stdscr)) == ERR) {WINE_FIXME("Ooch. somebody beat us\n");return;}
pfd[0].fd = 0;
WINE_TRACE("Got o%o (0x%x)\n", inchar,inchar); pfd[0].events = POLLIN;
pfd[1].fd = PRIVATE(data)->sync_pipe[0];
if (inchar >= KEY_MIN && inchar <= KEY_MAX) pfd[1].events = POLLHUP;
{
numEvent = WCCURSES_FillCode(data, ir, inchar); for (;;)
}
else
{ {
numEvent = WCCURSES_FillSimpleChar(ir, inchar); pfd[0].revents = pfd[1].revents = 0;
if (poll( pfd, 2, -1 ) == -1) break;
if (pfd[0].revents & (POLLHUP|POLLERR)) break;
if (pfd[1].revents & (POLLHUP|POLLERR)) break;
if (!(pfd[0].revents & POLLIN)) continue;
if ((inchar = wgetch(stdscr)) == ERR) continue;
WINE_TRACE("Got o%o (0x%x)\n", inchar,inchar);
if (inchar >= KEY_MIN && inchar <= KEY_MAX)
numEvent = WCCURSES_FillCode(data, ir, inchar);
else
numEvent = WCCURSES_FillSimpleChar(ir, inchar);
if (numEvent) WriteConsoleInput(data->hConIn, ir, numEvent, &n);
} }
if (numEvent) close( PRIVATE(data)->sync_pipe[0] );
WriteConsoleInput(data->hConIn, ir, numEvent, &n); return 0;
} }
/****************************************************************** /******************************************************************
...@@ -882,7 +897,12 @@ static void WCCURSES_DeleteBackend(struct inner_data* data) ...@@ -882,7 +897,12 @@ static void WCCURSES_DeleteBackend(struct inner_data* data)
{ {
if (!PRIVATE(data)) return; if (!PRIVATE(data)) return;
CloseHandle(PRIVATE(data)->hInput); if (PRIVATE(data)->input_thread)
{
close( PRIVATE(data)->sync_pipe[1] );
WaitForSingleObject( PRIVATE(data)->input_thread, INFINITE );
CloseHandle( PRIVATE(data)->input_thread );
}
delwin(PRIVATE(data)->pad); delwin(PRIVATE(data)->pad);
#ifdef HAVE_MOUSEMASK #ifdef HAVE_MOUSEMASK
...@@ -905,28 +925,21 @@ static void WCCURSES_DeleteBackend(struct inner_data* data) ...@@ -905,28 +925,21 @@ static void WCCURSES_DeleteBackend(struct inner_data* data)
*/ */
static int WCCURSES_MainLoop(struct inner_data* data) static int WCCURSES_MainLoop(struct inner_data* data)
{ {
HANDLE hin[2]; DWORD id;
hin[0] = PRIVATE(data)->hInput; if (pipe( PRIVATE(data)->sync_pipe ) == -1) return 0;
hin[1] = data->hSynchro; PRIVATE(data)->input_thread = CreateThread( NULL, 0, input_thread, data, 0, &id );
for (;;) while (WaitForSingleObject(data->hSynchro, INFINITE) == WAIT_OBJECT_0)
{ {
unsigned ret = WaitForMultipleObjects(2, hin, FALSE, INFINITE); if (!WINECON_GrabChanges(data)) break;
switch (ret)
{
case WAIT_OBJECT_0:
WCCURSES_GetEvents(data);
break;
case WAIT_OBJECT_0+1:
if (!WINECON_GrabChanges(data)) return 0;
break;
default:
WINE_ERR("got pb\n");
/* err */
break;
}
} }
close( PRIVATE(data)->sync_pipe[1] );
WaitForSingleObject( PRIVATE(data)->input_thread, INFINITE );
CloseHandle( PRIVATE(data)->input_thread );
PRIVATE(data)->input_thread = 0;
return 0;
} }
/****************************************************************** /******************************************************************
...@@ -955,13 +968,6 @@ enum init_return WCCURSES_InitBackend(struct inner_data* data) ...@@ -955,13 +968,6 @@ enum init_return WCCURSES_InitBackend(struct inner_data* data)
data->fnDeleteBackend = WCCURSES_DeleteBackend; data->fnDeleteBackend = WCCURSES_DeleteBackend;
data->hWnd = NULL; data->hWnd = NULL;
if (wine_server_fd_to_handle(0, GENERIC_READ|SYNCHRONIZE, 0,
(obj_handle_t*)&PRIVATE(data)->hInput))
{
WINE_FIXME("Cannot open 0\n");
return init_failed;
}
/* FIXME: should find a good way to enable buffer scrolling /* FIXME: should find a good way to enable buffer scrolling
* For the time being, setting this to 1 will allow scrolling up/down * For the time being, setting this to 1 will allow scrolling up/down
* on buffer with F11/F12. * on buffer with F11/F12.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment