X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2Flib_getch.c;fp=ncurses%2Flib_getch.c;h=b740885b81664c3b2d276e0939ebdf87e06f04d9;hp=337cc2ca8994067023ab9d271d554e4e94d77559;hb=0eb88fc5281804773e2a0c7a488a4452463535ce;hpb=661078ddbde3ce0f3b06e95642fbb9b5fef7dca1 diff --git a/ncurses/lib_getch.c b/ncurses/base/lib_getch.c similarity index 90% rename from ncurses/lib_getch.c rename to ncurses/base/lib_getch.c index 337cc2ca..b740885b 100644 --- a/ncurses/lib_getch.c +++ b/ncurses/base/lib_getch.c @@ -40,17 +40,48 @@ #include -MODULE_ID("$Id: lib_getch.c,v 1.40 1998/02/11 12:13:58 tom Exp $") +MODULE_ID("$Id: lib_getch.c,v 1.43 1999/03/08 02:35:10 tom Exp $") #include int ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */ +#ifdef USE_EMX_MOUSE +# include +static int +kbd_mouse_read(unsigned char *p) +{ +fd_set fdset; +int nums = SP->_ifd+1; + + for (;;) { + FD_ZERO(&fdset); + FD_SET(SP->_checkfd, &fdset); + if (SP->_mouse_fd >= 0) { + FD_SET(SP->_mouse_fd, &fdset); + if (SP->_mouse_fd > SP->_checkfd) + nums = SP->_mouse_fd+1; + } + if (select(nums, &fdset, NULL, NULL, NULL) >= 0) { + int n; + + if (FD_ISSET(SP->_mouse_fd, &fdset)) /* Prefer mouse */ + n = read(SP->_mouse_fd, p, 1); + else + n = read(SP->_ifd, p, 1); + return n; + } + if (errno != EINTR) + return -1; + } +} +#endif /* USE_EMX_MOUSE */ + static inline int fifo_peek(void) { int ch = SP->_fifo[peek]; T(("peeking at %d", peek)); - + p_inc(); return ch; } @@ -69,7 +100,7 @@ int ch; } else h_inc(); - + #ifdef TRACE if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump(); #endif @@ -88,8 +119,8 @@ again: errno = 0; #endif -#if USE_GPM_SUPPORT - if ((SP->_mouse_fd >= 0) +#if USE_GPM_SUPPORT + if ((SP->_mouse_fd >= 0) && (_nc_timed_wait(3, -1, (int *)0) & 2)) { SP->_mouse_event(SP); @@ -99,17 +130,21 @@ again: #endif { unsigned char c2=0; +#ifdef USE_EMX_MOUSE + n = kbd_mouse_read(&c2); +#else n = read(SP->_ifd, &c2, 1); - ch = c2; +#endif + ch = c2 & 0xff; } #ifdef HIDE_EINTR /* * Under System V curses with non-restarting signals, getch() returns - * with value ERR when a handled signal keeps it from completing. + * with value ERR when a handled signal keeps it from completing. * If signals restart system calls, OTOH, the signal is invisible * except to its handler. - * + * * We don't want this difference to show. This piece of code * tries to make it look like we always have restarting signals. */ @@ -194,8 +229,9 @@ int ch; if (wgetch_should_refresh(win)) wrefresh(win); - if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) { - int delay; + if (!win->_notimeout && (win->_delay >= 0 || SP->_cbreak > 1)) + { + int delay; T(("timed delay in wgetch()")); if (SP->_cbreak > 1) @@ -211,7 +247,8 @@ int ch; /* else go on to read data available */ } - if (win->_use_keypad) { + if (win->_use_keypad) + { /* * This is tricky. We only want to get special-key * events one at a time. But we want to accumulate