affection/src/Affection/Subsystems/AffectionKeyboard.hs

36 lines
960 B
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-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
:: (Participant ak KeyboardMessage us)
=> ak
-> [SDL.EventPayload]
-> Affection us [SDL.EventPayload]
consumeSDLKeyboardEvents ak eps = doConsume eps
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)