Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 12 of 12
Originally Posted by SamoaWarrrior Think I got my answer. No callbacks, I'll provide an abstraction of the event loop. The user code would like: Code: while(1) { myEvent = MyGetEvent( ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Linux Enthusiast
    Join Date
    Jun 2005
    Location
    The Hot Humid South
    Posts
    602

    Quote Originally Posted by SamoaWarrrior
    Think I got my answer. No callbacks, I'll provide an abstraction of the event loop.
    The user code would like:
    Code:
    while(1)
    {
       myEvent = MyGetEvent( );   // Uses XCheckNextEvent or something
       switch( myEvent )
       {
           case MOUSE_LBUTTON:
                   // stuff
           case KEYPRESS:
                   
       }
    }
    But isn't that the same as just using the regular X event loop? I see no advantage this provides over just using what posted here before. In your code you wouldn't be able to use XCheckWindowEvent (XCheckNextEvent doesn't exist, I assume you meant this one) because XCheckWindowEvent pulls a particular event, at which point you really wouldn't need the switch to check which event it is since you're only pulling a particular event type from a window.

    That's a good idea, but once I write a while(1) loop in my function, the user code from that point ahead won't be executed, right?
    You can still have the programmer write his own event handler, just use function pointers like you were thinking about doing before. If I'm not mistaken this is how most, if not all, C-based widget sets do it. This way you can also have your library handling events in a default manner and the programmer using the library can override the function pointer with his own.

    Good luck!
    "Today you are freer than ever to do what you want, provided you can pay for it!" --Bad Religion

  2. #12
    Just Joined!
    Join Date
    Apr 2007
    Posts
    8

    Post

    Quote Originally Posted by bidi
    You can still have the programmer write his own event handler, just use function pointers like you were thinking about doing before. If I'm not mistaken this is how most, if not all, C-based widget sets do it. This way you can also have your library handling events in a default manner and the programmer using the library can override the function pointer with his own.

    Good luck!
    I think you are thinking of something like this:

    The user code:
    Code:
    main( )
    {
      // Init windows and do drawing stuff, etc.
       .
       .
       // Register callbacks
       .
       MyLibraryHandleEvents( );  // This necessarily must be the last statement
    }
    My library:

    Code:
    void MyLibraryHandleEvents( )
    {
        XEvent event;
        while(1)
        {
              case ButtonPress:
                   // Call the registered callback, if any, else the default handler
        }
    }
    I guess this can be done, but is it Ok to expect users to call MyLibraryHandleEvents( ) this way?

Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •