Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions frame/layershell/dlayershellwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions frame/layershell/dlayershellwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment thread
xujin177 marked this conversation as resolved.
Resolved
*/
Q_INVOKABLE void setScreen(QScreen *screen);
QScreen *screen() const;
Expand Down
21 changes: 7 additions & 14 deletions frame/layershell/x11dlayershellemulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("<null>"))
<< "winId:" << m_window->winId();
onLayerChanged();
Expand Down Expand Up @@ -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("<null>"));
Expand All @@ -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();
Expand Down Expand Up @@ -157,21 +153,18 @@ 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())) {
Comment thread
xujin177 marked this conversation as resolved.
Resolved
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
Comment thread
xujin177 marked this conversation as resolved.
Resolved
return m_screen.data();
}
// 尚未锁存或锁存的 output 已消失:仅使用仍然有效的窗口屏幕。
auto *windowScreen = m_window ? m_window->screen() : nullptr;
return windowScreen && qApp->screens().contains(windowScreen) ? windowScreen : nullptr;
}

void LayerShellEmulation::onPositionChanged()
{
auto anchors = m_dlayerShellWindow->anchors();
// 注意:这里必须用锁存的 output,不能用 m_window->screen()。
// QWindow::screen() 是 Qt 依据窗口几何推导出来的,排列变化后窗口一旦
// 落进相邻屏就会被判成"属于那块屏",再把几何铺满那块屏,形成
// "错位 → 判成邻屏 → 更错位" 的正反馈,副屏桌面会永久跑到主屏上。
// 只有背景层固定归属输出;面板、通知、OSD 和描边窗口允许通过 Window.screen 换屏。
auto screen = targetScreen();
if (!screen) {
return;
Expand Down
2 changes: 1 addition & 1 deletion frame/layershell/x11dlayershellemulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private slots:
// void onKeyboardInteractivityChanged();

private:
// 该 surface 所属的 output。创建时锁存,之后不再随窗口当前所在屏漂移。
// 背景层使用锁存输出,其他层兼容 QWindow::screen() 的动态选屏。
QScreen *targetScreen() const;

QWindow* m_window;
Expand Down
7 changes: 3 additions & 4 deletions panels/dock/dockpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

#include "dockpanel.h"
#include "constants.h"
#include "dockadaptor.h"

Check warning on line 7 in panels/dock/dockpanel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dockadaptor.h" not found.
#include "docksettings.h"
#include "layershellextension.h"
#include "layershell/dlayershellwindow.h"

Check warning on line 10 in panels/dock/dockpanel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "layershell/dlayershellwindow.h" not found.
#include "panel.h"

Check warning on line 11 in panels/dock/dockpanel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "panel.h" not found.
#include "pluginfactory.h"

Check warning on line 12 in panels/dock/dockpanel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "pluginfactory.h" not found.
#include "waylanddockhelper.h"
#include "x11dockhelper.h"

Expand All @@ -21,14 +22,12 @@
#include <QGuiApplication>
#include <QLoggingCategory>
#include <QProcess>
#include <QQuickItem>

Check warning on line 25 in panels/dock/dockpanel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QQuickItem> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QQuickWindow>

Check warning on line 26 in panels/dock/dockpanel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QQuickWindow> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include "layershell/dlayershellwindow.h"

#include <wayland/xdgactivation.h>

Check warning on line 28 in panels/dock/dockpanel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <wayland/xdgactivation.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QtWaylandClient/private/qwaylanddisplay_p.h>

Check warning on line 30 in panels/dock/dockpanel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtWaylandClient/private/qwaylanddisplay_p.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QtWaylandClient/private/qwaylandinputdevice_p.h>
#include <QtWaylandClient/private/qwaylandwindow_p.h>

Expand Down Expand Up @@ -111,7 +110,7 @@
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 {
Expand Down Expand Up @@ -534,7 +533,7 @@
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();
}
Expand Down
7 changes: 1 addition & 6 deletions panels/notification/center/package/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -163,10 +160,8 @@ Window {
function onRequestClosePopup() {
Panel.close()
}
// 修复:监听dock屏幕变化,同步更新通知中心屏幕
function onScreenNameChanged() {
root.screen = getDockScreen()
root.DLayerShellWindow.setScreen(root.screen)
}
}

Expand Down
Loading