SDL_EventState and SDL_ALLEVENTS

Hello,

I’m going to be verbose to describe a very simple problem I meant to
report mounths ago.

SDL_events.h presently features the following definitions:

| […]
| /* Event enumerations /
| enum { SDL_NOEVENT = 0, /
Unused (do not remove) /
| SDL_ACTIVEEVENT, /
Application loses/gains visibility /
| SDL_KEYDOWN, /
Keys pressed /
| SDL_KEYUP, /
Keys released /
| […]
| };
|
| /
Predefined event masks /
| #define SDL_EVENTMASK(X) (1<<(X))
| enum {
| SDL_ACTIVEEVENTMASK = SDL_EVENTMASK(SDL_ACTIVEEVENT),
| SDL_KEYDOWNMASK = SDL_EVENTMASK(SDL_KEYDOWN),
| SDL_KEYUPMASK = SDL_EVENTMASK(SDL_KEYUP),
| […]
| };
| #define SDL_ALLEVENTS 0xFFFFFFFF
| […]
| /

| This function allows you to set the state of processing certain events.
| If ‘state’ is set to SDL_IGNORE, that event will be automatically dropped
| from the event queue and will not event be filtered.
| If ‘state’ is set to SDL_ENABLE, that event will be processed normally.
| If ‘state’ is set to SDL_QUERY, SDL_EventState() will return the
| current processing state of the specified event.
| */
| extern DECLSPEC Uint8 SDL_EventState(Uint8 type, int state);
| […]

So far, I have been using SDL_EventState as follow:

| SDL_EventState (SDL_ALLEVENTS, SDL_IGNORE);
| SDL_EventState (SDL_KEYDOWN, SDL_ENABLE);
| SDL_EventState (SDL_KEYUP, SDL_ENABLE);
| SDL_EventState (SDL_QUIT, SDL_ENABLE);

This works, but is wrong for (at least) two reasons:

  • semantically SDL_ALLEVENTS is an even mask, not an event-type
  • SDL_ALLEVENTS is a 32bit value, here used for a 8bit argument
    (thus it generates a compiler warning).

I don’t remember if I have seen the practice of passing SDL_ALLEVENTS
to SDL_EventState() in some documentation, or some other code; most likely
I have seen this in SDL_EventState itself:

| Uint8 SDL_EventState (Uint8 type, int state)
| {
| SDL_Event bitbucket;
| Uint8 current_state;
|
| /* If SDL_ALLEVENTS was specified… */
| if ( type == 0xFF ) {

SDL_EventState appears to promote the use of SDL_ALLEVENTS for type,
althought it’s too big.

So what I’m wishing here, is a clean way to rewrite
SDL_EventState (SDL_ALLEVENTS, SDL_IGNORE);

My present possibilities include
SDL_EventState ((Uint8) SDL_ALLEVENTS, SDL_IGNORE);
and
SDL_EventState (0xFF, SDL_IGNORE);
which are both ugly workarounds to something that ought to
be fixed in SDL. Maybe a new #define for 0xFF can do ?

Or maybe I’m too much finicky here…–
Alexandre Duret-Lutz