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

Toplevel move session utility. More...

Public Types

using OnBeforeUpdateCallback = std::function< void(LToplevelMoveSession *)>
 Callback function type used in setOnBeforeUpdateCallback() More...
 

Public Member Functions

bool start (const LEvent &triggeringEvent, const LPoint &initDragPoint)
 Start the move session. More...
 
void updateDragPoint (const LPoint &pos)
 Updates the drag point, causing the toplevel to move. More...
 
const std::vector< LToplevelMoveSession * >::const_iterator stop ()
 Stops the move session. More...
 
void setConstraints (const LMargins &constraints={LEdgeDisabled, LEdgeDisabled, LEdgeDisabled, LEdgeDisabled}) noexcept
 Sets the constraints for each side in compositor-global coordinates. More...
 
const LMarginsconstraints () const noexcept
 Retrieves the constraints set with setConstraints(). More...
 
void setOnBeforeUpdateCallback (const OnBeforeUpdateCallback &callback) noexcept
 Sets a custom callback function to be triggered each time before updating the toplevel position. More...
 
LToplevelRoletoplevel () const noexcept
 Retrieves the LToplevelRole associated with this session. More...
 
const LEventtriggeringEvent () const noexcept
 Retrieves the triggering event provided during the start of the session. More...
 
bool isActive () const noexcept
 Checks if the session is currently active. More...
 

Detailed Description

Toplevel move session utility.

This class serves as a utility for handling interactive move sessions for LToplevelRole surfaces.
Each LToplevelRole has an associated move session instance LToplevelRole::moveSession().

When a client triggers LToplevelRole::startMoveRequest(), the start() method should be invoked, providing the triggering event of the request and an initial drag point, which could be the current position of the pointer (typically obtained via LCursor::pos()) or a touch point if triggered by a touch event. This also adds the session to the LSeat::toplevelMoveSessions() vector.

Subsequently, whenever the drag point changes, such as within an LPointer::pointerMoveEvent() or LTouch::touchMoveEvent(), updateDragPoint() should be called. The LSeat::toplevelMoveSessions() provides access to all active move sessions, and the triggeringEvent() can be used to distinguish between pointer, touch or other kinds of sessions.

To dynamically modify constraints, a callback function can be specified with setOnBeforeUpdateCallback(), which is triggered each time before the toplevel position is updated. Within the callback function, setConstraints() can be used to update the constraints().

Finally, when the pointer button or touch point is released, the stop() method should be invoked to end the session and remove it from the LSeat::toplevelMoveSessions() vector. The stop() method also returns an iterator pointing to the next session in the vector which can be used in cases where the session is stopped while iterating through the vector.

Member Typedef Documentation

◆ OnBeforeUpdateCallback

using OnBeforeUpdateCallback = std::function<void(LToplevelMoveSession*)>

Callback function type used in setOnBeforeUpdateCallback()

Member Function Documentation

◆ start()

bool start ( const LEvent triggeringEvent,
const LPoint initDragPoint 
)

Start the move session.

Note
The session will automatically cease if the toplevel is destroyed.
Parameters
triggeringEventThe triggering event provided in LToplevelRole::startMoveRequest().
initDragPointThe initial pointer, touch, or other position at the start of the move operation.
Returns
true if the session successfully started, false if the toplevel is already in a session.

◆ updateDragPoint()

void updateDragPoint ( const LPoint pos)

Updates the drag point, causing the toplevel to move.

Parameters
posThe new position of the pointer or touch point.

◆ stop()

const std::vector< LToplevelMoveSession * >::const_iterator stop ( )

Stops the move session.

This method ends the current move session and removes it from the vector of active sessions.

Returns
An iterator pointing to the next session within the LSeat::toplevelMoveSessions() vector.

◆ setConstraints()

void setConstraints ( const LMargins constraints = {LEdgeDisabled, LEdgeDisabled, LEdgeDisabled ,LEdgeDisabled})
inlinenoexcept

Sets the constraints for each side in compositor-global coordinates.

Parameters
constraintsThe margins specifying the constraints for each side. Use LEdgeDisable to disable constraints on specific sides.

◆ constraints()

const LMargins& constraints ( ) const
inlinenoexcept

Retrieves the constraints set with setConstraints().

◆ setOnBeforeUpdateCallback()

void setOnBeforeUpdateCallback ( const OnBeforeUpdateCallback callback)
inlinenoexcept

Sets a custom callback function to be triggered each time before updating the toplevel position.

Parameters
callbackThe callback function to be executed before updating the toplevel window or nullptr to disable.

Default Implementation

setOnBeforeUpdateCallback([](LToplevelMoveSession *session)
{
LMargins constraints { session->toplevel()->calculateConstraintsFromOutput(cursor()->output()) };
constraints.bottom = LEdgeDisabled;
session->setConstraints(constraints);
});
void setOnBeforeUpdateCallback(const OnBeforeUpdateCallback &callback) noexcept
Sets a custom callback function to be triggered each time before updating the toplevel position.
Definition: LToplevelMoveSession.h:96
const LMargins & constraints() const noexcept
Retrieves the constraints set with setConstraints().
Definition: LToplevelMoveSession.h:83
LCursor * cursor() noexcept
Gets the compositor's cursor.
Definition: LCompositor.cpp:47
Int32 bottom
The bottom margin.
Definition: LMargins.h:16

◆ toplevel()

LToplevelRole* toplevel ( ) const
inlinenoexcept

Retrieves the LToplevelRole associated with this session.

◆ triggeringEvent()

const LEvent& triggeringEvent ( ) const
inlinenoexcept

Retrieves the triggering event provided during the start of the session.

◆ isActive()

bool isActive ( ) const
inlinenoexcept

Checks if the session is currently active.

Returns
true if the session is active, false otherwise.