Louvre
v1.2.1-2
C++ library for Wayland compositors
|
#include <LCompositor.h>
Louvre's primary class and resource factory. More...
Louvre's primary class and resource factory.
The LCompositor class initializes Louvre's Wayland event loop and backend systems.
After calling start(), the initialized() virtual method is invoked to indicate successful initialization. Any initial setup should be done there or later to prevent issues.
LCompositor also follows the factory design pattern, using virtual methods as constructors and destructors for various library classes. Each of those classes has multiple virtual methods that handle events. To customize a class's behavior for a specific event, subclass it and override the corresponding virtual method. To make the library use your custom subclass, override its virtual constructor in LCompositor.
For example, consider the LOutput class, created within LCompositor::createOutputRequest(). To use your custom LOutput subclass, override LCompositor::createOutputRequest() and return an instance of your subclass. This way, the library will use your custom LOutput subclass for output-related events.
Public Types | |
enum | CompositorState |
Possible compositor states. More... | |
Public Member Functions | |
LCompositor () | |
Constructor of the LCompositor class. More... | |
virtual | ~LCompositor () |
Destructor of the LCompositor class. More... | |
virtual bool | createGlobalsRequest () |
Wayland globals initialization. More... | |
const std::filesystem::path & | defaultAssetsPath () const |
Get the absolute path to the default Louvre assets directory. More... | |
const std::filesystem::path & | defaultBackendsPath () const |
Get the absolute path to the default Louvre backends directory. More... | |
bool | loadGraphicBackend (const std::filesystem::path &path) |
Loads a graphic backend (dynamic library). More... | |
bool | isGraphicBackendInitialized () const |
Checks if the graphic backend is initialized. More... | |
const std::string & | defaultGraphicBackendName () const |
Get the name of the default graphic backend. More... | |
bool | loadInputBackend (const std::filesystem::path &path) |
Loads an input backend (dynamic library). More... | |
bool | isInputBackendInitialized () const |
Checks if the input backend is initialized. More... | |
const std::string & | defaultInputBackendName () const |
Get the name of the default input backend. More... | |
virtual void | initialized () |
Notifies a successful compositor initialization. More... | |
virtual void | uninitialized () |
Notifies the uninitialization of the compositor. More... | |
virtual void | cursorInitialized () |
Notifies a successful cursor initialization. More... | |
CompositorState | state () const |
Gets the current compositor state. More... | |
bool | start () |
Starts the event loop and backends. More... | |
Int32 | processLoop (Int32 msTimeout) |
Process the compositor's main event loop. More... | |
Int32 | fd () const |
Get a pollable file descriptor of the main event loop. More... | |
void | finish () |
Ends and uninitializes the compositor. More... | |
LCursor * | cursor () const |
Gets the compositor cursor. More... | |
LSeat * | seat () const |
Gets the compositor seat. More... | |
void | repaintAllOutputs () |
Schedule a new rendering frame for each output in the compositor. More... | |
bool | addOutput (LOutput *output) |
Initializes the specified output. More... | |
void | removeOutput (LOutput *output) |
Uninitializes the specified output. More... | |
const std::list< LSurface * > & | surfaces () const |
Get a list of all surfaces created by clients. More... | |
const std::vector< LOutput * > & | outputs () const |
Get a list of all initialized outputs. More... | |
const std::vector< LClient * > & | clients () const |
Get a list of clients connected to the compositor. More... | |
LClient * | getClientFromNativeResource (wl_client *client) |
Gets the LClient of a native Wayland wl_client resource. More... | |
std::thread::id | mainThreadId () const |
Identifier of the main thread. More... | |
Virtual Constructors | |
virtual LOutput * | createOutputRequest (const void *params) |
Virtual constructor for creating LOutput instances when needed by the graphic backend. More... | |
virtual LClient * | createClientRequest (const void *params) |
Virtual constructor for creating LClient instances when a new client connects. More... | |
virtual LSurface * | createSurfaceRequest (const void *params) |
Virtual constructor for creating LSurface instances when a client creates a new surface. More... | |
virtual LSeat * | createSeatRequest (const void *params) |
Virtual constructor for creating the LSeat instance during compositor initialization. More... | |
virtual LPointer * | createPointerRequest (const void *params) |
Virtual constructor for creating the LPointer instance during LSeat initialization. More... | |
virtual LKeyboard * | createKeyboardRequest (const void *params) |
Virtual constructor for creating the LKeyboard instance during LSeat initialization. More... | |
virtual LDNDManager * | createDNDManagerRequest (const void *params) |
Virtual constructor for creating the LDNDManager instance during LSeat initialization. More... | |
virtual LToplevelRole * | createToplevelRoleRequest (const void *params) |
Virtual constructor for creating LToplevelRole instances when a client creates a toplevel role for a surface. More... | |
virtual LPopupRole * | createPopupRoleRequest (const void *params) |
Virtual constructor for creating LPopupRole instances when a client creates a Popup role for a surface. More... | |
virtual LSubsurfaceRole * | createSubsurfaceRoleRequest (const void *params) |
Virtual constructor for creating LSubsurfaceRole instances when a client creates a Subsurface role for a surface. More... | |
virtual LCursorRole * | createCursorRoleRequest (const void *params) |
Virtual constructor for creating LCursorRole instances when a client wants to use a surface as a cursor. More... | |
virtual LDNDIconRole * | createDNDIconRoleRequest (const void *params) |
Virtual constructor for creating LDNDIconRole instances when a client wants to use a surface as an icon for a Drag & Drop session. More... | |
Virtual Destructors | |
Virtual destructors are used by the compositor to provide early notification of the destruction of a resource.
| |
virtual void | destroyOutputRequest (LOutput *output) |
Virtual destructor for the LOutput class. More... | |
virtual void | destroyClientRequest (LClient *client) |
Virtual destructor for the LClient class. More... | |
virtual void | destroySurfaceRequest (LSurface *surface) |
Virtual destructor for the LSurface class. More... | |
virtual void | destroySeatRequest (LSeat *seat) |
Virtual destructor for the LSeat class. More... | |
virtual void | destroyPointerRequest (LPointer *pointer) |
Virtual destructor for the LPointer class. More... | |
virtual void | destroyKeyboardRequest (LKeyboard *keyboard) |
Virtual destructor for the LKeyboard class. More... | |
virtual void | destroyDNDManagerRequest (LDNDManager *dndManager) |
Virtual destructor for the LDNDManager class. More... | |
virtual void | destroyToplevelRoleRequest (LToplevelRole *toplevel) |
Virtual destructor for the LToplevelRole class. More... | |
virtual void | destroyPopupRoleRequest (LPopupRole *popup) |
Virtual destructor for the LPopupRole class. More... | |
virtual void | destroySubsurfaceRoleRequest (LSubsurfaceRole *subsurface) |
Virtual destructor for the LSubsurfaceRole class. More... | |
virtual void | destroyCursorRoleRequest (LCursorRole *cursor) |
Virtual destructor for the LCursorRole class. More... | |
virtual void | destroyDNDIconRoleRequest (LDNDIconRole *icon) |
Virtual destructor for the LDNDIconRole class. More... | |
Static Public Member Functions | |
static LCompositor * | compositor () |
Get the static LCompositor instance. More... | |
static const LVersion & | version () |
Get the current Louvre version. More... | |
static wl_display * | display () |
Get the native wl_display used by the compositor. More... | |
static wl_event_loop * | eventLoop () |
Get the main wl_event_loop used by the compositor. More... | |
static wl_event_source * | addFdListener (int fd, void *userData, int(*callback)(int, unsigned int, void *), UInt32 flags=WL_EVENT_READABLE) |
Add a pollable file descriptor to the compositor's event loop. More... | |
static void | removeFdListener (wl_event_source *source) |
Removes a previously added file descriptor from the compositor's event loop. More... | |
static UInt32 | nextSerial () |
Get a new positive integer number, incrementally. More... | |
static EGLDisplay | eglDisplay () |
Get the main EGL display created by the graphic backend. More... | |
static EGLContext | eglContext () |
Get the main EGL context created by the graphic backend. More... | |
static void | flushClients () |
Flush all pending client events. More... | |
enum CompositorState |
Possible compositor states.
LCompositor | ( | ) |
Constructor of the LCompositor class.
|
virtualdefault |
Destructor of the LCompositor class.
|
static |
Get the static LCompositor instance.
This method provides access to the single LCompositor instance that can exist per process.
You can also access it from any Louvre object with object->compositor()
.
|
virtual |
Wayland globals initialization.
Override this method if you want to remove or add custom Wayland globals when initializing the compositor.
true
on success, false
on failure (prevents the compositor from starting).const std::filesystem::path & defaultAssetsPath | ( | ) | const |
const std::filesystem::path & defaultBackendsPath | ( | ) | const |
bool loadGraphicBackend | ( | const std::filesystem::path & | path | ) |
Loads a graphic backend (dynamic library).
Use this method to load a custom graphic backend before calling start(). By default, Louvre loads the DRM backend which is tipically located at /usr/local/lib/Louvre/backends/graphic/drm.so
.
path | Absolute path of the dynamic library. |
true
if the backend is successfully loaded, false
otherwise. bool isGraphicBackendInitialized | ( | ) | const |
Checks if the graphic backend is initialized.
Use this method to determine whether the graphic backend has been initialized after calling start().
true
if the graphic backend is initialized, false
otherwise. const std::string & defaultGraphicBackendName | ( | ) | const |
Get the name of the default graphic backend.
This name is used when the LOUVRE_GRAPHIC_BACKEND environment variable is unset. It is automatically generated by Meson and defaults to drm
.
bool loadInputBackend | ( | const std::filesystem::path & | path | ) |
Loads an input backend (dynamic library).
Use this method to load a custom input backend before calling start(). By default, Louvre loads the Libinput backend which is tipically located at /usr/local/lib/Louvre/backends/input/libinput.so
.
path | Location of the backend's dynamic library. |
true
if the backend is successfully loaded, false
otherwise. bool isInputBackendInitialized | ( | ) | const |
Checks if the input backend is initialized.
Use this method to determine whether the input backend has been initialized after calling start().
true
if the input backend is initialized, false
otherwise. const std::string & defaultInputBackendName | ( | ) | const |
Get the name of the default input backend.
This name is used when the LOUVRE_INPUT_BACKEND environment variable is unset. It is automatically generated by Meson and defaults to libinput
.
|
virtual |
Notifies a successful compositor initialization.
Use this event to handle the successful initialization of the compositor after calling the start() method. Here you should perform initial configuration tasks, such as setting up outputs, as demonstrated in the default implementation.
|
virtual |
Notifies the uninitialization of the compositor.
This event is called just before the compositor is uninitialized when finish() is called. At this point, both the input and graphic backends, along with other resources such as connected clients and initialized outputs, are still operational. Use this opportunity to release any compositor-specific resources that you may have created.
|
virtual |
Notifies a successful cursor initialization.
Use this event to handle the successful initialization of the cursor. It is recommended to load cursor textures within this method. The LXCursor class provides the LXCursor::loadXCursorB() method for loading pixmaps of XCursors available on the system.
The default implementation includes a commented example demonstrating how to load XCursor pixmaps and assign them to the cursor.
LCompositor::CompositorState state | ( | ) | const |
Gets the current compositor state.
Use this method to retrieve the current state of the compositor.
|
virtual |
Virtual constructor for creating LOutput instances when needed by the graphic backend.
This method is invoked by the graphic backend when it needs to create a new output.
|
virtual |
Virtual constructor for creating LClient instances when a new client connects.
This method is called when a new client establishes a connection with the compositor.
params | Internal Louvre parameters for creating the client. |
|
virtual |
Virtual constructor for creating LSurface instances when a client creates a new surface.
This method is called when a client creates a new surface.
params | Internal Louvre parameters for creating the surface. |
|
virtual |
Virtual constructor for creating the LSeat instance during compositor initialization.
This method is called during the compositor initialization. The LSeat class provides virtual methods to access native events generated by the input backend, handle output hotplugging events, TTY switching events, and more.
params | Internal Louvre parameters for creating the seat. |
|
virtual |
Virtual constructor for creating the LPointer instance during LSeat initialization.
This method is called during LSeat initialization. The LPointer class provides virtual methods to listen to pointer events generated by the input backend.
params | Internal Louvre parameters for creating the pointer. |
|
virtual |
Virtual constructor for creating the LKeyboard instance during LSeat initialization.
This method is called during LSeat initialization. The LKeyboard class provides virtual methods to listen to keyboard events generated by the input backend.
params | Internal Louvre parameters for creating the keyboard. |
|
virtual |
Virtual constructor for creating the LDNDManager instance during LSeat initialization.
This method is called during LSeat initialization. The LDNDManager class provides virtual methods that notify the start and end of Drag & Drop sessions between clients.
params | Internal Louvre parameters for creating the DND manager. |
|
virtual |
Virtual constructor for creating LToplevelRole instances when a client creates a toplevel role for a surface.
This method is called when a client creates a toplevel role for a surface. The LToplevelRole class provides virtual methods to notify changes in geometry, state (activated, maximized, fullscreen, etc.), the start of interactive moving and resizing sessions, and more.
params | Internal Louvre parameters for creating the toplevel role. |
|
virtual |
Virtual constructor for creating LPopupRole instances when a client creates a Popup role for a surface.
This method is called when a client creates a Popup role for a surface. The LPopupRole class provides virtual methods to notify changes in geometry, repositioning based on its LPositioner, input grabbing requests, and more.
params | Internal Louvre parameters for creating the Popup role. |
|
virtual |
Virtual constructor for creating LSubsurfaceRole instances when a client creates a Subsurface role for a surface.
This method is called when a client creates a Subsurface role for a surface. The LSubsurfaceRole class provides virtual methods to notify changes in its local position relative to its parent, rearrangement on the stack of sibling surfaces, and more.
params | Internal Louvre parameters for creating the Subsurface role. |
|
virtual |
Virtual constructor for creating LCursorRole instances when a client wants to use a surface as a cursor.
This method is called when a client wants to use a surface as a cursor by invoking the LPointer::setCursorRequest() method. The LCursorRole class provides a virtual method that notifies changes in the hotspot of the cursor.
params | Internal Louvre parameters for creating the Cursor role. |
|
virtual |
Virtual constructor for creating LDNDIconRole instances when a client wants to use a surface as an icon for a Drag & Drop session.
This method is called when a client wants to use a surface as an icon for a Drag & Drop session. Similar to LCursorRole, the LDNDIconRole class provides a virtual method that notifies changes in the hotspot of the icon being dragged.
params | Optional parameters for creating the DND icon role. |
|
virtual |
Virtual destructor for the LOutput class.
This method is invoked by the graphic backend when an output becomes unavailable.
output | The LOutput instance to be destroyed. |
|
virtual |
Virtual destructor for the LClient class.
This method is called when a client disconnects, and it is invoked before all its resources have been released.
client | The LClient instance to be destroyed. |
|
virtual |
Virtual destructor for the LSurface class.
This method is called when a client requests to destroy one of its surfaces.
surface | The LSurface instance to be destroyed. |
|
virtual |
|
virtual |
Virtual destructor for the LPointer class.
This method is called during the compositor uninitialization.
pointer | The LPointer instance to be destroyed. |
|
virtual |
Virtual destructor for the LKeyboard class.
This method is called during the compositor uninitialization.
keyboard | The LKeyboard instance to be destroyed. |
|
virtual |
Virtual destructor for the LDNDManager class.
This method is called during the compositor uninitialization.
dndManager | The LDNDManager instance to be destroyed. |
|
virtual |
Virtual destructor for the LToplevelRole class.
This method is called when a client requests to destroy the toplevel role of one of its surfaces.
toplevel | The LToplevelRole instance to be destroyed. |
|
virtual |
Virtual destructor for the LPopupRole class.
This method is called when a client requests to destroy the Popup role of one of its surfaces.
popup | The LPopupRole instance to be destroyed. |
|
virtual |
Virtual destructor for the LSubsurfaceRole class.
This method is called when a client requests to destroy the Subsurface role of one of its surfaces.
subsurface | The LSubsurfaceRole instance to be destroyed. |
|
virtual |
Virtual destructor for the LCursorRole class.
This method is invoked when a client requests to destroy the Cursor role of one of its surfaces.
cursor | The LCursorRole instance to be destroyed. |
|
virtual |
Virtual destructor for the LDNDIconRole class.
This method is invoked when a client requests to destroy the DNDIcon role of one of its surfaces.
icon | The LDNDIconRole instance to be destroyed. |
bool start | ( | ) |
Starts the event loop and backends.
After successful initialization, notified with the initialized() event, the compositor can receive connections from Wayland clients and initialize output rendering threads using the addOutput() method.
false
on failure and true
otherwise. Process the compositor's main event loop.
You can also get a pollable file descriptor with fd().
msTimeout | Milliseconds to wait before an event occurs. Setting it to 0 disables the timeout, and setting it to -1 makes it wait indefinitely until an event occurs. |
Int32 fd | ( | ) | const |
Get a pollable file descriptor of the main event loop.
void finish | ( | ) |
Ends and uninitializes the compositor.
|
static |
Get the native wl_display
used by the compositor.
wl_display
.
|
static |
Get the main wl_event_loop
used by the compositor.
wl_event_loop
.
|
static |
Add a pollable file descriptor to the compositor's event loop.
fd | The file descriptor to be added. |
userData | User data to pass to the callback function. |
callback | The callback function to handle events on the file descriptor. |
flags | Flags to specify the type of event to listen for (e.g., WL_EVENT_READABLE). |
|
static |
Removes a previously added file descriptor from the compositor's event loop.
source | The wl_event_source to remove. |
LCursor * cursor | ( | ) | const |
Gets the compositor cursor.
This method must be accessed within or after the initialized() or cursorInitialized() events. If the cursor has not yet been initialized, this method returns nullptr
.
nullptr
if not yet initialized. LSeat * seat | ( | ) | const |
void repaintAllOutputs | ( | ) |
Schedule a new rendering frame for each output in the compositor.
This method schedules a new rendering frame by calling the LOutput::repaint() method for all initialized outputs.
bool addOutput | ( | LOutput * | output | ) |
Initializes the specified output.
This method initializes the specified output for rendering, allowing you to schedule rendering frames using the LOutput::repaint() method. The list of initialized outputs can be accessed with the outputs() method.
output | The output to initialize, obtained from LSeat::outputs(). |
true
on success, false
on failure. void removeOutput | ( | LOutput * | output | ) |
Uninitializes the specified output.
This method uninitializes and removes the specified output from the compositor, stopping its thread and rendering loop.
...GL()
events) has no effect. Doing so would lead to a deadlock, so Louvre simply ignores the request.output | The output to remove, previously added to the compositor. |
const std::list< LSurface * > & surfaces | ( | ) | const |
Get a list of all surfaces created by clients.
This method returns a list of all surfaces created by clients, respecting the stacking order of their roles/protocols. To access surfaces created by a specific client, use the LClient::surfaces() method instead.
const std::vector< LOutput * > & outputs | ( | ) | const |
Get a list of all initialized outputs.
This method returns a list of all outputs that have been initialized using the addOutput() method.
const std::vector< LClient * > & clients | ( | ) | const |
Get a list of clients connected to the compositor.
This method returns a list of clients that are currently connected to the compositor.
|
static |
Get a new positive integer number, incrementally.
This method returns a new positive integer number each time it is called, incrementally.
|
static |
Get the main EGL display created by the graphic backend.
This method returns the main EGL display created by the graphic backend.
|
static |
Get the main EGL context created by the graphic backend.
This method returns the main EGL context created by the graphic backend.
|
static |
Flush all pending client events.
This method immediatly flushes all pending client events.
LClient * getClientFromNativeResource | ( | wl_client * | client | ) |
std::thread::id mainThreadId | ( | ) | const |
Identifier of the main thread.
This ID corresponds to the primary thread responsible for managing the Wayland and input backend event loops, while individual output operations are performed on separate threads.