File indexing completed on 2024-11-03 13:42:57

0001 /*
0002 *  Copyright 2018  Michail Vourlakos <mvourlakos@gmail.com>
0003 *
0004 *  This file is part of Latte-Dock
0005 *
0006 *  Latte-Dock is free software; you can redistribute it and/or
0007 *  modify it under the terms of the GNU General Public License as
0008 *  published by the Free Software Foundation; either version 2 of
0009 *  the License, or (at your option) any later version.
0010 *
0011 *  Latte-Dock is distributed in the hope that it will be useful,
0012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 *  GNU General Public License for more details.
0015 *
0016 *  You should have received a copy of the GNU General Public License
0017 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 #ifndef POSITIONER_H
0021 #define POSITIONER_H
0022 
0023 //local
0024 #include "../wm/windowinfowrap.h"
0025 
0026 // Qt
0027 #include <QObject>
0028 #include <QPointer>
0029 #include <QScreen>
0030 #include <QTimer>
0031 
0032 // Plasma
0033 #include <Plasma/Containment>
0034 
0035 namespace Plasma {
0036 class Types;
0037 }
0038 
0039 namespace Latte {
0040 class Corona;
0041 class View;
0042 }
0043 
0044 namespace Latte {
0045 namespace ViewPart {
0046 
0047 class Positioner: public QObject
0048 {
0049     Q_OBJECT
0050 
0051     Q_PROPERTY(int currentScreenId READ currentScreenId NOTIFY currentScreenChanged)
0052     Q_PROPERTY(QString currentScreenName READ currentScreenName NOTIFY currentScreenChanged)
0053 
0054 public:
0055     Positioner(Latte::View *parent);
0056     virtual ~Positioner();
0057 
0058     int currentScreenId() const;
0059     QString currentScreenName() const;
0060 
0061     bool inLocationChangeAnimation();
0062     void setScreenToFollow(QScreen *scr, bool updateScreenId = true);
0063 
0064     void reconsiderScreen();
0065 
0066 public slots:
0067     Q_INVOKABLE void hideDockDuringLocationChange(int goToLocation);
0068     Q_INVOKABLE void hideDockDuringMovingToLayout(QString layoutName);
0069 
0070     Q_INVOKABLE bool setCurrentScreen(const QString id);
0071 
0072     void syncGeometry();
0073 
0074 signals:
0075     void currentScreenChanged();
0076     void edgeChanged();
0077     void screenGeometryChanged();
0078     void windowSizeChanged();
0079 
0080     //! these two signals are used from config ui and containment ui
0081     //! in order to orchestrate an animated hiding/showing of dock
0082     //! during changing location
0083     void hideDockDuringLocationChangeStarted();
0084     void hideDockDuringLocationChangeFinished();
0085     void hideDockDuringScreenChangeStarted();
0086     void hideDockDuringScreenChangeFinished();
0087     void hideDockDuringMovingToLayoutStarted();
0088     void hideDockDuringMovingToLayoutFinished();
0089     void onHideWindowsForSlidingOut();
0090     void showDockAfterLocationChangeFinished();
0091     void showDockAfterScreenChangeFinished();
0092     void showDockAfterMovingToLayoutFinished();
0093 
0094 private slots:
0095     void screenChanged(QScreen *screen);
0096     void validateDockGeometry();
0097 
0098 private:
0099     void init();
0100     void initSignalingForLocationChangeSliding();
0101     void resizeWindow(QRect availableScreenRect = QRect());
0102 
0103     void updateFormFactor();
0104     void updatePosition(QRect availableScreenRect = QRect());
0105 
0106     QRect maximumNormalGeometry();
0107 
0108 private:
0109     bool m_inDelete{false};
0110 
0111     //! it is used in order to enforce X11 to never miss window geometry
0112     QRect m_validGeometry;
0113 
0114     QPointer<Latte::View> m_view;
0115     QPointer<Latte::Corona> m_corona;
0116 
0117     QString m_screenToFollowId;
0118     QPointer<QScreen> m_screenToFollow;
0119     QTimer m_screenSyncTimer;
0120 
0121     QTimer m_validateGeometryTimer;
0122 
0123     //!used at sliding out/in animation
0124     QString m_moveToLayout;
0125     Plasma::Types::Location m_goToLocation{Plasma::Types::Floating};
0126     QScreen *m_goToScreen{nullptr};
0127 
0128     Latte::WindowSystem::WindowId m_trackedWindowId;
0129 };
0130 
0131 }
0132 }
0133 
0134 #endif