Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
SDL.Event exports an interface for working with the SDL event model. Event handling allows your application to receive input from the user. Internally, SDL stores all the events waiting to be handled in an event queue. Using functions like pollEvent
and waitEvent
you can observe and handle waiting input events.
The event queue itself is composed of a series of Event
values, one for each waiting event. Event
values are read from the queue with the pollEvent
function and it is then up to the application to process the information stored with them.
Synopsis
- pollEvent :: MonadIO m => m (Maybe Event)
- pollEvents :: MonadIO m => m [Event]
- mapEvents :: MonadIO m => (Event -> m ()) -> m ()
- pumpEvents :: MonadIO m => m ()
- waitEvent :: MonadIO m => m Event
- waitEventTimeout :: MonadIO m => CInt -> m (Maybe Event)
- data RegisteredEventType a = RegisteredEventType {
- pushRegisteredEvent :: a -> IO EventPushResult
- getRegisteredEvent :: Event -> IO (Maybe a)
- data RegisteredEventData = RegisteredEventData {
- registeredEventWindow :: !(Maybe Window)
- registeredEventCode :: !Int32
- registeredEventData1 :: !(Ptr ())
- registeredEventData2 :: !(Ptr ())
- data EventPushResult
- emptyRegisteredEvent :: RegisteredEventData
- registerEvent :: MonadIO m => (RegisteredEventData -> Timestamp -> IO (Maybe a)) -> (a -> IO RegisteredEventData) -> m (Maybe (RegisteredEventType a))
- type EventWatchCallback = Event -> IO ()
- data EventWatch
- addEventWatch :: MonadIO m => EventWatchCallback -> m EventWatch
- delEventWatch :: MonadIO m => EventWatch -> m ()
- data Event = Event {}
- type Timestamp = Word32
- data EventPayload
- = WindowShownEvent !WindowShownEventData
- | WindowHiddenEvent !WindowHiddenEventData
- | WindowExposedEvent !WindowExposedEventData
- | WindowMovedEvent !WindowMovedEventData
- | WindowResizedEvent !WindowResizedEventData
- | WindowSizeChangedEvent !WindowSizeChangedEventData
- | WindowMinimizedEvent !WindowMinimizedEventData
- | WindowMaximizedEvent !WindowMaximizedEventData
- | WindowRestoredEvent !WindowRestoredEventData
- | WindowGainedMouseFocusEvent !WindowGainedMouseFocusEventData
- | WindowLostMouseFocusEvent !WindowLostMouseFocusEventData
- | WindowGainedKeyboardFocusEvent !WindowGainedKeyboardFocusEventData
- | WindowLostKeyboardFocusEvent !WindowLostKeyboardFocusEventData
- | WindowClosedEvent !WindowClosedEventData
- | KeyboardEvent !KeyboardEventData
- | TextEditingEvent !TextEditingEventData
- | TextInputEvent !TextInputEventData
- | KeymapChangedEvent
- | MouseMotionEvent !MouseMotionEventData
- | MouseButtonEvent !MouseButtonEventData
- | MouseWheelEvent !MouseWheelEventData
- | JoyAxisEvent !JoyAxisEventData
- | JoyBallEvent !JoyBallEventData
- | JoyHatEvent !JoyHatEventData
- | JoyButtonEvent !JoyButtonEventData
- | JoyDeviceEvent !JoyDeviceEventData
- | ControllerAxisEvent !ControllerAxisEventData
- | ControllerButtonEvent !ControllerButtonEventData
- | ControllerDeviceEvent !ControllerDeviceEventData
- | AudioDeviceEvent !AudioDeviceEventData
- | QuitEvent
- | UserEvent !UserEventData
- | SysWMEvent !SysWMEventData
- | TouchFingerEvent !TouchFingerEventData
- | TouchFingerMotionEvent !TouchFingerMotionEventData
- | MultiGestureEvent !MultiGestureEventData
- | DollarGestureEvent !DollarGestureEventData
- | DropEvent !DropEventData
- | ClipboardUpdateEvent
- | UnknownEvent !UnknownEventData
- newtype WindowShownEventData = WindowShownEventData {}
- newtype WindowHiddenEventData = WindowHiddenEventData {}
- newtype WindowExposedEventData = WindowExposedEventData {}
- data WindowMovedEventData = WindowMovedEventData {}
- data WindowResizedEventData = WindowResizedEventData {}
- data WindowSizeChangedEventData = WindowSizeChangedEventData {}
- newtype WindowMinimizedEventData = WindowMinimizedEventData {}
- newtype WindowMaximizedEventData = WindowMaximizedEventData {}
- newtype WindowRestoredEventData = WindowRestoredEventData {}
- newtype WindowGainedMouseFocusEventData = WindowGainedMouseFocusEventData {}
- newtype WindowLostMouseFocusEventData = WindowLostMouseFocusEventData {}
- newtype WindowGainedKeyboardFocusEventData = WindowGainedKeyboardFocusEventData {}
- newtype WindowLostKeyboardFocusEventData = WindowLostKeyboardFocusEventData {}
- newtype WindowClosedEventData = WindowClosedEventData {}
- newtype SysWMEventData = SysWMEventData {}
- data KeyboardEventData = KeyboardEventData {}
- data TextEditingEventData = TextEditingEventData {}
- data TextInputEventData = TextInputEventData {}
- data MouseMotionEventData = MouseMotionEventData {}
- data MouseButtonEventData = MouseButtonEventData {}
- data MouseWheelEventData = MouseWheelEventData {}
- data JoyAxisEventData = JoyAxisEventData {}
- data JoyBallEventData = JoyBallEventData {}
- data JoyHatEventData = JoyHatEventData {}
- data JoyButtonEventData = JoyButtonEventData {}
- data JoyDeviceEventData = JoyDeviceEventData {}
- data ControllerAxisEventData = ControllerAxisEventData {}
- data ControllerButtonEventData = ControllerButtonEventData {}
- data ControllerDeviceEventData = ControllerDeviceEventData {}
- data AudioDeviceEventData = AudioDeviceEventData {}
- data UserEventData = UserEventData {
- userEventType :: !Word32
- userEventWindow :: !(Maybe Window)
- userEventCode :: !Int32
- userEventData1 :: !(Ptr ())
- userEventData2 :: !(Ptr ())
- data TouchFingerEventData = TouchFingerEventData {}
- data TouchFingerMotionEventData = TouchFingerMotionEventData {}
- data MultiGestureEventData = MultiGestureEventData {}
- data DollarGestureEventData = DollarGestureEventData {}
- newtype DropEventData = DropEventData {}
- newtype UnknownEventData = UnknownEventData {}
- data InputMotion
- data MouseButton
Polling events
pollEvent :: MonadIO m => m (Maybe Event) Source #
Poll for currently pending events. You can only call this function in the OS thread that set the video mode.
pollEvents :: MonadIO m => m [Event] Source #
Clear the event queue by polling for all pending events.
Like pollEvent
this function should only be called in the OS thread which
set the video mode.
mapEvents :: MonadIO m => (Event -> m ()) -> m () Source #
Run a monadic computation, accumulating over all known Event
s.
This can be useful when used with a state monad, allowing you to fold all events together.
pumpEvents :: MonadIO m => m () Source #
Pump the event loop, gathering events from the input devices.
This function updates the event queue and internal input device state.
This should only be run in the OS thread that initialized the video subsystem, and for extra safety, you should consider only doing those things on the main thread in any case.
pumpEvents
gathers all the pending input information from devices and places it in the event queue. Without calls to pumpEvents
no events would ever be placed on the queue. Often the need for calls to pumpEvents
is hidden from the user since pollEvent
and waitEvent
implicitly call pumpEvents
. However, if you are not polling or waiting for events (e.g. you are filtering them), then you must call pumpEvents
to force an event queue update.
See SDL_PumpEvents
for C documentation.
Wait until the specified timeout for the next available amount.
Registering user events
data RegisteredEventType a Source #
A user defined event structure that has been registered with SDL.
Use registerEvent
, below, to obtain an instance.
RegisteredEventType | |
|
data RegisteredEventData Source #
A record used to convert between SDL Events and user-defined data structures.
Used for registerEvent
, below.
RegisteredEventData | |
|
Instances
data EventPushResult Source #
Possible results of an attempted push of an event to the queue.
Instances
emptyRegisteredEvent :: RegisteredEventData Source #
A registered event with no associated data.
This is a resonable baseline to modify for converting to
RegisteredEventData
.
registerEvent :: MonadIO m => (RegisteredEventData -> Timestamp -> IO (Maybe a)) -> (a -> IO RegisteredEventData) -> m (Maybe (RegisteredEventType a)) Source #
Register a new event type with SDL.
Provide functions that convert between UserEventData
and your structure.
You can then use pushRegisteredEvent
to add a custom event of the
registered type to the queue, and getRegisteredEvent
to test for such
events in the main loop.
Watching events
type EventWatchCallback = Event -> IO () Source #
An EventWatchCallback
can process and respond to an event
when it is added to the event queue.
data EventWatch Source #
addEventWatch :: MonadIO m => EventWatchCallback -> m EventWatch Source #
Trigger an EventWatchCallback
when an event is added to the SDL
event queue.
See https://wiki.libsdl.org/SDL_AddEventWatch
for C documentation.
delEventWatch :: MonadIO m => EventWatch -> m () Source #
Remove an EventWatch
.
See https://wiki.libsdl.org/SDL_DelEventWatch
for C documentation.
Event data
A single SDL event. This event occurred at eventTimestamp
and carries data under eventPayload
.
Event | |
|
Instances
Generic Event Source # | |
Show Event Source # | |
Eq Event Source # | |
Ord Event Source # | |
type Rep Event Source # | |
Defined in SDL.Event type Rep Event = D1 ('MetaData "Event" "SDL.Event" "sdl2-2.5.5.0-inplace" 'False) (C1 ('MetaCons "Event" 'PrefixI 'True) (S1 ('MetaSel ('Just "eventTimestamp") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Timestamp) :*: S1 ('MetaSel ('Just "eventPayload") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 EventPayload))) |
data EventPayload Source #
An enumeration of all possible SDL event types. This data type pairs up event types with their payload, where possible.
Instances
Window events
newtype WindowShownEventData Source #
A window has been shown.
WindowShownEventData | |
|
Instances
newtype WindowHiddenEventData Source #
A window has been hidden.
WindowHiddenEventData | |
|
Instances
newtype WindowExposedEventData Source #
A part of a window has been exposed - where exposure means to become visible (for example, an overlapping window no longer overlaps with the window).
WindowExposedEventData | |
|
Instances
data WindowMovedEventData Source #
A Window
has been moved.
WindowMovedEventData | |
|
Instances
data WindowResizedEventData Source #
Window has been resized. This is event is always preceded by WindowSizeChangedEvent
.
WindowResizedEventData | |
|
Instances
data WindowSizeChangedEventData Source #
The window size has changed, either as a result of an API call or through the system or user changing the window size; this event is followed by WindowResizedEvent
if the size was changed by an external event, i.e. the user or the window manager.
WindowSizeChangedEventData | |
|
Instances
newtype WindowMinimizedEventData Source #
The window has been minimized.
WindowMinimizedEventData | |
|
Instances
newtype WindowMaximizedEventData Source #
The window has been maximized.
WindowMaximizedEventData | |
|
Instances
newtype WindowRestoredEventData Source #
The window has been restored to normal size and position.
WindowRestoredEventData | |
|
Instances
newtype WindowGainedMouseFocusEventData Source #
The window has gained mouse focus.
WindowGainedMouseFocusEventData | |
|
Instances
newtype WindowLostMouseFocusEventData Source #
The window has lost mouse focus.
WindowLostMouseFocusEventData | |
|
Instances
newtype WindowGainedKeyboardFocusEventData Source #
The window has gained keyboard focus.
WindowGainedKeyboardFocusEventData | |
|
Instances
newtype WindowLostKeyboardFocusEventData Source #
The window has lost keyboard focus.
WindowLostKeyboardFocusEventData | |
|
Instances
newtype WindowClosedEventData Source #
The window manager requests that the window be closed.
WindowClosedEventData | |
|
Instances
newtype SysWMEventData Source #
A video driver dependent system event
Instances
Keyboard events
data KeyboardEventData Source #
A keyboard key has been pressed or released.
KeyboardEventData | |
|
Instances
data TextEditingEventData Source #
Keyboard text editing event information.
TextEditingEventData | |
|
Instances
data TextInputEventData Source #
Keyboard text input event information.
TextInputEventData | |
|
Instances
Mouse events
data MouseMotionEventData Source #
A mouse or pointer device was moved.
MouseMotionEventData | |
|
Instances
data MouseButtonEventData Source #
A mouse or pointer device button was pressed or released.
MouseButtonEventData | |
|
Instances
data MouseWheelEventData Source #
Mouse wheel event information.
MouseWheelEventData | |
|
Instances
Joystick events
data JoyAxisEventData Source #
Joystick axis motion event information
JoyAxisEventData | |
|
Instances
data JoyBallEventData Source #
Joystick trackball motion event information.
JoyBallEventData | |
|
Instances
data JoyHatEventData Source #
Joystick hat position change event information
JoyHatEventData | |
|
Instances
data JoyButtonEventData Source #
Joystick button event information.
JoyButtonEventData | |
|
Instances
data JoyDeviceEventData Source #
Joystick device event information.
JoyDeviceEventData | |
|
Instances
Controller events
data ControllerAxisEventData Source #
Game controller axis motion event information.
ControllerAxisEventData | |
|
Instances
data ControllerButtonEventData Source #
Game controller button event information
ControllerButtonEventData | |
|
Instances
data ControllerDeviceEventData Source #
Controller device event information
ControllerDeviceEventData | |
|
Instances
Audio events
data AudioDeviceEventData Source #
AudioDeviceEventData | |
|
Instances
User events
data UserEventData Source #
Event data for application-defined events.
UserEventData | |
|
Instances
Touch events
data TouchFingerEventData Source #
Finger touch event information.
TouchFingerEventData | |
|
Instances
data TouchFingerMotionEventData Source #
Finger motion event information.
TouchFingerMotionEventData | |
|
Instances
Gesture events
data MultiGestureEventData Source #
Multiple finger gesture event information
MultiGestureEventData | |
|
Instances
data DollarGestureEventData Source #
Complex gesture event information.
DollarGestureEventData | |
|
Instances
Drag and drop events
newtype DropEventData Source #
An event used to request a file open by the system
DropEventData | |
|
Instances
Unknown events
newtype UnknownEventData Source #
SDL reported an unknown event type.
UnknownEventData | |
|
Instances
Auxiliary event data
data InputMotion Source #
Instances
data MouseButton Source #
ButtonLeft | |
ButtonMiddle | |
ButtonRight | |
ButtonX1 | |
ButtonX2 | |
ButtonExtra !Int | An unknown mouse button. |