Compare commits

..

16 Commits

Author SHA1 Message Date
44dfa3b45c Update version for new release 6.5.2 2025-10-29 11:55:55 +05:30
62864d136c Update version for new release 6.5.1 2025-10-28 14:00:07 +05:30
1333a34921 Update version for new release 6.5.0 2025-10-16 13:00:36 +05:30
7a746346b0 Update version for new release 6.4.91 2025-10-02 15:55:45 +05:30
ebd64dd395 Update version for new release 6.4.90 2025-09-18 17:26:46 +05:30
ca0ac57fb4 Update Qt version requirement to 6.9.0
GIT_SILENT
2025-09-18 14:00:16 +05:30
d085a88c81 Update Frameworks version requirement to 6.18.0
GIT_SILENT
2025-09-18 14:00:16 +05:30
5e57a060c6 Register anchors flags to QML
CCBUG: 507602
2025-08-05 13:04:50 +02:00
d436a779d7 Request activate on show
Unless the window doesn't have keyboard interactivity or the caller
wants it not to.

To match XDG Shell behavior and general Qt window behavior.
2025-08-03 10:08:40 +00:00
f599e829ad When activating, also try token from XDG_ACTIVATION_TOKEN
This matches upstream QWaylandXdgSurface behavior.

It also makes various activation magic e.g. KDBusService work.
2025-07-30 23:29:13 +00:00
397398dfd8 Port to declarative type registration
BUG: 507602
2025-07-30 21:39:23 +02:00
7a074a3684 update version for new release 2025-05-19 18:33:35 +05:30
8b54edb695 update version for new release 2025-05-15 15:14:19 +05:30
ffa33fef9f Update Qt version requirement to 6.8.0
GIT_SILENT
2025-05-15 14:20:07 +05:30
3522070454 Update Frameworks version requirement to 6.14.0
GIT_SILENT
2025-05-15 14:20:07 +05:30
80d5e3c935 Expose setDesiredSize to the C++ API
Making it possible for clients to call setDesiredSize directly,

The idea is that under Wayland, the panel calls this intead of setGeometry,
not trying to set an abosulute geometry that might cause the panel sized wrongly,
but just sets an hint which will ensure the panel won't overlap another one

used by https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/5437

CCBUG:489703
2025-04-30 17:23:48 +02:00
13 changed files with 212 additions and 146 deletions

View File

@ -4,13 +4,13 @@
cmake_minimum_required(VERSION 3.16)
project(layershellqt)
set(PROJECT_VERSION "6.3.80")
set(PROJECT_VERSION "6.5.2")
set(PROJECT_VERSION_MAJOR 6)
set(CMAKE_C_STANDARD 99)
set(QT_MIN_VERSION "6.7.0")
set(KF6_MIN_VERSION "6.10.0")
set(QT_MIN_VERSION "6.9.0")
set(KF6_MIN_VERSION "6.18.0")
set(KDE_COMPILERSETTINGS_LEVEL "5.82")
set(CMAKE_CXX_STANDARD 20)

View File

@ -5,6 +5,8 @@ remove_definitions(-DQT_NO_SIGNALS_SLOTS_KEYWORDS)
add_library(LayerShellQtInterface)
qt6_extract_metatypes(LayerShellQtInterface)
if (Qt6_VERSION VERSION_GREATER_EQUAL "6.8.0")
set(private_code_option "PRIVATE_CODE")
endif()

View File

@ -4,7 +4,8 @@
ecm_add_qml_module(LayerShellQtQml
URI "org.kde.layershell"
VERSION 1.0
SOURCES layershellqtplugin.cpp)
SOURCES types.h types.cpp
GENERATE_PLUGIN_SOURCE)
target_link_libraries(LayerShellQtQml PRIVATE Qt::Qml LayerShellQtInterface)
ecm_finalize_qml_module(LayerShellQtQml DESTINATION ${KDE_INSTALL_QMLDIR})
ecm_finalize_qml_module(LayerShellQtQml DESTINATION ${KDE_INSTALL_QMLDIR})

View File

@ -1,51 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 Aleix Pol Gonzalez <aleix.pol_gonzalez@mercedes-benz.com>
*
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "../interfaces/window.h"
#include <QQmlExtensionPlugin>
#include <qqml.h>
QML_DECLARE_TYPEINFO(LayerShellQt::Window, QML_HAS_ATTACHED_PROPERTIES)
class ExtQMargins
{
QMargins m_margins;
Q_GADGET
Q_PROPERTY(int left READ left WRITE setLeft FINAL)
Q_PROPERTY(int right READ right WRITE setRight FINAL)
Q_PROPERTY(int top READ top WRITE setTop FINAL)
Q_PROPERTY(int bottom READ bottom WRITE setBottom FINAL)
QML_FOREIGN(QMargins)
QML_EXTENDED(ExtQMargins)
public:
ExtQMargins(const QMargins &margins);
int left() const { return m_margins.left(); }
void setLeft(int left) { m_margins.setLeft(left); }
int right() const { return m_margins.right(); }
void setRight(int right) { m_margins.setRight(right); }
int top() const { return m_margins.top(); }
void setTop(int top) { m_margins.setTop(top); }
int bottom() const { return m_margins.bottom(); }
void setBottom(int bottom) { m_margins.setBottom(bottom); }
};
class Plugin : public QQmlExtensionPlugin
{
Q_PLUGIN_METADATA(IID "org.kde.layershellqt")
Q_OBJECT
public:
void registerTypes(const char *uri) override
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.layershell"));
qmlRegisterType<LayerShellQt::Window>(uri, 1, 0, "Window");
qmlRegisterExtendedUncreatableType<QMargins, ExtQMargins>(uri, 1, 0, "ExtQMargins", QStringLiteral("Only created from C++"));
}
};
#include "layershellqtplugin.moc"

49
src/declarative/types.cpp Normal file
View File

@ -0,0 +1,49 @@
/*
* SPDX-FileCopyrightText: 2023 Aleix Pol Gonzalez <aleix.pol_gonzalez@mercedes-benz.com>
*
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "types.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 1)
int QQmlMarginsValueType::left() const
{
return m.left();
}
int QQmlMarginsValueType::top() const
{
return m.top();
}
int QQmlMarginsValueType::right() const
{
return m.right();
}
int QQmlMarginsValueType::bottom() const
{
return m.bottom();
}
void QQmlMarginsValueType::setLeft(int left)
{
m.setLeft(left);
}
void QQmlMarginsValueType::setTop(int top)
{
m.setTop(top);
}
void QQmlMarginsValueType::setRight(int right)
{
m.setRight(right);
}
void QQmlMarginsValueType::setBottom(int bottom)
{
m.setBottom(bottom);
}
#endif

55
src/declarative/types.h Normal file
View File

@ -0,0 +1,55 @@
/*
* SPDX-FileCopyrightText: 2023 Aleix Pol Gonzalez <aleix.pol_gonzalez@mercedes-benz.com>
*
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "../interfaces/window.h"
#include <qqml.h>
QML_DECLARE_TYPEINFO(LayerShellQt::Window, QML_HAS_ATTACHED_PROPERTIES)
class WindowForeign
{
Q_GADGET
QML_NAMED_ELEMENT(Window)
QML_FOREIGN(LayerShellQt::Window)
QML_UNCREATABLE("")
QML_ATTACHED(LayerShellQt::Window)
};
// available upstream since https://invent.kde.org/qt/qt/qtdeclarative/-/commit/a398101f715bfc447aa889fc9c58b13bfe75ab47
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 1)
struct Q_QML_EXPORT QQmlMarginsValueType {
QMargins m;
Q_PROPERTY(int left READ left WRITE setLeft FINAL)
Q_PROPERTY(int right READ right WRITE setRight FINAL)
Q_PROPERTY(int top READ top WRITE setTop FINAL)
Q_PROPERTY(int bottom READ bottom WRITE setBottom FINAL)
Q_GADGET
QML_ANONYMOUS
QML_FOREIGN(QMargins)
QML_EXTENDED(QQmlMarginsValueType)
QML_STRUCTURED_VALUE
public:
QQmlMarginsValueType() = default;
Q_INVOKABLE QQmlMarginsValueType(const QMarginsF &margins)
: m(margins.toMargins())
{
}
int left() const;
int right() const;
int top() const;
int bottom() const;
void setLeft(int);
void setRight(int);
void setTop(int);
void setBottom(int);
operator QMargins() const
{
return m;
}
};
#endif

View File

@ -32,9 +32,10 @@ public:
Window::KeyboardInteractivity keyboardInteractivity = Window::KeyboardInteractivityOnDemand;
Window::Layer layer = Window::LayerTop;
QMargins margins;
QSize desiredSize = QSize(0, 0);
Window::ScreenConfiguration screenConfiguration = Window::ScreenFromQWindow;
bool closeOnDismissed = true;
Window::AnchorRect anchorRect = Window::AnchorRectWorkArea;
bool activateOnShow = true;
};
static QMap<QWindow *, Window *> s_map;
@ -85,21 +86,6 @@ Window::Anchor Window::exclusiveEdge() const
return d->exclusiveEdge;
}
Window::AnchorRect Window::anchorRect() const
{
return d->anchorRect;
}
void Window::setAnchorRect(Window::AnchorRect anchorRect)
{
if (d->anchorRect == anchorRect) {
return;
}
d->anchorRect = anchorRect;
Q_EMIT anchorRectChanged();
}
void Window::setMargins(const QMargins &margins)
{
if (d->margins != margins) {
@ -113,6 +99,21 @@ QMargins Window::margins() const
return d->margins;
}
void Window::setDesiredSize(const QSize &size)
{
if (size == d->desiredSize) {
return;
}
d->desiredSize = size;
Q_EMIT desiredSizeChanged();
}
QSize Window::desiredSize() const
{
return d->desiredSize;
}
void Window::setKeyboardInteractivity(KeyboardInteractivity interactivity)
{
if (d->keyboardInteractivity != interactivity) {
@ -170,6 +171,16 @@ void Window::setCloseOnDismissed(bool close)
d->closeOnDismissed = close;
}
bool Window::activateOnShow() const
{
return d->activateOnShow;
}
void Window::setActivateOnShow(bool activateOnShow)
{
d->activateOnShow = activateOnShow;
}
Window::Window(QWindow *window)
: QObject(window)
, d(new WindowPrivate(window))

View File

@ -25,10 +25,10 @@ class LAYERSHELLQT_EXPORT Window : public QObject
Q_PROPERTY(QString scope READ scope WRITE setScope)
Q_PROPERTY(QMargins margins READ margins WRITE setMargins NOTIFY marginsChanged)
Q_PROPERTY(qint32 exclusionZone READ exclusionZone WRITE setExclusiveZone NOTIFY exclusionZoneChanged)
Q_PROPERTY(AnchorRect anchorRect READ anchorRect WRITE setAnchorRect NOTIFY anchorRectChanged)
Q_PROPERTY(Layer layer READ layer WRITE setLayer NOTIFY layerChanged)
Q_PROPERTY(KeyboardInteractivity keyboardInteractivity READ keyboardInteractivity WRITE setKeyboardInteractivity NOTIFY keyboardInteractivityChanged)
Q_PROPERTY(ScreenConfiguration screenConfiguration READ screenConfiguration WRITE setScreenConfiguration)
Q_PROPERTY(bool activateOnShow READ activateOnShow WRITE setActivateOnShow)
public:
~Window() override;
@ -40,14 +40,8 @@ public:
AnchorLeft = 4, ///< The left edge of the anchor rectangle
AnchorRight = 8, ///< The right edge of the anchor rectangle
};
Q_ENUM(Anchor);
Q_DECLARE_FLAGS(Anchors, Anchor)
/**
* This enum is used to choose between anchoring to work area or screen area
*/
enum AnchorRect { AnchorRectWorkArea = 0, AnchorRectFullArea = 1 };
Q_ENUM(AnchorRect);
Q_FLAG(Anchors)
/**
* This enum type is used to specify the layer where a surface can be put in.
@ -90,12 +84,12 @@ public:
void setExclusiveEdge(Window::Anchor edge);
Window::Anchor exclusiveEdge() const;
AnchorRect anchorRect() const;
void setAnchorRect(AnchorRect anchorRect);
void setMargins(const QMargins &margins);
QMargins margins() const;
void setDesiredSize(const QSize &size);
QSize desiredSize() const;
void setKeyboardInteractivity(KeyboardInteractivity interactivity);
KeyboardInteractivity keyboardInteractivity() const;
@ -124,6 +118,18 @@ public:
void setCloseOnDismissed(bool close);
bool closeOnDismissed() const;
/**
* Whether the window should requestActivate on show.
*
* Normally, you want this enabled but in case of e.g. a desktop window, this can be disabled.
*
* It does nothing when KeyboardInteractivity is KeyboardInteractivityNone.
*
* The default is true.
*/
void setActivateOnShow(bool activateOnShow);
bool activateOnShow() const;
/**
* Gets the LayerShell Window for a given Qt Window
* Ownership is not transferred
@ -136,8 +142,8 @@ Q_SIGNALS:
void anchorsChanged();
void exclusionZoneChanged();
void exclusiveEdgeChanged();
void anchorRectChanged();
void marginsChanged();
void desiredSizeChanged();
void keyboardInteractivityChanged();
void layerChanged();

View File

@ -15,7 +15,7 @@
namespace LayerShellQt
{
QWaylandLayerShellIntegration::QWaylandLayerShellIntegration()
: QWaylandShellIntegrationTemplate<QWaylandLayerShellIntegration>(6)
: QWaylandShellIntegrationTemplate<QWaylandLayerShellIntegration>(5)
, m_xdgActivation(new QWaylandXdgActivationV1)
{
}

View File

@ -44,7 +44,11 @@ QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShellIntegration *shell,
setAnchor(m_interface->anchors());
connect(m_interface, &Window::anchorsChanged, this, [this]() {
setAnchor(m_interface->anchors());
setDesiredSize(m_window->windowContentGeometry().size());
if (m_interface->desiredSize().isNull()) {
setDesiredSize(m_window->windowContentGeometry().size());
} else {
setDesiredSize(m_interface->desiredSize());
}
});
setExclusiveZone(m_interface->exclusionZone());
@ -56,22 +60,27 @@ QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShellIntegration *shell,
setExclusiveEdge(m_interface->exclusiveEdge());
});
setAnchorRect(m_interface->anchorRect());
connect(m_interface, &Window::anchorRectChanged, this, [this]() {
setAnchorRect(m_interface->anchorRect());
});
setMargins(m_interface->margins());
connect(m_interface, &Window::marginsChanged, this, [this]() {
setMargins(m_interface->margins());
});
connect(m_interface, &Window::desiredSizeChanged, this, [this]() {
if (!m_interface->desiredSize().isNull()) {
setDesiredSize(m_interface->desiredSize());
}
});
setKeyboardInteractivity(m_interface->keyboardInteractivity());
connect(m_interface, &Window::keyboardInteractivityChanged, this, [this]() {
setKeyboardInteractivity(m_interface->keyboardInteractivity());
});
setDesiredSize(window->windowContentGeometry().size());
if (m_interface->desiredSize().isNull()) {
setDesiredSize(window->windowContentGeometry().size());
} else {
setDesiredSize(m_interface->desiredSize());
}
}
QWaylandLayerSurface::~QWaylandLayerSurface()
@ -156,13 +165,6 @@ void QWaylandLayerSurface::setExclusiveEdge(uint32_t edge)
}
}
void QWaylandLayerSurface::setAnchorRect(int32_t anchorRect)
{
if (zwlr_layer_surface_v1_get_version(object()) >= ZWLR_LAYER_SURFACE_V1_SET_ANCHOR_RECT_SINCE_VERSION) {
set_anchor_rect(anchorRect);
}
}
void QWaylandLayerSurface::setMargins(const QMargins &margins)
{
set_margin(margins.top(), margins.right(), margins.bottom(), margins.left());
@ -186,12 +188,16 @@ void QWaylandLayerSurface::setWindowGeometry(const QRect &geometry)
return;
}
setDesiredSize(geometry.size());
if (m_interface->desiredSize().isNull()) {
setDesiredSize(geometry.size());
}
}
#else
void QWaylandLayerSurface::setWindowSize(const QSize &size)
{
setDesiredSize(size);
if (m_interface->desiredSize().isNull()) {
setDesiredSize(size);
}
}
#endif
@ -205,6 +211,10 @@ bool QWaylandLayerSurface::requestActivate()
activation->activate(m_activationToken, window()->wlSurface());
m_activationToken = {};
return true;
} else if (const auto token = qEnvironmentVariable("XDG_ACTIVATION_TOKEN"); !token.isEmpty()) {
activation->activate(token, window()->wlSurface());
qunsetenv("XDG_ACTIVATION_TOKEN");
return true;
} else {
const auto focusWindow = QGuiApplication::focusWindow();
const auto wlWindow = focusWindow ? static_cast<QtWaylandClient::QWaylandWindow *>(focusWindow->handle()) : window();
@ -220,6 +230,23 @@ bool QWaylandLayerSurface::requestActivate()
return false;
}
bool QWaylandLayerSurface::requestActivateOnShow()
{
if (!m_interface->activateOnShow()) {
return false;
}
if (m_interface->keyboardInteractivity() == Window::KeyboardInteractivityNone) {
return false;
}
if (m_window->window()->property("_q_showWithoutActivating").toBool()) {
return false;
}
return requestActivate();
}
void QWaylandLayerSurface::setXdgActivationToken(const QString &token)
{
m_activationToken = token;

View File

@ -8,7 +8,6 @@
#ifndef _LAYERSURFACE_H
#define _LAYERSURFACE_H
#include <cstdint>
#include <wayland-client.h>
#include "qwaylandlayershellintegration_p.h"
@ -39,7 +38,6 @@ public:
void setAnchor(uint32_t anchor);
void setExclusiveZone(int32_t zone);
void setExclusiveEdge(uint32_t edge);
void setAnchorRect(int32_t anchorRect);
void setMargins(const QMargins &margins);
void setKeyboardInteractivity(uint32_t interactivity);
void setLayer(uint32_t layer);
@ -52,6 +50,7 @@ public:
#endif
bool requestActivate() override;
bool requestActivateOnShow() override;
void setXdgActivationToken(const QString &token) override;
void requestXdgActivationToken(quint32 serial) override;

View File

@ -25,7 +25,7 @@
THIS SOFTWARE.
</copyright>
<interface name="zwlr_layer_shell_v1" version="6">
<interface name="zwlr_layer_shell_v1" version="5">
<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="6">
<interface name="zwlr_layer_surface_v1" version="5">
<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
@ -168,25 +168,21 @@
Surfaces that do not wish to have an exclusive zone may instead specify
how they should interact with surfaces that do. If set to zero, the
surface indicates that it would like to be moved to avoid occluding
surfaces with a positive exclusive zone.
surfaces with a positive exclusive zone. If set to -1, the surface
indicates that it would not like to be moved to accommodate for other
surfaces, and the compositor should extend it all the way to the edges
it is anchored to.
For example, a panel might set its exclusive zone to 10, so that
maximized shell surfaces are not shown on top of it. A notification
might set its exclusive zone to 0, so that it is moved to avoid
occluding the panel, but shell surfaces are shown underneath it.
occluding the panel, but shell surfaces are shown underneath it. A
wallpaper or lock screen might set their exclusive zone to -1, so that
they stretch below or over the panel.
The default value is 0.
Exclusive zone is double-buffered, see wl_surface.commit.
Since version 6 It must be a value of 0 or more, otherwise the error
invalid_exclusive_zone will be triggered.
Until version 5 if set to -1, the surface indicates that it would not
like to be moved to accommodate for other surfaces, and the compositor
should extend it all the way to the edges it is anchored to.
A wallpaper or lock screen might set their exclusive zone to -1, so that
they stretch below or over the panel.
</description>
<arg name="zone" type="int"/>
</request>
@ -372,7 +368,6 @@
<entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/>
<entry name="invalid_keyboard_interactivity" value="3" summary="keyboard interactivity is invalid"/>
<entry name="invalid_exclusive_edge" value="4" summary="exclusive edge is invalid given the surface anchors"/>
<entry name="invalid_exclusive_zone" value="5" summary="exclusive zone value is invalid, since version 6 it can't be less than zero"/>
</enum>
<enum name="anchor" bitfield="true">
@ -408,33 +403,5 @@
</description>
<arg name="edge" type="uint"/>
</request>
<!-- Version 6 additions -->
<enum name="anchor_rect">
<entry name="full_area" value="0" summary="the full area anchor rect">
<description summary="the full area anchor rect">
Place the layer_surface_v1 relative to the full output area.
</description>
</entry>
<entry name="work_area" value="1" summary="the work area anchor rect">
<description summary="the work area anchor rect">
Place the layer_surface_v1 relative to the output area while taking
the exclusive zone of other surfaces into account.
</description>
</entry>
</enum>
<request name="set_anchor_rect" since="6">
<description summary="set the anchor rect">
Set the anchor rectangle relative to which the anchors are applied.
By default, the layer_surface_v1 is anchored to the 'work_area'.
Anchor rect is double-buffered, see wl_surface.commit.
</description>
<arg name="rect" type="uint" enum="anchor_rect"/>
</request>
</interface>
</protocol>

View File

@ -53,7 +53,7 @@ int main(int argc, char **argv)
QGuiApplication app(argc, argv);
const auto layerMetaEnum = QMetaEnum::fromType<Window::Layer>();
const auto anchorMetaEnum = QMetaEnum::fromType<Window::Anchor>();
const auto anchorMetaEnum = QMetaEnum::fromType<Window::Anchors>();
QCommandLineParser parser;
QCommandLineOption marginsOption(QStringLiteral("margins"), QStringLiteral("Window margins"), QStringLiteral("pixels"), QStringLiteral("0"));