From f287d37ac0157c2915ce3f4f6e73997c775e85e4 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Thu, 5 Apr 2018 10:09:04 +0300 Subject: [PATCH] add a dock geometry validator -- under X11 it was identified that windows many times especially under screen changes dont end up at the correct position and size. This vailidator(timer) will enforce repositionings and resizes every 500ms if the window hasnt end up to correct values and until this is achieved. --- app/dock/dockview.cpp | 53 +++++++++++++++++++++++++++++++------------ app/dock/dockview.h | 5 ++++ 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/app/dock/dockview.cpp b/app/dock/dockview.cpp index 33356a6b6..0cbcf0d40 100644 --- a/app/dock/dockview.cpp +++ b/app/dock/dockview.cpp @@ -121,6 +121,14 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool dockWindo m_screenSyncTimer.setInterval(2000); connect(&m_screenSyncTimer, &QTimer::timeout, this, &DockView::reconsiderScreen); + //! under X11 it was identified that windows many times especially under screen changes + //! dont end up at the correct position and size. This timer will enforce repositionings + //! and resizes every 500ms if the window hasnt end up to correct values and until this + //! is achieved + m_validateGeometryTimer.setSingleShot(true); + m_validateGeometryTimer.setInterval(500); + connect(&m_validateGeometryTimer, &QTimer::timeout, this, &DockView::syncGeometry); + auto *dockCorona = qobject_cast(this->corona()); if (dockCorona) { @@ -180,13 +188,18 @@ void DockView::init() connect(qGuiApp, &QGuiApplication::screenAdded, this, &DockView::screenChanged); connect(qGuiApp, &QGuiApplication::primaryScreenChanged, this, &DockView::screenChanged); connect(this, &DockView::screenGeometryChanged, this, &DockView::syncGeometry); + connect(this, &QQuickWindow::xChanged, this, &DockView::xChanged); + connect(this, &QQuickWindow::xChanged, this, &DockView::validateDockGeometry); connect(this, &QQuickWindow::xChanged, this, &DockView::updateAbsDockGeometry); connect(this, &QQuickWindow::yChanged, this, &DockView::yChanged); + connect(this, &QQuickWindow::yChanged, this, &DockView::validateDockGeometry); connect(this, &QQuickWindow::yChanged, this, &DockView::updateAbsDockGeometry); connect(this, &QQuickWindow::widthChanged, this, &DockView::widthChanged); + connect(this, &QQuickWindow::widthChanged, this, &DockView::validateDockGeometry); connect(this, &QQuickWindow::widthChanged, this, &DockView::updateAbsDockGeometry); connect(this, &QQuickWindow::heightChanged, this, &DockView::heightChanged); + connect(this, &QQuickWindow::heightChanged, this, &DockView::validateDockGeometry); connect(this, &QQuickWindow::heightChanged, this, &DockView::updateAbsDockGeometry); connect(corona(), &Plasma::Corona::availableScreenRectChanged, this, &DockView::availableScreenRectChanged); @@ -447,6 +460,10 @@ void DockView::setScreenToFollow(QScreen *screen, bool updateScreenId) //! correct screen void DockView::reconsiderScreen() { + if (m_inDelete) { + return; + } + qDebug() << " Delayer "; foreach (auto scr, qGuiApp->screens()) { @@ -718,33 +735,37 @@ QRect DockView::maximumNormalGeometry() void DockView::resizeWindow(QRect availableScreenRect) { + QSize screenSize = this->screen()->size(); + QSize size = (formFactor() == Plasma::Types::Vertical) ? QSize(maxThickness(), availableScreenRect.height()) : QSize(screenSize.width(), maxThickness()); + if (formFactor() == Plasma::Types::Vertical) { //qDebug() << "MAXIMUM RECT :: " << maximumRect << " - AVAILABLE RECT :: " << availableRect; - QSize size{maxThickness(), availableScreenRect.height()}; - if (m_behaveAsPlasmaPanel) { size.setWidth(normalThickness()); size.setHeight(static_cast(maxLength() * availableScreenRect.height())); } - - setMinimumSize(size); - setMaximumSize(size); - resize(size); } else { - QSize screenSize = this->screen()->size(); - QSize size{screenSize.width(), maxThickness()}; - if (m_behaveAsPlasmaPanel) { size.setWidth(static_cast(maxLength() * screenSize.width())); size.setHeight(normalThickness()); } + } + + m_validGeometry.setSize(size); - setMinimumSize(size); - setMaximumSize(size); - resize(size); + setMinimumSize(size); + setMaximumSize(size); + resize(size); + + if (formFactor() == Plasma::Types::Horizontal && corona()) { + emit corona()->availableScreenRectChanged(); + } +} - if (corona()) - emit corona()->availableScreenRectChanged(); +void DockView::validateDockGeometry() +{ + if (geometry() != m_validGeometry) { + m_validateGeometryTimer.start(); } } @@ -848,6 +869,8 @@ void DockView::updatePosition(QRect availableScreenRect) << location(); } + m_validGeometry.setTopLeft(position); + setPosition(position); if (m_shellSurface) { @@ -857,7 +880,7 @@ void DockView::updatePosition(QRect availableScreenRect) inline void DockView::syncGeometry() { - if (!(this->screen() && this->containment())) + if (!(this->screen() && this->containment()) || m_inDelete) return; bool found{false}; diff --git a/app/dock/dockview.h b/app/dock/dockview.h index 8b15d5a71..ea37ee5b3 100644 --- a/app/dock/dockview.h +++ b/app/dock/dockview.h @@ -304,6 +304,7 @@ private slots: void statusChanged(Plasma::Types::ItemStatus); void screenChanged(QScreen *screen); void updateEffects(); + void validateDockGeometry(); void restoreConfig(); void saveConfig(); @@ -346,6 +347,9 @@ private: QRect m_localGeometry; QRect m_absGeometry; QRect m_maskArea; + //! it is used in order to enforce X11 to never miss window geometry + QRect m_validGeometry; + Layout *m_managedLayout{nullptr}; QPointer m_configView; @@ -356,6 +360,7 @@ private: QString m_screenToFollowId; QTimer m_screenSyncTimer; + QTimer m_validateGeometryTimer; //! Connections to release and bound for the managed layout std::array connectionsManagedLayout;