hi,

thanks for your detailed reply :)

since i will be getting the same event twice, can i create a separate event
buffer for each window as well as a raw input event buffer. so in the main
event loop i wait for an event on the raw event buffer and then when i get
an event i check if it is a window event. if it is then i check each
window's event buffer and handle events accordingly otherwise i handle the
keystrokes. this approach does not need to track window id's at the cost of
more event buffers. i am basically going to use the raw event buffer to
"wake up" my main event loop. am i correct ? what do you guys think ?

cheers,

alex

-----Original Message-----
From: Denis Oliver Kropp [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 19, 2003 2:51 AM
To: Alex Song
Cc: '[EMAIL PROTECTED]'
Subject: [directfb-dev] Re: DFBInputEvent DFBWindowEvent


Quoting Alex Song ([EMAIL PROTECTED]):
> hi,
> 
> i have a question regarding how event buffers should be used efficiently.
i
> have an application which has lots of windows and the windows would only
> need to accept mouse events and not keyboard events. but i would also like
> to process keyboard events, but not on a per window basis but globally. so
i
> want to process window events separately and keyboard events globally. how
> should i approach this ? is it possible to do this using one "thread" ? do
i
> just setup separate event buffers and check each one in one big event loop
> or is there a better way ?

You create an input event buffer using IDirectFB::CreateInputEventBuffer()
setting "global" to DFB_TRUE or DFB_FALSE depending on whether you want to
get "raw" input events always or only if one of your windows is focused.

With that you get DFBInputEvents from all devices matching the caps.

Additionally you attach each created window to that buffer. You will get
DFBWindowEvents and DFBInputEvents then.

With the following code you can handle all events the way you like:

---------------------------

static void HandleInputEvent( DFBInputEvent *event )
{
     /*
      * NOTE: Global events are only received if the input event buffer has
      *       been created with global = DFB_TRUE.
      */
     if (event->flags & DIEF_GLOBAL) {
          printf("Got global input event (none of my windows are
focused).\n");
     }
     else {
          printf("Got input event while one of my windows has the
focus.\n");
     }
}

static void HandleWindowEvent( DFBWindowEvent *event )
{
     printf("Got a window event belonging to the window with the id
'%d'.\n",
            event->window_id);
}

static void EventLoop()
{
     while (buffer->WaitForEvent( buffer ) == DFB_OK) {
          DFBEvent event;

          while (buffer->GetEvent( buffer, &event ) == DFB_OK) {
               switch (event.clazz) {
                    case DFEC_INPUT:
                         HandleInputEvent( &event.input );
                         break;
                    case DFEC_WINDOW:
                         HandleWindowEvent( &event.window );
                         break;
                    default:
                         break;
               }
          }
     }
}

---------------------------

No guarantee that it compiles ;)

The buffer could be created by:

  dfb->CreateInputEventBuffer( dfb, DICAPS_KEYS, DFB_TRUE, &buffer );

The windows attached by:

  window->AttachEventBuffer( window, buffer );

You need the IDs of your windows (maybe within a hash table, but a short
list
may be faster). You get the ID by:

  window->GetID( window, &window_id );

Of course, you will receive key events twice (once via DFBWindowEvent and
once via DFBInputEvent). The DFBWindowEvent will be the first one arriving.

-- 
Best regards,
  Denis Oliver Kropp

.------------------------------------------.
| DirectFB - Hardware accelerated graphics |
| http://www.directfb.org/                 |
"------------------------------------------"

                            Convergence GmbH


-- 
Info:  To unsubscribe send a mail to [EMAIL PROTECTED] with 
"unsubscribe directfb-dev" as subject.


-- 
Info:  To unsubscribe send a mail to [EMAIL PROTECTED] with 
"unsubscribe directfb-dev" as subject.

Reply via email to