Louvre  v1.2.1-2
C++ library for Wayland compositors
List of all members | Public Types | Public Member Functions
LSeat Class Reference

#include <LSeat.h>

Group of input and output devices. More...

Detailed Description

Group of input and output devices.

The LSeat class represents a collection of input and output devices such as a mouse, keyboard, and outputs (screens). These devices are used within a session. Typically, access to these devices is restricted to a single process per session, often a Wayland or X11 compositor.

To enable input and graphics backends to manage seat devices without requiring superuser privileges, the openDevice() method can be used to obtain device file descriptors. This method internally employs libseat to request seat permissions.

By setting the environment variable LOUVRE_ENABLE_LIBSEAT to 0, libseat can be disabled, causing the compositor to launch without multi-seat support. Consequently, certain features such as switching to another TTY may become unavailable.

Note
Disabling libseat may be necessary in scenarios where the compositor needs to be started remotely via SSH.

The LSeat class also facilitates tasks such as session (TTY) switching, clipboard access, interaction with instances of LPointer and LKeyboard, as well as native events monitoring from the input backend.

Warning
Touch events have not been implemented yet.

Public Types

enum  InputCapabilities : InputCapabilitiesFlags
 Input capabilities. More...
 
using InputCapabilitiesFlags = UInt32
 

Public Member Functions

 LSeat (const void *params)
 LSeat class constructor. More...
 
virtual ~LSeat ()
 LSeat class destructor. More...
 
const std::vector< LOutput * > & outputs () const
 Vector of available outputs. More...
 
void * graphicBackendContextHandle () const
 Handle to the native context used by the graphic backend. More...
 
UInt32 graphicBackendId () const
 Get the ID of the current graphic backend. More...
 
void * inputBackendContextHandle () const
 Handle to the native context used by the input backend. More...
 
UInt32 inputBackendId () const
 Get the ID of the current input backend. More...
 
InputCapabilitiesFlags inputBackendCapabilities () const
 Input Backend Capabilities. More...
 
const char * name () const
 The seat name. More...
 
InputCapabilitiesFlags inputCapabilities () const
 Input capabilities of the compositor. More...
 
void setInputCapabilities (InputCapabilitiesFlags capabilitiesFlags)
 Assigns the input capabilities of the compositor. More...
 
LToplevelRoleactiveToplevel () const
 Active toplevel surface. More...
 
LPointerpointer () const
 Access to pointer events. More...
 
LKeyboardkeyboard () const
 Access to keyboard events. More...
 
LDNDManagerdndManager () const
 Access to the drag & drop session manager. More...
 
LDataSourcedataSelection () const
 Access to the clipboard. More...
 
Session
void setTTY (UInt32 tty)
 Switch session. More...
 
Int32 openDevice (const char *path, Int32 *fd)
 Open a device. More...
 
Int32 closeDevice (Int32 id)
 Close a device. More...
 
libseat * libseatHandle () const
 Libseat handle. More...
 
bool enabled () const
 Check the session state. More...
 
LPopupRoletopmostPopup () const
 Retrieve the topmost popup role. More...
 
Virtual Methods
virtual void initialized ()
 Seat initialization. More...
 
virtual bool setSelectionRequest (LDataDevice *device)
 Request to set the clipboard. More...
 
virtual void nativeInputEvent (void *event)
 Native input backend events. More...
 
virtual void enabledChanged ()
 Notify a change in the enabled() property. More...
 
virtual void outputPlugged (LOutput *output)
 New available output. More...
 
virtual void outputUnplugged (LOutput *output)
 Disconnected output. More...
 
- Public Member Functions inherited from LObject
 LObject ()=default
 Constructor of the LObject class. More...
 
 ~LObject ()
 Destructor of the LObject class. More...
 
std::shared_ptr< const bool > isAlive () const
 Object's liveness status. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from LObject
static LCompositorcompositor ()
 Quick access to the global compositor instance. More...
 
static LSeatseat ()
 Quick access to the global seat instance. More...
 
static LCursorcursor ()
 Quick access to the global cursor instance. More...
 

Member Typedef Documentation

◆ InputCapabilitiesFlags

Member Enumeration Documentation

◆ InputCapabilities

Input capabilities.

Compositor input capabilities.

Enumerator
Pointer 

Pointer events.

Keyboard 

Keyboard events.

Touch 

Touch events.

Constructor & Destructor Documentation

◆ LSeat()

LSeat ( const void *  params)

LSeat class constructor.

There is only one instance of LSeat, which can be accessed from LCompositor::seat().

Parameters
paramsInternal library parameters provided in the virtual LCompositor::createSeatRequest() constructor.

◆ ~LSeat()

~LSeat ( )
virtual

LSeat class destructor.

Invoked after LCompositor::destroySeatRequest().

Member Function Documentation

◆ outputs()

const std::vector< LOutput * > & outputs ( ) const

Vector of available outputs.

This method provides a vector of currently available outputs. The vector includes connected outputs that can be initialized as well as those that are already initialized. To obtain only initialized outputs, refer to LCompositor::outputs().

Returns
A reference to a vector of available outputs.

◆ graphicBackendContextHandle()

void * graphicBackendContextHandle ( ) const

Handle to the native context used by the graphic backend.

This opaque handle is unique to each graphic backend.
In the case of the DRM backend, it returns a pointer to a SRMCore struct.
In the case of the X11 backend, it returns a pointer to a Display struct.
You can use this handle to configure specific aspects of each backend.

◆ graphicBackendId()

UInt32 graphicBackendId ( ) const

Get the ID of the current graphic backend.

Each graphic backend is assigned a unique Louvre::UInt32 ID. You can use this method to retrieve the ID of the current graphic backend in use.

The IDs of graphic backends shipped with Louvre are listed in the Louvre::LGraphicBackendID enum.

Returns
The ID of the graphic backend.

◆ inputBackendContextHandle()

void * inputBackendContextHandle ( ) const

Handle to the native context used by the input backend.

This opaque handle is unique to each input backend.
In the case of the Libinput backend, it returns a pointer to a libinput struct.
In the case of the X11 backend, it returns a pointer to a Display struct.
You can use this handle to configure specific aspects of each backend.

◆ inputBackendId()

UInt32 inputBackendId ( ) const

Get the ID of the current input backend.

Each input backend is assigned a unique Louvre::UInt32 ID. You can use this method to retrieve the ID of the current input backend in use.

The IDs of input backends shipped with Louvre are listed in the Louvre::LInputBackendID enum.

Returns
The ID of the input backend.

◆ inputBackendCapabilities()

LSeat::InputCapabilitiesFlags inputBackendCapabilities ( ) const

Input Backend Capabilities.

Flags representing the input capabilities of the input backend, defined in Louvre::LSeat::InputCapabilities.

◆ name()

const char * name ( ) const

The seat name.

This method returns the name of the seat (E.g. "seat0").

◆ inputCapabilities()

LSeat::InputCapabilitiesFlags inputCapabilities ( ) const

Input capabilities of the compositor.

Flags with the input capabilities of the compositor assigned with setInputCapabilities().

◆ setInputCapabilities()

void setInputCapabilities ( LSeat::InputCapabilitiesFlags  capabilitiesFlags)

Assigns the input capabilities of the compositor.

This method notifies clients about the compositor's input capabilities.
Clients will only listen to events specified in the capabilities flags.
The default implementation of initialized() sets the compositor's capabilities to those of the input backend.

Parameters
capabilitiesFlagsFlags with the input capabilities of the compositor defined in Louvre::LSeat::InputCapabilities. They may differ from the input capabilities of the input backend.

◆ activeToplevel()

LToplevelRole * activeToplevel ( ) const

Active toplevel surface.

This method returns the active LToplevelRole role assigned by passing the flag Louvre::LToplevelRole::Activated in Louvre::LToplevelRole::confgure().
Only one toplevel surface can be active at a time, the library automatically deactivates other Toplevels when one is activated.

Returns
The currently active LToplevelRole instance or nullptr if no toplevel is active.

◆ pointer()

LPointer * pointer ( ) const

Access to pointer events.

Access to the LPointer instance used to receive pointer events from the backend and redirect them to clients.

◆ keyboard()

LKeyboard * keyboard ( ) const

Access to keyboard events.

Access to the LKeyboard instance used to receive keyboard events from the backend and redirect them to clients.

◆ dndManager()

LDNDManager * dndManager ( ) const

Access to the drag & drop session manager.

Access to the LDNDManager instance used to handle drag & drop sessions.

◆ dataSelection()

LDataSource * dataSelection ( ) const

Access to the clipboard.

Access to the clipboard (data source) assigned by the last client.

Returns
nullptr if the clipboard has not been assigned.

◆ setTTY()

void setTTY ( UInt32  tty)

Switch session.

This method allows you to switch to another session (TTY). Louvre also allows switching sessions using the shortcuts Ctrl + Alt + [F1, F2, ..., F10].

Parameters
ttyTTY number.

◆ openDevice()

Int32 openDevice ( const char *  path,
Int32 fd 
)

Open a device.

Opens a device on the seat, returning its ID and storing its file descriptor in fd.
The DRM graphic backend and the Libinput input backend use this method to open GPUs and input devices respectively.

Parameters
pathLocation of the device (E.g. "/dev/dri/card0")
fdStores the file descriptor.
Returns
The ID of the device or -1 in case of an error.

◆ closeDevice()

Int32 closeDevice ( Int32  id)

Close a device.

This method is used by the input and graphic backends to close devices.

Parameters
idThe id of the device returned by openDevice().
Returns
0 if the device is closed successfully and -1 in case of error.

◆ libseatHandle()

libseat * libseatHandle ( ) const

Libseat handle.

struct libseat handle.

◆ enabled()

bool enabled ( ) const

Check the session state.

The session is considered disabled if the user is engaged in another active session (TTY).

Returns
true if the seat is active, false otherwise.

◆ topmostPopup()

LPopupRole * topmostPopup ( ) const

Retrieve the topmost popup role.

This method returns a pointer to the topmost popup.

Returns
A pointer to the topmost LPopupRole or nullptr if there is no popup.

◆ initialized()

virtual void initialized ( )
virtual

Seat initialization.

Reimplement this virtual method if you want to be notified when the seat is initialized.
The seat is initialized during the compositor's initialization process.

Default implementation

{
}
void setInputCapabilities(InputCapabilitiesFlags capabilitiesFlags)
Assigns the input capabilities of the compositor.
Definition: LSeat.cpp:106
virtual void initialized()
Seat initialization.
InputCapabilitiesFlags inputBackendCapabilities() const
Input Backend Capabilities.
Definition: LSeat.cpp:78

◆ setSelectionRequest()

virtual bool setSelectionRequest ( LDataDevice device)
virtual

Request to set the clipboard.

Reimplement this virtual method if you want to control which clients can set the clipboard.
The default implementation allows clients to set the clipboard only if one of their surfaces has pointer or keyboard focus.
Returning true grants the client permission to set the clipboard and false prohibits it.

Parameters
deviceData device that makes the request.

Default Implementation

bool LSeat::setSelectionRequest(LDataDevice *device)
{
// Let the client set the clipboard only if one of its surfaces has pointer or keyboard focus
return (pointer()->focus() && pointer()->focus()->client() == device->client()) ||
(keyboard()->focus() && keyboard()->focus()->client() == device->client());
}
wl_client * client() const
Native wl_client struct of the client.
Definition: LClient.cpp:24
LSurface * focus() const
Surface with keyboard focus.
Definition: LKeyboard.cpp:238
LPointer * pointer() const
Access to pointer events.
Definition: LSeat.cpp:122
virtual bool setSelectionRequest(LDataDevice *device)
Request to set the clipboard.
LKeyboard * keyboard() const
Access to keyboard events.
Definition: LSeat.cpp:127
LClient * client() const
Client owner of the surface.
Definition: LSurface.cpp:333

◆ nativeInputEvent()

virtual void nativeInputEvent ( void *  event)
virtual

Native input backend events.

Reimplement this virtual method if you want to access all events generated by the input backend.

Parameters
eventOpaque handle to the native backend event. In the Libinput backend it corresponds to a libinput_event struct and in the X11 backend to a XEvent struct.

Default implementation

void LSeat::nativeInputEvent(void *event)
{
L_UNUSED(event);
}
virtual void nativeInputEvent(void *event)
Native input backend events.

◆ enabledChanged()

virtual void enabledChanged ( )
virtual

Notify a change in the enabled() property.

Reimplement this virtual method if you want to be notified when the seat is enabled or disabled.
The seat is enabled when the user is in the session (TTY) in which the compositor is running, and disabled when switching to a different session.

See also
setTTY()

Default implementation

{
if (!enabled())
return;
cursor()->setVisible(false);
cursor()->setVisible(true);
cursor()->move(1, 1);
}
void repaintAllOutputs()
Schedule a new rendering frame for each output in the compositor.
Definition: LCompositor.cpp:375
void move(Float32 dx, Float32 dy)
Move the cursor.
Definition: LCursor.cpp:137
void setVisible(bool state)
Change cursor visibility.
Definition: LCursor.cpp:171
static LCursor * cursor()
Quick access to the global cursor instance.
Definition: LObject.h:44
static LCompositor * compositor()
Quick access to the global compositor instance.
Definition: LObject.h:28
virtual void enabledChanged()
Notify a change in the enabled() property.
bool enabled() const
Check the session state.
Definition: LSeat.cpp:179

◆ outputPlugged()

virtual void outputPlugged ( LOutput output)
virtual

New available output.

This event is invoked by the graphic backend when a new output is available, for example when connecting an external monitor through an HDMI port.
You can reimplement this method to be notified when a new output is available.
The default implementation initializes the new output and positions it at the end (right) of the already initialized outputs.

Default Implementation

void LSeat::outputPlugged(LOutput *output)
{
output->setScale(output->dpi() >= 200 ? 2 : 1);
if (compositor()->outputs().empty())
output->setPos(0);
else
output->setPos(compositor()->outputs().back()->pos() + LPoint(compositor()->outputs().back()->size().w(), 0));
compositor()->addOutput(output);
}
bool addOutput(LOutput *output)
Initializes the specified output.
Definition: LCompositor.cpp:381
const std::vector< LOutput * > & outputs() const
Vector of available outputs.
Definition: LSeat.cpp:63
virtual void outputPlugged(LOutput *output)
New available output.
LPointTemplate< Int32, Float32 > LPoint
2D vector of 32 bits integers
Definition: LNamespaces.h:240

◆ outputUnplugged()

virtual void outputUnplugged ( LOutput output)
virtual

Disconnected output.

This event is invoked by the graphic backend when an output is no longer available, for example when an external monitor connected to an HDMI port is disconnected.
You can override this method to be notified when an output is no longer available.
The default implementation removes the output from the compositor if it is initialized and re-arranges the ones already initialized.

Note
Louvre automatically calls LCompositor::removeOutput() after this event, so calling it directly is not mandatory.

Default Implementation

void LSeat::outputUnplugged(LOutput *output)
{
Int32 totalWidth { 0 };
for (LOutput *o : compositor()->outputs())
{
o->setPos(LPoint(totalWidth, 0));
totalWidth += o->size().w();
}
}
void removeOutput(LOutput *output)
Uninitializes the specified output.
Definition: LCompositor.cpp:403
virtual void outputUnplugged(LOutput *output)
Disconnected output.
int32_t Int32
32 bits signed integer
Definition: LNamespaces.h:210