Changeset View
Changeset View
Standalone View
Standalone View
plugins/windowsystem/windoweffects.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Martin Flöser <mgraesslin@kde.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | #include "windoweffects.h" | ||||
21 | #include "effect_builtins.h" | ||||
22 | #include "../../effects.h" | ||||
23 | | ||||
24 | #include <QGuiApplication> | ||||
25 | #include <QWidget> | ||||
26 | #include <QWindow> | ||||
27 | | ||||
28 | Q_DECLARE_METATYPE(KWindowEffects::SlideFromLocation) | ||||
29 | | ||||
30 | namespace KWin | ||||
31 | { | ||||
32 | | ||||
33 | WindowEffects::WindowEffects() | ||||
34 | : QObject(), | ||||
35 | KWindowEffectsPrivate() | ||||
36 | { | ||||
37 | } | ||||
38 | | ||||
39 | WindowEffects::~WindowEffects() | ||||
40 | {} | ||||
41 | | ||||
42 | namespace | ||||
43 | { | ||||
44 | QWindow *findWindow(WId win) | ||||
45 | { | ||||
46 | const auto windows = qApp->allWindows(); | ||||
47 | auto it = std::find_if(windows.begin(), windows.end(), [win] (QWindow *w) { return w->winId() == win; }); | ||||
48 | if (it == windows.end()) { | ||||
49 | return nullptr; | ||||
50 | } | ||||
51 | return *it; | ||||
52 | } | ||||
53 | } | ||||
54 | | ||||
55 | bool WindowEffects::isEffectAvailable(KWindowEffects::Effect effect) | ||||
56 | { | ||||
57 | if (!effects) { | ||||
58 | return false; | ||||
59 | } | ||||
60 | auto e = static_cast<EffectsHandlerImpl*>(effects); | ||||
61 | switch (effect) { | ||||
62 | case KWindowEffects::BackgroundContrast: | ||||
63 | return e->isEffectLoaded(BuiltInEffects::nameForEffect(BuiltInEffect::Contrast)); | ||||
64 | case KWindowEffects::BlurBehind: | ||||
65 | return e->isEffectLoaded(BuiltInEffects::nameForEffect(BuiltInEffect::Blur)); | ||||
66 | case KWindowEffects::Slide: | ||||
67 | return e->isEffectLoaded(BuiltInEffects::nameForEffect(BuiltInEffect::SlidingPopups)); | ||||
68 | default: | ||||
69 | // plugin does not provide integration for other effects | ||||
70 | return false; | ||||
71 | } | ||||
72 | } | ||||
73 | | ||||
74 | void WindowEffects::slideWindow(WId id, KWindowEffects::SlideFromLocation location, int offset) | ||||
75 | { | ||||
76 | auto w = findWindow(id); | ||||
77 | if (!w) { | ||||
78 | return; | ||||
79 | } | ||||
80 | w->setProperty("kwin_slide", QVariant::fromValue(location)); | ||||
81 | w->setProperty("kwin_slide_offset", offset); | ||||
82 | } | ||||
83 | | ||||
84 | void WindowEffects::slideWindow(QWidget *widget, KWindowEffects::SlideFromLocation location) | ||||
85 | { | ||||
86 | slideWindow(widget->winId(), location, 0); | ||||
87 | } | ||||
88 | | ||||
89 | QList<QSize> WindowEffects::windowSizes(const QList<WId> &ids) | ||||
90 | { | ||||
91 | Q_UNUSED(ids) | ||||
92 | return {}; | ||||
93 | } | ||||
94 | | ||||
95 | void WindowEffects::presentWindows(WId controller, const QList<WId> &ids) | ||||
96 | { | ||||
97 | Q_UNUSED(controller) | ||||
98 | Q_UNUSED(ids) | ||||
99 | } | ||||
100 | | ||||
101 | void WindowEffects::presentWindows(WId controller, int desktop) | ||||
102 | { | ||||
103 | Q_UNUSED(controller) | ||||
104 | Q_UNUSED(desktop) | ||||
105 | } | ||||
106 | | ||||
107 | void WindowEffects::highlightWindows(WId controller, const QList<WId> &ids) | ||||
108 | { | ||||
109 | Q_UNUSED(controller) | ||||
110 | Q_UNUSED(ids) | ||||
111 | } | ||||
112 | | ||||
113 | void WindowEffects::enableBlurBehind(WId window, bool enable, const QRegion ®ion) | ||||
114 | { | ||||
115 | auto w = findWindow(window); | ||||
116 | if (!w) { | ||||
117 | return; | ||||
118 | } | ||||
119 | if (enable) { | ||||
120 | w->setProperty("kwin_blur", region); | ||||
121 | } else { | ||||
122 | w->setProperty("kwin_blur", {}); | ||||
123 | } | ||||
124 | } | ||||
125 | | ||||
126 | void WindowEffects::enableBackgroundContrast(WId window, bool enable, qreal contrast, qreal intensity, qreal saturation, const QRegion ®ion) | ||||
127 | { | ||||
128 | auto w = findWindow(window); | ||||
129 | if (!w) { | ||||
130 | return; | ||||
131 | } | ||||
132 | if (enable) { | ||||
133 | w->setProperty("kwin_background_region", region); | ||||
134 | w->setProperty("kwin_background_contrast", contrast); | ||||
135 | w->setProperty("kwin_background_intensity", intensity); | ||||
136 | w->setProperty("kwin_background_saturation", saturation); | ||||
137 | } else { | ||||
138 | w->setProperty("kwin_background_region", {}); | ||||
139 | w->setProperty("kwin_background_contrast", {}); | ||||
140 | w->setProperty("kwin_background_intensity", {}); | ||||
141 | w->setProperty("kwin_background_saturation", {}); | ||||
142 | } | ||||
143 | } | ||||
144 | | ||||
145 | void WindowEffects::markAsDashboard(WId window) | ||||
146 | { | ||||
147 | Q_UNUSED(window) | ||||
148 | } | ||||
149 | | ||||
150 | } |