include/SDL_events.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 29 Dec 2011 05:13:55 -0500
changeset 6114 d166819bf2b3
parent 6091 61fa4f3238c5
child 6138 4c64952a58fb
permissions -rw-r--r--
Fixed bug 1336 - Added a timestamp on all SDL events

Gueniffey 2011-11-23 04:11:31 PST

The attached simple patch adds a timestamp to all SDL events. It is useful to
dismiss old events and add UI responsiveness (my application does some
extensive tasks that creates a delay in the event queue handling. With this
patch, I can deal only with the most recent events.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 /**
    23  *  \file SDL_events.h
    24  *  
    25  *  Include file for SDL event handling.
    26  */
    27 
    28 #ifndef _SDL_events_h
    29 #define _SDL_events_h
    30 
    31 #include "SDL_stdinc.h"
    32 #include "SDL_error.h"
    33 #include "SDL_video.h"
    34 #include "SDL_keyboard.h"
    35 #include "SDL_mouse.h"
    36 #include "SDL_joystick.h"
    37 #include "SDL_quit.h"
    38 #include "SDL_gesture.h"
    39 #include "SDL_touch.h"
    40 
    41 #include "begin_code.h"
    42 /* Set up for C function definitions, even when using C++ */
    43 #ifdef __cplusplus
    44 /* *INDENT-OFF* */
    45 extern "C" {
    46 /* *INDENT-ON* */
    47 #endif
    48 
    49 /* General keyboard/mouse state definitions */
    50 #define SDL_RELEASED	0
    51 #define SDL_PRESSED	1
    52 
    53 /**
    54  * \brief The types of events that can be delivered.
    55  */
    56 typedef enum
    57 {
    58     SDL_FIRSTEVENT     = 0,     /**< Unused (do not remove) */
    59 
    60     /* Application events */
    61     SDL_QUIT           = 0x100, /**< User-requested quit */
    62 
    63     /* Window events */
    64     SDL_WINDOWEVENT    = 0x200, /**< Window state change */
    65     SDL_SYSWMEVENT,             /**< System specific event */
    66 
    67     /* Keyboard events */
    68     SDL_KEYDOWN        = 0x300, /**< Key pressed */
    69     SDL_KEYUP,                  /**< Key released */
    70     SDL_TEXTEDITING,            /**< Keyboard text editing (composition) */
    71     SDL_TEXTINPUT,              /**< Keyboard text input */
    72 
    73     /* Mouse events */
    74     SDL_MOUSEMOTION    = 0x400, /**< Mouse moved */
    75     SDL_MOUSEBUTTONDOWN,        /**< Mouse button pressed */
    76     SDL_MOUSEBUTTONUP,          /**< Mouse button released */
    77     SDL_MOUSEWHEEL,             /**< Mouse wheel motion */
    78 
    79     /* Tablet or multiple mice input device events */
    80     SDL_INPUTMOTION    = 0x500, /**< Input moved */
    81     SDL_INPUTBUTTONDOWN,        /**< Input button pressed */
    82     SDL_INPUTBUTTONUP,          /**< Input button released */
    83     SDL_INPUTWHEEL,             /**< Input wheel motion */
    84     SDL_INPUTPROXIMITYIN,       /**< Input pen entered proximity */
    85     SDL_INPUTPROXIMITYOUT,      /**< Input pen left proximity */
    86 
    87     /* Joystick events */
    88     SDL_JOYAXISMOTION  = 0x600, /**< Joystick axis motion */
    89     SDL_JOYBALLMOTION,          /**< Joystick trackball motion */
    90     SDL_JOYHATMOTION,           /**< Joystick hat position change */
    91     SDL_JOYBUTTONDOWN,          /**< Joystick button pressed */
    92     SDL_JOYBUTTONUP,            /**< Joystick button released */
    93 
    94     /* Touch events */
    95     SDL_FINGERDOWN      = 0x700,
    96     SDL_FINGERUP,
    97     SDL_FINGERMOTION,
    98     SDL_TOUCHBUTTONDOWN,
    99     SDL_TOUCHBUTTONUP,    
   100 
   101     /* Gesture events */
   102     SDL_DOLLARGESTURE   = 0x800,
   103     SDL_DOLLARRECORD,
   104     SDL_MULTIGESTURE,
   105 
   106     /* Clipboard events */
   107     SDL_CLIPBOARDUPDATE = 0x900, /**< The clipboard changed */
   108 
   109     /* Drag and drop events */
   110     SDL_DROPFILE        = 0x1000, /**< The system requests a file open */
   111 
   112     /* Obsolete events */
   113     SDL_EVENT_COMPAT1 = 0x7000, /**< SDL 1.2 events for compatibility */
   114     SDL_EVENT_COMPAT2,
   115     SDL_EVENT_COMPAT3,
   116 
   117 
   118     /** Events ::SDL_USEREVENT through ::SDL_LASTEVENT are for your use,
   119      *  and should be allocated with SDL_RegisterEvents()
   120      */
   121     SDL_USEREVENT    = 0x8000,
   122 
   123     /**
   124      *  This last event is only for bounding internal arrays
   125      */
   126     SDL_LASTEVENT    = 0xFFFF
   127 } SDL_EventType;
   128 
   129 /**
   130  *  \brief Window state change event data (event.window.*)
   131  */
   132 typedef struct SDL_WindowEvent
   133 {
   134     Uint32 type;        /**< ::SDL_WINDOWEVENT */
   135     Uint32 timestamp;
   136     Uint32 windowID;    /**< The associated window */
   137     Uint8 event;        /**< ::SDL_WindowEventID */
   138     Uint8 padding1;
   139     Uint8 padding2;
   140     Uint8 padding3;
   141     int data1;          /**< event dependent data */
   142     int data2;          /**< event dependent data */
   143 } SDL_WindowEvent;
   144 
   145 /**
   146  *  \brief Keyboard button event structure (event.key.*)
   147  */
   148 typedef struct SDL_KeyboardEvent
   149 {
   150     Uint32 type;        /**< ::SDL_KEYDOWN or ::SDL_KEYUP */
   151     Uint32 timestamp;
   152     Uint32 windowID;    /**< The window with keyboard focus, if any */
   153     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   154     Uint8 repeat;       /**< Non-zero if this is a key repeat */
   155     Uint8 padding2;
   156     Uint8 padding3;
   157     SDL_Keysym keysym;  /**< The key that was pressed or released */
   158 } SDL_KeyboardEvent;
   159 
   160 #define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
   161 /**
   162  *  \brief Keyboard text editing event structure (event.edit.*)
   163  */
   164 typedef struct SDL_TextEditingEvent
   165 {
   166     Uint32 type;                                /**< ::SDL_TEXTEDITING */
   167     Uint32 timestamp;
   168     Uint32 windowID;                            /**< The window with keyboard focus, if any */
   169     char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE];  /**< The editing text */
   170     int start;                                  /**< The start cursor of selected editing text */
   171     int length;                                 /**< The length of selected editing text */
   172 } SDL_TextEditingEvent;
   173 
   174 
   175 #define SDL_TEXTINPUTEVENT_TEXT_SIZE (32)
   176 /**
   177  *  \brief Keyboard text input event structure (event.text.*)
   178  */
   179 typedef struct SDL_TextInputEvent
   180 {
   181     Uint32 type;                              /**< ::SDL_TEXTINPUT */
   182     Uint32 timestamp;
   183     Uint32 windowID;                          /**< The window with keyboard focus, if any */
   184     char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];  /**< The input text */
   185 } SDL_TextInputEvent;
   186 
   187 /**
   188  *  \brief Mouse motion event structure (event.motion.*)
   189  */
   190 typedef struct SDL_MouseMotionEvent
   191 {
   192     Uint32 type;        /**< ::SDL_MOUSEMOTION */
   193     Uint32 timestamp;
   194     Uint32 windowID;    /**< The window with mouse focus, if any */
   195     Uint8 state;        /**< The current button state */
   196     Uint8 padding1;
   197     Uint8 padding2;
   198     Uint8 padding3;
   199     int x;              /**< X coordinate, relative to window */
   200     int y;              /**< Y coordinate, relative to window */
   201     int xrel;           /**< The relative motion in the X direction */
   202     int yrel;           /**< The relative motion in the Y direction */
   203 } SDL_MouseMotionEvent;
   204 
   205 /**
   206  *  \brief Mouse button event structure (event.button.*)
   207  */
   208 typedef struct SDL_MouseButtonEvent
   209 {
   210     Uint32 type;        /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
   211     Uint32 timestamp;
   212     Uint32 windowID;    /**< The window with mouse focus, if any */
   213     Uint8 button;       /**< The mouse button index */
   214     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   215     Uint8 padding1;
   216     Uint8 padding2;
   217     int x;              /**< X coordinate, relative to window */
   218     int y;              /**< Y coordinate, relative to window */
   219 } SDL_MouseButtonEvent;
   220 
   221 /**
   222  *  \brief Mouse wheel event structure (event.wheel.*)
   223  */
   224 typedef struct SDL_MouseWheelEvent
   225 {
   226     Uint32 type;        /**< ::SDL_MOUSEWHEEL */
   227     Uint32 timestamp;
   228     Uint32 windowID;    /**< The window with mouse focus, if any */
   229     int x;              /**< The amount scrolled horizontally */
   230     int y;              /**< The amount scrolled vertically */
   231 } SDL_MouseWheelEvent;
   232 
   233 /**
   234  *  \brief Joystick axis motion event structure (event.jaxis.*)
   235  */
   236 typedef struct SDL_JoyAxisEvent
   237 {
   238     Uint32 type;        /**< ::SDL_JOYAXISMOTION */
   239     Uint32 timestamp;
   240     Uint8 which;        /**< The joystick device index */
   241     Uint8 axis;         /**< The joystick axis index */
   242     Uint8 padding1;
   243     Uint8 padding2;
   244     int value;          /**< The axis value (range: -32768 to 32767) */
   245 } SDL_JoyAxisEvent;
   246 
   247 /**
   248  *  \brief Joystick trackball motion event structure (event.jball.*)
   249  */
   250 typedef struct SDL_JoyBallEvent
   251 {
   252     Uint32 type;        /**< ::SDL_JOYBALLMOTION */
   253     Uint32 timestamp;
   254     Uint8 which;        /**< The joystick device index */
   255     Uint8 ball;         /**< The joystick trackball index */
   256     Uint8 padding1;
   257     Uint8 padding2;
   258     int xrel;           /**< The relative motion in the X direction */
   259     int yrel;           /**< The relative motion in the Y direction */
   260 } SDL_JoyBallEvent;
   261 
   262 /**
   263  *  \brief Joystick hat position change event structure (event.jhat.*)
   264  */
   265 typedef struct SDL_JoyHatEvent
   266 {
   267     Uint32 type;        /**< ::SDL_JOYHATMOTION */
   268     Uint32 timestamp;
   269     Uint8 which;        /**< The joystick device index */
   270     Uint8 hat;          /**< The joystick hat index */
   271     Uint8 value;        /**< The hat position value.
   272                          *   \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP
   273                          *   \sa ::SDL_HAT_LEFT ::SDL_HAT_CENTERED ::SDL_HAT_RIGHT
   274                          *   \sa ::SDL_HAT_LEFTDOWN ::SDL_HAT_DOWN ::SDL_HAT_RIGHTDOWN
   275                          *   
   276                          *   Note that zero means the POV is centered.
   277                          */
   278     Uint8 padding1;
   279 } SDL_JoyHatEvent;
   280 
   281 /**
   282  *  \brief Joystick button event structure (event.jbutton.*)
   283  */
   284 typedef struct SDL_JoyButtonEvent
   285 {
   286     Uint32 type;        /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
   287     Uint32 timestamp;
   288     Uint8 which;        /**< The joystick device index */
   289     Uint8 button;       /**< The joystick button index */
   290     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
   291     Uint8 padding1;
   292 } SDL_JoyButtonEvent;
   293 
   294 
   295 /**
   296  *  \brief Touch finger motion/finger event structure (event.tfinger.*)
   297  */
   298 typedef struct SDL_TouchFingerEvent
   299 {
   300     Uint32 type;        /**< ::SDL_FINGERMOTION OR 
   301 			   SDL_FINGERDOWN OR SDL_FINGERUP*/
   302     Uint32 timestamp;
   303     Uint32 windowID;    /**< The window with mouse focus, if any */
   304     SDL_TouchID touchId;        /**< The touch device id */
   305     SDL_FingerID fingerId;
   306     Uint8 state;        /**< The current button state */
   307     Uint8 padding1;
   308     Uint8 padding2;
   309     Uint8 padding3;
   310     Uint16 x;
   311     Uint16 y;
   312     Sint16 dx;
   313     Sint16 dy;
   314     Uint16 pressure;
   315 } SDL_TouchFingerEvent;
   316 
   317 
   318 /**
   319  *  \brief Touch finger motion/finger event structure (event.tbutton.*)
   320  */
   321 typedef struct SDL_TouchButtonEvent
   322 {
   323     Uint32 type;        /**< ::SDL_TOUCHBUTTONUP OR SDL_TOUCHBUTTONDOWN */
   324     Uint32 timestamp;
   325     Uint32 windowID;    /**< The window with mouse focus, if any */
   326     SDL_TouchID touchId;        /**< The touch device index */
   327     Uint8 state;        /**< The current button state */
   328     Uint8 button;        /**< The button changing state */
   329     Uint8 padding1;
   330     Uint8 padding2;
   331 } SDL_TouchButtonEvent;
   332 
   333 
   334 /**
   335  *  \brief Multiple Finger Gesture Event (event.mgesture.*)
   336  */
   337 typedef struct SDL_MultiGestureEvent
   338 {
   339     Uint32 type;        /**< ::SDL_MULTIGESTURE */
   340     Uint32 timestamp;
   341     Uint32 windowID;    /**< The window with mouse focus, if any */
   342     SDL_TouchID touchId;        /**< The touch device index */
   343     float dTheta;
   344     float dDist;
   345     float x;  //currently 0...1. Change to screen coords?
   346     float y;  
   347     Uint16 numFingers;
   348     Uint16 padding;
   349 } SDL_MultiGestureEvent;
   350 
   351 /* (event.dgesture.*) */
   352 typedef struct SDL_DollarGestureEvent
   353 {
   354     Uint32 type;        /**< ::SDL_DOLLARGESTURE */
   355     Uint32 timestamp;
   356     Uint32 windowID;    /**< The window with mouse focus, if any */
   357     SDL_TouchID touchId;        /**< The touch device index */
   358     SDL_GestureID gestureId;
   359     Uint32 numFingers;
   360     float error;
   361   /*
   362     //TODO: Enable to give location?
   363     float x;  //currently 0...1. Change to screen coords?
   364     float y;  
   365   */
   366 } SDL_DollarGestureEvent;
   367 
   368 
   369 /**
   370  *  \brief An event used to request a file open by the system (event.drop.*)
   371  *         This event is disabled by default, you can enable it with SDL_EventState()
   372  *  \note If you enable this event, you must free the filename in the event.
   373  */
   374 typedef struct SDL_DropEvent
   375 {
   376     Uint32 type;        /**< ::SDL_DROPFILE */
   377     Uint32 timestamp;
   378     char *file;         /**< The file name, which should be freed with SDL_free() */
   379 } SDL_DropEvent;
   380 
   381 
   382 /**
   383  *  \brief The "quit requested" event
   384  */
   385 typedef struct SDL_QuitEvent
   386 {
   387     Uint32 type;        /**< ::SDL_QUIT */
   388     Uint32 timestamp;
   389 } SDL_QuitEvent;
   390 
   391 
   392 /**
   393  *  \brief A user-defined event type (event.user.*)
   394  */
   395 typedef struct SDL_UserEvent
   396 {
   397     Uint32 type;        /**< ::SDL_USEREVENT through ::SDL_NUMEVENTS-1 */
   398     Uint32 timestamp;
   399     Uint32 windowID;    /**< The associated window if any */
   400     int code;           /**< User defined event code */
   401     void *data1;        /**< User defined data pointer */
   402     void *data2;        /**< User defined data pointer */
   403 } SDL_UserEvent;
   404 
   405 
   406 struct SDL_SysWMmsg;
   407 typedef struct SDL_SysWMmsg SDL_SysWMmsg;
   408 
   409 /**
   410  *  \brief A video driver dependent system event (event.syswm.*)
   411  *         This event is disabled by default, you can enable it with SDL_EventState()
   412  *
   413  *  \note If you want to use this event, you should include SDL_syswm.h.
   414  */
   415 typedef struct SDL_SysWMEvent
   416 {
   417     Uint32 type;        /**< ::SDL_SYSWMEVENT */
   418     Uint32 timestamp;
   419     SDL_SysWMmsg *msg;  /**< driver dependent data, defined in SDL_syswm.h */
   420 } SDL_SysWMEvent;
   421 
   422 #ifndef SDL_NO_COMPAT
   423 /**
   424  *  \addtogroup Compatibility 
   425  */
   426 /*@{*/
   427 
   428 /**
   429  *  \name Typedefs for backwards compatibility
   430  */
   431 /*@{*/
   432 typedef struct SDL_ActiveEvent
   433 {
   434     Uint32 type;
   435     Uint32 timestamp;
   436     Uint8 gain;
   437     Uint8 state;
   438 } SDL_ActiveEvent;
   439 
   440 typedef struct SDL_ResizeEvent
   441 {
   442     Uint32 type;
   443     Uint32 timestamp;
   444     int w;
   445     int h;
   446 } SDL_ResizeEvent;
   447 /*@}*/
   448 
   449 /*@}*//*Compatibility*/
   450 #endif
   451 
   452 /**
   453  *  \brief General event structure
   454  */
   455 typedef union SDL_Event
   456 {
   457     Uint32 type;                    /**< Event type, shared with all events */
   458     SDL_WindowEvent window;         /**< Window event data */
   459     SDL_KeyboardEvent key;          /**< Keyboard event data */
   460     SDL_TextEditingEvent edit;      /**< Text editing event data */
   461     SDL_TextInputEvent text;        /**< Text input event data */
   462     SDL_MouseMotionEvent motion;    /**< Mouse motion event data */
   463     SDL_MouseButtonEvent button;    /**< Mouse button event data */
   464     SDL_MouseWheelEvent wheel;      /**< Mouse wheel event data */
   465     SDL_JoyAxisEvent jaxis;         /**< Joystick axis event data */
   466     SDL_JoyBallEvent jball;         /**< Joystick ball event data */
   467     SDL_JoyHatEvent jhat;           /**< Joystick hat event data */
   468     SDL_JoyButtonEvent jbutton;     /**< Joystick button event data */
   469     SDL_QuitEvent quit;             /**< Quit request event data */
   470     SDL_UserEvent user;             /**< Custom event data */
   471     SDL_SysWMEvent syswm;           /**< System dependent window event data */
   472     SDL_TouchFingerEvent tfinger;   /**< Touch finger event data */
   473     SDL_TouchButtonEvent tbutton;   /**< Touch button event data */
   474     SDL_MultiGestureEvent mgesture; /**< Multi Finger Gesture data */
   475     SDL_DollarGestureEvent dgesture; /**< Multi Finger Gesture data */
   476     SDL_DropEvent drop;             /**< Drag and drop event data */
   477 
   478     /** Temporarily here for backwards compatibility */
   479     /*@{*/
   480 #ifndef SDL_NO_COMPAT
   481     SDL_ActiveEvent active;
   482     SDL_ResizeEvent resize;
   483 #endif
   484     /*@}*/
   485 } SDL_Event;
   486 
   487 
   488 /* Function prototypes */
   489 
   490 /**
   491  *  Pumps the event loop, gathering events from the input devices.
   492  *  
   493  *  This function updates the event queue and internal input device state.
   494  *  
   495  *  This should only be run in the thread that sets the video mode.
   496  */
   497 extern DECLSPEC void SDLCALL SDL_PumpEvents(void);
   498 
   499 /*@{*/
   500 typedef enum
   501 {
   502     SDL_ADDEVENT,
   503     SDL_PEEKEVENT,
   504     SDL_GETEVENT
   505 } SDL_eventaction;
   506 
   507 /**
   508  *  Checks the event queue for messages and optionally returns them.
   509  *  
   510  *  If \c action is ::SDL_ADDEVENT, up to \c numevents events will be added to
   511  *  the back of the event queue.
   512  *  
   513  *  If \c action is ::SDL_PEEKEVENT, up to \c numevents events at the front
   514  *  of the event queue, within the specified minimum and maximum type,
   515  *  will be returned and will not be removed from the queue.
   516  *  
   517  *  If \c action is ::SDL_GETEVENT, up to \c numevents events at the front 
   518  *  of the event queue, within the specified minimum and maximum type,
   519  *  will be returned and will be removed from the queue.
   520  *  
   521  *  \return The number of events actually stored, or -1 if there was an error.
   522  *  
   523  *  This function is thread-safe.
   524  */
   525 extern DECLSPEC int SDLCALL SDL_PeepEvents(SDL_Event * events, int numevents,
   526                                            SDL_eventaction action,
   527                                            Uint32 minType, Uint32 maxType);
   528 /*@}*/
   529 
   530 /**
   531  *  Checks to see if certain event types are in the event queue.
   532  */
   533 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvent(Uint32 type);
   534 extern DECLSPEC SDL_bool SDLCALL SDL_HasEvents(Uint32 minType, Uint32 maxType);
   535 
   536 /**
   537  *  This function clears events from the event queue
   538  */
   539 extern DECLSPEC void SDLCALL SDL_FlushEvent(Uint32 type);
   540 extern DECLSPEC void SDLCALL SDL_FlushEvents(Uint32 minType, Uint32 maxType);
   541 
   542 /**
   543  *  \brief Polls for currently pending events.
   544  *  
   545  *  \return 1 if there are any pending events, or 0 if there are none available.
   546  *  
   547  *  \param event If not NULL, the next event is removed from the queue and 
   548  *               stored in that area.
   549  */
   550 extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event * event);
   551 
   552 /**
   553  *  \brief Waits indefinitely for the next available event.
   554  *  
   555  *  \return 1, or 0 if there was an error while waiting for events.
   556  *   
   557  *  \param event If not NULL, the next event is removed from the queue and 
   558  *               stored in that area.
   559  */
   560 extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event);
   561 
   562 /**
   563  *  \brief Waits until the specified timeout (in milliseconds) for the next 
   564  *         available event.
   565  *  
   566  *  \return 1, or 0 if there was an error while waiting for events.
   567  *  
   568  *  \param event If not NULL, the next event is removed from the queue and 
   569  *               stored in that area.
   570  */
   571 extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event,
   572                                                  int timeout);
   573 
   574 /**
   575  *  \brief Add an event to the event queue.
   576  *  
   577  *  \return 1 on success, 0 if the event was filtered, or -1 if the event queue 
   578  *          was full or there was some other error.
   579  */
   580 extern DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event * event);
   581 
   582 typedef int (SDLCALL * SDL_EventFilter) (void *userdata, SDL_Event * event);
   583 
   584 /**
   585  *  Sets up a filter to process all events before they change internal state and
   586  *  are posted to the internal event queue.
   587  *  
   588  *  The filter is protypted as:
   589  *  \code
   590  *      int SDL_EventFilter(void *userdata, SDL_Event * event);
   591  *  \endcode
   592  *
   593  *  If the filter returns 1, then the event will be added to the internal queue.
   594  *  If it returns 0, then the event will be dropped from the queue, but the 
   595  *  internal state will still be updated.  This allows selective filtering of
   596  *  dynamically arriving events.
   597  *  
   598  *  \warning  Be very careful of what you do in the event filter function, as 
   599  *            it may run in a different thread!
   600  *  
   601  *  There is one caveat when dealing with the ::SDL_QUITEVENT event type.  The
   602  *  event filter is only called when the window manager desires to close the
   603  *  application window.  If the event filter returns 1, then the window will
   604  *  be closed, otherwise the window will remain open if possible.
   605  *
   606  *  If the quit event is generated by an interrupt signal, it will bypass the
   607  *  internal queue and be delivered to the application at the next event poll.
   608  */
   609 extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
   610                                                 void *userdata);
   611 
   612 /**
   613  *  Return the current event filter - can be used to "chain" filters.
   614  *  If there is no event filter set, this function returns SDL_FALSE.
   615  */
   616 extern DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter * filter,
   617                                                     void **userdata);
   618 
   619 /**
   620  *  Add a function which is called when an event is added to the queue.
   621  */
   622 extern DECLSPEC void SDLCALL SDL_AddEventWatch(SDL_EventFilter filter,
   623                                                void *userdata);
   624 
   625 /**
   626  *  Remove an event watch function added with SDL_AddEventWatch()
   627  */
   628 extern DECLSPEC void SDLCALL SDL_DelEventWatch(SDL_EventFilter filter,
   629                                                void *userdata);
   630 
   631 /**
   632  *  Run the filter function on the current event queue, removing any
   633  *  events for which the filter returns 0.
   634  */
   635 extern DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter,
   636                                               void *userdata);
   637 
   638 /*@{*/
   639 #define SDL_QUERY	-1
   640 #define SDL_IGNORE	 0
   641 #define SDL_DISABLE	 0
   642 #define SDL_ENABLE	 1
   643 
   644 /**
   645  *  This function allows you to set the state of processing certain events.
   646  *   - If \c state is set to ::SDL_IGNORE, that event will be automatically 
   647  *     dropped from the event queue and will not event be filtered.
   648  *   - If \c state is set to ::SDL_ENABLE, that event will be processed 
   649  *     normally.
   650  *   - If \c state is set to ::SDL_QUERY, SDL_EventState() will return the 
   651  *     current processing state of the specified event.
   652  */
   653 extern DECLSPEC Uint8 SDLCALL SDL_EventState(Uint32 type, int state);
   654 /*@}*/
   655 #define SDL_GetEventState(type) SDL_EventState(type, SDL_QUERY)
   656 
   657 /**
   658  *  This function allocates a set of user-defined events, and returns
   659  *  the beginning event number for that set of events.
   660  *
   661  *  If there aren't enough user-defined events left, this function
   662  *  returns (Uint32)-1
   663  */
   664 extern DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
   665 
   666 /* Ends C function definitions when using C++ */
   667 #ifdef __cplusplus
   668 /* *INDENT-OFF* */
   669 }
   670 /* *INDENT-ON* */
   671 #endif
   672 #include "close_code.h"
   673 
   674 #endif /* _SDL_events_h */
   675 
   676 /* vi: set ts=4 sw=4 expandtab: */