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
24 changes: 18 additions & 6 deletions frame/layershell/dlayershellwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include "dlayershellwindow.h"
#include "qwaylandlayershellintegration_p.h"

#include <QMargins>

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <QtWaylandClient/private/qwaylandwindow_p.h>

Expand Down Expand Up @@ -261,7 +262,8 @@
s_map.insert(window, this);
window->create();
if (dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle())) {
ensureWaylandShellIntegration();
window->installEventFilter(this);
installWaylandShellIntegration();
}
#ifdef BUILD_WITH_X11
else if (dynamic_cast<QNativeInterface::Private::QXcbWindow *>(window->handle())) {
Expand All @@ -274,13 +276,23 @@
}
}

bool DLayerShellWindow::ensureWaylandShellIntegration()
bool DLayerShellWindow::eventFilter(QObject *watched, QEvent *event)
{
auto *window = d->parentWindow;
if (!window->handle())
window->create();
if (watched == d->parentWindow && event->type() == QEvent::PlatformSurface) {
auto *surfaceEvent = static_cast<QPlatformSurfaceEvent *>(event);
if (surfaceEvent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated
&& dynamic_cast<QtWaylandClient::QWaylandWindow *>(d->parentWindow->handle())) {
// Only bind the existing platform window; never create one from this event.
if (!installWaylandShellIntegration())
Comment on lines +284 to +286

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 · XEmbed positioning uses stale surface

When display reconnection recreates the Dock’s Wayland platform surface and an XEmbed window is subsequently moved, WaylandDockHelper caches the Dock’s wl_surface before reconnection, but this restoration path does not refresh that cache when a new platform surface is created. moveXEmbedWindow() only reacquires the surface when the cached pointer is null, so a later XEmbed move sends the destroyed surface to Wayland instead of positioning the window.

Refresh or clear the cached Dock surface when the platform surface is destroyed or created, before it can be used for XEmbed positioning.

Prompt for AI agents
In `frame/layershell/dlayershellwindow.cpp` at lines 284-286:

**XEmbed positioning uses stale surface**

When display reconnection recreates the Dock’s Wayland platform surface and an XEmbed window is subsequently moved, `WaylandDockHelper` caches the Dock’s `wl_surface` before reconnection, but this restoration path does not refresh that cache when a new platform surface is created. `moveXEmbedWindow()` only reacquires the surface when the cached pointer is null, so a later XEmbed move sends the destroyed surface to Wayland instead of positioning the window.

Refresh or clear the cached Dock surface when the platform surface is destroyed or created, before it can be used for XEmbed positioning.

qCWarning(layershellwindow) << "Failed to restore layer-shell integration for" << d->scope;
}
}
return QObject::eventFilter(watched, event);
}

auto *waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle());
bool DLayerShellWindow::installWaylandShellIntegration()
{
auto *waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(d->parentWindow->handle());
if (!waylandWindow)
return false;

Expand Down
4 changes: 2 additions & 2 deletions frame/layershell/dlayershellwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@
void setCloseOnDismissed(bool close);
bool closeOnDismissed() const;

bool ensureWaylandShellIntegration();

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 · Downstream consumers lose layer-shell API

When a downstream consumer calls DLayerShellWindow::ensureWaylandShellIntegration(), removing the public declaration makes downstream consumers fail to compile, and removing the exported symbol makes already-built consumers fail to load.

Retain the public declaration and exported implementation, or provide a compatible replacement.

Prompt for AI agents
In `frame/layershell/dlayershellwindow.h` at line 151:

**Downstream consumers lose layer-shell API**

When a downstream consumer calls `DLayerShellWindow::ensureWaylandShellIntegration()`, removing the public declaration makes downstream consumers fail to compile, and removing the exported symbol makes already-built consumers fail to load.

Retain the public declaration and exported implementation, or provide a compatible replacement.


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

Expand Down Expand Up @@ -178,7 +176,9 @@
friend class QWaylandLayerShellSurface;
void setResizing(bool resizing);

bool eventFilter(QObject *watched, QEvent *event) override;
bool installWaylandShellIntegration();
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
3 changes: 3 additions & 0 deletions panels/dock/dockhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,11 @@ void DockHelper::initAreas()
if (m_areas.contains(screen))
return;
m_areas.insert(screen, createArea(screen));
updateAllDockWakeArea();
});

connect(qApp, &QGuiApplication::primaryScreenChanged, this, &DockHelper::updateAllDockWakeArea);

connect(qApp, &QGuiApplication::screenRemoved, this, [this](QScreen *screen) {
if (!m_areas.contains(screen))
return;
Expand Down
4 changes: 1 addition & 3 deletions panels/dock/dockpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

#include "dockpanel.h"
#include "constants.h"
#include "dockadaptor.h"

Check warning on line 7 in panels/dock/dockpanel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dockadaptor.h" not found.
#include "docksettings.h"
#include "layershell/dlayershellwindow.h"
#include "panel.h"

Check warning on line 9 in panels/dock/dockpanel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "panel.h" not found.
#include "pluginfactory.h"

Check warning on line 10 in panels/dock/dockpanel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "pluginfactory.h" not found.
#include "waylanddockhelper.h"
#include "x11dockhelper.h"

Expand Down Expand Up @@ -512,8 +511,7 @@
auto *waylandScreen = dynamic_cast<QtWaylandClient::QWaylandScreen *>(primary->handle());
if (!waylandScreen || !waylandScreen->output())
return;
if (DS_NAMESPACE::DLayerShellWindow::get(win)->ensureWaylandShellIntegration())
win->show();
win->show();

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 · Dock appears as ordinary window

When layer-shell integration fails while updateDockScreen() is showing the Dock, win->show() runs despite the failed integration, so the Dock is displayed with an ordinary shell role instead of remaining hidden or a layer surface.

Only call win->show() when layer-shell integration succeeds.

Prompt for AI agents
In `panels/dock/dockpanel.cpp` at line 514:

**Dock appears as ordinary window**

When layer-shell integration fails while `updateDockScreen()` is showing the Dock, `win->show()` runs despite the failed integration, so the Dock is displayed with an ordinary shell role instead of remaining hidden or a layer surface.

Only call `win->show()` when layer-shell integration succeeds.

}

bool DockPanel::showInPrimary() const
Expand Down
1 change: 1 addition & 0 deletions panels/dock/waylanddockhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ WaylandDockHelper::WaylandDockHelper(DockPanel *panel)

connect(m_panel, &DockPanel::positionChanged, this, &WaylandDockHelper::updateRegionWatchPos);
connect(m_panel, &DockPanel::dockSizeChanged, this, &WaylandDockHelper::updateRegionWatchPos);
connect(m_panel, &DockPanel::dockScreenChanged, this, &WaylandDockHelper::updateRegionWatchPos);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Dock crashes without a screen

When the last display is removed while a SmartHide region watch is active and the Dock window has no screen, dockScreenChanged invokes updateRegionWatchPos(), which dereferences m_panel->window()->screen() (and its handle) without checking for null, crashing the Dock during reconnection.

Check that the window has a screen before dereferencing it, and defer updating the region watch until a screen is available.

Prompt for AI agents
In `panels/dock/waylanddockhelper.cpp` at line 150:

**Dock crashes without a screen**

When the last display is removed while a SmartHide region watch is active and the Dock window has no screen, `dockScreenChanged` invokes `updateRegionWatchPos()`, which dereferences `m_panel->window()->screen()` (and its handle) without checking for null, crashing the Dock during reconnection.

Check that the window has a screen before dereferencing it, and defer updating the region watch until a screen is available.

connect(m_panel, &DockPanel::rootObjectChanged, this, &WaylandDockHelper::updateRegionWatchPos);

auto ensureRegionWatch = [this]() {
Expand Down
Loading