Re: [AD] X11 key repeat fix

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


On Tue, 2003-12-09 at 11:25, Eric Botcazou wrote:
> Yes.  Remove the superfluous TABs too and the patch will be fine.
> 

Oops - and I thought vim automatically removes trailing whitespace.
Well, at least I can cope with Allegro's weird
8-space-tabs-but-3-space-indention now, after asking the author of
cream-vim to add some support for it :)

Oh, and revised patch is attached.

-- 
Elias Pschernig <elias@xxxxxxxxxx>
Index: src/x/xwin.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xwin.c,v
retrieving revision 1.55
diff -u -r1.55 xwin.c
--- src/x/xwin.c	29 Oct 2003 12:37:57 -0000	1.55
+++ src/x/xwin.c	9 Dec 2003 10:49:07 -0000
@@ -143,6 +143,7 @@
 static Colormap _xdga_colormap[2];
 #endif
 
+#define MAX_EVENTS   5
 #define MOUSE_WARP_DELAY   200
 
 static char _xwin_driver_desc[256] = EMPTY_STRING;
@@ -2207,8 +2208,8 @@
  */
 static void _xwin_private_handle_input(void)
 {
-   int i, events;
-   static XEvent event[5];
+   int i, events, events_queued;
+   static XEvent event[MAX_EVENTS + 1]; /* +1 for possible extra event, see below. */
 
    if (_xwin.display == 0)
       return;
@@ -2233,21 +2234,43 @@
    _xwin_private_flush_buffers();
 
    /* How much events are available in the queue.  */
-   events = XEventsQueued(_xwin.display, QueuedAlready);
+   events = events_queued = XEventsQueued(_xwin.display, QueuedAlready);
    if (events <= 0)
       return;
 
    /* Limit amount of events we read at once.  */
-   if (events > 5)
-      events = 5;
+   if (events > MAX_EVENTS)
+      events = MAX_EVENTS;
 
    /* Read pending events.  */
    for (i = 0; i < events; i++)
       XNextEvent(_xwin.display, &event[i]);
 
+   /* Can't have a KeyRelease as last event, since it might be only half
+    * of a key repeat pair. Also see comment below.
+    */
+   if (events_queued > events && event[i - 1].type == KeyRelease) {
+      XNextEvent(_xwin.display, &event[i]);
+      events++;
+   }
+
    /* Process all events.  */
-   for (i = 0; i < events; i++)
+   for (i = 0; i < events; i++) {
+
+      /* Hack to make Allegro's key[] array work despite of key repeat.
+       * If a KeyRelease is sent at the same time as a KeyPress following
+       * it with the same keycode, we ignore the release event.
+       */
+      if (event[i].type == KeyRelease && i + 1 < events) {
+	 if (event[i + 1].type == KeyPress) {
+	    if (event[i].xkey.keycode == event[i + 1].xkey.keycode &&
+	       event[i].xkey.time == event[i + 1].xkey.time)
+	       continue;
+	 }
+      }
+
       _xwin_private_process_event(&event[i]);
+   }
 }
 
 void _xwin_handle_input(void)


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