From e74e013f4396dac6d33e57e6b3bc132ca0da48f2 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Thu, 9 Jul 2020 09:20:33 +0300 Subject: [PATCH] provide CanvasGeometry from View::Positioner --View::Positioner is now responsible to provide the proper Canvas config window geometry --- app/view/positioner.cpp | 60 +++++++++++++++++++++++++ app/view/positioner.h | 9 +++- app/view/settings/canvasconfigview.cpp | 62 ++++---------------------- app/view/settings/subconfigview.cpp | 2 +- 4 files changed, 78 insertions(+), 55 deletions(-) diff --git a/app/view/positioner.cpp b/app/view/positioner.cpp index 611360866..17667e6cd 100644 --- a/app/view/positioner.cpp +++ b/app/view/positioner.cpp @@ -485,8 +485,10 @@ void Positioner::immediateSyncGeometry() } m_view->effects()->updateEnabledBorders(); + resizeWindow(availableScreenRect); updatePosition(availableScreenRect); + updateCanvasGeometry(availableScreenRect); qDebug() << "syncGeometry() calculations for screen: " << m_view->screen()->name() << " _ " << m_view->screen()->geometry(); qDebug() << "syncGeometry() calculations for edge: " << m_view->location(); @@ -504,6 +506,22 @@ void Positioner::validateDockGeometry() } } +QRect Positioner::canvasGeometry() +{ + return m_canvasGeometry; +} + +void Positioner::setCanvasGeometry(const QRect &geometry) +{ + if (m_canvasGeometry == geometry) { + return; + } + + m_canvasGeometry = geometry; + emit canvasGeometryChanged(); +} + + //! this is used mainly from vertical panels in order to //! to get the maximum geometry that can be used from the dock //! based on their alignment type and the location dock @@ -573,6 +591,48 @@ void Positioner::validateTopBottomBorders(QRect availableScreenRect, QRegion ava } } +void Positioner::updateCanvasGeometry(QRect availableScreenRect) +{ + QRect canvas; + QRect screenGeometry{m_view->screen()->geometry()}; + int thickness{m_view->editThickness()}; + + if (m_view->formFactor() == Plasma::Types::Vertical) { + canvas.setWidth(thickness); + canvas.setHeight(availableScreenRect.height()); + } else { + canvas.setWidth(screenGeometry.width()); + canvas.setHeight(thickness); + } + + switch (m_view->location()) { + case Plasma::Types::TopEdge: + canvas.moveLeft(screenGeometry.x()); + canvas.moveTop(screenGeometry.y()); + break; + + case Plasma::Types::BottomEdge: + canvas.moveLeft(screenGeometry.x()); + canvas.moveTop(screenGeometry.bottom() - thickness + 1); + break; + + case Plasma::Types::RightEdge: + canvas.moveLeft(screenGeometry.right() - thickness + 1); + canvas.moveTop(availableScreenRect.y()); + break; + + case Plasma::Types::LeftEdge: + canvas.moveLeft(availableScreenRect.x()); + canvas.moveTop(availableScreenRect.y()); + break; + + default: + qWarning() << "wrong location, couldn't update the canvas config window geometry " << m_view->location(); + } + + setCanvasGeometry(canvas); +} + void Positioner::updatePosition(QRect availableScreenRect) { QRect screenGeometry{availableScreenRect}; diff --git a/app/view/positioner.h b/app/view/positioner.h index 71831f7ea..035e898df 100644 --- a/app/view/positioner.h +++ b/app/view/positioner.h @@ -80,6 +80,8 @@ public: bool isStickedOnBottomEdge() const; void setIsStickedOnBottomEdge(bool sticked); + QRect canvasGeometry(); + void setScreenToFollow(QScreen *scr, bool updateScreenId = true); void reconsiderScreen(); @@ -97,6 +99,7 @@ public slots: void initDelayedSignals(); signals: + void canvasGeometryChanged(); void currentScreenChanged(); void edgeChanged(); void screenGeometryChanged(); @@ -137,13 +140,16 @@ private slots: private: void init(); void initSignalingForLocationChangeSliding(); - void resizeWindow(QRect availableScreenRect = QRect()); void updateFormFactor(); + void resizeWindow(QRect availableScreenRect = QRect()); void updatePosition(QRect availableScreenRect = QRect()); + void updateCanvasGeometry(QRect availableScreenRect = QRect()); void validateTopBottomBorders(QRect availableScreenRect, QRegion availableScreenRegion); + void setCanvasGeometry(const QRect &geometry); + QRect maximumNormalGeometry(); private: @@ -156,6 +162,7 @@ private: int m_slideOffset{0}; + QRect m_canvasGeometry; //! it is used in order to enforce X11 to never miss window geometry QRect m_validGeometry; diff --git a/app/view/settings/canvasconfigview.cpp b/app/view/settings/canvasconfigview.cpp index 1a40b9abb..19ef8269a 100644 --- a/app/view/settings/canvasconfigview.cpp +++ b/app/view/settings/canvasconfigview.cpp @@ -46,7 +46,7 @@ CanvasConfigView::CanvasConfigView(Latte::View *view, PrimaryConfigView *parent) { setResizeMode(QQuickView::SizeRootObjectToView); - connections << connect(m_parent, &PrimaryConfigView::availableScreenGeometryChanged, this, &CanvasConfigView::syncGeometry); + //connections << connect(m_parent, &PrimaryConfigView::availableScreenGeometryChanged, this, &CanvasConfigView::syncGeometry); setParentView(view); init(); @@ -79,6 +79,8 @@ void CanvasConfigView::initParentView(Latte::View *view) { SubConfigView::initParentView(view); + viewconnections << connect(m_latteView->positioner(), &ViewPart::Positioner::canvasGeometryChanged, this, &CanvasConfigView::syncGeometry); + updateEnabledBorders(); syncGeometry(); @@ -91,55 +93,9 @@ void CanvasConfigView::syncGeometry() return; } - const auto location = m_latteView->containment()->location(); - const auto scrGeometry = m_latteView->screenGeometry(); - const auto availGeometry = m_parent->availableScreenGeometry(); - QSize size; - - int editThickness = m_latteView->editThickness(); - - QPoint position{0, 0}; - - int xPos{0}; - int yPos{0}; - - switch (m_latteView->containment()->formFactor()) { - case Plasma::Types::Horizontal: { - xPos = availGeometry.x(); - size.setWidth(availGeometry.width()); - size.setHeight(editThickness); - - if (location == Plasma::Types::TopEdge) { - yPos = scrGeometry.y(); - } else if (location == Plasma::Types::BottomEdge) { - yPos = scrGeometry.y() + scrGeometry.height() - editThickness; - } - } - break; - - case Plasma::Types::Vertical: { - yPos = availGeometry.y(); - size.setWidth(editThickness); - size.setHeight(availGeometry.height()); - - if (location == Plasma::Types::LeftEdge) { - xPos = scrGeometry.x(); - } else if (location == Plasma::Types::RightEdge) { - xPos = scrGeometry.x() + scrGeometry.width() - editThickness; - } - } - break; - - default: - qWarning() << "no sync geometry, wrong formFactor"; - break; - } - - position = {xPos, yPos}; - updateEnabledBorders(); - auto geometry = QRect(position.x(), position.y(), size.width(), size.height()); + auto geometry = m_latteView->positioner()->canvasGeometry(); if (m_geometryWhenVisible == geometry) { return; @@ -147,15 +103,15 @@ void CanvasConfigView::syncGeometry() m_geometryWhenVisible = geometry; - setPosition(position); + setPosition(geometry.topLeft()); if (m_shellSurface) { - m_shellSurface->setPosition(position); + m_shellSurface->setPosition(geometry.topLeft()); } - setMaximumSize(size); - setMinimumSize(size); - resize(size); + setMaximumSize(geometry.size()); + setMinimumSize(geometry.size()); + resize(geometry.size()); //! after placement request to activate the main config window in order to avoid //! rare cases of closing settings window from secondaryConfigView->focusOutEvent diff --git a/app/view/settings/subconfigview.cpp b/app/view/settings/subconfigview.cpp index b7df187b7..1e8a1b290 100644 --- a/app/view/settings/subconfigview.cpp +++ b/app/view/settings/subconfigview.cpp @@ -168,7 +168,7 @@ void SubConfigView::initParentView(Latte::View *view) m_latteView = view; viewconnections << connect(m_latteView->visibility(), &VisibilityManager::modeChanged, this, &SubConfigView::syncGeometry); - viewconnections << connect(m_latteView, &Latte::View::normalThicknessChanged, [&]() { + viewconnections << connect(m_latteView, &Latte::View::editThicknessChanged, [&]() { m_thicknessSyncTimer.start(); });