From 32aca948135abde7f4d42170ad3c9ccc7ea12bd9 Mon Sep 17 00:00:00 2001 From: liujiangtao Date: Fri, 27 Nov 2026 10:53:15 +0800 Subject: [PATCH] fix: preserve Dock behavior after display reconnection [cherry-pick] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Restore layer-shell integration when platform windows are created. 2. Refresh edge wakeup areas when screens are added or primary changes. 3. Rebind overlap monitoring when the Dock changes screens. Influence: 1. Reconnect the only display and verify the Dock remains a layer surface. 2. In always-hidden mode, reconnect and reveal the Dock from the screen edge. 3. In smart-hide mode, reconnect with a maximized window and verify hiding. fix: 修复显示器重连后任务栏角色与隐藏行为异常 1. 平台窗口创建时自动恢复 layer-shell 集成,保留构造阶段补绑定。 2. 屏幕加入或主屏切换时更新边缘唤醒区域。 3. 任务栏切换屏幕时重新注册遮挡检测区域。 Influence: 1. 拔插唯一显示器,确认任务栏保持 layer-shell 角色。 2. 一直隐藏模式下重连显示器,确认可从屏幕边缘唤出任务栏。 3. 智能隐藏模式下保持窗口最大化并重连,确认任务栏恢复隐藏。 Log: Restore Dock window roles and hiding behavior after display reconnects. Log: 修复显示器重连后任务栏变成普通窗口、无法唤出或不再隐藏的问题。 Issue: None (cherry picked from commit 20dd983e65833bab93f023a0d38215658d6a8239) --- frame/layershell/dlayershellwindow.cpp | 24 ++++++++++++++++++------ frame/layershell/dlayershellwindow.h | 4 ++-- panels/dock/dockhelper.cpp | 3 +++ panels/dock/dockpanel.cpp | 4 +--- panels/dock/waylanddockhelper.cpp | 1 + 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/frame/layershell/dlayershellwindow.cpp b/frame/layershell/dlayershellwindow.cpp index 7261b1eff..ba6833eb7 100644 --- a/frame/layershell/dlayershellwindow.cpp +++ b/frame/layershell/dlayershellwindow.cpp @@ -6,6 +6,7 @@ #include "qwaylandlayershellintegration_p.h" #include +#include #include #include #include @@ -261,7 +262,8 @@ DLayerShellWindow::DLayerShellWindow(QWindow* window) s_map.insert(window, this); window->create(); if (dynamic_cast(window->handle())) { - ensureWaylandShellIntegration(); + window->installEventFilter(this); + installWaylandShellIntegration(); } #ifdef BUILD_WITH_X11 else if (dynamic_cast(window->handle())) { @@ -274,13 +276,23 @@ DLayerShellWindow::DLayerShellWindow(QWindow* window) } } -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(event); + if (surfaceEvent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated + && dynamic_cast(d->parentWindow->handle())) { + // Only bind the existing platform window; never create one from this event. + if (!installWaylandShellIntegration()) + qCWarning(layershellwindow) << "Failed to restore layer-shell integration for" << d->scope; + } + } + return QObject::eventFilter(watched, event); +} - auto *waylandWindow = dynamic_cast(window->handle()); +bool DLayerShellWindow::installWaylandShellIntegration() +{ + auto *waylandWindow = dynamic_cast(d->parentWindow->handle()); if (!waylandWindow) return false; diff --git a/frame/layershell/dlayershellwindow.h b/frame/layershell/dlayershellwindow.h index 5579558a7..12217adbd 100644 --- a/frame/layershell/dlayershellwindow.h +++ b/frame/layershell/dlayershellwindow.h @@ -148,8 +148,6 @@ class DS_SHARE DLayerShellWindow : public QObject void setCloseOnDismissed(bool close); bool closeOnDismissed() const; - bool ensureWaylandShellIntegration(); - /** Whether a system resize is pending or active on this layer surface. */ bool isResizing() const; @@ -178,6 +176,8 @@ class DS_SHARE DLayerShellWindow : public QObject friend class QWaylandLayerShellSurface; void setResizing(bool resizing); + bool eventFilter(QObject *watched, QEvent *event) override; + bool installWaylandShellIntegration(); DLayerShellWindow(QWindow* window); QScopedPointer d; }; diff --git a/panels/dock/dockhelper.cpp b/panels/dock/dockhelper.cpp index e3767bcb1..71e11be0d 100644 --- a/panels/dock/dockhelper.cpp +++ b/panels/dock/dockhelper.cpp @@ -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; diff --git a/panels/dock/dockpanel.cpp b/panels/dock/dockpanel.cpp index 3defb3fec..a409a456f 100644 --- a/panels/dock/dockpanel.cpp +++ b/panels/dock/dockpanel.cpp @@ -6,7 +6,6 @@ #include "constants.h" #include "dockadaptor.h" #include "docksettings.h" -#include "layershell/dlayershellwindow.h" #include "panel.h" #include "pluginfactory.h" #include "waylanddockhelper.h" @@ -512,8 +511,7 @@ void DockPanel::updateDockScreen() auto *waylandScreen = dynamic_cast(primary->handle()); if (!waylandScreen || !waylandScreen->output()) return; - if (DS_NAMESPACE::DLayerShellWindow::get(win)->ensureWaylandShellIntegration()) - win->show(); + win->show(); } bool DockPanel::showInPrimary() const diff --git a/panels/dock/waylanddockhelper.cpp b/panels/dock/waylanddockhelper.cpp index 8164ac94b..08cb86f52 100644 --- a/panels/dock/waylanddockhelper.cpp +++ b/panels/dock/waylanddockhelper.cpp @@ -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); connect(m_panel, &DockPanel::rootObjectChanged, this, &WaylandDockHelper::updateRegionWatchPos); auto ensureRegionWatch = [this]() {