@@ -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);
0 commit comments