mirror of
https://invent.kde.org/plasma/layer-shell-qt.git
synced 2025-07-14 11:04:20 -04:00
Compare commits
28 Commits
work/initi
...
work/zzag/
Author | SHA1 | Date | |
---|---|---|---|
826c3e3ce0 | |||
3214fb588f | |||
8c39cad0ba | |||
80f6a629bb | |||
662afeba22 | |||
3dac2dd012 | |||
5b280a4602 | |||
eb6fb8ab13 | |||
06815f2817 | |||
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
|
6
.gitlab-ci.yml
Normal file
6
.gitlab-ci.yml
Normal file
@ -0,0 +1,6 @@
|
||||
# SPDX-FileCopyrightText: None
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
include:
|
||||
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/linux.yml
|
||||
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/freebsd.yml
|
7
.kde-ci.yml
Normal file
7
.kde-ci.yml
Normal file
@ -0,0 +1,7 @@
|
||||
# SPDX-FileCopyrightText: None
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
Dependencies:
|
||||
- 'on': ['@all']
|
||||
'require':
|
||||
'frameworks/extra-cmake-modules': '@latest'
|
@ -4,17 +4,19 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(layershellqt)
|
||||
set(PROJECT_VERSION "5.21.80")
|
||||
set(PROJECT_VERSION_MAJOR 5)
|
||||
set(PROJECT_VERSION "6.0.0")
|
||||
set(PROJECT_VERSION_MAJOR 6)
|
||||
|
||||
set(QT_MIN_VERSION "5.15.0")
|
||||
set(KF5_MIN_VERSION "5.78")
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
|
||||
set(QT_MIN_VERSION "6.2.0")
|
||||
set(KF5_MIN_VERSION "5.86")
|
||||
set(KDE_COMPILERSETTINGS_LEVEL "5.82")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS WaylandClient Qml)
|
||||
find_package(Qt5XkbCommonSupport REQUIRED PRIVATE)
|
||||
find_package(Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS WaylandClient Qml)
|
||||
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${ECM_MODULE_PATH})
|
||||
|
||||
@ -33,6 +35,7 @@ find_package(WaylandScanner)
|
||||
find_package(QtWaylandScanner)
|
||||
find_package(Wayland 1.3 COMPONENTS Client Server)
|
||||
find_package(WaylandProtocols)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
set_package_properties(Wayland PROPERTIES
|
||||
TYPE REQUIRED)
|
||||
|
@ -4,6 +4,6 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
find_dependency(Qt5Gui "@QT_MIN_VERSION@")
|
||||
find_dependency(Qt6Gui "@QT_MIN_VERSION@")
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/LayerShellQtTargets.cmake")
|
||||
|
@ -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})
|
||||
target_link_libraries(LayerShellQtInterface PRIVATE Qt::Gui Qt::WaylandClientPrivate Qt::XkbCommonSupportPrivate Wayland::Client)
|
||||
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}/>"
|
||||
)
|
||||
|
||||
set_target_properties(LayerShellQtInterface PROPERTIES VERSION ${LAYERSHELLQT_VERSION_STRING}
|
||||
set_target_properties(LayerShellQtInterface PROPERTIES VERSION ${LAYERSHELLQT_VERSION}
|
||||
SOVERSION ${LAYERSHELLQT_SOVERSION}
|
||||
EXPORT_NAME Interface
|
||||
)
|
||||
|
||||
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 Wayland::Client)
|
||||
|
||||
ecm_generate_headers(LayerShellQt_HEADERS
|
||||
HEADER_NAMES
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
#include "shell.h"
|
||||
#include <QByteArray>
|
||||
#include <qglobal.h>
|
||||
#include <layershellqt_logging.h>
|
||||
#include <qglobal.h>
|
||||
|
||||
using namespace LayerShellQt;
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
#define LAYERSHELLQTSHELL_H
|
||||
|
||||
#include "layershellqt_export.h"
|
||||
#include "window.h"
|
||||
#include <QString>
|
||||
|
||||
namespace LayerShellQt
|
||||
{
|
||||
|
@ -15,58 +15,134 @@ using namespace LayerShellQt;
|
||||
class LayerShellQt::WindowPrivate
|
||||
{
|
||||
public:
|
||||
WindowPrivate(QWaylandLayerSurface *surface)
|
||||
: surface(surface)
|
||||
WindowPrivate(QWindow *window)
|
||||
: 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
d->surface->setLayer(layer);
|
||||
d->layer = layer;
|
||||
if (auto surface = d->getSurface()) {
|
||||
surface->setLayer(layer);
|
||||
}
|
||||
}
|
||||
|
||||
Window::Window(WindowPrivate *d)
|
||||
: d(d)
|
||||
void Window::setScope(const QString &scope)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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) {
|
||||
qCDebug(LAYERSHELLQT) << "window not a wayland window" << window;
|
||||
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" << window << ww->shellSurface();
|
||||
qCDebug(LAYERSHELLQT) << "window not using wlr-layer-shell" << parentWindow << ww->shellSurface();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new Window(new WindowPrivate(s));
|
||||
return s;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ public:
|
||||
AnchorRight = 8, // the right edge of the anchor rectangle
|
||||
};
|
||||
Q_ENUM(Anchor);
|
||||
Q_DECLARE_FLAGS(Anchors, Anchor)
|
||||
|
||||
/**
|
||||
* This enum type is used to specify the layer where a surface can be put in.
|
||||
@ -42,16 +43,49 @@ public:
|
||||
};
|
||||
Q_ENUM(Layer)
|
||||
|
||||
void setAnchor(Anchor anchor);
|
||||
void setExclusiveZone(int32_t zone);
|
||||
void setMargins(const QMargins &margins);
|
||||
void setKeyboardInteractivity(bool enabled);
|
||||
void setLayer(Layer layer);
|
||||
/**
|
||||
* This enum type is used to specify how the layer surface handles keyboard focus.
|
||||
*/
|
||||
enum KeyboardInteractivity {
|
||||
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);
|
||||
|
||||
private:
|
||||
Window(WindowPrivate *d);
|
||||
Window(QWindow *window);
|
||||
QScopedPointer<WindowPrivate> d;
|
||||
};
|
||||
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
namespace LayerShellQt
|
||||
{
|
||||
QWaylandLayerShell::QWaylandLayerShell(QtWayland::zwlr_layer_shell_v1 *shell)
|
||||
: QtWayland::zwlr_layer_shell_v1(shell->object())
|
||||
QWaylandLayerShell::QWaylandLayerShell(::wl_registry *registry, uint32_t id, uint32_t version)
|
||||
: QtWayland::zwlr_layer_shell_v1(registry, id, version)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,8 @@ namespace LayerShellQt
|
||||
class LAYERSHELLQT_EXPORT QWaylandLayerShell : public QtWayland::zwlr_layer_shell_v1
|
||||
{
|
||||
public:
|
||||
QWaylandLayerShell(QtWayland::zwlr_layer_shell_v1 *shell);
|
||||
virtual ~QWaylandLayerShell();
|
||||
QWaylandLayerShell(::wl_registry *registry, uint32_t id, uint32_t version);
|
||||
~QWaylandLayerShell() override;
|
||||
|
||||
QWaylandLayerSurface *createLayerSurface(QtWaylandClient::QWaylandWindow *window);
|
||||
// TODO: Popups
|
||||
|
@ -18,26 +18,34 @@ QWaylandLayerShellIntegration::QWaylandLayerShellIntegration()
|
||||
{
|
||||
}
|
||||
|
||||
bool QWaylandLayerShellIntegration::initialize(QtWaylandClient::QWaylandDisplay *display)
|
||||
QWaylandLayerShellIntegration::~QWaylandLayerShellIntegration()
|
||||
{
|
||||
QWaylandShellIntegration::initialize(display);
|
||||
display->addRegistryListener(registryLayer, this);
|
||||
return m_layerShell != nullptr;
|
||||
}
|
||||
|
||||
bool QWaylandLayerShellIntegration::initialize()
|
||||
{
|
||||
if (m_layerShell) {
|
||||
return true;
|
||||
}
|
||||
wl_registry *registry;
|
||||
uint32_t id;
|
||||
uint32_t version;
|
||||
const bool found = findGlobal(QLatin1String("zwlr_layer_shell_v1"), ®istry, &id, &version);
|
||||
if (!found) {
|
||||
qWarning() << "Could not find the zwlr_layer_shell_v1 global. Compositor does not support the layer shell protocol?";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_layerShell.reset(new QWaylandLayerShell(registry, id, std::min(version, 4u)));
|
||||
return true;
|
||||
}
|
||||
|
||||
QtWaylandClient::QWaylandShellSurface *QWaylandLayerShellIntegration::createShellSurface(QtWaylandClient::QWaylandWindow *window)
|
||||
{
|
||||
return m_layerShell->createLayerSurface(window);
|
||||
}
|
||||
|
||||
void QWaylandLayerShellIntegration::registryLayer(void *data, struct wl_registry *registry, uint32_t id, const QString &interface, uint32_t version)
|
||||
{
|
||||
QWaylandLayerShellIntegration *shell = static_cast<QWaylandLayerShellIntegration *>(data);
|
||||
|
||||
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)));
|
||||
if (m_layerShell) {
|
||||
return m_layerShell->createLayerSurface(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//#include "qwaylandlayershellintegration.moc"
|
||||
|
@ -8,10 +8,9 @@
|
||||
#ifndef _LAYERSHELLINTEGRATION_P_H
|
||||
#define _LAYERSHELLINTEGRATION_P_H
|
||||
|
||||
#include <wayland-client.h>
|
||||
|
||||
#include "layershellqt_export.h"
|
||||
#include <QtWaylandClient/private/qwaylandshellintegration_p.h>
|
||||
|
||||
#include <QtWaylandClient/private/qwaylandclientshellapi_p.h>
|
||||
|
||||
namespace LayerShellQt
|
||||
{
|
||||
@ -21,14 +20,13 @@ class LAYERSHELLQT_EXPORT QWaylandLayerShellIntegration : public QtWaylandClient
|
||||
{
|
||||
public:
|
||||
QWaylandLayerShellIntegration();
|
||||
~QWaylandLayerShellIntegration() override;
|
||||
|
||||
bool initialize(QtWaylandClient::QWaylandDisplay *display) override;
|
||||
bool initialize() override;
|
||||
QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override;
|
||||
|
||||
private:
|
||||
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
|
||||
*/
|
||||
|
||||
#include "interfaces/shell.h"
|
||||
#include "qwaylandlayershell_p.h"
|
||||
#include "qwaylandlayersurface_p.h"
|
||||
#include "layershellqt_logging.h"
|
||||
|
||||
#include <QtWaylandClient/private/qwaylandscreen_p.h>
|
||||
#include <QtWaylandClient/private/qwaylandsurface_p.h>
|
||||
@ -16,14 +18,37 @@ namespace LayerShellQt
|
||||
{
|
||||
QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window)
|
||||
: QtWaylandClient::QWaylandShellSurface(window)
|
||||
, 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")))
|
||||
, QtWayland::zwlr_layer_surface_v1()
|
||||
{
|
||||
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()
|
||||
@ -72,9 +97,9 @@ void QWaylandLayerSurface::setMargins(const QMargins &margins)
|
||||
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)
|
||||
|
@ -23,7 +23,7 @@ class LAYERSHELLQT_EXPORT QWaylandLayerSurface : public QtWaylandClient::QWaylan
|
||||
Q_OBJECT
|
||||
public:
|
||||
QWaylandLayerSurface(QWaylandLayerShell *shell, QtWaylandClient::QWaylandWindow *window);
|
||||
virtual ~QWaylandLayerSurface();
|
||||
~QWaylandLayerSurface() override;
|
||||
|
||||
bool isExposed() const override
|
||||
{
|
||||
@ -33,7 +33,7 @@ public:
|
||||
void setAnchor(uint32_t anchor);
|
||||
void setExclusiveZone(int32_t zone);
|
||||
void setMargins(const QMargins &margins);
|
||||
void setKeyboardInteractivity(bool enabled);
|
||||
void setKeyboardInteractivity(uint32_t interactivity);
|
||||
void setLayer(uint32_t layer);
|
||||
|
||||
void applyConfigure() override;
|
||||
|
@ -25,7 +25,7 @@
|
||||
THIS SOFTWARE.
|
||||
</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">
|
||||
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
|
||||
@ -100,7 +100,7 @@
|
||||
</request>
|
||||
</interface>
|
||||
|
||||
<interface name="zwlr_layer_surface_v1" version="3">
|
||||
<interface name="zwlr_layer_surface_v1" version="4">
|
||||
<description summary="layer metadata interface">
|
||||
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
|
||||
@ -203,21 +203,85 @@
|
||||
<arg name="left" type="int"/>
|
||||
</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">
|
||||
<description summary="requests keyboard events">
|
||||
Set to 1 to request that the seat send keyboard events to this layer
|
||||
surface. For layers below the shell surface layer, the seat will use
|
||||
normal focus semantics. For layers above the shell surface layers, the
|
||||
seat will always give exclusive keyboard focus to the top-most layer
|
||||
which has keyboard interactivity set to true.
|
||||
Set how keyboard events are delivered to this surface. By default,
|
||||
layer shell surfaces do not receive keyboard events; this request can
|
||||
be used to change this.
|
||||
|
||||
This setting is inherited by child surfaces set by the get_popup
|
||||
request.
|
||||
|
||||
Layer surfaces receive pointer, touch, and tablet events normally. If
|
||||
you do not want to receive them, set the input region on your surface
|
||||
to an empty region.
|
||||
|
||||
Events is double-buffered, see wl_surface.commit.
|
||||
Keyboard interactivity is double-buffered, see wl_surface.commit.
|
||||
</description>
|
||||
<arg name="keyboard_interactivity" type="uint"/>
|
||||
<arg name="keyboard_interactivity" type="uint" enum="keyboard_interactivity"/>
|
||||
</request>
|
||||
|
||||
<request name="get_popup">
|
||||
@ -302,6 +366,7 @@
|
||||
<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_anchor" value="2" summary="anchor bitfield is invalid"/>
|
||||
<entry name="invalid_keyboard_interactivity" value="3" summary="keyboard interactivity is invalid"/>
|
||||
</enum>
|
||||
|
||||
<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
|
||||
*/
|
||||
|
||||
#include <QCommandLineParser>
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QPainter>
|
||||
#include <QRasterWindow>
|
||||
#include <QTimer>
|
||||
#include <QWindow>
|
||||
|
||||
#include <QMetaEnum>
|
||||
|
||||
#include <interfaces/shell.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)
|
||||
{
|
||||
LayerShellQt::Shell::useLayerShell();
|
||||
Shell::useLayerShell();
|
||||
|
||||
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 }"
|
||||
"}"
|
||||
|
||||
,
|
||||
QStringLiteral("bananaland:/potato.qml"));
|
||||
const auto layerMetaEnum = QMetaEnum::fromType<Window::Layer>();
|
||||
const auto anchorMetaEnum = QMetaEnum::fromType<Window::Anchor>();
|
||||
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [](QObject *object) {
|
||||
auto layerWindow = LayerShellQt::Window::get(qobject_cast<QWindow *>(object));
|
||||
Q_ASSERT(layerWindow);
|
||||
layerWindow->setMargins({50, 50, 50, 50});
|
||||
});
|
||||
QCommandLineParser parser;
|
||||
QCommandLineOption marginsOption(QStringLiteral("margins"), QStringLiteral("Window margins"), QStringLiteral("pixels"), QStringLiteral("0"));
|
||||
QCommandLineOption scopeOption(QStringLiteral("scope"), QStringLiteral("Window scope"), QStringLiteral("namespace"), QStringLiteral("normal"));
|
||||
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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user