Repository navigation
fix: preserve layer surface screen bindings #1920
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: master
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 |
|---|---|---|
|
|
@@ -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()) | ||
| { | ||
| // 背景窗口锁存创建时的 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())) { | ||
|
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 stays on old output When a background window's QWindow screen changes directly, or a moved non-background window becomes a background layer, Use the current QWindow screen for background targeting when it has changed directly, rather than retaining the construction-time Prompt for AI agentsIn `frame/layershell/x11dlayershellemulation.cpp` at line 212:
**Background stays on old output**
When a background window's QWindow screen changes directly, or a moved non-background window becomes a background layer, `targetScreen()` returns construction-time `m_screen`, so X11 geometry updates keep positioning the background on the old output, including through the bundled example's `Window.screen` path.
Use the current QWindow screen for background targeting when it has changed directly, rather than retaining the construction-time `m_screen`. |
||
| 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 · Non-background screen getter is stale
When a non-background layer has a saved screen from
setScreen()and its QWindow screen later changes directly,DLayerShellWindow::screen()returns cachedd->screeninstead of the current parent/QWindow screen, so callers see the old output.Make
screen()follow the current QWindow screen for non-background layers instead of returning the savedd->screen.Also at
frame/layershell/dlayershellwindow.cpp:185-186.Prompt for AI agents