Changeset View
Changeset View
Standalone View
Standalone View
effects/diminactive/diminactive.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 Lubos Lunak <l.lunak@kde.org> | 5 | Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org> | ||
6 | Copyright (C) 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net> | 6 | Copyright (C) 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net> | ||
7 | Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
7 | 8 | | |||
8 | This program is free software; you can redistribute it and/or modify | 9 | This program is free software; you can redistribute it and/or modify | ||
9 | it under the terms of the GNU General Public License as published by | 10 | it under the terms of the GNU General Public License as published by | ||
10 | the Free Software Foundation; either version 2 of the License, or | 11 | the Free Software Foundation; either version 2 of the License, or | ||
11 | (at your option) any later version. | 12 | (at your option) any later version. | ||
12 | 13 | | |||
13 | This program is distributed in the hope that it will be useful, | 14 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU General Public License for more details. | 17 | GNU General Public License for more details. | ||
17 | 18 | | |||
18 | You should have received a copy of the GNU General Public License | 19 | You should have received a copy of the GNU General Public License | ||
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | *********************************************************************/ | 21 | *********************************************************************/ | ||
21 | 22 | | |||
22 | #ifndef KWIN_DIMINACTIVE_H | 23 | #ifndef KWIN_DIMINACTIVE_H | ||
23 | #define KWIN_DIMINACTIVE_H | 24 | #define KWIN_DIMINACTIVE_H | ||
24 | 25 | | |||
25 | // Include with base class for effects. | 26 | // kwineffects | ||
26 | #include <kwineffects.h> | 27 | #include <kwineffects.h> | ||
27 | #include <QTimeLine> | | |||
28 | | ||||
29 | 28 | | |||
30 | namespace KWin | 29 | namespace KWin | ||
31 | { | 30 | { | ||
32 | 31 | | |||
33 | class DimInactiveEffect | 32 | class DimInactiveEffect : public Effect | ||
34 | : public Effect | | |||
35 | { | 33 | { | ||
36 | Q_OBJECT | 34 | Q_OBJECT | ||
37 | Q_PROPERTY(bool dimPanels READ isDimPanels) | 35 | Q_PROPERTY(int dimStrength READ dimStrength) | ||
38 | Q_PROPERTY(bool dimDesktop READ isDimDesktop) | 36 | Q_PROPERTY(bool dimPanels READ dimPanels) | ||
39 | Q_PROPERTY(bool dimKeepAbove READ isDimKeepAbove) | 37 | Q_PROPERTY(bool dimDesktop READ dimDesktop) | ||
40 | Q_PROPERTY(bool dimByGroup READ isDimByGroup) | 38 | Q_PROPERTY(bool dimKeepAbove READ dimKeepAbove) | ||
41 | Q_PROPERTY(int dimStrength READ configuredDimStrength) | 39 | Q_PROPERTY(bool dimByGroup READ dimByGroup) | ||
40 | | ||||
42 | public: | 41 | public: | ||
43 | DimInactiveEffect(); | 42 | DimInactiveEffect(); | ||
44 | virtual void reconfigure(ReconfigureFlags); | 43 | ~DimInactiveEffect() override; | ||
45 | virtual void prePaintScreen(ScreenPrePaintData& data, int time); | 44 | | ||
46 | virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data); | 45 | void reconfigure(ReconfigureFlags flags) override; | ||
46 | | ||||
47 | void prePaintScreen(ScreenPrePaintData &data, int time) override; | ||||
48 | void paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) override; | ||||
49 | void postPaintScreen() override; | ||||
50 | | ||||
51 | int requestedEffectChainPosition() const override; | ||||
52 | bool isActive() const override; | ||||
53 | | ||||
54 | int dimStrength() const; | ||||
55 | bool dimPanels() const; | ||||
56 | bool dimDesktop() const; | ||||
57 | bool dimKeepAbove() const; | ||||
58 | bool dimByGroup() const; | ||||
59 | | ||||
60 | private Q_SLOTS: | ||||
61 | void windowActivated(EffectWindow *w); | ||||
62 | void windowClosed(EffectWindow *w); | ||||
63 | void windowDeleted(EffectWindow *w); | ||||
64 | void activeFullScreenEffectChanged(); | ||||
65 | | ||||
66 | private: | ||||
67 | void dimWindow(WindowPaintData &data, qreal strength); | ||||
68 | bool canDimWindow(const EffectWindow *w) const; | ||||
69 | void scheduleInTransition(EffectWindow *w); | ||||
70 | void scheduleGroupInTransition(EffectWindow *w); | ||||
71 | void scheduleOutTransition(EffectWindow *w); | ||||
72 | void scheduleGroupOutTransition(EffectWindow *w); | ||||
73 | void scheduleRepaint(EffectWindow *w); | ||||
47 | 74 | | |||
48 | int requestedEffectChainPosition() const override { | 75 | private: | ||
76 | qreal m_dimStrength; | ||||
77 | bool m_dimPanels; | ||||
78 | bool m_dimDesktop; | ||||
79 | bool m_dimKeepAbove; | ||||
80 | bool m_dimByGroup; | ||||
81 | | ||||
82 | EffectWindow *m_activeWindow; | ||||
83 | const EffectWindowGroup *m_activeWindowGroup; | ||||
84 | QHash<EffectWindow*, TimeLine> m_transitions; | ||||
85 | QHash<EffectWindow*, qreal> m_forceDim; | ||||
86 | | ||||
87 | struct { | ||||
88 | bool active = false; | ||||
89 | TimeLine timeLine; | ||||
90 | } m_fullScreenTransition; | ||||
91 | }; | ||||
92 | | ||||
93 | inline int DimInactiveEffect::requestedEffectChainPosition() const | ||||
94 | { | ||||
49 | return 50; | 95 | return 50; | ||
50 | } | 96 | } | ||
51 | 97 | | |||
52 | // for properties | 98 | inline bool DimInactiveEffect::isActive() const | ||
53 | bool isDimPanels() const { | 99 | { | ||
54 | return dim_panels; | 100 | return true; | ||
55 | } | 101 | } | ||
56 | bool isDimDesktop() const { | 102 | | ||
57 | return dim_desktop; | 103 | inline int DimInactiveEffect::dimStrength() const | ||
104 | { | ||||
105 | return qRound(m_dimStrength * 100.0); | ||||
58 | } | 106 | } | ||
59 | bool isDimKeepAbove() const { | 107 | | ||
60 | return dim_keepabove; | 108 | inline bool DimInactiveEffect::dimPanels() const | ||
109 | { | ||||
110 | return m_dimPanels; | ||||
61 | } | 111 | } | ||
62 | bool isDimByGroup() const { | 112 | | ||
63 | return dim_by_group; | 113 | inline bool DimInactiveEffect::dimDesktop() const | ||
114 | { | ||||
115 | return m_dimDesktop; | ||||
64 | } | 116 | } | ||
65 | int configuredDimStrength() const { | 117 | | ||
66 | return dim_strength; | 118 | inline bool DimInactiveEffect::dimKeepAbove() const | ||
119 | { | ||||
120 | return m_dimKeepAbove; | ||||
67 | } | 121 | } | ||
68 | public Q_SLOTS: | | |||
69 | void slotWindowActivated(KWin::EffectWindow* c); | | |||
70 | void slotWindowDeleted(KWin::EffectWindow *w); | | |||
71 | 122 | | |||
72 | private: | 123 | inline bool DimInactiveEffect::dimByGroup() const | ||
73 | bool dimWindow(const EffectWindow* w) const; | 124 | { | ||
74 | QTimeLine timeline; | 125 | return m_dimByGroup; | ||
75 | EffectWindow* active; | 126 | } | ||
76 | EffectWindow* previousActive; | | |||
77 | QTimeLine previousActiveTimeline; | | |||
78 | int dim_strength; // reduce saturation and brightness by this percentage | | |||
79 | bool dim_panels; // do/don't dim also all panels | | |||
80 | bool dim_desktop; // do/don't dim the desktop | | |||
81 | bool dim_keepabove; // do/don't dim keep-above windows | | |||
82 | bool dim_by_group; // keep visible all windows from the active window's group or only the active window | | |||
83 | }; | | |||
84 | 127 | | |||
85 | } // namespace | 128 | } // namespace KWin | ||
86 | 129 | | |||
87 | #endif | 130 | #endif |