KWin
Loading...
Searching...
No Matches
slide.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: 2007 Lubos Lunak <l.lunak@kde.org>
6 SPDX-FileCopyrightText: 2008 Lucas Murray <lmurray@undefinedfire.com>
7 SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
8
9 SPDX-License-Identifier: GPL-2.0-or-later
10*/
11
12#pragma once
13
14// kwineffects
15#include "effect/effect.h"
16#include "effect/effectwindow.h"
18
19namespace KWin
20{
21
22/*
23 * How it Works:
24 *
25 * This effect doesn't change the current desktop, only recieves changes from the VirtualDesktopManager.
26 * The only visually aparent inputs are desktopChanged() and desktopChanging().
27 *
28 * When responding to desktopChanging(), the draw position is only affected by what's recieved from there.
29 * After desktopChanging() is done, or without desktopChanging() having been called at all, desktopChanged() is called.
30 * The desktopChanged() function configures the m_startPos and m_endPos for the animation, and the duration.
31 *
32 * m_currentPosition and everything else not labeled "drawCoordinate" uses desktops as a unit.
33 * Exmp: 1.2 means the dekstop at index 1 shifted over by .2 desktops.
34 * All coords must be positive.
35 *
36 * For the wrapping effect, the render loop has to handle desktop coordinates larger than the total grid's width.
37 * 1. It uses modulus to keep the desktop coords in the range [0, gridWidth].
38 * 2. It will draw the desktop at index 0 at index gridWidth if it has to.
39 * I will not draw any thing farther outside the range than that.
40 *
41 * I've put an explanation of all the important private vars down at the bottom.
42 *
43 * Good luck :)
44 */
45
46class SlideEffect : public Effect
47{
48 Q_OBJECT
49 Q_PROPERTY(int horizontalGap READ horizontalGap)
50 Q_PROPERTY(int verticalGap READ verticalGap)
51 Q_PROPERTY(bool slideBackground READ slideBackground)
52
53public:
55 ~SlideEffect() override;
56
57 void reconfigure(ReconfigureFlags) override;
58
59 void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) override;
60 void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion &region, Output *screen) override;
61 void postPaintScreen() override;
62
63 void prePaintWindow(EffectWindow *w, WindowPrePaintData &data, std::chrono::milliseconds presentTime) override;
64 void paintWindow(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, int mask, QRegion region, WindowPaintData &data) override;
65
66 bool isActive() const override;
67 int requestedEffectChainPosition() const override;
68
69 static bool supported();
70
71 int horizontalGap() const;
72 int verticalGap() const;
73 bool slideBackground() const;
74
75private Q_SLOTS:
76 void desktopChanged(VirtualDesktop *old, VirtualDesktop *current, EffectWindow *with);
77 void desktopChanging(VirtualDesktop *old, QPointF desktopOffset, EffectWindow *with);
78 void desktopChangingCancelled();
79 void windowAdded(EffectWindow *w);
80 void windowDeleted(EffectWindow *w);
81
83 QPoint getDrawCoords(QPointF pos, Output *screen);
84 bool isTranslated(const EffectWindow *w) const;
85 bool willBePainted(const EffectWindow *w) const;
86 bool shouldElevate(const EffectWindow *w) const;
87 QPointF moveInsideDesktopGrid(QPointF p);
88 QPointF constrainToDrawableRange(QPointF p);
89 QPointF forcePositivePosition(QPointF p) const;
90 void optimizePath(); // Find the best path to target desktop
91
92 void startAnimation(VirtualDesktop *old, VirtualDesktop *current, EffectWindow *movingWindow = nullptr);
93 void prepareSwitching();
94 void finishedSwitching();
95
97 int m_hGap;
98 int m_vGap;
99 bool m_slideBackground;
100
101 enum class State {
102 Inactive,
103 ActiveAnimation,
104 ActiveGesture,
105 };
106
107 State m_state = State::Inactive;
108 SpringMotion m_motionX;
109 SpringMotion m_motionY;
110
111 // When the desktop isn't desktopChanging(), these two variables are used to control the animation path.
112 // They use desktops as a unit.
113 QPointF m_startPos;
114 QPointF m_endPos;
115
116 EffectWindow *m_movingWindow = nullptr;
117 std::chrono::milliseconds m_lastPresentTime = std::chrono::milliseconds::zero();
118 QPointF m_currentPosition; // Should always be kept up to date with where on the grid we're seeing.
119
120 struct
121 {
122 bool wrap;
123 QList<VirtualDesktop *> visibleDesktops;
124 } m_paintCtx;
125
126 struct WindowData
127 {
128 EffectWindowVisibleRef visibilityRef;
129 };
130
131 QList<EffectWindow *> m_elevatedWindows;
132 QHash<EffectWindow *, WindowData> m_windowData;
133};
134
136{
137 return m_hGap;
138}
139
140inline int SlideEffect::verticalGap() const
141{
142 return m_vGap;
143}
144
146{
147 return m_slideBackground;
148}
149
150inline bool SlideEffect::isActive() const
151{
152 return m_state != State::Inactive;
153}
154
156{
157 return 50;
158}
159
160} // namespace KWin
Base class for all KWin effects.
Definition effect.h:535
Representation of a window used by/for Effect classes.
void reconfigure(ReconfigureFlags) override
Definition slide.cpp:62
void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) override
Definition slide.cpp:96
bool slideBackground
Definition slide.h:51
bool isActive() const override
Definition slide.h:150
void prePaintWindow(EffectWindow *w, WindowPrePaintData &data, std::chrono::milliseconds presentTime) override
Definition slide.cpp:193
int horizontalGap
Definition slide.h:49
void postPaintScreen() override
Definition slide.cpp:254
void paintWindow(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, int mask, QRegion region, WindowPaintData &data) override
Definition slide.cpp:199
static bool supported()
Definition slide.cpp:57
int requestedEffectChainPosition() const override
Definition slide.h:155
QList< VirtualDesktop * > visibleDesktops
Definition slide.h:123
void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion &region, Output *screen) override
Definition slide.cpp:143
#define private