Compare commits

..

5 Commits

Author SHA1 Message Date
4c40fddf04 update description from kwin 2025-04-25 15:26:50 +02:00
29a4489c72 rename the api to setAnchorRect 2025-04-25 15:26:50 +02:00
94c82f2ed1 update docs 2025-04-25 15:26:50 +02:00
5c987fb03e -1 is forbidden now 2025-04-25 15:26:50 +02:00
b40888ac2a Add set_accomodate_exclusive_zones call
Add a new method that tells the surface whether to accomodate
exclusive zones set by other surfaces or not.
right until now this was possible by setting the eclusive zone of
this surface to the value of -1.
Besides being a magic number, it makes impossible for this surface to
set an exclusive zone by itself if we want to ignore other exclusive zones
2025-04-25 15:26:50 +02:00
7 changed files with 91 additions and 59 deletions

View File

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

View File

@ -32,9 +32,9 @@ public:
Window::KeyboardInteractivity keyboardInteractivity = Window::KeyboardInteractivityOnDemand; Window::KeyboardInteractivity keyboardInteractivity = Window::KeyboardInteractivityOnDemand;
Window::Layer layer = Window::LayerTop; Window::Layer layer = Window::LayerTop;
QMargins margins; QMargins margins;
QSize desiredSize = QSize(0, 0);
Window::ScreenConfiguration screenConfiguration = Window::ScreenFromQWindow; Window::ScreenConfiguration screenConfiguration = Window::ScreenFromQWindow;
bool closeOnDismissed = true; bool closeOnDismissed = true;
Window::AnchorRect anchorRect = Window::AnchorRectWorkArea;
}; };
static QMap<QWindow *, Window *> s_map; static QMap<QWindow *, Window *> s_map;
@ -85,6 +85,21 @@ Window::Anchor Window::exclusiveEdge() const
return d->exclusiveEdge; 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) void Window::setMargins(const QMargins &margins)
{ {
if (d->margins != margins) { if (d->margins != margins) {
@ -98,21 +113,6 @@ QMargins Window::margins() const
return d->margins; 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) void Window::setKeyboardInteractivity(KeyboardInteractivity interactivity)
{ {
if (d->keyboardInteractivity != interactivity) { if (d->keyboardInteractivity != interactivity) {

View File

@ -25,6 +25,7 @@ class LAYERSHELLQT_EXPORT Window : public QObject
Q_PROPERTY(QString scope READ scope WRITE setScope) Q_PROPERTY(QString scope READ scope WRITE setScope)
Q_PROPERTY(QMargins margins READ margins WRITE setMargins NOTIFY marginsChanged) Q_PROPERTY(QMargins margins READ margins WRITE setMargins NOTIFY marginsChanged)
Q_PROPERTY(qint32 exclusionZone READ exclusionZone WRITE setExclusiveZone NOTIFY exclusionZoneChanged) 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(Layer layer READ layer WRITE setLayer NOTIFY layerChanged)
Q_PROPERTY(KeyboardInteractivity keyboardInteractivity READ keyboardInteractivity WRITE setKeyboardInteractivity NOTIFY keyboardInteractivityChanged) Q_PROPERTY(KeyboardInteractivity keyboardInteractivity READ keyboardInteractivity WRITE setKeyboardInteractivity NOTIFY keyboardInteractivityChanged)
Q_PROPERTY(ScreenConfiguration screenConfiguration READ screenConfiguration WRITE setScreenConfiguration) Q_PROPERTY(ScreenConfiguration screenConfiguration READ screenConfiguration WRITE setScreenConfiguration)
@ -42,6 +43,12 @@ public:
Q_ENUM(Anchor); Q_ENUM(Anchor);
Q_DECLARE_FLAGS(Anchors, 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);
/** /**
* 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.
*/ */
@ -83,12 +90,12 @@ public:
void setExclusiveEdge(Window::Anchor edge); void setExclusiveEdge(Window::Anchor edge);
Window::Anchor exclusiveEdge() const; Window::Anchor exclusiveEdge() const;
AnchorRect anchorRect() const;
void setAnchorRect(AnchorRect anchorRect);
void setMargins(const QMargins &margins); void setMargins(const QMargins &margins);
QMargins margins() const; QMargins margins() const;
void setDesiredSize(const QSize &size);
QSize desiredSize() const;
void setKeyboardInteractivity(KeyboardInteractivity interactivity); void setKeyboardInteractivity(KeyboardInteractivity interactivity);
KeyboardInteractivity keyboardInteractivity() const; KeyboardInteractivity keyboardInteractivity() const;
@ -129,8 +136,8 @@ Q_SIGNALS:
void anchorsChanged(); void anchorsChanged();
void exclusionZoneChanged(); void exclusionZoneChanged();
void exclusiveEdgeChanged(); void exclusiveEdgeChanged();
void anchorRectChanged();
void marginsChanged(); void marginsChanged();
void desiredSizeChanged();
void keyboardInteractivityChanged(); void keyboardInteractivityChanged();
void layerChanged(); void layerChanged();

View File

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

View File

@ -44,11 +44,7 @@ QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShellIntegration *shell,
setAnchor(m_interface->anchors()); setAnchor(m_interface->anchors());
connect(m_interface, &Window::anchorsChanged, this, [this]() { connect(m_interface, &Window::anchorsChanged, this, [this]() {
setAnchor(m_interface->anchors()); setAnchor(m_interface->anchors());
if (m_interface->desiredSize().isNull()) {
setDesiredSize(m_window->windowContentGeometry().size()); setDesiredSize(m_window->windowContentGeometry().size());
} else {
setDesiredSize(m_interface->desiredSize());
}
}); });
setExclusiveZone(m_interface->exclusionZone()); setExclusiveZone(m_interface->exclusionZone());
@ -60,27 +56,22 @@ QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShellIntegration *shell,
setExclusiveEdge(m_interface->exclusiveEdge()); setExclusiveEdge(m_interface->exclusiveEdge());
}); });
setAnchorRect(m_interface->anchorRect());
connect(m_interface, &Window::anchorRectChanged, this, [this]() {
setAnchorRect(m_interface->anchorRect());
});
setMargins(m_interface->margins()); setMargins(m_interface->margins());
connect(m_interface, &Window::marginsChanged, this, [this]() { connect(m_interface, &Window::marginsChanged, this, [this]() {
setMargins(m_interface->margins()); setMargins(m_interface->margins());
}); });
connect(m_interface, &Window::desiredSizeChanged, this, [this]() {
if (!m_interface->desiredSize().isNull()) {
setDesiredSize(m_interface->desiredSize());
}
});
setKeyboardInteractivity(m_interface->keyboardInteractivity()); setKeyboardInteractivity(m_interface->keyboardInteractivity());
connect(m_interface, &Window::keyboardInteractivityChanged, this, [this]() { connect(m_interface, &Window::keyboardInteractivityChanged, this, [this]() {
setKeyboardInteractivity(m_interface->keyboardInteractivity()); setKeyboardInteractivity(m_interface->keyboardInteractivity());
}); });
if (m_interface->desiredSize().isNull()) {
setDesiredSize(window->windowContentGeometry().size()); setDesiredSize(window->windowContentGeometry().size());
} else {
setDesiredSize(m_interface->desiredSize());
}
} }
QWaylandLayerSurface::~QWaylandLayerSurface() QWaylandLayerSurface::~QWaylandLayerSurface()
@ -165,6 +156,13 @@ 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) 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());
@ -188,16 +186,12 @@ void QWaylandLayerSurface::setWindowGeometry(const QRect &geometry)
return; return;
} }
if (m_interface->desiredSize().isNull()) {
setDesiredSize(geometry.size()); setDesiredSize(geometry.size());
}
} }
#else #else
void QWaylandLayerSurface::setWindowSize(const QSize &size) void QWaylandLayerSurface::setWindowSize(const QSize &size)
{ {
if (m_interface->desiredSize().isNull()) {
setDesiredSize(size); setDesiredSize(size);
}
} }
#endif #endif
@ -211,10 +205,6 @@ bool QWaylandLayerSurface::requestActivate()
activation->activate(m_activationToken, window()->wlSurface()); activation->activate(m_activationToken, window()->wlSurface());
m_activationToken = {}; m_activationToken = {};
return true; 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 { } else {
const auto focusWindow = QGuiApplication::focusWindow(); const auto focusWindow = QGuiApplication::focusWindow();
const auto wlWindow = focusWindow ? static_cast<QtWaylandClient::QWaylandWindow *>(focusWindow->handle()) : window(); const auto wlWindow = focusWindow ? static_cast<QtWaylandClient::QWaylandWindow *>(focusWindow->handle()) : window();

View File

@ -8,6 +8,7 @@
#ifndef _LAYERSURFACE_H #ifndef _LAYERSURFACE_H
#define _LAYERSURFACE_H #define _LAYERSURFACE_H
#include <cstdint>
#include <wayland-client.h> #include <wayland-client.h>
#include "qwaylandlayershellintegration_p.h" #include "qwaylandlayershellintegration_p.h"
@ -38,6 +39,7 @@ public:
void setAnchor(uint32_t anchor); void setAnchor(uint32_t anchor);
void setExclusiveZone(int32_t zone); void setExclusiveZone(int32_t zone);
void setExclusiveEdge(uint32_t edge); void setExclusiveEdge(uint32_t edge);
void setAnchorRect(int32_t anchorRect);
void setMargins(const QMargins &margins); void setMargins(const QMargins &margins);
void setKeyboardInteractivity(uint32_t interactivity); void setKeyboardInteractivity(uint32_t interactivity);
void setLayer(uint32_t layer); void setLayer(uint32_t layer);

View File

@ -25,7 +25,7 @@
THIS SOFTWARE. THIS SOFTWARE.
</copyright> </copyright>
<interface name="zwlr_layer_shell_v1" version="5"> <interface name="zwlr_layer_shell_v1" version="6">
<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="5"> <interface name="zwlr_layer_surface_v1" version="6">
<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
@ -168,21 +168,25 @@
Surfaces that do not wish to have an exclusive zone may instead specify 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 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 surface indicates that it would like to be moved to avoid occluding
surfaces with a positive exclusive zone. If set to -1, the surface surfaces with a positive exclusive zone.
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 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 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 might set its exclusive zone to 0, so that it is moved to avoid
occluding the panel, but shell surfaces are shown underneath it. A occluding the panel, but shell surfaces are shown underneath it.
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. The default value is 0.
Exclusive zone is double-buffered, see wl_surface.commit. 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> </description>
<arg name="zone" type="int"/> <arg name="zone" type="int"/>
</request> </request>
@ -368,6 +372,7 @@
<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"/> <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_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>
<enum name="anchor" bitfield="true"> <enum name="anchor" bitfield="true">
@ -403,5 +408,33 @@
</description> </description>
<arg name="edge" type="uint"/> <arg name="edge" type="uint"/>
</request> </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> </interface>
</protocol> </protocol>