Changeset View
Changeset View
Standalone View
Standalone View
effects/glide/glide.h
1 | /******************************************************************** | 1 | /******************************************************************** | ||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | 2 | KWin - the KDE window manager | ||
3 | This file is part of the KDE project. | 3 | This file is part of the KDE project. | ||
4 | 4 | | |||
5 | Copyright (C) 2007 Philip Falkner <philip.falkner@gmail.com> | 5 | Copyright (C) 2007 Philip Falkner <philip.falkner@gmail.com> | ||
6 | Copyright (C) 2009 Martin Gräßlin <mgraesslin@kde.org> | 6 | Copyright (C) 2009 Martin Gräßlin <mgraesslin@kde.org> | ||
7 | Copyright (C) 2010 Alexandre Pereira <pereira.alex@gmail.com> | 7 | Copyright (C) 2010 Alexandre Pereira <pereira.alex@gmail.com> | ||
8 | Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
8 | 9 | | |||
9 | This program is free software; you can redistribute it and/or modify | 10 | This program is free software; you can redistribute it and/or modify | ||
10 | it under the terms of the GNU General Public License as published by | 11 | it under the terms of the GNU General Public License as published by | ||
11 | the Free Software Foundation; either version 2 of the License, or | 12 | the Free Software Foundation; either version 2 of the License, or | ||
12 | (at your option) any later version. | 13 | (at your option) any later version. | ||
13 | 14 | | |||
14 | This program is distributed in the hope that it will be useful, | 15 | This program is distributed in the hope that it will be useful, | ||
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | GNU General Public License for more details. | 18 | GNU General Public License for more details. | ||
18 | 19 | | |||
19 | You should have received a copy of the GNU General Public License | 20 | You should have received a copy of the GNU General Public License | ||
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
21 | *********************************************************************/ | 22 | *********************************************************************/ | ||
22 | 23 | | |||
23 | #ifndef KWIN_GLIDE_H | 24 | #ifndef KWIN_GLIDE_H | ||
24 | #define KWIN_GLIDE_H | 25 | #define KWIN_GLIDE_H | ||
25 | 26 | | |||
27 | // kwineffects | ||||
26 | #include <kwineffects.h> | 28 | #include <kwineffects.h> | ||
27 | 29 | | |||
28 | class QTimeLine; | | |||
29 | | ||||
30 | namespace KWin | 30 | namespace KWin | ||
31 | { | 31 | { | ||
32 | 32 | | |||
33 | class GlideEffect | 33 | class GlideEffect : public Effect | ||
34 | : public Effect | | |||
35 | { | 34 | { | ||
36 | Q_OBJECT | 35 | Q_OBJECT | ||
37 | Q_PROPERTY(int duration READ configuredDuration) | 36 | Q_PROPERTY(int duration READ duration) | ||
38 | Q_PROPERTY(int effect READ configuredEffect) | 37 | Q_PROPERTY(RotationEdge inRotationEdge READ inRotationEdge) | ||
39 | Q_PROPERTY(int angle READ configuredAngle) | 38 | Q_PROPERTY(qreal inRotationAngle READ inRotationAngle) | ||
39 | Q_PROPERTY(qreal inDistance READ inDistance) | ||||
40 | Q_PROPERTY(qreal inOpacity READ inOpacity) | ||||
41 | Q_PROPERTY(RotationEdge outRotationEdge READ outRotationEdge) | ||||
42 | Q_PROPERTY(qreal outRotationAngle READ outRotationAngle) | ||||
43 | Q_PROPERTY(qreal outDistance READ outDistance) | ||||
44 | Q_PROPERTY(qreal outOpacity READ outOpacity) | ||||
45 | | ||||
40 | public: | 46 | public: | ||
41 | GlideEffect(); | 47 | GlideEffect(); | ||
42 | ~GlideEffect(); | 48 | ~GlideEffect() override; | ||
43 | virtual void reconfigure(ReconfigureFlags); | | |||
44 | virtual void prePaintScreen(ScreenPrePaintData& data, int time); | | |||
45 | virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time); | | |||
46 | virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data); | | |||
47 | virtual void postPaintWindow(EffectWindow* w); | | |||
48 | virtual bool isActive() const; | | |||
49 | 49 | | |||
50 | int requestedEffectChainPosition() const override { | 50 | void reconfigure(ReconfigureFlags flags) override; | ||
51 | return 50; | 51 | | ||
52 | } | 52 | void prePaintScreen(ScreenPrePaintData &data, int time) override; | ||
53 | void prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time) override; | ||||
54 | void paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) override; | ||||
55 | void postPaintScreen() override; | ||||
56 | | ||||
57 | bool isActive() const override; | ||||
58 | int requestedEffectChainPosition() const override; | ||||
53 | 59 | | |||
54 | static bool supported(); | 60 | static bool supported(); | ||
55 | 61 | | |||
56 | // for properties | 62 | enum RotationEdge { | ||
57 | int configuredDuration() const { | 63 | Top = 0, | ||
58 | return duration; | 64 | Right = 1, | ||
59 | } | 65 | Bottom = 2, | ||
60 | int configuredEffect() const { | 66 | Left = 3 | ||
61 | return effect; | 67 | }; | ||
62 | } | 68 | Q_ENUM(RotationEdge) | ||
63 | int configuredAngle() const { | 69 | | ||
64 | return angle; | 70 | int duration() const; | ||
65 | } | 71 | RotationEdge inRotationEdge() const; | ||
66 | public Q_SLOTS: | 72 | qreal inRotationAngle() const; | ||
67 | void slotWindowAdded(KWin::EffectWindow* c); | 73 | qreal inDistance() const; | ||
68 | void slotWindowClosed(KWin::EffectWindow *c); | 74 | qreal inOpacity() const; | ||
69 | void slotWindowDeleted(KWin::EffectWindow *w); | 75 | RotationEdge outRotationEdge() const; | ||
76 | qreal outRotationAngle() const; | ||||
77 | qreal outDistance() const; | ||||
78 | qreal outOpacity() const; | ||||
79 | | ||||
80 | private Q_SLOTS: | ||||
81 | void windowAdded(EffectWindow *w); | ||||
82 | void windowClosed(EffectWindow *w); | ||||
83 | void windowDeleted(EffectWindow *w); | ||||
84 | void windowDataChanged(EffectWindow *w, int role); | ||||
70 | 85 | | |||
71 | private: | 86 | private: | ||
72 | class WindowInfo; | 87 | bool isGlideWindow(EffectWindow *w) const; | ||
73 | typedef QMap< const EffectWindow*, WindowInfo > InfoHash; | 88 | | ||
74 | void glideIn(EffectWindow* w, WindowPaintData& data, const InfoHash::const_iterator &info); | 89 | std::chrono::milliseconds m_duration; | ||
75 | void glideOut(EffectWindow* w, WindowPaintData& data, const InfoHash::const_iterator &info); | 90 | QHash<EffectWindow*, TimeLine> m_animations; | ||
76 | bool isGlideWindow(EffectWindow* w); | 91 | | ||
77 | void cancelWindowGrab(EffectWindow *w, int grabRole); | 92 | struct GlideParams { | ||
78 | InfoHash windows; | 93 | RotationEdge edge; | ||
79 | float duration; | 94 | struct { | ||
80 | int angle; | 95 | qreal from; | ||
81 | enum EffectStyle { | 96 | qreal to; | ||
82 | GlideIn = 0, | 97 | } angle, distance, opacity; | ||
83 | GlideInOut = 1, | | |||
84 | GlideOutIn = 2, | | |||
85 | GlideOut = 3 | | |||
86 | }; | 98 | }; | ||
87 | EffectStyle effect; | 99 | | ||
100 | GlideParams m_inParams; | ||||
101 | GlideParams m_outParams; | ||||
88 | }; | 102 | }; | ||
89 | 103 | | |||
90 | class GlideEffect::WindowInfo | 104 | inline int GlideEffect::requestedEffectChainPosition() const | ||
91 | { | 105 | { | ||
92 | public: | 106 | return 50; | ||
93 | WindowInfo(); | 107 | } | ||
94 | ~WindowInfo(); | 108 | | ||
95 | bool deleted; | 109 | inline int GlideEffect::duration() const | ||
96 | bool added; | 110 | { | ||
97 | bool closed; | 111 | return m_duration.count(); | ||
98 | QTimeLine *timeLine; | 112 | } | ||
99 | }; | 113 | | ||
114 | inline GlideEffect::RotationEdge GlideEffect::inRotationEdge() const | ||||
115 | { | ||||
116 | return m_inParams.edge; | ||||
117 | } | ||||
118 | | ||||
119 | inline qreal GlideEffect::inRotationAngle() const | ||||
120 | { | ||||
121 | return m_inParams.angle.from; | ||||
122 | } | ||||
123 | | ||||
124 | inline qreal GlideEffect::inDistance() const | ||||
125 | { | ||||
126 | return m_inParams.distance.from; | ||||
127 | } | ||||
128 | | ||||
129 | inline qreal GlideEffect::inOpacity() const | ||||
130 | { | ||||
131 | return m_inParams.opacity.from; | ||||
132 | } | ||||
133 | | ||||
134 | inline GlideEffect::RotationEdge GlideEffect::outRotationEdge() const | ||||
135 | { | ||||
136 | return m_outParams.edge; | ||||
137 | } | ||||
138 | | ||||
139 | inline qreal GlideEffect::outRotationAngle() const | ||||
140 | { | ||||
141 | return m_outParams.angle.to; | ||||
142 | } | ||||
143 | | ||||
144 | inline qreal GlideEffect::outDistance() const | ||||
145 | { | ||||
146 | return m_outParams.distance.to; | ||||
147 | } | ||||
148 | | ||||
149 | inline qreal GlideEffect::outOpacity() const | ||||
150 | { | ||||
151 | return m_outParams.opacity.to; | ||||
152 | } | ||||
100 | 153 | | |||
101 | } // namespace | 154 | } // namespace KWin | ||
102 | 155 | | |||
103 | #endif | 156 | #endif |