Re: [AD] another keyboard bug (bleurgh)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> The reason I post now is that Eric mentioned only one problem left in beta 
> 4.0.3, and I haven't checked if the following problem is in 4.0.3 too or
> only in 4.1.8:

Thanks for helping to make Allegro bugfree!

> When you hold the alt button and make a window loose focus, Either by
> pressing alt-tab in windowmaker or by holding alt while moving the
> mouse out of the window and giving focus to another, the alt key
> release isn't detected. This means that when the focus comes back, the
> X driver thinks the alt key is still pressed, which results in
> ureadkey returning complete bogus results.

Confirmed. The X server doesn't send the KeyRelease event because the focus 
is lost, so it's up to Allegro to make it so that the key is properly 
released.

This is currently done in src/x/xkeybd.c:_xwin_keydrv_focused(), which 
contains the following lines:

      for (i=0; i<KEY_MAX; i++) {
	 if (key[i])
	    _handle_key_release(i);
      }

But doing so is basically wrong, because _handle_key_release() is the 
top-level internal keyboard release handling function from src/keyboard.c 
and, in particular, it doesn't really handle the 'key_shifts' bitmask: it 
simply updates it according to what the low-level keyboard handling code 
tells it through '_key_shifts'.

Therefore we must go through the low-level keyboard handling code to 
release the keys (see for example the Windows port). Patch attached.

-- 
Eric Botcazou
diff -u /home/eric/cvs/allegro/src/x/xkeybd.c allegro/src/x/xkeybd.c
--- /home/eric/cvs/allegro/src/x/xkeybd.c	Sun Dec  2 15:59:54 2001
+++ allegro/src/x/xkeybd.c	Mon Jan 20 12:10:23 2003
@@ -134,18 +134,12 @@
  */
 static void _xwin_keydrv_focused(int focused, int state)
 {
-   int i, mask;
+   int mask;
 
    if (focused) {
       mask = KB_SCROLOCK_FLAG | KB_NUMLOCK_FLAG | KB_CAPSLOCK_FLAG;
       _key_shifts = (_key_shifts & ~mask) | (state & mask);
    }
-   else {
-      for (i=0; i<KEY_MAX; i++) {
-	 if (key[i])
-	    _handle_key_release(i);
-      }
-   }
 }
 
 
diff -u /home/eric/cvs/allegro/src/x/xwin.c allegro/src/x/xwin.c
--- /home/eric/cvs/allegro/src/x/xwin.c	Sat Jan 18 13:40:49 2003
+++ allegro/src/x/xwin.c	Mon Jan 20 12:12:15 2003
@@ -2018,8 +2018,15 @@
 	 /* Losing input focus.  */
 	 if (_xwin_keyboard_focused)
 	    (*_xwin_keyboard_focused)(FALSE, 0);
-	 for (kcode = 0; kcode < 256; kcode++)
-	    _xwin_keycode_pressed[kcode] = FALSE;
+	 for (kcode = 0; kcode < 256; kcode++) {
+	    if (_xwin_keycode_pressed[kcode]) {
+	       scode = _xwin.keycode_to_scancode[kcode];
+	       if ((scode > 0) && (_xwin_keyboard_interrupt != 0)) {
+		  (*_xwin_keyboard_interrupt)(0, scode);
+		  _xwin_keycode_pressed[kcode] = FALSE;
+	       }
+	    }
+	 }
 	 _switch_out();
 	 break;
       case ButtonPress:


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/