From bfa31b53a27034f47902b966e6bf06d9684471df Mon Sep 17 00:00:00 2001 From: Ollie Charles Date: Sun, 24 Jan 2021 16:49:38 +0000 Subject: [PATCH] Fix event handling in demo --- Main.hs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Main.hs b/Main.hs index cc24404..987618e 100644 --- a/Main.hs +++ b/Main.hs @@ -30,7 +30,7 @@ main = do loop :: Window -> IORef Bool -> IO () loop w checked = do - ev <- pollEventWithImGui + quit <- pollEvents openGL2NewFrame sdl2NewFrame w @@ -85,11 +85,21 @@ loop w checked = do glSwapWindow w - case ev of - Nothing -> loop w checked - Just Event{ eventPayload } -> case eventPayload of - QuitEvent -> return () - _ -> loop w checked + if quit then return () else loop w checked + + where + + pollEvents = do + ev <- pollEventWithImGui + + case ev of + Nothing -> return False + Just Event{ eventPayload } -> do + let isQuit = case eventPayload of + QuitEvent -> True + _ -> False + + (isQuit ||) <$> pollEvents whenTrue :: IO () -> Bool -> IO ()