Commit 8b024494 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

[windowsystem] Provide a KWindowShadow implementation

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: davidedmundson, plasma-devel

Tags: #plasma

Maniphest Tasks: T12496

Differential Revision: https://phabricator.kde.org/D26458
parent aae0cdd1
......@@ -3,8 +3,9 @@ set(wayland_plugin_SRCS
plugin.cpp
waylandintegration.cpp
windoweffects.cpp
windowsystem.cpp
windowinfo.cpp
windowshadow.cpp
windowsystem.cpp
)
ecm_qt_declare_logging_category(wayland_plugin_SRCS HEADER logging.h IDENTIFIER KWAYLAND_KWS CATEGORY_NAME org.kde.kf5.kwindowsystem.kwayland DEFAULT_SEVERITY Warning)
......
......@@ -18,6 +18,7 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "plugin.h"
#include "windowshadow.h"
#include "windowsystem.h"
#include "windoweffects.h"
#include "windowinfo.h"
......@@ -45,3 +46,13 @@ KWindowInfoPrivate *KWaylandPlugin::createWindowInfo(WId window, NET::Properties
{
return new WindowInfo(window, properties, properties2);
}
KWindowShadowTilePrivate *KWaylandPlugin::createWindowShadowTile()
{
return new WindowShadowTile();
}
KWindowShadowPrivate *KWaylandPlugin::createWindowShadow()
{
return new WindowShadow();
}
......@@ -35,6 +35,8 @@ public:
KWindowEffectsPrivate *createEffects() override;
KWindowSystemPrivate *createWindowSystem() override;
KWindowInfoPrivate *createWindowInfo(WId window, NET::Properties properties, NET::Properties2 properties2) override;
KWindowShadowTilePrivate *createWindowShadowTile() override;
KWindowShadowPrivate *createWindowShadow() override;
};
#endif
/*
* Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
* Copyright 2015 Marco Martin <mart@kde.org>
* Copyright 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -32,6 +33,8 @@
#include <KWayland/Client/contrast.h>
#include <KWayland/Client/region.h>
#include <KWayland/Client/slide.h>
#include <KWayland/Client/shadow.h>
#include <KWayland/Client/shm_pool.h>
#include <KWindowSystem/KWindowSystem>
......@@ -143,6 +146,28 @@ KWayland::Client::SlideManager *WaylandIntegration::waylandSlideManager()
return m_waylandSlideManager;
}
KWayland::Client::ShadowManager *WaylandIntegration::waylandShadowManager()
{
if (!m_waylandShadowManager && m_registry) {
const KWayland::Client::Registry::AnnouncedInterface wmInterface = m_registry->interface(KWayland::Client::Registry::Interface::Shadow);
if (wmInterface.name == 0) {
qCWarning(KWAYLAND_KWS) << "This compositor does not support the Shadow interface";
return nullptr;
}
m_waylandShadowManager = m_registry->createShadowManager(wmInterface.name, wmInterface.version, qApp);
connect(m_waylandShadowManager, &KWayland::Client::ShadowManager::removed, this,
[this] () {
m_waylandShadowManager->deleteLater();
}
);
}
return m_waylandShadowManager;
}
KWayland::Client::Compositor *WaylandIntegration::waylandCompositor() const
{
return m_waylandCompositor;
......@@ -208,3 +233,24 @@ KWayland::Client::PlasmaShell *WaylandIntegration::waylandPlasmaShell()
}
return m_waylandPlasmaShell;
}
KWayland::Client::ShmPool *WaylandIntegration::waylandShmPool()
{
if (!m_waylandShmPool && m_registry) {
const KWayland::Client::Registry::AnnouncedInterface wmInterface = m_registry->interface(KWayland::Client::Registry::Interface::Shm);
if (wmInterface.name == 0) {
return nullptr;
}
m_waylandShmPool = m_registry->createShmPool(wmInterface.name, wmInterface.version, qApp);
connect(m_waylandShmPool, &KWayland::Client::ShmPool::removed, this,
[this] () {
m_waylandShmPool->deleteLater();
}
);
}
return m_waylandShmPool;
}
/*
* Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
* Copyright 2015 Marco Martin <mart@kde.org>
* Copyright 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -35,6 +36,8 @@ namespace KWayland
class PlasmaWindowManagement;
class PlasmaShell;
class Registry;
class ShadowManager;
class ShmPool;
class SlideManager;
}
}
......@@ -52,9 +55,11 @@ public:
KWayland::Client::BlurManager *waylandBlurManager();
KWayland::Client::ContrastManager *waylandContrastManager();
KWayland::Client::SlideManager *waylandSlideManager();
KWayland::Client::ShadowManager *waylandShadowManager();
KWayland::Client::Compositor *waylandCompositor() const;
KWayland::Client::PlasmaWindowManagement *plasmaWindowManagement();
KWayland::Client::PlasmaShell *waylandPlasmaShell();
KWayland::Client::ShmPool *waylandShmPool();
private:
QPointer<KWayland::Client::ConnectionThread> m_waylandConnection;
......@@ -63,8 +68,10 @@ private:
QPointer<KWayland::Client::BlurManager> m_waylandBlurManager;
QPointer<KWayland::Client::ContrastManager> m_waylandContrastManager;
QPointer<KWayland::Client::SlideManager> m_waylandSlideManager;
QPointer<KWayland::Client::ShadowManager> m_waylandShadowManager;
QPointer<KWayland::Client::PlasmaWindowManagement> m_wm;
QPointer<KWayland::Client::PlasmaShell> m_waylandPlasmaShell;
QPointer<KWayland::Client::ShmPool> m_waylandShmPool;
};
#endif
/*
* Copyright 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "windowshadow.h"
#include "waylandintegration.h"
#include <KWayland/Client/shm_pool.h>
#include <KWayland/Client/surface.h>
bool WindowShadowTile::create()
{
KWayland::Client::ShmPool *shmPool = WaylandIntegration::self()->waylandShmPool();
if (!shmPool) {
return false;
}
buffer = shmPool->createBuffer(image);
return true;
}
void WindowShadowTile::destroy()
{
buffer = nullptr;
}
WindowShadowTile *WindowShadowTile::get(const KWindowShadowTile *tile)
{
KWindowShadowTilePrivate *d = KWindowShadowTilePrivate::get(tile);
return static_cast<WindowShadowTile *>(d);
}
static KWayland::Client::Buffer::Ptr bufferForTile(const KWindowShadowTile::Ptr &tile)
{
if (!tile) {
return KWayland::Client::Buffer::Ptr();
}
WindowShadowTile *d = WindowShadowTile::get(tile.data());
return d->buffer;
}
bool WindowShadow::create()
{
KWayland::Client::ShadowManager *shadowManager = WaylandIntegration::self()->waylandShadowManager();
if (!shadowManager) {
return false;
}
KWayland::Client::Surface *surface = KWayland::Client::Surface::fromWindow(window);
if (!surface) {
return false;
}
shadow = shadowManager->createShadow(surface, surface);
shadow->attachLeft(bufferForTile(leftTile));
shadow->attachTopLeft(bufferForTile(topLeftTile));
shadow->attachTop(bufferForTile(topTile));
shadow->attachTopRight(bufferForTile(topRightTile));
shadow->attachRight(bufferForTile(rightTile));
shadow->attachBottomRight(bufferForTile(bottomRightTile));
shadow->attachBottom(bufferForTile(bottomTile));
shadow->attachBottomLeft(bufferForTile(bottomLeftTile));
shadow->setOffsets(padding);
shadow->commit();
// Commit wl_surface at the next available time.
window->requestUpdate();
return true;
}
void WindowShadow::destroy()
{
if (!shadow) {
return;
}
KWayland::Client::ShadowManager *shadowManager = WaylandIntegration::self()->waylandShadowManager();
if (!shadowManager) {
return;
}
KWayland::Client::Surface *surface = KWayland::Client::Surface::fromWindow(window);
if (!surface) {
return;
}
shadowManager->removeShadow(surface);
shadow = nullptr;
window->requestUpdate();
}
/*
* Copyright 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINDOWSHADOW_H
#define WINDOWSHADOW_H
#include <KWayland/Client/buffer.h>
#include <KWayland/Client/shadow.h>
#include <KWindowSystem/private/kwindowshadow_p.h>
class WindowShadowTile final : public KWindowShadowTilePrivate
{
public:
bool create() override;
void destroy() override;
static WindowShadowTile *get(const KWindowShadowTile *tile);
KWayland::Client::Buffer::Ptr buffer;
};
class WindowShadow final : public KWindowShadowPrivate
{
public:
bool create() override;
void destroy() override;
QPointer<KWayland::Client::Shadow> shadow;
};
#endif // WINDOWSHADOW_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment