public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Simplify check for Alt-Numpad
@ 2017-01-19 20:58 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2017-01-19 20:58 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=3b7b65b2f8a809af30eb1eff6f26df5907e6f0ba
commit 3b7b65b2f8a809af30eb1eff6f26df5907e6f0ba
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Thu Jan 19 21:41:21 2017 +0100
Simplify check for Alt-Numpad
Create two new inline functions is_alt_numpad_key(PINPUT_RECORD) and
is_alt_numpad_event(PINPUT_RECORD) which contain the actual checks.
Call these functions from fhandler_console::read and peek_console for
better readability.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/cygwin/fhandler_console.cc | 29 +++++------------------------
winsup/cygwin/miscfuncs.h | 25 +++++++++++++++++++++++++
winsup/cygwin/select.cc | 20 +++++---------------
3 files changed, 35 insertions(+), 39 deletions(-)
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 13450d8..1f89acd 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -7,7 +7,6 @@ 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>
@@ -399,33 +398,16 @@ fhandler_console::read (void *pv, size_t& buflen)
break;
}
-#define ich (input_rec.Event.KeyEvent.uChar.AsciiChar)
#define wch (input_rec.Event.KeyEvent.uChar.UnicodeChar)
- /* Ignore key up events, except for left alt events with non-zero character
- */
+ /* Ignore key up events, except for Alt+Numpad events. */
if (!input_rec.Event.KeyEvent.bKeyDown &&
- /*
- Event for left alt, with a non-zero character, comes from
- "alt + numerics" key sequence.
- e.g. <left-alt> 0233 => é
- */
- !(wch != 0
- // ?? experimentally determined on an XP system
- && virtual_key_code == VK_MENU
- // left alt -- see http://www.microsoft.com/hwdev/tech/input/Scancode.asp
- && input_rec.Event.KeyEvent.wVirtualScanCode == 0x38))
+ !is_alt_numpad_event (&input_rec))
continue;
- /* Ignore Alt+Numpad keys. These are used to enter codepoints not
- available in the current keyboard layout. They are eventually
- handled below after releasing the Alt key. For details see
- http://www.fileformat.info/tip/microsoft/enter_unicode.htm */
+ /* Ignore Alt+Numpad keys. They are eventually handled below after
+ releasing the Alt key. */
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)
+ && is_alt_numpad_key (&input_rec))
continue;
if (control_key_state & SHIFT_PRESSED)
@@ -510,7 +492,6 @@ fhandler_console::read (void *pv, size_t& buflen)
con.nModifiers &= ~4;
}
}
-#undef ich
#undef wch
break;
diff --git a/winsup/cygwin/miscfuncs.h b/winsup/cygwin/miscfuncs.h
index cc22935..eb898e6 100644
--- a/winsup/cygwin/miscfuncs.h
+++ b/winsup/cygwin/miscfuncs.h
@@ -9,9 +9,34 @@ details. */
#ifndef _MISCFUNCS_H
#define _MISCFUNCS_H
+#include <dinput.h>
+
#define likely(X) __builtin_expect (!!(X), 1)
#define unlikely(X) __builtin_expect (!!(X), 0)
+/* Check for Alt+Numpad keys in a console input record. These are used to
+ enter codepoints not available in the current keyboard layout For details
+ see http://www.fileformat.info/tip/microsoft/enter_unicode.htm */
+static inline bool
+is_alt_numpad_key (PINPUT_RECORD pirec)
+{
+ return pirec->Event.KeyEvent.uChar.UnicodeChar == 0
+ && pirec->Event.KeyEvent.dwControlKeyState == LEFT_ALT_PRESSED
+ && pirec->Event.KeyEvent.wVirtualScanCode >= DIK_NUMPAD7
+ && pirec->Event.KeyEvent.wVirtualScanCode <= DIK_NUMPAD0
+ && pirec->Event.KeyEvent.wVirtualScanCode != DIK_SUBTRACT;
+}
+
+/* Event for left Alt, with a non-zero character, comes from Alt+Numpad
+ key sequence. e.g. <left-alt> 233 => é This is typically handled
+ as the key up event after releasing the Alt key. */
+static inline bool
+is_alt_numpad_event (PINPUT_RECORD pirec)
+{
+ return pirec->Event.KeyEvent.uChar.UnicodeChar != 0
+ && pirec->Event.KeyEvent.wVirtualKeyCode == VK_MENU
+ && pirec->Event.KeyEvent.wVirtualScanCode == 0x38;
+}
int __reg1 winprio_to_nice (DWORD);
DWORD __reg1 nice_to_winprio (int &);
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 1195951..158de6a 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -12,7 +12,6 @@ details. */
#define __INSIDE_CYGWIN_NET__
#include "winsup.h"
-#include <dinput.h>
#include <stdlib.h>
#include <sys/param.h>
#include "ntdll.h"
@@ -896,26 +895,17 @@ peek_console (select_record *me, bool)
{
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)
+ /* Ignore Alt+Numpad keys. They are eventually handled in the
+ key-up case below. */
+ if (is_alt_numpad_key (&irec))
;
/* 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)
+ /* Ignore key up events, except for Alt+Numpad events. */
+ else if (is_alt_numpad_event (&irec))
return me->read_ready = true;
}
else
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-01-19 20:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-19 20:58 [newlib-cygwin] Simplify check for Alt-Numpad Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).