[client] app: move SDL window event handing out of main.c

This commit is contained in:
Geoffrey McRae 2021-01-17 13:41:59 +11:00
parent 31c42e3676
commit 570abeda52
2 changed files with 32 additions and 51 deletions

View File

@ -65,6 +65,10 @@ static bool sdlEventFilter(SDL_Event * event)
{ {
switch(event->type) switch(event->type)
{ {
case SDL_QUIT:
app_handleCloseEvent();
return true;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
// stop motion events during the warp out of the window // stop motion events during the warp out of the window
if (sdl.exiting) if (sdl.exiting)
@ -75,19 +79,42 @@ static bool sdlEventFilter(SDL_Event * event)
app_handleMouseGrabbed(event->motion.xrel, event->motion.yrel); app_handleMouseGrabbed(event->motion.xrel, event->motion.yrel);
else else
app_handleMouseNormal(event->motion.xrel, event->motion.yrel); app_handleMouseNormal(event->motion.xrel, event->motion.yrel);
break; return true;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
{
switch(event->window.event) switch(event->window.event)
{ {
/* after leave re-enable warp and cursor processing */ case SDL_WINDOWEVENT_ENTER:
app_handleWindowEnter();
return true;
case SDL_WINDOWEVENT_LEAVE: case SDL_WINDOWEVENT_LEAVE:
sdl.exiting = false; sdl.exiting = false;
return false; app_handleWindowLeave();
return true;
case SDL_WINDOWEVENT_FOCUS_GAINED:
app_handleFocusEvent(true);
return true;
case SDL_WINDOWEVENT_FOCUS_LOST:
app_handleFocusEvent(false);
return true;
case SDL_WINDOWEVENT_SIZE_CHANGED:
case SDL_WINDOWEVENT_RESIZED:
app_handleResizeEvent(event->window.data1, event->window.data2);
return true;
case SDL_WINDOWEVENT_MOVED:
app_updateWindowPos(event->window.data1, event->window.data2);
return true;
case SDL_WINDOWEVENT_CLOSE:
app_handleCloseEvent();
return true;
} }
break; break;
}
} }
return false; return false;

View File

@ -1338,52 +1338,6 @@ int eventFilter(void * userdata, SDL_Event * event)
switch(event->type) switch(event->type)
{ {
case SDL_QUIT:
{
if (!params.ignoreQuit)
{
DEBUG_INFO("Quit event received, exiting...");
g_state.state = APP_STATE_SHUTDOWN;
}
return 0;
}
case SDL_WINDOWEVENT:
{
switch(event->window.event)
{
case SDL_WINDOWEVENT_ENTER:
app_handleWindowEnter();
break;
case SDL_WINDOWEVENT_LEAVE:
app_handleWindowLeave();
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
app_handleFocusEvent(true);
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
app_handleFocusEvent(false);
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
case SDL_WINDOWEVENT_RESIZED:
app_handleResizeEvent(event->window.data1, event->window.data2);
break;
case SDL_WINDOWEVENT_MOVED:
app_updateWindowPos(event->window.data1, event->window.data2);
break;
case SDL_WINDOWEVENT_CLOSE:
app_handleCloseEvent();
break;
}
return 0;
}
case SDL_KEYDOWN: case SDL_KEYDOWN:
{ {
SDL_Scancode sc = event->key.keysym.scancode; SDL_Scancode sc = event->key.keysym.scancode;