OSDN Git Service

* fhandler.h (fhandler_tty_slave): Declare new methods.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / select.cc
index 8331271..1823cd1 100644 (file)
@@ -1,6 +1,6 @@
 /* select.cc
 
-   Copyright 1996, 1997, 1998, 1999, 2000 Red Hat, Inc.
+   Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc.
 
    Written by Christopher Faylor of Cygnus Solutions
    cgf@cygnus.com
@@ -412,7 +412,7 @@ peek_pipe (select_record *s, int ignra)
          gotone = 1;
          goto out;
        }
-      if (fh->bg_check (SIGTTIN) <= 0)
+      if (fh->bg_check (SIGTTIN) <= bg_eof)
        {
          gotone = s->read_ready = 1;
          goto out;
@@ -627,7 +627,7 @@ peek_console (select_record *me, int ignra)
   set_handle_or_return_if_not_open (h, me);
 
   for (;;)
-    if (fh->bg_check (SIGTTIN) <= 0)
+    if (fh->bg_check (SIGTTIN) <= bg_eof)
       return me->read_ready = 1;
     else if (!PeekConsoleInput (h, &irec, 1, &events_read) || !events_read)
       break;
@@ -635,6 +635,13 @@ peek_console (select_record *me, int ignra)
       {
        if (irec.EventType == WINDOW_BUFFER_SIZE_EVENT)
          kill_pgrp (fh->tc->getpgid (), SIGWINCH);
+       else if (irec.EventType == MOUSE_EVENT &&
+                (irec.Event.MouseEvent.dwEventFlags == 0 ||
+                 irec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK))
+         {
+           if (fh->mouse_aware ())
+             return me->read_ready = 1;
+         }
        else if (irec.EventType == KEY_EVENT && irec.Event.KeyEvent.bKeyDown == TRUE &&
                 (irec.Event.KeyEvent.uChar.AsciiChar || get_nonascii_key (irec, tmpbuf)))
          return me->read_ready = 1;
@@ -736,6 +743,53 @@ fhandler_tty_common::select_except (select_record *s)
   return ((fhandler_pipe *)this)->fhandler_pipe::select_except (s);
 }
 
+static int
+verify_tty_slave (select_record *me, fd_set *readfds, fd_set *writefds,
+          fd_set *exceptfds)
+{
+  if (WaitForSingleObject (me->h, 0) == WAIT_OBJECT_0)
+    me->read_ready = 1;
+  return set_bits (me, readfds, writefds, exceptfds);
+}
+
+select_record *
+fhandler_tty_slave::select_read (select_record *s)
+{
+  if (!s)
+    s = new select_record;
+  s->h = input_available_event;
+  s->startup = no_startup;
+  s->poll = poll_pipe;
+  s->verify = verify_tty_slave;
+  s->read_selected = TRUE;
+  s->cleanup = NULL;
+  return s;
+}
+
+int
+fhandler_tty_slave::ready_for_read (int fd, DWORD howlong, int ignra)
+{
+  HANDLE w4[2];
+  if (!ignra && get_readahead_valid ())
+    {
+      select_printf ("readahead");
+      return 1;
+    }
+  w4[0] = signal_arrived;
+  w4[1] = input_available_event;
+  switch (WaitForMultipleObjects (2, w4, FALSE, howlong))
+    {
+    case WAIT_OBJECT_0 + 1:
+      return 1;
+    case WAIT_FAILED:
+      select_printf ( "wait failed %E" );
+    case WAIT_OBJECT_0:
+    case WAIT_TIMEOUT:
+    default:
+      return 0;
+    }
+}
+
 select_record *
 fhandler_dev_null::select_read (select_record *s)
 {