Compare commits

..

1 Commits

Author SHA1 Message Date
aa96aeb7e5 per window API 2021-11-26 13:53:38 +00:00
10 changed files with 34 additions and 121 deletions

View File

@ -15,7 +15,7 @@ ecm_qt_declare_logging_category(LAYER_SHELL_SOURCES
layershellqt
)
add_library(LayerShellQtInterface SHARED qwaylandlayersurface.cpp interfaces/window.cpp qwaylandlayershellintegration.cpp qwaylandlayershell.cpp ${LAYER_SHELL_SOURCES})
add_library(LayerShellQtInterface SHARED qwaylandlayersurface.cpp interfaces/window.cpp qwaylandlayershell.cpp ${LAYER_SHELL_SOURCES})
target_link_libraries(LayerShellQtInterface PRIVATE Qt::Gui Qt::WaylandClientPrivate Wayland::Client)
target_include_directories(LayerShellQtInterface PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/LayerShellQt>"
INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR}/>"
@ -33,6 +33,7 @@ ecm_generate_headers(LayerShellQt_HEADERS
REQUIRED_HEADERS LayerShellQt_HEADERS
)
generate_export_header(LayerShellQtInterface
BASE_NAME LayerShellQtInterface
EXPORT_MACRO_NAME LAYERSHELLQT_EXPORT

View File

@ -5,43 +5,45 @@
*/
#include "window.h"
#include "../qwaylandlayershell_p.h"
#include "../qwaylandlayersurface_p.h"
#include "../qwaylandlayershellintegration_p.h"
#include <layershellqt_logging.h>
#include <private/qwaylandwindowshellintegration_p.h>
#include <private/qwaylandshellsurface_p.h>
#include <private/qwaylandwindow_p.h>
using namespace LayerShellQt;
static const char *s_interfaceKey = "__kde_layer_window";
class LayerShellQt::WindowPrivate
class LayerShellQt::WindowPrivate : public QtWaylandClient::QWaylandWindowShellIntegration
{
public:
WindowPrivate(QWindow *window)
: parentWindow(window)
WindowPrivate(Window *_q, QWindow *window)
: QtWaylandClient::QWaylandWindowShellIntegration(window)
, q(_q)
{
}
QWindow *parentWindow;
Window *q;
QString scope = QStringLiteral("window");
Window::Anchors anchors = {Window::AnchorTop | Window::AnchorBottom | Window::AnchorLeft | Window::AnchorRight};
int32_t exclusionZone = 0;
Window::KeyboardInteractivity keyboardInteractivity = Window::KeyboardInteractivityExclusive;
Window::Layer layer = Window::LayerTop;
QMargins margins;
QWaylandLayerSurface *getSurface() const;
QPointer<QWaylandLayerSurface> surface;
QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override;
};
Window::~Window()
{
d->parentWindow->setProperty(s_interfaceKey, QVariant());
}
void Window::setAnchors(Anchors anchors)
{
d->anchors = anchors;
if (auto surface = d->getSurface()) {
if (auto surface = d->surface) {
surface->setAnchor(anchors);
}
}
@ -54,7 +56,7 @@ Window::Anchors Window::anchors() const
void Window::setExclusiveZone(int32_t zone)
{
d->exclusionZone = zone;
if (auto surface = d->getSurface()) {
if (auto surface = d->surface) {
surface->setExclusiveZone(zone);
}
}
@ -67,7 +69,7 @@ int32_t Window::exclusionZone() const
void Window::setMargins(const QMargins &margins)
{
d->margins = margins;
if (auto surface = d->getSurface()) {
if (auto surface = d->surface) {
surface->setMargins(margins);
}
}
@ -80,7 +82,7 @@ QMargins Window::margins() const
void Window::setKeyboardInteractivity(KeyboardInteractivity interactivity)
{
d->keyboardInteractivity = interactivity;
if (auto surface = d->getSurface()) {
if (auto surface = d->surface) {
surface->setKeyboardInteractivity(interactivity);
}
}
@ -93,7 +95,7 @@ Window::KeyboardInteractivity Window::keyboardInteractivity() const
void Window::setLayer(Layer layer)
{
d->layer = layer;
if (auto surface = d->getSurface()) {
if (auto surface = d->surface) {
surface->setLayer(layer);
}
}
@ -114,44 +116,18 @@ Window::Layer Window::layer() const
return d->layer;
}
static QWaylandLayerShellIntegration *s_integration = nullptr;
Window::Window(QWindow *window)
: QObject(window)
, d(new WindowPrivate(window))
, d(new WindowPrivate(this, window))
{
Q_ASSERT(!Window::get(window));
window->winId(); // create platform window
QtWaylandClient::QWaylandWindow *waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle());
if (waylandWindow) {
if (!s_integration) {
s_integration = new QWaylandLayerShellIntegration();
}
waylandWindow->setShellIntegration(s_integration);
window->setProperty(s_interfaceKey, QVariant::fromValue<QObject *>(this));
}
}
Window *Window::get(QWindow *window)
{
return qobject_cast<Window *>(qvariant_cast<QObject *>(window->property(s_interfaceKey)));
}
static LayerShellQt::QWaylandLayerShell *s_shell = nullptr;
QWaylandLayerSurface *WindowPrivate::getSurface() const
QtWaylandClient::QWaylandShellSurface *WindowPrivate::createShellSurface(QtWaylandClient::QWaylandWindow *window)
{
if (!parentWindow) {
return nullptr;
if (!s_shell) {
s_shell = new LayerShellQt::QWaylandLayerShell;
}
auto ww = dynamic_cast<QtWaylandClient::QWaylandWindow *>(parentWindow->handle());
if (!ww) {
qCDebug(LAYERSHELLQT) << "window not a wayland window" << parentWindow;
return nullptr;
}
QWaylandLayerSurface *s = qobject_cast<QWaylandLayerSurface *>(ww->shellSurface());
if (!s) {
qCDebug(LAYERSHELLQT) << "window not using wlr-layer-shell" << parentWindow << ww->shellSurface();
return nullptr;
}
return s;
return new QWaylandLayerSurface(s_shell, window, q);
}

View File

@ -21,7 +21,6 @@ class LAYERSHELLQT_EXPORT Window : public QObject
{
Q_OBJECT
public:
explicit Window(QWindow *window);
~Window() override;
enum Anchor {
@ -79,12 +78,7 @@ public:
void setScope(const QString &scope);
QString scope() const;
/**
* Gets the LayerShell Window for a given Qt Window
* Ownership is not transferred
*/
static Window *get(QWindow *window);
Window(QWindow *window);
private:
QScopedPointer<WindowPrivate> d;
};

3
src/layer-shell.json Normal file
View File

@ -0,0 +1,3 @@
{
"Keys": [ "layer-shell" ]
}

View File

@ -0,0 +1,2 @@
SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
SPDX-License-Identifier: CC0-1.0

View File

@ -23,6 +23,7 @@ class QWaylandLayerShell : public QWaylandClientExtensionTemplate<QWaylandLayerS
public:
QWaylandLayerShell();
~QWaylandLayerShell() override;
};
}

View File

@ -1,31 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
* SPDX-FileCopyrightText: 2018 Drew DeVault <sir@cmpwn.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "qwaylandlayershell_p.h"
#include "qwaylandlayershellintegration_p.h"
#include <QtWaylandClient/private/qwaylanddisplay_p.h>
#include <QtWaylandClient/private/qwaylandwindow_p.h>
#include <qwayland-wlr-layer-shell-unstable-v1.h>
namespace LayerShellQt
{
QWaylandLayerShellIntegration::QWaylandLayerShellIntegration()
: m_layerShell(new QWaylandLayerShell())
{
}
QWaylandLayerShellIntegration::~QWaylandLayerShellIntegration()
{
}
QtWaylandClient::QWaylandShellSurface *QWaylandLayerShellIntegration::createShellSurface(QtWaylandClient::QWaylandWindow *window)
{
return new QWaylandLayerSurface(m_layerShell.data(), window);
}
}

View File

@ -1,32 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
* SPDX-FileCopyrightText: 2018 Drew DeVault <sir@cmpwn.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef _LAYERSHELLINTEGRATION_P_H
#define _LAYERSHELLINTEGRATION_P_H
#include "layershellqt_export.h"
#include <QtWaylandClient/private/qwaylandshellintegration_p.h>
namespace LayerShellQt
{
class QWaylandLayerShell;
class LAYERSHELLQT_EXPORT QWaylandLayerShellIntegration : public QtWaylandClient::QWaylandShellIntegration
{
public:
QWaylandLayerShellIntegration();
~QWaylandLayerShellIntegration() override;
QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override;
private:
QScopedPointer<QWaylandLayerShell> m_layerShell;
};
}
#endif

View File

@ -5,9 +5,9 @@
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "interfaces/window.h"
#include "qwaylandlayershell_p.h"
#include "qwaylandlayersurface_p.h"
#include "interfaces/window.h"
#include "layershellqt_logging.h"
#include <QtWaylandClient/private/qwaylandscreen_p.h>
@ -16,12 +16,10 @@
namespace LayerShellQt
{
QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window)
QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window, LayerShellQt::Window *interface )
: QtWaylandClient::QWaylandShellSurface(window)
, QtWayland::zwlr_layer_surface_v1()
{
Window *interface = Window::get(window->window());
Q_ASSERT(interface);
// Qt will always assign a screen to a window, but if the compositor has no screens available a dummy QScreen object is created
// this will not cast to a QWaylandScreen

View File

@ -17,12 +17,13 @@
namespace LayerShellQt
{
class QWaylandLayerShell;
class Window;
class LAYERSHELLQT_EXPORT QWaylandLayerSurface : public QtWaylandClient::QWaylandShellSurface, public QtWayland::zwlr_layer_surface_v1
{
Q_OBJECT
public:
QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window);
QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window, LayerShellQt::Window *interface);
~QWaylandLayerSurface() override;
bool isExposed() const override