DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2809
Version: 2.0-current


Steps to reproduce:
===================

- Overload the "handle" method of a window with the following code:
==============================8<------------------------------
int MyWindow::handle (int event)
{
   if ((event == fltk::KEY) || (event == fltk::KEYUP)) {
      printf ("Key %s event: code = %u, text = '%s'\n",
              (event == fltk::KEY) ? "down" : "up",
              fltk::event_key(), fltk::event_text());
   }
   return fltk::Window::handle (event);
}
------------------------------>8==============================

- Compile and run on X11;
- Press a key and keep it pressed;
- While still pressing the first key, press a second key;
- Release the first key;
- Release the second key.


Expected result:
================

The program prints the following messages in this order:
- "Key down event" with the key code and text for the first key;
- "Key down event" with the key code and text for the second key;
- "Key up event" with the key code and text for the first key;
- "Key up event" with the key code and text for the second key.


Actual result:
==============

The program prints the following messages in this order:
- "Key down event" with the key code and text for the first key;
- "Key down event" with the key code and text for the second key;
- "Key up event" with the text for the *second* key and the key code for
the first key, unless the second key is in the numeric pad in which case
it prints the text and code for the second key;
- "Key up event" with the key code and text for the second key.


Patch:
======

The attached patch fixes the issue for me.


Link: http://www.fltk.org/str.php?L2809
Version: 2.0-current
# HG changeset patch
# Parent 7124c05c97d96a0ee585f996482e10607fc55961
Fixed an issue on X11 where pressing multiple keys at once before releasing 
them causes incorrect 'release' events to be generated.


diff -r 7124c05c97d9 -r 8018acd17718 src/x11/run.cxx
--- a/src/x11/run.cxx   Sun Dec 04 11:20:28 2011 +0000
+++ b/src/x11/run.cxx   Sat Mar 03 18:46:41 2012 +0100
@@ -1631,50 +1631,7 @@
       recent_keycode = keycode;
     }
     fl_key_vector[keycode/8] |= (1 << (keycode%8));
-    static char* buffer = 0;
-    static int buffer_len;
-    if (!buffer) buffer = new char[buffer_len = 20];
-    int len;
-    KeySym keysym;
-#if USE_XIM
-    if (!fl_xim_ic)
-        fl_new_ic(xevent.xany.window);
-    if (fl_xim_ic) {
-      Status status;
-    RETRY:
-      buffer[0] = 0;
-      keysym = 0;
-#ifdef __sgi
-#define Xutf8LookupString XmbLookupString
-#endif
-      len = Xutf8LookupString(fl_xim_ic, (XKeyPressedEvent *)&xevent.xkey,
-                             buffer, buffer_len-1, &keysym, &status);
-      switch (status) {
-      case XBufferOverflow:
-       delete[] buffer;
-       buffer = new char[buffer_len = len+1];
-       goto RETRY;
-      case XLookupChars:
-      case XLookupKeySym:
-      case XLookupBoth:
-       break;
-      default:
-       goto NO_XIM;
-      }
-    } else {
-    NO_XIM:
-#endif
-      len = XLookupString(&(xevent.xkey), buffer, buffer_len-1, &keysym, 0);
-#if USE_XIM
-    }
-#endif
-    // Make ctrl+dash produce ^_ like it used to:
-    if (len==1 && xevent.xbutton.state&4 && keysym == '-') buffer[0] = 0x1f;
-    buffer[len] = 0;
-    e_text = buffer;
-    e_length = len;
     event = KEY;
-    fl_actual_keysym = int(keysym);
     goto GET_KEYSYM;}
 
   case KeyRelease: {
@@ -1726,7 +1683,50 @@
     // we always return the unshifted keysym, except for the keypad where
     // if numlock is off we return the function keys to match Windows:
     unsigned keycode = xevent.xkey.keycode;
-    KeySym keysym = XKeycodeToKeysym(xdisplay, keycode, 0);
+    static char* buffer = 0;
+    static int buffer_len;
+    if (!buffer) buffer = new char[buffer_len = 20];
+    int len;
+    KeySym keysym;
+#if USE_XIM
+    if (!fl_xim_ic)
+        fl_new_ic(xevent.xany.window);
+    if (fl_xim_ic) {
+      Status status;
+    RETRY:
+      buffer[0] = 0;
+      keysym = 0;
+#ifdef __sgi
+#define Xutf8LookupString XmbLookupString
+#endif
+      len = Xutf8LookupString(fl_xim_ic, (XKeyPressedEvent *)&xevent.xkey,
+                             buffer, buffer_len-1, &keysym, &status);
+      switch (status) {
+      case XBufferOverflow:
+       delete[] buffer;
+       buffer = new char[buffer_len = len+1];
+       goto RETRY;
+      case XLookupChars:
+      case XLookupKeySym:
+      case XLookupBoth:
+       break;
+      default:
+       goto NO_XIM;
+      }
+    } else {
+    NO_XIM:
+#endif
+      len = XLookupString(&(xevent.xkey), buffer, buffer_len-1, &keysym, 0);
+#if USE_XIM
+    }
+#endif
+    // Make ctrl+dash produce ^_ like it used to:
+    if (len==1 && xevent.xbutton.state&4 && keysym == '-') buffer[0] = 0x1f;
+    buffer[len] = 0;
+    e_text = buffer;
+    e_length = len;
+    fl_actual_keysym = int(keysym);
+    keysym = XKeycodeToKeysym(xdisplay, keycode, 0);
     if (!keysym) {
       // X did not map this key, return keycode with 0x8000:
       keysym = keycode|0x8000;
_______________________________________________
fltk-bugs mailing list
fltk-bugs@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to