libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
promeki::SdlSubsystem Class Reference

SDL subsystem installed alongside an Application. More...

#include <sdlsubsystem.h>

Public Member Functions

 SdlSubsystem ()
 Initialises SDL and installs the event-loop bridge.
 
 ~SdlSubsystem ()
 Destructor. Removes I/O source, closes pipe, calls SDL_Quit.
 
 SdlSubsystem (const SdlSubsystem &)=delete
 
SdlSubsystemoperator= (const SdlSubsystem &)=delete
 
SDLEventPumpeventPump ()
 Returns the subsystem's SDLEventPump.
 
EventLoop * eventLoop ()
 Returns the main EventLoop the subsystem is bound to.
 
Widget * focusedWidget () const
 Returns the widget that currently receives keyboard input, or nullptr if none is set.
 
void setFocusedWidget (Widget *widget)
 Sets the widget that receives keyboard input.
 

Static Public Member Functions

static SdlSubsysteminstance ()
 Returns the active SdlSubsystem instance.
 

Detailed Description

SDL subsystem installed alongside an Application.

Owns the SDL library state (init / quit), the SDLEventPump, and the SDL-to-EventLoop bridge (a self-pipe fed by SDL_AddEventWatch and registered as an EventLoop::addIoSource). Stack-construct one after Application:

int main(int argc, char **argv) {
Application app(argc, argv);
SDLWindow window("demo", 1280, 720);
window.show();
return app.exec();
}
Top-level SDL window that serves as a root Widget.
Definition sdlwindow.h:47
SDL subsystem installed alongside an Application.
Definition sdlsubsystem.h:55

Multiple subsystems can coexist in the same process — e.g. a program that wants both a graphical SDL window and a text-mode TUI can construct a TuiSubsystem alongside this one and both will install their I/O sources on the same Application main EventLoop.

Thread Safety
Thread-affine. SdlSubsystem must be constructed, used, and destroyed on the thread that owns the bound EventLoop (typically the main thread). SDL's video subsystem itself requires that windows and renderers be created and operated from the same thread that initialised SDL — this class enforces that contract by binding to that thread at construction. Cross-thread interaction is supported only through EventLoop::postCallable / ObjectBase signal/slot dispatch.

Constructor & Destructor Documentation

◆ SdlSubsystem()

promeki::SdlSubsystem::SdlSubsystem ( )

Initialises SDL and installs the event-loop bridge.

Requires an Application to have been constructed before this object. Calls SDL_Init with video / audio / event subsystems, creates the self-pipe used to wake the main EventLoop on SDL events, and registers the watcher + I/O source.

Member Function Documentation

◆ eventLoop()

EventLoop * promeki::SdlSubsystem::eventLoop ( )
inline

Returns the main EventLoop the subsystem is bound to.

Convenience accessor used by SDL-side code that wants to post a callable onto the main loop (e.g. SDL player sinks marshalling a resize to the main thread). Same as Application::mainEventLoop().

◆ eventPump()

SDLEventPump & promeki::SdlSubsystem::eventPump ( )
inline

Returns the subsystem's SDLEventPump.

SDLWindow uses this to register itself for event routing.

◆ instance()

static SdlSubsystem * promeki::SdlSubsystem::instance ( )
inlinestatic

Returns the active SdlSubsystem instance.

Returns
The singleton instance, or nullptr.

◆ setFocusedWidget()

void promeki::SdlSubsystem::setFocusedWidget ( Widget *  widget)
inline

Sets the widget that receives keyboard input.

Key events arriving from SDL are delivered to widget first; if the widget does not accept the event, delivery walks up the parent chain until a handler accepts or the chain ends.

Passing nullptr clears focus — key events with no focused widget fall back to the receiving window.

Managing Widget::setFocused on the old / new widget is the caller's responsibility.

Parameters
widgetThe new focused widget, or nullptr.

The documentation for this class was generated from the following file: