File indexing completed on 2022-11-29 15:04:21

0001 /*
0002     SPDX-FileCopyrightText: 2018 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "effects.h"
0007 
0008 // local
0009 #include <config-latte.h>
0010 #include <coretypes.h>
0011 #include "panelshadows_p.h"
0012 #include "view.h"
0013 #include "../lattecorona.h"
0014 #include "../wm/abstractwindowinterface.h"
0015 
0016 // Qt
0017 #include <QRegion>
0018 
0019 // KDE
0020 #include <KWindowEffects>
0021 #include <KWindowSystem>
0022 
0023 
0024 namespace Latte {
0025 namespace ViewPart {
0026 
0027 Effects::Effects(Latte::View *parent)
0028     : QObject(parent),
0029       m_view(parent)
0030 {
0031     m_corona = qobject_cast<Latte::Corona *>(m_view->corona());
0032 
0033     init();
0034 }
0035 
0036 Effects::~Effects()
0037 {
0038 }
0039 
0040 void Effects::init()
0041 {
0042     connect(this, &Effects::backgroundOpacityChanged, this, &Effects::updateEffects);
0043     connect(this, &Effects::backgroundOpacityChanged, this, &Effects::updateBackgroundContrastValues);
0044     connect(this, &Effects::backgroundCornersMaskChanged, this, &Effects::updateEffects);
0045     connect(this, &Effects::backgroundRadiusEnabledChanged, this, &Effects::updateEffects);
0046     connect(this, &Effects::drawEffectsChanged, this, &Effects::updateEffects);
0047     connect(this, &Effects::enabledBordersChanged, this, &Effects::updateEffects);
0048     connect(this, &Effects::rectChanged, this, &Effects::updateEffects);
0049 
0050 
0051     connect(this, &Effects::backgroundCornersMaskChanged, this, &Effects::updateMask);
0052     connect(this, &Effects::backgroundRadiusEnabledChanged, this, &Effects::updateMask);
0053     connect(this, &Effects::subtractedMaskRegionsChanged, this, &Effects::updateMask);
0054     connect(this, &Effects::unitedMaskRegionsChanged, this, &Effects::updateMask);
0055     connect(m_view, &QQuickWindow::widthChanged, this, &Effects::updateMask);
0056     connect(m_view, &QQuickWindow::heightChanged, this, &Effects::updateMask);
0057     connect(m_view, &Latte::View::behaveAsPlasmaPanelChanged, this, &Effects::updateMask);
0058     connect(KWindowSystem::self(), &KWindowSystem::compositingChanged, this, [&]() {
0059         if (!KWindowSystem::compositingActive() && !m_view->behaveAsPlasmaPanel()) {
0060             setMask(m_rect);
0061         }
0062 
0063         updateMask();
0064     });
0065 
0066     connect(this, &Effects::rectChanged, this, [&]() {
0067         if (!KWindowSystem::compositingActive() && !m_view->behaveAsPlasmaPanel()) {
0068             setMask(m_rect);
0069         }
0070     });
0071 
0072     connect(this, &Effects::backgroundRadiusChanged, this, &Effects::updateBackgroundCorners);
0073 
0074     connect(this, &Effects::drawShadowsChanged, this, [&]() {
0075         if (m_view->behaveAsPlasmaPanel()) {
0076             updateEnabledBorders();
0077         }
0078     });
0079 
0080     connect(this, &Effects::backgroundAllCornersChanged, this, &Effects::updateEnabledBorders);
0081 
0082     connect(this, &Effects::popUpMarginChanged, this, &Effects::onPopUpMarginChanged);
0083 
0084     connect(m_view, &Latte::View::alignmentChanged, this, &Effects::updateEnabledBorders);
0085     connect(m_view, &Latte::View::maxLengthChanged, this, &Effects::updateEnabledBorders);
0086     connect(m_view, &Latte::View::offsetChanged, this, &Effects::updateEnabledBorders);
0087     connect(m_view, &Latte::View::screenEdgeMarginEnabledChanged, this, &Effects::updateEnabledBorders);
0088     connect(m_view, &Latte::View::behaveAsPlasmaPanelChanged, this, &Effects::updateEffects);
0089     connect(this, &Effects::drawShadowsChanged, this, &Effects::updateShadows);
0090     connect(m_view, &Latte::View::behaveAsPlasmaPanelChanged, this, &Effects::updateShadows);
0091     connect(m_view, &Latte::View::configWindowGeometryChanged, this, &Effects::updateMask);
0092     connect(m_view, &Latte::View::layoutChanged, this, &Effects::onPopUpMarginChanged);
0093 
0094     connect(&m_theme, &Plasma::Theme::themeChanged, this, [&]() {
0095         updateBackgroundContrastValues();
0096         updateEffects();
0097     });
0098 }
0099 
0100 bool Effects::animationsBlocked() const
0101 {
0102     return m_animationsBlocked;
0103 }
0104 
0105 void Effects::setAnimationsBlocked(bool blocked)
0106 {
0107     if (m_animationsBlocked == blocked) {
0108         return;
0109     }
0110 
0111     m_animationsBlocked = blocked;
0112     emit animationsBlockedChanged();
0113 }
0114 
0115 bool Effects::backgroundAllCorners() const
0116 {
0117     return m_backgroundAllCorners;
0118 }
0119 
0120 void Effects::setBackgroundAllCorners(bool allcorners)
0121 {
0122     if (m_backgroundAllCorners == allcorners) {
0123         return;
0124     }
0125 
0126     m_backgroundAllCorners = allcorners;
0127     emit backgroundAllCornersChanged();
0128 }
0129 
0130 bool Effects::backgroundRadiusEnabled() const
0131 {
0132     return m_backgroundRadiusEnabled;
0133 }
0134 
0135 void Effects::setBackgroundRadiusEnabled(bool enabled)
0136 {
0137     if (m_backgroundRadiusEnabled == enabled) {
0138         return;
0139     }
0140 
0141     m_backgroundRadiusEnabled = enabled;
0142     emit backgroundRadiusEnabledChanged();
0143 }
0144 
0145 bool Effects::drawShadows() const
0146 {
0147     return m_drawShadows;
0148 }
0149 
0150 void Effects::setDrawShadows(bool draw)
0151 {
0152     if (m_drawShadows == draw) {
0153         return;
0154     }
0155 
0156     m_drawShadows = draw;
0157 
0158     emit drawShadowsChanged();
0159 }
0160 
0161 bool Effects::drawEffects() const
0162 {
0163     return m_drawEffects;
0164 }
0165 
0166 void Effects::setDrawEffects(bool draw)
0167 {
0168     if (m_drawEffects == draw) {
0169         return;
0170     }
0171 
0172     m_drawEffects = draw;
0173 
0174     emit drawEffectsChanged();
0175 }
0176 
0177 void Effects::setForceBottomBorder(bool draw)
0178 {
0179     if (m_forceBottomBorder == draw) {
0180         return;
0181     }
0182 
0183     m_forceBottomBorder = draw;
0184     updateEnabledBorders();
0185 }
0186 
0187 void Effects::setForceTopBorder(bool draw)
0188 {
0189     if (m_forceTopBorder == draw) {
0190         return;
0191     }
0192 
0193     m_forceTopBorder = draw;
0194     updateEnabledBorders();
0195 }
0196 
0197 int Effects::backgroundRadius()
0198 {
0199     return m_backgroundRadius;
0200 }
0201 
0202 void Effects::setBackgroundRadius(const int &radius)
0203 {
0204     if (m_backgroundRadius == radius) {
0205         return;
0206     }
0207 
0208     m_backgroundRadius = radius;
0209     emit backgroundRadiusChanged();
0210 }
0211 
0212 float Effects::backgroundOpacity() const
0213 {
0214     return m_backgroundOpacity;
0215 }
0216 
0217 void Effects::setBackgroundOpacity(float opacity)
0218 {
0219     if (m_backgroundOpacity == opacity) {
0220         return;
0221     }
0222 
0223     m_backgroundOpacity = opacity;
0224 
0225     updateBackgroundContrastValues();
0226     emit backgroundOpacityChanged();
0227 }
0228 
0229 int Effects::editShadow() const
0230 {
0231     return m_editShadow;
0232 }
0233 
0234 void Effects::setEditShadow(int shadow)
0235 {
0236     if (m_editShadow == shadow) {
0237         return;
0238     }
0239 
0240     m_editShadow = shadow;
0241     emit editShadowChanged();
0242 }
0243 
0244 int Effects::innerShadow() const
0245 {
0246     return m_innerShadow;
0247 }
0248 
0249 void Effects::setInnerShadow(int shadow)
0250 {
0251     if (m_innerShadow == shadow)
0252         return;
0253 
0254     m_innerShadow = shadow;
0255 
0256     emit innerShadowChanged();
0257 }
0258 
0259 int Effects::popUpMargin() const
0260 {
0261     return m_view->layout() ? m_view->layout()->popUpMargin() : -1/*default*/;
0262 }
0263 
0264 QRect Effects::rect() const
0265 {
0266     return m_rect;
0267 }
0268 
0269 void Effects::setRect(QRect area)
0270 {
0271     if (m_rect == area) {
0272         return;
0273     }
0274 
0275     m_rect = area;
0276 
0277     emit rectChanged();
0278 }
0279 
0280 QRect Effects::mask() const
0281 {
0282     return m_mask;
0283 }
0284 
0285 void Effects::setMask(QRect area)
0286 {
0287     if (m_mask == area)
0288         return;
0289 
0290     m_mask = area;
0291     updateMask();
0292 
0293     // qDebug() << "dock mask set:" << m_mask;
0294     emit maskChanged();
0295 }
0296 
0297 QRect Effects::inputMask() const
0298 {
0299     return m_inputMask;
0300 }
0301 
0302 void Effects::setInputMask(QRect area)
0303 {
0304     if (m_inputMask == area) {
0305         return;
0306     }
0307 
0308     m_inputMask = area;
0309 
0310     if (KWindowSystem::isPlatformX11()) {
0311         if (m_view->devicePixelRatio() != 1.0) {
0312             //!Fix for X11 Global Scale
0313             auto ratio = m_view->devicePixelRatio();
0314             area = QRect(qRound(area.x() * ratio),
0315                          qRound(area.y() * ratio),
0316                          qRound(area.width()*ratio),
0317                          qRound(area.height() * ratio));
0318         }
0319 
0320         m_corona->wm()->setInputMask(m_view, area);
0321     } else {
0322         //under wayland mask() is providing the Input Area
0323         m_view->setMask(area);
0324     }
0325 
0326     emit inputMaskChanged();
0327 }
0328 
0329 QRect Effects::appletsLayoutGeometry() const
0330 {
0331     return m_appletsLayoutGeometry;
0332 }
0333 
0334 void Effects::setAppletsLayoutGeometry(const QRect &geom)
0335 {
0336     if (m_appletsLayoutGeometry == geom) {
0337         return;
0338     }
0339 
0340     m_appletsLayoutGeometry = geom;
0341     m_view->setProperty("_applets_layout_geometry", QVariant(m_appletsLayoutGeometry));
0342 
0343     emit appletsLayoutGeometryChanged();
0344 }
0345 
0346 QQuickItem *Effects::panelBackgroundSvg() const
0347 {
0348     return m_panelBackgroundSvg;
0349 }
0350 
0351 void Effects::setPanelBackgroundSvg(QQuickItem *quickitem)
0352 {
0353     if (m_panelBackgroundSvg == quickitem) {
0354         return;
0355     }
0356 
0357     m_panelBackgroundSvg = quickitem;
0358     emit panelBackgroundSvgChanged();
0359 }
0360 
0361 void Effects::onPopUpMarginChanged()
0362 {
0363     m_view->setProperty("_applets_popup_margin", QVariant(popUpMargin()));
0364 }
0365 
0366 void Effects::forceMaskRedraw()
0367 {
0368     updateMask();
0369 }
0370 
0371 void Effects::setSubtractedMaskRegion(const QString &regionid, const QRegion &region)
0372 {
0373     if (m_subtractedMaskRegions.contains(regionid) && m_subtractedMaskRegions[regionid] == region) {
0374         return;
0375     }
0376 
0377     m_subtractedMaskRegions[regionid] = region;
0378     emit subtractedMaskRegionsChanged();
0379 }
0380 
0381 void Effects::removeSubtractedMaskRegion(const QString &regionid)
0382 {
0383     if (!m_subtractedMaskRegions.contains(regionid)) {
0384         return;
0385     }
0386 
0387     m_subtractedMaskRegions.remove(regionid);
0388     emit subtractedMaskRegionsChanged();
0389 }
0390 
0391 void Effects::setUnitedMaskRegion(const QString &regionid, const QRegion &region)
0392 {
0393     if (m_unitedMaskRegions.contains(regionid) && m_unitedMaskRegions[regionid] == region) {
0394         return;
0395     }
0396 
0397     m_unitedMaskRegions[regionid] = region;
0398     emit unitedMaskRegionsChanged();
0399 }
0400 
0401 void Effects::removeUnitedMaskRegion(const QString &regionid)
0402 {
0403     if (!m_unitedMaskRegions.contains(regionid)) {
0404         return;
0405     }
0406 
0407     m_unitedMaskRegions.remove(regionid);
0408     emit unitedMaskRegionsChanged();
0409 }
0410 
0411 QRegion Effects::customMask(const QRect &rect)
0412 {
0413     QRegion result = rect;
0414     int dx = rect.right() - m_cornersMaskRegion.topLeft.boundingRect().width() + 1;
0415     int dy = rect.bottom() - m_cornersMaskRegion.topLeft.boundingRect().height() + 1;
0416 
0417     if (m_hasTopLeftCorner) {
0418         QRegion tl = m_cornersMaskRegion.topLeft;
0419         tl.translate(rect.x(), rect.y());
0420         result = result.subtracted(tl);
0421     }
0422 
0423     if (m_hasTopRightCorner) {
0424         QRegion tr = m_cornersMaskRegion.topRight;
0425         tr.translate(rect.x() + dx, rect.y());
0426         result = result.subtracted(tr);
0427     }
0428 
0429     if (m_hasBottomRightCorner) {
0430         QRegion br = m_cornersMaskRegion.bottomRight;
0431         br.translate(rect.x() + dx, rect.y() + dy);
0432         result = result.subtracted(br);
0433     }
0434 
0435     if (m_hasBottomLeftCorner) {
0436         QRegion bl = m_cornersMaskRegion.bottomLeft;
0437         bl.translate(rect.x(), rect.y() + dy);
0438         result = result.subtracted(bl);
0439     }
0440 
0441     return result;
0442 }
0443 
0444 QRegion Effects::maskCombinedRegion()
0445 {
0446     QRegion region = m_mask;
0447 
0448     for(auto subregion : m_subtractedMaskRegions) {
0449         region = region.subtracted(subregion);
0450     }
0451 
0452     for(auto subregion : m_unitedMaskRegions) {
0453         region = region.united(subregion);
0454     }
0455 
0456     return region;
0457 }
0458 
0459 void Effects::updateBackgroundCorners()
0460 {
0461     if (m_backgroundRadius<0) {
0462         return;
0463     }
0464 
0465     m_corona->themeExtended()->cornersMask(m_backgroundRadius);
0466 
0467     m_cornersMaskRegion = m_corona->themeExtended()->cornersMask(m_backgroundRadius);
0468     emit backgroundCornersMaskChanged();
0469 }
0470 
0471 void Effects::updateMask()
0472 {
0473     if (KWindowSystem::compositingActive()) {
0474         if (KWindowSystem::isPlatformX11()) {
0475             if (m_view->behaveAsPlasmaPanel()) {
0476                 // set as NULL in order for plasma framrworks to identify NULL Mask properly
0477                 m_view->setMask(QRect(-1, -1, 0, 0));
0478             } else {
0479                 m_view->setMask(QRect(0, 0, m_view->width(), m_view->height()));
0480             }
0481         } else {
0482             // under wayland do nothing
0483         }
0484     } else {
0485         QRegion fixedMask;
0486 
0487         QRect maskRect = m_view->behaveAsPlasmaPanel() ? QRect(0,0, m_view->width(), m_view->height()) : m_mask;
0488 
0489         if (m_backgroundRadiusEnabled) {
0490             //! CustomBackground way
0491             fixedMask = customMask(QRect(0,0,maskRect.width(), maskRect.height()));
0492         } else {
0493             //! Plasma::Theme way
0494             //! this is used when compositing is disabled and provides
0495             //! the correct way for the mask to be painted in order for
0496             //! rounded corners to be shown correctly
0497             //! the enabledBorders check was added because there was cases
0498             //! that the mask region wasn't calculated correctly after location changes
0499             if (!m_panelBackgroundSvg) {
0500                 return;
0501             }
0502 
0503             const QVariant maskProperty = m_panelBackgroundSvg->property("mask");
0504             if (static_cast<QMetaType::Type>(maskProperty.type()) == QMetaType::QRegion) {
0505                 fixedMask = maskProperty.value<QRegion>();
0506             }
0507         }
0508 
0509         fixedMask.translate(maskRect.x(), maskRect.y());
0510 
0511         //! fix for KF5.32 that return empty QRegion's for the mask
0512         if (fixedMask.isEmpty()) {
0513             fixedMask = QRegion(maskRect);
0514         }
0515 
0516         m_view->setMask(fixedMask);
0517     }
0518 }
0519 
0520 void Effects::clearShadows()
0521 {
0522     PanelShadows::self()->removeWindow(m_view);
0523 }
0524 
0525 void Effects::updateShadows()
0526 {
0527     if (m_view->behaveAsPlasmaPanel() && drawShadows()) {
0528         PanelShadows::self()->addWindow(m_view, enabledBorders());
0529     } else {
0530         PanelShadows::self()->removeWindow(m_view);
0531     }
0532 }
0533 
0534 void Effects::updateEffects()
0535 {
0536     //! Don't apply any effect before the wayland surface is created under wayland
0537     //! https://bugs.kde.org/show_bug.cgi?id=392890
0538     if (KWindowSystem::isPlatformWayland() && !m_view->surface()) {
0539         return;
0540     }
0541 
0542     bool clearEffects{true};
0543 
0544     if (m_drawEffects) {
0545         if (!m_view->behaveAsPlasmaPanel()) {
0546             if (!m_rect.isNull() && !m_rect.isEmpty() && m_rect != VisibilityManager::ISHIDDENMASK) {
0547                 QRegion backMask;
0548 
0549                 if (m_backgroundRadiusEnabled) {
0550                     //! CustomBackground way
0551                     backMask = customMask(QRect(0,0,m_rect.width(), m_rect.height()));
0552                 } else {
0553                     //! Plasma::Theme way
0554                     //! this is used when compositing is disabled and provides
0555                     //! the correct way for the mask to be painted in order for
0556                     //! rounded corners to be shown correctly
0557                     if (!m_panelBackgroundSvg) {
0558                         return;
0559                     }
0560 
0561                     if (m_rect == VisibilityManager::ISHIDDENMASK) {
0562                         clearEffects = true;
0563                     } else {
0564                         const QVariant maskProperty = m_panelBackgroundSvg->property("mask");
0565                         if (static_cast<QMetaType::Type>(maskProperty.type()) == QMetaType::QRegion) {
0566                             backMask = maskProperty.value<QRegion>();
0567                         }
0568                     }
0569                 }
0570 
0571                 //! adjust mask coordinates based on local coordinates
0572                 int fX = m_rect.x(); int fY = m_rect.y();
0573 
0574                 //! Latte is now using GtkFrameExtents so Effects geometries must be adjusted
0575                 //! windows that use GtkFrameExtents and apply Effects on them they take GtkFrameExtents
0576                 //! as granted
0577                 if (KWindowSystem::isPlatformX11() && !m_view->byPassWM()) {
0578                     if (m_view->location() == Plasma::Types::BottomEdge) {
0579                         fY = qMax(0, fY - m_view->headThicknessGap());
0580                     } else if (m_view->location() == Plasma::Types::RightEdge) {
0581                         fX = qMax(0, fX - m_view->headThicknessGap());
0582                     }
0583                 }
0584 
0585                 //! There are cases that mask is NULL even though it should not
0586                 //! Example: SidebarOnDemand from v0.10 that BEHAVEASPLASMAPANEL in EditMode
0587                 //! switching multiple times between inConfigureAppletsMode and LiveEditMode
0588                 //! is such a case
0589                 QRegion fixedMask;
0590 
0591                 if (!backMask.isNull()) {
0592                     fixedMask = backMask;
0593                     fixedMask.translate(fX, fY);
0594                 } else {
0595                     fixedMask = QRect(fX, fY, m_rect.width(), m_rect.height());
0596                 }
0597 
0598                 if (!fixedMask.isEmpty()) {
0599                     clearEffects = false;
0600                     KWindowEffects::enableBlurBehind(m_view->winId(), true, fixedMask);
0601                     KWindowEffects::enableBackgroundContrast(m_view->winId(),
0602                                                              m_theme.backgroundContrastEnabled(),
0603                                                              m_backEffectContrast,
0604                                                              m_backEffectIntesity,
0605                                                              m_backEffectSaturation,
0606                                                              fixedMask);
0607                 }
0608             }
0609         } else {
0610             //!  BEHAVEASPLASMAPANEL case
0611             clearEffects = false;
0612             KWindowEffects::enableBlurBehind(m_view->winId(), true);
0613             KWindowEffects::enableBackgroundContrast(m_view->winId(),
0614                                                      m_theme.backgroundContrastEnabled(),
0615                                                      m_backEffectContrast,
0616                                                      m_backEffectIntesity,
0617                                                      m_backEffectSaturation);
0618         }
0619     }
0620 
0621     if (clearEffects) {
0622         KWindowEffects::enableBlurBehind(m_view->winId(), false);
0623         KWindowEffects::enableBackgroundContrast(m_view->winId(), false);
0624     }
0625 }
0626 
0627 //!BEGIN draw panel shadows outside the dock window
0628 Plasma::FrameSvg::EnabledBorders Effects::enabledBorders() const
0629 {
0630     return m_enabledBorders;
0631 }
0632 
0633 qreal Effects::currentMidValue(const qreal &max, const qreal &factor, const qreal &min) const
0634 {
0635     if (max==min || factor==0) {
0636         return min;
0637     }
0638 
0639     qreal space = 0;
0640     qreal distance = 0;
0641 
0642     if (max<min) {
0643         space = min-max;
0644         distance = factor*space;
0645         return 1-distance;
0646     } else {
0647         space = max-min;
0648         distance = factor*space;
0649         return 1+distance;
0650     }
0651 }
0652 
0653 void Effects::updateBackgroundContrastValues()
0654 {
0655     if (!m_theme.backgroundContrastEnabled()) {
0656         m_backEffectContrast = 1.0;
0657         m_backEffectIntesity = 1.0;
0658         m_backEffectSaturation = 1.0;
0659         return;
0660     }
0661 
0662     if (m_backgroundOpacity == -1 /*Default plasma opacity option*/) {
0663         m_backEffectContrast = m_theme.backgroundContrast();
0664         m_backEffectIntesity = m_theme.backgroundIntensity();
0665         m_backEffectSaturation = m_theme.backgroundSaturation();
0666     } else {
0667         m_backEffectContrast = currentMidValue(m_theme.backgroundContrast(), m_backgroundOpacity, 1);
0668         m_backEffectIntesity = currentMidValue(m_theme.backgroundIntensity(), m_backgroundOpacity, 1);
0669         m_backEffectSaturation = currentMidValue(m_theme.backgroundSaturation(), m_backgroundOpacity, 1);
0670     }
0671 }
0672 
0673 void Effects::updateEnabledBorders()
0674 {
0675     if (!m_view->screen()) {
0676         return;
0677     }
0678 
0679     Plasma::FrameSvg::EnabledBorders borders = Plasma::FrameSvg::AllBorders;
0680 
0681     if (!m_view->screenEdgeMarginEnabled() && !m_backgroundAllCorners) {
0682         switch (m_view->location()) {
0683         case Plasma::Types::TopEdge:
0684             borders &= ~Plasma::FrameSvg::TopBorder;
0685             break;
0686 
0687         case Plasma::Types::LeftEdge:
0688             borders &= ~Plasma::FrameSvg::LeftBorder;
0689             break;
0690 
0691         case Plasma::Types::RightEdge:
0692             borders &= ~Plasma::FrameSvg::RightBorder;
0693             break;
0694 
0695         case Plasma::Types::BottomEdge:
0696             borders &= ~Plasma::FrameSvg::BottomBorder;
0697             break;
0698 
0699         default:
0700             break;
0701         }
0702     }
0703 
0704     if (!m_backgroundAllCorners) {
0705         if ((m_view->location() == Plasma::Types::LeftEdge || m_view->location() == Plasma::Types::RightEdge)) {
0706             if (m_view->maxLength() == 1 && m_view->alignment() == Latte::Types::Justify) {
0707                 if (!m_forceTopBorder) {
0708                     borders &= ~Plasma::FrameSvg::TopBorder;
0709                 }
0710 
0711                 if (!m_forceBottomBorder) {
0712                     borders &= ~Plasma::FrameSvg::BottomBorder;
0713                 }
0714             }
0715 
0716             if (m_view->alignment() == Latte::Types::Top && !m_forceTopBorder && m_view->offset() == 0) {
0717                 borders &= ~Plasma::FrameSvg::TopBorder;
0718             }
0719 
0720             if (m_view->alignment() == Latte::Types::Bottom && !m_forceBottomBorder && m_view->offset() == 0) {
0721                 borders &= ~Plasma::FrameSvg::BottomBorder;
0722             }
0723         }
0724 
0725         if (m_view->location() == Plasma::Types::TopEdge || m_view->location() == Plasma::Types::BottomEdge) {
0726             if (m_view->maxLength() == 1 && m_view->alignment() == Latte::Types::Justify) {
0727                 borders &= ~Plasma::FrameSvg::LeftBorder;
0728                 borders &= ~Plasma::FrameSvg::RightBorder;
0729             }
0730 
0731             if (m_view->alignment() == Latte::Types::Left && m_view->offset() == 0) {
0732                 borders &= ~Plasma::FrameSvg::LeftBorder;
0733             }
0734 
0735             if (m_view->alignment() == Latte::Types::Right  && m_view->offset() == 0) {
0736                 borders &= ~Plasma::FrameSvg::RightBorder;
0737             }
0738         }
0739     }
0740 
0741     m_hasTopLeftCorner =  (borders == Plasma::FrameSvg::AllBorders) || ((borders & Plasma::FrameSvg::TopBorder) && (borders & Plasma::FrameSvg::LeftBorder));
0742     m_hasTopRightCorner =  (borders == Plasma::FrameSvg::AllBorders) || ((borders & Plasma::FrameSvg::TopBorder) && (borders & Plasma::FrameSvg::RightBorder));
0743     m_hasBottomLeftCorner =  (borders == Plasma::FrameSvg::AllBorders) || ((borders & Plasma::FrameSvg::BottomBorder) && (borders & Plasma::FrameSvg::LeftBorder));
0744     m_hasBottomRightCorner =  (borders == Plasma::FrameSvg::AllBorders) || ((borders & Plasma::FrameSvg::BottomBorder) && (borders & Plasma::FrameSvg::RightBorder));
0745 
0746     if (m_enabledBorders != borders) {
0747         m_enabledBorders = borders;
0748         emit enabledBordersChanged();
0749     }
0750 
0751     if (!m_view->behaveAsPlasmaPanel() || !m_drawShadows) {
0752         PanelShadows::self()->removeWindow(m_view);
0753     } else {
0754         PanelShadows::self()->setEnabledBorders(m_view, borders);
0755     }
0756 }
0757 //!END draw panel shadows outside the dock window
0758 
0759 }
0760 }