This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] Handle Alt+Numpad key sequences in console input and select


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4652cc4384c3f24db901010adcad021c19b2b7a2

commit 4652cc4384c3f24db901010adcad021c19b2b7a2
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Thu Jan 19 18:59:48 2017 +0100

    Handle Alt+Numpad key sequences in console input and select
    
    {p}select/{p}poll completely ignored Alt+Numpad key sequences in console
    input which results in newer readline using pselect to fail handling such
    sequences correctly.  See https://cygwin.com/ml/cygwin/2017-01/msg00135.html
    
    During debugging and testing it turned out that while reading console
    input, single key presses during an Alt+Numpad sequences where not
    ignored, so ultimately a sequence like
    
      Alt-down Numpad-1 Numpad-2 Numpad-3
    
    whihc is supposed to result in a single character in the input stream
    will actually result in 4 chars in the input stream, three control
    sequences and the actual character.
    
    Both problems should be fixed by this patch.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/fhandler_console.cc | 12 ++++++++++++
 winsup/cygwin/select.cc           | 26 +++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 1162bfc..ced4f4b 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -7,6 +7,7 @@ Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
 details. */
 
 #include "winsup.h"
+#include <dinput.h>
 #include "miscfuncs.h"
 #include <stdio.h>
 #include <stdlib.h>
@@ -415,6 +416,17 @@ fhandler_console::read (void *pv, size_t& buflen)
 		// left alt -- see http://www.microsoft.com/hwdev/tech/input/Scancode.asp
 		&& input_rec.Event.KeyEvent.wVirtualScanCode == 0x38))
 	    continue;
+	  /* Ignore Alt+Numpad keys.  These are used to enter codepoints not
+	     available in the current keyboard layout.  They are eventually
+	     handled in the key-up case below.  For details see
+	     http://www.fileformat.info/tip/microsoft/enter_unicode.htm */
+	  if (input_rec.Event.KeyEvent.bKeyDown
+	      && wch == 0
+	      && input_rec.Event.KeyEvent.dwControlKeyState == LEFT_ALT_PRESSED
+	      && input_rec.Event.KeyEvent.wVirtualScanCode >= DIK_NUMPAD7
+	      && input_rec.Event.KeyEvent.wVirtualScanCode <= DIK_NUMPAD0
+	      && input_rec.Event.KeyEvent.wVirtualScanCode != DIK_SUBTRACT)
+	    continue;
 
 	  if (control_key_state & SHIFT_PRESSED)
 	    con.nModifiers |= 1;
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 5789737..1195951 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -12,6 +12,7 @@ details. */
 #define  __INSIDE_CYGWIN_NET__
 
 #include "winsup.h"
+#include <dinput.h>
 #include <stdlib.h>
 #include <sys/param.h>
 #include "ntdll.h"
@@ -893,9 +894,28 @@ peek_console (select_record *me, bool)
 	fh->send_winch_maybe ();
 	if (irec.EventType == KEY_EVENT)
 	  {
-	    if (irec.Event.KeyEvent.bKeyDown
-		&& (irec.Event.KeyEvent.uChar.AsciiChar
-		    || fhandler_console::get_nonascii_key (irec, tmpbuf)))
+	    if (irec.Event.KeyEvent.bKeyDown)
+	      {
+		/* Ignore Alt+Numpad keys.  These are used to enter codepoints
+		   not available in the current keyboard layout.  They are
+		   eventually handled in the key-up case below.  For details see
+		   http://www.fileformat.info/tip/microsoft/enter_unicode.htm */
+		if (irec.Event.KeyEvent.uChar.UnicodeChar == 0
+		    && irec.Event.KeyEvent.dwControlKeyState == LEFT_ALT_PRESSED
+		    && irec.Event.KeyEvent.wVirtualScanCode >= DIK_NUMPAD7
+		    && irec.Event.KeyEvent.wVirtualScanCode <= DIK_NUMPAD0
+		    && irec.Event.KeyEvent.wVirtualScanCode != DIK_SUBTRACT)
+		   ;
+		/* Handle normal input. */
+		else if (irec.Event.KeyEvent.uChar.UnicodeChar
+			 || fhandler_console::get_nonascii_key (irec, tmpbuf))
+		  return me->read_ready = true;
+	      }
+	    /* Ignore key up events, except for left alt events with
+	       non-zero character */
+	    else if (irec.Event.KeyEvent.uChar.UnicodeChar != 0
+		     && irec.Event.KeyEvent.wVirtualKeyCode == VK_MENU
+		     && irec.Event.KeyEvent.wVirtualScanCode == 0x38)
 	      return me->read_ready = true;
 	  }
 	else


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]