From c61c14e9be91ef12de23d3f1777313465c2b5b4d Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 12 Mar 2017 20:18:18 +0200 Subject: [PATCH] improve panel painting for disabled compositing --- app/dockview.cpp | 57 +++++++------------ app/dockview.h | 2 + containment/contents/ui/PanelBox.qml | 28 ++++----- containment/contents/ui/VisibilityManager.qml | 17 +++++- containment/contents/ui/main.qml | 21 ++----- 5 files changed, 60 insertions(+), 65 deletions(-) diff --git a/app/dockview.cpp b/app/dockview.cpp index d187d66c1..5d9017ec5 100644 --- a/app/dockview.cpp +++ b/app/dockview.cpp @@ -24,6 +24,7 @@ #include "visibilitymanager.h" #include "panelshadows_p.h" #include "../liblattedock/extras.h" +#include "../liblattedock/quickwindowsystem.h" #include #include @@ -38,6 +39,7 @@ #include #include #include +#include #include #include @@ -53,6 +55,7 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool alwaysVis setTitle(corona->kPackage().metadata().name()); setIcon(qGuiApp->windowIcon()); setResizeMode(QuickViewSharedEngine::SizeRootObjectToView); + setColor(QColor(Qt::transparent)); setClearBeforeRendering(true); if (!alwaysVisible) { @@ -75,7 +78,6 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool alwaysVis connect(this, &DockView::containmentChanged , this, [&]() { - if (!this->containment()) return; @@ -121,7 +123,6 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool alwaysVis DockView::~DockView() { m_screenSyncTimer.stop(); - qDebug() << "dock view deleting..."; rootContext()->setContextProperty(QStringLiteral("dock"), nullptr); this->disconnect(); @@ -139,7 +140,6 @@ DockView::~DockView() void DockView::init() { connect(this, &QQuickWindow::screenChanged, this, &DockView::screenChanged); - connect(qGuiApp, &QGuiApplication::screenAdded, this, &DockView::screenChanged); connect(qGuiApp, &QGuiApplication::primaryScreenChanged, this, &DockView::screenChanged); connect(this, &DockView::screenGeometryChanged, this, &DockView::syncGeometry); @@ -151,7 +151,6 @@ void DockView::init() 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) syncGeometry(); @@ -159,22 +158,16 @@ void DockView::init() connect(this, &DockView::drawShadowsChanged, this, &DockView::syncGeometry); connect(this, &DockView::maxLengthChanged, this, &DockView::syncGeometry); connect(this, &DockView::alignmentChanged, this, &DockView::updateEnabledBorders); - connect(this, &DockView::onPrimaryChanged, this, &DockView::saveConfig); connect(this, &DockView::onPrimaryChanged, this, &DockView::reconsiderScreen); - connect(this, &DockView::sessionChanged, this, &DockView::saveConfig); - connect(this, &DockView::locationChanged, this, [&]() { updateFormFactor(); syncGeometry(); }); - connect(&m_theme, &Plasma::Theme::themeChanged, this, &DockView::themeChanged); - connect(this, SIGNAL(normalThicknessChanged()), corona(), SIGNAL(availableScreenRectChanged())); connect(this, SIGNAL(shadowChanged()), corona(), SIGNAL(availableScreenRectChanged())); - rootContext()->setContextProperty(QStringLiteral("dock"), this); setSource(corona()->kPackage().filePath("lattedockui")); setVisible(true); @@ -237,14 +230,12 @@ void DockView::setScreenToFollow(QScreen *screen, bool updateScreenId) } qDebug() << "adapting to screen..."; - setScreen(screen); if (this->containment()) this->containment()->reactToScreenChange(); syncGeometry(); - emit screenGeometryChanged(); } @@ -259,7 +250,6 @@ void DockView::reconsiderScreen() } auto *dockCorona = qobject_cast(this->corona()); - bool screenExists{false}; //!check if the associated screen is running @@ -409,9 +399,7 @@ QRect DockView::maximumNormalGeometry() int yPos = 0; int maxHeight = maxLength() * screen()->geometry().height(); int maxWidth = normalThickness(); - QRect maxGeometry; - maxGeometry.setRect(0, 0, maxWidth, maxHeight); switch (location()) { @@ -434,7 +422,6 @@ QRect DockView::maximumNormalGeometry() } maxGeometry.setRect(xPos, yPos, maxWidth, maxHeight); - break; case Plasma::Types::RightEdge: @@ -456,7 +443,6 @@ QRect DockView::maximumNormalGeometry() } maxGeometry.setRect(xPos, yPos, maxWidth, maxHeight); - break; } @@ -507,9 +493,7 @@ void DockView::setLocalGeometry(const QRect &geometry) } m_localGeometry = geometry; - emit localGeometryChanged(); - updateAbsDockGeometry(); } @@ -530,13 +514,10 @@ void DockView::updatePosition(QRect availableScreenRect) { QRect screenGeometry; QPoint position; - position = {0, 0}; - const auto length = [&](int length) -> int { return static_cast(length * (1 - maxLength()) / 2); }; - int cleanThickness = normalThickness() - shadow(); switch (location()) { @@ -623,14 +604,12 @@ inline void DockView::syncGeometry() maximumRect = maximumNormalGeometry(); QRegion availableRegion = freeRegion.intersected(maximumRect); availableScreenRect = freeRegion.intersected(maximumRect).boundingRect(); - float area = 0; //! it is used to choose which or the availableRegion rectangles will //! be the one representing dock geometry for (int i = 0; i < availableRegion.rectCount(); ++i) { QRect rect = availableRegion.rects().at(i); - //! the area of each rectangle in calculated in squares of 50x50 //! this is a way to avoid enourmous numbers for area value float tempArea = (float)(rect.width() * rect.height()) / 2500; @@ -649,7 +628,6 @@ inline void DockView::syncGeometry() m_forceDrawCenteredBorders = false; } - updateEnabledBorders(); resizeWindow(availableScreenRect); updatePosition(availableScreenRect); @@ -691,7 +669,6 @@ void DockView::setNormalThickness(int thickness) } m_normalThickness = thickness; - emit normalThicknessChanged(); } @@ -754,12 +731,10 @@ void DockView::setDrawShadows(bool draw) } else { PanelShadows::self()->removeWindow(this); m_enabledBorders = Plasma::FrameSvg::AllBorders; - emit enabledBordersChanged(); } themeChanged(); - emit drawShadowsChanged(); } @@ -805,7 +780,6 @@ void DockView::setMaxLength(float length) } m_maxLength = length; - emit maxLengthChanged(); } @@ -852,7 +826,25 @@ void DockView::setMaskArea(QRect area) return; m_maskArea = area; - setMask(m_maskArea); + + if (KWindowSystem::compositingActive()) { + setMask(m_maskArea); + } else { + //! this is used when compositing is disabled and provides + //! the correct way for the mask to be painted in order for + //! rounded corners to be shown correctly + if (!m_background) { + m_background = new Plasma::FrameSvg(this); + m_background->setImagePath(QStringLiteral("opaque/dialogs/background")); + } + + m_background->setEnabledBorders(enabledBorders()); + m_background->resizeFrame(area.size()); + QRegion fixedMask = m_background->mask(); + fixedMask.translate(area.x(), area.y()); + setMask(fixedMask); + } + //qDebug() << "dock mask set:" << m_maskArea; emit maskAreaChanged(); } @@ -1023,7 +1015,6 @@ void DockView::mouseReleaseEvent(QMouseEvent *event) void DockView::mousePressEvent(QMouseEvent *event) { //qDebug() << "Step -1 ..."; - if (!event || !this->containment()) { return; } @@ -1076,7 +1067,6 @@ void DockView::mousePressEvent(QMouseEvent *event) //Try to find applets inside a systray if (meta.pluginId() == "org.kde.plasma.systemtray") { auto systrayId = applet->config().readEntry("SystrayContainmentId"); - applet = 0; inSystray = true; Plasma::Containment *cont = containmentById(systrayId.toInt()); @@ -1119,7 +1109,6 @@ void DockView::mousePressEvent(QMouseEvent *event) if (this->mouseGrabberItem()) { //workaround, this fixes for me most of the right click menu behavior this->mouseGrabberItem()->ungrabMouse(); - return; } @@ -1340,7 +1329,6 @@ Plasma::FrameSvg::EnabledBorders DockView::enabledBorders() const void DockView::updateEnabledBorders() { // qDebug() << "draw shadow!!!! :" << m_drawShadows; - if (!this->screen()) { return; } @@ -1381,7 +1369,6 @@ void DockView::updateEnabledBorders() if (m_alignment == Dock::Bottom && !m_forceDrawCenteredBorders) { borders &= ~Plasma::FrameSvg::BottomBorder; } - } if (location() == Plasma::Types::TopEdge || location() == Plasma::Types::BottomEdge) { diff --git a/app/dockview.h b/app/dockview.h index 16d0d0989..0ba3cecc5 100644 --- a/app/dockview.h +++ b/app/dockview.h @@ -227,6 +227,8 @@ private: QTimer m_screenSyncTimer; Plasma::Theme m_theme; + //only for the mask on disabled compositing, not to actually paint + Plasma::FrameSvg *m_background{nullptr}; //only for the mask, not to actually paint Plasma::FrameSvg::EnabledBorders m_enabledBorders = Plasma::FrameSvg::AllBorders; diff --git a/containment/contents/ui/PanelBox.qml b/containment/contents/ui/PanelBox.qml index d49432b1f..95a2b8387 100644 --- a/containment/contents/ui/PanelBox.qml +++ b/containment/contents/ui/PanelBox.qml @@ -62,9 +62,13 @@ Item{ } } - property int spacing: (root.panelAlignment === Latte.Dock.Center - || plasmoid.configuration.panelPosition === Latte.Dock.Justify) ? - root.panelEdgeSpacing/2 : root.panelEdgeSpacing/4 + property int spacing: { + if (root.panelAlignment === Latte.Dock.Center || plasmoid.configuration.panelPosition === Latte.Dock.Justify) { + return root.panelEdgeSpacing/2; + } else { + return root.panelEdgeSpacing/4; + } + } property int smallSize: Math.max(3.7*root.statesLineSize, 16) Behavior on opacity{ @@ -104,8 +108,8 @@ Item{ height: root.isVertical ? Math.min(parent.height + marginsHeight, root.height - marginsHeight) : panelSize + marginsHeight - (solidBackground.topIncreaser + solidBackground.bottomIncreaser) - imagePath: root.drawShadowsExternal ? "" : "widgets/panel-background" - prefix: root.drawShadowsExternal ? "" : "shadow" + imagePath: root.drawShadowsExternal || !Latte.WindowSystem.compositingActive ? "" : "widgets/panel-background" + prefix: root.drawShadowsExternal || !Latte.WindowSystem.compositingActive ? "" : "shadow" opacity: root.useThemePanel ? 1 : 0 visible: (opacity == 0) ? false : true @@ -113,7 +117,7 @@ Item{ enabledBorders: dock ? dock.enabledBorders : 0 property int marginsWidth: { - if (root.drawShadowsExternal) { + if (root.drawShadowsExternal || !Latte.WindowSystem.compositingActive) { return 0; } else { if (root.panelAlignment === Latte.Dock.Left) @@ -126,7 +130,7 @@ Item{ } property int marginsHeight: { - if (root.drawShadowsExternal) { + if (root.drawShadowsExternal || !Latte.WindowSystem.compositingActive) { return 0; } else { if (root.panelAlignment === Latte.Dock.Top) @@ -196,10 +200,10 @@ Item{ PlasmaCore.FrameSvgItem{ id: solidBackground - anchors.leftMargin: shadowsSvgItem.margins.left - leftIncreaser - anchors.rightMargin: shadowsSvgItem.margins.right - rightIncreaser - anchors.topMargin: shadowsSvgItem.margins.top - topIncreaser - anchors.bottomMargin: shadowsSvgItem.margins.bottom - bottomIncreaser + anchors.leftMargin: Latte.WindowSystem.compositingActive ? shadowsSvgItem.margins.left - leftIncreaser : 0 + anchors.rightMargin: Latte.WindowSystem.compositingActive ? shadowsSvgItem.margins.right - rightIncreaser : 0 + anchors.topMargin: Latte.WindowSystem.compositingActive ? shadowsSvgItem.margins.top - topIncreaser : 0 + anchors.bottomMargin: Latte.WindowSystem.compositingActive ? shadowsSvgItem.margins.bottom - bottomIncreaser : 0 anchors.fill:parent imagePath: root.solidPanel ? "opaque/dialogs/background" : "widgets/panel-background" @@ -251,8 +255,6 @@ Item{ else if (plasmoid.location === PlasmaCore.Types.TopEdge) return solidBackground.margins.bottom; } - } else { - return 0; } } } diff --git a/containment/contents/ui/VisibilityManager.qml b/containment/contents/ui/VisibilityManager.qml index 96516c528..9d995658c 100644 --- a/containment/contents/ui/VisibilityManager.qml +++ b/containment/contents/ui/VisibilityManager.qml @@ -178,8 +178,21 @@ Item{ var tempLength = root.isHorizontal ? width : height; var tempThickness = root.isHorizontal ? height : width; - var space = root.useThemePanel ? (plasmoid.configuration.panelPosition === Latte.Dock.Justify) ? - root.panelEdgeSpacing + 2*root.panelShadow : root.panelEdgeSpacing + 2*root.panelShadow : 2; + var space = 0; + + if (Latte.WindowSystem.compositingActive) { + if (root.useThemePanel){ + space = root.panelEdgeSpacing + 2*root.panelShadow; + } else { + space = 2; + } + } else { + if (root.panelAlignment === Latte.Dock.Center || plasmoid.configuration.panelPosition === Latte.Dock.Justify) { + space = root.panelEdgeSpacing/2; + } else { + space = root.panelEdgeSpacing/4; + } + } if (normalState) { //console.log("entered normal state..."); diff --git a/containment/contents/ui/main.qml b/containment/contents/ui/main.qml index b811050ea..576a7d991 100644 --- a/containment/contents/ui/main.qml +++ b/containment/contents/ui/main.qml @@ -62,7 +62,7 @@ DragDrop.DropArea { property bool normalState : false property bool onlyAddingStarup: true //is used for the initialization phase in startup where there arent removals, this variable provides a way to grow icon size property bool shrinkThickMargins: plasmoid.configuration.shrinkThickMargins - property bool solidPanel: plasmoid.configuration.solidPanel + property bool solidPanel: Latte.WindowSystem.compositingActive ? plasmoid.configuration.solidPanel : true //FIXME: possibly this is going to be the default behavior, this user choice //has been dropped from the Dock Configuration Window //property bool smallAutomaticIconJumps: plasmoid.configuration.smallAutomaticIconJumps @@ -110,7 +110,7 @@ DragDrop.DropArea { var panelBase = root.statesLineSize + root.panelMargin; var margin = latteApplet ? thickMargin : 0; var maxPanelSize = (root.statesLineSize + iconSize + margin + 1) - panelBase; - var percentage = plasmoid.configuration.panelSize/100; + var percentage = Latte.WindowSystem.compositingActive ? plasmoid.configuration.panelSize/100 : 1; return Math.max(panelBase, panelBase + percentage*maxPanelSize); } @@ -184,7 +184,7 @@ DragDrop.DropArea { layoutsContainer.height + 0.5*iconMargin : mainLayout.height + iconMargin) : Screen.height //on unlocked state use the maximum*/ - Plasmoid.backgroundHints: Latte.WindowSystem.compositingActive ? PlasmaCore.Types.NoBackground : PlasmaCore.Types.DefaultBackground + Plasmoid.backgroundHints: PlasmaCore.Types.NoBackground //// BEGIN properties in functions property int noApplets: { @@ -1133,23 +1133,14 @@ DragDrop.DropArea { EditModeVisual{ id:editModeVisual - z: root.drawShadowsExternal ? 1 : 0 + z: root.drawShadowsExternal || !Latte.WindowSystem.compositingActive ? 1 : 0 } Item{ anchors.fill:layoutsContainer - z: root.drawShadowsExternal ? 0 : 1 + z: root.drawShadowsExternal || !Latte.WindowSystem.compositingActive ? 0 : 1 - Loader{ - width: parent.width - height: parent.height - // FIX IT && TEST IT: it is crashing Plasma with two Now Docks one of which has only - // task manager (small) - //active: root.useThemePanel - active: Latte.WindowSystem.compositingActive - sourceComponent: PanelBox{} - - } + PanelBox{} } Item {