Skip to content

Commit

Permalink
Filter SDL1 active events (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
clementgallet committed Jul 1, 2020
1 parent 31b21b2 commit 8052a88
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 64 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
### Changed
### Fixed

* Filter SDL1 active events (#351)

## [1.4.0] - 2020-06-19
### Added

Expand Down
60 changes: 0 additions & 60 deletions src/library/SDLEventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,66 +309,6 @@ void SDLEventQueue::delWatch(SDL_EventFilter filter, void* userdata)
watches.erase(it);
}

bool SDLEventQueue::isBannedEvent(SDL_Event *event)
{
switch(event->type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEWHEEL:
case SDL_JOYAXISMOTION:
case SDL_JOYBALLMOTION:
case SDL_JOYHATMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_JOYDEVICEADDED:
case SDL_JOYDEVICEREMOVED:
case SDL_CONTROLLERAXISMOTION:
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
case SDL_CONTROLLERDEVICEREMAPPED:
return true;
case SDL_WINDOWEVENT:
switch (event->window.event) {
case SDL_WINDOWEVENT_FOCUS_GAINED:
case SDL_WINDOWEVENT_FOCUS_LOST:
case SDL_WINDOWEVENT_SHOWN:
case SDL_WINDOWEVENT_EXPOSED:
case SDL_WINDOWEVENT_ENTER:
case SDL_WINDOWEVENT_LEAVE:
case SDL_WINDOWEVENT_TAKE_FOCUS:
return true;
default:
return false;
}
default:
return false;
}
}

bool SDLEventQueue::isBannedEvent(SDL1::SDL_Event *event)
{
switch(event->type) {
case SDL1::SDL_KEYDOWN:
case SDL1::SDL_KEYUP:
case SDL1::SDL_MOUSEMOTION:
case SDL1::SDL_MOUSEBUTTONDOWN:
case SDL1::SDL_MOUSEBUTTONUP:
case SDL1::SDL_JOYAXISMOTION:
case SDL1::SDL_JOYBALLMOTION:
case SDL1::SDL_JOYHATMOTION:
case SDL1::SDL_JOYBUTTONDOWN:
case SDL1::SDL_JOYBUTTONUP:
return true;
default:
return false;
}
}

bool SDLEventQueue::waitForEmpty()
{
int attempts = 0;
Expand Down
4 changes: 0 additions & 4 deletions src/library/SDLEventQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ class SDLEventQueue

/* Was the queue emptied? Used for asynchronous events */
bool emptied;

/* We don't want some events to be pushed by the game */
bool isBannedEvent(SDL_Event *event);
bool isBannedEvent(SDL1::SDL_Event *event);
};

extern SDLEventQueue sdlEventQueue;
Expand Down
5 changes: 5 additions & 0 deletions src/library/sdlevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static bool isBannedEvent(SDL_Event *event)
static bool isBannedEvent(SDL1::SDL_Event *event)
{
switch(event->type) {
case SDL1::SDL_ACTIVEEVENT:
case SDL1::SDL_KEYDOWN:
case SDL1::SDL_KEYUP:
case SDL1::SDL_MOUSEMOTION:
Expand Down Expand Up @@ -393,6 +394,10 @@ void pushNativeSDLEvents(void)
int SDLver = get_sdlversion();
if (SDLver == 1) {
SDL1::SDL_Event* ev1 = reinterpret_cast<SDL1::SDL_Event*>(event);

if (isBannedEvent(ev1))
return 0;

int ret = sdlEventQueue.insert(ev1);

if (ev1->type == SDL1::SDL_QUIT) {
Expand Down
6 changes: 6 additions & 0 deletions src/library/sdlwindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ static int swapInterval = 0;
* our pixel access routine */
ScreenCapture::init();

SDL1::SDL_Event event;
event.type = SDL1::SDL_ACTIVEEVENT;
event.active.gain = 1;
event.active.state = 0x7;
sdlEventQueue.insert(&event);

return surf;
}

Expand Down

0 comments on commit 8052a88

Please sign in to comment.