mirror of
https://invent.kde.org/plasma/layer-shell-qt.git
synced 2025-07-14 19:14:23 -04:00
Compare commits
22 Commits
work/initi
...
v5.23.1
Author | SHA1 | Date | |
---|---|---|---|
134594b8f2 | |||
4d2459af03 | |||
83192c0c63 | |||
dc07e14630 | |||
4a439143ba | |||
331505a4d2 | |||
f6084b2c43 | |||
9af3c35020 | |||
525fa9b819 | |||
1021ca5ab5 | |||
204eeaf1c9 | |||
42a87ad728 | |||
7d46bd63c5 | |||
710152a7f3 | |||
8d1aeb7bf1 | |||
93f3ed2c07 | |||
efd32eed53 | |||
11a811061f | |||
549f5ad682 | |||
cd409ed50e | |||
2b1219cfdd | |||
29d0078909 |
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# SPDX-License-Identifier: CC0-1.0
|
||||||
|
# SPDX-FileCopyrightText: none
|
||||||
|
# Ignore the following files
|
||||||
|
.vscode
|
||||||
|
*~
|
||||||
|
*.[oa]
|
||||||
|
*.diff
|
||||||
|
*.kate-swp
|
||||||
|
*.kdev4
|
||||||
|
.kdev_include_paths
|
||||||
|
*.kdevelop.pcs
|
||||||
|
*.moc
|
||||||
|
*.moc.cpp
|
||||||
|
*.orig
|
||||||
|
*.user
|
||||||
|
.*.swp
|
||||||
|
.swp.*
|
||||||
|
Doxyfile
|
||||||
|
Makefile
|
||||||
|
avail
|
||||||
|
random_seed
|
||||||
|
/build*/
|
||||||
|
CMakeLists.txt.user*
|
||||||
|
.clang-format
|
||||||
|
/compile_commands.json
|
||||||
|
.clangd
|
||||||
|
.idea
|
||||||
|
/cmake-build*
|
||||||
|
.cache
|
@ -4,11 +4,14 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
project(layershellqt)
|
project(layershellqt)
|
||||||
set(PROJECT_VERSION "5.21.80")
|
set(PROJECT_VERSION "5.23.1")
|
||||||
set(PROJECT_VERSION_MAJOR 5)
|
set(PROJECT_VERSION_MAJOR 5)
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 99)
|
||||||
|
|
||||||
set(QT_MIN_VERSION "5.15.0")
|
set(QT_MIN_VERSION "5.15.0")
|
||||||
set(KF5_MIN_VERSION "5.78")
|
set(KF5_MIN_VERSION "5.86")
|
||||||
|
set(KDE_COMPILERSETTINGS_LEVEL "5.82")
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
@ -33,6 +36,9 @@ find_package(WaylandScanner)
|
|||||||
find_package(QtWaylandScanner)
|
find_package(QtWaylandScanner)
|
||||||
find_package(Wayland 1.3 COMPONENTS Client Server)
|
find_package(Wayland 1.3 COMPONENTS Client Server)
|
||||||
find_package(WaylandProtocols)
|
find_package(WaylandProtocols)
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
|
pkg_check_modules(XKBCOMMON xkbcommon REQUIRED IMPORTED_TARGET)
|
||||||
|
|
||||||
set_package_properties(Wayland PROPERTIES
|
set_package_properties(Wayland PROPERTIES
|
||||||
TYPE REQUIRED)
|
TYPE REQUIRED)
|
||||||
|
@ -16,18 +16,18 @@ ecm_qt_declare_logging_category(LAYER_SHELL_SOURCES
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_library(LayerShellQtInterface SHARED qwaylandlayersurface.cpp interfaces/window.cpp interfaces/shell.cpp qwaylandlayershellintegration.cpp qwaylandlayershell.cpp ${LAYER_SHELL_SOURCES})
|
add_library(LayerShellQtInterface SHARED qwaylandlayersurface.cpp interfaces/window.cpp interfaces/shell.cpp qwaylandlayershellintegration.cpp qwaylandlayershell.cpp ${LAYER_SHELL_SOURCES})
|
||||||
target_link_libraries(LayerShellQtInterface PRIVATE Qt::Gui Qt::WaylandClientPrivate Qt::XkbCommonSupportPrivate Wayland::Client)
|
target_link_libraries(LayerShellQtInterface PRIVATE Qt::Gui Qt::WaylandClientPrivate Qt::XkbCommonSupportPrivate Wayland::Client PkgConfig::XKBCOMMON)
|
||||||
target_include_directories(LayerShellQtInterface PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/LayerShellQt>"
|
target_include_directories(LayerShellQtInterface PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/LayerShellQt>"
|
||||||
INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR}/>"
|
INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR}/>"
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(LayerShellQtInterface PROPERTIES VERSION ${LAYERSHELLQT_VERSION_STRING}
|
set_target_properties(LayerShellQtInterface PROPERTIES VERSION ${LAYERSHELLQT_VERSION}
|
||||||
SOVERSION ${LAYERSHELLQT_SOVERSION}
|
SOVERSION ${LAYERSHELLQT_SOVERSION}
|
||||||
EXPORT_NAME Interface
|
EXPORT_NAME Interface
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(layer-shell SHARED qwaylandlayershellintegrationplugin.cpp)
|
add_library(layer-shell SHARED qwaylandlayershellintegrationplugin.cpp)
|
||||||
target_link_libraries(layer-shell LayerShellQtInterface Qt::WaylandClient Qt::WaylandClientPrivate Qt::XkbCommonSupportPrivate Wayland::Client)
|
target_link_libraries(layer-shell LayerShellQtInterface Qt::WaylandClient Qt::WaylandClientPrivate Qt::XkbCommonSupportPrivate Wayland::Client PkgConfig::XKBCOMMON)
|
||||||
|
|
||||||
ecm_generate_headers(LayerShellQt_HEADERS
|
ecm_generate_headers(LayerShellQt_HEADERS
|
||||||
HEADER_NAMES
|
HEADER_NAMES
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <qglobal.h>
|
|
||||||
#include <layershellqt_logging.h>
|
#include <layershellqt_logging.h>
|
||||||
|
#include <qglobal.h>
|
||||||
|
|
||||||
using namespace LayerShellQt;
|
using namespace LayerShellQt;
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#define LAYERSHELLQTSHELL_H
|
#define LAYERSHELLQTSHELL_H
|
||||||
|
|
||||||
#include "layershellqt_export.h"
|
#include "layershellqt_export.h"
|
||||||
|
#include "window.h"
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
namespace LayerShellQt
|
namespace LayerShellQt
|
||||||
{
|
{
|
||||||
|
@ -15,58 +15,134 @@ using namespace LayerShellQt;
|
|||||||
class LayerShellQt::WindowPrivate
|
class LayerShellQt::WindowPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WindowPrivate(QWaylandLayerSurface *surface)
|
WindowPrivate(QWindow *window)
|
||||||
: surface(surface)
|
: parentWindow(window)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QWaylandLayerSurface *const surface;
|
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;
|
||||||
|
QWaylandLayerSurface *getSurface() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
Window::~Window() = default;
|
static QMap<QWindow *, Window *> s_map;
|
||||||
|
|
||||||
void Window::setAnchor(Anchor anchor)
|
Window::~Window()
|
||||||
{
|
{
|
||||||
d->surface->setAnchor(anchor);
|
s_map.remove(d->parentWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::setAnchors(Anchors anchors)
|
||||||
|
{
|
||||||
|
d->anchors = anchors;
|
||||||
|
if (auto surface = d->getSurface()) {
|
||||||
|
surface->setAnchor(anchors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Window::Anchors Window::anchors() const
|
||||||
|
{
|
||||||
|
return d->anchors;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setExclusiveZone(int32_t zone)
|
void Window::setExclusiveZone(int32_t zone)
|
||||||
{
|
{
|
||||||
d->surface->setExclusiveZone(zone);
|
d->exclusionZone = zone;
|
||||||
|
if (auto surface = d->getSurface()) {
|
||||||
|
surface->setExclusiveZone(zone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t Window::exclusionZone() const
|
||||||
|
{
|
||||||
|
return d->exclusionZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setMargins(const QMargins &margins)
|
void Window::setMargins(const QMargins &margins)
|
||||||
{
|
{
|
||||||
d->surface->setMargins(margins);
|
d->margins = margins;
|
||||||
|
if (auto surface = d->getSurface()) {
|
||||||
|
surface->setMargins(margins);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setKeyboardInteractivity(bool enabled)
|
QMargins Window::margins() const
|
||||||
{
|
{
|
||||||
d->surface->setKeyboardInteractivity(enabled);
|
return d->margins;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::setKeyboardInteractivity(KeyboardInteractivity interactivity)
|
||||||
|
{
|
||||||
|
d->keyboardInteractivity = interactivity;
|
||||||
|
if (auto surface = d->getSurface()) {
|
||||||
|
surface->setKeyboardInteractivity(interactivity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Window::KeyboardInteractivity Window::keyboardInteractivity() const
|
||||||
|
{
|
||||||
|
return d->keyboardInteractivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setLayer(Layer layer)
|
void Window::setLayer(Layer layer)
|
||||||
{
|
{
|
||||||
d->surface->setLayer(layer);
|
d->layer = layer;
|
||||||
|
if (auto surface = d->getSurface()) {
|
||||||
|
surface->setLayer(layer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::Window(WindowPrivate *d)
|
void Window::setScope(const QString &scope)
|
||||||
: d(d)
|
|
||||||
{
|
{
|
||||||
|
d->scope = scope;
|
||||||
|
// this is static and must be set before the platform window is created
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Window::scope() const
|
||||||
|
{
|
||||||
|
return d->scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
Window::Layer Window::layer() const
|
||||||
|
{
|
||||||
|
return d->layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
Window::Window(QWindow *window)
|
||||||
|
: QObject(window)
|
||||||
|
, d(new WindowPrivate(window))
|
||||||
|
{
|
||||||
|
s_map.insert(d->parentWindow, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window *Window::get(QWindow *window)
|
Window *Window::get(QWindow *window)
|
||||||
{
|
{
|
||||||
auto ww = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle());
|
auto layerShellWindow = s_map.value(window);
|
||||||
|
if (layerShellWindow) {
|
||||||
|
return layerShellWindow;
|
||||||
|
}
|
||||||
|
return new Window(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
QWaylandLayerSurface *WindowPrivate::getSurface() const
|
||||||
|
{
|
||||||
|
if (!parentWindow) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
auto ww = dynamic_cast<QtWaylandClient::QWaylandWindow *>(parentWindow->handle());
|
||||||
if (!ww) {
|
if (!ww) {
|
||||||
qCDebug(LAYERSHELLQT) << "window not a wayland window" << window;
|
qCDebug(LAYERSHELLQT) << "window not a wayland window" << parentWindow;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
QWaylandLayerSurface *s = qobject_cast<QWaylandLayerSurface *>(ww->shellSurface());
|
QWaylandLayerSurface *s = qobject_cast<QWaylandLayerSurface *>(ww->shellSurface());
|
||||||
if (!s) {
|
if (!s) {
|
||||||
qCDebug(LAYERSHELLQT) << "window not using wlr-layer-shell" << window << ww->shellSurface();
|
qCDebug(LAYERSHELLQT) << "window not using wlr-layer-shell" << parentWindow << ww->shellSurface();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
return s;
|
||||||
return new Window(new WindowPrivate(s));
|
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ public:
|
|||||||
AnchorRight = 8, // the right edge of the anchor rectangle
|
AnchorRight = 8, // the right edge of the anchor rectangle
|
||||||
};
|
};
|
||||||
Q_ENUM(Anchor);
|
Q_ENUM(Anchor);
|
||||||
|
Q_DECLARE_FLAGS(Anchors, Anchor)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This enum type is used to specify the layer where a surface can be put in.
|
* This enum type is used to specify the layer where a surface can be put in.
|
||||||
@ -42,16 +43,49 @@ public:
|
|||||||
};
|
};
|
||||||
Q_ENUM(Layer)
|
Q_ENUM(Layer)
|
||||||
|
|
||||||
void setAnchor(Anchor anchor);
|
/**
|
||||||
void setExclusiveZone(int32_t zone);
|
* This enum type is used to specify how the layer surface handles keyboard focus.
|
||||||
void setMargins(const QMargins &margins);
|
*/
|
||||||
void setKeyboardInteractivity(bool enabled);
|
enum KeyboardInteractivity {
|
||||||
void setLayer(Layer layer);
|
KeyboardInteractivityNone = 0,
|
||||||
|
KeyboardInteractivityExclusive = 1,
|
||||||
|
KeyboardInteractivityOnDemand = 2,
|
||||||
|
};
|
||||||
|
Q_ENUM(KeyboardInteractivity)
|
||||||
|
|
||||||
|
void setAnchors(Anchors anchor);
|
||||||
|
Anchors anchors() const;
|
||||||
|
|
||||||
|
void setExclusiveZone(int32_t zone);
|
||||||
|
int32_t exclusionZone() const;
|
||||||
|
|
||||||
|
void setMargins(const QMargins &margins);
|
||||||
|
QMargins margins() const;
|
||||||
|
|
||||||
|
void setKeyboardInteractivity(KeyboardInteractivity interactivity);
|
||||||
|
KeyboardInteractivity keyboardInteractivity() const;
|
||||||
|
|
||||||
|
void setLayer(Layer layer);
|
||||||
|
Layer layer() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a string based identifier for this window.
|
||||||
|
* This may be used by a compositor to determine stacking
|
||||||
|
* order within a given layer.
|
||||||
|
*
|
||||||
|
* May also be referred to as a role
|
||||||
|
*/
|
||||||
|
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);
|
static Window *get(QWindow *window);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Window(WindowPrivate *d);
|
Window(QWindow *window);
|
||||||
QScopedPointer<WindowPrivate> d;
|
QScopedPointer<WindowPrivate> d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
namespace LayerShellQt
|
namespace LayerShellQt
|
||||||
{
|
{
|
||||||
QWaylandLayerShell::QWaylandLayerShell(QtWayland::zwlr_layer_shell_v1 *shell)
|
QWaylandLayerShell::QWaylandLayerShell(::wl_registry *registry, uint32_t id, uint32_t version)
|
||||||
: QtWayland::zwlr_layer_shell_v1(shell->object())
|
: QtWayland::zwlr_layer_shell_v1(registry, id, version)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ namespace LayerShellQt
|
|||||||
class LAYERSHELLQT_EXPORT QWaylandLayerShell : public QtWayland::zwlr_layer_shell_v1
|
class LAYERSHELLQT_EXPORT QWaylandLayerShell : public QtWayland::zwlr_layer_shell_v1
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QWaylandLayerShell(QtWayland::zwlr_layer_shell_v1 *shell);
|
QWaylandLayerShell(::wl_registry *registry, uint32_t id, uint32_t version);
|
||||||
virtual ~QWaylandLayerShell();
|
virtual ~QWaylandLayerShell();
|
||||||
|
|
||||||
QWaylandLayerSurface *createLayerSurface(QtWaylandClient::QWaylandWindow *window);
|
QWaylandLayerSurface *createLayerSurface(QtWaylandClient::QWaylandWindow *window);
|
||||||
|
@ -18,6 +18,10 @@ QWaylandLayerShellIntegration::QWaylandLayerShellIntegration()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWaylandLayerShellIntegration::~QWaylandLayerShellIntegration()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool QWaylandLayerShellIntegration::initialize(QtWaylandClient::QWaylandDisplay *display)
|
bool QWaylandLayerShellIntegration::initialize(QtWaylandClient::QWaylandDisplay *display)
|
||||||
{
|
{
|
||||||
QWaylandShellIntegration::initialize(display);
|
QWaylandShellIntegration::initialize(display);
|
||||||
@ -35,7 +39,7 @@ void QWaylandLayerShellIntegration::registryLayer(void *data, struct wl_registry
|
|||||||
QWaylandLayerShellIntegration *shell = static_cast<QWaylandLayerShellIntegration *>(data);
|
QWaylandLayerShellIntegration *shell = static_cast<QWaylandLayerShellIntegration *>(data);
|
||||||
|
|
||||||
if (interface == zwlr_layer_shell_v1_interface.name)
|
if (interface == zwlr_layer_shell_v1_interface.name)
|
||||||
shell->m_layerShell = new QWaylandLayerShell(new QtWayland::zwlr_layer_shell_v1(registry, id, std::min(version, 3u)));
|
shell->m_layerShell.reset(new QWaylandLayerShell(registry, id, std::min(version, 4u)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ class LAYERSHELLQT_EXPORT QWaylandLayerShellIntegration : public QtWaylandClient
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QWaylandLayerShellIntegration();
|
QWaylandLayerShellIntegration();
|
||||||
|
~QWaylandLayerShellIntegration() override;
|
||||||
|
|
||||||
bool initialize(QtWaylandClient::QWaylandDisplay *display) override;
|
bool initialize(QtWaylandClient::QWaylandDisplay *display) override;
|
||||||
QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override;
|
QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override;
|
||||||
@ -28,7 +29,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
static void registryLayer(void *data, struct wl_registry *registry, uint32_t id, const QString &interface, uint32_t version);
|
static void registryLayer(void *data, struct wl_registry *registry, uint32_t id, const QString &interface, uint32_t version);
|
||||||
|
|
||||||
QWaylandLayerShell *m_layerShell = nullptr;
|
QScopedPointer<QWaylandLayerShell> m_layerShell;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,10 @@
|
|||||||
* SPDX-License-Identifier: LGPL-3.0-or-later
|
* SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "interfaces/shell.h"
|
||||||
#include "qwaylandlayershell_p.h"
|
#include "qwaylandlayershell_p.h"
|
||||||
#include "qwaylandlayersurface_p.h"
|
#include "qwaylandlayersurface_p.h"
|
||||||
|
#include "layershellqt_logging.h"
|
||||||
|
|
||||||
#include <QtWaylandClient/private/qwaylandscreen_p.h>
|
#include <QtWaylandClient/private/qwaylandscreen_p.h>
|
||||||
#include <QtWaylandClient/private/qwaylandsurface_p.h>
|
#include <QtWaylandClient/private/qwaylandsurface_p.h>
|
||||||
@ -16,14 +18,37 @@ namespace LayerShellQt
|
|||||||
{
|
{
|
||||||
QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window)
|
QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window)
|
||||||
: QtWaylandClient::QWaylandShellSurface(window)
|
: QtWaylandClient::QWaylandShellSurface(window)
|
||||||
, QtWayland::zwlr_layer_surface_v1(
|
, QtWayland::zwlr_layer_surface_v1()
|
||||||
// TODO: Specify namespace
|
|
||||||
shell->get_layer_surface(window->waylandSurface()->object(),
|
|
||||||
window->waylandScreen()->output(),
|
|
||||||
QtWayland::zwlr_layer_shell_v1::layer_top,
|
|
||||||
QStringLiteral("qt")))
|
|
||||||
{
|
{
|
||||||
set_anchor(anchor_top | anchor_bottom | anchor_left | anchor_right);
|
LayerShellQt::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
|
||||||
|
QtWaylandClient::QWaylandScreen *screen = window->waylandScreen();
|
||||||
|
if (screen->isPlaceholder()) {
|
||||||
|
qCWarning(LAYERSHELLQT) << "Creating a layer shell for placeholder screen. This will be positioned incorrectly";
|
||||||
|
}
|
||||||
|
|
||||||
|
init(shell->get_layer_surface(window->waylandSurface()->object(), screen->isPlaceholder() ? nullptr : screen->output(), interface->layer(), interface->scope()));
|
||||||
|
|
||||||
|
Window::Anchors anchors = interface->anchors();
|
||||||
|
|
||||||
|
set_anchor(interface->anchors());
|
||||||
|
setMargins(interface->margins());
|
||||||
|
setKeyboardInteractivity(interface->keyboardInteractivity());
|
||||||
|
setExclusiveZone(interface->exclusionZone());
|
||||||
|
|
||||||
|
QSize size = window->surfaceSize();
|
||||||
|
if ((anchors & Window::AnchorLeft) && (anchors & Window::AnchorRight)) {
|
||||||
|
size.setWidth(0);
|
||||||
|
}
|
||||||
|
if ((anchors & Window::AnchorTop) && (anchors & Window::AnchorBottom)) {
|
||||||
|
size.setHeight(0);
|
||||||
|
}
|
||||||
|
if (size.isValid() && size != QSize(0, 0)) {
|
||||||
|
set_size(size.width(), size.height());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QWaylandLayerSurface::~QWaylandLayerSurface()
|
QWaylandLayerSurface::~QWaylandLayerSurface()
|
||||||
@ -72,9 +97,9 @@ void QWaylandLayerSurface::setMargins(const QMargins &margins)
|
|||||||
set_margin(margins.top(), margins.right(), margins.bottom(), margins.left());
|
set_margin(margins.top(), margins.right(), margins.bottom(), margins.left());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWaylandLayerSurface::setKeyboardInteractivity(bool enabled)
|
void QWaylandLayerSurface::setKeyboardInteractivity(uint32_t interactivity)
|
||||||
{
|
{
|
||||||
set_keyboard_interactivity(enabled);
|
set_keyboard_interactivity(interactivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWaylandLayerSurface::setLayer(uint32_t layer)
|
void QWaylandLayerSurface::setLayer(uint32_t layer)
|
||||||
|
@ -33,7 +33,7 @@ public:
|
|||||||
void setAnchor(uint32_t anchor);
|
void setAnchor(uint32_t anchor);
|
||||||
void setExclusiveZone(int32_t zone);
|
void setExclusiveZone(int32_t zone);
|
||||||
void setMargins(const QMargins &margins);
|
void setMargins(const QMargins &margins);
|
||||||
void setKeyboardInteractivity(bool enabled);
|
void setKeyboardInteractivity(uint32_t interactivity);
|
||||||
void setLayer(uint32_t layer);
|
void setLayer(uint32_t layer);
|
||||||
|
|
||||||
void applyConfigure() override;
|
void applyConfigure() override;
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
THIS SOFTWARE.
|
THIS SOFTWARE.
|
||||||
</copyright>
|
</copyright>
|
||||||
|
|
||||||
<interface name="zwlr_layer_shell_v1" version="3">
|
<interface name="zwlr_layer_shell_v1" version="4">
|
||||||
<description summary="create surfaces that are layers of the desktop">
|
<description summary="create surfaces that are layers of the desktop">
|
||||||
Clients can use this interface to assign the surface_layer role to
|
Clients can use this interface to assign the surface_layer role to
|
||||||
wl_surfaces. Such surfaces are assigned to a "layer" of the output and
|
wl_surfaces. Such surfaces are assigned to a "layer" of the output and
|
||||||
@ -100,7 +100,7 @@
|
|||||||
</request>
|
</request>
|
||||||
</interface>
|
</interface>
|
||||||
|
|
||||||
<interface name="zwlr_layer_surface_v1" version="3">
|
<interface name="zwlr_layer_surface_v1" version="4">
|
||||||
<description summary="layer metadata interface">
|
<description summary="layer metadata interface">
|
||||||
An interface that may be implemented by a wl_surface, for surfaces that
|
An interface that may be implemented by a wl_surface, for surfaces that
|
||||||
are designed to be rendered as a layer of a stacked desktop-like
|
are designed to be rendered as a layer of a stacked desktop-like
|
||||||
@ -203,21 +203,85 @@
|
|||||||
<arg name="left" type="int"/>
|
<arg name="left" type="int"/>
|
||||||
</request>
|
</request>
|
||||||
|
|
||||||
|
<enum name="keyboard_interactivity">
|
||||||
|
<description summary="types of keyboard interaction possible for a layer shell surface">
|
||||||
|
Types of keyboard interaction possible for layer shell surfaces. The
|
||||||
|
rationale for this is twofold: (1) some applications are not interested
|
||||||
|
in keyboard events and not allowing them to be focused can improve the
|
||||||
|
desktop experience; (2) some applications will want to take exclusive
|
||||||
|
keyboard focus.
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<entry name="none" value="0">
|
||||||
|
<description summary="no keyboard focus is possible">
|
||||||
|
This value indicates that this surface is not interested in keyboard
|
||||||
|
events and the compositor should never assign it the keyboard focus.
|
||||||
|
|
||||||
|
This is the default value, set for newly created layer shell surfaces.
|
||||||
|
|
||||||
|
This is useful for e.g. desktop widgets that display information or
|
||||||
|
only have interaction with non-keyboard input devices.
|
||||||
|
</description>
|
||||||
|
</entry>
|
||||||
|
<entry name="exclusive" value="1">
|
||||||
|
<description summary="request exclusive keyboard focus">
|
||||||
|
Request exclusive keyboard focus if this surface is above the shell surface layer.
|
||||||
|
|
||||||
|
For the top and overlay layers, the seat will always give
|
||||||
|
exclusive keyboard focus to the top-most layer which has keyboard
|
||||||
|
interactivity set to exclusive. If this layer contains multiple
|
||||||
|
surfaces with keyboard interactivity set to exclusive, the compositor
|
||||||
|
determines the one receiving keyboard events in an implementation-
|
||||||
|
defined manner. In this case, no guarantee is made when this surface
|
||||||
|
will receive keyboard focus (if ever).
|
||||||
|
|
||||||
|
For the bottom and background layers, the compositor is allowed to use
|
||||||
|
normal focus semantics.
|
||||||
|
|
||||||
|
This setting is mainly intended for applications that need to ensure
|
||||||
|
they receive all keyboard events, such as a lock screen or a password
|
||||||
|
prompt.
|
||||||
|
</description>
|
||||||
|
</entry>
|
||||||
|
<entry name="on_demand" value="2" since="4">
|
||||||
|
<description summary="request regular keyboard focus semantics">
|
||||||
|
This requests the compositor to allow this surface to be focused and
|
||||||
|
unfocused by the user in an implementation-defined manner. The user
|
||||||
|
should be able to unfocus this surface even regardless of the layer
|
||||||
|
it is on.
|
||||||
|
|
||||||
|
Typically, the compositor will want to use its normal mechanism to
|
||||||
|
manage keyboard focus between layer shell surfaces with this setting
|
||||||
|
and regular toplevels on the desktop layer (e.g. click to focus).
|
||||||
|
Nevertheless, it is possible for a compositor to require a special
|
||||||
|
interaction to focus or unfocus layer shell surfaces (e.g. requiring
|
||||||
|
a click even if focus follows the mouse normally, or providing a
|
||||||
|
keybinding to switch focus between layers).
|
||||||
|
|
||||||
|
This setting is mainly intended for desktop shell components (e.g.
|
||||||
|
panels) that allow keyboard interaction. Using this option can allow
|
||||||
|
implementing a desktop shell that can be fully usable without the
|
||||||
|
mouse.
|
||||||
|
</description>
|
||||||
|
</entry>
|
||||||
|
</enum>
|
||||||
|
|
||||||
<request name="set_keyboard_interactivity">
|
<request name="set_keyboard_interactivity">
|
||||||
<description summary="requests keyboard events">
|
<description summary="requests keyboard events">
|
||||||
Set to 1 to request that the seat send keyboard events to this layer
|
Set how keyboard events are delivered to this surface. By default,
|
||||||
surface. For layers below the shell surface layer, the seat will use
|
layer shell surfaces do not receive keyboard events; this request can
|
||||||
normal focus semantics. For layers above the shell surface layers, the
|
be used to change this.
|
||||||
seat will always give exclusive keyboard focus to the top-most layer
|
|
||||||
which has keyboard interactivity set to true.
|
This setting is inherited by child surfaces set by the get_popup
|
||||||
|
request.
|
||||||
|
|
||||||
Layer surfaces receive pointer, touch, and tablet events normally. If
|
Layer surfaces receive pointer, touch, and tablet events normally. If
|
||||||
you do not want to receive them, set the input region on your surface
|
you do not want to receive them, set the input region on your surface
|
||||||
to an empty region.
|
to an empty region.
|
||||||
|
|
||||||
Events is double-buffered, see wl_surface.commit.
|
Keyboard interactivity is double-buffered, see wl_surface.commit.
|
||||||
</description>
|
</description>
|
||||||
<arg name="keyboard_interactivity" type="uint"/>
|
<arg name="keyboard_interactivity" type="uint" enum="keyboard_interactivity"/>
|
||||||
</request>
|
</request>
|
||||||
|
|
||||||
<request name="get_popup">
|
<request name="get_popup">
|
||||||
@ -302,6 +366,7 @@
|
|||||||
<entry name="invalid_surface_state" value="0" summary="provided surface state is invalid"/>
|
<entry name="invalid_surface_state" value="0" summary="provided surface state is invalid"/>
|
||||||
<entry name="invalid_size" value="1" summary="size is invalid"/>
|
<entry name="invalid_size" value="1" summary="size is invalid"/>
|
||||||
<entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/>
|
<entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/>
|
||||||
|
<entry name="invalid_keyboard_interactivity" value="3" summary="keyboard interactivity is invalid"/>
|
||||||
</enum>
|
</enum>
|
||||||
|
|
||||||
<enum name="anchor" bitfield="true">
|
<enum name="anchor" bitfield="true">
|
||||||
|
108
tests/main.cpp
108
tests/main.cpp
@ -4,35 +4,105 @@
|
|||||||
* SPDX-License-Identifier: LGPL-3.0-or-later
|
* SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QPainter>
|
||||||
|
#include <QRasterWindow>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QWindow>
|
||||||
|
|
||||||
|
#include <QMetaEnum>
|
||||||
|
|
||||||
#include <interfaces/shell.h>
|
#include <interfaces/shell.h>
|
||||||
#include <interfaces/window.h>
|
#include <interfaces/window.h>
|
||||||
|
|
||||||
|
using namespace LayerShellQt;
|
||||||
|
|
||||||
|
QStringList enumsToStringList(QMetaEnum metaEnum)
|
||||||
|
{
|
||||||
|
QStringList ret;
|
||||||
|
ret.reserve(metaEnum.keyCount());
|
||||||
|
for (int i = 0; i < metaEnum.keyCount(); ++i) {
|
||||||
|
ret.append(metaEnum.key(i));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T stringToEnum(QMetaEnum metaEnum, const QString &str)
|
||||||
|
{
|
||||||
|
T ret = {};
|
||||||
|
const auto splitted = str.split(QLatin1Char('|'));
|
||||||
|
for (const auto &value : splitted) {
|
||||||
|
ret |= T(metaEnum.keyToValue(qPrintable(value)));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
class BasicWindow : public QRasterWindow
|
||||||
|
{
|
||||||
|
void paintEvent(QPaintEvent *)
|
||||||
|
{
|
||||||
|
QPainter p(this);
|
||||||
|
p.fillRect(QRect(0, 0, width(), height()), Qt::red);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
LayerShellQt::Shell::useLayerShell();
|
Shell::useLayerShell();
|
||||||
|
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
QQmlApplicationEngine engine;
|
|
||||||
engine.loadData(
|
|
||||||
"import QtQuick.Controls 2.10\n"
|
|
||||||
"import QtQuick 2.10\n"
|
|
||||||
"\n"
|
|
||||||
"ApplicationWindow {"
|
|
||||||
" width: 100; height: 100\n"
|
|
||||||
" visible: true\n"
|
|
||||||
" Rectangle { color: 'red'; anchors.fill: parent }"
|
|
||||||
"}"
|
|
||||||
|
|
||||||
,
|
const auto layerMetaEnum = QMetaEnum::fromType<Window::Layer>();
|
||||||
QStringLiteral("bananaland:/potato.qml"));
|
const auto anchorMetaEnum = QMetaEnum::fromType<Window::Anchor>();
|
||||||
|
|
||||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [](QObject *object) {
|
QCommandLineParser parser;
|
||||||
auto layerWindow = LayerShellQt::Window::get(qobject_cast<QWindow *>(object));
|
QCommandLineOption marginsOption(QStringLiteral("margins"), QStringLiteral("Window margins"), QStringLiteral("pixels"), QStringLiteral("0"));
|
||||||
Q_ASSERT(layerWindow);
|
QCommandLineOption scopeOption(QStringLiteral("scope"), QStringLiteral("Window scope"), QStringLiteral("namespace"), QStringLiteral("normal"));
|
||||||
layerWindow->setMargins({50, 50, 50, 50});
|
QCommandLineOption anchorsOption(QStringLiteral("anchors"),
|
||||||
});
|
QStringLiteral("Either ") + enumsToStringList(anchorMetaEnum).join(QLatin1String("|")),
|
||||||
|
QStringLiteral("anchors"),
|
||||||
|
QStringLiteral("AnchorTop|AnchorBottom|AnchorLeft|AnchorRight"));
|
||||||
|
QCommandLineOption layerOption(QStringLiteral("layer"),
|
||||||
|
QStringLiteral("One of ") + enumsToStringList(layerMetaEnum).join(QLatin1String("|")),
|
||||||
|
QStringLiteral("layer"),
|
||||||
|
QStringLiteral("LayerTop"));
|
||||||
|
QCommandLineOption widthOption(QStringLiteral("width"), QStringLiteral("Width of the window"), QStringLiteral("pixels"), QStringLiteral("0"));
|
||||||
|
QCommandLineOption heightOption(QStringLiteral("height"), QStringLiteral("Height of the window"), QStringLiteral("pixels"), QStringLiteral("0"));
|
||||||
|
|
||||||
|
parser.addOptions({marginsOption, scopeOption, anchorsOption, layerOption, widthOption, heightOption});
|
||||||
|
parser.addHelpOption();
|
||||||
|
parser.process(app);
|
||||||
|
|
||||||
|
BasicWindow window;
|
||||||
|
|
||||||
|
LayerShellQt::Window *layerShell = LayerShellQt::Window::get(&window);
|
||||||
|
if (parser.isSet(marginsOption)) {
|
||||||
|
int margins = parser.value(marginsOption).toInt();
|
||||||
|
layerShell->setMargins({margins, margins, margins, margins});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser.isSet(scopeOption)) {
|
||||||
|
layerShell->setScope(parser.value(scopeOption));
|
||||||
|
}
|
||||||
|
if (parser.isSet(layerOption)) {
|
||||||
|
layerShell->setLayer(Window::Layer(layerMetaEnum.keyToValue(qPrintable(parser.value(layerOption)))));
|
||||||
|
}
|
||||||
|
if (parser.isSet(anchorsOption)) {
|
||||||
|
layerShell->setAnchors(stringToEnum<Window::Anchors>(anchorMetaEnum, parser.value(anchorsOption)));
|
||||||
|
}
|
||||||
|
if (parser.isSet(widthOption)) {
|
||||||
|
window.setWidth(parser.value(widthOption).toInt());
|
||||||
|
}
|
||||||
|
if (parser.isSet(heightOption)) {
|
||||||
|
window.setHeight(parser.value(heightOption).toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
window.show();
|
||||||
|
|
||||||
|
// just so you don't block yourself out whilst testing
|
||||||
|
QTimer::singleShot(5000, &app, &QGuiApplication::quit);
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user