    {-# LINE 1 "Graphics/UI/SDL/Events.hsc" #-}

    {-# LINE 5 "Graphics/UI/SDL/Events.hsc" #-}
    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.UI.SDL.Events
    -- Copyright   :  (c) David Himmelstrup 2005
    -- License     :  BSD-like
    --
    -- Maintainer  :  lemmih@gmail.com
    -- Stability   :  provisional
    -- Portability :  portable
    --
    -----------------------------------------------------------------------------
    module Graphics.UI.SDL.Events
        ( Event (..)
        , SDLEvent (..)
        , UserEventID (..)
        , MouseButton (..)
        , Focus(..)
        , toSafePtr
        , tryFromSafePtr
        , fromSafePtr
        , typeOfSafePtr
        , enableKeyRepeat
        , enableUnicode
        , queryUnicodeState
        , getKeyName
        , getMouseState
        , getRelativeMouseState
        , getModState
        , setModState
        , tryPushEvent
        , pushEvent
        , pollEvent
        , waitEvent
        , waitEventBlocking
        , pumpEvents
        , enableEvent
        , queryEventState
        , getAppState
        ) where

    import Foreign (Int16, Word8, Word16, Word32, Ptr,
                   Storable(poke, sizeOf, alignment, peekByteOff, pokeByteOff, peek),
                   toBool, new, alloca)
    import Foreign.C (peekCString, CString, CInt)
    import System.IO.Unsafe (unsafePerformIO)
    import Data.Bits (Bits((.&.), shiftL))
    import Control.Concurrent (threadDelay)
    import Prelude hiding (Enum(..))
    import qualified Prelude (Enum(..))

    import Foreign.StablePtr (newStablePtr,castStablePtrToPtr,castPtrToStablePtr,deRefStablePtr)
    import Data.Typeable (Typeable,typeOf,TypeRep)

    import Graphics.UI.SDL.Keysym (SDLKey, Modifier, Keysym)
    import Graphics.UI.SDL.Utilities (Enum(..), intToBool, toBitmask, fromBitmask, fromCInt)
    import Graphics.UI.SDL.General (unwrapBool, failWithError)
    import Graphics.UI.SDL.Video (Toggle(..), fromToggle)

    -- |Low level event structure keeping a one-to-one relation with the C event structure.
    data SDLEvent = SDLNoEvent
                  | SDLActiveEvent
                  | SDLKeyDown
                  | SDLKeyUp
                  | SDLMouseMotion
                  | SDLMouseButtonDown
                  | SDLMouseButtonUp
                  | SDLJoyAxisMotion
                  | SDLJoyBallMotion
                  | SDLJoyHatMotion
                  | SDLJoyButtonDown
                  | SDLJoyButtonUp
                  | SDLQuit
                  | SDLSysWMEvent
                  | SDLVideoResize
                  | SDLVideoExpose
                  | SDLUserEvent Word8
                  | SDLNumEvents
        deriving (SDLEvent -> SDLEvent -> Bool
    (SDLEvent -> SDLEvent -> Bool)
    -> (SDLEvent -> SDLEvent -> Bool) -> Eq SDLEvent
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: SDLEvent -> SDLEvent -> Bool
    == :: SDLEvent -> SDLEvent -> Bool
    $c/= :: SDLEvent -> SDLEvent -> Bool
    /= :: SDLEvent -> SDLEvent -> Bool
    Eq, Eq SDLEvent
    Eq SDLEvent
    -> (SDLEvent -> SDLEvent -> Ordering)
    -> (SDLEvent -> SDLEvent -> Bool)
    -> (SDLEvent -> SDLEvent -> Bool)
    -> (SDLEvent -> SDLEvent -> Bool)
    -> (SDLEvent -> SDLEvent -> Bool)
    -> (SDLEvent -> SDLEvent -> SDLEvent)
    -> (SDLEvent -> SDLEvent -> SDLEvent)
    -> Ord SDLEvent
    SDLEvent -> SDLEvent -> Bool
    SDLEvent -> SDLEvent -> Ordering
    SDLEvent -> SDLEvent -> SDLEvent
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: SDLEvent -> SDLEvent -> Ordering
    compare :: SDLEvent -> SDLEvent -> Ordering
    $c< :: SDLEvent -> SDLEvent -> Bool
    < :: SDLEvent -> SDLEvent -> Bool
    $c<= :: SDLEvent -> SDLEvent -> Bool
    <= :: SDLEvent -> SDLEvent -> Bool
    $c> :: SDLEvent -> SDLEvent -> Bool
    > :: SDLEvent -> SDLEvent -> Bool
    $c>= :: SDLEvent -> SDLEvent -> Bool
    >= :: SDLEvent -> SDLEvent -> Bool
    $cmax :: SDLEvent -> SDLEvent -> SDLEvent
    max :: SDLEvent -> SDLEvent -> SDLEvent
    $cmin :: SDLEvent -> SDLEvent -> SDLEvent
    min :: SDLEvent -> SDLEvent -> SDLEvent
    Ord, Int -> SDLEvent -> ShowS
    [SDLEvent] -> ShowS
    SDLEvent -> String
    (Int -> SDLEvent -> ShowS)
    -> (SDLEvent -> String) -> ([SDLEvent] -> ShowS) -> Show SDLEvent
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> SDLEvent -> ShowS
    showsPrec :: Int -> SDLEvent -> ShowS
    $cshow :: SDLEvent -> String
    show :: SDLEvent -> String
    $cshowList :: [SDLEvent] -> ShowS
    showList :: [SDLEvent] -> ShowS
    Show)
    instance Bounded SDLEvent where
        minBound :: SDLEvent
    minBound = SDLEvent
    SDLNoEvent
        maxBound :: SDLEvent
    maxBound = SDLEvent
    SDLNumEvents

    fromSDLEvent :: SDLEvent -> Word8
    fromSDLEvent :: SDLEvent -> Word8
    fromSDLEvent SDLEvent
    SDLNoEvent = Word8
    0
    {-# LINE 89 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLActiveEvent = 1
    {-# LINE 90 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLKeyDown = 2
    {-# LINE 91 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLKeyUp = 3
    {-# LINE 92 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLMouseMotion = 4
    {-# LINE 93 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLMouseButtonDown = 5
    {-# LINE 94 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLMouseButtonUp = 6
    {-# LINE 95 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLJoyAxisMotion = 7
    {-# LINE 96 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLJoyBallMotion = 8
    {-# LINE 97 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLJoyHatMotion = 9
    {-# LINE 98 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLJoyButtonDown = 10
    {-# LINE 99 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLJoyButtonUp = 11
    {-# LINE 100 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLQuit = 12
    {-# LINE 101 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLSysWMEvent = 13
    {-# LINE 102 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLVideoResize = 16
    {-# LINE 103 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLVideoExpose = 17
    {-# LINE 104 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent (SDLUserEvent n) = 24 + n
    {-# LINE 105 "Graphics/UI/SDL/Events.hsc" #-}
    fromSDLEvent SDLNumEvents = 32
    {-# LINE 106 "Graphics/UI/SDL/Events.hsc" #-}

    toSDLEvent :: Word8 -> SDLEvent
    toSDLEvent :: Word8 -> SDLEvent
    toSDLEvent Word8
    0 = SDLEvent
    SDLNoEvent
    {-# LINE 109 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 1 = SDLActiveEvent
    {-# LINE 110 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 2 = SDLKeyDown
    {-# LINE 111 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 3 = SDLKeyUp
    {-# LINE 112 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 4 = SDLMouseMotion
    {-# LINE 113 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 5 = SDLMouseButtonDown
    {-# LINE 114 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 6 = SDLMouseButtonUp
    {-# LINE 115 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 7 = SDLJoyAxisMotion
    {-# LINE 116 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 8 = SDLJoyBallMotion
    {-# LINE 117 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 9 = SDLJoyHatMotion
    {-# LINE 118 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 10 = SDLJoyButtonDown
    {-# LINE 119 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 11 = SDLJoyButtonUp
    {-# LINE 120 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 12 = SDLQuit
    {-# LINE 121 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 13 = SDLSysWMEvent
    {-# LINE 122 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 16 = SDLVideoResize
    {-# LINE 123 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent 17 = SDLVideoExpose
    {-# LINE 124 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent n
        | n >= 24 &&
    {-# LINE 126 "Graphics/UI/SDL/Events.hsc" #-}
          n <  32 = SDLUserEvent (n - 24)
    {-# LINE 127 "Graphics/UI/SDL/Events.hsc" #-}
    toSDLEvent _ = error "Graphics.UI.SDL.Events.toSDLEvent: bad argument"

    -- |High level event structure.
    data Event
        = NoEvent
        | GotFocus [Focus]
        | LostFocus [Focus]
        | KeyDown !Keysym
        | KeyUp !Keysym
        | MouseMotion !Word16 !Word16 !Int16 !Int16
        | MouseButtonDown !Word16
                          !Word16
                          !MouseButton
        | MouseButtonUp !Word16
                        !Word16
                        !MouseButton
        | JoyAxisMotion !Word8 !Word8 !Int16
          -- ^ device index, axis index, axis value.
        | JoyBallMotion !Word8 !Word8 !Int16 !Int16
          -- ^ device index, trackball index, relative motion.
        | JoyHatMotion !Word8 !Word8 !Word8
          -- ^ device index, hat index, hat position.
        | JoyButtonDown !Word8 !Word8
          -- ^ device index, button index.
        | JoyButtonUp !Word8 !Word8
          -- ^ device index, button index.
        | VideoResize !Int !Int
          -- ^ When @Resizable@ is passed as a flag to 'Graphics.UI.SDL.Video.setVideoMode' the user is
          --   allowed to resize the applications window. When the window is resized
          --   an @VideoResize@ is reported, with the new window width and height values.
          --   When an @VideoResize@ is recieved the window should be resized to the
          --   new dimensions using 'Graphics.UI.SDL.Video.setVideoMode'.
        | VideoExpose
          -- ^ A @VideoExpose@ event is triggered when the screen has been modified
          --   outside of the application, usually by the window manager and needs to be redrawn.
        | Quit
        | User !UserEventID !Int !(Ptr ()) !(Ptr ())
        | Unknown
          deriving (Int -> Event -> ShowS
    [Event] -> ShowS
    Event -> String
    (Int -> Event -> ShowS)
    -> (Event -> String) -> ([Event] -> ShowS) -> Show Event
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Event -> ShowS
    showsPrec :: Int -> Event -> ShowS
    $cshow :: Event -> String
    show :: Event -> String
    $cshowList :: [Event] -> ShowS
    showList :: [Event] -> ShowS
    Show,Event -> Event -> Bool
    (Event -> Event -> Bool) -> (Event -> Event -> Bool) -> Eq Event
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Event -> Event -> Bool
    == :: Event -> Event -> Bool
    $c/= :: Event -> Event -> Bool
    /= :: Event -> Event -> Bool
    Eq)

    data MouseButton
        = ButtonLeft
        | ButtonMiddle
        | ButtonRight
        | ButtonWheelUp
        | ButtonWheelDown
        | ButtonUnknown !Word8
          deriving (Int -> MouseButton -> ShowS
    [MouseButton] -> ShowS
    MouseButton -> String
    (Int -> MouseButton -> ShowS)
    -> (MouseButton -> String)
    -> ([MouseButton] -> ShowS)
    -> Show MouseButton
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> MouseButton -> ShowS
    showsPrec :: Int -> MouseButton -> ShowS
    $cshow :: MouseButton -> String
    show :: MouseButton -> String
    $cshowList :: [MouseButton] -> ShowS
    showList :: [MouseButton] -> ShowS
    Show,MouseButton -> MouseButton -> Bool
    (MouseButton -> MouseButton -> Bool)
    -> (MouseButton -> MouseButton -> Bool) -> Eq MouseButton
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: MouseButton -> MouseButton -> Bool
    == :: MouseButton -> MouseButton -> Bool
    $c/= :: MouseButton -> MouseButton -> Bool
    /= :: MouseButton -> MouseButton -> Bool
    Eq,Eq MouseButton
    Eq MouseButton
    -> (MouseButton -> MouseButton -> Ordering)
    -> (MouseButton -> MouseButton -> Bool)
    -> (MouseButton -> MouseButton -> Bool)
    -> (MouseButton -> MouseButton -> Bool)
    -> (MouseButton -> MouseButton -> Bool)
    -> (MouseButton -> MouseButton -> MouseButton)
    -> (MouseButton -> MouseButton -> MouseButton)
    -> Ord MouseButton
    MouseButton -> MouseButton -> Bool
    MouseButton -> MouseButton -> Ordering
    MouseButton -> MouseButton -> MouseButton
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: MouseButton -> MouseButton -> Ordering
    compare :: MouseButton -> MouseButton -> Ordering
    $c< :: MouseButton -> MouseButton -> Bool
    < :: MouseButton -> MouseButton -> Bool
    $c<= :: MouseButton -> MouseButton -> Bool
    <= :: MouseButton -> MouseButton -> Bool
    $c> :: MouseButton -> MouseButton -> Bool
    > :: MouseButton -> MouseButton -> Bool
    $c>= :: MouseButton -> MouseButton -> Bool
    >= :: MouseButton -> MouseButton -> Bool
    $cmax :: MouseButton -> MouseButton -> MouseButton
    max :: MouseButton -> MouseButton -> MouseButton
    $cmin :: MouseButton -> MouseButton -> MouseButton
    min :: MouseButton -> MouseButton -> MouseButton
    Ord)

    instance Enum MouseButton Word8 where
        toEnum :: Word8 -> MouseButton
    toEnum Word8
    1 = MouseButton
    ButtonLeft
    {-# LINE 178 "Graphics/UI/SDL/Events.hsc" #-}
        toEnum 2 = ButtonMiddle
    {-# LINE 179 "Graphics/UI/SDL/Events.hsc" #-}
        toEnum 3 = ButtonRight
    {-# LINE 180 "Graphics/UI/SDL/Events.hsc" #-}
        toEnum 4 = ButtonWheelUp
    {-# LINE 181 "Graphics/UI/SDL/Events.hsc" #-}
        toEnum 5 = ButtonWheelDown
    {-# LINE 182 "Graphics/UI/SDL/Events.hsc" #-}
        toEnum n = ButtonUnknown (fromIntegral n)
        fromEnum :: MouseButton -> Word8
    fromEnum MouseButton
    ButtonLeft = Word8
    1
    {-# LINE 184 "Graphics/UI/SDL/Events.hsc" #-}
        fromEnum ButtonMiddle = 2
    {-# LINE 185 "Graphics/UI/SDL/Events.hsc" #-}
        fromEnum ButtonRight = 3
    {-# LINE 186 "Graphics/UI/SDL/Events.hsc" #-}
        fromEnum ButtonWheelUp = 4
    {-# LINE 187 "Graphics/UI/SDL/Events.hsc" #-}
        fromEnum ButtonWheelDown = 5
    {-# LINE 188 "Graphics/UI/SDL/Events.hsc" #-}
        fromEnum (ButtonUnknown n) = fromIntegral n
        succ :: MouseButton -> MouseButton
    succ = Word8 -> MouseButton
    forall a b. Enum a b => b -> a
    toEnum (Word8 -> MouseButton)
    -> (MouseButton -> Word8) -> MouseButton -> MouseButton
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Word8 -> Word8 -> Word8
    forall a. Num a => a -> a -> a
    +Word8
    1) (Word8 -> Word8) -> (MouseButton -> Word8) -> MouseButton -> Word8
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MouseButton -> Word8
    forall a b. Enum a b => a -> b
    fromEnum
        pred :: MouseButton -> MouseButton
    pred = Word8 -> MouseButton
    forall a b. Enum a b => b -> a
    toEnum (Word8 -> MouseButton)
    -> (MouseButton -> Word8) -> MouseButton -> MouseButton
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Word8 -> Word8 -> Word8
    forall a. Num a => a -> a -> a
    subtract Word8
    1) (Word8 -> Word8) -> (MouseButton -> Word8) -> MouseButton -> Word8
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MouseButton -> Word8
    forall a b. Enum a b => a -> b
    fromEnum
        enumFromTo :: MouseButton -> MouseButton -> [MouseButton]
    enumFromTo = MouseButton -> MouseButton -> [MouseButton]
    forall a b. (Enum a b, Ord a) => a -> a -> [a]
    defEnumFromTo

    mouseButtonMask :: MouseButton -> Word8
    mouseButtonMask :: MouseButton -> Word8
    mouseButtonMask MouseButton
    ButtonLeft = Word8
    1
    {-# LINE 195 "Graphics/UI/SDL/Events.hsc" #-}
    mouseButtonMask ButtonMiddle = 2
    {-# LINE 196 "Graphics/UI/SDL/Events.hsc" #-}
    mouseButtonMask ButtonRight = 4
    {-# LINE 197 "Graphics/UI/SDL/Events.hsc" #-}
    mouseButtonMask ButtonWheelUp = 8
    {-# LINE 198 "Graphics/UI/SDL/Events.hsc" #-}
    mouseButtonMask ButtonWheelDown = 16
    {-# LINE 199 "Graphics/UI/SDL/Events.hsc" #-}
    mouseButtonMask (ButtonUnknown n) = 1 `shiftL` (fromIntegral n-1)

    allButtons :: [MouseButton]
    allButtons :: [MouseButton]
    allButtons = [MouseButton
    ButtonLeft
                 ,MouseButton
    ButtonMiddle
                 ,MouseButton
    ButtonRight
                 ,MouseButton
    ButtonWheelUp
                 ,MouseButton
    ButtonWheelDown
                 ]

    defEnumFromTo :: (Enum a b, Ord a) => a -> a -> [a]
    defEnumFromTo :: forall a b. (Enum a b, Ord a) => a -> a -> [a]
    defEnumFromTo a
    x a
    y | a
    x a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    > a
    y     = []
                      | a
    x a -> a -> Bool
    forall a. Eq a => a -> a -> Bool
    == a
    y    = [a
    y]
                      | Bool
    otherwise = a
    x a -> [a] -> [a]
    forall a. a -> [a] -> [a]
    : a -> a -> [a]
    forall a b. (Enum a b, Ord a) => a -> a -> [a]
    defEnumFromTo (a -> a
    forall a b. Enum a b => a -> a
    succ a
    x) a
    y

    data Focus
        = MouseFocus
        | InputFocus
        | ApplicationFocus
          deriving (Int -> Focus -> ShowS
    [Focus] -> ShowS
    Focus -> String
    (Int -> Focus -> ShowS)
    -> (Focus -> String) -> ([Focus] -> ShowS) -> Show Focus
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Focus -> ShowS
    showsPrec :: Int -> Focus -> ShowS
    $cshow :: Focus -> String
    show :: Focus -> String
    $cshowList :: [Focus] -> ShowS
    showList :: [Focus] -> ShowS
    Show,Focus -> Focus -> Bool
    (Focus -> Focus -> Bool) -> (Focus -> Focus -> Bool) -> Eq Focus
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Focus -> Focus -> Bool
    == :: Focus -> Focus -> Bool
    $c/= :: Focus -> Focus -> Bool
    /= :: Focus -> Focus -> Bool
    Eq,Eq Focus
    Eq Focus
    -> (Focus -> Focus -> Ordering)
    -> (Focus -> Focus -> Bool)
    -> (Focus -> Focus -> Bool)
    -> (Focus -> Focus -> Bool)
    -> (Focus -> Focus -> Bool)
    -> (Focus -> Focus -> Focus)
    -> (Focus -> Focus -> Focus)
    -> Ord Focus
    Focus -> Focus -> Bool
    Focus -> Focus -> Ordering
    Focus -> Focus -> Focus
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Focus -> Focus -> Ordering
    compare :: Focus -> Focus -> Ordering
    $c< :: Focus -> Focus -> Bool
    < :: Focus -> Focus -> Bool
    $c<= :: Focus -> Focus -> Bool
    <= :: Focus -> Focus -> Bool
    $c> :: Focus -> Focus -> Bool
    > :: Focus -> Focus -> Bool
    $c>= :: Focus -> Focus -> Bool
    >= :: Focus -> Focus -> Bool
    $cmax :: Focus -> Focus -> Focus
    max :: Focus -> Focus -> Focus
    $cmin :: Focus -> Focus -> Focus
    min :: Focus -> Focus -> Focus
    Ord)

    instance Bounded Focus where
        minBound :: Focus
    minBound = Focus
    MouseFocus
        maxBound :: Focus
    maxBound = Focus
    ApplicationFocus

    instance Enum Focus Word8 where
        fromEnum :: Focus -> Word8
    fromEnum Focus
    MouseFocus = Word8
    1
    {-# LINE 227 "Graphics/UI/SDL/Events.hsc" #-}
        fromEnum InputFocus = 2
    {-# LINE 228 "Graphics/UI/SDL/Events.hsc" #-}
        fromEnum ApplicationFocus = 4
    {-# LINE 229 "Graphics/UI/SDL/Events.hsc" #-}
        toEnum 1 = MouseFocus
    {-# LINE 230 "Graphics/UI/SDL/Events.hsc" #-}
        toEnum 2 = InputFocus
    {-# LINE 231 "Graphics/UI/SDL/Events.hsc" #-}
        toEnum 4 = ApplicationFocus
    {-# LINE 232 "Graphics/UI/SDL/Events.hsc" #-}
        toEnum _ = error "Graphics.UI.SDL.Events.toEnum: bad argument"
        succ :: Focus -> Focus
    succ Focus
    MouseFocus = Focus
    InputFocus
        succ Focus
    InputFocus = Focus
    ApplicationFocus
        succ Focus
    _ = String -> Focus
    forall a. HasCallStack => String -> a
    error String
    "Graphics.UI.SDL.Events.succ: bad argument"
        pred :: Focus -> Focus
    pred Focus
    InputFocus = Focus
    MouseFocus
        pred Focus
    ApplicationFocus = Focus
    InputFocus
        pred Focus
    _ = String -> Focus
    forall a. HasCallStack => String -> a
    error String
    "Graphics.UI.SDL.Events.pred: bad argument"
        enumFromTo :: Focus -> Focus -> [Focus]
    enumFromTo Focus
    x Focus
    y | Focus
    x Focus -> Focus -> Bool
    forall a. Ord a => a -> a -> Bool
    > Focus
    y = []
                       | Focus
    x Focus -> Focus -> Bool
    forall a. Eq a => a -> a -> Bool
    == Focus
    y = [Focus
    y]
                       | Bool
    True = Focus
    x Focus -> [Focus] -> [Focus]
    forall a. a -> [a] -> [a]
    : Focus -> Focus -> [Focus]
    forall a b. Enum a b => a -> a -> [a]
    enumFromTo (Focus -> Focus
    forall a b. Enum a b => a -> a
    succ Focus
    x) Focus
    y

    -- |Typed user events ranging from 0 to 7
    data UserEventID
        = UID0 | UID1 | UID2 | UID3 | UID4 | UID5 | UID6 | UID7
          deriving (Int -> UserEventID -> ShowS
    [UserEventID] -> ShowS
    UserEventID -> String
    (Int -> UserEventID -> ShowS)
    -> (UserEventID -> String)
    -> ([UserEventID] -> ShowS)
    -> Show UserEventID
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> UserEventID -> ShowS
    showsPrec :: Int -> UserEventID -> ShowS
    $cshow :: UserEventID -> String
    show :: UserEventID -> String
    $cshowList :: [UserEventID] -> ShowS
    showList :: [UserEventID] -> ShowS
    Show,UserEventID -> UserEventID -> Bool
    (UserEventID -> UserEventID -> Bool)
    -> (UserEventID -> UserEventID -> Bool) -> Eq UserEventID
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: UserEventID -> UserEventID -> Bool
    == :: UserEventID -> UserEventID -> Bool
    $c/= :: UserEventID -> UserEventID -> Bool
    /= :: UserEventID -> UserEventID -> Bool
    Eq,Int -> UserEventID
    UserEventID -> Int
    UserEventID -> [UserEventID]
    UserEventID -> UserEventID
    UserEventID -> UserEventID -> [UserEventID]
    UserEventID -> UserEventID -> UserEventID -> [UserEventID]
    (UserEventID -> UserEventID)
    -> (UserEventID -> UserEventID)
    -> (Int -> UserEventID)
    -> (UserEventID -> Int)
    -> (UserEventID -> [UserEventID])
    -> (UserEventID -> UserEventID -> [UserEventID])
    -> (UserEventID -> UserEventID -> [UserEventID])
    -> (UserEventID -> UserEventID -> UserEventID -> [UserEventID])
    -> Enum UserEventID
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: UserEventID -> UserEventID
    succ :: UserEventID -> UserEventID
    $cpred :: UserEventID -> UserEventID
    pred :: UserEventID -> UserEventID
    $ctoEnum :: Int -> UserEventID
    toEnum :: Int -> UserEventID
    $cfromEnum :: UserEventID -> Int
    fromEnum :: UserEventID -> Int
    $cenumFrom :: UserEventID -> [UserEventID]
    enumFrom :: UserEventID -> [UserEventID]
    $cenumFromThen :: UserEventID -> UserEventID -> [UserEventID]
    enumFromThen :: UserEventID -> UserEventID -> [UserEventID]
    $cenumFromTo :: UserEventID -> UserEventID -> [UserEventID]
    enumFromTo :: UserEventID -> UserEventID -> [UserEventID]
    $cenumFromThenTo :: UserEventID -> UserEventID -> UserEventID -> [UserEventID]
    enumFromThenTo :: UserEventID -> UserEventID -> UserEventID -> [UserEventID]
    Prelude.Enum)

    -- |A safe pointer keeps the type of the object it was created from
    --  and checks it when it's deconstructed.
    type SafePtr = Ptr ()

    -- |Constructs a safe pointer from an arbitrary value.
    toSafePtr :: (Typeable a) => a -> IO SafePtr
    toSafePtr :: forall a. Typeable a => a -> IO (Ptr ())
    toSafePtr a
    val
        = do StablePtr (TypeRep, a)
    stablePtr <- (TypeRep, a) -> IO (StablePtr (TypeRep, a))
    forall a. a -> IO (StablePtr a)
    newStablePtr (a -> TypeRep
    forall a. Typeable a => a -> TypeRep
    typeOf a
    val,a
    val)
             Ptr () -> IO (Ptr ())
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (StablePtr (TypeRep, a) -> Ptr ()
    forall a. StablePtr a -> Ptr ()
    castStablePtrToPtr StablePtr (TypeRep, a)
    stablePtr)

    -- |Return the type of the object the safe pointer was created from.
    typeOfSafePtr :: SafePtr -> IO TypeRep
    typeOfSafePtr :: Ptr () -> IO TypeRep
    typeOfSafePtr Ptr ()
    ptr
        = ((TypeRep, Any) -> TypeRep) -> IO (TypeRep, Any) -> IO TypeRep
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (TypeRep, Any) -> TypeRep
    forall a b. (a, b) -> a
    fst (StablePtr (TypeRep, Any) -> IO (TypeRep, Any)
    forall a. StablePtr a -> IO a
    deRefStablePtr (Ptr () -> StablePtr (TypeRep, Any)
    forall a. Ptr () -> StablePtr a
    castPtrToStablePtr Ptr ()
    ptr))

    -- |Get object from a safe pointer. @Nothing@ on type mismatch.
    tryFromSafePtr :: (Typeable a) => SafePtr -> IO (Maybe a)
    tryFromSafePtr :: forall a. Typeable a => Ptr () -> IO (Maybe a)
    tryFromSafePtr Ptr ()
    ptr
        = do (TypeRep
    ty,a
    val) <- StablePtr (TypeRep, a) -> IO (TypeRep, a)
    forall a. StablePtr a -> IO a
    deRefStablePtr (Ptr () -> StablePtr (TypeRep, a)
    forall a. Ptr () -> StablePtr a
    castPtrToStablePtr Ptr ()
    ptr)
             if TypeRep
    ty TypeRep -> TypeRep -> Bool
    forall a. Eq a => a -> a -> Bool
    == a -> TypeRep
    forall a. Typeable a => a -> TypeRep
    typeOf a
    val
                then Maybe a -> IO (Maybe a)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (a -> Maybe a
    forall a. a -> Maybe a
    Just a
    val)
                else Maybe a -> IO (Maybe a)
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe a
    forall a. Maybe a
    Nothing

    -- |Get object from a safe pointer. Throws an exception on type mismatch.
    fromSafePtr :: (Typeable a) => SafePtr -> IO a
    fromSafePtr :: forall a. Typeable a => Ptr () -> IO a
    fromSafePtr Ptr ()
    ptr
        = do Maybe a
    ret <- Ptr () -> IO (Maybe a)
    forall a. Typeable a => Ptr () -> IO (Maybe a)
    tryFromSafePtr Ptr ()
    ptr
             case Maybe a
    ret of
               Maybe a
    Nothing -> String -> IO a
    forall a. HasCallStack => String -> a
    error String
    "Graphics.UI.SDL.Events.fromSafePtr: invalid type."
               Just a
    a  -> a -> IO a
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return a
    a

    toEventType :: UserEventID -> Word8
    toEventType :: UserEventID -> Word8
    toEventType UserEventID
    eid = Int -> Word8
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (UserEventID -> Int
    forall a. Enum a => a -> Int
    Prelude.fromEnum UserEventID
    eid)

    fromEventType :: Word8 -> UserEventID
    fromEventType :: Word8 -> UserEventID
    fromEventType Word8
    etype = Int -> UserEventID
    forall a. Enum a => Int -> a
    Prelude.toEnum (Word8 -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Word8
    etype)

    peekActiveEvent :: Ptr Event -> IO Event
    peekActiveEvent :: Ptr Event -> IO Event
    peekActiveEvent Ptr Event
    ptr
        = do Bool
    gain <- (Word8 -> Bool) -> IO Word8 -> IO Bool
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Word8 -> Bool
    forall a. (Eq a, Num a) => a -> Bool
    toBool (((\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    1) Ptr Event
    ptr) :: IO Word8)
    {-# LINE 288 "Graphics/UI/SDL/Events.hsc" #-}
             Word8
    state <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr :: IO Word8
    {-# LINE 289 "Graphics/UI/SDL/Events.hsc" #-}
             Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Event -> IO Event) -> Event -> IO Event
    forall a b. (a -> b) -> a -> b
    $! (if Bool
    gain then [Focus] -> Event
    GotFocus else [Focus] -> Event
    LostFocus) (Word8 -> [Focus]
    forall a b. (Bounded a, Enum a b, Bits b, Num b) => b -> [a]
    fromBitmask Word8
    state)

    peekKey :: (Keysym -> Event) -> Ptr Event -> IO Event
    peekKey :: (Keysym -> Event) -> Ptr Event -> IO Event
    peekKey Keysym -> Event
    mkEvent Ptr Event
    ptr
        = do Keysym
    keysym <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Keysym
    forall b. Ptr b -> Int -> IO Keysym
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr
    {-# LINE 294 "Graphics/UI/SDL/Events.hsc" #-}
             Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Event -> IO Event) -> Event -> IO Event
    forall a b. (a -> b) -> a -> b
    $! Keysym -> Event
    mkEvent Keysym
    keysym

    peekMouseMotion :: Ptr Event -> IO Event
    peekMouseMotion :: Ptr Event -> IO Event
    peekMouseMotion Ptr Event
    ptr
        = do Word16
    x <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word16
    forall b. Ptr b -> Int -> IO Word16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr
    {-# LINE 299 "Graphics/UI/SDL/Events.hsc" #-}
             Word16
    y <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word16
    forall b. Ptr b -> Int -> IO Word16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    6) Ptr Event
    ptr
    {-# LINE 300 "Graphics/UI/SDL/Events.hsc" #-}
             Int16
    xrel <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Int16
    forall b. Ptr b -> Int -> IO Int16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    8) Ptr Event
    ptr
    {-# LINE 301 "Graphics/UI/SDL/Events.hsc" #-}
             Int16
    yrel <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Int16
    forall b. Ptr b -> Int -> IO Int16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    10) Ptr Event
    ptr
    {-# LINE 302 "Graphics/UI/SDL/Events.hsc" #-}
             Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Event -> IO Event) -> Event -> IO Event
    forall a b. (a -> b) -> a -> b
    $! Word16 -> Word16 -> Int16 -> Int16 -> Event
    MouseMotion Word16
    x Word16
    y Int16
    xrel Int16
    yrel

    peekMouse :: (Word16 -> Word16 -> MouseButton -> Event) -> Ptr Event -> IO Event
    peekMouse :: (Word16 -> Word16 -> MouseButton -> Event) -> Ptr Event -> IO Event
    peekMouse Word16 -> Word16 -> MouseButton -> Event
    mkEvent Ptr Event
    ptr
        = do Word8
    b <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr
    {-# LINE 307 "Graphics/UI/SDL/Events.hsc" #-}
             Word16
    x <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word16
    forall b. Ptr b -> Int -> IO Word16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr
    {-# LINE 308 "Graphics/UI/SDL/Events.hsc" #-}
             Word16
    y <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word16
    forall b. Ptr b -> Int -> IO Word16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    6) Ptr Event
    ptr
    {-# LINE 309 "Graphics/UI/SDL/Events.hsc" #-}
             Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Event -> IO Event) -> Event -> IO Event
    forall a b. (a -> b) -> a -> b
    $! Word16 -> Word16 -> MouseButton -> Event
    mkEvent Word16
    x Word16
    y (Word8 -> MouseButton
    forall a b. Enum a b => b -> a
    toEnum (Word8
    b::Word8))

    peekJoyAxisMotion :: Ptr Event -> IO Event
    peekJoyAxisMotion :: Ptr Event -> IO Event
    peekJoyAxisMotion Ptr Event
    ptr
        = do Word8
    which <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    1) Ptr Event
    ptr
    {-# LINE 314 "Graphics/UI/SDL/Events.hsc" #-}
             Word8
    axis <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr
    {-# LINE 315 "Graphics/UI/SDL/Events.hsc" #-}
             Int16
    value <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Int16
    forall b. Ptr b -> Int -> IO Int16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr
    {-# LINE 316 "Graphics/UI/SDL/Events.hsc" #-}
             Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Event -> IO Event) -> Event -> IO Event
    forall a b. (a -> b) -> a -> b
    $! Word8 -> Word8 -> Int16 -> Event
    JoyAxisMotion Word8
    which Word8
    axis Int16
    value

    peekJoyBallMotion :: Ptr Event -> IO Event
    peekJoyBallMotion :: Ptr Event -> IO Event
    peekJoyBallMotion Ptr Event
    ptr
        = do Word8
    which <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    1) Ptr Event
    ptr
    {-# LINE 321 "Graphics/UI/SDL/Events.hsc" #-}
             Word8
    ball <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr
    {-# LINE 322 "Graphics/UI/SDL/Events.hsc" #-}
             Int16
    xrel <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Int16
    forall b. Ptr b -> Int -> IO Int16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr
    {-# LINE 323 "Graphics/UI/SDL/Events.hsc" #-}
             Int16
    yrel <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Int16
    forall b. Ptr b -> Int -> IO Int16
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    6) Ptr Event
    ptr
    {-# LINE 324 "Graphics/UI/SDL/Events.hsc" #-}
             Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Event -> IO Event) -> Event -> IO Event
    forall a b. (a -> b) -> a -> b
    $! Word8 -> Word8 -> Int16 -> Int16 -> Event
    JoyBallMotion Word8
    which Word8
    ball Int16
    xrel Int16
    yrel

    peekJoyHatMotion :: Ptr Event -> IO Event
    peekJoyHatMotion :: Ptr Event -> IO Event
    peekJoyHatMotion Ptr Event
    ptr
        = do Word8
    which <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    1) Ptr Event
    ptr
    {-# LINE 329 "Graphics/UI/SDL/Events.hsc" #-}
             Word8
    hat <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr
    {-# LINE 330 "Graphics/UI/SDL/Events.hsc" #-}
             Word8
    value <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    3) Ptr Event
    ptr
    {-# LINE 331 "Graphics/UI/SDL/Events.hsc" #-}
             Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Event -> IO Event) -> Event -> IO Event
    forall a b. (a -> b) -> a -> b
    $! Word8 -> Word8 -> Word8 -> Event
    JoyHatMotion Word8
    which Word8
    hat Word8
    value

    peekJoyButton :: (Word8 -> Word8 -> Event) -> Ptr Event -> IO Event
    peekJoyButton :: (Word8 -> Word8 -> Event) -> Ptr Event -> IO Event
    peekJoyButton Word8 -> Word8 -> Event
    mkEvent Ptr Event
    ptr
        = do Word8
    which <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    1) Ptr Event
    ptr
    {-# LINE 336 "Graphics/UI/SDL/Events.hsc" #-}
             Word8
    button <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr
    {-# LINE 337 "Graphics/UI/SDL/Events.hsc" #-}
             Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Event -> IO Event) -> Event -> IO Event
    forall a b. (a -> b) -> a -> b
    $! Word8 -> Word8 -> Event
    mkEvent Word8
    which Word8
    button

    peekResize :: Ptr Event -> IO Event
    peekResize :: Ptr Event -> IO Event
    peekResize Ptr Event
    ptr
        = do CInt
    w <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr
    {-# LINE 342 "Graphics/UI/SDL/Events.hsc" #-}
             CInt
    h <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    8) Ptr Event
    ptr
    {-# LINE 343 "Graphics/UI/SDL/Events.hsc" #-}
             Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Event -> IO Event) -> Event -> IO Event
    forall a b. (a -> b) -> a -> b
    $! Int -> Int -> Event
    VideoResize (CInt -> Int
    forall a. Num a => CInt -> a
    fromCInt CInt
    w) (CInt -> Int
    forall a. Num a => CInt -> a
    fromCInt CInt
    h)

    peekUserEvent :: Ptr Event -> Word8 -> IO Event
    peekUserEvent :: Ptr Event -> Word8 -> IO Event
    peekUserEvent Ptr Event
    ptr Word8
    n
        = do CInt
    code <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO CInt
    forall b. Ptr b -> Int -> IO CInt
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr
    {-# LINE 348 "Graphics/UI/SDL/Events.hsc" #-}
             Ptr ()
    data1 <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO (Ptr ())
    forall b. Ptr b -> Int -> IO (Ptr ())
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    8) Ptr Event
    ptr
    {-# LINE 349 "Graphics/UI/SDL/Events.hsc" #-}
             Ptr ()
    data2 <- (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> IO (Ptr ())
    forall b. Ptr b -> Int -> IO (Ptr ())
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    hsc_ptr Int
    16) Ptr Event
    ptr
    {-# LINE 350 "Graphics/UI/SDL/Events.hsc" #-}
             Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Event -> IO Event) -> Event -> IO Event
    forall a b. (a -> b) -> a -> b
    $ UserEventID -> Int -> Ptr () -> Ptr () -> Event
    User (Word8 -> UserEventID
    fromEventType Word8
    n) (CInt -> Int
    forall a. Num a => CInt -> a
    fromCInt CInt
    code) Ptr ()
    data1 Ptr ()
    data2

    getEventType :: Event -> Word8
    getEventType :: Event -> Word8
    getEventType = SDLEvent -> Word8
    fromSDLEvent (SDLEvent -> Word8) -> (Event -> SDLEvent) -> Event -> Word8
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Event -> SDLEvent
    eventToSDLEvent

    eventToSDLEvent :: Event -> SDLEvent
    eventToSDLEvent :: Event -> SDLEvent
    eventToSDLEvent Event
    NoEvent = SDLEvent
    SDLNoEvent
    eventToSDLEvent (GotFocus [Focus]
    _) = SDLEvent
    SDLActiveEvent
    eventToSDLEvent (LostFocus [Focus]
    _) = SDLEvent
    SDLActiveEvent
    eventToSDLEvent (KeyDown Keysym
    _) = SDLEvent
    SDLKeyDown
    eventToSDLEvent (KeyUp Keysym
    _) = SDLEvent
    SDLKeyUp
    eventToSDLEvent (MouseMotion Word16
    _ Word16
    _ Int16
    _ Int16
    _) = SDLEvent
    SDLMouseMotion
    eventToSDLEvent (MouseButtonDown Word16
    _ Word16
    _ MouseButton
    _) = SDLEvent
    SDLMouseButtonDown
    eventToSDLEvent (MouseButtonUp Word16
    _ Word16
    _ MouseButton
    _) = SDLEvent
    SDLMouseButtonUp
    eventToSDLEvent (JoyAxisMotion Word8
    _ Word8
    _ Int16
    _) = SDLEvent
    SDLJoyAxisMotion
    eventToSDLEvent (JoyBallMotion Word8
    _ Word8
    _ Int16
    _ Int16
    _) = SDLEvent
    SDLJoyBallMotion
    eventToSDLEvent (JoyHatMotion Word8
    _ Word8
    _ Word8
    _) = SDLEvent
    SDLJoyHatMotion
    eventToSDLEvent (JoyButtonDown Word8
    _ Word8
    _) = SDLEvent
    SDLJoyButtonDown
    eventToSDLEvent (JoyButtonUp Word8
    _ Word8
    _) = SDLEvent
    SDLJoyButtonUp
    eventToSDLEvent Event
    Quit = SDLEvent
    SDLQuit
    eventToSDLEvent (VideoResize Int
    _ Int
    _) = SDLEvent
    SDLVideoResize
    eventToSDLEvent Event
    VideoExpose = SDLEvent
    SDLVideoExpose
    eventToSDLEvent (User UserEventID
    uid Int
    _ Ptr ()
    _ Ptr ()
    _) = Word8 -> SDLEvent
    SDLUserEvent (UserEventID -> Word8
    toEventType UserEventID
    uid)
    eventToSDLEvent Event
    _ = String -> SDLEvent
    forall a. HasCallStack => String -> a
    error String
    "Graphics.UI.SDL.Events.eventToSDLEvent: bad argument"

    pokeActiveEvent :: Ptr Event -> Word8 -> [Focus] -> IO ()
    pokeActiveEvent :: Ptr Event -> Word8 -> [Focus] -> IO ()
    pokeActiveEvent Ptr Event
    ptr Word8
    gain [Focus]
    focus
        = do (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    1) Ptr Event
    ptr Word8
    gain
    {-# LINE 378 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr ([Focus] -> Word8
    forall a b. (Enum a b, Bits b, Num b) => [a] -> b
    toBitmask [Focus]
    focus)
    {-# LINE 379 "Graphics/UI/SDL/Events.hsc" #-}

    pokeKey :: Ptr Event -> Word8 -> Keysym -> IO ()
    pokeKey :: Ptr Event -> Word8 -> Keysym -> IO ()
    pokeKey Ptr Event
    ptr Word8
    state Keysym
    keysym
        = do (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr Word8
    state
    {-# LINE 383 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Keysym -> IO ()
    forall b. Ptr b -> Int -> Keysym -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr Keysym
    keysym
    {-# LINE 384 "Graphics/UI/SDL/Events.hsc" #-}

    pokeMouseMotion :: Ptr Event -> Word16 -> Word16 -> Int16 -> Int16 -> IO ()
    pokeMouseMotion :: Ptr Event -> Word16 -> Word16 -> Int16 -> Int16 -> IO ()
    pokeMouseMotion Ptr Event
    ptr Word16
    x Word16
    y Int16
    xrel Int16
    yrel
        = do (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word16 -> IO ()
    forall b. Ptr b -> Int -> Word16 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr Word16
    x
    {-# LINE 388 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word16 -> IO ()
    forall b. Ptr b -> Int -> Word16 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    6) Ptr Event
    ptr Word16
    y
    {-# LINE 389 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Int16 -> IO ()
    forall b. Ptr b -> Int -> Int16 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    8) Ptr Event
    ptr Int16
    xrel
    {-# LINE 390 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Int16 -> IO ()
    forall b. Ptr b -> Int -> Int16 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    10) Ptr Event
    ptr Int16
    yrel
    {-# LINE 391 "Graphics/UI/SDL/Events.hsc" #-}

    pokeMouseButton :: Ptr Event -> Word8 -> Word16 -> Word16 -> MouseButton -> IO ()
    pokeMouseButton :: Ptr Event -> Word8 -> Word16 -> Word16 -> MouseButton -> IO ()
    pokeMouseButton Ptr Event
    ptr Word8
    state Word16
    x Word16
    y MouseButton
    b
        = do (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word16 -> IO ()
    forall b. Ptr b -> Int -> Word16 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr Word16
    x
    {-# LINE 395 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word16 -> IO ()
    forall b. Ptr b -> Int -> Word16 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    6) Ptr Event
    ptr Word16
    y
    {-# LINE 396 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    3) Ptr Event
    ptr Word8
    state
    {-# LINE 397 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr (MouseButton -> Word8
    forall a b. Enum a b => a -> b
    fromEnum MouseButton
    b)
    {-# LINE 398 "Graphics/UI/SDL/Events.hsc" #-}

    pokeJoyAxisMotion :: Ptr Event -> Word8 -> Word8 -> Int16 -> IO ()
    pokeJoyAxisMotion :: Ptr Event -> Word8 -> Word8 -> Int16 -> IO ()
    pokeJoyAxisMotion Ptr Event
    ptr Word8
    which Word8
    axis Int16
    value
        = do (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    1) Ptr Event
    ptr Word8
    which
    {-# LINE 402 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr Word8
    axis
    {-# LINE 403 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Int16 -> IO ()
    forall b. Ptr b -> Int -> Int16 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr Int16
    value
    {-# LINE 404 "Graphics/UI/SDL/Events.hsc" #-}

    pokeJoyBallMotion :: Ptr Event -> Word8 -> Word8 -> Int16 -> Int16 -> IO ()
    pokeJoyBallMotion :: Ptr Event -> Word8 -> Word8 -> Int16 -> Int16 -> IO ()
    pokeJoyBallMotion Ptr Event
    ptr Word8
    which Word8
    ball Int16
    xrel Int16
    yrel
        = do (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    1) Ptr Event
    ptr Word8
    which
    {-# LINE 408 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr Word8
    ball
    {-# LINE 409 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Int16 -> IO ()
    forall b. Ptr b -> Int -> Int16 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr Int16
    xrel
    {-# LINE 410 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Int16 -> IO ()
    forall b. Ptr b -> Int -> Int16 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    6) Ptr Event
    ptr Int16
    yrel
    {-# LINE 411 "Graphics/UI/SDL/Events.hsc" #-}

    pokeJoyHatMotion :: Ptr Event -> Word8 -> Word8 -> Word8 -> IO ()
    pokeJoyHatMotion :: Ptr Event -> Word8 -> Word8 -> Word8 -> IO ()
    pokeJoyHatMotion Ptr Event
    ptr Word8
    which Word8
    hat Word8
    value
        = do (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    1) Ptr Event
    ptr Word8
    which
    {-# LINE 415 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr Word8
    hat
    {-# LINE 416 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    3) Ptr Event
    ptr Word8
    value
    {-# LINE 417 "Graphics/UI/SDL/Events.hsc" #-}

    pokeJoyButton :: Ptr Event -> Word8 -> Word8 -> Word8 -> IO ()
    pokeJoyButton :: Ptr Event -> Word8 -> Word8 -> Word8 -> IO ()
    pokeJoyButton Ptr Event
    ptr Word8
    which Word8
    button Word8
    state
        = do (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    1) Ptr Event
    ptr Word8
    which
    {-# LINE 421 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    2) Ptr Event
    ptr Word8
    button
    {-# LINE 422 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    3) Ptr Event
    ptr Word8
    state
    {-# LINE 423 "Graphics/UI/SDL/Events.hsc" #-}

    pokeResize :: Ptr Event -> Int -> Int -> IO ()
    pokeResize :: Ptr Event -> Int -> Int -> IO ()
    pokeResize Ptr Event
    ptr Int
    w Int
    h
        = do (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Int -> IO ()
    forall b. Ptr b -> Int -> Int -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr Int
    w
    {-# LINE 427 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Int -> IO ()
    forall b. Ptr b -> Int -> Int -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    8) Ptr Event
    ptr Int
    h
    {-# LINE 428 "Graphics/UI/SDL/Events.hsc" #-}

    pokeUserEvent :: Ptr Event -> UserEventID -> Int -> Ptr () -> Ptr () -> IO ()
    pokeUserEvent :: Ptr Event -> UserEventID -> Int -> Ptr () -> Ptr () -> IO ()
    pokeUserEvent Ptr Event
    ptr UserEventID
    _eventId Int
    code Ptr ()
    data1 Ptr ()
    data2
        = do (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Int -> IO ()
    forall b. Ptr b -> Int -> Int -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    4) Ptr Event
    ptr Int
    code
    {-# LINE 432 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Ptr () -> IO ()
    forall b. Ptr b -> Int -> Ptr () -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    8) Ptr Event
    ptr Ptr ()
    data1
    {-# LINE 433 "Graphics/UI/SDL/Events.hsc" #-}
             (\Ptr Event
    hsc_ptr -> Ptr Event -> Int -> Ptr () -> IO ()
    forall b. Ptr b -> Int -> Ptr () -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    hsc_ptr Int
    16) Ptr Event
    ptr Ptr ()
    data2
    {-# LINE 434 "Graphics/UI/SDL/Events.hsc" #-}

    instance Storable Event where
        sizeOf :: Event -> Int
    sizeOf = Int -> Event -> Int
    forall a b. a -> b -> a
    const ((Int
    24))
    {-# LINE 437 "Graphics/UI/SDL/Events.hsc" #-}
        alignment = const 4
        poke :: Ptr Event -> Event -> IO ()
    poke Ptr Event
    ptr Event
    event
            = do Ptr Event -> Int -> Word8 -> IO ()
    forall b. Ptr b -> Int -> Word8 -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr Event
    ptr Int
    0 (Event -> Word8
    getEventType Event
    event)
                 case Event
    event of
                   Event
    NoEvent               -> () -> IO ()
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
                   GotFocus [Focus]
    focus        -> Ptr Event -> Word8 -> [Focus] -> IO ()
    pokeActiveEvent Ptr Event
    ptr Word8
    1 [Focus]
    focus
                   LostFocus [Focus]
    focus       -> Ptr Event -> Word8 -> [Focus] -> IO ()
    pokeActiveEvent Ptr Event
    ptr Word8
    0 [Focus]
    focus
                   KeyDown Keysym
    keysym        -> Ptr Event -> Word8 -> Keysym -> IO ()
    pokeKey Ptr Event
    ptr Word8
    1 Keysym
    keysym
    {-# LINE 445 "Graphics/UI/SDL/Events.hsc" #-}
                   KeyUp Keysym
    keysym          -> Ptr Event -> Word8 -> Keysym -> IO ()
    pokeKey Ptr Event
    ptr Word8
    0 Keysym
    keysym
    {-# LINE 446 "Graphics/UI/SDL/Events.hsc" #-}
                   MouseMotion Word16
    x Word16
    y Int16
    xrel Int16
    yrel -> Ptr Event -> Word16 -> Word16 -> Int16 -> Int16 -> IO ()
    pokeMouseMotion Ptr Event
    ptr Word16
    x Word16
    y Int16
    xrel Int16
    yrel
                   MouseButtonDown Word16
    x Word16
    y MouseButton
    b -> Ptr Event -> Word8 -> Word16 -> Word16 -> MouseButton -> IO ()
    pokeMouseButton Ptr Event
    ptr Word8
    1 Word16
    x Word16
    y MouseButton
    b
    {-# LINE 448 "Graphics/UI/SDL/Events.hsc" #-}
                   MouseButtonUp Word16
    x Word16
    y MouseButton
    b   -> Ptr Event -> Word8 -> Word16 -> Word16 -> MouseButton -> IO ()
    pokeMouseButton Ptr Event
    ptr Word8
    0 Word16
    x Word16
    y MouseButton
    b
    {-# LINE 449 "Graphics/UI/SDL/Events.hsc" #-}
                   JoyAxisMotion Word8
    w Word8
    a Int16
    v   -> Ptr Event -> Word8 -> Word8 -> Int16 -> IO ()
    pokeJoyAxisMotion Ptr Event
    ptr Word8
    w Word8
    a Int16
    v
                   JoyBallMotion Word8
    w Word8
    b Int16
    x Int16
    y -> Ptr Event -> Word8 -> Word8 -> Int16 -> Int16 -> IO ()
    pokeJoyBallMotion Ptr Event
    ptr Word8
    w Word8
    b Int16
    x Int16
    y
                   JoyHatMotion Word8
    w Word8
    h Word8
    v    -> Ptr Event -> Word8 -> Word8 -> Word8 -> IO ()
    pokeJoyHatMotion Ptr Event
    ptr Word8
    w Word8
    h Word8
    v
                   JoyButtonDown Word8
    w Word8
    b     -> Ptr Event -> Word8 -> Word8 -> Word8 -> IO ()
    pokeJoyButton Ptr Event
    ptr Word8
    w Word8
    b Word8
    1
    {-# LINE 453 "Graphics/UI/SDL/Events.hsc" #-}
                   JoyButtonUp Word8
    w Word8
    b       -> Ptr Event -> Word8 -> Word8 -> Word8 -> IO ()
    pokeJoyButton Ptr Event
    ptr Word8
    w Word8
    b Word8
    0
    {-# LINE 454 "Graphics/UI/SDL/Events.hsc" #-}
                   Event
    Quit                  -> () -> IO ()
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
                   VideoResize Int
    w Int
    h       -> Ptr Event -> Int -> Int -> IO ()
    pokeResize Ptr Event
    ptr Int
    w Int
    h
                   Event
    VideoExpose           -> () -> IO ()
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
                   User UserEventID
    eventId Int
    c Ptr ()
    d1 Ptr ()
    d2  -> Ptr Event -> UserEventID -> Int -> Ptr () -> Ptr () -> IO ()
    pokeUserEvent Ptr Event
    ptr UserEventID
    eventId Int
    c Ptr ()
    d1 Ptr ()
    d2
                   Event
    e                     -> String -> IO ()
    forall a. String -> IO a
    failWithError (String -> IO ()) -> String -> IO ()
    forall a b. (a -> b) -> a -> b
    $ String
    "Unhandled eventtype: " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ Event -> String
    forall a. Show a => a -> String
    show Event
    e
        peek :: Ptr Event -> IO Event
    peek Ptr Event
    ptr
            = do Word8
    eventType <- Ptr Event -> Int -> IO Word8
    forall b. Ptr b -> Int -> IO Word8
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr Event
    ptr Int
    0
                 case Word8 -> SDLEvent
    toSDLEvent Word8
    eventType of
                   SDLEvent
    SDLNoEvent         -> Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Event
    NoEvent
                   SDLEvent
    SDLActiveEvent     -> Ptr Event -> IO Event
    peekActiveEvent Ptr Event
    ptr
                   SDLEvent
    SDLKeyDown         -> (Keysym -> Event) -> Ptr Event -> IO Event
    peekKey Keysym -> Event
    KeyDown Ptr Event
    ptr
                   SDLEvent
    SDLKeyUp           -> (Keysym -> Event) -> Ptr Event -> IO Event
    peekKey Keysym -> Event
    KeyUp Ptr Event
    ptr
                   SDLEvent
    SDLMouseMotion     -> Ptr Event -> IO Event
    peekMouseMotion Ptr Event
    ptr
                   SDLEvent
    SDLMouseButtonDown -> (Word16 -> Word16 -> MouseButton -> Event) -> Ptr Event -> IO Event
    peekMouse Word16 -> Word16 -> MouseButton -> Event
    MouseButtonDown Ptr Event
    ptr
                   SDLEvent
    SDLMouseButtonUp   -> (Word16 -> Word16 -> MouseButton -> Event) -> Ptr Event -> IO Event
    peekMouse Word16 -> Word16 -> MouseButton -> Event
    MouseButtonUp Ptr Event
    ptr
                   SDLEvent
    SDLJoyAxisMotion   -> Ptr Event -> IO Event
    peekJoyAxisMotion Ptr Event
    ptr
                   SDLEvent
    SDLJoyBallMotion   -> Ptr Event -> IO Event
    peekJoyBallMotion Ptr Event
    ptr
                   SDLEvent
    SDLJoyHatMotion    -> Ptr Event -> IO Event
    peekJoyHatMotion Ptr Event
    ptr
                   SDLEvent
    SDLJoyButtonDown   -> (Word8 -> Word8 -> Event) -> Ptr Event -> IO Event
    peekJoyButton Word8 -> Word8 -> Event
    JoyButtonDown Ptr Event
    ptr
                   SDLEvent
    SDLJoyButtonUp     -> (Word8 -> Word8 -> Event) -> Ptr Event -> IO Event
    peekJoyButton Word8 -> Word8 -> Event
    JoyButtonUp Ptr Event
    ptr
                   SDLEvent
    SDLQuit            -> Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Event
    Quit
    --           SDLSysWMEvent
                   SDLEvent
    SDLVideoResize     -> Ptr Event -> IO Event
    peekResize Ptr Event
    ptr
                   SDLEvent
    SDLVideoExpose     -> Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Event
    VideoExpose
                   SDLUserEvent Word8
    n     -> Ptr Event -> Word8 -> IO Event
    peekUserEvent Ptr Event
    ptr Word8
    n
    --           SDLNumEvents
                   SDLEvent
    e                  -> String -> IO Event
    forall a. String -> IO a
    failWithError (String -> IO Event) -> String -> IO Event
    forall a b. (a -> b) -> a -> b
    $ String
    "Unhandled eventtype: " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ SDLEvent -> String
    forall a. Show a => a -> String
    show SDLEvent
    e

    -- int SDL_EnableKeyRepeat(int delay, int interval);
    foreign import ccall unsafe "SDL_EnableKeyRepeat" sdlEnableKeyRepeat :: Int -> Int -> IO Int

    -- | Sets keyboard repeat rate. Returns @False@ on error.
    enableKeyRepeat :: Int -- ^ Initial delay. @0@ to disable.
                    -> Int -- ^ Interval.
                    -> IO Bool
    enableKeyRepeat :: Int -> Int -> IO Bool
    enableKeyRepeat Int
    delay Int
    interval
        = Int -> IO Int -> IO Bool
    intToBool (-Int
    1) (Int -> Int -> IO Int
    sdlEnableKeyRepeat Int
    delay Int
    interval)

    -- int SDL_EnableUNICODE(int enable);
    foreign import ccall unsafe "SDL_EnableUNICODE" sdlEnableUnicode :: Int -> IO Int

    -- | Enables or disables unicode translation.
    enableUnicode :: Bool -> IO ()
    enableUnicode :: Bool -> IO ()
    enableUnicode Bool
    enable = Int -> IO Int
    sdlEnableUnicode (Toggle -> Int
    forall a. Num a => Toggle -> a
    fromToggle Toggle
    toggle) IO Int -> IO () -> IO ()
    forall a b. IO a -> IO b -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >>
                           () -> IO ()
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
        where toggle :: Toggle
    toggle = case Bool
    enable of
                         Bool
    True -> Toggle
    Enable
                         Bool
    False -> Toggle
    Disable

    -- | Returns the current state of unicode translation. See also 'enableUnicode'.
    queryUnicodeState :: IO Bool
    queryUnicodeState :: IO Bool
    queryUnicodeState = (Int -> Bool) -> IO Int -> IO Bool
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Int -> Bool
    forall a. (Eq a, Num a) => a -> Bool
    toBool (Int -> IO Int
    sdlEnableUnicode (Toggle -> Int
    forall a. Num a => Toggle -> a
    fromToggle Toggle
    Query))

    -- char *SDL_GetKeyName(SDLKey key);
    foreign import ccall unsafe "SDL_GetKeyName" sdlGetKeyName :: Word32 -> IO CString
    {-# LINE 509 "Graphics/UI/SDL/Events.hsc" #-}

    -- | Gets the name of an SDL virtual keysym.
    getKeyName :: SDLKey -> String
    getKeyName :: SDLKey -> String
    getKeyName SDLKey
    key = IO String -> String
    forall a. IO a -> a
    unsafePerformIO (IO String -> String) -> IO String -> String
    forall a b. (a -> b) -> a -> b
    $
                     Word32 -> IO CString
    sdlGetKeyName (SDLKey -> Word32
    forall a b. Enum a b => a -> b
    fromEnum SDLKey
    key) IO CString -> (CString -> IO String) -> IO String
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= CString -> IO String
    peekCString

    -- SDLMod SDL_GetModState(void);
    foreign import ccall unsafe "SDL_GetModState" sdlGetModState :: IO Word32
    {-# LINE 517 "Graphics/UI/SDL/Events.hsc" #-}

    -- | Gets the state of modifier keys.
    getModState :: IO [Modifier]
    getModState :: IO [Modifier]
    getModState = (Word32 -> [Modifier]) -> IO Word32 -> IO [Modifier]
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Word32 -> [Modifier]
    forall a b. (Bounded a, Enum a b, Bits b, Num b) => b -> [a]
    fromBitmask IO Word32
    sdlGetModState

    -- void SDL_SetModState(SDLMod modstate);
    foreign import ccall unsafe "SDL_SetModState" sdlSetModState :: Word32 -> IO ()
    {-# LINE 524 "Graphics/UI/SDL/Events.hsc" #-}

    -- | Sets the internal state of modifier keys.
    setModState :: [Modifier] -> IO ()
    setModState :: [Modifier] -> IO ()
    setModState = Word32 -> IO ()
    sdlSetModState (Word32 -> IO ()) -> ([Modifier] -> Word32) -> [Modifier] -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [Modifier] -> Word32
    forall a b. (Enum a b, Bits b, Num b) => [a] -> b
    toBitmask

    mousePressed :: Word8 -> MouseButton -> Bool
    mousePressed :: Word8 -> MouseButton -> Bool
    mousePressed Word8
    mask MouseButton
    b
        = Word8
    mask Word8 -> Word8 -> Word8
    forall a. Bits a => a -> a -> a
    .&. (MouseButton -> Word8
    mouseButtonMask MouseButton
    b) Word8 -> Word8 -> Bool
    forall a. Eq a => a -> a -> Bool
    /= Word8
    0

    -- Uint8 SDL_GetMouseState(int *x, int *y);
    foreign import ccall "SDL_GetMouseState" sdlGetMouseState :: Ptr CInt -> Ptr CInt -> IO Word8
    foreign import ccall "SDL_GetRelativeMouseState" sdlGetRelativeMouseState :: Ptr CInt -> Ptr CInt -> IO Word8

    -- | Retrieves the current state of the mouse. Returns (X position, Y position, pressed buttons).
    getMouseState :: IO (Int, Int, [MouseButton])
    getMouseState :: IO (Int, Int, [MouseButton])
    getMouseState = (Ptr CInt -> Ptr CInt -> IO Word8) -> IO (Int, Int, [MouseButton])
    mouseStateGetter Ptr CInt -> Ptr CInt -> IO Word8
    sdlGetMouseState

    -- | Retrieve the current state of the mouse. Like 'getMouseState' except that X and Y are
    --   set to the change since last call to getRelativeMouseState.
    getRelativeMouseState :: IO (Int, Int, [MouseButton])
    getRelativeMouseState :: IO (Int, Int, [MouseButton])
    getRelativeMouseState = (Ptr CInt -> Ptr CInt -> IO Word8) -> IO (Int, Int, [MouseButton])
    mouseStateGetter Ptr CInt -> Ptr CInt -> IO Word8
    sdlGetRelativeMouseState

    mouseStateGetter :: (Ptr CInt -> Ptr CInt -> IO Word8) -> IO  (Int, Int, [MouseButton])
    mouseStateGetter :: (Ptr CInt -> Ptr CInt -> IO Word8) -> IO (Int, Int, [MouseButton])
    mouseStateGetter Ptr CInt -> Ptr CInt -> IO Word8
    getter
        = (Ptr CInt -> IO (Int, Int, [MouseButton]))
    -> IO (Int, Int, [MouseButton])
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CInt -> IO (Int, Int, [MouseButton]))
     -> IO (Int, Int, [MouseButton]))
    -> (Ptr CInt -> IO (Int, Int, [MouseButton]))
    -> IO (Int, Int, [MouseButton])
    forall a b. (a -> b) -> a -> b
    $ \Ptr CInt
    xPtr ->
          (Ptr CInt -> IO (Int, Int, [MouseButton]))
    -> IO (Int, Int, [MouseButton])
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr CInt -> IO (Int, Int, [MouseButton]))
     -> IO (Int, Int, [MouseButton]))
    -> (Ptr CInt -> IO (Int, Int, [MouseButton]))
    -> IO (Int, Int, [MouseButton])
    forall a b. (a -> b) -> a -> b
    $ \Ptr CInt
    yPtr ->
          do Word8
    ret <- Ptr CInt -> Ptr CInt -> IO Word8
    getter Ptr CInt
    xPtr Ptr CInt
    yPtr
             [CInt
    x,CInt
    y] <- (Ptr CInt -> IO CInt) -> [Ptr CInt] -> IO [CInt]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM Ptr CInt -> IO CInt
    forall a. Storable a => Ptr a -> IO a
    peek [Ptr CInt
    xPtr,Ptr CInt
    yPtr]
             (Int, Int, [MouseButton]) -> IO (Int, Int, [MouseButton])
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    x,CInt -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CInt
    y
                    ,(MouseButton -> Bool) -> [MouseButton] -> [MouseButton]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (Word8 -> MouseButton -> Bool
    mousePressed Word8
    ret) [MouseButton]
    allButtons)

    -- int SDL_PollEvent(SDL_Event *event);
    foreign import ccall "SDL_PollEvent" sdlPollEvent :: Ptr Event -> IO Int

    -- | Polls for currently pending events.
    pollEvent :: IO Event
    pollEvent :: IO Event
    pollEvent
        = (Ptr Event -> IO Event) -> IO Event
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca Ptr Event -> IO Event
    poll
        where poll :: Ptr Event -> IO Event
    poll Ptr Event
    ptr
                  = do Int
    ret <- Ptr Event -> IO Int
    sdlPollEvent Ptr Event
    ptr
                       case Int
    ret of
                         Int
    0 -> Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Event
    NoEvent
                         Int
    _ -> do Event
    event <- Ptr Event -> IO Event
    forall a. Storable a => Ptr a -> IO a
    peek Ptr Event
    ptr
                                 case Event
    event of
                                   Event
    NoEvent -> Ptr Event -> IO Event
    poll Ptr Event
    ptr
                                   Event
    _ -> Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Event
    event

    -- void SDL_PumpEvents(void);
    -- | Pumps the event loop, gathering events from the input devices.
    foreign import ccall unsafe "SDL_PumpEvents" pumpEvents :: IO ()

    -- int SDL_PushEvent(SDL_Event *event);
    foreign import ccall unsafe "SDL_PushEvent" sdlPushEvent :: Ptr Event -> IO Int

    -- | Pushes an event onto the event queue. Returns @False@ on error.
    tryPushEvent :: Event -> IO Bool
    tryPushEvent :: Event -> IO Bool
    tryPushEvent Event
    event
        = Event -> IO (Ptr Event)
    forall a. Storable a => a -> IO (Ptr a)
    new Event
    event IO (Ptr Event) -> (Ptr Event -> IO Bool) -> IO Bool
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= ((Int -> Bool) -> IO Int -> IO Bool
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (Int
    0Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    ==) (IO Int -> IO Bool)
    -> (Ptr Event -> IO Int) -> Ptr Event -> IO Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Ptr Event -> IO Int
    sdlPushEvent)

    -- | Pushes an event onto the event queue. Throws an exception on error.
    pushEvent :: Event -> IO ()
    pushEvent :: Event -> IO ()
    pushEvent = String -> IO Bool -> IO ()
    unwrapBool String
    "SDL_PushEvent" (IO Bool -> IO ()) -> (Event -> IO Bool) -> Event -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Event -> IO Bool
    tryPushEvent

    -- int SDL_WaitEvent(SDL_Event *event);
    foreign import ccall safe "SDL_WaitEvent" sdlWaitEvent :: Ptr Event -> IO Int

    -- | Waits indefinitely for the next available event.
    waitEvent :: IO Event
    waitEvent :: IO Event
    waitEvent
        = IO Event
    loop
        where loop :: IO Event
    loop = do IO ()
    pumpEvents
                        Event
    event <- IO Event
    pollEvent
                        case Event
    event of
                          Event
    NoEvent -> Int -> IO ()
    threadDelay Int
    10 IO () -> IO Event -> IO Event
    forall a b. IO a -> IO b -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> IO Event
    loop
                          Event
    _ -> Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Event
    event

    -- | Waits indefinitely for the next available event. Blocks Haskell threads.
    waitEventBlocking :: IO Event
    waitEventBlocking :: IO Event
    waitEventBlocking
        = (Ptr Event -> IO Event) -> IO Event
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca Ptr Event -> IO Event
    wait
        where wait :: Ptr Event -> IO Event
    wait Ptr Event
    ptr
                  = do Int
    ret <- Ptr Event -> IO Int
    sdlWaitEvent Ptr Event
    ptr
                       case Int
    ret of
                         Int
    0 -> String -> IO Event
    forall a. String -> IO a
    failWithError String
    "SDL_WaitEvent"
                         Int
    _ -> do Event
    event <- Ptr Event -> IO Event
    forall a. Storable a => Ptr a -> IO a
    peek Ptr Event
    ptr
                                 case Event
    event of
                                   Event
    NoEvent -> Ptr Event -> IO Event
    wait Ptr Event
    ptr
                                   Event
    _ -> Event -> IO Event
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Event
    event

    -- Uint8 SDL_EventState(Uint8 type, int state);
    foreign import ccall unsafe "SDL_EventState" sdlEventState :: Word8 -> Int -> IO Word8

    -- |Enable or disable events from being processed.
    enableEvent :: SDLEvent -> Bool -> IO ()
    enableEvent :: SDLEvent -> Bool -> IO ()
    enableEvent SDLEvent
    event Bool
    on
        = Word8 -> Int -> IO Word8
    sdlEventState (SDLEvent -> Word8
    fromSDLEvent SDLEvent
    event) (Toggle -> Int
    forall a. Num a => Toggle -> a
    fromToggle Toggle
    state) IO Word8 -> IO () -> IO ()
    forall a b. IO a -> IO b -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> () -> IO ()
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
        where state :: Toggle
    state
                  | Bool
    on = Toggle
    Enable
                  | Bool
    otherwise = Toggle
    Disable

    -- |Checks current state of a event. See also 'enableEvent'.
    queryEventState :: SDLEvent -> IO Bool
    queryEventState :: SDLEvent -> IO Bool
    queryEventState SDLEvent
    event
        = (Word8 -> Bool) -> IO Word8 -> IO Bool
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (Word8 -> Word8 -> Bool
    forall a. Eq a => a -> a -> Bool
    ==Word8
    1) (Word8 -> Int -> IO Word8
    sdlEventState (SDLEvent -> Word8
    fromSDLEvent SDLEvent
    event) (Toggle -> Int
    forall a. Num a => Toggle -> a
    fromToggle Toggle
    Query))

    -- Uint8 SDL_GetAppState(void);
    foreign import ccall unsafe "SDL_GetAppState" sdlGetAppState :: IO Word8

    -- | Gets the state of the application.
    getAppState :: IO [Focus]
    getAppState :: IO [Focus]
    getAppState = (Word8 -> [Focus]) -> IO Word8 -> IO [Focus]
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Word8 -> [Focus]
    forall a b. (Bounded a, Enum a b, Bits b, Num b) => b -> [a]
    fromBitmask IO Word8
    sdlGetAppState