pituicat/src/Affection/Subsystems/AffectionKeyboard.hs

38 lines
1 KiB
Haskell
Raw Normal View History

2017-12-12 12:10:55 +00:00
{-# LANGUAGE MultiParamTypeClasses #-}
2017-12-15 16:48:12 +00:00
{-# LANGUAGE FlexibleContexts #-}
2017-12-27 16:33:31 +00:00
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
2017-12-12 12:10:55 +00:00
module Affection.Subsystems.AffectionKeyboard where
import Affection.Types
2017-12-13 14:19:53 +00:00
import Affection.Util
2017-12-13 14:53:51 +00:00
import Affection.MessageBus
import Affection.Subsystems.Class
2017-12-12 12:10:55 +00:00
2017-12-13 03:37:16 +00:00
import Control.Concurrent.STM as STM
2017-12-13 14:53:51 +00:00
import Control.Monad.IO.Class (liftIO)
2017-12-12 12:10:55 +00:00
import qualified SDL
2017-12-15 16:48:12 +00:00
consumeSDLKeyboardEvents
2017-12-27 16:33:31 +00:00
:: forall ak us. (Participant ak us, Mesg ak us ~ KeyboardMessage)
2017-12-15 16:48:12 +00:00
=> ak
-> [SDL.EventPayload]
-> Affection us [SDL.EventPayload]
2017-12-15 16:58:55 +00:00
consumeSDLKeyboardEvents ak = doConsume
2017-12-15 16:48:12 +00:00
where
doConsume [] = return []
doConsume (e:es) = do
ts <- getElapsedTime
case e of
SDL.KeyboardEvent dat -> do
partEmit ak (MsgKeyboardEvent
ts
(SDL.keyboardEventWindow dat)
(SDL.keyboardEventKeyMotion dat)
(SDL.keyboardEventRepeat dat)
(SDL.keyboardEventKeysym dat)
)
doConsume es
_ -> fmap (e :) (doConsume es)