-
Notifications
You must be signed in to change notification settings - Fork 0
/
effects.h
560 lines (464 loc) · 19 KB
/
effects.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <[email protected]>
Copyright (C) 2010, 2011 Martin Gräßlin <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_EFFECTSIMPL_H
#define KWIN_EFFECTSIMPL_H
#include "kwineffects.h"
#include "client.h"
#include "scene.h"
#include <QHash>
#include <Plasma/FrameSvg>
namespace Plasma {
class Theme;
}
namespace KWayland
{
namespace Server
{
class Display;
}
}
class QDBusPendingCallWatcher;
class QDBusServiceWatcher;
namespace KWin
{
class AbstractThumbnailItem;
class DesktopThumbnailItem;
class WindowThumbnailItem;
class Client;
class Compositor;
class Deleted;
class EffectLoader;
class Unmanaged;
class WindowPropertyNotifyX11Filter;
class KWIN_EXPORT EffectsHandlerImpl : public EffectsHandler
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Effects")
Q_PROPERTY(QStringList activeEffects READ activeEffects)
Q_PROPERTY(QStringList loadedEffects READ loadedEffects)
Q_PROPERTY(QStringList listOfEffects READ listOfEffects)
public:
EffectsHandlerImpl(Compositor *compositor, Scene *scene);
virtual ~EffectsHandlerImpl();
void prePaintScreen(ScreenPrePaintData& data, int time) override;
void paintScreen(int mask, QRegion region, ScreenPaintData& data) override;
/**
* Special hook to perform a paintScreen but just with the windows on @p desktop.
**/
void paintDesktop(int desktop, int mask, QRegion region, ScreenPaintData& data);
void postPaintScreen() override;
void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time) override;
void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) override;
void postPaintWindow(EffectWindow* w) override;
void paintEffectFrame(EffectFrame* frame, QRegion region, double opacity, double frameOpacity) override;
Effect *provides(Effect::Feature ef);
void drawWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) override;
void buildQuads(EffectWindow* w, WindowQuadList& quadList) override;
void activateWindow(EffectWindow* c) override;
EffectWindow* activeWindow() const override;
void moveWindow(EffectWindow* w, const QPoint& pos, bool snap = false, double snapAdjust = 1.0) override;
void windowToDesktop(EffectWindow* w, int desktop) override;
void windowToScreen(EffectWindow* w, int screen) override;
void setShowingDesktop(bool showing) override;
QString currentActivity() const override;
int currentDesktop() const override;
int numberOfDesktops() const override;
void setCurrentDesktop(int desktop) override;
void setNumberOfDesktops(int desktops) override;
QSize desktopGridSize() const override;
int desktopGridWidth() const override;
int desktopGridHeight() const override;
int workspaceWidth() const override;
int workspaceHeight() const override;
int desktopAtCoords(QPoint coords) const override;
QPoint desktopGridCoords(int id) const override;
QPoint desktopCoords(int id) const override;
int desktopAbove(int desktop = 0, bool wrap = true) const override;
int desktopToRight(int desktop = 0, bool wrap = true) const override;
int desktopBelow(int desktop = 0, bool wrap = true) const override;
int desktopToLeft(int desktop = 0, bool wrap = true) const override;
QString desktopName(int desktop) const override;
bool optionRollOverDesktops() const override;
QPoint cursorPos() const override;
bool grabKeyboard(Effect* effect) override;
void ungrabKeyboard() override;
// not performing XGrabPointer
void startMouseInterception(Effect *effect, Qt::CursorShape shape) override;
void stopMouseInterception(Effect *effect) override;
bool isMouseInterception() const;
void registerGlobalShortcut(const QKeySequence &shortcut, QAction *action) override;
void registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action) override;
void registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action) override;
void registerTouchpadSwipeShortcut(SwipeDirection direction, QAction *action) override;
void* getProxy(QString name) override;
void startMousePolling() override;
void stopMousePolling() override;
EffectWindow* findWindow(WId id) const override;
EffectWindow* findWindow(KWayland::Server::SurfaceInterface *surf) const override;
EffectWindowList stackingOrder() const override;
void setElevatedWindow(KWin::EffectWindow* w, bool set) override;
void setTabBoxWindow(EffectWindow*) override;
void setTabBoxDesktop(int) override;
EffectWindowList currentTabBoxWindowList() const override;
void refTabBox() override;
void unrefTabBox() override;
void closeTabBox() override;
QList< int > currentTabBoxDesktopList() const override;
int currentTabBoxDesktop() const override;
EffectWindow* currentTabBoxWindow() const override;
void setActiveFullScreenEffect(Effect* e) override;
Effect* activeFullScreenEffect() const override;
void addRepaintFull() override;
void addRepaint(const QRect& r) override;
void addRepaint(const QRegion& r) override;
void addRepaint(int x, int y, int w, int h) override;
int activeScreen() const override;
int numScreens() const override;
int screenNumber(const QPoint& pos) const override;
QRect clientArea(clientAreaOption, int screen, int desktop) const override;
QRect clientArea(clientAreaOption, const EffectWindow* c) const override;
QRect clientArea(clientAreaOption, const QPoint& p, int desktop) const override;
QSize virtualScreenSize() const override;
QRect virtualScreenGeometry() const override;
double animationTimeFactor() const override;
WindowQuadType newWindowQuadType() override;
void defineCursor(Qt::CursorShape shape) override;
bool checkInputWindowEvent(QMouseEvent *e);
bool checkInputWindowEvent(QWheelEvent *e);
void checkInputWindowStacking();
void reserveElectricBorder(ElectricBorder border, Effect *effect) override;
void unreserveElectricBorder(ElectricBorder border, Effect *effect) override;
void registerTouchBorder(ElectricBorder border, QAction *action) override;
void unregisterTouchBorder(ElectricBorder border, QAction *action) override;
unsigned long xrenderBufferPicture() override;
QPainter* scenePainter() override;
void reconfigure() override;
QByteArray readRootProperty(long atom, long type, int format) const override;
xcb_atom_t announceSupportProperty(const QByteArray& propertyName, Effect* effect) override;
void removeSupportProperty(const QByteArray& propertyName, Effect* effect) override;
bool hasDecorationShadows() const override;
bool decorationsHaveAlpha() const override;
bool decorationSupportsBlurBehind() const override;
EffectFrame* effectFrame(EffectFrameStyle style, bool staticSize, const QPoint& position, Qt::Alignment alignment) const override;
QVariant kwinOption(KWinOption kwopt) override;
bool isScreenLocked() const override;
bool makeOpenGLContextCurrent() override;
void doneOpenGLContextCurrent() override;
xcb_connection_t *xcbConnection() const override;
xcb_window_t x11RootWindow() const override;
// internal (used by kwin core or compositing code)
void startPaint();
void grabbedKeyboardEvent(QKeyEvent* e);
bool hasKeyboardGrab() const;
void desktopResized(const QSize &size);
void reloadEffect(Effect *effect) override;
QStringList loadedEffects() const;
QStringList listOfEffects() const;
void unloadAllEffects();
QList<EffectWindow*> elevatedWindows() const;
QStringList activeEffects() const;
/**
* @returns Whether we are currently in a desktop rendering process triggered by paintDesktop hook
**/
bool isDesktopRendering() const {
return m_desktopRendering;
}
/**
* @returns the desktop currently being rendered in the paintDesktop hook.
**/
int currentRenderedDesktop() const {
return m_currentRenderedDesktop;
}
KWayland::Server::Display *waylandDisplay() const override;
bool animationsSupported() const override;
PlatformCursorImage cursorImage() const override;
void hideCursor() override;
void showCursor() override;
void startInteractiveWindowSelection(std::function<void(KWin::EffectWindow*)> callback) override;
void startInteractivePositionSelection(std::function<void(const QPoint &)> callback) override;
void showOnScreenMessage(const QString &message, const QString &iconName = QString()) override;
void hideOnScreenMessage(OnScreenMessageHideFlags flags = OnScreenMessageHideFlags()) override;
KSharedConfigPtr config() const override;
KSharedConfigPtr inputConfig() const override;
Scene *scene() const {
return m_scene;
}
bool touchDown(quint32 id, const QPointF &pos, quint32 time);
bool touchMotion(quint32 id, const QPointF &pos, quint32 time);
bool touchUp(quint32 id, quint32 time);
void highlightWindows(const QVector<EffectWindow *> &windows);
bool isPropertyTypeRegistered(xcb_atom_t atom) const {
return registered_atoms.contains(atom);
}
public Q_SLOTS:
void slotCurrentTabAboutToChange(EffectWindow* from, EffectWindow* to);
void slotTabAdded(EffectWindow* from, EffectWindow* to);
void slotTabRemoved(EffectWindow* c, EffectWindow* newActiveWindow);
// slots for D-Bus interface
Q_SCRIPTABLE void reconfigureEffect(const QString& name);
Q_SCRIPTABLE bool loadEffect(const QString& name);
Q_SCRIPTABLE void toggleEffect(const QString& name);
Q_SCRIPTABLE void unloadEffect(const QString& name);
Q_SCRIPTABLE bool isEffectLoaded(const QString& name) const;
Q_SCRIPTABLE bool isEffectSupported(const QString& name);
Q_SCRIPTABLE QList<bool> areEffectsSupported(const QStringList &names);
Q_SCRIPTABLE QString supportInformation(const QString& name) const;
Q_SCRIPTABLE QString debug(const QString& name, const QString& parameter = QString()) const;
protected Q_SLOTS:
void slotClientShown(KWin::Toplevel*);
void slotShellClientShown(KWin::Toplevel*);
void slotUnmanagedShown(KWin::Toplevel*);
void slotWindowClosed(KWin::Toplevel *c, KWin::Deleted *d);
void slotClientMaximized(KWin::AbstractClient *c, MaximizeMode maxMode);
void slotOpacityChanged(KWin::Toplevel *t, qreal oldOpacity);
void slotClientModalityChanged();
void slotGeometryShapeChanged(KWin::Toplevel *t, const QRect &old);
void slotPaddingChanged(KWin::Toplevel *t, const QRect &old);
void slotWindowDamaged(KWin::Toplevel *t, const QRect& r);
protected:
void connectNotify(const QMetaMethod &signal) override;
void disconnectNotify(const QMetaMethod &signal) override;
void effectsChanged();
void setupAbstractClientConnections(KWin::AbstractClient *c);
void setupClientConnections(KWin::Client *c);
void setupUnmanagedConnections(KWin::Unmanaged *u);
/**
* Default implementation does nothing and returns @c true.
**/
virtual bool doGrabKeyboard();
/**
* Default implementation does nothing.
**/
virtual void doUngrabKeyboard();
/**
* Default implementation sets Effects override cursor on the PointerInputRedirection.
**/
virtual void doStartMouseInterception(Qt::CursorShape shape);
/**
* Default implementation removes the Effects override cursor on the PointerInputRedirection.
**/
virtual void doStopMouseInterception();
/**
* Default implementation does nothing
**/
virtual void doCheckInputWindowStacking();
Effect* keyboard_grab_effect;
Effect* fullscreen_effect;
QList<EffectWindow*> elevated_windows;
QMultiMap< int, EffectPair > effect_order;
QHash< long, int > registered_atoms;
int next_window_quad_type;
private:
void registerPropertyType(long atom, bool reg);
typedef QVector< Effect*> EffectsList;
typedef EffectsList::const_iterator EffectsIterator;
EffectsList m_activeEffects;
EffectsIterator m_currentDrawWindowIterator;
EffectsIterator m_currentPaintWindowIterator;
EffectsIterator m_currentPaintEffectFrameIterator;
EffectsIterator m_currentPaintScreenIterator;
EffectsIterator m_currentBuildQuadsIterator;
typedef QHash< QByteArray, QList< Effect*> > PropertyEffectMap;
PropertyEffectMap m_propertiesForEffects;
QHash<QByteArray, qulonglong> m_managedProperties;
Compositor *m_compositor;
Scene *m_scene;
bool m_desktopRendering;
int m_currentRenderedDesktop;
QList<Effect*> m_grabbedMouseEffects;
EffectLoader *m_effectLoader;
int m_trackingCursorChanges;
std::unique_ptr<WindowPropertyNotifyX11Filter> m_x11WindowPropertyNotify;
};
class EffectWindowImpl : public EffectWindow
{
Q_OBJECT
public:
explicit EffectWindowImpl(Toplevel *toplevel);
virtual ~EffectWindowImpl();
void enablePainting(int reason) override;
void disablePainting(int reason) override;
bool isPaintingEnabled() override;
void refWindow() override;
void unrefWindow() override;
const EffectWindowGroup* group() const override;
QRegion shape() const override;
QRect decorationInnerRect() const override;
QByteArray readProperty(long atom, long type, int format) const override;
void deleteProperty(long atom) const override;
EffectWindow* findModal() override;
EffectWindowList mainWindows() const override;
WindowQuadList buildQuads(bool force = false) const override;
void referencePreviousWindowPixmap() override;
void unreferencePreviousWindowPixmap() override;
const Toplevel* window() const;
Toplevel* window();
void setWindow(Toplevel* w); // internal
void setSceneWindow(Scene::Window* w); // internal
const Scene::Window* sceneWindow() const; // internal
Scene::Window* sceneWindow(); // internal
void elevate(bool elevate);
void setData(int role, const QVariant &data);
QVariant data(int role) const;
void registerThumbnail(AbstractThumbnailItem *item);
QHash<WindowThumbnailItem*, QWeakPointer<EffectWindowImpl> > const &thumbnails() const {
return m_thumbnails;
}
QList<DesktopThumbnailItem*> const &desktopThumbnails() const {
return m_desktopThumbnails;
}
private Q_SLOTS:
void thumbnailDestroyed(QObject *object);
void thumbnailTargetChanged();
void desktopThumbnailDestroyed(QObject *object);
private:
void insertThumbnail(WindowThumbnailItem *item);
Toplevel* toplevel;
Scene::Window* sw; // This one is used only during paint pass.
QHash<int, QVariant> dataMap;
QHash<WindowThumbnailItem*, QWeakPointer<EffectWindowImpl> > m_thumbnails;
QList<DesktopThumbnailItem*> m_desktopThumbnails;
};
class EffectWindowGroupImpl
: public EffectWindowGroup
{
public:
explicit EffectWindowGroupImpl(Group* g);
EffectWindowList members() const override;
private:
Group* group;
};
class KWIN_EXPORT EffectFrameImpl
: public QObject, public EffectFrame
{
Q_OBJECT
public:
explicit EffectFrameImpl(EffectFrameStyle style, bool staticSize = true, QPoint position = QPoint(-1, -1),
Qt::Alignment alignment = Qt::AlignCenter);
virtual ~EffectFrameImpl();
void free() override;
void render(QRegion region = infiniteRegion(), double opacity = 1.0, double frameOpacity = 1.0) override;
Qt::Alignment alignment() const override;
void setAlignment(Qt::Alignment alignment) override;
const QFont& font() const override;
void setFont(const QFont& font) override;
const QRect& geometry() const override;
void setGeometry(const QRect& geometry, bool force = false) override;
const QIcon& icon() const override;
void setIcon(const QIcon& icon) override;
const QSize& iconSize() const override;
void setIconSize(const QSize& size) override;
void setPosition(const QPoint& point) override;
const QString& text() const override;
void setText(const QString& text) override;
EffectFrameStyle style() const override {
return m_style;
};
Plasma::FrameSvg& frame() {
return m_frame;
}
bool isStatic() const {
return m_static;
};
void finalRender(QRegion region, double opacity, double frameOpacity) const;
void setShader(GLShader* shader) override {
m_shader = shader;
}
GLShader* shader() const override {
return m_shader;
}
void setSelection(const QRect& selection) override;
const QRect& selection() const {
return m_selectionGeometry;
}
Plasma::FrameSvg& selectionFrame() {
return m_selection;
}
/**
* The foreground text color as specified by the default Plasma theme.
*/
QColor styledTextColor();
private Q_SLOTS:
void plasmaThemeChanged();
private:
Q_DISABLE_COPY(EffectFrameImpl) // As we need to use Qt slots we cannot copy this class
void align(QRect &geometry); // positions geometry around m_point respecting m_alignment
void autoResize(); // Auto-resize if not a static size
EffectFrameStyle m_style;
Plasma::FrameSvg m_frame; // TODO: share between all EffectFrames
Plasma::FrameSvg m_selection;
// Position
bool m_static;
QPoint m_point;
Qt::Alignment m_alignment;
QRect m_geometry;
// Contents
QString m_text;
QFont m_font;
QIcon m_icon;
QSize m_iconSize;
QRect m_selectionGeometry;
Scene::EffectFrame* m_sceneFrame;
GLShader* m_shader;
Plasma::Theme *m_theme;
};
inline
QList<EffectWindow*> EffectsHandlerImpl::elevatedWindows() const
{
if (isScreenLocked())
return QList<EffectWindow*>();
return elevated_windows;
}
inline
xcb_window_t EffectsHandlerImpl::x11RootWindow() const
{
return rootWindow();
}
inline
xcb_connection_t *EffectsHandlerImpl::xcbConnection() const
{
return connection();
}
inline
EffectWindowGroupImpl::EffectWindowGroupImpl(Group* g)
: group(g)
{
}
EffectWindow* effectWindow(Toplevel* w);
EffectWindow* effectWindow(Scene::Window* w);
inline
const Scene::Window* EffectWindowImpl::sceneWindow() const
{
return sw;
}
inline
Scene::Window* EffectWindowImpl::sceneWindow()
{
return sw;
}
inline
const Toplevel* EffectWindowImpl::window() const
{
return toplevel;
}
inline
Toplevel* EffectWindowImpl::window()
{
return toplevel;
}
} // namespace
#endif