On Thu, Nov 14, 2002 at 09:37:52PM +0100, Denis Oliver Kropp wrote:
> 
> As DirectFB input drivers have an own thread we could just do a
> select or poll with a timeout to deliver the release event.

Of course.  I was thinking about trying to use a timer and wondering
if DirectFB had any sort of generic timers (like gtk/glib does).  Of
course a select/poll would work very nicely in this situation as the
whole thread basically spins around a read loop.

Find attached a patch which accomplishes this.  I chose 70ms as the
timeout after which the release is sent only due to the time between
repeated keys on my remote seems to bound upwardly at about 60ms.

Interestingly, I implemented a userspace version (in the keypress
handler of my GTK app) of my original patch (to suppress events 2-9 in
a stream of repeat events) in any case.  It works much better than
trying to correlate keypress events with keyrelease events.

In case anyone is interested, here is the function you can attach
to the GTK key_press_event of you app to provide a keyboard-like
repeat functionality.  The first event of a held down key is followed
by a gap and then followed by a stream of key events.

gboolean
on_key_press_event                     (GtkWidget       *widget,
                                        GdkEventKey     *event,
                                        gpointer         user_data)
{

  static guint32 last_time;
  static guint repeat_count = 0;

  /* first determine if this is a key repeat */
  if (event->time - last_time < 90)
      repeat_count++;
  else
      repeat_count = 0;

  last_time = event->time;

  if (repeat_count > 0 && repeat_count < 5 || mplaying)
    // discard it
    return TRUE;

  return FALSE;
}

The only drawback is that you have to hook that to the signal handler
for all of your toplevel widgets.

b.

-- 
Brian J. Murrell
Index: inputdrivers/lirc/lirc.c
===================================================================
RCS file: /cvs/directfb/DirectFB/inputdrivers/lirc/lirc.c,v
retrieving revision 1.15
diff -u -r1.15 lirc.c
--- inputdrivers/lirc/lirc.c    25 Sep 2002 11:18:43 -0000      1.15
+++ inputdrivers/lirc/lirc.c    15 Nov 2002 17:56:17 -0000
@@ -124,6 +124,9 @@
      int            readlen;
      char           buf[128];
      DFBInputEvent  evt;
+     fd_set         rfds;
+     struct         timeval tv;
+     int            retval;
 
      memset( &evt, 0, sizeof(DFBInputEvent) );
 
@@ -140,6 +143,16 @@
                evt.flags = DIEF_KEYSYMBOL;
                dfb_input_dispatch( data->device, &evt );
 
+               FD_ZERO(&rfds);
+               FD_SET(data->fd, &rfds);
+               tv.tv_sec = 0;
+               tv.tv_usec = 70000;
+
+               retval = select(data->fd + 1, &rfds, NULL, NULL, &tv);
+               if (retval)
+                    continue;
+
+               /* timed out, send the key release */
                evt.type = DIET_KEYRELEASE;
                evt.flags = DIEF_KEYSYMBOL;
                dfb_input_dispatch( data->device, &evt );

Attachment: msg01069/pgp00000.pgp
Description: PGP signature

Reply via email to