[Plasma Quick] Add WaylandIntegration class

Summary: It allows us to get rid of DialogShadows::waylandPlasmaShellInterface().

Reviewers: #plasma, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: kde-frameworks-devel

Tags: #frameworks

Maniphest Tasks: T12496

Differential Revision: https://phabricator.kde.org/D26491
This commit is contained in:
Vlad Zahorodnii 2020-01-07 13:21:32 +02:00
parent 1e5966147d
commit f5f43514af
6 changed files with 209 additions and 72 deletions

View File

@ -21,6 +21,10 @@ set(plasmaquick_LIB_SRC
../declarativeimports/core/units.cpp
)
if(HAVE_KWAYLAND)
set(plasmaquick_LIB_SRC ${plasmaquick_LIB_SRC} waylandintegration.cpp)
endif()
ecm_qt_declare_logging_category(PlasmaQuick_LIB_SRCS HEADER debug_p.h IDENTIFIER LOG_PLASMAQUICK CATEGORY_NAME org.kde.plasmaquick)
add_library(KF5PlasmaQuick SHARED ${plasmaquick_LIB_SRC})

View File

@ -48,6 +48,7 @@
#include <QDebug>
#if HAVE_KWAYLAND
#include "waylandintegration_p.h"
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/surface.h>
#endif
@ -704,7 +705,7 @@ void DialogPrivate::setupWaylandIntegration()
}
using namespace KWayland::Client;
PlasmaShell *interface = DialogShadows::self()->waylandPlasmaShellInterface();
PlasmaShell *interface = WaylandIntegration::self()->waylandPlasmaShell();
if (!interface) {
return;
}

View File

@ -32,12 +32,10 @@
#endif
#if HAVE_KWAYLAND
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/registry.h>
#include "waylandintegration_p.h"
#include <KWayland/Client/shadow.h>
#include <KWayland/Client/shm_pool.h>
#include <KWayland/Client/surface.h>
#include <KWayland/Client/plasmashell.h>
#endif
#include <qdebug.h>
@ -53,7 +51,6 @@ public:
, m_isX11(KWindowSystem::isPlatformX11())
#endif
{
setupWaylandIntegration();
}
~Private()
@ -80,8 +77,6 @@ public:
void windowDestroyed(QObject *deletedObject);
void setupData(Plasma::FrameSvg::EnabledBorders enabledBorders);
void setupWaylandIntegration();
DialogShadows *q;
QList<QPixmap> m_shadowPixmaps;
@ -104,10 +99,6 @@ public:
#if HAVE_KWAYLAND
struct Wayland {
KWayland::Client::ShadowManager *manager = nullptr;
KWayland::Client::ShmPool *shmPool = nullptr;
KWayland::Client::PlasmaShell *plasmaShell = nullptr;
QList<KWayland::Client::Buffer::Ptr> shadowBuffers;
};
Wayland m_wayland;
@ -308,9 +299,9 @@ void DialogShadows::Private::setupPixmaps()
m_emptyHorizontalPix = initEmptyPixmap(QSize(q->elementSize(QStringLiteral("shadow-top")).width(), 1));
#if HAVE_KWAYLAND
if (m_wayland.shmPool) {
if (KWayland::Client::ShmPool *shmPool = WaylandIntegration::self()->waylandShmPool()) {
for (auto it = m_shadowPixmaps.constBegin(); it != m_shadowPixmaps.constEnd(); ++it) {
m_wayland.shadowBuffers << m_wayland.shmPool->createBuffer(it->toImage());
m_wayland.shadowBuffers << shmPool->createBuffer(it->toImage());
}
}
#endif
@ -524,7 +515,7 @@ void DialogShadows::Private::updateShadow(const QWindow *window, Plasma::FrameSv
}
#endif
#if HAVE_KWAYLAND
if (m_wayland.manager) {
if (WaylandIntegration::self()->waylandShadowManager()) {
updateShadowWayland(window, enabledBorders);
}
#endif
@ -553,7 +544,7 @@ void DialogShadows::Private::updateShadowX11(const QWindow *window, Plasma::Fram
void DialogShadows::Private::updateShadowWayland(const QWindow *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
{
#if HAVE_KWAYLAND
if (!m_wayland.shmPool) {
if (!WaylandIntegration::self()->waylandShmPool()) {
return;
}
if (m_wayland.shadowBuffers.isEmpty()) {
@ -564,7 +555,8 @@ void DialogShadows::Private::updateShadowWayland(const QWindow *window, Plasma::
if (!surface) {
return;
}
auto shadow = m_wayland.manager->createShadow(surface, surface);
KWayland::Client::ShadowManager *manager = WaylandIntegration::self()->waylandShadowManager();
auto shadow = manager->createShadow(surface, surface);
//shadow-top
if (enabledBorders & Plasma::FrameSvg::TopBorder) {
@ -666,7 +658,7 @@ void DialogShadows::Private::clearShadow(const QWindow *window)
}
#endif
#if HAVE_KWAYLAND
if (m_wayland.manager) {
if (WaylandIntegration::self()->waylandShadowManager()) {
clearShadowWayland(window);
}
#endif
@ -688,7 +680,8 @@ void DialogShadows::Private::clearShadowWayland(const QWindow *window)
if (!surface) {
return;
}
m_wayland.manager->removeShadow(surface);
KWayland::Client::ShadowManager *manager = WaylandIntegration::self()->waylandShadowManager();
manager->removeShadow(surface);
surface->commit(KWayland::Client::Surface::CommitFlag::None);
#endif
}
@ -698,49 +691,5 @@ bool DialogShadows::enabled() const
return hasElement(QStringLiteral("shadow-left"));
}
KWayland::Client::PlasmaShell *DialogShadows::waylandPlasmaShellInterface() const
{
#if HAVE_KWAYLAND
return d->m_wayland.plasmaShell;
#else
return nullptr;
#endif
}
void DialogShadows::Private::setupWaylandIntegration()
{
#if HAVE_KWAYLAND
if (!KWindowSystem::isPlatformWayland()) {
return;
}
using namespace KWayland::Client;
ConnectionThread *connection = ConnectionThread::fromApplication(q);
if (!connection) {
return;
}
Registry *registry = new Registry(q);
registry->create(connection);
connect(registry, &Registry::shadowAnnounced, q,
[this, registry] (quint32 name, quint32 version) {
m_wayland.manager = registry->createShadowManager(name, version, q);
updateShadows();
}, Qt::QueuedConnection
);
connect(registry, &Registry::shmAnnounced, q,
[this, registry] (quint32 name, quint32 version) {
m_wayland.shmPool = registry->createShmPool(name, version, q);
updateShadows();
}, Qt::QueuedConnection
);
connect(registry, &Registry::plasmaShellAnnounced, q,
[this, registry] (quint32 name, quint32 version) {
m_wayland.plasmaShell = registry->createPlasmaShell(name, version, q);
}
);
registry->setup();
connection->roundtrip();
#endif
}
#include "moc_dialogshadows_p.cpp"

View File

@ -24,14 +24,6 @@
#include "plasma/framesvg.h"
#include "plasma/svg.h"
namespace KWayland
{
namespace Client
{
class PlasmaShell;
}
}
class DialogShadows : public Plasma::Svg
{
Q_OBJECT
@ -49,8 +41,6 @@ public:
bool enabled() const;
KWayland::Client::PlasmaShell *waylandPlasmaShellInterface() const;
private:
class Private;
Private *const d;

View File

@ -0,0 +1,132 @@
/*
* Copyright 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
*
* Based on WaylandIntegration from kwayland-integration
*
* Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
* Copyright 2015 Marco Martin <mart@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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "waylandintegration_p.h"
#include "debug_p.h"
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/shadow.h>
#include <KWayland/Client/shm_pool.h>
#include <QCoreApplication>
class WaylandIntegrationSingleton
{
public:
WaylandIntegration self;
};
Q_GLOBAL_STATIC(WaylandIntegrationSingleton, privateWaylandIntegrationSelf)
WaylandIntegration::WaylandIntegration(QObject *parent)
: QObject(parent)
{
setupKWaylandIntegration();
}
WaylandIntegration::~WaylandIntegration()
{
}
KWayland::Client::PlasmaShell *WaylandIntegration::waylandPlasmaShell()
{
if (!m_waylandPlasmaShell && m_registry) {
const KWayland::Client::Registry::AnnouncedInterface interface =
m_registry->interface(KWayland::Client::Registry::Interface::PlasmaShell);
if (interface.name == 0) {
qCWarning(LOG_PLASMAQUICK) << "The compositor does not support the plasma shell protocol";
return nullptr;
}
m_waylandPlasmaShell = m_registry->createPlasmaShell(interface.name, interface.version, qApp);
connect(m_waylandPlasmaShell, &KWayland::Client::PlasmaShell::removed, this, [this]() {
m_waylandPlasmaShell->deleteLater();
});
}
return m_waylandPlasmaShell;
}
KWayland::Client::ShadowManager *WaylandIntegration::waylandShadowManager()
{
if (!m_waylandShadowManager && m_registry) {
const KWayland::Client::Registry::AnnouncedInterface interface =
m_registry->interface(KWayland::Client::Registry::Interface::Shadow);
if (interface.name == 0) {
qCWarning(LOG_PLASMAQUICK) << "The compositor does not support the shadow protocol";
return nullptr;
}
m_waylandShadowManager = m_registry->createShadowManager(interface.name, interface.version, qApp);
connect(m_waylandShadowManager, &KWayland::Client::ShadowManager::removed, this, [this]() {
m_waylandShadowManager->deleteLater();
});
}
return m_waylandShadowManager;
}
KWayland::Client::ShmPool *WaylandIntegration::waylandShmPool()
{
if (!m_waylandShmPool && m_registry) {
const KWayland::Client::Registry::AnnouncedInterface interface =
m_registry->interface(KWayland::Client::Registry::Interface::Shm);
if (interface.name == 0) {
return nullptr;
}
m_waylandShmPool = m_registry->createShmPool(interface.name, interface.version, qApp);
connect(m_waylandShmPool, &KWayland::Client::ShmPool::removed, this, [this]() {
m_waylandShmPool->deleteLater();
});
}
return m_waylandShmPool;
}
WaylandIntegration *WaylandIntegration::self()
{
return &privateWaylandIntegrationSelf()->self;
}
void WaylandIntegration::setupKWaylandIntegration()
{
KWayland::Client::ConnectionThread *connection = KWayland::Client::ConnectionThread::fromApplication(this);
if (!connection) {
return;
}
m_registry = new KWayland::Client::Registry(qApp);
m_registry->create(connection);
m_registry->setup();
connection->roundtrip();
}

View File

@ -0,0 +1,61 @@
/*
* Copyright 2020 Vlad Zahorodnii <vlad.zahorodnii@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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef WAYLANDINTEGRATION_P_H
#define WAYLANDINTEGRATION_P_H
#include <QObject>
#include <QPointer>
namespace KWayland
{
namespace Client
{
class PlasmaShell;
class Registry;
class ShadowManager;
class ShmPool;
}
}
class WaylandIntegration : public QObject
{
Q_OBJECT
public:
explicit WaylandIntegration(QObject *parent = nullptr);
~WaylandIntegration() override;
KWayland::Client::PlasmaShell *waylandPlasmaShell();
KWayland::Client::ShadowManager *waylandShadowManager();
KWayland::Client::ShmPool *waylandShmPool();
static WaylandIntegration *self();
private:
void setupKWaylandIntegration();
QPointer<KWayland::Client::Registry> m_registry;
QPointer<KWayland::Client::PlasmaShell> m_waylandPlasmaShell;
QPointer<KWayland::Client::ShadowManager> m_waylandShadowManager;
QPointer<KWayland::Client::ShmPool> m_waylandShmPool;
Q_DISABLE_COPY(WaylandIntegration)
};
#endif // WAYLANDINTEGRATION_P_H