Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
BlobTransitionManager Class Referencefinal

Manages transitions and movement analysis for the Blob animation based on window events. More...

#include <blob_transition_manager.h>

Inheritance diagram for BlobTransitionManager:
Collaboration diagram for BlobTransitionManager:

Classes

struct  WindowMovementSample
 Structure representing a single sample of the window's position at a specific time. More...
 

Signals

void movementStopped ()
 Emitted when the inactivity counter exceeds a threshold, indicating that window movement has stopped.
 
void significantMovementDetected ()
 Emitted when the calculated velocity exceeds a threshold, indicating significant window movement.
 
void transitionCompleted ()
 Emitted when a transition (e.g., to idle state) completes.
 

Public Member Functions

void AddMovementSample (const QPointF &position, qint64 timestamp)
 Adds a new window movement sample to the internal buffer. Removes the oldest sample if the buffer exceeds kMaxMovementSamples. Updates last_movement_time_.
 
 BlobTransitionManager (QObject *parent=nullptr)
 Constructs a BlobTransitionManager.
 
void ClearAllMovementBuffers ()
 Clears the internal movement sample buffer.
 
void ClearMovementBuffer ()
 Clears the internal buffer of window movement samples.
 
int GetInactivityCounter () const
 Gets the current value of the inactivity counter.
 
qint64 GetLastMovementTime () const
 Gets the timestamp of the last recorded movement sample.
 
std::pmr::deque< WindowMovementSampleGetMovementBuffer () const
 Gets a copy of the current movement buffer.
 
void IncrementInactivityCounter ()
 Increments the inactivity counter. Called when no significant movement is detected.
 
bool IsMoving () const
 Checks if the manager currently considers the window to be moving.
 
void ProcessMovementBuffer (std::vector< QPointF > &velocity, QPointF &blob_center, std::vector< QPointF > &control_points, float blob_radius, const std::function< void(std::vector< QPointF > &, QPointF &, std::vector< QPointF > &, float, QVector2D)> &ApplyInertiaForce, const std::function< void(const QPointF &)> &SetLastWindowPos)
 Processes the buffered window movement samples to calculate velocity and apply inertia.
 
void ResetInactivityCounter ()
 Resets the inactivity counter to zero. Typically called when movement is detected.
 
void SetLastMovementTime (const qint64 time)
 Manually sets the timestamp of the last movement.
 
void SetMoving (const bool is_moving)
 Manually sets the moving state.
 
void SetResizingState (const bool is_resizing)
 Sets the flag indicating whether the window is currently being resized. Movement processing is skipped if this flag is true.
 

Private Attributes

int inactivity_counter_ = 0
 Counter incremented each frame when no significant movement is detected. Used to determine when movement stops.
 
bool is_moving_ = false
 Flag indicating if the window is currently considered to be moving based on processed samples.
 
bool is_resizing_ = false
 Flag indicating if the window is currently being resized (prevents movement processing during resize).
 
qint64 last_movement_time_ = 0
 Timestamp (ms since epoch) of the last added movement sample.
 
QVector2D m_smoothed_velocity_
 Smoothed velocity vector calculated from the movement buffer.
 
std::pmr::deque< WindowMovementSamplemovement_buffer_
 Buffer storing recent window movement samples. Uses polymorphic allocator for potential performance benefits.
 

Static Private Attributes

static constexpr int kMaxMovementSamples = 10
 Maximum number of window movement samples to store in the buffer.
 

Detailed Description

Manages transitions and movement analysis for the Blob animation based on window events.

This class processes a buffer of window movement samples to calculate velocity and determine if the window is actively moving. It applies inertia forces to the blob based on this movement and detects when movement starts and stops.

Constructor & Destructor Documentation

◆ BlobTransitionManager()

BlobTransitionManager::BlobTransitionManager ( QObject * parent = nullptr)
explicit

Constructs a BlobTransitionManager.

Parameters
parentOptional parent QObject.

Member Function Documentation

◆ AddMovementSample()

void BlobTransitionManager::AddMovementSample ( const QPointF & position,
qint64 timestamp )

Adds a new window movement sample to the internal buffer. Removes the oldest sample if the buffer exceeds kMaxMovementSamples. Updates last_movement_time_.

Parameters
positionThe window position sample.
timestampThe timestamp of the sample.

◆ ClearAllMovementBuffers()

void BlobTransitionManager::ClearAllMovementBuffers ( )
inline

Clears the internal movement sample buffer.

◆ ClearMovementBuffer()

void BlobTransitionManager::ClearMovementBuffer ( )

Clears the internal buffer of window movement samples.

◆ GetInactivityCounter()

int BlobTransitionManager::GetInactivityCounter ( ) const
inlinenodiscard

Gets the current value of the inactivity counter.

Returns
The inactivity counter-value.

◆ GetLastMovementTime()

qint64 BlobTransitionManager::GetLastMovementTime ( ) const
inlinenodiscard

Gets the timestamp of the last recorded movement sample.

Returns
Timestamp in milliseconds since the epoch.

◆ GetMovementBuffer()

std::pmr::deque< WindowMovementSample > BlobTransitionManager::GetMovementBuffer ( ) const
inlinenodiscard

Gets a copy of the current movement buffer.

Returns
A deque containing the recent WindowMovementSample structs.

◆ IncrementInactivityCounter()

void BlobTransitionManager::IncrementInactivityCounter ( )
inline

Increments the inactivity counter. Called when no significant movement is detected.

◆ IsMoving()

bool BlobTransitionManager::IsMoving ( ) const
inlinenodiscard

Checks if the manager currently considers the window to be moving.

Returns
True if moving, false otherwise.

◆ movementStopped

void BlobTransitionManager::movementStopped ( )
signal

Emitted when the inactivity counter exceeds a threshold, indicating that window movement has stopped.

Here is the caller graph for this function:

◆ ProcessMovementBuffer()

void BlobTransitionManager::ProcessMovementBuffer ( std::vector< QPointF > & velocity,
QPointF & blob_center,
std::vector< QPointF > & control_points,
float blob_radius,
const std::function< void(std::vector< QPointF > &, QPointF &, std::vector< QPointF > &, float, QVector2D)> & ApplyInertiaForce,
const std::function< void(const QPointF &)> & SetLastWindowPos )

Processes the buffered window movement samples to calculate velocity and apply inertia.

Calculates a smoothed velocity based on recent movement samples. If significant movement is detected, it calls the provided ApplyInertiaForce function to affect the blob's dynamics, updates the last known window position, resets the inactivity counter, and emits significantMovementDetected(). If movement stops, it increments the inactivity counter and emits movementStopped() after a period of inactivity.

Parameters
velocityReference to the vector storing velocities of blob control points (modified by ApplyInertiaForce).
blob_centerReference to the blob's center position (modified by ApplyInertiaForce).
control_pointsReference to the vector storing blob control points (modified by ApplyInertiaForce).
blob_radiusThe current radius of the blob.
ApplyInertiaForceA function callback to apply the calculated inertia force to the blob's state.
SetLastWindowPosA function callback to update the last known window position used by dynamics.
Here is the call graph for this function:

◆ ResetInactivityCounter()

void BlobTransitionManager::ResetInactivityCounter ( )
inline

Resets the inactivity counter to zero. Typically called when movement is detected.

◆ SetLastMovementTime()

void BlobTransitionManager::SetLastMovementTime ( const qint64 time)
inline

Manually sets the timestamp of the last movement.

Parameters
timeThe timestamp in milliseconds since the epoch.

◆ SetMoving()

void BlobTransitionManager::SetMoving ( const bool is_moving)
inline

Manually sets the moving state.

Parameters
is_movingThe new moving state.

◆ SetResizingState()

void BlobTransitionManager::SetResizingState ( const bool is_resizing)
inline

Sets the flag indicating whether the window is currently being resized. Movement processing is skipped if this flag is true.

Parameters
is_resizingTrue if resizing, false otherwise.

◆ significantMovementDetected

void BlobTransitionManager::significantMovementDetected ( )
signal

Emitted when the calculated velocity exceeds a threshold, indicating significant window movement.

Here is the caller graph for this function:

◆ transitionCompleted

void BlobTransitionManager::transitionCompleted ( )
signal

Emitted when a transition (e.g., to idle state) completes.

Here is the caller graph for this function:

Member Data Documentation

◆ inactivity_counter_

int BlobTransitionManager::inactivity_counter_ = 0
private

Counter incremented each frame when no significant movement is detected. Used to determine when movement stops.

◆ is_moving_

bool BlobTransitionManager::is_moving_ = false
private

Flag indicating if the window is currently considered to be moving based on processed samples.

◆ is_resizing_

bool BlobTransitionManager::is_resizing_ = false
private

Flag indicating if the window is currently being resized (prevents movement processing during resize).

◆ kMaxMovementSamples

int BlobTransitionManager::kMaxMovementSamples = 10
staticconstexprprivate

Maximum number of window movement samples to store in the buffer.

◆ last_movement_time_

qint64 BlobTransitionManager::last_movement_time_ = 0
private

Timestamp (ms since epoch) of the last added movement sample.

◆ m_smoothed_velocity_

QVector2D BlobTransitionManager::m_smoothed_velocity_
private

Smoothed velocity vector calculated from the movement buffer.

◆ movement_buffer_

std::pmr::deque<WindowMovementSample> BlobTransitionManager::movement_buffer_
private

Buffer storing recent window movement samples. Uses polymorphic allocator for potential performance benefits.


The documentation for this class was generated from the following files: