Compare commits

..

1 Commits

Author SHA1 Message Date
2502a4a6dd hacks 2021-11-26 21:26:19 +02:00
10 changed files with 124 additions and 37 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 qwaylandlayershell.cpp ${LAYER_SHELL_SOURCES})
add_library(LayerShellQtInterface SHARED qwaylandlayersurface.cpp interfaces/window.cpp qwaylandlayershellintegration.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,7 +33,6 @@ ecm_generate_headers(LayerShellQt_HEADERS
REQUIRED_HEADERS LayerShellQt_HEADERS
)
generate_export_header(LayerShellQtInterface
BASE_NAME LayerShellQtInterface
EXPORT_MACRO_NAME LAYERSHELLQT_EXPORT

View File

@ -5,45 +5,43 @@
*/
#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 : public QtWaylandClient::QWaylandWindowShellIntegration
class LayerShellQt::WindowPrivate
{
public:
WindowPrivate(Window *_q, QWindow *window)
: QtWaylandClient::QWaylandWindowShellIntegration(window)
, q(_q)
WindowPrivate(QWindow *window)
: parentWindow(window)
{
}
Window *q;
QWindow *parentWindow;
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;
QPointer<QWaylandLayerSurface> surface;
QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override;
QWaylandLayerSurface *getSurface() const;
};
Window::~Window()
{
d->parentWindow->setProperty(s_interfaceKey, QVariant());
}
void Window::setAnchors(Anchors anchors)
{
d->anchors = anchors;
if (auto surface = d->surface) {
if (auto surface = d->getSurface()) {
surface->setAnchor(anchors);
}
}
@ -56,7 +54,7 @@ Window::Anchors Window::anchors() const
void Window::setExclusiveZone(int32_t zone)
{
d->exclusionZone = zone;
if (auto surface = d->surface) {
if (auto surface = d->getSurface()) {
surface->setExclusiveZone(zone);
}
}
@ -69,7 +67,7 @@ int32_t Window::exclusionZone() const
void Window::setMargins(const QMargins &margins)
{
d->margins = margins;
if (auto surface = d->surface) {
if (auto surface = d->getSurface()) {
surface->setMargins(margins);
}
}
@ -82,7 +80,7 @@ QMargins Window::margins() const
void Window::setKeyboardInteractivity(KeyboardInteractivity interactivity)
{
d->keyboardInteractivity = interactivity;
if (auto surface = d->surface) {
if (auto surface = d->getSurface()) {
surface->setKeyboardInteractivity(interactivity);
}
}
@ -95,7 +93,7 @@ Window::KeyboardInteractivity Window::keyboardInteractivity() const
void Window::setLayer(Layer layer)
{
d->layer = layer;
if (auto surface = d->surface) {
if (auto surface = d->getSurface()) {
surface->setLayer(layer);
}
}
@ -116,18 +114,44 @@ Window::Layer Window::layer() const
return d->layer;
}
static QWaylandLayerShellIntegration *s_integration = nullptr;
Window::Window(QWindow *window)
: QObject(window)
, d(new WindowPrivate(this, window))
, d(new WindowPrivate(window))
{
}
Q_ASSERT(!Window::get(window));
window->winId(); // create platform window
static LayerShellQt::QWaylandLayerShell *s_shell = nullptr;
QtWaylandClient::QWaylandShellSurface *WindowPrivate::createShellSurface(QtWaylandClient::QWaylandWindow *window)
{
if (!s_shell) {
s_shell = new LayerShellQt::QWaylandLayerShell;
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));
}
return new QWaylandLayerSurface(s_shell, window, q);
}
Window *Window::get(QWindow *window)
{
return qobject_cast<Window *>(qvariant_cast<QObject *>(window->property(s_interfaceKey)));
}
QWaylandLayerSurface *WindowPrivate::getSurface() const
{
if (!parentWindow) {
return nullptr;
}
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;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,31 @@
/*
* 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

@ -0,0 +1,32 @@
/*
* 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,10 +16,12 @@
namespace LayerShellQt
{
QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window, LayerShellQt::Window *interface )
QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window)
: 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,13 +17,12 @@
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, LayerShellQt::Window *interface);
QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window);
~QWaylandLayerSurface() override;
bool isExposed() const override