2013-01-31 12:31:49 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "screenedgeeffect.h"
|
|
|
|
// KWin
|
|
|
|
#include <kwinglutils.h>
|
|
|
|
#include <kwingltexture.h>
|
2013-02-13 09:25:33 +00:00
|
|
|
#include <kwinxrenderutils.h>
|
2013-01-31 12:31:49 +00:00
|
|
|
// KDE
|
|
|
|
#include <Plasma/Svg>
|
|
|
|
// Qt
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QPainter>
|
2013-02-26 07:02:27 +00:00
|
|
|
#include <QVector4D>
|
2013-02-13 09:25:33 +00:00
|
|
|
// xcb
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
#include <xcb/render.h>
|
|
|
|
#endif
|
2013-01-31 12:31:49 +00:00
|
|
|
|
|
|
|
namespace KWin {
|
|
|
|
|
|
|
|
ScreenEdgeEffect::ScreenEdgeEffect()
|
|
|
|
: Effect()
|
|
|
|
, m_cleanupTimer(new QTimer(this))
|
|
|
|
{
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(effects, &EffectsHandler::screenEdgeApproaching, this, &ScreenEdgeEffect::edgeApproaching);
|
2013-01-31 12:31:49 +00:00
|
|
|
m_cleanupTimer->setInterval(5000);
|
|
|
|
m_cleanupTimer->setSingleShot(true);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(m_cleanupTimer, &QTimer::timeout, this, &ScreenEdgeEffect::cleanup);
|
2015-11-20 10:17:16 +00:00
|
|
|
connect(effects, &EffectsHandler::screenLockingChanged, this,
|
|
|
|
[this] (bool locked) {
|
|
|
|
if (locked) {
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2013-01-31 12:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScreenEdgeEffect::~ScreenEdgeEffect()
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|
2017-09-28 08:18:36 +00:00
|
|
|
void ScreenEdgeEffect::ensureGlowSvg()
|
|
|
|
{
|
|
|
|
if (!m_glow) {
|
|
|
|
m_glow = new Plasma::Svg(this);
|
|
|
|
m_glow->setImagePath(QStringLiteral("widgets/glowbar"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-31 12:31:49 +00:00
|
|
|
void ScreenEdgeEffect::cleanup()
|
|
|
|
{
|
|
|
|
for (QHash<ElectricBorder, Glow*>::iterator it = m_borders.begin();
|
|
|
|
it != m_borders.end();
|
|
|
|
++it) {
|
|
|
|
effects->addRepaint((*it)->geometry);
|
|
|
|
}
|
|
|
|
qDeleteAll(m_borders);
|
|
|
|
m_borders.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdgeEffect::prePaintScreen(ScreenPrePaintData &data, int time)
|
|
|
|
{
|
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
for (QHash<ElectricBorder, Glow*>::iterator it = m_borders.begin();
|
|
|
|
it != m_borders.end();
|
|
|
|
++it) {
|
|
|
|
if ((*it)->strength == 0.0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
data.paint += (*it)->geometry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdgeEffect::paintScreen(int mask, QRegion region, ScreenPaintData &data)
|
|
|
|
{
|
|
|
|
effects->paintScreen(mask, region, data);
|
|
|
|
for (QHash<ElectricBorder, Glow*>::iterator it = m_borders.begin();
|
|
|
|
it != m_borders.end();
|
|
|
|
++it) {
|
|
|
|
const qreal opacity = (*it)->strength;
|
|
|
|
if (opacity == 0.0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (effects->isOpenGLCompositing()) {
|
|
|
|
GLTexture *texture = (*it)->texture.data();
|
|
|
|
glEnable(GL_BLEND);
|
2019-02-06 23:02:32 +00:00
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
2013-01-31 12:31:49 +00:00
|
|
|
texture->bind();
|
2015-11-27 09:43:40 +00:00
|
|
|
ShaderBinder binder(ShaderTrait::MapTexture | ShaderTrait::Modulate);
|
2014-02-25 10:02:32 +00:00
|
|
|
const QVector4D constant(opacity, opacity, opacity, opacity);
|
|
|
|
binder.shader()->setUniform(GLShader::ModulationConstant, constant);
|
2015-11-27 09:43:40 +00:00
|
|
|
QMatrix4x4 mvp = data.projectionMatrix();
|
|
|
|
mvp.translate((*it)->geometry.x(), (*it)->geometry.y());
|
|
|
|
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
2014-02-25 10:02:32 +00:00
|
|
|
texture->render(infiniteRegion(), (*it)->geometry);
|
2013-01-31 12:31:49 +00:00
|
|
|
texture->unbind();
|
|
|
|
glDisable(GL_BLEND);
|
2013-02-13 09:25:33 +00:00
|
|
|
} else if (effects->compositingType() == XRenderCompositing) {
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
const QRect &rect = (*it)->geometry;
|
|
|
|
const QSize &size = (*it)->pictureSize;
|
|
|
|
int x = rect.x();
|
|
|
|
int y = rect.y();
|
|
|
|
int width = rect.width();
|
|
|
|
int height = rect.height();
|
|
|
|
switch ((*it)->border) {
|
|
|
|
case ElectricTopRight:
|
|
|
|
x = rect.x() + rect.width() - size.width();
|
|
|
|
break;
|
|
|
|
case ElectricBottomRight:
|
|
|
|
x = rect.x() + rect.width() - size.width();
|
|
|
|
y = rect.y() + rect.height() - size.height();
|
|
|
|
break;
|
|
|
|
case ElectricBottomLeft:
|
|
|
|
y = rect.y() + rect.height() - size.height();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
}
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_composite(xcbConnection(), XCB_RENDER_PICT_OP_OVER, *(*it)->picture.data(),
|
2013-02-13 09:25:33 +00:00
|
|
|
xRenderBlendPicture(opacity), effects->xrenderBufferPicture(),
|
|
|
|
0, 0, 0, 0, x, y, width, height);
|
|
|
|
#endif
|
2013-06-21 13:34:40 +00:00
|
|
|
} else if (effects->compositingType() == QPainterCompositing) {
|
|
|
|
QImage tmp((*it)->image->size(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
tmp.fill(Qt::transparent);
|
|
|
|
QPainter p(&tmp);
|
|
|
|
p.drawImage(0, 0, *(*it)->image.data());
|
|
|
|
QColor color(Qt::transparent);
|
|
|
|
color.setAlphaF(opacity);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
|
|
|
p.fillRect(QRect(QPoint(0, 0), tmp.size()), color);
|
|
|
|
p.end();
|
|
|
|
|
|
|
|
QPainter *painter = effects->scenePainter();
|
|
|
|
const QRect &rect = (*it)->geometry;
|
|
|
|
const QSize &size = (*it)->pictureSize;
|
|
|
|
int x = rect.x();
|
|
|
|
int y = rect.y();
|
|
|
|
switch ((*it)->border) {
|
|
|
|
case ElectricTopRight:
|
|
|
|
x = rect.x() + rect.width() - size.width();
|
|
|
|
break;
|
|
|
|
case ElectricBottomRight:
|
|
|
|
x = rect.x() + rect.width() - size.width();
|
|
|
|
y = rect.y() + rect.height() - size.height();
|
|
|
|
break;
|
|
|
|
case ElectricBottomLeft:
|
|
|
|
y = rect.y() + rect.height() - size.height();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
painter->drawImage(QPoint(x, y), tmp);
|
2013-01-31 12:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdgeEffect::edgeApproaching(ElectricBorder border, qreal factor, const QRect &geometry)
|
|
|
|
{
|
|
|
|
QHash<ElectricBorder, Glow*>::iterator it = m_borders.find(border);
|
|
|
|
if (it != m_borders.end()) {
|
|
|
|
// need to update
|
|
|
|
effects->addRepaint((*it)->geometry);
|
|
|
|
(*it)->strength = factor;
|
|
|
|
if ((*it)->geometry != geometry) {
|
|
|
|
(*it)->geometry = geometry;
|
|
|
|
effects->addRepaint((*it)->geometry);
|
|
|
|
if (border == ElectricLeft || border == ElectricRight || border == ElectricTop || border == ElectricBottom) {
|
2013-02-13 09:25:33 +00:00
|
|
|
if (effects->isOpenGLCompositing()) {
|
|
|
|
(*it)->texture.reset(createEdgeGlow<GLTexture>(border, geometry.size()));
|
|
|
|
} else if (effects->compositingType() == XRenderCompositing) {
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
(*it)->picture.reset(createEdgeGlow<XRenderPicture>(border, geometry.size()));
|
|
|
|
#endif
|
2013-06-21 13:34:40 +00:00
|
|
|
} else if (effects->compositingType() == QPainterCompositing) {
|
|
|
|
(*it)->image.reset(createEdgeGlow<QImage>(border, geometry.size()));
|
2013-02-13 09:25:33 +00:00
|
|
|
}
|
2013-01-31 12:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (factor == 0.0) {
|
|
|
|
m_cleanupTimer->start();
|
|
|
|
} else {
|
|
|
|
m_cleanupTimer->stop();
|
|
|
|
}
|
|
|
|
} else if (factor != 0.0) {
|
|
|
|
// need to generate new Glow
|
|
|
|
Glow *glow = createGlow(border, factor, geometry);
|
|
|
|
if (glow) {
|
|
|
|
m_borders.insert(border, glow);
|
|
|
|
effects->addRepaint(glow->geometry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Glow *ScreenEdgeEffect::createGlow(ElectricBorder border, qreal factor, const QRect &geometry)
|
|
|
|
{
|
|
|
|
Glow *glow = new Glow();
|
2013-02-13 09:25:33 +00:00
|
|
|
glow->border = border;
|
2013-01-31 12:31:49 +00:00
|
|
|
glow->strength = factor;
|
|
|
|
glow->geometry = geometry;
|
|
|
|
|
|
|
|
// render the glow image
|
2013-02-13 09:25:33 +00:00
|
|
|
if (effects->isOpenGLCompositing()) {
|
Better handling for making the compositing OpenGL context current
With QtQuick2 it's possible that the scene graph rendering context either
lives in an own thread or uses the main GUI thread. In the latter case
it's the same thread as our compositing OpenGL context lives in. This
means our basic assumption that between two rendering passes the context
stays current does not hold.
The code already ensured that before we start a rendering pass the
context is made current, but there are many more possible cases. If we
use OpenGL in areas not triggered by the rendering loop but in response
to other events the context needs to be made current. This includes the
loading and unloading of effects (some effects use OpenGL in the static
effect check, in the ctor and dtor), background loading of texture data,
lazy loading after first usage invoked by shortcut, etc. etc.
To properly handle these cases new methods are added to EffectsHandler
to make the compositing OpenGL context current. These calls delegate down
into the scene. On non-OpenGL scenes they are noop, but on OpenGL they go
into the backend and make the context current. In addition they ensure
that Qt doesn't think that it's QOpenGLContext is current by calling
doneCurrent() on the QOpenGLContext::currentContext(). This unfortunately
causes an additional call to makeCurrent with a null context, but there
is no other way to tell Qt - it doesn't notice when a different context
is made current with low level API calls. In the multi-threaded
architecture this doesn't matter as ::currentContext() returns null.
A short evaluation showed that a transition to QOpenGLContext doesn't
seem feasible. Qt only supports either GLX or EGL while KWin supports
both and when entering the transition phase for Wayland, it would become
extremely tricky if our native platform is X11, but we want a Wayland
EGL context. A future solution might be to have a "KWin-QPA plugin" which
uses either xcb or Wayland and hides everything from Qt.
The API documentation is extended to describe when the effects-framework
ensures that an OpenGL context is current. The effects are changed to
make the context current in cases where it's not guaranteed. This has
been done by looking for creation or deletion of GLTextures and Shaders.
If there are other OpenGL usages outside the rendering loop, ctor/dtor
this needs to be changed, too.
2013-11-22 14:05:36 +00:00
|
|
|
effects->makeOpenGLContextCurrent();
|
2013-02-13 09:25:33 +00:00
|
|
|
if (border == ElectricTopLeft || border == ElectricTopRight || border == ElectricBottomRight || border == ElectricBottomLeft) {
|
|
|
|
glow->texture.reset(createCornerGlow<GLTexture>(border));
|
|
|
|
} else {
|
|
|
|
glow->texture.reset(createEdgeGlow<GLTexture>(border, geometry.size()));
|
|
|
|
}
|
|
|
|
if (!glow->texture.isNull()) {
|
|
|
|
glow->texture->setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
2013-02-21 17:21:46 +00:00
|
|
|
if (glow->texture.isNull()) {
|
|
|
|
delete glow;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
return nullptr;
|
2013-02-21 17:21:46 +00:00
|
|
|
}
|
2013-02-13 09:25:33 +00:00
|
|
|
} else if (effects->compositingType() == XRenderCompositing) {
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
if (border == ElectricTopLeft || border == ElectricTopRight || border == ElectricBottomRight || border == ElectricBottomLeft) {
|
|
|
|
glow->pictureSize = cornerGlowSize(border);
|
|
|
|
glow->picture.reset(createCornerGlow<XRenderPicture>(border));
|
|
|
|
} else {
|
|
|
|
glow->pictureSize = geometry.size();
|
|
|
|
glow->picture.reset(createEdgeGlow<XRenderPicture>(border, geometry.size()));
|
|
|
|
}
|
2013-02-21 17:21:46 +00:00
|
|
|
if (glow->picture.isNull()) {
|
|
|
|
delete glow;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
return nullptr;
|
2013-02-21 17:21:46 +00:00
|
|
|
}
|
2013-02-13 09:25:33 +00:00
|
|
|
#endif
|
2013-06-21 13:34:40 +00:00
|
|
|
} else if (effects->compositingType() == QPainterCompositing) {
|
|
|
|
if (border == ElectricTopLeft || border == ElectricTopRight || border == ElectricBottomRight || border == ElectricBottomLeft) {
|
|
|
|
glow->image.reset(createCornerGlow<QImage>(border));
|
|
|
|
glow->pictureSize = cornerGlowSize(border);
|
|
|
|
} else {
|
|
|
|
glow->image.reset(createEdgeGlow<QImage>(border, geometry.size()));
|
|
|
|
glow->pictureSize = geometry.size();
|
|
|
|
}
|
|
|
|
if (glow->image.isNull()) {
|
|
|
|
delete glow;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
return nullptr;
|
2013-06-21 13:34:40 +00:00
|
|
|
}
|
2013-01-31 12:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return glow;
|
|
|
|
}
|
|
|
|
|
2013-02-13 09:25:33 +00:00
|
|
|
template <typename T>
|
|
|
|
T *ScreenEdgeEffect::createCornerGlow(ElectricBorder border)
|
2013-01-31 12:31:49 +00:00
|
|
|
{
|
2017-09-28 08:18:36 +00:00
|
|
|
ensureGlowSvg();
|
|
|
|
|
2013-01-31 12:31:49 +00:00
|
|
|
switch (border) {
|
|
|
|
case ElectricTopLeft:
|
2013-08-13 05:19:09 +00:00
|
|
|
return new T(m_glow->pixmap(QStringLiteral("bottomright")).toImage());
|
2013-01-31 12:31:49 +00:00
|
|
|
case ElectricTopRight:
|
2013-08-13 05:19:09 +00:00
|
|
|
return new T(m_glow->pixmap(QStringLiteral("bottomleft")).toImage());
|
2013-01-31 12:31:49 +00:00
|
|
|
case ElectricBottomRight:
|
2013-08-13 05:19:09 +00:00
|
|
|
return new T(m_glow->pixmap(QStringLiteral("topleft")).toImage());
|
2013-01-31 12:31:49 +00:00
|
|
|
case ElectricBottomLeft:
|
2013-08-13 05:19:09 +00:00
|
|
|
return new T(m_glow->pixmap(QStringLiteral("topright")).toImage());
|
2013-01-31 12:31:49 +00:00
|
|
|
default:
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
return nullptr;
|
2013-01-31 12:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-28 08:18:36 +00:00
|
|
|
QSize ScreenEdgeEffect::cornerGlowSize(ElectricBorder border)
|
2013-02-13 09:25:33 +00:00
|
|
|
{
|
2017-09-28 08:18:36 +00:00
|
|
|
ensureGlowSvg();
|
|
|
|
|
2013-02-13 09:25:33 +00:00
|
|
|
switch (border) {
|
|
|
|
case ElectricTopLeft:
|
2013-07-23 05:02:52 +00:00
|
|
|
return m_glow->elementSize(QStringLiteral("bottomright"));
|
2013-02-13 09:25:33 +00:00
|
|
|
case ElectricTopRight:
|
2013-07-23 05:02:52 +00:00
|
|
|
return m_glow->elementSize(QStringLiteral("bottomleft"));
|
2013-02-13 09:25:33 +00:00
|
|
|
case ElectricBottomRight:
|
2013-07-23 05:02:52 +00:00
|
|
|
return m_glow->elementSize(QStringLiteral("topleft"));
|
2013-02-13 09:25:33 +00:00
|
|
|
case ElectricBottomLeft:
|
2013-07-23 05:02:52 +00:00
|
|
|
return m_glow->elementSize(QStringLiteral("topright"));
|
2013-02-13 09:25:33 +00:00
|
|
|
default:
|
|
|
|
return QSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T *ScreenEdgeEffect::createEdgeGlow(ElectricBorder border, const QSize &size)
|
2013-01-31 12:31:49 +00:00
|
|
|
{
|
2017-09-28 08:18:36 +00:00
|
|
|
ensureGlowSvg();
|
|
|
|
|
[effects/screenedge] Support "hint-stretch-borders"
Summary:
Some old themes have the flag set and also a style which expects the
borders to be stretched. Given that the documentation on techbase
describes widgets/glowbar still as "a frame without a prefix", one also
would assume that all the optional hints (which make sense) still apply.
Even more, the Air & Oxygen themes have the hint also set, though for
their rendering it makes no difference.
The small code needed seems worth the unbreaking of old themes as well
as giving theme creators another variable of freedom for their styles.
Test Plan:
Glow bar still works on all corners and edges with all themes as before,
though rendering now as expected for themes which have the
"hint-stretch-borders" set.
Reviewers: #kwin, zzag, davidedmundson
Reviewed By: #kwin, zzag, davidedmundson
Subscribers: davidedmundson, zzag, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D20621
2019-04-16 22:36:37 +00:00
|
|
|
const bool stretchBorder = m_glow->hasElement(QStringLiteral("hint-stretch-borders"));
|
|
|
|
|
2013-01-31 12:31:49 +00:00
|
|
|
QPoint pixmapPosition(0, 0);
|
|
|
|
QPixmap l, r, c;
|
|
|
|
switch (border) {
|
|
|
|
case ElectricTop:
|
2013-07-23 05:02:52 +00:00
|
|
|
l = m_glow->pixmap(QStringLiteral("bottomleft"));
|
|
|
|
r = m_glow->pixmap(QStringLiteral("bottomright"));
|
|
|
|
c = m_glow->pixmap(QStringLiteral("bottom"));
|
2013-01-31 12:31:49 +00:00
|
|
|
break;
|
|
|
|
case ElectricBottom:
|
2013-07-23 05:02:52 +00:00
|
|
|
l = m_glow->pixmap(QStringLiteral("topleft"));
|
|
|
|
r = m_glow->pixmap(QStringLiteral("topright"));
|
|
|
|
c = m_glow->pixmap(QStringLiteral("top"));
|
2013-01-31 12:31:49 +00:00
|
|
|
pixmapPosition = QPoint(0, size.height() - c.height());
|
|
|
|
break;
|
|
|
|
case ElectricLeft:
|
2013-07-23 05:02:52 +00:00
|
|
|
l = m_glow->pixmap(QStringLiteral("topright"));
|
|
|
|
r = m_glow->pixmap(QStringLiteral("bottomright"));
|
|
|
|
c = m_glow->pixmap(QStringLiteral("right"));
|
2013-01-31 12:31:49 +00:00
|
|
|
break;
|
|
|
|
case ElectricRight:
|
2013-07-23 05:02:52 +00:00
|
|
|
l = m_glow->pixmap(QStringLiteral("topleft"));
|
|
|
|
r = m_glow->pixmap(QStringLiteral("bottomleft"));
|
|
|
|
c = m_glow->pixmap(QStringLiteral("left"));
|
2013-01-31 12:31:49 +00:00
|
|
|
pixmapPosition = QPoint(size.width() - c.width(), 0);
|
|
|
|
break;
|
|
|
|
default:
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
return nullptr;
|
2013-01-31 12:31:49 +00:00
|
|
|
}
|
2013-02-13 09:25:33 +00:00
|
|
|
QPixmap image(size);
|
2013-01-31 12:31:49 +00:00
|
|
|
image.fill(Qt::transparent);
|
|
|
|
QPainter p;
|
|
|
|
p.begin(&image);
|
|
|
|
if (border == ElectricBottom || border == ElectricTop) {
|
|
|
|
p.drawPixmap(pixmapPosition, l);
|
[effects/screenedge] Support "hint-stretch-borders"
Summary:
Some old themes have the flag set and also a style which expects the
borders to be stretched. Given that the documentation on techbase
describes widgets/glowbar still as "a frame without a prefix", one also
would assume that all the optional hints (which make sense) still apply.
Even more, the Air & Oxygen themes have the hint also set, though for
their rendering it makes no difference.
The small code needed seems worth the unbreaking of old themes as well
as giving theme creators another variable of freedom for their styles.
Test Plan:
Glow bar still works on all corners and edges with all themes as before,
though rendering now as expected for themes which have the
"hint-stretch-borders" set.
Reviewers: #kwin, zzag, davidedmundson
Reviewed By: #kwin, zzag, davidedmundson
Subscribers: davidedmundson, zzag, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D20621
2019-04-16 22:36:37 +00:00
|
|
|
const QRect cRect(l.width(), pixmapPosition.y(), size.width() - l.width() - r.width(), c.height());
|
|
|
|
if (stretchBorder) {
|
|
|
|
p.drawPixmap(cRect, c);
|
|
|
|
} else {
|
|
|
|
p.drawTiledPixmap(cRect, c);
|
|
|
|
}
|
2013-01-31 12:31:49 +00:00
|
|
|
p.drawPixmap(QPoint(size.width() - r.width(), pixmapPosition.y()), r);
|
|
|
|
} else {
|
|
|
|
p.drawPixmap(pixmapPosition, l);
|
[effects/screenedge] Support "hint-stretch-borders"
Summary:
Some old themes have the flag set and also a style which expects the
borders to be stretched. Given that the documentation on techbase
describes widgets/glowbar still as "a frame without a prefix", one also
would assume that all the optional hints (which make sense) still apply.
Even more, the Air & Oxygen themes have the hint also set, though for
their rendering it makes no difference.
The small code needed seems worth the unbreaking of old themes as well
as giving theme creators another variable of freedom for their styles.
Test Plan:
Glow bar still works on all corners and edges with all themes as before,
though rendering now as expected for themes which have the
"hint-stretch-borders" set.
Reviewers: #kwin, zzag, davidedmundson
Reviewed By: #kwin, zzag, davidedmundson
Subscribers: davidedmundson, zzag, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D20621
2019-04-16 22:36:37 +00:00
|
|
|
const QRect cRect(pixmapPosition.x(), l.height(), c.width(), size.height() - l.height() - r.height());
|
|
|
|
if (stretchBorder) {
|
|
|
|
p.drawPixmap(cRect, c);
|
|
|
|
} else {
|
|
|
|
p.drawTiledPixmap(cRect, c);
|
|
|
|
}
|
2013-01-31 12:31:49 +00:00
|
|
|
p.drawPixmap(QPoint(pixmapPosition.x(), size.height() - r.height()), r);
|
|
|
|
}
|
|
|
|
p.end();
|
2013-08-13 05:19:09 +00:00
|
|
|
return new T(image.toImage());
|
2013-01-31 12:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ScreenEdgeEffect::isActive() const
|
|
|
|
{
|
2015-11-20 10:17:16 +00:00
|
|
|
return !m_borders.isEmpty() && !effects->isScreenLocked();
|
2013-01-31 12:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|