Skip to content

Commit a31434b

Browse files
committed
fix: Changing screen layout might make dock exclusion zone incorrect
Changing screen layout may not change the geometry of the screen binded to dock. (For example, the screen stay on top or left without resolution changed) So, connect slot to all screens instead. pms: BUG-292677 Log: Changing screen layout might make dock exclusion zone incorrect
1 parent f1148d3 commit a31434b

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

frame/layershell/x11dlayershellemulation.cpp

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,37 @@ LayerShellEmulation::LayerShellEmulation(QWindow* window, QObject *parent)
3030
connect(m_dlayerShellWindow, &DLayerShellWindow::layerChanged, this, &LayerShellEmulation::onLayerChanged);
3131

3232
onPositionChanged();
33-
connect(m_dlayerShellWindow, &DLayerShellWindow::anchorsChanged, this, &LayerShellEmulation::onPositionChanged);
34-
connect(m_dlayerShellWindow, &DLayerShellWindow::marginsChanged, this, &LayerShellEmulation::onPositionChanged);
33+
m_positionChangedTimer.setSingleShot(true);
34+
m_positionChangedTimer.setInterval(100);
35+
connect(&m_positionChangedTimer, &QTimer::timeout, this, &LayerShellEmulation::onPositionChanged);
36+
connect(m_dlayerShellWindow, &DLayerShellWindow::anchorsChanged, &m_positionChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
37+
connect(m_dlayerShellWindow, &DLayerShellWindow::marginsChanged, &m_positionChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
3538

3639
onExclusionZoneChanged();
37-
connect(m_dlayerShellWindow, &DLayerShellWindow::anchorsChanged, this, &LayerShellEmulation::onExclusionZoneChanged);
38-
connect(m_dlayerShellWindow, &DLayerShellWindow::exclusionZoneChanged, this, &LayerShellEmulation::onExclusionZoneChanged);
40+
m_exclusionZoneChangedTimer.setSingleShot(true);
41+
m_exclusionZoneChangedTimer.setInterval(100);
42+
connect(&m_exclusionZoneChangedTimer, &QTimer::timeout, this, &LayerShellEmulation::onExclusionZoneChanged);
43+
connect(m_dlayerShellWindow, &DLayerShellWindow::anchorsChanged, &m_exclusionZoneChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
44+
connect(m_dlayerShellWindow, &DLayerShellWindow::exclusionZoneChanged, &m_exclusionZoneChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
3945

4046
// qml height or width may update later, need to update anchor postion and exclusion zone
41-
connect(m_window, &QWindow::widthChanged, this, &LayerShellEmulation::onExclusionZoneChanged);
42-
connect(m_window, &QWindow::widthChanged, this, &LayerShellEmulation::onPositionChanged);
43-
44-
connect(m_window, &QWindow::heightChanged, this, &LayerShellEmulation::onExclusionZoneChanged);
45-
connect(m_window, &QWindow::heightChanged, this, &LayerShellEmulation::onPositionChanged);
46-
47-
auto screen = m_window->screen();
48-
connect(screen, &QScreen::geometryChanged, this, &LayerShellEmulation::onPositionChanged);
49-
connect(screen, &QScreen::geometryChanged, this, &LayerShellEmulation::onExclusionZoneChanged);
50-
connect(qApp, &QGuiApplication::primaryScreenChanged, this, &LayerShellEmulation::onExclusionZoneChanged);
47+
connect(m_window, &QWindow::widthChanged, &m_exclusionZoneChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
48+
connect(m_window, &QWindow::widthChanged, &m_positionChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
49+
connect(m_window, &QWindow::heightChanged, &m_exclusionZoneChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
50+
connect(m_window, &QWindow::heightChanged, &m_positionChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
51+
52+
for (auto screen : qApp->screens()) {
53+
connect(screen, &QScreen::geometryChanged, &m_positionChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
54+
connect(screen, &QScreen::geometryChanged, &m_exclusionZoneChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
55+
}
56+
connect(qApp, &QGuiApplication::screenAdded, this, [this] (const QScreen *newScreen) {
57+
connect(newScreen, &QScreen::geometryChanged, &m_positionChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
58+
connect(newScreen, &QScreen::geometryChanged, &m_exclusionZoneChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
59+
});
60+
connect(qApp, &QGuiApplication::primaryScreenChanged, &m_exclusionZoneChangedTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
5161
connect(m_window, &QWindow::screenChanged, this, [this](QScreen *nowScreen){
52-
for (auto screen : qApp->screens()) {
53-
screen->disconnect(this);
54-
}
55-
56-
connect(nowScreen, &QScreen::geometryChanged, this, &LayerShellEmulation::onPositionChanged);
57-
connect(nowScreen, &QScreen::geometryChanged, this, &LayerShellEmulation::onExclusionZoneChanged);
58-
onPositionChanged();
59-
QMetaObject::invokeMethod(this, &LayerShellEmulation::onExclusionZoneChanged, Qt::QueuedConnection);
62+
m_positionChangedTimer.start();
63+
m_exclusionZoneChangedTimer.start();
6064
});
6165

6266
// connect(m_dlayerShellWindow, &DS_NAMESPACE::DLayerShellWindow::keyboardInteractivityChanged, this, &LayerShellEmulation::onKeyboardInteractivityChanged);

frame/layershell/x11dlayershellemulation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <QObject>
1111
#include <QWindow>
12+
#include <QTimer>
1213

1314
#include <xcb/xcb.h>
1415
#include <xcb/xproto.h>
@@ -31,5 +32,7 @@ private slots:
3132
private:
3233
QWindow* m_window;
3334
DLayerShellWindow* m_dlayerShellWindow;
35+
QTimer m_positionChangedTimer;
36+
QTimer m_exclusionZoneChangedTimer;
3437
};
3538
DS_END_NAMESPACE

0 commit comments

Comments
 (0)