Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ endif()
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)
find_package(ICU 74.2 REQUIRED COMPONENTS uc i18n io)
find_package(WaylandProtocols REQUIRED)
find_package(TreelandProtocols 0.9.0 REQUIRED)
find_package(PkgConfig REQUIRED)

# Check if dde-api provides EventLogger (header-only)
Expand Down
3 changes: 3 additions & 0 deletions frame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(PRIVATE_HEADERS
private/appletproxy_p.h
private/appletbridge_p.h
private/dsqmlglobal_p.h
layershell/layershellextension_p.h
layershell/qwaylandlayershellsurface_p.h
layershell/qwaylandlayershellintegration_p.h
wayland/xdgactivation_p.h
Expand Down Expand Up @@ -68,6 +69,7 @@ add_library(dde-shell-frame SHARED
appletitemmodel.cpp
dsqmlglobal.cpp
layershell/dlayershellwindow.cpp
layershell/layershellextension.cpp
layershell/qwaylandlayershellsurface.cpp
layershell/qwaylandlayershellintegration.cpp
models/kextracolumnsproxymodel.cpp
Expand All @@ -87,6 +89,7 @@ qt_generate_wayland_protocol_client_sources(dde-shell-frame FILES
${CMAKE_CURRENT_SOURCE_DIR}/layershell/protocol/wlr-layer-shell-unstable-v1.xml
${WaylandProtocols_DATADIR}/stable/xdg-shell/xdg-shell.xml
${WaylandProtocols_DATADIR}/staging/xdg-activation/xdg-activation-v1.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-layer-shell-extension-unstable-v1.xml
)

set_target_properties(dde-shell-frame PROPERTIES
Expand Down
14 changes: 14 additions & 0 deletions frame/layershell/dlayershellwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
int preferredWidth = -1;
int preferredHeight = -1;
bool closeOnDismissed = true;
bool resizing = false;
QRegion inputRegion;
};

Expand Down Expand Up @@ -299,6 +300,19 @@
return waylandWindow->shellIntegration() == shellIntegration;
}

bool DLayerShellWindow::isResizing() const

Check warning on line 303 in frame/layershell/dlayershellwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'isResizing' is never used.
{
return d->resizing;
}

void DLayerShellWindow::setResizing(bool resizing)

Check warning on line 308 in frame/layershell/dlayershellwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'setResizing' is never used.
{
if (d->resizing == resizing)
return;
d->resizing = resizing;
Q_EMIT resizingChanged();
}

DLayerShellWindow* DLayerShellWindow::get(QWindow* window)
{
auto dlayerShellWindow = s_map.value(window);
Expand Down
10 changes: 10 additions & 0 deletions frame/layershell/dlayershellwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight RESET resetPreferredHeight NOTIFY geometryHintsChanged)
Q_PROPERTY(QRegion inputRegion READ inputRegion WRITE setInputRegion RESET resetInputRegion NOTIFY inputRegionChanged)

Q_PROPERTY(bool resizing READ isResizing NOTIFY resizingChanged)
Q_PROPERTY(bool closeOnDismissed READ closeOnDismissed WRITE setCloseOnDismissed)

public:
Expand Down Expand Up @@ -149,6 +150,9 @@

bool ensureWaylandShellIntegration();

/** Whether a system resize is pending or active on this layer surface. */
bool isResizing() const;

/**
* Gets the LayerShell Window for a given Qt Window
* Ownership is not transferred
Expand All @@ -166,9 +170,15 @@
void scopeChanged();
void geometryHintsChanged();
void inputRegionChanged();
void resizingChanged();
// Final size in QWindow coordinates, delivered before resizing becomes false.
void resizeFinished(const QSize &size);

private:
friend class QWaylandLayerShellSurface;
void setResizing(bool resizing);

DLayerShellWindow(QWindow* window);

Check warning on line 181 in frame/layershell/dlayershellwindow.h

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'DLayerShellWindow' has a constructor with 1 argument that is not explicit. Such, so called "Converting constructors", should in general be explicit for type safety reasons as that prevents unintended implicit conversions.
QScopedPointer<DLayerShellWindowPrivate> d;
};

Expand Down
55 changes: 55 additions & 0 deletions frame/layershell/layershellextension.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "layershellextension_p.h"

#include <QCoreApplication>

Check warning on line 7 in frame/layershell/layershellextension.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCoreApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPointer>

Check warning on line 8 in frame/layershell/layershellextension.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPointer> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DS_BEGIN_NAMESPACE

TreeLandLayerShellExtensionManager::TreeLandLayerShellExtensionManager()
: QWaylandClientExtensionTemplate<TreeLandLayerShellExtensionManager>(1)
{
initialize();
}

TreeLandLayerShellExtensionManager::~TreeLandLayerShellExtensionManager()
{
if (isInitialized())
destroy();
}

TreeLandLayerShellExtensionManager *TreeLandLayerShellExtensionManager::instance()
{
static QPointer<TreeLandLayerShellExtensionManager> manager;
if (!manager) {
manager = new TreeLandLayerShellExtensionManager;
manager->setParent(qApp);
}
return manager;
}

TreeLandLayerShellExtensionObject::TreeLandLayerShellExtensionObject(struct ::treeland_layer_shell_extension_object_v1 *object)
: QtWayland::treeland_layer_shell_extension_object_v1(object)
{
}

TreeLandLayerShellExtensionObject::~TreeLandLayerShellExtensionObject()
{
if (isInitialized())
destroy();
}

void TreeLandLayerShellExtensionObject::treeland_layer_shell_extension_object_v1_resizing(uint32_t resizing)
{
Q_EMIT resizingChanged(resizing != 0);
}

void TreeLandLayerShellExtensionObject::treeland_layer_shell_extension_object_v1_resize_rejected(uint32_t error)
{
Q_EMIT resizeRejected(error);
}

DS_END_NAMESPACE
43 changes: 43 additions & 0 deletions frame/layershell/layershellextension_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include "dsglobal.h"

Check warning on line 7 in frame/layershell/layershellextension_p.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dsglobal.h" not found.
#include "qwayland-treeland-layer-shell-extension-unstable-v1.h"

Check warning on line 8 in frame/layershell/layershellextension_p.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "qwayland-treeland-layer-shell-extension-unstable-v1.h" not found.

#include <QtWaylandClient/QWaylandClientExtension>

Check warning on line 10 in frame/layershell/layershellextension_p.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtWaylandClient/QWaylandClientExtension> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DS_BEGIN_NAMESPACE

class TreeLandLayerShellExtensionManager : public QWaylandClientExtensionTemplate<TreeLandLayerShellExtensionManager>,
public QtWayland::treeland_layer_shell_extension_manager_v1
{
Q_OBJECT
public:
TreeLandLayerShellExtensionManager();
~TreeLandLayerShellExtensionManager() override;

static TreeLandLayerShellExtensionManager *instance();
};

// Owned by the layer shell surface, and destroyed before its wl_surface.
class TreeLandLayerShellExtensionObject : public QObject,
public QtWayland::treeland_layer_shell_extension_object_v1
{
Q_OBJECT
public:
explicit TreeLandLayerShellExtensionObject(struct ::treeland_layer_shell_extension_object_v1 *object);
~TreeLandLayerShellExtensionObject() override;

Q_SIGNALS:
void resizingChanged(bool resizing);
void resizeRejected(uint32_t error);

Check warning on line 36 in frame/layershell/layershellextension_p.h

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'resizeRejected' shadows outer function

protected:
void treeland_layer_shell_extension_object_v1_resizing(uint32_t resizing) override;
void treeland_layer_shell_extension_object_v1_resize_rejected(uint32_t error) override;
};

DS_END_NAMESPACE
85 changes: 84 additions & 1 deletion frame/layershell/qwaylandlayershellsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "dsglobal.h"

Check warning on line 5 in frame/layershell/qwaylandlayershellsurface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dsglobal.h" not found.
#include "dlayershellwindow.h"
#include "qwaylandlayershellsurface_p.h"
#include "layershellextension_p.h"

#include <qwayland-wlr-layer-shell-unstable-v1.h>
#include <wayland-wlr-layer-shell-unstable-v1-client-protocol.h>

#include <QLoggingCategory>
#include <QScopedValueRollback>
#include <private/qhighdpiscaling_p.h>

#include <QtWaylandClient/private/qwaylandinputdevice_p.h>
#include <QtWaylandClient/private/qwaylandscreen_p.h>
#include <QtWaylandClient/private/qwaylandsurface_p.h>
#include <QtWaylandClient/private/qwaylandwindow_p.h>
Expand Down Expand Up @@ -63,6 +67,9 @@

QWaylandLayerShellSurface::~QWaylandLayerShellSurface()
{
m_shellExtension.reset();
if (m_dlayerShellWindow)
m_dlayerShellWindow->setResizing(false);
Comment on lines +70 to +72

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Final dock size is lost

When the output changes while a resize is active and the latest configure has not yet been applied, the surface destructor clears the resizing state without calling finishResize(), so it never adopts m_pendingSize or emits resizeFinished. The QML resizing-state handler then persists the last reflected dockSize, which can be older than the final configure, and the recreated surface shows the wrong size.

Finalize and persist the pending resize size before destroying the shell surface during recreation.

Prompt for AI agents
In `frame/layershell/qwaylandlayershellsurface.cpp` at lines 70-72:

**Final dock size is lost**

When the output changes while a resize is active and the latest configure has not yet been applied, the surface destructor clears the resizing state without calling `finishResize()`, so it never adopts `m_pendingSize` or emits `resizeFinished`. The QML resizing-state handler then persists the last reflected `dockSize`, which can be older than the final configure, and the recreated surface shows the wrong size.

Finalize and persist the pending resize size before destroying the shell surface during recreation.

destroy();
}

Expand Down Expand Up @@ -173,7 +180,7 @@

if (!m_configured) {
m_configured = true;
window()->resizeFromApplyConfigure(m_pendingSize);
applyConfigure();
#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
window()->handleExpose(QRect(QPoint(), m_pendingSize));
#elif QT_VERSION < QT_VERSION_CHECK(6, 9, 0)
Expand All @@ -189,11 +196,87 @@

void QWaylandLayerShellSurface::applyConfigure()
{
if (m_interactiveResize) {
// Keep layer layout in step with the size Qt is about to render. In
// particular, margin/exclusive-zone commits must not re-anchor the
// surface using its pre-drag size. Do not echo unchanged replies.
const QSize previousRequest = m_requestSize;
calcAndSetRequestSize(m_pendingSize);
if (m_requestSize != previousRequest)
trySetAnchorsAndSize();
}

QScopedValueRollback<bool> applyingConfigure(m_applyingConfigure, true);
window()->resizeFromApplyConfigure(m_pendingSize);
}

void QWaylandLayerShellSurface::finishResize()
{
// An interactive resize can end before Qt applies its last configure.
// Adopt it before clients persist their size or restore geometry bindings.
if (m_interactiveResize && m_configured) {
calcAndSetRequestSize(m_pendingSize);
trySetAnchorsAndSize();
Q_EMIT m_dlayerShellWindow->resizeFinished(QHighDpi::fromNativePixels(m_pendingSize, windowHandle()));
}
m_interactiveResize = false;
m_dlayerShellWindow->setResizing(false);
}

bool QWaylandLayerShellSurface::resize(QtWaylandClient::QWaylandInputDevice *inputDevice, Qt::Edges edges)
{
if (!inputDevice || !inputDevice->wl_seat() || !m_configured || m_dlayerShellWindow->isResizing())
return false;

auto *manager = TreeLandLayerShellExtensionManager::instance();
if (!manager->isActive())
return false;

// Qt::Edge and the protocol's xdg_toplevel-compatible enum differ.
uint32_t protocolEdges = 0;
if (edges.testFlag(Qt::TopEdge))
protocolEdges |= TreeLandLayerShellExtensionObject::resize_edge_top;
if (edges.testFlag(Qt::BottomEdge))
protocolEdges |= TreeLandLayerShellExtensionObject::resize_edge_bottom;
if (edges.testFlag(Qt::LeftEdge))
protocolEdges |= TreeLandLayerShellExtensionObject::resize_edge_left;
if (edges.testFlag(Qt::RightEdge))
protocolEdges |= TreeLandLayerShellExtensionObject::resize_edge_right;

if (!m_shellExtension) {
m_shellExtension.reset(new TreeLandLayerShellExtensionObject(
manager->get_layer_shell_extension_object(window()->wlSurface())));
connect(m_shellExtension.get(), &TreeLandLayerShellExtensionObject::resizingChanged, this, [this](bool resizing) {
if (resizing)
m_interactiveResize = true;
else
finishResize();
});
connect(m_shellExtension.get(), &TreeLandLayerShellExtensionObject::resizeRejected, this, [this](uint32_t error) {
qCWarning(layershellsurface) << "Layer surface resize rejected:" << error;
finishResize();
});
}

const QSize minSize = window()->windowMinimumSize();
const QSize maxSize = window()->windowMaximumSize();
m_shellExtension->begin_resize(inputDevice->wl_seat(), inputDevice->serial(), protocolEdges,
qMax(0, minSize.width()), qMax(0, minSize.height()),
maxSize.width() == QWINDOWSIZE_MAX ? 0 : qMax(0, maxSize.width()),
maxSize.height() == QWINDOWSIZE_MAX ? 0 : qMax(0, maxSize.height()));
// QWaylandWindow releases the client pointer grab after this returns.
// Keep clients in resize mode while waiting for acceptance or rejection.
m_dlayerShellWindow->setResizing(true);
return true;
}

void QWaylandLayerShellSurface::setWindowGeometry(const QRect &geometry)
{
// Qt also calls this while applying a compositor configure. Echoing that
// size back can replace a newer client request and start a resize loop.
if (m_applyingConfigure)
return;

calcAndSetRequestSize(geometry.size());
trySetAnchorsAndSize();
}
Expand Down
10 changes: 9 additions & 1 deletion frame/layershell/qwaylandlayershellsurface_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
#include "dsglobal.h"
#include "dlayershellwindow.h"

#include <QPointer>
#include <private/qwaylandwindow_p.h>
#include <qwayland-wlr-layer-shell-unstable-v1.h>
#include <QtWaylandClient/private/qwaylandshellsurface_p.h>

DS_BEGIN_NAMESPACE

class TreeLandLayerShellExtensionObject;

class QWaylandLayerShellSurface : public QtWaylandClient::QWaylandShellSurface, public QtWayland::zwlr_layer_surface_v1
{
Q_OBJECT
Expand All @@ -28,6 +31,7 @@ class QWaylandLayerShellSurface : public QtWaylandClient::QWaylandShellSurface,
void applyConfigure() override;
void setWindowGeometry(const QRect &geometry) override;
void attachPopup(QWaylandShellSurface *popup) override;
bool resize(QtWaylandClient::QWaylandInputDevice *inputDevice, Qt::Edges edges) override;

private:
void zwlr_layer_surface_v1_configure(uint32_t serial, uint32_t width, uint32_t height) override;
Expand All @@ -51,12 +55,16 @@ class QWaylandLayerShellSurface : public QtWaylandClient::QWaylandShellSurface,
void recreateWindow();
void flushRecreate();
void scheduleRecreate();
void finishResize();

DLayerShellWindow* m_dlayerShellWindow;
QPointer<DLayerShellWindow> m_dlayerShellWindow;
QScopedPointer<TreeLandLayerShellExtensionObject> m_shellExtension;
QSize m_pendingSize;
QSize m_requestSize;
wl_output *m_output = nullptr;
bool m_configured = false;
bool m_applyingConfigure = false;
bool m_interactiveResize = false;
bool m_commitScheduled = false;
bool m_recreateScheduled = false;
};
Expand Down
4 changes: 0 additions & 4 deletions panels/dock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ configure_file(environments.h.in environments.h @ONLY)
find_package(PkgConfig REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} COMPONENTS Core DBus Gui Qml WaylandCompositor Widgets WaylandClient)
find_package(DdeTrayLoader REQUIRED)
find_package(TreelandProtocols 0.9.0 REQUIRED)
pkg_check_modules(WaylandClient REQUIRED IMPORTED_TARGET wayland-client)

file(
Expand All @@ -26,8 +25,6 @@ file(
dockhelper.cpp
waylanddockhelper.h
waylanddockhelper.cpp
layershellextension.h
layershellextension.cpp
)

# Old dbus interface compatible
Expand Down Expand Up @@ -66,7 +63,6 @@ qt_generate_wayland_protocol_client_sources(dockpanel
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-foreign-toplevel-manager-unstable-v3.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-xwindow-control-unstable-v1.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-region-watch-unstable-v1.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-layer-shell-extension-unstable-v1.xml
)

target_link_libraries(dockpanel PRIVATE
Expand Down
Loading
Loading