public inbox for cygwin-xfree@sourceware.org
help / color / mirror / Atom feed
* Fix for modifier keys after gaining focus patch
@ 2012-03-01 18:05 Vedat Hallac
  0 siblings, 0 replies; only message in thread
From: Vedat Hallac @ 2012-03-01 18:05 UTC (permalink / raw)
  To: cygwin-xfree

[-- Attachment #1: Type: text/plain, Size: 1092 bytes --]

The recent patch for sending modifier key presses when a window gains
focus depending on internal state and modifier key state has a
problem. If the right control key is pressed when a window is gaining
focus, it receives a left control keydown event, and the control state
gets stuck because the window never receives a left control keyup
event. The problem is fairly easy to replicate: run emacs-X11 from
xterm, quit with [C-x C-x] using right control (which gives focus back
to xterm), and try pressing keys. Until you press left control, all
keys you've pressed get interpreted as [C-key].

The patch is easy (and it has already been raised in
http://cygwin.com/ml/cygwin-xfree/2012-01/msg00003.html, but
the idea was dismissed later because of internal state only keeping
track of control
key, and not individual left/right control keys). I have tried the
patch below, and didn't observe any side effects so far. I've also
modified the alt/ctrl check t only consider lctrl, since the other
parts of the source seemed to indicate altgr emits a spurious lctrl.

Best regards,
Vedat Hallac

[-- Attachment #2: 0001-Fix-stuck-RCtrl-key-problem.patch --]
[-- Type: application/octet-stream, Size: 1451 bytes --]

diff --git a/hw/xwin/winkeybd.c b/hw/xwin/winkeybd.c
--- a/hw/xwin/winkeybd.c
+++ b/hw/xwin/winkeybd.c
@@ -286,18 +286,26 @@ winRestoreModeKeyStates (void)
   {
     /* consider modifer keys */
 
-    BOOL ctrl   = (GetAsyncKeyState (VK_CONTROL) < 0);
-    BOOL shift  = (GetAsyncKeyState (VK_SHIFT)   < 0);
+    BOOL lctrl   = (GetAsyncKeyState (VK_LCONTROL) < 0);
+    BOOL rctrl   = (GetAsyncKeyState (VK_RCONTROL) < 0);
+    BOOL lshift  = (GetAsyncKeyState (VK_LSHIFT)   < 0);
+    BOOL rshift  = (GetAsyncKeyState (VK_RSHIFT)   < 0);
     BOOL alt    = (GetAsyncKeyState (VK_LMENU)   < 0);
     BOOL altgr  = (GetAsyncKeyState (VK_RMENU)   < 0);
 
-    if (ctrl && altgr) ctrl = FALSE;
+    if (lctrl && altgr) lctrl = FALSE;
 
-    if (WIN_XOR (internalKeyStates & ControlMask, ctrl))
-      winSendKeyEvent (KEY_LCtrl, ctrl);
+    if (WIN_XOR (internalKeyStates & ControlMask, lctrl))
+      winSendKeyEvent (KEY_LCtrl, lctrl);
 
-    if (WIN_XOR (internalKeyStates & ShiftMask, shift))
-      winSendKeyEvent (KEY_ShiftL, shift);
+    if (WIN_XOR (internalKeyStates & ControlMask, rctrl))
+      winSendKeyEvent (KEY_RCtrl, rctrl);
+
+    if (WIN_XOR (internalKeyStates & ShiftMask, lshift))
+      winSendKeyEvent (KEY_ShiftL, lshift);
+
+    if (WIN_XOR (internalKeyStates & ShiftMask, rshift))
+      winSendKeyEvent (KEY_ShiftR, rshift);
 
     if (WIN_XOR (internalKeyStates & Mod1Mask, alt))
       winSendKeyEvent (KEY_Alt, alt);
-- 


[-- Attachment #3: Type: text/plain, Size: 223 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-03-01 18:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-01 18:05 Fix for modifier keys after gaining focus patch Vedat Hallac

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).