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

Toplevel resize session utility. More...

Public Types

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

Public Member Functions

bool start (const LEvent &triggeringEvent, LBitset< LEdge > edge, const LPoint &initDragPoint)
 Start the resizing session. More...
 
void updateDragPoint (const LPoint &pos)
 Updates the drag point, causing the toplevel to move and/or resize. More...
 
const std::vector< LToplevelResizeSession * >::const_iterator stop ()
 Stops the resizing 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 setMinSize (const LSize &minSize) noexcept
 Sets a minimum size for the toplevel. More...
 
const LSizeminSize () const noexcept
 Retrieves the minimum size set with setMinSize(). More...
 
void setOnBeforeUpdateCallback (const OnBeforeUpdateCallback &callback) noexcept
 Sets a custom callback function to be triggered each time before updating the toplevel position or size. 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 resize session utility.

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

When a client triggers LToplevelRole::startResizeRequest(), the start() method should be invoked, providing the triggering event and edges 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::toplevelResizeSessions() vector.

Subsequently, whenever the drag point changes, such as within an LPointer::pointerMoveEvent() or LTouch::touchMoveEvent(), updateDragPoint() should be called. The LSeat::toplevelResizeSessions() provides access to all active resize 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 or size 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::toplevelResizeSessions() 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(LToplevelResizeSession*)>

Callback function type used in setOnBeforeUpdateCallback()

Member Function Documentation

◆ start()

bool start ( const LEvent triggeringEvent,
LBitset< LEdge edge,
const LPoint initDragPoint 
)

Start the resizing session.

Note
The session will automatically cease if the toplevel is destroyed.
Parameters
triggeringEventThe triggering event provided in LToplevelRole::startResizeRequest().
edgeThe edge or corner provided in LToplevelRole::startResizeRequest() indicating the starting edge of the resize operation.
initDragPointThe initial pointer, touch, or other position at the start of the resizing 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 and/or resize.

Parameters
posThe new position of the pointer or touch point.

◆ stop()

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

Stops the resizing session.

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

Returns
An iterator pointing to the next session within the LSeat::toplevelResizeSessions() 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().

◆ setMinSize()

void setMinSize ( const LSize minSize)
inlinenoexcept

Sets a minimum size for the toplevel.

Parameters
minSizeThe minimum size that the toplevel window can be resized to.

◆ minSize()

const LSize& minSize ( ) const
inlinenoexcept

Retrieves the minimum size set with setMinSize().

◆ setOnBeforeUpdateCallback()

void setOnBeforeUpdateCallback ( const OnBeforeUpdateCallback callback)
inlinenoexcept

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

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

Default Implementation

setOnBeforeUpdateCallback([](LToplevelResizeSession *session)
{
LMargins constraints { session->toplevel()->calculateConstraintsFromOutput(cursor()->output()) };
session->setConstraints(constraints);
});
void setOnBeforeUpdateCallback(const OnBeforeUpdateCallback &callback) noexcept
Sets a custom callback function to be triggered each time before updating the toplevel position or si...
Definition: LToplevelResizeSession.h:117
const LMargins & constraints() const noexcept
Retrieves the constraints set with setConstraints().
Definition: LToplevelResizeSession.h:86
LCursor * cursor() noexcept
Gets the compositor's cursor.
Definition: LCompositor.cpp:45

◆ 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.