KWin
Loading...
Searching...
No Matches
wobblywindows.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2008 Cédric Borgese <cedric.borgese@gmail.com>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#pragma once
11
12// Include with base class for effects.
14
15namespace KWin
16{
17
18struct ParameterSet;
19
24{
25 Q_OBJECT
26 Q_PROPERTY(qreal stiffness READ stiffness)
27 Q_PROPERTY(qreal drag READ drag)
28 Q_PROPERTY(qreal moveFactor READ moveFactor)
29 Q_PROPERTY(qreal xTesselation READ xTesselation)
30 Q_PROPERTY(qreal yTesselation READ yTesselation)
31 Q_PROPERTY(qreal minVelocity READ minVelocity)
32 Q_PROPERTY(qreal maxVelocity READ maxVelocity)
33 Q_PROPERTY(qreal stopVelocity READ stopVelocity)
34 Q_PROPERTY(qreal minAcceleration READ minAcceleration)
35 Q_PROPERTY(qreal maxAcceleration READ maxAcceleration)
36 Q_PROPERTY(qreal stopAcceleration READ stopAcceleration)
37 Q_PROPERTY(bool moveWobble READ isMoveWobble)
38 Q_PROPERTY(bool resizeWobble READ isResizeWobble)
39public:
41 ~WobblyWindowsEffect() override;
42
43 void reconfigure(ReconfigureFlags) override;
44 void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) override;
45 void prePaintWindow(EffectWindow *w, WindowPrePaintData &data, std::chrono::milliseconds presentTime) override;
46 void postPaintScreen() override;
47 bool isActive() const override;
48
49 int requestedEffectChainPosition() const override
50 {
51 // Please notice that the Wobbly Windows effect has to be placed
52 // after the Maximize effect in the effect chain, otherwise there
53 // can be visual artifacts when dragging maximized windows.
54 return 70;
55 }
56
57 // Wobbly model parameters
58 void setStiffness(qreal stiffness);
59 void setDrag(qreal drag);
60 void setVelocityThreshold(qreal velocityThreshold);
61 void setMoveFactor(qreal factor);
62
63 struct Pair
64 {
65 qreal x;
66 qreal y;
67 };
68
73
74 static bool supported();
75
76 // for properties
77 qreal stiffness() const;
78 qreal drag() const;
79 qreal moveFactor() const;
80 qreal xTesselation() const;
81 qreal yTesselation() const;
82 qreal minVelocity() const;
83 qreal maxVelocity() const;
84 qreal stopVelocity() const;
85 qreal minAcceleration() const;
86 qreal maxAcceleration() const;
87 qreal stopAcceleration() const;
88 bool isMoveWobble() const;
89 bool isResizeWobble() const;
90
91protected:
92 void apply(EffectWindow *w, int mask, WindowPaintData &data, WindowQuadList &quads) override;
93
94public Q_SLOTS:
97 void slotWindowStepUserMovedResized(KWin::EffectWindow *w, const QRectF &geometry);
99 void slotWindowMaximizeStateChanged(KWin::EffectWindow *w, bool horizontal, bool vertical);
100
101private:
102 void startMovedResized(EffectWindow *w);
103 void stepMovedResized(EffectWindow *w);
104 bool updateWindowWobblyDatas(EffectWindow *w, qreal time);
105
106 struct WindowWobblyInfos
107 {
108 QList<Pair> origin;
109 QList<Pair> position;
110 QList<Pair> velocity;
111 QList<Pair> acceleration;
112 QList<Pair> buffer;
113
114 // if true, the physics system moves this point based only on it "normal" destination
115 // given by the window position, ignoring neighbour points.
116 QList<bool> constraint;
117
118 unsigned int width;
119 unsigned int height;
120 unsigned int count;
121
122 QList<Pair> bezierSurface;
123 unsigned int bezierWidth;
124 unsigned int bezierHeight;
125 unsigned int bezierCount;
126
127 WindowStatus status;
128 bool wobblying = false;
129
130 // for resizing. Only sides that have moved will wobble
131 bool can_wobble_top, can_wobble_left, can_wobble_right, can_wobble_bottom;
132 QRectF resize_original_rect;
133
134 std::chrono::milliseconds clock;
135 };
136
137 QHash<const EffectWindow *, WindowWobblyInfos> windows;
138
139 QRegion m_updateRegion;
140
141 qreal m_stiffness;
142 qreal m_drag;
143 qreal m_move_factor;
144
145 // the default tesselation for windows
146 // use qreal instead of int as I really often need
147 // these values as real to do divisions.
148 qreal m_xTesselation;
149 qreal m_yTesselation;
150
151 qreal m_minVelocity;
152 qreal m_maxVelocity;
153 qreal m_stopVelocity;
154 qreal m_minAcceleration;
155 qreal m_maxAcceleration;
156 qreal m_stopAcceleration;
157
158 bool m_moveWobble;
159 bool m_resizeWobble;
160
161 void initWobblyInfo(WindowWobblyInfos &wwi, QRectF geometry) const;
162
163 WobblyWindowsEffect::Pair computeBezierPoint(const WindowWobblyInfos &wwi, Pair point) const;
164
165 static void heightRingLinearMean(QList<Pair> &data, WindowWobblyInfos &wwi);
166
167 void setParameterSet(const ParameterSet &pset);
168};
169
170} // namespace KWin
Representation of a window used by/for Effect classes.
void slotWindowStepUserMovedResized(KWin::EffectWindow *w, const QRectF &geometry)
void apply(EffectWindow *w, int mask, WindowPaintData &data, WindowQuadList &quads) override
void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) override
void setMoveFactor(qreal factor)
void slotWindowAdded(KWin::EffectWindow *w)
void slotWindowStartUserMovedResized(KWin::EffectWindow *w)
void setVelocityThreshold(qreal velocityThreshold)
void postPaintScreen() override
bool isActive() const override
void slotWindowFinishUserMovedResized(KWin::EffectWindow *w)
void slotWindowMaximizeStateChanged(KWin::EffectWindow *w, bool horizontal, bool vertical)
int requestedEffectChainPosition() const override
void prePaintWindow(EffectWindow *w, WindowPrePaintData &data, std::chrono::milliseconds presentTime) override
void reconfigure(ReconfigureFlags) override
void setStiffness(qreal stiffness)