update PanelShadows to upstream code

pull/16/head
Michail Vourlakos 5 years ago
parent d62e77eca7
commit a2edffa8e7

@ -96,7 +96,7 @@ Theme::~Theme()
bool Theme::hasShadow() const bool Theme::hasShadow() const
{ {
return PanelShadows::self()->enabled(); return PanelShadows::self()->hasShadows();
} }
bool Theme::isLightTheme() const bool Theme::isLightTheme() const

@ -18,30 +18,27 @@
#include "panelshadows_p.h" #include "panelshadows_p.h"
// local
#include <config-latte.h>
// Qt
#include <QDebug>
#include <QWindow> #include <QWindow>
#include <QPainter> #include <QPainter>
// KDE #include <config-latte.h>
#include <KWindowSystem>
#if HAVE_X11
#include <QX11Info>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xlib-xcb.h>
#include <fixx11h.h>
#endif
#include <KWayland/Client/connection_thread.h> #include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/registry.h> #include <KWayland/Client/registry.h>
#include <KWayland/Client/shadow.h> #include <KWayland/Client/shadow.h>
#include <KWayland/Client/shm_pool.h> #include <KWayland/Client/shm_pool.h>
#include <KWayland/Client/surface.h> #include <KWayland/Client/surface.h>
#include <KWindowSystem>
// X11 #include <qdebug.h>
#if HAVE_X11
#include <QX11Info>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xlib-xcb.h>
#include <fixx11h.h>
#endif
class PanelShadows::Private class PanelShadows::Private
{ {
@ -49,15 +46,16 @@ public:
Private(PanelShadows *shadows) Private(PanelShadows *shadows)
: q(shadows) : q(shadows)
#if HAVE_X11 #if HAVE_X11
, _connection(nullptr), ,_connection( nullptr ),
_gc(0x0) _gc( 0x0 )
, m_isX11(KWindowSystem::isPlatformX11()) , m_isX11(KWindowSystem::isPlatformX11())
#endif #endif
{ {
setupWaylandIntegration(); setupWaylandIntegration();
} }
~Private() { ~Private()
{
// Do not call clearPixmaps() from here: it creates new QPixmap(), // Do not call clearPixmaps() from here: it creates new QPixmap(),
// which causes a crash when application is stopping. // which causes a crash when application is stopping.
freeX11Pixmaps(); freeX11Pixmaps();
@ -67,7 +65,7 @@ public:
void freeWaylandBuffers(); void freeWaylandBuffers();
void clearPixmaps(); void clearPixmaps();
void setupPixmaps(); void setupPixmaps();
Qt::HANDLE createPixmap(const QPixmap &source); Qt::HANDLE createPixmap(const QPixmap& source);
void initPixmap(const QString &element); void initPixmap(const QString &element);
QPixmap initEmptyPixmap(const QSize &size); QPixmap initEmptyPixmap(const QSize &size);
void updateShadow(const QWindow *window, Plasma::FrameSvg::EnabledBorders); void updateShadow(const QWindow *window, Plasma::FrameSvg::EnabledBorders);
@ -77,8 +75,8 @@ public:
void clearShadowX11(const QWindow *window); void clearShadowX11(const QWindow *window);
void clearShadowWayland(const QWindow *window); void clearShadowWayland(const QWindow *window);
void updateShadows(); void updateShadows();
void windowDestroyed(QObject *deletedObject);
void setupData(Plasma::FrameSvg::EnabledBorders enabledBorders); void setupData(Plasma::FrameSvg::EnabledBorders enabledBorders);
bool hasShadows() const;
void setupWaylandIntegration(); void setupWaylandIntegration();
@ -95,15 +93,14 @@ public:
#if HAVE_X11 #if HAVE_X11
//! xcb connection //! xcb connection
xcb_connection_t *_connection; xcb_connection_t* _connection;
//! graphical context //! graphical context
xcb_gcontext_t _gc; xcb_gcontext_t _gc;
bool m_isX11; bool m_isX11;
#endif #endif
struct Wayland struct Wayland {
{
KWayland::Client::ShadowManager *manager = nullptr; KWayland::Client::ShadowManager *manager = nullptr;
KWayland::Client::ShmPool *shmPool = nullptr; KWayland::Client::ShmPool *shmPool = nullptr;
@ -111,17 +108,18 @@ public:
}; };
Wayland m_wayland; Wayland m_wayland;
QHash<Plasma::FrameSvg::EnabledBorders, QVector<unsigned long>> data; QHash<Plasma::FrameSvg::EnabledBorders, QVector<unsigned long> > data;
QHash<const QWindow *, Plasma::FrameSvg::EnabledBorders> m_windows; QHash<const QWindow *, Plasma::FrameSvg::EnabledBorders> m_windows;
}; };
class PanelShadowsSingleton class PanelShadowsSingleton
{ {
public: public:
PanelShadowsSingleton() { PanelShadowsSingleton()
{
} }
PanelShadows self; PanelShadows self;
}; };
Q_GLOBAL_STATIC(PanelShadowsSingleton, privatePanelShadowsSelf) Q_GLOBAL_STATIC(PanelShadowsSingleton, privatePanelShadowsSelf)
@ -131,7 +129,9 @@ PanelShadows::PanelShadows(QObject *parent, const QString &prefix)
d(new Private(this)) d(new Private(this))
{ {
setImagePath(prefix); setImagePath(prefix);
connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateShadows())); connect(this, &Plasma::Svg::repaintNeeded, this, [this]() {
d->updateShadows();
});
} }
PanelShadows::~PanelShadows() PanelShadows::~PanelShadows()
@ -152,8 +152,12 @@ void PanelShadows::addWindow(const QWindow *window, Plasma::FrameSvg::EnabledBor
d->m_windows[window] = enabledBorders; d->m_windows[window] = enabledBorders;
d->updateShadow(window, enabledBorders); d->updateShadow(window, enabledBorders);
connect(window, SIGNAL(destroyed(QObject *)), connect(window, &QObject::destroyed, this, [this, window]() {
this, SLOT(windowDestroyed(QObject *)), Qt::UniqueConnection); d->m_windows.remove(window);
if (d->m_windows.isEmpty()) {
d->clearPixmaps();
}
});
} }
void PanelShadows::removeWindow(const QWindow *window) void PanelShadows::removeWindow(const QWindow *window)
@ -171,6 +175,11 @@ void PanelShadows::removeWindow(const QWindow *window)
} }
} }
bool PanelShadows::hasShadows() const
{
return hasElement(QStringLiteral("shadow-left"));
}
void PanelShadows::setEnabledBorders(const QWindow *window, Plasma::FrameSvg::EnabledBorders enabledBorders) void PanelShadows::setEnabledBorders(const QWindow *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
{ {
if (!window || !d->m_windows.contains(window)) { if (!window || !d->m_windows.contains(window)) {
@ -181,31 +190,33 @@ void PanelShadows::setEnabledBorders(const QWindow *window, Plasma::FrameSvg::En
d->updateShadow(window, enabledBorders); d->updateShadow(window, enabledBorders);
} }
void PanelShadows::Private::windowDestroyed(QObject *deletedObject)
{
m_windows.remove(static_cast<QWindow *>(deletedObject));
if (m_windows.isEmpty()) {
clearPixmaps();
}
}
void PanelShadows::Private::updateShadows() void PanelShadows::Private::updateShadows()
{ {
setupPixmaps(); const bool hadShadowsBefore = !m_shadowPixmaps.isEmpty();
QHash<const QWindow *, Plasma::FrameSvg::EnabledBorders>::const_iterator i;
for (i = m_windows.constBegin(); i != m_windows.constEnd(); ++i) { // has shadows now?
updateShadow(i.key(), i.value()); if (hasShadows()) {
if (hadShadowsBefore) {
clearPixmaps();
}
for (auto i = m_windows.constBegin(); i != m_windows.constEnd(); ++i) {
updateShadow(i.key(), i.value());
}
} else {
if (hadShadowsBefore) {
for (auto i = m_windows.constBegin(); i != m_windows.constEnd(); ++i) {
clearShadow(i.key());
}
clearPixmaps();
}
} }
} }
Qt::HANDLE PanelShadows::Private::createPixmap(const QPixmap &source) Qt::HANDLE PanelShadows::Private::createPixmap(const QPixmap& source)
{ {
// do nothing for invalid pixmaps // do nothing for invalid pixmaps
if (source.isNull()) return nullptr; if( source.isNull() ) return nullptr;
/* /*
in some cases, pixmap handle is invalid. This is the case notably in some cases, pixmap handle is invalid. This is the case notably
@ -213,25 +224,25 @@ Qt::HANDLE PanelShadows::Private::createPixmap(const QPixmap &source)
explicitly and draw the source pixmap on it. explicitly and draw the source pixmap on it.
*/ */
#if HAVE_X11 #if HAVE_X11
if (!m_isX11) { if (!m_isX11) {
return nullptr; return nullptr;
} }
// check connection // check connection
if (!_connection) _connection = QX11Info::connection(); if( !_connection ) _connection = QX11Info::connection();
const int width(source.width()); const int width( source.width() );
const int height(source.height()); const int height( source.height() );
// create X11 pixmap // create X11 pixmap
Pixmap pixmap = XCreatePixmap(QX11Info::display(), QX11Info::appRootWindow(), width, height, 32); Pixmap pixmap = XCreatePixmap( QX11Info::display(), QX11Info::appRootWindow(), width, height, 32 );
// check gc // check gc
if (!_gc) { if( !_gc )
_gc = xcb_generate_id(_connection); {
xcb_create_gc(_connection, _gc, pixmap, 0, nullptr); _gc = xcb_generate_id( _connection );
xcb_create_gc( _connection, _gc, pixmap, 0, nullptr );
} }
// // create explicitly shared QPixmap from it // // create explicitly shared QPixmap from it
@ -246,18 +257,18 @@ Qt::HANDLE PanelShadows::Private::createPixmap(const QPixmap &source)
// //
// //
// return pixmap; // return pixmap;
QImage image(source.toImage()); QImage image( source.toImage() );
xcb_put_image( xcb_put_image(
_connection, XCB_IMAGE_FORMAT_Z_PIXMAP, pixmap, _gc, _connection, XCB_IMAGE_FORMAT_Z_PIXMAP, pixmap, _gc,
image.width(), image.height(), 0, 0, image.width(), image.height(), 0, 0,
0, 32, 0, 32,
image.byteCount(), image.constBits()); image.sizeInBytes(), image.constBits());
return (Qt::HANDLE)pixmap; return (Qt::HANDLE)pixmap;
#else #else
return 0; return 0;
#endif #endif
} }
@ -269,17 +280,13 @@ void PanelShadows::Private::initPixmap(const QString &element)
QPixmap PanelShadows::Private::initEmptyPixmap(const QSize &size) QPixmap PanelShadows::Private::initEmptyPixmap(const QSize &size)
{ {
#if HAVE_X11 #if HAVE_X11
if (!m_isX11) { if (!m_isX11) {
return QPixmap(); return QPixmap();
} }
QPixmap tempEmptyPix(size); QPixmap tempEmptyPix(size);
if (!size.isEmpty()) { if (!size.isEmpty()) {
tempEmptyPix.fill(Qt::transparent); tempEmptyPix.fill(Qt::transparent);
} }
return tempEmptyPix; return tempEmptyPix;
#else #else
Q_UNUSED(size) Q_UNUSED(size)
@ -299,7 +306,7 @@ void PanelShadows::Private::setupPixmaps()
initPixmap(QStringLiteral("shadow-left")); initPixmap(QStringLiteral("shadow-left"));
initPixmap(QStringLiteral("shadow-topleft")); initPixmap(QStringLiteral("shadow-topleft"));
m_emptyCornerPix = initEmptyPixmap(QSize(1, 1)); m_emptyCornerPix = initEmptyPixmap(QSize(1,1));
m_emptyCornerLeftPix = initEmptyPixmap(QSize(q->elementSize(QStringLiteral("shadow-topleft")).width(), 1)); m_emptyCornerLeftPix = initEmptyPixmap(QSize(q->elementSize(QStringLiteral("shadow-topleft")).width(), 1));
m_emptyCornerTopPix = initEmptyPixmap(QSize(1, q->elementSize(QStringLiteral("shadow-topleft")).height())); m_emptyCornerTopPix = initEmptyPixmap(QSize(1, q->elementSize(QStringLiteral("shadow-topleft")).height()));
m_emptyCornerRightPix = initEmptyPixmap(QSize(q->elementSize(QStringLiteral("shadow-bottomright")).width(), 1)); m_emptyCornerRightPix = initEmptyPixmap(QSize(q->elementSize(QStringLiteral("shadow-bottomright")).width(), 1));
@ -318,11 +325,9 @@ void PanelShadows::Private::setupPixmaps()
void PanelShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBorders) void PanelShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBorders)
{ {
#if HAVE_X11 #if HAVE_X11
if (!m_isX11) { if (!m_isX11) {
return; return;
} }
//shadow-top //shadow-top
if (enabledBorders & Plasma::FrameSvg::TopBorder) { if (enabledBorders & Plasma::FrameSvg::TopBorder) {
data[enabledBorders] << reinterpret_cast<unsigned long>(createPixmap(m_shadowPixmaps[0])); data[enabledBorders] << reinterpret_cast<unsigned long>(createPixmap(m_shadowPixmaps[0]));
@ -398,16 +403,13 @@ void PanelShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBo
} else { } else {
data[enabledBorders] << reinterpret_cast<unsigned long>(createPixmap(m_emptyCornerPix)); data[enabledBorders] << reinterpret_cast<unsigned long>(createPixmap(m_emptyCornerPix));
} }
#endif #endif
int left, top, right, bottom = 0; int left, top, right, bottom = 0;
QSize marginHint; QSize marginHint;
if (enabledBorders & Plasma::FrameSvg::TopBorder) { if (enabledBorders & Plasma::FrameSvg::TopBorder) {
marginHint = q->elementSize(QStringLiteral("shadow-hint-top-margin")); marginHint = q->elementSize(QStringLiteral("shadow-hint-top-margin"));
if (marginHint.isValid()) { if (marginHint.isValid()) {
top = marginHint.height(); top = marginHint.height();
} else { } else {
@ -419,7 +421,6 @@ void PanelShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBo
if (enabledBorders & Plasma::FrameSvg::RightBorder) { if (enabledBorders & Plasma::FrameSvg::RightBorder) {
marginHint = q->elementSize(QStringLiteral("shadow-hint-right-margin")); marginHint = q->elementSize(QStringLiteral("shadow-hint-right-margin"));
if (marginHint.isValid()) { if (marginHint.isValid()) {
right = marginHint.width(); right = marginHint.width();
} else { } else {
@ -431,7 +432,6 @@ void PanelShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBo
if (enabledBorders & Plasma::FrameSvg::BottomBorder) { if (enabledBorders & Plasma::FrameSvg::BottomBorder) {
marginHint = q->elementSize(QStringLiteral("shadow-hint-bottom-margin")); marginHint = q->elementSize(QStringLiteral("shadow-hint-bottom-margin"));
if (marginHint.isValid()) { if (marginHint.isValid()) {
bottom = marginHint.height(); bottom = marginHint.height();
} else { } else {
@ -443,7 +443,6 @@ void PanelShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBo
if (enabledBorders & Plasma::FrameSvg::LeftBorder) { if (enabledBorders & Plasma::FrameSvg::LeftBorder) {
marginHint = q->elementSize(QStringLiteral("shadow-hint-left-margin")); marginHint = q->elementSize(QStringLiteral("shadow-hint-left-margin"));
if (marginHint.isValid()) { if (marginHint.isValid()) {
left = marginHint.width(); left = marginHint.width();
} else { } else {
@ -459,18 +458,16 @@ void PanelShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBo
void PanelShadows::Private::freeX11Pixmaps() void PanelShadows::Private::freeX11Pixmaps()
{ {
#if HAVE_X11 #if HAVE_X11
if (!m_isX11) { if (!m_isX11) {
return; return;
} }
auto *display = QX11Info::display(); auto *display = QX11Info::display();
if (!display) { if (!display) {
return; return;
} }
for (const QPixmap &pixmap : m_shadowPixmaps) { foreach (const QPixmap &pixmap, m_shadowPixmaps) {
if (!pixmap.isNull()) { if (!pixmap.isNull()) {
XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(pixmap))); XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(pixmap)));
} }
@ -479,31 +476,24 @@ void PanelShadows::Private::freeX11Pixmaps()
if (!m_emptyCornerPix.isNull()) { if (!m_emptyCornerPix.isNull()) {
XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyCornerPix))); XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyCornerPix)));
} }
if (!m_emptyCornerBottomPix.isNull()) { if (!m_emptyCornerBottomPix.isNull()) {
XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyCornerBottomPix))); XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyCornerBottomPix)));
} }
if (!m_emptyCornerLeftPix.isNull()) { if (!m_emptyCornerLeftPix.isNull()) {
XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyCornerLeftPix))); XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyCornerLeftPix)));
} }
if (!m_emptyCornerRightPix.isNull()) { if (!m_emptyCornerRightPix.isNull()) {
XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyCornerRightPix))); XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyCornerRightPix)));
} }
if (!m_emptyCornerTopPix.isNull()) { if (!m_emptyCornerTopPix.isNull()) {
XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyCornerTopPix))); XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyCornerTopPix)));
} }
if (!m_emptyVerticalPix.isNull()) { if (!m_emptyVerticalPix.isNull()) {
XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyVerticalPix))); XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyVerticalPix)));
} }
if (!m_emptyHorizontalPix.isNull()) { if (!m_emptyHorizontalPix.isNull()) {
XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyHorizontalPix))); XFreePixmap(display, reinterpret_cast<unsigned long>(createPixmap(m_emptyHorizontalPix)));
} }
#endif #endif
} }
@ -532,14 +522,15 @@ void PanelShadows::Private::freeWaylandBuffers()
void PanelShadows::Private::updateShadow(const QWindow *window, Plasma::FrameSvg::EnabledBorders enabledBorders) void PanelShadows::Private::updateShadow(const QWindow *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
{ {
#if HAVE_X11 if (!hasShadows()) {
return;
}
#if HAVE_X11
if (m_isX11) { if (m_isX11) {
updateShadowX11(window, enabledBorders); updateShadowX11(window, enabledBorders);
} }
#endif #endif
if (m_wayland.manager) { if (m_wayland.manager) {
updateShadowWayland(window, enabledBorders); updateShadowWayland(window, enabledBorders);
} }
@ -548,7 +539,6 @@ void PanelShadows::Private::updateShadow(const QWindow *window, Plasma::FrameSvg
void PanelShadows::Private::updateShadowX11(const QWindow *window, Plasma::FrameSvg::EnabledBorders enabledBorders) void PanelShadows::Private::updateShadowX11(const QWindow *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
{ {
#if HAVE_X11 #if HAVE_X11
if (m_shadowPixmaps.isEmpty()) { if (m_shadowPixmaps.isEmpty()) {
setupPixmaps(); setupPixmaps();
} }
@ -571,18 +561,14 @@ void PanelShadows::Private::updateShadowWayland(const QWindow *window, Plasma::F
if (!m_wayland.shmPool) { if (!m_wayland.shmPool) {
return; return;
} }
if (m_wayland.shadowBuffers.isEmpty()) { if (m_wayland.shadowBuffers.isEmpty()) {
setupPixmaps(); setupPixmaps();
} }
// TODO: check whether the surface already has a shadow // TODO: check whether the surface already has a shadow
KWayland::Client::Surface *surface = KWayland::Client::Surface::fromWindow(const_cast<QWindow *>(window)); KWayland::Client::Surface *surface = KWayland::Client::Surface::fromWindow(const_cast<QWindow*>(window));
if (!surface) { if (!surface) {
return; return;
} }
auto shadow = m_wayland.manager->createShadow(surface, surface); auto shadow = m_wayland.manager->createShadow(surface, surface);
//shadow-top //shadow-top
@ -630,11 +616,9 @@ void PanelShadows::Private::updateShadowWayland(const QWindow *window, Plasma::F
} }
QSize marginHint; QSize marginHint;
QMarginsF margins = QMarginsF(1, 1, 1, 1); QMarginsF margins;
if (enabledBorders & Plasma::FrameSvg::TopBorder) { if (enabledBorders & Plasma::FrameSvg::TopBorder) {
marginHint = q->elementSize(QStringLiteral("shadow-hint-top-margin")); marginHint = q->elementSize(QStringLiteral("shadow-hint-top-margin"));
if (marginHint.isValid()) { if (marginHint.isValid()) {
margins.setTop(marginHint.height()); margins.setTop(marginHint.height());
} else { } else {
@ -644,7 +628,6 @@ void PanelShadows::Private::updateShadowWayland(const QWindow *window, Plasma::F
if (enabledBorders & Plasma::FrameSvg::RightBorder) { if (enabledBorders & Plasma::FrameSvg::RightBorder) {
marginHint = q->elementSize(QStringLiteral("shadow-hint-right-margin")); marginHint = q->elementSize(QStringLiteral("shadow-hint-right-margin"));
if (marginHint.isValid()) { if (marginHint.isValid()) {
margins.setRight(marginHint.width()); margins.setRight(marginHint.width());
} else { } else {
@ -654,7 +637,6 @@ void PanelShadows::Private::updateShadowWayland(const QWindow *window, Plasma::F
if (enabledBorders & Plasma::FrameSvg::BottomBorder) { if (enabledBorders & Plasma::FrameSvg::BottomBorder) {
marginHint = q->elementSize(QStringLiteral("shadow-hint-bottom-margin")); marginHint = q->elementSize(QStringLiteral("shadow-hint-bottom-margin"));
if (marginHint.isValid()) { if (marginHint.isValid()) {
margins.setBottom(marginHint.height()); margins.setBottom(marginHint.height());
} else { } else {
@ -664,7 +646,6 @@ void PanelShadows::Private::updateShadowWayland(const QWindow *window, Plasma::F
if (enabledBorders & Plasma::FrameSvg::LeftBorder) { if (enabledBorders & Plasma::FrameSvg::LeftBorder) {
marginHint = q->elementSize(QStringLiteral("shadow-hint-left-margin")); marginHint = q->elementSize(QStringLiteral("shadow-hint-left-margin"));
if (marginHint.isValid()) { if (marginHint.isValid()) {
margins.setLeft(marginHint.width()); margins.setLeft(marginHint.width());
} else { } else {
@ -679,25 +660,21 @@ void PanelShadows::Private::updateShadowWayland(const QWindow *window, Plasma::F
void PanelShadows::Private::clearShadow(const QWindow *window) void PanelShadows::Private::clearShadow(const QWindow *window)
{ {
if (!static_cast<const QSurface *>(window)->surfaceHandle()) { if (!static_cast<const QSurface*>(window)->surfaceHandle()) {
qWarning() << "Cannot clear shadow from window without native surface!"; qWarning() << "Cannot clear shadow from window without native surface!";
return; return;
} }
#if HAVE_X11 #if HAVE_X11
if (m_isX11) { if (m_isX11) {
clearShadowX11(window); clearShadowX11(window);
} }
#endif #endif
if (m_wayland.manager) { if (m_wayland.manager) {
clearShadowWayland(window); clearShadowWayland(window);
} }
} }
void PanelShadows::Private::clearShadowX11(const QWindow *window) void PanelShadows::Private::clearShadowX11(const QWindow* window)
{ {
#if HAVE_X11 #if HAVE_X11
Display *dpy = QX11Info::display(); Display *dpy = QX11Info::display();
@ -708,19 +685,17 @@ void PanelShadows::Private::clearShadowX11(const QWindow *window)
void PanelShadows::Private::clearShadowWayland(const QWindow *window) void PanelShadows::Private::clearShadowWayland(const QWindow *window)
{ {
KWayland::Client::Surface *surface = KWayland::Client::Surface::fromWindow(const_cast<QWindow *>(window)); KWayland::Client::Surface *surface = KWayland::Client::Surface::fromWindow(const_cast<QWindow*>(window));
if (!surface) { if (!surface) {
return; return;
} }
m_wayland.manager->removeShadow(surface); m_wayland.manager->removeShadow(surface);
surface->commit(KWayland::Client::Surface::CommitFlag::None); surface->commit(KWayland::Client::Surface::CommitFlag::None);
} }
bool PanelShadows::enabled() const bool PanelShadows::Private::hasShadows() const
{ {
return hasElement(QStringLiteral("shadow-left")); return q->hasShadows();
} }
void PanelShadows::Private::setupWaylandIntegration() void PanelShadows::Private::setupWaylandIntegration()
@ -728,28 +703,25 @@ void PanelShadows::Private::setupWaylandIntegration()
if (!KWindowSystem::isPlatformWayland()) { if (!KWindowSystem::isPlatformWayland()) {
return; return;
} }
using namespace KWayland::Client; using namespace KWayland::Client;
ConnectionThread *connection = ConnectionThread::fromApplication(q); ConnectionThread *connection = ConnectionThread::fromApplication(q);
if (!connection) { if (!connection) {
return; return;
} }
Registry *registry = new Registry(q); Registry *registry = new Registry(q);
registry->create(connection); registry->create(connection);
connect(registry, &Registry::shadowAnnounced, q, connect(registry, &Registry::shadowAnnounced, q,
[this, registry](quint32 name, quint32 version) { [this, registry] (quint32 name, quint32 version) {
m_wayland.manager = registry->createShadowManager(name, version, q); m_wayland.manager = registry->createShadowManager(name, version, q);
updateShadows(); updateShadows();
}, Qt::QueuedConnection }, Qt::QueuedConnection
); );
connect(registry, &Registry::shmAnnounced, q, connect(registry, &Registry::shmAnnounced, q,
[this, registry](quint32 name, quint32 version) { [this, registry] (quint32 name, quint32 version) {
m_wayland.shmPool = registry->createShmPool(name, version, q); m_wayland.shmPool = registry->createShmPool(name, version, q);
updateShadows(); updateShadows();
}, Qt::QueuedConnection }, Qt::QueuedConnection
); );
registry->setup(); registry->setup();
connection->roundtrip(); connection->roundtrip();
} }

@ -19,10 +19,8 @@
#ifndef PANELSHADOWS_P_H #ifndef PANELSHADOWS_P_H
#define PANELSHADOWS_P_H #define PANELSHADOWS_P_H
// Qt
#include <QSet> #include <QSet>
// Plasma
#include "plasma/framesvg.h" #include "plasma/framesvg.h"
#include "plasma/svg.h" #include "plasma/svg.h"
@ -42,14 +40,11 @@ public:
void setEnabledBorders(const QWindow *window, Plasma::FrameSvg::EnabledBorders enabledBorders = Plasma::FrameSvg::AllBorders); void setEnabledBorders(const QWindow *window, Plasma::FrameSvg::EnabledBorders enabledBorders = Plasma::FrameSvg::AllBorders);
bool enabled() const; bool hasShadows() const;
private: private:
class Private; class Private;
Private *const d; Private * const d;
Q_PRIVATE_SLOT(d, void updateShadows())
Q_PRIVATE_SLOT(d, void windowDestroyed(QObject *deletedObject))
}; };
#endif #endif

Loading…
Cancel
Save