| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
SDL3.Sys.Events
Contents
Description
Event queue management.
It's extremely common often required that an app deal with SDL's event queue. Almost all useful information about interactions with the real world flow through here: the user interacting with the computer and app, hardware coming and going, the system changing in some way, etc.
An app generally takes a moment, perhaps at the start of a new frame, to examine any events that have occurred since the last time and process or ignore them. This is generally done by calling in a loop until it returns false (or, if using the main callbacks, events are provided one at a time in calls to SDL_AppEvent() before the next call to SDL_AppIterate(); in this scenario, the app does not call pollEvent at all).pollEvent
There is other forms of control, too: has more functionality at the cost of more complexity, and peepEvents can block the process until something interesting happens, which might be beneficial for certain types of programs on low-power hardware. One may also call waitEvent to set a callback when new events arrive.addEventWatch
The app is free to generate their own events, too: pushEvent allows the app to put events onto the queue for later retrieval; registerEvents can guarantee that these events have a type that isn't in use by other parts of the system. The types of events that can be delivered.
FFI conventions
Unsuffixed aliases are unsafe foreign imports; aliases suffixed Safe are safe. Functions whose callbacks fire during the call export only the Safe alias (the genuine unsafe import stays reachable under SDL3.Sys.Bindgen.Events.Unsafe); functions curated unsafe-only export only the unsuffixed one. Each alias's documentation records its flavor and rationale.
Full conventions: SDL3.Sys.
Reading events
SDL_Event is a C union: poll into an alloca buffer, read the event-type discriminant first, then peek the payload member for that type. The sdl3-raw example in the repository shows the full idiom; pollEvent and the SDL_EVENT_* patterns live in this module.
Since: 3.2.0
Synopsis
- module SDL3.Sys.Bindgen.Events
- pumpEvents :: IO ()
- pumpEventsSafe :: IO ()
- peepEvents :: Ptr SDL_Event -> Int32 -> SDL_EventAction -> Word32 -> Word32 -> IO Int32
- peepEventsSafe :: Ptr SDL_Event -> Int32 -> SDL_EventAction -> Word32 -> Word32 -> IO Int32
- hasEvent :: Word32 -> IO Bool
- hasEventSafe :: Word32 -> IO Bool
- hasEvents :: Word32 -> Word32 -> IO Bool
- hasEventsSafe :: Word32 -> Word32 -> IO Bool
- flushEvent :: Word32 -> IO ()
- flushEventSafe :: Word32 -> IO ()
- flushEvents :: Word32 -> Word32 -> IO ()
- flushEventsSafe :: Word32 -> Word32 -> IO ()
- pollEvent :: Ptr SDL_Event -> IO Bool
- pollEventSafe :: Ptr SDL_Event -> IO Bool
- waitEvent :: Ptr SDL_Event -> IO Bool
- waitEventSafe :: Ptr SDL_Event -> IO Bool
- waitEventTimeout :: Ptr SDL_Event -> Int32 -> IO Bool
- waitEventTimeoutSafe :: Ptr SDL_Event -> Int32 -> IO Bool
- pushEvent :: Ptr SDL_Event -> IO Bool
- pushEventSafe :: Ptr SDL_Event -> IO Bool
- setEventFilter :: SDL_EventFilter -> Ptr Void -> IO ()
- setEventFilterSafe :: SDL_EventFilter -> Ptr Void -> IO ()
- getEventFilter :: Ptr SDL_EventFilter -> Ptr (Ptr Void) -> IO Bool
- getEventFilterSafe :: Ptr SDL_EventFilter -> Ptr (Ptr Void) -> IO Bool
- addEventWatch :: SDL_EventFilter -> Ptr Void -> IO Bool
- addEventWatchSafe :: SDL_EventFilter -> Ptr Void -> IO Bool
- removeEventWatch :: SDL_EventFilter -> Ptr Void -> IO ()
- removeEventWatchSafe :: SDL_EventFilter -> Ptr Void -> IO ()
- filterEventsSafe :: SDL_EventFilter -> Ptr Void -> IO ()
- setEventEnabled :: Word32 -> Bool -> IO ()
- setEventEnabledSafe :: Word32 -> Bool -> IO ()
- eventEnabled :: Word32 -> IO Bool
- eventEnabledSafe :: Word32 -> IO Bool
- registerEvents :: Int32 -> IO Word32
- registerEventsSafe :: Int32 -> IO Word32
- getWindowFromEvent :: PtrConst SDL_Event -> IO (Ptr SDL_Window)
- getWindowFromEventSafe :: PtrConst SDL_Event -> IO (Ptr SDL_Window)
- getEventDescription :: PtrConst SDL_Event -> Ptr CChar -> Int32 -> IO Int32
- getEventDescriptionSafe :: PtrConst SDL_Event -> Ptr CChar -> Int32 -> IO Int32
Documentation
module SDL3.Sys.Bindgen.Events
Function aliases
pumpEvents :: IO () Source #
Pump the event loop, gathering events from the input devices.
This function updates the event queue and internal input device state.
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 pumpEvents and pollEvent implicitly call waitEvent. 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.pumpEvents
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_PumpEvents. The safe flavor ispumpEventsSafe: may re-enter registered watchers/filters/hit tests. - C declaration
SDL_PumpEvents, defined atSDL3/SDL_events.h 1106:34
Since: 3.2.0
pumpEventsSafe :: IO () Source #
Pump the event loop, gathering events from the input devices.
This function updates the event queue and internal input device state.
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 pumpEvents and pollEvent implicitly call waitEvent. 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.pumpEvents
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_PumpEvents. The unsafe flavor ispumpEvents: may re-enter registered watchers/filters/hit tests. - C declaration
SDL_PumpEvents, defined atSDL3/SDL_events.h 1106:34
Since: 3.2.0
Arguments
| :: Ptr SDL_Event |
|
| -> Int32 |
|
| -> SDL_EventAction |
|
| -> Word32 |
|
| -> Word32 |
|
| -> IO Int32 |
Check the event queue for messages and optionally return them.
action may be any of the following:
SDL_ADDEVENT: up tonumeventsevents will be added to the back of the event queue.SDL_PEEKEVENT:numeventsevents at the front of the event queue, within the specified minimum and maximum type, will be returned to the caller and will not be removed from the queue. If you pass NULL forevents, thennumeventsis ignored and the total number of matching events will be returned.SDL_GETEVENT: up tonumeventsevents at the front of the event queue, within the specified minimum and maximum type, will be returned to the caller and will be removed from the queue.
You may have to call before calling this function. Otherwise, the events may not be ready to be filtered when you call pumpEvents.peepEvents
- Returns
- the number of events actually stored or -1 on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
pollEvent,pumpEvents,pushEvent
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_PeepEvents. The safe flavor ispeepEventsSafe: SDL_ADDEVENT runs registered event filters/watchers synchronously. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_PeepEvents, defined atSDL3/SDL_events.h 1164:33
Since: 3.2.0
Arguments
| :: Ptr SDL_Event |
|
| -> Int32 |
|
| -> SDL_EventAction |
|
| -> Word32 |
|
| -> Word32 |
|
| -> IO Int32 |
Check the event queue for messages and optionally return them.
action may be any of the following:
SDL_ADDEVENT: up tonumeventsevents will be added to the back of the event queue.SDL_PEEKEVENT:numeventsevents at the front of the event queue, within the specified minimum and maximum type, will be returned to the caller and will not be removed from the queue. If you pass NULL forevents, thennumeventsis ignored and the total number of matching events will be returned.SDL_GETEVENT: up tonumeventsevents at the front of the event queue, within the specified minimum and maximum type, will be returned to the caller and will be removed from the queue.
You may have to call before calling this function. Otherwise, the events may not be ready to be filtered when you call pumpEvents.peepEvents
- Returns
- the number of events actually stored or -1 on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
pollEvent,pumpEvents,pushEvent
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_PeepEvents. The unsafe flavor ispeepEvents: SDL_ADDEVENT runs registered event filters/watchers synchronously. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_PeepEvents, defined atSDL3/SDL_events.h 1164:33
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> IO Bool |
Check for the existence of a certain event type in the event queue.
If you need to check for a range of event types, use instead.hasEvents
- Returns
- true if events matching
typeare present, or false if events matchingtypeare not present. - Thread safety
- It is safe to call this function from any thread.
- See also
hasEvents
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_HasEvent. The safe flavor ishasEventSafe. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_HasEvent, defined atSDL3/SDL_events.h 1183:34
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> IO Bool |
Check for the existence of a certain event type in the event queue.
If you need to check for a range of event types, use instead.hasEvents
- Returns
- true if events matching
typeare present, or false if events matchingtypeare not present. - Thread safety
- It is safe to call this function from any thread.
- See also
hasEvents
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_HasEvent. The unsafe flavor ishasEvent. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_HasEvent, defined atSDL3/SDL_events.h 1183:34
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> Word32 |
|
| -> IO Bool |
Check for the existence of certain event types in the event queue.
If you need to check for a single event type, use instead.hasEvent
- Returns
- true if events with type >=
minTypeand <=maxTypeare present, or false if not. - Thread safety
- It is safe to call this function from any thread.
- See also
hasEvents
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_HasEvents. The safe flavor ishasEventsSafe. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_HasEvents, defined atSDL3/SDL_events.h 1204:34
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> Word32 |
|
| -> IO Bool |
Check for the existence of certain event types in the event queue.
If you need to check for a single event type, use instead.hasEvent
- Returns
- true if events with type >=
minTypeand <=maxTypeare present, or false if not. - Thread safety
- It is safe to call this function from any thread.
- See also
hasEvents
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_HasEvents. The unsafe flavor ishasEvents. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_HasEvents, defined atSDL3/SDL_events.h 1204:34
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> IO () |
Clear events of a specific type from the event queue.
This will unconditionally remove any events from the queue that match type. If you need to remove a range of event types, use instead.flushEvents
It's also normal to just ignore events you don't care about in your event loop without calling this function.
This function only affects currently queued events. If you want to make sure that all pending OS events are flushed, you can call on the main thread immediately before the flush call.pumpEvents
If you have user events with custom data that needs to be freed, you should use to remove and clean up those events before calling this function.peepEvents
- Thread safety
- It is safe to call this function from any thread.
- See also
flushEvents
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_FlushEvent. The safe flavor isflushEventSafe. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_FlushEvent, defined atSDL3/SDL_events.h 1232:34
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> IO () |
Clear events of a specific type from the event queue.
This will unconditionally remove any events from the queue that match type. If you need to remove a range of event types, use instead.flushEvents
It's also normal to just ignore events you don't care about in your event loop without calling this function.
This function only affects currently queued events. If you want to make sure that all pending OS events are flushed, you can call on the main thread immediately before the flush call.pumpEvents
If you have user events with custom data that needs to be freed, you should use to remove and clean up those events before calling this function.peepEvents
- Thread safety
- It is safe to call this function from any thread.
- See also
flushEvents
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_FlushEvent. The unsafe flavor isflushEvent. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_FlushEvent, defined atSDL3/SDL_events.h 1232:34
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> Word32 |
|
| -> IO () |
Clear events of a range of types from the event queue.
This will unconditionally remove any events from the queue that are in the range of minType to maxType, inclusive. If you need to remove a single event type, use instead.flushEvent
It's also normal to just ignore events you don't care about in your event loop without calling this function.
This function only affects currently queued events. If you want to make sure that all pending OS events are flushed, you can call on the main thread immediately before the flush call.pumpEvents
- Thread safety
- It is safe to call this function from any thread.
- See also
flushEvent
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_FlushEvents. The safe flavor isflushEventsSafe. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_FlushEvents, defined atSDL3/SDL_events.h 1259:34
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> Word32 |
|
| -> IO () |
Clear events of a range of types from the event queue.
This will unconditionally remove any events from the queue that are in the range of minType to maxType, inclusive. If you need to remove a single event type, use instead.flushEvent
It's also normal to just ignore events you don't care about in your event loop without calling this function.
This function only affects currently queued events. If you want to make sure that all pending OS events are flushed, you can call on the main thread immediately before the flush call.pumpEvents
- Thread safety
- It is safe to call this function from any thread.
- See also
flushEvent
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_FlushEvents. The unsafe flavor isflushEvents. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_FlushEvents, defined atSDL3/SDL_events.h 1259:34
Since: 3.2.0
Arguments
| :: Ptr SDL_Event |
|
| -> IO Bool |
Poll for currently pending events.
If event is not NULL, the next event is removed from the queue and stored in the SDL_Event structure pointed to by event.
If event is NULL, it simply returns true if there is an event in the queue, but will not remove it from the queue.
As this function may implicitly call , you can only call this function in the thread that initialized the video subsystem.pumpEvents
is the favored way of receiving system events since it can be done from the main loop and does not suspend the main loop while waiting on an event to be posted.pollEvent
The common practice is to fully process the event queue once every frame, usually as a first step before updating the game's state:
while (game_is_still_running) {
SDL_Event event;
while (SDL_PollEvent(&event)) { // poll until all events are handled!
// decide what to do with this event.
}
// update game state, draw the current frame
}
Note that Windows (and possibly other platforms) has a quirk about how it handles events while dragging/resizing a window, which can cause this function to block for significant amounts of time. Technical explanations and solutions are discussed on the wiki:
https://wiki.libsdl.org/SDL3/AppFreezeDuringDrag
- Returns
- true if this got an event or false if there are none available.
- Thread safety
- This function should only be called on the main thread.
- See also
pushEvent,waitEvent,waitEventTimeout
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_PollEvent. The safe flavor ispollEventSafe: pumps events; may re-enter registered watchers/filters/hit tests. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_PollEvent, defined atSDL3/SDL_events.h 1310:34
Since: 3.2.0
Arguments
| :: Ptr SDL_Event |
|
| -> IO Bool |
Poll for currently pending events.
If event is not NULL, the next event is removed from the queue and stored in the SDL_Event structure pointed to by event.
If event is NULL, it simply returns true if there is an event in the queue, but will not remove it from the queue.
As this function may implicitly call , you can only call this function in the thread that initialized the video subsystem.pumpEvents
is the favored way of receiving system events since it can be done from the main loop and does not suspend the main loop while waiting on an event to be posted.pollEvent
The common practice is to fully process the event queue once every frame, usually as a first step before updating the game's state:
while (game_is_still_running) {
SDL_Event event;
while (SDL_PollEvent(&event)) { // poll until all events are handled!
// decide what to do with this event.
}
// update game state, draw the current frame
}
Note that Windows (and possibly other platforms) has a quirk about how it handles events while dragging/resizing a window, which can cause this function to block for significant amounts of time. Technical explanations and solutions are discussed on the wiki:
https://wiki.libsdl.org/SDL3/AppFreezeDuringDrag
- Returns
- true if this got an event or false if there are none available.
- Thread safety
- This function should only be called on the main thread.
- See also
pushEvent,waitEvent,waitEventTimeout
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_PollEvent. The unsafe flavor ispollEvent: pumps events; may re-enter registered watchers/filters/hit tests. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_PollEvent, defined atSDL3/SDL_events.h 1310:34
Since: 3.2.0
Arguments
| :: Ptr SDL_Event |
|
| -> IO Bool |
Wait indefinitely for the next available event.
If event is not NULL, the next event is removed from the queue and stored in the SDL_Event structure pointed to by event.
As this function may implicitly call , you can only call this function in the thread that initialized the video subsystem.pumpEvents
- Returns
- true on success or false if there was an error while waiting for events; call
getErrorfor more information. - Thread safety
- This function should only be called on the main thread.
- See also
pollEvent,pushEvent,waitEventTimeout
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_WaitEvent. The safe flavor iswaitEventSafe: blocks the calling capability; a blocking unsafe call stalls GC program-wide. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_WaitEvent, defined atSDL3/SDL_events.h 1334:34
Since: 3.2.0
Arguments
| :: Ptr SDL_Event |
|
| -> IO Bool |
Wait indefinitely for the next available event.
If event is not NULL, the next event is removed from the queue and stored in the SDL_Event structure pointed to by event.
As this function may implicitly call , you can only call this function in the thread that initialized the video subsystem.pumpEvents
- Returns
- true on success or false if there was an error while waiting for events; call
getErrorfor more information. - Thread safety
- This function should only be called on the main thread.
- See also
pollEvent,pushEvent,waitEventTimeout
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_WaitEvent. The unsafe flavor iswaitEvent: blocks the calling capability; a blocking unsafe call stalls GC program-wide. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_WaitEvent, defined atSDL3/SDL_events.h 1334:34
Since: 3.2.0
Arguments
| :: Ptr SDL_Event |
|
| -> Int32 |
|
| -> IO Bool |
Wait until the specified timeout (in milliseconds) for the next available event.
If event is not NULL, the next event is removed from the queue and stored in the SDL_Event structure pointed to by event.
As this function may implicitly call , you can only call this function in the thread that initialized the video subsystem.pumpEvents
The timeout is not guaranteed, the actual wait time could be longer due to system scheduling.
- Returns
- true if this got an event or false if the timeout elapsed without any events available.
- Thread safety
- This function should only be called on the main thread.
- See also
pollEvent,pushEvent,waitEvent
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_WaitEventTimeout. The safe flavor iswaitEventTimeoutSafe: blocks up to the timeout. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_WaitEventTimeout, defined atSDL3/SDL_events.h 1364:34
Since: 3.2.0
Arguments
| :: Ptr SDL_Event |
|
| -> Int32 |
|
| -> IO Bool |
Wait until the specified timeout (in milliseconds) for the next available event.
If event is not NULL, the next event is removed from the queue and stored in the SDL_Event structure pointed to by event.
As this function may implicitly call , you can only call this function in the thread that initialized the video subsystem.pumpEvents
The timeout is not guaranteed, the actual wait time could be longer due to system scheduling.
- Returns
- true if this got an event or false if the timeout elapsed without any events available.
- Thread safety
- This function should only be called on the main thread.
- See also
pollEvent,pushEvent,waitEvent
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_WaitEventTimeout. The unsafe flavor iswaitEventTimeout: blocks up to the timeout. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_WaitEventTimeout, defined atSDL3/SDL_events.h 1364:34
Since: 3.2.0
Add an event to the event queue.
The event queue can actually be used as a two way communication channel. Not only can events be read from the queue, but the user can also push their own events onto it. event is a pointer to the event structure you wish to push onto the queue. The event is copied into the queue, and the caller may dispose of the memory pointed to after returns.pushEvent
Note: Pushing device input events onto the queue doesn't modify the state of the device within SDL.
Note: Events pushed onto the queue with get passed through the event filter but events added with pushEvent do not.peepEvents
For pushing application-specific events, please use to get an event type that does not conflict with other code that also wants its own custom event types.registerEvents
- Returns
- true on success, false if the event was filtered or on failure; call
getErrorfor more information. A common reason for error is the event queue being full. - Thread safety
- It is safe to call this function from any thread.
- See also
peepEvents,pollEvent,registerEvents
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_PushEvent. The safe flavor ispushEventSafe: runs registered event filters/watchers synchronously. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_PushEvent, defined atSDL3/SDL_events.h 1398:34
Since: 3.2.0
Add an event to the event queue.
The event queue can actually be used as a two way communication channel. Not only can events be read from the queue, but the user can also push their own events onto it. event is a pointer to the event structure you wish to push onto the queue. The event is copied into the queue, and the caller may dispose of the memory pointed to after returns.pushEvent
Note: Pushing device input events onto the queue doesn't modify the state of the device within SDL.
Note: Events pushed onto the queue with get passed through the event filter but events added with pushEvent do not.peepEvents
For pushing application-specific events, please use to get an event type that does not conflict with other code that also wants its own custom event types.registerEvents
- Returns
- true on success, false if the event was filtered or on failure; call
getErrorfor more information. A common reason for error is the event queue being full. - Thread safety
- It is safe to call this function from any thread.
- See also
peepEvents,pollEvent,registerEvents
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_PushEvent. The unsafe flavor ispushEvent: runs registered event filters/watchers synchronously. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_PushEvent, defined atSDL3/SDL_events.h 1398:34
Since: 3.2.0
Arguments
| :: SDL_EventFilter |
|
| -> Ptr Void |
|
| -> IO () |
Set up a filter to process all events before they are added to the internal event queue.
If you just want to see events without modifying them or preventing them from being queued, you should use instead.addEventWatch
If the filter function returns true when called, then the event will be added to the internal queue. If it returns false, then the event will be dropped from the queue, but the internal state will still be updated. This allows selective filtering of dynamically arriving events.
WARNING: Be very careful of what you do in the event filter function, as it may run in a different thread! The exception is handling of SDL_EVENT_WINDOW_EXPOSED, which is guaranteed to be sent from the OS on the main thread and you are expected to redraw your window in response to this event.
On platforms that support it, if the quit event is generated by an interrupt signal (e.g. pressing Ctrl-C), it will be delivered to the application at the next event poll.
Note: Disabled events never make it to the event filter function; see .setEventEnabled
Note: Events pushed onto the queue with get passed through the event filter, but events pushed onto the queue with pushEvent do not.peepEvents
- Thread safety
- It is safe to call this function from any thread.
- See also
addEventWatch,setEventEnabled,getEventFilter,peepEvents,pushEvent
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_SetEventFilter. The safe flavor issetEventFilterSafe: registration; the filter runs from later event calls. - C declaration
SDL_SetEventFilter, defined atSDL3/SDL_events.h 1463:34
Since: 3.2.0
Arguments
| :: SDL_EventFilter |
|
| -> Ptr Void |
|
| -> IO () |
Set up a filter to process all events before they are added to the internal event queue.
If you just want to see events without modifying them or preventing them from being queued, you should use instead.addEventWatch
If the filter function returns true when called, then the event will be added to the internal queue. If it returns false, then the event will be dropped from the queue, but the internal state will still be updated. This allows selective filtering of dynamically arriving events.
WARNING: Be very careful of what you do in the event filter function, as it may run in a different thread! The exception is handling of SDL_EVENT_WINDOW_EXPOSED, which is guaranteed to be sent from the OS on the main thread and you are expected to redraw your window in response to this event.
On platforms that support it, if the quit event is generated by an interrupt signal (e.g. pressing Ctrl-C), it will be delivered to the application at the next event poll.
Note: Disabled events never make it to the event filter function; see .setEventEnabled
Note: Events pushed onto the queue with get passed through the event filter, but events pushed onto the queue with pushEvent do not.peepEvents
- Thread safety
- It is safe to call this function from any thread.
- See also
addEventWatch,setEventEnabled,getEventFilter,peepEvents,pushEvent
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_SetEventFilter. The unsafe flavor issetEventFilter: registration; the filter runs from later event calls. - C declaration
SDL_SetEventFilter, defined atSDL3/SDL_events.h 1463:34
Since: 3.2.0
Arguments
| :: Ptr SDL_EventFilter |
|
| -> Ptr (Ptr Void) |
|
| -> IO Bool |
Query the current event filter.
This function can be used to "chain" filters, by saving the existing filter before replacing it with a function that will call that saved filter.
- Returns
- true on success or false if there is no event filter set.
- Thread safety
- It is safe to call this function from any thread.
- See also
setEventFilter
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetEventFilter. The safe flavor isgetEventFilterSafe. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_GetEventFilter, defined atSDL3/SDL_events.h 1482:34
Since: 3.2.0
Arguments
| :: Ptr SDL_EventFilter |
|
| -> Ptr (Ptr Void) |
|
| -> IO Bool |
Query the current event filter.
This function can be used to "chain" filters, by saving the existing filter before replacing it with a function that will call that saved filter.
- Returns
- true on success or false if there is no event filter set.
- Thread safety
- It is safe to call this function from any thread.
- See also
setEventFilter
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_GetEventFilter. The unsafe flavor isgetEventFilter. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_GetEventFilter, defined atSDL3/SDL_events.h 1482:34
Since: 3.2.0
Arguments
| :: SDL_EventFilter |
|
| -> Ptr Void |
|
| -> IO Bool |
Add a callback to be triggered when an event is added to the event queue.
filter will be called when an event happens, and its return value is ignored.
WARNING: Be very careful of what you do in the event filter function, as it may run in a different thread!
If the quit event is generated by a signal (e.g. SIGINT), it will bypass the internal queue and be delivered to the watch callback immediately, and arrive at the next event poll.
Note: the callback is called for events posted by the user through , but not for disabled events, nor for events by a filter callback set with pushEvent, nor for events posted by the user through setEventFilter.peepEvents
- Returns
- true on success or false on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
removeEventWatch,setEventFilter
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_AddEventWatch. The safe flavor isaddEventWatchSafe: registration; the watch runs from later event pumping. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_AddEventWatch, defined atSDL3/SDL_events.h 1514:34
Since: 3.2.0
Arguments
| :: SDL_EventFilter |
|
| -> Ptr Void |
|
| -> IO Bool |
Add a callback to be triggered when an event is added to the event queue.
filter will be called when an event happens, and its return value is ignored.
WARNING: Be very careful of what you do in the event filter function, as it may run in a different thread!
If the quit event is generated by a signal (e.g. SIGINT), it will bypass the internal queue and be delivered to the watch callback immediately, and arrive at the next event poll.
Note: the callback is called for events posted by the user through , but not for disabled events, nor for events by a filter callback set with pushEvent, nor for events posted by the user through setEventFilter.peepEvents
- Returns
- true on success or false on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
removeEventWatch,setEventFilter
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_AddEventWatch. The unsafe flavor isaddEventWatch: registration; the watch runs from later event pumping. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_AddEventWatch, defined atSDL3/SDL_events.h 1514:34
Since: 3.2.0
Arguments
| :: SDL_EventFilter |
|
| -> Ptr Void |
|
| -> IO () |
Remove an event watch callback added with .addEventWatch
This function takes the same input as to identify and delete the corresponding callback.addEventWatch
- Thread safety
- It is safe to call this function from any thread.
- See also
addEventWatch
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_RemoveEventWatch. The safe flavor isremoveEventWatchSafe: deregistration only. - C declaration
SDL_RemoveEventWatch, defined atSDL3/SDL_events.h 1531:34
Since: 3.2.0
Arguments
| :: SDL_EventFilter |
|
| -> Ptr Void |
|
| -> IO () |
Remove an event watch callback added with .addEventWatch
This function takes the same input as to identify and delete the corresponding callback.addEventWatch
- Thread safety
- It is safe to call this function from any thread.
- See also
addEventWatch
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_RemoveEventWatch. The unsafe flavor isremoveEventWatch: deregistration only. - C declaration
SDL_RemoveEventWatch, defined atSDL3/SDL_events.h 1531:34
Since: 3.2.0
Arguments
| :: SDL_EventFilter |
|
| -> Ptr Void |
|
| -> IO () |
Run a specific filter function on the current event queue, removing any events for which the filter returns false.
See for more information. Unlike setEventFilter, this function does not change the filter permanently, it only uses the supplied filter until this function returns.setEventFilter
- Thread safety
- It is safe to call this function from any thread.
- See also
getEventFilter,setEventFilter
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_FilterEvents. The unsafe import is not exported : runs the filter over the queue synchronously. If your callback is a non-Haskell function pointer that never re-enters the Haskell runtime, the unsafe import remains available asSDL3.Sys.Bindgen.Events.Unsafe.sDL_FilterEvents. - C declaration
SDL_FilterEvents, defined atSDL3/SDL_events.h 1551:34
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> Bool |
|
| -> IO () |
Set the state of processing events by type.
- Thread safety
- It is safe to call this function from any thread.
- See also
eventEnabled
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_SetEventEnabled. The safe flavor issetEventEnabledSafe. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_SetEventEnabled, defined atSDL3/SDL_events.h 1565:34
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> Bool |
|
| -> IO () |
Set the state of processing events by type.
- Thread safety
- It is safe to call this function from any thread.
- See also
eventEnabled
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_SetEventEnabled. The unsafe flavor issetEventEnabled. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_SetEventEnabled, defined atSDL3/SDL_events.h 1565:34
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> IO Bool |
Query the state of processing events by type.
- Returns
- true if the event is being processed, false otherwise.
- Thread safety
- It is safe to call this function from any thread.
- See also
setEventEnabled
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_EventEnabled. The safe flavor iseventEnabledSafe. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_EventEnabled, defined atSDL3/SDL_events.h 1579:34
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> IO Bool |
Query the state of processing events by type.
- Returns
- true if the event is being processed, false otherwise.
- Thread safety
- It is safe to call this function from any thread.
- See also
setEventEnabled
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_EventEnabled. The unsafe flavor iseventEnabled. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_EventEnabled, defined atSDL3/SDL_events.h 1579:34
Since: 3.2.0
Allocate a set of user-defined events, and return the beginning event number for that set of events.
- Returns
- the beginning event number, or 0 if numevents is invalid or if there are not enough user-defined events left.
- Thread safety
- It is safe to call this function from any thread.
- See also
pushEvent
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_RegisterEvents. The safe flavor isregisterEventsSafe. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_RegisterEvents, defined atSDL3/SDL_events.h 1595:36
Since: 3.2.0
Allocate a set of user-defined events, and return the beginning event number for that set of events.
- Returns
- the beginning event number, or 0 if numevents is invalid or if there are not enough user-defined events left.
- Thread safety
- It is safe to call this function from any thread.
- See also
pushEvent
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_RegisterEvents. The unsafe flavor isregisterEvents. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_RegisterEvents, defined atSDL3/SDL_events.h 1595:36
Since: 3.2.0
Arguments
| :: PtrConst SDL_Event |
|
| -> IO (Ptr SDL_Window) |
Get window associated with an event.
- Returns
- the associated window on success or NULL if there is none.
- Thread safety
- It is safe to call this function from any thread.
- See also
pollEvent,waitEvent,waitEventTimeout
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetWindowFromEvent. The safe flavor isgetWindowFromEventSafe. - C declaration
SDL_GetWindowFromEvent, defined atSDL3/SDL_events.h 1611:42
Since: 3.2.0
getWindowFromEventSafe Source #
Arguments
| :: PtrConst SDL_Event |
|
| -> IO (Ptr SDL_Window) |
Get window associated with an event.
- Returns
- the associated window on success or NULL if there is none.
- Thread safety
- It is safe to call this function from any thread.
- See also
pollEvent,waitEvent,waitEventTimeout
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_GetWindowFromEvent. The unsafe flavor isgetWindowFromEvent. - C declaration
SDL_GetWindowFromEvent, defined atSDL3/SDL_events.h 1611:42
Since: 3.2.0
Arguments
| :: PtrConst SDL_Event |
|
| -> Ptr CChar |
|
| -> Int32 |
|
| -> IO Int32 |
Generate an English description of an event.
This will fill buf with a null-terminated string that might look something like this:
SDL_EVENT_MOUSE_MOTION (timestamp=1140256324 windowid=2 which=0 state=0 x=492.99 y=139.09 xrel=52 yrel=6)
The exact format of the string is not guaranteed; it is intended for logging purposes, to be read by a human, and not parsed by a computer.
The returned value follows the same rules as SDL_snprintf(): buf will always be NULL-terminated (unless buflen is zero), and will be truncated if buflen is too small. The return code is the number of bytes needed for the complete string, not counting the NULL-terminator, whether the string was truncated or not. Unlike SDL_snprintf(), though, this function never returns -1.
- Returns
- number of bytes needed for the full string, not counting the null-terminator byte.
- Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetEventDescription. The safe flavor isgetEventDescriptionSafe. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_GetEventDescription, defined atSDL3/SDL_events.h 1643:33
Since: 3.4.0
getEventDescriptionSafe Source #
Arguments
| :: PtrConst SDL_Event |
|
| -> Ptr CChar |
|
| -> Int32 |
|
| -> IO Int32 |
Generate an English description of an event.
This will fill buf with a null-terminated string that might look something like this:
SDL_EVENT_MOUSE_MOTION (timestamp=1140256324 windowid=2 which=0 state=0 x=492.99 y=139.09 xrel=52 yrel=6)
The exact format of the string is not guaranteed; it is intended for logging purposes, to be read by a human, and not parsed by a computer.
The returned value follows the same rules as SDL_snprintf(): buf will always be NULL-terminated (unless buflen is zero), and will be truncated if buflen is too small. The return code is the number of bytes needed for the complete string, not counting the NULL-terminator, whether the string was truncated or not. Unlike SDL_snprintf(), though, this function never returns -1.
- Returns
- number of bytes needed for the full string, not counting the null-terminator byte.
- Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_GetEventDescription. The unsafe flavor isgetEventDescription. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_GetEventDescription, defined atSDL3/SDL_events.h 1643:33
Since: 3.4.0