Setting up multiple event filters

Does SDL2 provide support for multiple event filters?

Take the following source for example:===============================

#include “SDL.h”

int event_filter(void* unused, SDL_Event* event)
{
if(event->type == SDL_MOUSEBUTTONDOWN)
printf(“Mouse event filter 1\n”);

return 1;

}

int event_filter2(void* unused, SDL_Event* event)
{
if(event->type == SDL_MOUSEBUTTONDOWN)
printf(“Mouse event filter 2\n”);

return 1;

}

int main(int argc, char** argv)
{
SDL_Window* window;
SDL_Event event;

SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow("",0,0,640,480,0);

SDL_SetEventFilter(event_filter,NULL);
SDL_SetEventFilter(event_filter2,NULL);

while( 1 ) {
    SDL_PollEvent(&event);

    if (event.type == SDL_QUIT) {
        SDL_Quit();
        return 0;
    }
}

}

==================================

It is quite bad, I know, but what it does is set two different
event filters (event_filter and event_filter2). However,
when executing the code, when I press the mouse, I only
get output from the event_filter2 which is set last.

Which practically means that currently SDL2 does not support
more than one event filter at a time. Is that true ?? Or at least,
is there any way to add more than one filter??

Thanks in advance,
Aggelos Kolaitis


C is the God’s Programming Language

You only get 1 event filter, which allows you to block events, but you get
multiple event watchers which get to look at them as they go by.

Check out SDL_AddEventWatch() and SDL_DelEventWatch()On Fri, Jul 26, 2013 at 11:26 AM, neoaggelos wrote:

**
Does SDL2 provide support for multiple event filters?

Take the following source for example:

===============================

#include “SDL.h”

int event_filter(void* unused, SDL_Event* event)
{
if(event->type == SDL_MOUSEBUTTONDOWN)
printf(“Mouse event filter 1\n”);

return 1;
}

int event_filter2(void* unused, SDL_Event* event)
{
if(event->type == SDL_MOUSEBUTTONDOWN)
printf(“Mouse event filter 2\n”);

return 1;
}

int main(int argc, char** argv)
{
SDL_Window* window;
SDL_Event event;

SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow("",0,0,640,480,0);

SDL_SetEventFilter(event_filter,NULL);
SDL_SetEventFilter(event_filter2,NULL);

while( 1 ) {
SDL_PollEvent(&event);

if (event.type == SDL_QUIT) {
SDL_Quit();
return 0;
}
}
}

==================================

It is quite bad, I know, but what it does is set two different
event filters (event_filter and event_filter2). However,
when executing the code, when I press the mouse, I only
get output from the event_filter2 which is set last.

Which practically means that currently SDL2 does not support
more than one event filter at a time. Is that true ?? Or at least,
is there any way to add more than one filter??

Thanks in advance,
Aggelos Kolaitis


C is the God’s Programming Language


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org