#include <curses.priv.h>
-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 <fifo_defs.h>
int ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */
+#ifdef USE_EMX_MOUSE
+# include <sys/select.h>
+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;
}
}
else
h_inc();
-
+
#ifdef TRACE
if (_nc_tracing & TRACE_IEVENT) _nc_fifo_dump();
#endif
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);
#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.
*/
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)
/* 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