Louvre  v2.13.0-1
C++ library for Wayland compositors
Public Member Functions | List of all members
LCursor Class Referencefinal

Utility class for rendering cursors. More...

+ Inheritance diagram for LCursor:

Public Member Functions

void setPos (const LPointF &pos) noexcept
 Sets the cursor position. More...
 
void setPos (Float32 x, Float32 y) noexcept
 Set the cursor position. More...
 
const LPointFpos () const noexcept
 Gets the current cursor position in compositor-global coordinates. More...
 
void move (Float32 dx, Float32 dy) noexcept
 Moves the cursor. More...
 
void move (const LPointF &delta) noexcept
 Moves the cursor. More...
 
const LRectrect () const noexcept
 Gets the cursor rect on the screen. More...
 
void setSize (const LSizeF &size) noexcept
 Sets the cursor size. More...
 
void setVisible (bool state) noexcept
 Toggles the cursor visibility. More...
 
bool visible () const noexcept
 Checks if the cursor is visible. More...
 
void setCursor (const LClientCursor &clientCursor) noexcept
 Assigns an LClientCursor. More...
 
void setCursor (const LXCursor *xcursor) noexcept
 Assigns an LXCursor. More...
 
const LClientCursorclientCursor () const noexcept
 Retrieves the client cursor set with setCursor(). More...
 
LTexturetexture () const noexcept
 Gets the current cursor texture. More...
 
void setTextureB (const LTexture *texture, const LPointF &hotspot) noexcept
 Sets the cursor texture. More...
 
void useDefault () noexcept
 Restores the default cursor. More...
 
void replaceDefaultB (const LTexture *texture, const LPointF &hotspot) noexcept
 Replaces Louvre's default cursor. More...
 
LTexturedefaultTexture () const noexcept
 Gets the default cursor texture. More...
 
const LPointFdefaultHotspotB () const noexcept
 Gets the default cursor hotspot. More...
 
LTexturedefaultLouvreTexture () const noexcept
 Default Louvre's cursor texture. More...
 
void setHotspotB (const LPointF &hotspot) noexcept
 Sets the cursor hotspot in buffer coordinates. More...
 
const LPointFhotspotB () const noexcept
 Gets the current cursor hotspot in buffer coordinates. More...
 
void enable (LOutput *output, bool enable) noexcept
 Enables or disables LCursor for the specified output. More...
 
bool enabled (LOutput *output) const noexcept
 Checks if LCursor is enabled for the specified output. More...
 
bool hasHardwareSupport (const LOutput *output) const noexcept
 Checks if a given output supports hardware compositing. More...
 
void enableHwCompositing (LOutput *output, bool enabled) noexcept
 Toggles hardware compositing for the specified output. More...
 
bool hwCompositingEnabled (LOutput *output) const noexcept
 Checks if hardware compositing is enabled for the specified output. More...
 
const LRegiondamage (LOutput *output) const noexcept
 Damaged region in compositor-global coordinates. More...
 
LOutputoutput () const noexcept
 Gets the current cursor output. More...
 
const std::vector< LOutput * > & intersectedOutputs () const noexcept
 Vector of intersected outputs. More...
 
void repaintOutputs (bool nonHardwareOnly=true) noexcept
 Repaint intersected outputs. More...
 
- Public Member Functions inherited from LObject
 LObject (const LObject &) noexcept
 Copy constructor. More...
 
LObjectoperator= (const LObject &) noexcept
 Assignment operator (each object has its own individual LWeak reference count). More...
 
void setUserData (UIntPtr data) const noexcept
 Store an unsigned integer value/pointer. More...
 
UIntPtr userData () const noexcept
 Retrieves the stored unsigned integer value/pointer. More...
 

Additional Inherited Members

- Protected Member Functions inherited from LObject
 LObject () noexcept=default
 Constructor of the LObject class. More...
 
virtual ~LObject () noexcept
 Destructor of the LObject class. More...
 
void notifyDestruction () noexcept
 Notifies the object destruction. More...
 

Detailed Description

Utility class for rendering cursors.

The LCursor class is designed to make cursor rendering easier and take advantage of compositing properties of certain graphic backends to improve performance.

See also
LXCursor, LClientCursor, LCursorRole.
Note
Clients can request to set the cursor through LPointer::setCursorRequest(), see LClientCursor.

Hardware Composition

Some graphic backends, such as DRM, allow for hardware cursor compositing, which can improve performance by reducing the need to repaint an output every time the cursor changes position.
To check if an output supports hardware cursor compositing, use hasHardwareSupport().
If hardware compositing is not supported for a specific output, the cursor is rendered by Louvre using OpenGL after a paintGL() event (when needed). In such cases the damage region provided by damage() has to be repainted.

Member Function Documentation

◆ setPos() [1/2]

void setPos ( const LPointF pos)
noexcept

Sets the cursor position.

Sets the cursor position in compositor-global coordinates.

Parameters
posThe new cursor position.
Note
Louvre automatically repositions the cursor if the specified position is not within any output.

◆ setPos() [2/2]

void setPos ( Float32  x,
Float32  y 
)
noexcept

Set the cursor position.

See also
setPos()

◆ pos()

const LPointF& pos ( ) const
inlinenoexcept

Gets the current cursor position in compositor-global coordinates.

◆ move() [1/2]

void move ( Float32  dx,
Float32  dy 
)
noexcept

Moves the cursor.

Adjusts the cursor position by a delta (dx, dy) in surface coordinates.

Parameters
dxDelta x in surface coordinates.
dyDelta y in surface coordinates.
Note
Louvre automatically repositions the cursor if the new position is not within any output.

◆ move() [2/2]

void move ( const LPointF delta)
noexcept

Moves the cursor.

See also
move()

◆ rect()

const LRect & rect ( ) const
noexcept

Gets the cursor rect on the screen.

Returns the cursor rect, which is defined as LRect(pos - hotspot, size), in compositor-global coordinates.

You can use this rect and texture() to paint the cursor with LPainter if needed.

◆ setSize()

void setSize ( const LSizeF size)
noexcept

Sets the cursor size.

Sets the cursor size in surface coordinates. The texture and hotspot are automatically scaled, with the hotspot maintaining its proportion to the texture buffer size.

Note
You don't need to set the cursor size every time you change its texture or hotspot, Louvre automatically updates it.

The initial cursor size is (24, 24).

Parameters
sizeThe desired cursor size in surface coordinates.

◆ setVisible()

void setVisible ( bool  state)
noexcept

Toggles the cursor visibility.

Parameters
statetrue to set visible, false otherwise.

◆ visible()

bool visible ( ) const
noexcept

Checks if the cursor is visible.

See also
setVisible()

◆ setCursor() [1/2]

void setCursor ( const LClientCursor clientCursor)
noexcept

Assigns an LClientCursor.

While an LClientCursor is assigned, the cursor is automatically updated when the client updates its LCursorRole surface texture, hotspot, and visibility.

If the LClientCursor is destroyed while set, useDefault() is called and the cursor is set to visible.

See also
LPointer::setCursorRequest()
LClient::lastCursorRequest()
Parameters
clientCursorThe LClientCursor to assign.

◆ setCursor() [2/2]

void setCursor ( const LXCursor xcursor)
noexcept

Assigns an LXCursor.

Note
Passing nullptr is a no-op.

◆ clientCursor()

const LClientCursor * clientCursor ( ) const
noexcept

Retrieves the client cursor set with setCursor().

Returns
A pointer to the LClientCursor if set, nullptr otherwise.

◆ texture()

LTexture * texture ( ) const
noexcept

Gets the current cursor texture.

Returns
A pointer to the current texture, nullptr otherwise.

◆ setTextureB()

void setTextureB ( const LTexture texture,
const LPointF hotspot 
)
noexcept

Sets the cursor texture.

Assigns the texture and hotspot of the cursor. The texture size does not necessarily define the cursor size, see setSize().

Parameters
textureTexture to assign.
hotspotCursor hotspot in buffer coordinates.

◆ useDefault()

void useDefault ( )
noexcept

Restores the default cursor.

Sets the cursor's texture and hotspot to the default values configured using replaceDefaultB().

The default texture initially matches defaultLouvreTexture() with a hotspot at (8, 8).

◆ replaceDefaultB()

void replaceDefaultB ( const LTexture texture,
const LPointF hotspot 
)
noexcept

Replaces Louvre's default cursor.

This method allows you to replace the Louvre's default cursor texture and hotspot, which is set when useDefault() is called.

Parameters
textureThe new texture to use as the default cursor, or nullptr to restore the default Louvre cursor.
hotspotThe hotspot position for the new cursor in buffer coordinates.

◆ defaultTexture()

LTexture * defaultTexture ( ) const
noexcept

Gets the default cursor texture.

This method returns the texture that has been set using replaceDefaultB().
Initially, the default texture is the same as defaultLouvreTexture().

Returns
A pointer to the default cursor texture.

◆ defaultHotspotB()

const LPointF & defaultHotspotB ( ) const
noexcept

Gets the default cursor hotspot.

The hotspot that has been set using replaceDefaultB().
Initially set to (8, 8).

◆ defaultLouvreTexture()

LTexture * defaultLouvreTexture ( ) const
noexcept

Default Louvre's cursor texture.

The default Louvre's cursor has a size of 64x64 pixels and hotspot at (8,8).

◆ setHotspotB()

void setHotspotB ( const LPointF hotspot)
noexcept

Sets the cursor hotspot in buffer coordinates.

The cursor hotspot is defined by coordinates relative to the origin of its buffer (upper left corner).

Note
The hotspot is automatically scaled proportionally to the cursor size().
Parameters
hotspotThe desired hotspot in buffer coordinates.

◆ hotspotB()

const LPointF & hotspotB ( ) const
noexcept

Gets the current cursor hotspot in buffer coordinates.

◆ enable()

void enable ( LOutput output,
bool  enable 
)
noexcept

Enables or disables LCursor for the specified output.

By default, LCursor is enabled for all outputs.

Parameters
outputThe output for which to enable or disable LCursor.
enableSet to true to enable LCursor, or false to disable it.

◆ enabled()

bool enabled ( LOutput output) const
noexcept

Checks if LCursor is enabled for the specified output.

See also
enable()
Parameters
outputThe output to check.
Returns
true if LCursor is enabled for the given output, false otherwise.

◆ hasHardwareSupport()

bool hasHardwareSupport ( const LOutput output) const
noexcept

Checks if a given output supports hardware compositing.

Returns
true if hardware compositing is supported and false otherwise.

◆ enableHwCompositing()

void enableHwCompositing ( LOutput output,
bool  enabled 
)
noexcept

Toggles hardware compositing for the specified output.

When disabled, Louvre will render the cursor using OpenGL after an LOutput::paintGL() event.

See also
damage()

Hardware compositing is enabled by default if the output supports it, see hasHardwareSupport().

Parameters
outputThe output for which to enable or disable hardware compositing.
enabledSet to true to enable hardware compositing, or false to disable it.

◆ hwCompositingEnabled()

bool hwCompositingEnabled ( LOutput output) const
noexcept

Checks if hardware compositing is enabled for the specified output.

Note
This method always returns false if hasHardwareSupport() for the given output returns false.
Parameters
outputThe output to check.
Returns
true if hardware compositing is enabled for the given output, false otherwise.

◆ damage()

const LRegion & damage ( LOutput output) const
noexcept

Damaged region in compositor-global coordinates.

Provides the region that needs to be repainted when hardware compositing isn't supported or is disabled, allowing Louvre to properly render it after an LOutput::paintGL() event.

Returns
The region that needs to be repainted.

◆ output()

LOutput * output ( ) const
noexcept

Gets the current cursor output.

Returns the output where the cursor is currently positioned.

Note
This method always returns a valid output unless there are none initialized.

◆ intersectedOutputs()

const std::vector< LOutput * > & intersectedOutputs ( ) const
noexcept

Vector of intersected outputs.

Returns a vector of initialized outputs that intersect with the cursor's rect() property.

◆ repaintOutputs()

void repaintOutputs ( bool  nonHardwareOnly = true)
noexcept

Repaint intersected outputs.

Invokes LOutput::repaint() for each output in the vector of intersected outputs.

Parameters
nonHardwareOnlyIf true, only repaints outputs that do not support hardware compositing.