| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
SDL3.Sys.Bindgen.Events.FunPtr
Synopsis
- sDL_PumpEvents :: FunPtr (IO ())
- sDL_PeepEvents :: FunPtr (Ptr SDL_Event -> CInt -> SDL_EventAction -> Uint32 -> Uint32 -> IO CInt)
- sDL_HasEvent :: FunPtr (Uint32 -> IO CBool)
- sDL_HasEvents :: FunPtr (Uint32 -> Uint32 -> IO CBool)
- sDL_FlushEvent :: FunPtr (Uint32 -> IO ())
- sDL_FlushEvents :: FunPtr (Uint32 -> Uint32 -> IO ())
- sDL_PollEvent :: FunPtr (Ptr SDL_Event -> IO CBool)
- sDL_WaitEvent :: FunPtr (Ptr SDL_Event -> IO CBool)
- sDL_WaitEventTimeout :: FunPtr (Ptr SDL_Event -> Sint32 -> IO CBool)
- sDL_PushEvent :: FunPtr (Ptr SDL_Event -> IO CBool)
- sDL_SetEventFilter :: FunPtr (SDL_EventFilter -> Ptr Void -> IO ())
- sDL_GetEventFilter :: FunPtr (Ptr SDL_EventFilter -> Ptr (Ptr Void) -> IO CBool)
- sDL_AddEventWatch :: FunPtr (SDL_EventFilter -> Ptr Void -> IO CBool)
- sDL_RemoveEventWatch :: FunPtr (SDL_EventFilter -> Ptr Void -> IO ())
- sDL_FilterEvents :: FunPtr (SDL_EventFilter -> Ptr Void -> IO ())
- sDL_SetEventEnabled :: FunPtr (Uint32 -> CBool -> IO ())
- sDL_EventEnabled :: FunPtr (Uint32 -> IO CBool)
- sDL_RegisterEvents :: FunPtr (CInt -> IO Uint32)
- sDL_GetWindowFromEvent :: FunPtr (PtrConst SDL_Event -> IO (Ptr SDL_Window))
- sDL_GetEventDescription :: FunPtr (PtrConst SDL_Event -> Ptr CChar -> CInt -> IO CInt)
Documentation
sDL_PumpEvents :: FunPtr (IO ()) Source #
Pump the event loop, gathering events from the input devices.
This function updates the event queue and internal input device state.
SDL_PumpEvents() gathers all the pending input information from devices and places it in the event queue. Without calls to SDL_PumpEvents() no events would ever be placed on the queue. Often the need for calls to SDL_PumpEvents() is hidden from the user since SDL_PollEvent() and SDL_WaitEvent() implicitly call SDL_PumpEvents(). However, if you are not polling or waiting for events (e.g. you are filtering them), then you must call SDL_PumpEvents() to force an event queue update.
- Thread safety
- This function should only be called on the main thread.
- See also
sDL_PollEvent,sDL_WaitEvent- C declaration
SDL_PumpEvents, defined atSDL3/SDL_events.h 1106:34
Since: 3.2.0
sDL_PeepEvents :: FunPtr (Ptr SDL_Event -> CInt -> SDL_EventAction -> Uint32 -> Uint32 -> IO CInt) Source #
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 SDL_PumpEvents() before calling this function. Otherwise, the events may not be ready to be filtered when you call SDL_PeepEvents().
events- destination buffer for the retrieved events, may be NULL to leave the events in the queue and return the number of events that would have been stored.
numevents- if action is SDL_ADDEVENT, the number of events to add back to the event queue; if action is SDL_PEEKEVENT or SDL_GETEVENT, the maximum number of events to retrieve.
action- action to take; see RemarksRemarks for details.
minType- minimum value of the event type to be considered; SDL_EVENT_FIRST is a safe choice.
maxType- maximum value of the event type to be considered; SDL_EVENT_LAST is a safe choice.
- Returns
- the number of events actually stored or -1 on failure; call SDL_GetError() for more information.
- Thread safety
- It is safe to call this function from any thread.
- See also
sDL_PollEvent,sDL_PumpEvents,sDL_PushEvent- C declaration
SDL_PeepEvents, defined atSDL3/SDL_events.h 1164:33
Since: 3.2.0
sDL_HasEvent :: FunPtr (Uint32 -> IO CBool) Source #
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 SDL_HasEvents() instead.
type- the type of event to be queried; see
SDL_EventTypefor details. - 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
sDL_HasEvents- C declaration
SDL_HasEvent, defined atSDL3/SDL_events.h 1183:34
Since: 3.2.0
sDL_HasEvents :: FunPtr (Uint32 -> Uint32 -> IO CBool) Source #
Check for the existence of certain event types in the event queue.
If you need to check for a single event type, use SDL_HasEvent() instead.
minType- the low end of event type to be queried, inclusive; see
SDL_EventTypefor details. maxType- the high end of event type to be queried, inclusive; see
SDL_EventTypefor details. - 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
sDL_HasEvents- C declaration
SDL_HasEvents, defined atSDL3/SDL_events.h 1204:34
Since: 3.2.0
sDL_FlushEvent :: FunPtr (Uint32 -> IO ()) Source #
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 SDL_FlushEvents() instead.
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 SDL_PumpEvents() on the main thread immediately before the flush call.
If you have user events with custom data that needs to be freed, you should use SDL_PeepEvents() to remove and clean up those events before calling this function.
type- the type of event to be cleared; see
SDL_EventTypefor details. - Thread safety
- It is safe to call this function from any thread.
- See also
sDL_FlushEvents- C declaration
SDL_FlushEvent, defined atSDL3/SDL_events.h 1232:34
Since: 3.2.0
sDL_FlushEvents :: FunPtr (Uint32 -> Uint32 -> IO ()) Source #
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 SDL_FlushEvent() instead.
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 SDL_PumpEvents() on the main thread immediately before the flush call.
minType- the low end of event type to be cleared, inclusive; see
SDL_EventTypefor details. maxType- the high end of event type to be cleared, inclusive; see
SDL_EventTypefor details. - Thread safety
- It is safe to call this function from any thread.
- See also
sDL_FlushEvent- C declaration
SDL_FlushEvents, defined atSDL3/SDL_events.h 1259:34
Since: 3.2.0
sDL_PollEvent :: FunPtr (Ptr SDL_Event -> IO CBool) Source #
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 SDL_PumpEvents(), you can only call this function in the thread that initialized the video subsystem.
SDL_PollEvent() 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.
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
event- the
SDL_Eventstructure to be filled with the next event from the queue, or NULL. - 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
sDL_PushEvent,sDL_WaitEvent,sDL_WaitEventTimeout- C declaration
SDL_PollEvent, defined atSDL3/SDL_events.h 1310:34
Since: 3.2.0
sDL_WaitEvent :: FunPtr (Ptr SDL_Event -> IO CBool) Source #
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 SDL_PumpEvents(), you can only call this function in the thread that initialized the video subsystem.
event- the
SDL_Eventstructure to be filled in with the next event from the queue, or NULL. - Returns
- true on success or false if there was an error while waiting for events; call SDL_GetError() for more information.
- Thread safety
- This function should only be called on the main thread.
- See also
sDL_PollEvent,sDL_PushEvent,sDL_WaitEventTimeout- C declaration
SDL_WaitEvent, defined atSDL3/SDL_events.h 1334:34
Since: 3.2.0
sDL_WaitEventTimeout :: FunPtr (Ptr SDL_Event -> Sint32 -> IO CBool) Source #
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 SDL_PumpEvents(), you can only call this function in the thread that initialized the video subsystem.
The timeout is not guaranteed, the actual wait time could be longer due to system scheduling.
event- the
SDL_Eventstructure to be filled in with the next event from the queue, or NULL. timeoutMS- the maximum number of milliseconds to wait for the next available event.
- 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
sDL_PollEvent,sDL_PushEvent,sDL_WaitEvent- C declaration
SDL_WaitEventTimeout, defined atSDL3/SDL_events.h 1364:34
Since: 3.2.0
sDL_PushEvent :: FunPtr (Ptr SDL_Event -> IO CBool) Source #
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 SDL_PushEvent() returns.
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 SDL_PushEvent() get passed through the event filter but events added with SDL_PeepEvents() do not.
For pushing application-specific events, please use SDL_RegisterEvents() to get an event type that does not conflict with other code that also wants its own custom event types.
event- the
SDL_Eventto be added to the queue. - Returns
- true on success, false if the event was filtered or on failure; call SDL_GetError() for 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
sDL_PeepEvents,sDL_PollEvent,sDL_RegisterEvents- C declaration
SDL_PushEvent, defined atSDL3/SDL_events.h 1398:34
Since: 3.2.0
sDL_SetEventFilter :: FunPtr (SDL_EventFilter -> Ptr Void -> IO ()) Source #
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 SDL_AddEventWatch() instead.
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 SDL_SetEventEnabled().
Note: Events pushed onto the queue with SDL_PushEvent() get passed through the event filter, but events pushed onto the queue with SDL_PeepEvents() do not.
filter- a function to call when an event happens.
userdata- a pointer that is passed to
filter. - Thread safety
- It is safe to call this function from any thread.
- See also
sDL_AddEventWatch,sDL_SetEventEnabled,sDL_GetEventFilter,sDL_PeepEvents,sDL_PushEvent- C declaration
SDL_SetEventFilter, defined atSDL3/SDL_events.h 1463:34
Since: 3.2.0
sDL_GetEventFilter :: FunPtr (Ptr SDL_EventFilter -> Ptr (Ptr Void) -> IO CBool) Source #
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.
filter- the current callback function will be stored here.
userdata- the pointer that is passed to the current event filter will be stored here.
- 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
sDL_SetEventFilter- C declaration
SDL_GetEventFilter, defined atSDL3/SDL_events.h 1482:34
Since: 3.2.0
sDL_AddEventWatch :: FunPtr (SDL_EventFilter -> Ptr Void -> IO CBool) Source #
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 SDL_PushEvent(), but not for disabled events, nor for events by a filter callback set with SDL_SetEventFilter(), nor for events posted by the user through SDL_PeepEvents().
filter- an
SDL_EventFilterfunction to call when an event happens. userdata- a pointer that is passed to
filter. - Returns
- true on success or false on failure; call SDL_GetError() for more information.
- Thread safety
- It is safe to call this function from any thread.
- See also
sDL_RemoveEventWatch,sDL_SetEventFilter- C declaration
SDL_AddEventWatch, defined atSDL3/SDL_events.h 1514:34
Since: 3.2.0
sDL_RemoveEventWatch :: FunPtr (SDL_EventFilter -> Ptr Void -> IO ()) Source #
Remove an event watch callback added with SDL_AddEventWatch().
This function takes the same input as SDL_AddEventWatch() to identify and delete the corresponding callback.
filter- the function originally passed to
SDL_AddEventWatch(). userdata- the pointer originally passed to
SDL_AddEventWatch(). - Thread safety
- It is safe to call this function from any thread.
- See also
sDL_AddEventWatch- C declaration
SDL_RemoveEventWatch, defined atSDL3/SDL_events.h 1531:34
Since: 3.2.0
sDL_FilterEvents :: FunPtr (SDL_EventFilter -> Ptr Void -> IO ()) Source #
Run a specific filter function on the current event queue, removing any events for which the filter returns false.
See SDL_SetEventFilter() for more information. Unlike SDL_SetEventFilter(), this function does not change the filter permanently, it only uses the supplied filter until this function returns.
filter- the
SDL_EventFilterfunction to call when an event happens. userdata- a pointer that is passed to
filter. - Thread safety
- It is safe to call this function from any thread.
- See also
sDL_GetEventFilter,sDL_SetEventFilter- C declaration
SDL_FilterEvents, defined atSDL3/SDL_events.h 1551:34
Since: 3.2.0
sDL_SetEventEnabled :: FunPtr (Uint32 -> CBool -> IO ()) Source #
Set the state of processing events by type.
type- the type of event; see
SDL_EventTypefor details. enabled- whether to process the event or not.
- Thread safety
- It is safe to call this function from any thread.
- See also
sDL_EventEnabled- C declaration
SDL_SetEventEnabled, defined atSDL3/SDL_events.h 1565:34
Since: 3.2.0
sDL_EventEnabled :: FunPtr (Uint32 -> IO CBool) Source #
Query the state of processing events by type.
type- the type of event; see
SDL_EventTypefor details. - Returns
- true if the event is being processed, false otherwise.
- Thread safety
- It is safe to call this function from any thread.
- See also
sDL_SetEventEnabled- C declaration
SDL_EventEnabled, defined atSDL3/SDL_events.h 1579:34
Since: 3.2.0
sDL_RegisterEvents :: FunPtr (CInt -> IO Uint32) Source #
Allocate a set of user-defined events, and return the beginning event number for that set of events.
numevents- the number of events to be allocated.
- 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
sDL_PushEvent- C declaration
SDL_RegisterEvents, defined atSDL3/SDL_events.h 1595:36
Since: 3.2.0
sDL_GetWindowFromEvent :: FunPtr (PtrConst SDL_Event -> IO (Ptr SDL_Window)) Source #
Get window associated with an event.
event- an event containing a
windowID. - 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
sDL_PollEvent,sDL_WaitEvent,sDL_WaitEventTimeout- C declaration
SDL_GetWindowFromEvent, defined atSDL3/SDL_events.h 1611:42
Since: 3.2.0
sDL_GetEventDescription :: FunPtr (PtrConst SDL_Event -> Ptr CChar -> CInt -> IO CInt) Source #
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.
event- an event to describe. May be NULL.
buf- the buffer to fill with the description string. May be NULL.
buflen- the maximum bytes that can be written to
buf. - 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.
- C declaration
SDL_GetEventDescription, defined atSDL3/SDL_events.h 1643:33
Since: 3.4.0