Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
blob_transition_manager.h
Go to the documentation of this file.
1#ifndef BLOB_TRANSITION_MANAGER_H
2#define BLOB_TRANSITION_MANAGER_H
3
4#include <deque>
5#include <QObject>
6#include <QVector2D>
7
15class BlobTransitionManager final : public QObject {
16 Q_OBJECT
17
18public:
23 explicit BlobTransitionManager(QObject *parent = nullptr);
24
29 QPointF position;
30 qint64 timestamp;
31 };
32
50 std::vector<QPointF> &velocity,
51 QPointF &blob_center,
52 std::vector<QPointF> &control_points,
53 float blob_radius,
54 const std::function<void(std::vector<QPointF> &, QPointF &, std::vector<QPointF> &, float, QVector2D)> &
55 ApplyInertiaForce,
56 const std::function<void(const QPointF &)> &SetLastWindowPos
57 );
58
63 movement_buffer_.clear();
64 }
65
72 void AddMovementSample(const QPointF &position, qint64 timestamp);
73
78
83 [[nodiscard]] bool IsMoving() const { return is_moving_; }
84
89 void SetMoving(const bool is_moving) { is_moving_ = is_moving; }
90
96 void SetResizingState(const bool is_resizing) { is_resizing_ = is_resizing; }
97
102
107 [[nodiscard]] int GetInactivityCounter() const { return inactivity_counter_; }
108
113
118 [[nodiscard]] qint64 GetLastMovementTime() const { return last_movement_time_; }
119
124 void SetLastMovementTime(const qint64 time) { last_movement_time_ = time; }
125
130 [[nodiscard]] std::pmr::deque<WindowMovementSample> GetMovementBuffer() const { return movement_buffer_; }
131
132signals:
137
142
147
148private:
150 static constexpr int kMaxMovementSamples = 10;
152 std::pmr::deque<WindowMovementSample> movement_buffer_;
156 bool is_moving_ = false;
162 bool is_resizing_ = false;
163};
164
165#endif // BLOB_TRANSITION_MANAGER_H
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.
std::pmr::deque< WindowMovementSample > GetMovementBuffer() const
Gets a copy of the current movement buffer.
Definition blob_transition_manager.h:130
BlobTransitionManager(QObject *parent=nullptr)
Constructs a BlobTransitionManager.
Definition blob_transition_manager.cpp:5
void IncrementInactivityCounter()
Increments the inactivity counter. Called when no significant movement is detected.
Definition blob_transition_manager.h:112
std::pmr::deque< WindowMovementSample > movement_buffer_
Buffer storing recent window movement samples. Uses polymorphic allocator for potential performance b...
Definition blob_transition_manager.h:152
QVector2D m_smoothed_velocity_
Smoothed velocity vector calculated from the movement buffer.
Definition blob_transition_manager.h:154
qint64 last_movement_time_
Timestamp (ms since epoch) of the last added movement sample.
Definition blob_transition_manager.h:160
static constexpr int kMaxMovementSamples
Maximum number of window movement samples to store in the buffer.
Definition blob_transition_manager.h:150
void AddMovementSample(const QPointF &position, qint64 timestamp)
Adds a new window movement sample to the internal buffer. Removes the oldest sample if the buffer exc...
Definition blob_transition_manager.cpp:94
void SetLastMovementTime(const qint64 time)
Manually sets the timestamp of the last movement.
Definition blob_transition_manager.h:124
void ClearAllMovementBuffers()
Clears the internal movement sample buffer.
Definition blob_transition_manager.h:62
void ResetInactivityCounter()
Resets the inactivity counter to zero. Typically called when movement is detected.
Definition blob_transition_manager.h:101
bool is_moving_
Flag indicating if the window is currently considered to be moving based on processed samples.
Definition blob_transition_manager.h:156
bool IsMoving() const
Checks if the manager currently considers the window to be moving.
Definition blob_transition_manager.h:83
void transitionCompleted()
Emitted when a transition (e.g., to idle state) completes.
void SetMoving(const bool is_moving)
Manually sets the moving state.
Definition blob_transition_manager.h:89
int inactivity_counter_
Counter incremented each frame when no significant movement is detected. Used to determine when movem...
Definition blob_transition_manager.h:158
bool is_resizing_
Flag indicating if the window is currently being resized (prevents movement processing during resize)...
Definition blob_transition_manager.h:162
void SetResizingState(const bool is_resizing)
Sets the flag indicating whether the window is currently being resized. Movement processing is skippe...
Definition blob_transition_manager.h:96
qint64 GetLastMovementTime() const
Gets the timestamp of the last recorded movement sample.
Definition blob_transition_manager.h:118
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.
Definition blob_transition_manager.cpp:9
int GetInactivityCounter() const
Gets the current value of the inactivity counter.
Definition blob_transition_manager.h:107
void ClearMovementBuffer()
Clears the internal buffer of window movement samples.
Definition blob_transition_manager.cpp:102
Structure representing a single sample of the window's position at a specific time.
Definition blob_transition_manager.h:28
QPointF position
The window's top-left position at the time of the sample.
Definition blob_transition_manager.h:29
qint64 timestamp
The timestamp (milliseconds since epoch) when the sample was taken.
Definition blob_transition_manager.h:30