From e19b20dc222bb5d4b1cea1c849ea9d21a19b5dc8 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Wed, 8 Mar 2017 21:00:09 +0200 Subject: [PATCH] fix #198,recreate windows when it is needed --in order for a dock to be above KeepAbove windows must contain flag BypassWindowManagerHint. Unfortunately this flag breaks the experience with AlwaysVisible state especially the struts and snapping behavior. This patch recreates a dockView when a mode is changed and an update for the flags is needed. --at the same time move the localGeometry to dockView in order to trigger properly the updateAbsGeometry when it is needed, on window's geometry changes not only when there is local geometry change --when a dock is created through corona, the addDock function reads the mode which is going to be used and specifys this way the flags that have to be set during docks creation --- app/dockconfigview.cpp | 13 +++++++ app/dockconfigview.h | 4 ++ app/dockcorona.cpp | 24 +++++++++++- app/dockcorona.h | 1 + app/dockview.cpp | 37 ++++++++++++++----- app/dockview.h | 6 ++- containment/contents/ui/VisibilityManager.qml | 12 ++---- 7 files changed, 76 insertions(+), 21 deletions(-) diff --git a/app/dockconfigview.cpp b/app/dockconfigview.cpp index ebed24786..de202637a 100644 --- a/app/dockconfigview.cpp +++ b/app/dockconfigview.cpp @@ -197,6 +197,8 @@ void DockConfigView::showEvent(QShowEvent *ev) m_screenSyncTimer.start(); QTimer::singleShot(400, this, &DockConfigView::syncGeometry); + m_previousMode = m_dockView->visibility()->mode(); + emit showSignal(); } @@ -207,6 +209,17 @@ void DockConfigView::hideEvent(QHideEvent *ev) QQuickWindow::hideEvent(ev); + if (m_dockView->visibility()->mode() != m_previousMode + && ((m_dockView->visibility()->mode() == Dock::AlwaysVisible) + || (m_previousMode == Dock::AlwaysVisible))) { + + auto *dockCorona = qobject_cast(m_dockView->corona()); + + if (dockCorona) { + dockCorona->recreateDock(m_dockView->containment()); + } + } + deleteLater(); } diff --git a/app/dockconfigview.h b/app/dockconfigview.h index 5a966ce4e..acbcb6c1f 100644 --- a/app/dockconfigview.h +++ b/app/dockconfigview.h @@ -22,6 +22,8 @@ #define NOWDOCKCONFIGVIEW_H #include "plasmaquick/configview.h" +#include "../liblattedock/dock.h" + #include #include @@ -76,6 +78,8 @@ private: QTimer m_screenSyncTimer; QList connections; + + Dock::Visibility m_previousMode{Dock::None}; }; } diff --git a/app/dockcorona.cpp b/app/dockcorona.cpp index 2eb2645f8..122c4518b 100644 --- a/app/dockcorona.cpp +++ b/app/dockcorona.cpp @@ -717,7 +717,18 @@ void DockCorona::addDock(Plasma::Containment *containment) qDebug() << "Adding dock for container..."; qDebug() << "onPrimary: " << onPrimary << "screen!!! :" << containment->screen() << " - " << m_screenPool->connector(containment->screen()); - auto dockView = new DockView(this, nextScreen); + + //! it is used to set the correct flag during the creation + //! of the window... This of course is also used during + //! recreations of the window between different visibility modes + auto mode = static_cast(containment->config().readEntry("visibility", static_cast(Dock::DodgeActive))); + bool alwaysVisible{false}; + + if (mode == Latte::Dock::AlwaysVisible) { + alwaysVisible = true; + } + + auto dockView = new DockView(this, nextScreen, alwaysVisible); dockView->init(); dockView->setContainment(containment); @@ -738,6 +749,17 @@ void DockCorona::addDock(Plasma::Containment *containment) emit docksCountChanged(); } +void DockCorona::recreateDock(Plasma::Containment *containment) +{ + auto view = m_dockViews.take(containment); + + if (view) { + view->setVisible(false); + view->deleteLater(); + addDock(view->containment()); + } +} + void DockCorona::destroyedChanged(bool destroyed) { qDebug() << "dock containment destroyed changed!!!!"; diff --git a/app/dockcorona.h b/app/dockcorona.h index d84dd757d..b9499044e 100644 --- a/app/dockcorona.h +++ b/app/dockcorona.h @@ -63,6 +63,7 @@ public: int screenForContainment(const Plasma::Containment *containment) const override; void addDock(Plasma::Containment *containment); + void recreateDock(Plasma::Containment *containment); void aboutApplication(); void closeApplication(); diff --git a/app/dockview.cpp b/app/dockview.cpp index 96a84e852..2e105cb07 100644 --- a/app/dockview.cpp +++ b/app/dockview.cpp @@ -45,7 +45,7 @@ namespace Latte { -DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen) +DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool alwaysVisible) : PlasmaQuick::ContainmentView(corona), m_contextMenu(nullptr) { @@ -54,10 +54,19 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen) setIcon(QIcon::fromTheme(corona->kPackage().metadata().iconName())); setResizeMode(QuickViewSharedEngine::SizeRootObjectToView); setClearBeforeRendering(true); - setFlags(Qt::FramelessWindowHint - | Qt::WindowStaysOnTopHint - | Qt::NoDropShadowWindowHint - | Qt::WindowDoesNotAcceptFocus); + + if (!alwaysVisible) { + setFlags(Qt::BypassWindowManagerHint + | Qt::FramelessWindowHint + | Qt::WindowStaysOnTopHint + | Qt::NoDropShadowWindowHint + | Qt::WindowDoesNotAcceptFocus); + } else { + setFlags(Qt::FramelessWindowHint + | Qt::WindowStaysOnTopHint + | Qt::NoDropShadowWindowHint + | Qt::WindowDoesNotAcceptFocus); + } if (targetScreen) setScreenToFollow(targetScreen); @@ -136,9 +145,13 @@ void DockView::init() 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::updateAbsDockGeometry); connect(this, &QQuickWindow::yChanged, this, &DockView::yChanged); + connect(this, &QQuickWindow::yChanged, this, &DockView::updateAbsDockGeometry); connect(this, &QQuickWindow::widthChanged, this, &DockView::widthChanged); + connect(this, &QQuickWindow::widthChanged, this, &DockView::updateAbsDockGeometry); connect(this, &QQuickWindow::heightChanged, this, &DockView::heightChanged); + connect(this, &QQuickWindow::heightChanged, this, &DockView::updateAbsDockGeometry); connect(corona(), &Plasma::Corona::availableScreenRectChanged, this, [&]() { if (formFactor() == Plasma::Types::Vertical) @@ -481,13 +494,19 @@ void DockView::resizeWindow(QRect availableScreenRect) void DockView::setLocalDockGeometry(const QRect &geometry) { - updateAbsDockGeometry(geometry); + if (m_localGeometry == geometry) { + return; + } + + m_localGeometry = geometry; + + updateAbsDockGeometry(); } -void DockView::updateAbsDockGeometry(const QRect &localDockGeometry) +void DockView::updateAbsDockGeometry() { - QRect absGeometry {x() + localDockGeometry.x(), y() + localDockGeometry.y() - , localDockGeometry.width() - 1, localDockGeometry.height() - 1}; + QRect absGeometry {x() + m_localGeometry.x(), y() + m_localGeometry.y() + , m_localGeometry.width() - 1, m_localGeometry.height() - 1}; if (m_absGeometry == absGeometry) return; diff --git a/app/dockview.h b/app/dockview.h index 8fe7987a6..7f665d8ec 100644 --- a/app/dockview.h +++ b/app/dockview.h @@ -71,7 +71,7 @@ class DockView : public PlasmaQuick::ContainmentView { Q_PROPERTY(QRect screenGeometry READ screenGeometry NOTIFY screenGeometryChanged) public: - DockView(Plasma::Corona *corona, QScreen *targetScreen = nullptr); + DockView(Plasma::Corona *corona, QScreen *targetScreen = nullptr, bool alwaysVisible = false); virtual ~DockView(); void init(); @@ -109,7 +109,6 @@ public: QRect maskArea() const; void setMaskArea(QRect area); - void updateAbsDockGeometry(const QRect &localDockGeometry); QRect absGeometry() const; QRect screenGeometry() const; @@ -139,6 +138,8 @@ public slots: Q_INVOKABLE void closeApplication(); + void updateAbsDockGeometry(); + protected slots: void showConfigurationInterface(Plasma::Applet *applet) override; @@ -203,6 +204,7 @@ private: Dock::Alignment m_alignment{Dock::Center}; + QRect m_localGeometry; QRect m_absGeometry; QRect m_maskArea; QMenu *m_contextMenu; diff --git a/containment/contents/ui/VisibilityManager.qml b/containment/contents/ui/VisibilityManager.qml index 867a7b58d..226705d01 100644 --- a/containment/contents/ui/VisibilityManager.qml +++ b/containment/contents/ui/VisibilityManager.qml @@ -63,8 +63,6 @@ Item{ property int thicknessZoomOriginal: Math.max(statesLineSizeOriginal + ((plasmoid.configuration.iconSize+iconMarginOriginal) * root.zoomFactor) + 2, root.realPanelSize + root.panelShadow) - property rect localGeometry: Qt.rect(-1,-1,0,0) - Binding{ target: dock property:"maxThickness" @@ -309,7 +307,7 @@ Item{ } } - // console.log("update mask area:"+newMaskArea); + //console.log("reached updating geometry ::: "+dock.maskArea); if((normalState && !dock.visibility.isHidden) || root.editMode){ var tempGeometry = Qt.rect(dock.maskArea.x, dock.maskArea.y, dock.maskArea.width, dock.maskArea.height); @@ -338,12 +336,8 @@ Item{ tempGeometry.height = Math.min(tempGeometry.height, dock.height); } - if (localGeometry.x !== tempGeometry.x || localGeometry.y !== tempGeometry.y - || localGeometry.width !== tempGeometry.width || localGeometry.height !== tempGeometry.height) { - localGeometry = tempGeometry; - dock.setLocalDockGeometry(localGeometry); - } - // console.log("update dock geometry:"+newMaskArea); + //console.log("update geometry ::: "+tempGeometry); + dock.setLocalDockGeometry(tempGeometry); } }