2011-03-27 10:33:07 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org>
|
2020-01-01 01:11:17 +00:00
|
|
|
Copyright (C) 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2011-03-27 10:33:07 +00:00
|
|
|
|
|
|
|
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_SHADOW_H
|
|
|
|
#define KWIN_SHADOW_H
|
|
|
|
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QObject>
|
2018-06-05 10:52:57 +00:00
|
|
|
#include <QPixmap>
|
2011-03-27 10:33:07 +00:00
|
|
|
#include <kwineffects.h>
|
|
|
|
|
2014-07-24 06:39:25 +00:00
|
|
|
namespace KDecoration2
|
|
|
|
{
|
|
|
|
class Decoration;
|
|
|
|
class DecorationShadow;
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
namespace KWaylandServer
|
2015-07-15 09:24:19 +00:00
|
|
|
{
|
|
|
|
class ShadowInterface;
|
|
|
|
}
|
|
|
|
|
2011-03-27 10:33:07 +00:00
|
|
|
namespace KWin {
|
|
|
|
|
|
|
|
class Toplevel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @short Class representing a Window's Shadow to be rendered by the Compositor.
|
|
|
|
*
|
|
|
|
* This class holds all information about the Shadow to be rendered together with the
|
|
|
|
* window during the Compositing stage. The Shadow consists of several pixmaps and offsets.
|
2019-03-25 18:11:15 +00:00
|
|
|
* For a complete description please refer to https://community.kde.org/KWin/Shadow
|
2011-03-27 10:33:07 +00:00
|
|
|
*
|
2019-01-12 10:31:32 +00:00
|
|
|
* To create a Shadow instance use the static factory method createShadow which will
|
2011-03-27 10:33:07 +00:00
|
|
|
* create an instance for the currently used Compositing Backend. It will read the X11 Property
|
|
|
|
* and create the Shadow and all required data (such as WindowQuads). If there is no Shadow
|
|
|
|
* defined for the Toplevel the factory method returns @c NULL.
|
|
|
|
*
|
|
|
|
* @author Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
* @todo React on Toplevel size changes.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-08-10 16:13:42 +00:00
|
|
|
class KWIN_EXPORT Shadow : public QObject
|
2011-03-27 10:33:07 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
Run clang-tidy with modernize-use-override check
Summary:
Currently code base of kwin can be viewed as two pieces. One is very
ancient, and the other one is more modern, which uses new C++ features.
The main problem with the ancient code is that it was written before
C++11 era. So, no override or final keywords, lambdas, etc.
Quite recently, KDE compiler settings were changed to show a warning if
a virtual method has missing override keyword. As you might have already
guessed, this fired back at us because of that ancient code. We had
about 500 new compiler warnings.
A "solution" was proposed to that problem - disable -Wno-suggest-override
and the other similar warning for clang. It's hard to call a solution
because those warnings are disabled not only for the old code, but also
for new. This is not what we want!
The main argument for not actually fixing the problem was that git
history will be screwed as well because of human factor. While good git
history is a very important thing, we should not go crazy about it and
block every change that somehow alters git history. git blame allows to
specify starting revision for a reason.
The other argument (human factor) can be easily solved by using tools
such as clang-tidy. clang-tidy is a clang-based linter for C++. It can
be used for various things, e.g. fixing coding style(e.g. add missing
braces to if statements, readability-braces-around-statements check),
or in our case add missing override keywords.
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, apol, romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
|
|
|
~Shadow() override;
|
2011-03-27 10:33:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Region of the shadow.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2011-04-03 09:31:33 +00:00
|
|
|
const QRegion &shadowRegion() const {
|
2011-03-27 10:33:07 +00:00
|
|
|
return m_shadowRegion;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* @return Cached Shadow Quads
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2011-06-23 17:06:12 +00:00
|
|
|
const WindowQuadList &shadowQuads() const {
|
|
|
|
return m_shadowQuads;
|
|
|
|
};
|
|
|
|
WindowQuadList &shadowQuads() {
|
2011-03-27 10:33:07 +00:00
|
|
|
return m_shadowQuads;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method updates the Shadow when the property has been changed.
|
|
|
|
* It is the responsibility of the owner of the Shadow to call this method
|
|
|
|
* whenever the owner receives a PropertyNotify event.
|
|
|
|
* This method will invoke a re-read of the Property. In case the Property has
|
|
|
|
* been withdrawn the method returns @c false. In that case the owner should
|
|
|
|
* delete the Shadow.
|
|
|
|
* @returns @c true when the shadow has been updated, @c false if the property is not set anymore.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2011-03-27 10:33:07 +00:00
|
|
|
virtual bool updateShadow();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory Method to create the shadow from the property.
|
|
|
|
* This method takes care of creating an instance of the
|
|
|
|
* Shadow class for the current Compositing Backend.
|
|
|
|
*
|
|
|
|
* If there is no shadow defined for @p toplevel this method
|
|
|
|
* will return @c NULL.
|
|
|
|
* @param toplevel The Toplevel for which the shadow should be created
|
|
|
|
* @return Created Shadow or @c NULL in case there is no shadow defined.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2011-03-27 10:33:07 +00:00
|
|
|
static Shadow *createShadow(Toplevel *toplevel);
|
|
|
|
|
2011-04-01 19:49:44 +00:00
|
|
|
/**
|
|
|
|
* Reparents the shadow to @p toplevel.
|
|
|
|
* Used when a window is deleted.
|
|
|
|
* @param toplevel The new parent
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2011-04-01 19:49:44 +00:00
|
|
|
void setToplevel(Toplevel *toplevel);
|
|
|
|
|
2014-07-24 06:39:25 +00:00
|
|
|
bool hasDecorationShadow() const {
|
2014-10-28 10:01:43 +00:00
|
|
|
return !m_decorationShadow.isNull();
|
2014-07-24 06:39:25 +00:00
|
|
|
}
|
|
|
|
QImage decorationShadowImage() const;
|
|
|
|
|
2014-12-04 09:36:19 +00:00
|
|
|
QWeakPointer<KDecoration2::DecorationShadow> decorationShadow() const {
|
|
|
|
return m_decorationShadow.toWeakRef();
|
|
|
|
}
|
|
|
|
|
2011-04-03 10:43:57 +00:00
|
|
|
public Q_SLOTS:
|
|
|
|
void geometryChanged();
|
|
|
|
|
2011-03-27 10:33:07 +00:00
|
|
|
protected:
|
|
|
|
Shadow(Toplevel *toplevel);
|
|
|
|
enum ShadowElements {
|
|
|
|
ShadowElementTop,
|
|
|
|
ShadowElementTopRight,
|
|
|
|
ShadowElementRight,
|
|
|
|
ShadowElementBottomRight,
|
|
|
|
ShadowElementBottom,
|
|
|
|
ShadowElementBottomLeft,
|
|
|
|
ShadowElementLeft,
|
|
|
|
ShadowElementTopLeft,
|
|
|
|
ShadowElementsCount
|
|
|
|
};
|
2011-11-25 00:56:56 +00:00
|
|
|
|
|
|
|
inline const QPixmap &shadowPixmap(ShadowElements element) const {
|
2011-03-27 10:33:07 +00:00
|
|
|
return m_shadowElements[element];
|
|
|
|
};
|
2014-07-24 06:39:25 +00:00
|
|
|
QSize elementSize(ShadowElements element) const;
|
2011-11-25 00:56:56 +00:00
|
|
|
|
2011-03-27 10:33:07 +00:00
|
|
|
int topOffset() const {
|
|
|
|
return m_topOffset;
|
|
|
|
};
|
|
|
|
int rightOffset() const {
|
|
|
|
return m_rightOffset;
|
|
|
|
};
|
|
|
|
int bottomOffset() const {
|
|
|
|
return m_bottomOffset;
|
|
|
|
};
|
|
|
|
int leftOffset() const {
|
|
|
|
return m_leftOffset;
|
|
|
|
};
|
|
|
|
virtual void buildQuads();
|
2011-04-03 10:43:57 +00:00
|
|
|
void updateShadowRegion();
|
2011-06-23 17:06:12 +00:00
|
|
|
Toplevel *topLevel() {
|
|
|
|
return m_topLevel;
|
|
|
|
};
|
|
|
|
void setShadowRegion(const QRegion ®ion) {
|
|
|
|
m_shadowRegion = region;
|
|
|
|
};
|
|
|
|
virtual bool prepareBackend() = 0;
|
|
|
|
WindowQuadList m_shadowQuads;
|
2015-01-12 09:13:47 +00:00
|
|
|
void setShadowElement(const QPixmap &shadow, ShadowElements element);
|
2011-03-27 10:33:07 +00:00
|
|
|
|
|
|
|
private:
|
2014-07-24 06:39:25 +00:00
|
|
|
static Shadow *createShadowFromX11(Toplevel *toplevel);
|
2018-08-03 17:35:22 +00:00
|
|
|
static Shadow *createShadowFromDecoration(Toplevel *toplevel);
|
2015-07-15 09:24:19 +00:00
|
|
|
static Shadow *createShadowFromWayland(Toplevel *toplevel);
|
2020-01-01 01:11:17 +00:00
|
|
|
static Shadow *createShadowFromInternalWindow(Toplevel *toplevel);
|
2013-09-11 06:21:44 +00:00
|
|
|
static QVector<uint32_t> readX11ShadowProperty(xcb_window_t id);
|
|
|
|
bool init(const QVector<uint32_t> &data);
|
2014-07-24 06:39:25 +00:00
|
|
|
bool init(KDecoration2::Decoration *decoration);
|
2020-04-29 15:18:41 +00:00
|
|
|
bool init(const QPointer<KWaylandServer::ShadowInterface> &shadow);
|
2020-01-01 01:11:17 +00:00
|
|
|
bool init(const QWindow *window);
|
2011-03-27 10:33:07 +00:00
|
|
|
Toplevel *m_topLevel;
|
|
|
|
// shadow pixmaps
|
|
|
|
QPixmap m_shadowElements[ShadowElementsCount];
|
|
|
|
// shadow offsets
|
|
|
|
int m_topOffset;
|
|
|
|
int m_rightOffset;
|
|
|
|
int m_bottomOffset;
|
|
|
|
int m_leftOffset;
|
|
|
|
// caches
|
|
|
|
QRegion m_shadowRegion;
|
2011-04-03 10:43:57 +00:00
|
|
|
QSize m_cachedSize;
|
2014-07-24 06:39:25 +00:00
|
|
|
// Decoration based shadows
|
2014-12-01 08:40:24 +00:00
|
|
|
QSharedPointer<KDecoration2::DecorationShadow> m_decorationShadow;
|
2011-03-27 10:33:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // KWIN_SHADOW_H
|