Repository navigation
fix: preserve layer surface screen bindings #1921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop/2500u3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,8 @@ class DLayerShellWindowPrivate | |
| } | ||
|
|
||
| QWindow* parentWindow; | ||
| // 绑定(锁存)的 output。为空表示尚未显式绑定,此时沿用 QWindow::screen()。 | ||
| QPointer<QScreen> screen; | ||
| QString scope; | ||
| DLayerShellWindow::Anchors anchors = {DLayerShellWindow::AnchorNone}; | ||
| int32_t exclusionZone = 0; | ||
|
|
@@ -159,6 +161,32 @@ void DLayerShellWindow::setScreenConfiguration(DLayerShellWindow::ScreenConfigur | |
| } | ||
| } | ||
|
|
||
| void DLayerShellWindow::setScreen(QScreen *screen) | ||
| { | ||
| if (d->screen == screen && (!d->parentWindow || d->parentWindow->screen() == screen)) { | ||
| return; | ||
| } | ||
|
|
||
| d->screen = screen; | ||
|
|
||
| // 先同步背景层的锁存屏幕,避免切屏时的几何回调仍按旧屏定位。 | ||
| Q_EMIT screenChanged(screen); | ||
|
|
||
| // Wayland 下由 QWindow::screen() 决定 zwlr_layer_surface 绑定的 output, | ||
| // X11 背景层读取锁存输出,其他层继续跟随 QWindow::screen()。 | ||
| if (d->parentWindow && screen && d->parentWindow->screen() != screen) { | ||
| d->parentWindow->setScreen(screen); | ||
| } | ||
| } | ||
|
|
||
| QScreen *DLayerShellWindow::screen() const | ||
| { | ||
| if (d->screen) { | ||
| return d->screen.data(); | ||
| } | ||
|
Comment on lines
+184
to
+186
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Screen getter reports the old output When a non-background layer has been explicitly bound and its Use the current window screen for non-background layers and retain the stored screen only for background layers. Also at Prompt for AI agentsIn `frame/layershell/dlayershellwindow.cpp` at lines 184-186:
**Screen getter reports the old output**
When a non-background layer has been explicitly bound and its `QWindow::screen()` changes independently, `DLayerShellWindow::screen()` returns the stored `d->screen` instead of the window's current screen, so callers see the old output and the background emulator can latch that stale screen.
Use the current window screen for non-background layers and retain the stored screen only for background layers.
Also at `frame/layershell/dlayershellwindow.cpp:170`. |
||
| return d->parentWindow ? d->parentWindow->screen() : nullptr; | ||
| } | ||
|
|
||
| void DLayerShellWindow::setPreferredWidth(int width) | ||
| { | ||
| if (width != d->preferredWidth) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,12 @@ LayerShellEmulation::LayerShellEmulation(QWindow* window, QObject *parent) | |
| : QObject(parent) | ||
| , m_window(window) | ||
| , m_dlayerShellWindow(DLayerShellWindow::get(m_window)) | ||
| , m_screen(m_dlayerShellWindow->screen()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Background windows stay on the wrong output When a background window's screen is changed explicitly, or a non-background window changes screens before becoming a background layer, Refresh Also at Prompt for AI agentsIn `frame/layershell/x11dlayershellemulation.cpp` at line 79:
**Background windows stay on the wrong output**
When a background window's screen is changed explicitly, or a non-background window changes screens before becoming a background layer, `targetScreen()` keeps using the screen captured when the emulation was constructed because `m_screen` is not refreshed on screen or layer changes, so the background window is positioned on the previous output.
Refresh `m_screen` when the window's screen changes and when it becomes a background layer.
Also at `frame/layershell/x11dlayershellemulation.cpp:212-213`. |
||
| { | ||
| // 背景窗口锁存创建时的 output,避免屏幕重排时随几何漂移。 | ||
| // 其他层仍使用 QWindow::screen(),保留现有客户端主动换屏的语义。 | ||
| qCInfo(layershell) << "layer surface bound to screen:" << (m_screen ? m_screen->name() : QStringLiteral("<null>")) | ||
| << "winId:" << m_window->winId(); | ||
| onLayerChanged(); | ||
| connect(m_dlayerShellWindow, &DLayerShellWindow::layerChanged, this, &LayerShellEmulation::onLayerChanged); | ||
|
|
||
|
|
@@ -116,6 +121,34 @@ LayerShellEmulation::LayerShellEmulation(QWindow* window, QObject *parent) | |
| m_exclusionZoneChangedTimer.start(); | ||
| }); | ||
|
|
||
| // 显式重绑允许背景窗口迁移到另一块输出,其他层仍跟随窗口屏幕。 | ||
| 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("<null>")); | ||
| onPositionChanged(); | ||
| m_exclusionZoneChangedTimer.start(); | ||
| }); | ||
|
|
||
| // 锁存的 output 被拔掉时退回窗口当前所在屏,避免用空指针算几何。 | ||
| connect(qApp, &QGuiApplication::screenRemoved, this, [this](QScreen *removed) { | ||
| if (!m_screen || m_screen == removed) { | ||
| // Qt 可能尚未迁走窗口,只从仍然存在的输出中选择回退屏幕。 | ||
| const auto screens = qApp->screens(); | ||
| QScreen *fallback = nullptr; | ||
| const auto primaryScreen = qApp->primaryScreen(); | ||
| for (auto *screen : screens) { | ||
| if (screen == removed) | ||
| continue; | ||
| if (!fallback || screen == primaryScreen) | ||
| fallback = screen; | ||
| if (screen == primaryScreen) | ||
| break; | ||
| } | ||
| m_screen = fallback; | ||
| onPositionChanged(); | ||
| } | ||
| }); | ||
|
|
||
| connect(qApp, &QGuiApplication::screenRemoved, &m_exclusionZoneChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start)); | ||
|
|
||
| onScopeChanged(); | ||
|
|
@@ -173,10 +206,21 @@ void LayerShellEmulation::onLayerChanged() | |
| } | ||
| } | ||
|
|
||
| QScreen *LayerShellEmulation::targetScreen() const | ||
| { | ||
| if (m_dlayerShellWindow->layer() == DLayerShellWindow::LayerBackground | ||
| && m_screen && qApp->screens().contains(m_screen.data())) { | ||
| return m_screen.data(); | ||
| } | ||
| auto *windowScreen = m_window ? m_window->screen() : nullptr; | ||
| return windowScreen && qApp->screens().contains(windowScreen) ? windowScreen : nullptr; | ||
| } | ||
|
|
||
| void LayerShellEmulation::onPositionChanged() | ||
| { | ||
| auto anchors = m_dlayerShellWindow->anchors(); | ||
| auto screen = m_window->screen(); | ||
| // 只有背景层固定归属输出;面板、通知、OSD 和描边窗口允许通过 Window.screen 换屏。 | ||
| auto screen = targetScreen(); | ||
| if (!screen) { | ||
| return; | ||
| } | ||
|
|
@@ -260,7 +304,10 @@ void LayerShellEmulation::onExclusionZoneChanged() | |
| xcb_ewmh_wm_strut_partial_t strut_partial; | ||
| memset(&strut_partial, 0, sizeof(xcb_ewmh_wm_strut_partial_t)); | ||
| auto anchors = m_dlayerShellWindow->anchors(); | ||
| QScreen *currentScreen = m_window->screen(); | ||
| QScreen *currentScreen = targetScreen(); | ||
| if (!currentScreen) { | ||
| return; | ||
| } | ||
| if ((anchors == DLayerShellWindow::AnchorLeft) || (anchors ^ DLayerShellWindow::AnchorLeft) == (DLayerShellWindow::AnchorTop | DLayerShellWindow::AnchorBottom)) { | ||
| // 计算独占区域:屏幕X坐标 + 任务栏物理宽度 | ||
| // 注意:QScreen::geometry().x() 已经是设备无关像素,不需要缩放 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · Compositor-selected output ignores rebinding
When a caller uses
setScreen()while the layer is configured withScreenFromCompositor,setScreen()changes onlyQWindow::screen(), but a layer configured withScreenFromCompositorcreates its Wayland surface with a null output and does not listen for window screen changes. Calling the new binding API in that configuration therefore leaves the layer surface compositor-selected instead of bound to the requested screen.Make explicit
setScreen()switch the layer toScreenFromQWindow, or reject/document rebinding as unsupported in compositor-selected mode.Prompt for AI agents