From c51dff6a4e5bd21491bb0c085cb08f35275332a0 Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Wed, 23 Aug 2017 21:16:30 +0100 Subject: Workaround bug where events are received incorrectly For some reason SDL passes events to us that occurred before we gained focus, and passes them *after* the focus gained event. Due to behavioural quirks from such events, whenever we gain focus we have to clear the event queue. It's hacky, but works without any visible side effects. --- src/imv.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/imv.c b/src/imv.c index 63addcf..afefce7 100644 --- a/src/imv.c +++ b/src/imv.c @@ -752,6 +752,17 @@ static void handle_event(struct imv *imv, SDL_Event *event) SDL_ShowCursor(SDL_ENABLE); break; case SDL_WINDOWEVENT: + /* For some reason SDL passes events to us that occurred before we + * gained focus, and passes them *after* the focus gained event. + * Due to behavioural quirks from such events, whenever we gain focus + * we have to clear the event queue. It's hacky, but works without + * any visible side effects. + */ + if(event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { + SDL_PumpEvents(); + SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); + } + imv_viewport_update(imv->view, imv->texture); break; } -- cgit v1.2.3