Hello,

I'm suggesting the following patch wich allows keyboard modifiers (CTRL,
SHIFT, ALT) to be retrieved by applications that might need them using an ioctl
command - MC is one of them. I don't really care if the name used will be
TIOCLINUX, I am open to suggestions what the proper name might for the ioctl
control code should be. In fact I have coded an alternative patch that uses
cygwin_internal () to retrieve the data but I dont feel too comfortable with it
since it seems too Cygwin specific - in any case I prefer the ioctl way of
doing things but as I said I have an alternative just in case. The attached
patch is pretty much non-intrusive, while the one employing cygwin_internal ()
adds a new member to the tty_min structure thus changing the shared memory
footprint and I consider it too intrusive.

Please, review and share your thoughts :)

2003-08-01  Pavel Tsekov  <[EMAIL PROTECTED]>

        * fhandler_console.c (fhandler_console::read): Record the state of the
SHIFT, CTRL and
        ALT keys at the time of the last keyboard input event.
        (fhandler_console::ioctl): Handle requests to retrieve the keyboard
modifiers via the
        TIOCLINUX command.
        * fhandler_tty.c (fhandler_tty_slave::read): Ditto.
        * include/sys/termios.h (TIOCLINUX): New macro definition.

-- 
COMPUTERBILD 15/03: Premium-e-mail-Dienste im Test
--------------------------------------------------
1. GMX TopMail - Platz 1 und Testsieger!
2. GMX ProMail - Platz 2 und Preis-Qualitätssieger!
3. Arcor - 4. web.de - 5. T-Online - 6. freenet.de - 7. daybyday - 8. e-Post
Index: fhandler_console.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_console.cc,v
retrieving revision 1.111
diff -u -p -r1.111 fhandler_console.cc
--- fhandler_console.cc 16 Jun 2003 03:24:10 -0000      1.111
+++ fhandler_console.cc 1 Aug 2003 00:30:54 -0000
@@ -294,6 +294,8 @@ fhandler_console::read (void *pv, size_t
 #define virtual_key_code (input_rec.Event.KeyEvent.wVirtualKeyCode)
 #define control_key_state (input_rec.Event.KeyEvent.dwControlKeyState)
 
+         dev_state->nModifiers = 0;
+
 #ifdef DEBUGGING
          /* allow manual switching to/from raw mode via ctrl-alt-scrolllock */
          if (input_rec.Event.KeyEvent.bKeyDown &&
@@ -340,13 +342,25 @@ fhandler_console::read (void *pv, size_t
                && input_rec.Event.KeyEvent.wVirtualScanCode == 0x38))
            continue;
 
+         if (control_key_state & SHIFT_PRESSED)
+           dev_state->nModifiers |= 1;
+         if (control_key_state & RIGHT_ALT_PRESSED)
+           dev_state->nModifiers |= 2;
+         if (control_key_state & CTRL_PRESSED)
+           dev_state->nModifiers |= 4;
+         if (control_key_state & LEFT_ALT_PRESSED)
+           dev_state->nModifiers |= 8;
+
          if (wch == 0 ||
              /* arrow/function keys */
              (input_rec.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
            {
              toadd = get_nonascii_key (input_rec, tmp);
              if (!toadd)
-               continue;
+               {
+                 dev_state->nModifiers = 0;
+                 continue;
+               }
              nread = strlen (toadd);
            }
          else
@@ -379,6 +393,7 @@ fhandler_console::read (void *pv, size_t
                  tmp[1] = cyg_tolower (tmp[1]);
                  toadd = tmp;
                  nread++;
+                 dev_state->nModifiers &= ~4;
                }
            }
 #undef ich
@@ -715,6 +730,17 @@ fhandler_console::ioctl (unsigned int cm
       case TIOCSWINSZ:
        (void) bg_check (SIGTTOU);
        return 0;
+      case TIOCLINUX:
+       if (* (int *) buf == 6)
+         {
+           * (int *) buf = dev_state->nModifiers;
+           return 0;
+         }
+       else
+         {
+           set_errno (EINVAL);
+           return -1;
+         }
     }
 
   return fhandler_base::ioctl (cmd, buf);
Index: fhandler_tty.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_tty.cc,v
retrieving revision 1.101
diff -u -p -r1.101 fhandler_tty.cc
--- fhandler_tty.cc     26 Jul 2003 04:53:59 -0000      1.101
+++ fhandler_tty.cc     1 Aug 2003 00:30:58 -0000
@@ -991,6 +991,7 @@ fhandler_tty_slave::ioctl (unsigned int 
     {
     case TIOCGWINSZ:
     case TIOCSWINSZ:
+    case TIOCLINUX:
       break;
     case FIONBIO:
       set_nonblocking (*(int *) arg);
@@ -1032,6 +1033,21 @@ fhandler_tty_slave::ioctl (unsigned int 
            }
          if (ioctl_done_event)
            WaitForSingleObject (ioctl_done_event, INFINITE);
+       }
+      break;
+    case TIOCLINUX:
+      int val = * (unsigned char *) arg;
+      if (val == 6 && ioctl_request_event && ioctl_done_event)
+       {
+         get_ttyp ()->arg.value = val; 
+         SetEvent (ioctl_request_event);
+         WaitForSingleObject (ioctl_done_event, INFINITE);
+         * (unsigned char *) arg = get_ttyp ()->arg.value & 0xFF;
+       }
+      else
+       {
+         get_ttyp ()->ioctl_retval = -1;
+         set_errno (EINVAL);
        }
       break;
     }
Index: include/sys/termios.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/include/sys/termios.h,v
retrieving revision 1.7
diff -u -p -r1.7 termios.h
--- include/sys/termios.h       10 Jan 2003 12:32:49 -0000      1.7
+++ include/sys/termios.h       1 Aug 2003 00:31:02 -0000
@@ -330,5 +330,6 @@ struct winsize
 
 #define TIOCGWINSZ (('T' << 8) | 1)
 #define TIOCSWINSZ (('T' << 8) | 2)
+#define TIOCLINUX  (('T' << 8) | 3)
 
 #endif /* _SYS_TERMIOS_H */

Reply via email to