From f48587bda4dea13920a96dda06b735be484614a9 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 14 Dec 2024 18:28:19 +0530 Subject: Add left click on space + minor fixes --- src/Chelleport/AppShell.hs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/Chelleport/AppShell.hs') diff --git a/src/Chelleport/AppShell.hs b/src/Chelleport/AppShell.hs index 545df13..6a0195d 100644 --- a/src/Chelleport/AppShell.hs +++ b/src/Chelleport/AppShell.hs @@ -1,10 +1,12 @@ module Chelleport.AppShell where -import Chelleport.Context (DrawContext (ctxRenderer, ctxWindow), createContext) +import Chelleport.Context (DrawContext (ctxRenderer, ctxWindow, ctxX11Display), createContext) import Control.Monad (foldM, unless) +import qualified Graphics.X11 as X11 import SDL (($=)) import qualified SDL import qualified SDL.Font as TTF +import System.Exit (exitSuccess) data Action act = SysQuit | AppAction act @@ -25,8 +27,7 @@ setupAppShell initState update eventHandler draw = do state <- initState ctx appLoop ctx (state, SysState {sysExit = False}) - SDL.destroyRenderer $ ctxRenderer ctx - SDL.destroyWindow $ ctxWindow ctx + shutdownApp ctx where appLoop drawCtx (state, sysState) = do events <- SDL.pollEvents @@ -43,3 +44,17 @@ setupAppShell initState update eventHandler draw = do updateState _drawCtx (state, sysState) SysQuit = pure (state, sysState {sysExit = True}) updateState drawCtx (state, sysState) (AppAction action) = (,sysState) <$> update state drawCtx action + +hideWindow :: DrawContext -> IO () +hideWindow ctx = SDL.hideWindow (ctxWindow ctx) + +closeWindow :: DrawContext -> IO () +closeWindow ctx = do + SDL.destroyRenderer $ ctxRenderer ctx + SDL.destroyWindow $ ctxWindow ctx + +shutdownApp :: DrawContext -> IO () +shutdownApp ctx = do + closeWindow ctx + X11.closeDisplay $ ctxX11Display ctx + exitSuccess -- cgit v1.3.1