From e024e2fa6feeacf96531090752e5701bf6565346 Mon Sep 17 00:00:00 2001 From: Robertkill Date: Fri, 27 Nov 2026 14:57:17 +0800 Subject: [PATCH] fix: keep X11 layer shell windows on their screen [cherry-pick] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. When margins push an X11 layer shell window completely off its screen, Qt reassigns it to the neighbouring screen and positioning re-enters with the new origin, ping-ponging between screens forever and freezing dde-shell (e.g. moving the dock to the left on dual screens with 125% scaling). 2. After the final geometry is computed (including opposite anchors), move an axis back only when the window center leaves the current screen on that axis, matching how Qt picks the window's screen; a window larger than the screen is centered on it. Intentional partial overlap such as the full-height notification bubble avoiding the dock is preserved. Influence: 1. On dual screens with scaling, switch the dock between bottom, left, top and right from the context menu; dde-shell must not freeze 2. Open and close the windowed launcher on primary and secondary screens 3. With the dock at the bottom or right, send a notification and verify it does not overlap the dock fix: X11 下 layer shell 窗口保持在所在屏幕 1. 边距把 X11 layer shell 窗口完全推出所在屏幕时,Qt 会把窗口改归相邻屏幕, 定位逻辑以新屏幕原点再次进入,在两块屏幕间反复切换,导致 dde-shell 卡死 (如双屏 125% 缩放下将任务栏切到左侧) 2. 在最终几何(含两侧锚定)计算完成后,仅当窗口中心在某一轴上离开当前屏幕时 才把该轴拉回,与 Qt 按中心点判定所属屏幕一致;比屏幕大的窗口居中于当前屏幕。 保留通知气泡等有意的部分越界以避让任务栏 Influence: 1. 双屏缩放环境下通过右键菜单在底部、左侧、顶部、右侧间切换任务栏位置,dde-shell 不卡死 2. 在主副屏打开、关闭窗口模式启动器 3. 任务栏位于底部或右侧时发送通知,确认通知不与任务栏重叠 Log: 修复双屏缩放下切换任务栏位置导致界面卡死的问题 PMS: BUG-384699 (cherry picked from commit a4bc0f0512fa2fd247f634bfcc90165beb95def1) --- frame/layershell/x11dlayershellemulation.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/frame/layershell/x11dlayershellemulation.cpp b/frame/layershell/x11dlayershellemulation.cpp index b38bdfe7f..6b0a8f3d6 100644 --- a/frame/layershell/x11dlayershellemulation.cpp +++ b/frame/layershell/x11dlayershellemulation.cpp @@ -223,6 +223,22 @@ void LayerShellEmulation::onPositionChanged() rect.setHeight(screen->geometry().height() - m_dlayerShellWindow->topMargin() - m_dlayerShellWindow->bottomMargin()); } + // Qt moves a window to the screen holding its center, re-entering here with that screen's origin forever; + // keep the center on this screen but preserve intentional partial overlap (e.g. notifications avoiding the dock). + const auto keepOnScreen = [](int pos, int size, int screenStart, int screenSize) { + if (size > screenSize) { + return screenStart + (screenSize - size) / 2; + } + return qBound(screenStart, pos, screenStart + screenSize - size); + }; + const QPoint center = rect.center(); + if (center.x() < screenRect.left() || center.x() > screenRect.right()) { + rect.moveLeft(keepOnScreen(rect.left(), rect.width(), screenRect.left(), screenRect.width())); + } + if (center.y() < screenRect.top() || center.y() > screenRect.bottom()) { + rect.moveTop(keepOnScreen(rect.top(), rect.height(), screenRect.top(), screenRect.height())); + } + if (m_window->geometry() != rect) { m_window->setGeometry(rect); }