This is the mail archive of the cygwin-xfree@cygwin.com mailing list for the Cygwin XFree86 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]

RE: New devel to-do item (release all pressed keyboard keys on focus loss)




> John,
>
> Have you finished up your patches for key releasing on loss of keyboard
> focus?
>
> If so, please submit a patch by doing the following:
>
> cd xc/programs/Xserver/hw
> cvs diff -U3 xwin > xwin.diff
>
> If not, good luck figuring out those last little details,
>
> Harold

Well unfortunately I don't know whether this patch should be applied or not.

I've been using it for the past week, but occasionally I see duplicate
keystrokes.  It seems pretty random and not dependent on focus changes, but not
completely random.  It does not happen during normal typing, only with
temporally isolated presses, which is pretty vague, but it's the best I can do
at the moment.  And it does not happen often, maybe once a day under moderate
use.

I thought I was having a serious problem with X crashing whenever I returned to
my session after having locked NT 4 with CtrlAltDel, but it turned out that this
continued when I switched back to Test 53, and it stopped when I uninstalled
Folding@Home, so I blamed Folding@Home and resumed use of my patched server.
That's part of my delay.

I don't really have much time to work on this.  I'll keep reporting how it's
going if you ask, but it looks as if I will put up with the duplicates as being
a lesser evil than the autorepeat.  Of course, people not suffering from the
autorepeat may see it differently.

-John

Index: xwin/winkeybd.c
===================================================================
RCS file: /cvs/xc/programs/Xserver/hw/xwin/winkeybd.c,v
retrieving revision 1.8
diff -U3 -r1.8 winkeybd.c
--- xwin/winkeybd.c 2001/11/12 08:47:53  1.8
+++ xwin/winkeybd.c 2001/12/14 14:07:44
@@ -391,7 +391,12 @@
   return FALSE;
 }

+/*
+ * Remember which keys are down for when we lose focus.
+ */

+Bool g_fKeyStates[MAP_LENGTH];
+
 /*
  * Lift any modifier keys that are pressed
  */
@@ -399,16 +404,28 @@
 void
 winKeybdReleaseModifierKeys ()
 {
+  int i;
+
   /* Verify that the mi input system has been initialized */
   if (g_fdMessageQueue == WIN_FD_INVALID)
     return;

-  winSendKeyEvent (KEY_Alt, FALSE);
-  winSendKeyEvent (KEY_AltLang, FALSE);
-  winSendKeyEvent (KEY_LCtrl, FALSE);
-  winSendKeyEvent (KEY_RCtrl, FALSE);
-  winSendKeyEvent (KEY_ShiftL, FALSE);
-  winSendKeyEvent (KEY_ShiftR, FALSE);
+  for (i = 0; i < MAP_LENGTH; i++)
+    switch (i)
+      {
+      default:
+    if (g_fKeyStates[i])
+      {
+        ErrorF ("Simulating release of key #%d!\n", i);
+        winSendKeyEvent (i, FALSE);
+      }
+    break;
+      case KEY_CapsLock:
+      case KEY_ScrollLock:
+      case KEY_NumLock:
+      case KEY_HKTG:
+    break;
+      }
 }


@@ -422,7 +439,12 @@
 winSendKeyEvent (DWORD dwKey, Bool fDown)
 {
   xEvent           xCurrentEvent;
-
+
+  /* Ignore ups without a preceding down.  This happens when a keystroke
+     causes X to gain focus.  */
+  if (!fDown && !g_fKeyStates[dwKey])
+    return;
+
   ZeroMemory (&xCurrentEvent, sizeof (xCurrentEvent));

   xCurrentEvent.u.u.type = fDown ? KeyPress : KeyRelease;
@@ -430,4 +452,5 @@
     g_c32LastInputEventTime = GetTickCount ();
   xCurrentEvent.u.u.detail = dwKey + MIN_KEYCODE;
   mieqEnqueue (&xCurrentEvent);
+  g_fKeyStates[dwKey] = fDown;
 }



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