From 15b98767a35663b6242037b779314e2a6668dfe9 Mon Sep 17 00:00:00 2001 From: xujin Date: Mon, 30 Nov 2026 16:49:04 +0800 Subject: [PATCH] fix: restore X11 layer screen switching compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Restrict output latching to background surfaces to preserve desktop placement when rearranging extended screens. 2. Restore QWindow::screen() tracking for other layers to fix dock freezes and incorrect screen selection outlines. 3. Update the latched output before switching the window screen and remove redundant notification center rebinding. Influence: 1. Rearrange extended screens and verify both desktop backgrounds. 2. Switch primary screens with the dock following the primary screen or mouse. 3. Select HDMI and eDP in display settings and verify the matching outlines. 4. Verify notification center, notification bubbles and OSD after switching. fix: 修复多屏切换卡死及屏幕选中描边错位 1. 将输出锁存限定为背景层,保留扩展屏重排时的桌面背景归属。 2. 其他层恢复跟随 QWindow::screen(),修复任务栏卡死及选屏描边错屏, 无需修改控制中心等现有调用方。 3. 切换窗口屏幕前同步锁存输出,移除通知中心多余的屏幕重绑调用。 Influence: 1. 扩展模式下调整屏幕排列,确认主副屏背景正常显示。 2. 分别设置任务栏跟随主屏、跟随鼠标,切换主屏后确认无卡死。 3. 点击显示设置中的 HDMI、eDP 缩略图,确认描边对应正确屏幕。 4. 切屏后确认通知中心、通知气泡及 OSD 的位置和交互正常。 Log: 修复多屏切换导致任务栏卡死及屏幕选中描边错位,保留副屏背景重排修复。 PMS: TASK-384487, TASK-384649 --- frame/layershell/dlayershellwindow.cpp | 7 ++++--- frame/layershell/dlayershellwindow.h | 11 ++++------ frame/layershell/x11dlayershellemulation.cpp | 21 +++++++------------- frame/layershell/x11dlayershellemulation.h | 2 +- panels/dock/dockpanel.cpp | 7 +++---- panels/notification/center/package/main.qml | 7 +------ 6 files changed, 20 insertions(+), 35 deletions(-) diff --git a/frame/layershell/dlayershellwindow.cpp b/frame/layershell/dlayershellwindow.cpp index d1c5a9b49..f5100c194 100644 --- a/frame/layershell/dlayershellwindow.cpp +++ b/frame/layershell/dlayershellwindow.cpp @@ -167,13 +167,14 @@ void DLayerShellWindow::setScreen(QScreen *screen) d->screen = screen; + // 先同步背景层的锁存屏幕,避免切屏时的几何回调仍按旧屏定位。 + Q_EMIT screenChanged(screen); + // Wayland 下由 QWindow::screen() 决定 zwlr_layer_surface 绑定的 output, - // X11 下模拟层会读取 d->screen 锁存,两边都同步一次。 + // X11 背景层读取锁存输出,其他层继续跟随 QWindow::screen()。 if (d->parentWindow && screen && d->parentWindow->screen() != screen) { d->parentWindow->setScreen(screen); } - - Q_EMIT screenChanged(screen); } QScreen *DLayerShellWindow::screen() const diff --git a/frame/layershell/dlayershellwindow.h b/frame/layershell/dlayershellwindow.h index 6ffc37145..17fa42875 100644 --- a/frame/layershell/dlayershellwindow.h +++ b/frame/layershell/dlayershellwindow.h @@ -117,13 +117,10 @@ class DS_SHARE DLayerShellWindow : public QObject /** * Binds the layer surface to @p screen. * - * On Wayland this simply forwards to QWindow::setScreen() before the - * zwlr_layer_surface is created. On X11 the emulation *latches* the screen: - * the surface keeps belonging to it and its geometry is always computed - * from that screen, no matter where the window is currently placed. - * X11 clients that need to move an existing surface to another screen must - * call this, a plain QWindow::setScreen() is no longer enough once the - * emulation has been created. + * On Wayland this forwards to QWindow::setScreen(). On X11 only background + * surfaces latch their output to survive screen rearrangements; use this + * method to explicitly move an existing background surface. Other layers + * continue to follow QWindow::screen(), including changes made from QML. */ Q_INVOKABLE void setScreen(QScreen *screen); QScreen *screen() const; diff --git a/frame/layershell/x11dlayershellemulation.cpp b/frame/layershell/x11dlayershellemulation.cpp index 364845d21..aefc2a69a 100644 --- a/frame/layershell/x11dlayershellemulation.cpp +++ b/frame/layershell/x11dlayershellemulation.cpp @@ -29,10 +29,8 @@ LayerShellEmulation::LayerShellEmulation(QWindow* window, QObject *parent) , m_dlayerShellWindow(DLayerShellWindow::get(m_window)) , m_screen(m_dlayerShellWindow->screen()) { - // 创建时锁存 output。客户端(如桌面)在创建 layer surface 之前已经 - // QWindow::setScreen(),此处取到的就是它声明的屏。此后 QWindow::screen() - // 会随窗口几何被 Qt 自动推导,导致"窗口压在哪块屏上就属于哪块屏"的 - // 正反馈,所以不能再拿它当归属依据。 + // 背景窗口锁存创建时的 output,避免屏幕重排时随几何漂移。 + // 其他层仍使用 QWindow::screen(),保留现有客户端主动换屏的语义。 qCInfo(layershell) << "layer surface bound to screen:" << (m_screen ? m_screen->name() : QStringLiteral("")) << "winId:" << m_window->winId(); onLayerChanged(); @@ -74,8 +72,7 @@ LayerShellEmulation::LayerShellEmulation(QWindow* window, QObject *parent) m_exclusionZoneChangedTimer.start(); }); - // 只有显式重绑(DLayerShellWindow::setScreen)才允许改变归属屏, - // 客户端靠它把已有 surface 搬到另一块屏(如 dock 切换主屏)。 + // 显式重绑允许背景窗口迁移到另一块输出,其他层仍跟随窗口屏幕。 connect(m_dlayerShellWindow, &DLayerShellWindow::screenChanged, this, [this](QScreen *newScreen) { m_screen = newScreen ? newScreen : m_window->screen(); qCInfo(layershell) << "layer surface rebound to screen:" << (m_screen ? m_screen->name() : QStringLiteral("")); @@ -86,8 +83,7 @@ LayerShellEmulation::LayerShellEmulation(QWindow* window, QObject *parent) // 锁存的 output 被拔掉时退回窗口当前所在屏,避免用空指针算几何。 connect(qApp, &QGuiApplication::screenRemoved, this, [this](QScreen *removed) { if (!m_screen || m_screen == removed) { - // screenRemoved can be emitted before Qt has moved the window off - // the removed screen. Select only from the remaining outputs. + // Qt 可能尚未迁走窗口,只从仍然存在的输出中选择回退屏幕。 const auto screens = qApp->screens(); QScreen *fallback = nullptr; const auto primaryScreen = qApp->primaryScreen(); @@ -157,10 +153,10 @@ void LayerShellEmulation::onLayerChanged() QScreen *LayerShellEmulation::targetScreen() const { - if (m_screen && qApp->screens().contains(m_screen.data())) { + if (m_dlayerShellWindow->layer() == DLayerShellWindow::LayerBackground + && m_screen && qApp->screens().contains(m_screen.data())) { return m_screen.data(); } - // 尚未锁存或锁存的 output 已消失:仅使用仍然有效的窗口屏幕。 auto *windowScreen = m_window ? m_window->screen() : nullptr; return windowScreen && qApp->screens().contains(windowScreen) ? windowScreen : nullptr; } @@ -168,10 +164,7 @@ QScreen *LayerShellEmulation::targetScreen() const void LayerShellEmulation::onPositionChanged() { auto anchors = m_dlayerShellWindow->anchors(); - // 注意:这里必须用锁存的 output,不能用 m_window->screen()。 - // QWindow::screen() 是 Qt 依据窗口几何推导出来的,排列变化后窗口一旦 - // 落进相邻屏就会被判成"属于那块屏",再把几何铺满那块屏,形成 - // "错位 → 判成邻屏 → 更错位" 的正反馈,副屏桌面会永久跑到主屏上。 + // 只有背景层固定归属输出;面板、通知、OSD 和描边窗口允许通过 Window.screen 换屏。 auto screen = targetScreen(); if (!screen) { return; diff --git a/frame/layershell/x11dlayershellemulation.h b/frame/layershell/x11dlayershellemulation.h index f0b392de5..f24b86c96 100644 --- a/frame/layershell/x11dlayershellemulation.h +++ b/frame/layershell/x11dlayershellemulation.h @@ -34,7 +34,7 @@ private slots: // void onKeyboardInteractivityChanged(); private: - // 该 surface 所属的 output。创建时锁存,之后不再随窗口当前所在屏漂移。 + // 背景层使用锁存输出,其他层兼容 QWindow::screen() 的动态选屏。 QScreen *targetScreen() const; QWindow* m_window; diff --git a/panels/dock/dockpanel.cpp b/panels/dock/dockpanel.cpp index a5fc4f965..9a3685bd6 100644 --- a/panels/dock/dockpanel.cpp +++ b/panels/dock/dockpanel.cpp @@ -7,6 +7,7 @@ #include "dockadaptor.h" #include "docksettings.h" #include "layershellextension.h" +#include "layershell/dlayershellwindow.h" #include "panel.h" #include "pluginfactory.h" #include "waylanddockhelper.h" @@ -24,8 +25,6 @@ #include #include -#include "layershell/dlayershellwindow.h" - #include #include @@ -111,7 +110,7 @@ bool DockPanel::init() if (m_dockScreen != window()->screen() && qApp->screens().contains( m_dockScreen)) { qWarning() << "m_dockScreen" << m_dockScreen << m_dockScreen->name() << "window()->screen()" << window()->screen() << window()->screen()->name(); QTimer::singleShot(10, this, [this](){ - DS_NAMESPACE::DLayerShellWindow::get(window())->setScreen(m_dockScreen); + ds::DLayerShellWindow::get(window())->setScreen(m_dockScreen); onWindowGeometryChanged(); }); } else { @@ -534,7 +533,7 @@ void DockPanel::setDockScreen(QScreen *screen) return; m_dockScreen = screen; if (window()) - DS_NAMESPACE::DLayerShellWindow::get(window())->setScreen(m_dockScreen); + ds::DLayerShellWindow::get(window())->setScreen(m_dockScreen); Q_EMIT dockScreenChanged(m_dockScreen); Q_EMIT screenNameChanged(); } diff --git a/panels/notification/center/package/main.qml b/panels/notification/center/package/main.qml index 939ef6de6..9b63bfbac 100644 --- a/panels/notification/center/package/main.qml +++ b/panels/notification/center/package/main.qml @@ -113,13 +113,10 @@ Window { DWindow.enableBlurWindow: true DWindow.borderColor: DTK.themeType === ApplicationHelper.DarkType ? Qt.rgba(0, 0, 0, 0.8) : Qt.rgba(0, 0, 0, 0.06) - // 修复:通知中心屏幕跟随任务栏屏幕,而不是硬编码为第一个屏幕 + // 通知中心跟随任务栏屏幕,非背景层由框架兼容 Window.screen 的动态选屏。 screen: getDockScreen() - // TODO `Qt.application.screens[0]` maybe invalid, why screen is changed. onScreenChanged: { - // 修复:屏幕变化时重新获取dock所在的屏幕 root.screen = Qt.binding(function () { return getDockScreen() }) - root.DLayerShellWindow.setScreen(root.screen) } onVisibleChanged: function (v) { @@ -163,10 +160,8 @@ Window { function onRequestClosePopup() { Panel.close() } - // 修复:监听dock屏幕变化,同步更新通知中心屏幕 function onScreenNameChanged() { root.screen = getDockScreen() - root.DLayerShellWindow.setScreen(root.screen) } }