File indexing completed on 2024-03-24 17:07:26

0001 /*
0002 *  Copyright 2016  Smith AR <audoban@openmailbox.org>
0003 *                  Michail Vourlakos <mvourlakos@gmail.com>
0004 *
0005 *  This file is part of Latte-Dock
0006 *
0007 *  Latte-Dock is free software; you can redistribute it and/or
0008 *  modify it under the terms of the GNU General Public License as
0009 *  published by the Free Software Foundation; either version 2 of
0010 *  the License, or (at your option) any later version.
0011 *
0012 *  Latte-Dock is distributed in the hope that it will be useful,
0013 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015 *  GNU General Public License for more details.
0016 *
0017 *  You should have received a copy of the GNU General Public License
0018 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0019 */
0020 
0021 #ifndef VISIBILITYMANAGER_H
0022 #define VISIBILITYMANAGER_H
0023 
0024 #include <array>
0025 
0026 // local
0027 #include "../plasma/quick/containmentview.h"
0028 #include "../../liblatte2/types.h"
0029 
0030 // Qt
0031 #include <QObject>
0032 #include <QTimer>
0033 
0034 // Plasma
0035 #include <Plasma/Containment>
0036 
0037 namespace Latte {
0038 class Corona;
0039 class View;
0040 namespace ViewPart {
0041 class ScreenEdgeGhostWindow;
0042 }
0043 namespace WindowSystem {
0044 class AbstractWindowInterface;
0045 }
0046 }
0047 
0048 namespace Latte {
0049 namespace ViewPart {
0050 
0051 class VisibilityManager : public QObject
0052 {
0053     Q_OBJECT
0054 
0055     Q_PROPERTY(Latte::Types::Visibility mode READ mode WRITE setMode NOTIFY modeChanged)
0056     Q_PROPERTY(bool raiseOnDesktop READ raiseOnDesktop WRITE setRaiseOnDesktop NOTIFY raiseOnDesktopChanged)
0057     Q_PROPERTY(bool raiseOnActivity READ raiseOnActivity WRITE setRaiseOnActivity NOTIFY raiseOnActivityChanged)
0058     Q_PROPERTY(bool isHidden READ isHidden WRITE setIsHidden NOTIFY isHiddenChanged)
0059     Q_PROPERTY(bool blockHiding READ blockHiding WRITE setBlockHiding NOTIFY blockHidingChanged)
0060     Q_PROPERTY(bool containsMouse READ containsMouse NOTIFY containsMouseChanged)
0061 
0062     //! KWin Edges Support Options
0063     Q_PROPERTY(bool enableKWinEdges READ enableKWinEdges WRITE setEnableKWinEdges NOTIFY enableKWinEdgesChanged)
0064     Q_PROPERTY(bool supportsKWinEdges READ supportsKWinEdges NOTIFY supportsKWinEdgesChanged)
0065 
0066     Q_PROPERTY(int timerShow READ timerShow WRITE setTimerShow NOTIFY timerShowChanged)
0067     Q_PROPERTY(int timerHide READ timerHide WRITE setTimerHide NOTIFY timerHideChanged)
0068 
0069 public:
0070     explicit VisibilityManager(PlasmaQuick::ContainmentView *view);
0071     virtual ~VisibilityManager();
0072 
0073     Latte::Types::Visibility mode() const;
0074     void setMode(Latte::Types::Visibility mode);
0075 
0076     void applyActivitiesToHiddenWindows(const QStringList &activities);
0077 
0078     bool raiseOnDesktop() const;
0079     void setRaiseOnDesktop(bool enable);
0080 
0081     bool raiseOnActivity() const;
0082     void setRaiseOnActivity(bool enable);
0083 
0084     bool isHidden() const;
0085     void setIsHidden(bool isHidden);
0086 
0087     bool blockHiding() const;
0088     void setBlockHiding(bool blockHiding);
0089 
0090     bool containsMouse() const;
0091 
0092     int timerShow() const;
0093     void setTimerShow(int msec);
0094 
0095     int timerHide() const;
0096     void setTimerHide(int msec);
0097 
0098     //! KWin Edges Support functions
0099     bool enableKWinEdges() const;
0100     void setEnableKWinEdges(bool enable);
0101 
0102     bool supportsKWinEdges() const;
0103 
0104 public slots:
0105     Q_INVOKABLE void hide();
0106     Q_INVOKABLE void show();
0107 
0108 signals:
0109     void mustBeShown();
0110     void mustBeHide();
0111 
0112     void slideOutFinished();
0113     void slideInFinished();
0114 
0115     void modeChanged();
0116     void raiseOnDesktopChanged();
0117     void raiseOnActivityChanged();
0118     void isHiddenChanged();
0119     void blockHidingChanged();
0120     void containsMouseChanged();
0121     void timerShowChanged();
0122     void timerHideChanged();
0123 
0124     //! KWin Edges Support signals
0125     void enableKWinEdgesChanged();
0126     void supportsKWinEdgesChanged();
0127 
0128 private slots:
0129     void saveConfig();
0130     void restoreConfig();
0131 
0132     //! KWin Edges Support functions
0133     void updateKWinEdgesSupport();
0134 
0135 private:
0136     void setContainsMouse(bool contains);
0137 
0138     void raiseView(bool raise);
0139     void raiseViewTemporarily();
0140 
0141     //! KWin Edges Support functions
0142     void createEdgeGhostWindow();
0143     void deleteEdgeGhostWindow();
0144     void updateGhostWindowState();
0145 
0146     void updateStrutsBasedOnLayoutsAndActivities(bool forceUpdate = false);
0147     void viewEventManager(QEvent *ev);
0148 
0149     QRect acceptableStruts();
0150 
0151 private slots:
0152     void dodgeAllWindows();
0153     void dodgeActive();
0154     void dodgeMaximized();
0155     void updateHiddenState();
0156 
0157 private:
0158     WindowSystem::AbstractWindowInterface *m_wm;
0159     Types::Visibility m_mode{Types::None};
0160     std::array<QMetaObject::Connection, 5> m_connections;
0161 
0162     QTimer m_timerShow;
0163     QTimer m_timerHide;
0164     QTimer m_timerStartUp;
0165 
0166     bool m_isHidden{false};
0167     bool m_dragEnter{false};
0168     bool m_blockHiding{false};
0169     bool m_containsMouse{false};
0170     bool m_raiseTemporarily{false};
0171     bool m_raiseOnDesktopChange{false};
0172     bool m_raiseOnActivityChange{false};
0173     bool m_hideNow{false};
0174 
0175     QRect m_publishedStruts;
0176 
0177     //! KWin Edges
0178     bool m_enableKWinEdgesFromUser{true};
0179     std::array<QMetaObject::Connection, 1> m_connectionsKWinEdges;
0180     ScreenEdgeGhostWindow *m_edgeGhostWindow{nullptr};
0181 
0182     Latte::Corona *m_corona{nullptr};
0183     Latte::View *m_latteView{nullptr};
0184 
0185 };
0186 
0187 }
0188 }
0189 #endif // VISIBILITYMANAGER_H