File indexing completed on 2024-07-07 05:13:56

0001 /*
0002     SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef WINDOWSYSTEMLASTACTIVEWINDOW_H
0007 #define WINDOWSYSTEMLASTACTIVEWINDOW_H
0008 
0009 // local
0010 #include "../windowinfowrap.h"
0011 #include "../abstractwindowinterface.h"
0012 
0013 // Qt
0014 #include <QObject>
0015 #include <QRect>
0016 
0017 namespace Latte {
0018 class View;
0019 namespace WindowSystem {
0020 class AbstractWindowInterface;
0021 namespace Tracker {
0022 class TrackedGeneralInfo;
0023 class Windows;
0024 }
0025 }
0026 }
0027 
0028 namespace Latte {
0029 namespace WindowSystem {
0030 namespace Tracker {
0031 
0032 class LastActiveWindow : public QObject {
0033     Q_OBJECT
0034     Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged)
0035 
0036     Q_PROPERTY(bool isActive READ isActive NOTIFY isActiveChanged)
0037     Q_PROPERTY(bool isMinimized READ isMinimized NOTIFY isMinimizedChanged)
0038     Q_PROPERTY(bool isMaximized READ isMaximized NOTIFY isMaximizedChanged)
0039     Q_PROPERTY(bool isFullScreen READ isFullScreen NOTIFY isFullScreenChanged)
0040     Q_PROPERTY(bool isKeepAbove READ isKeepAbove NOTIFY isKeepAboveChanged)
0041     Q_PROPERTY(bool isOnAllDesktops  READ isOnAllDesktops NOTIFY isOnAllDesktopsChanged)
0042     Q_PROPERTY(bool isShaded READ isShaded NOTIFY isShadedChanged)
0043     Q_PROPERTY(bool hasSkipTaskbar READ hasSkipTaskbar NOTIFY hasSkipTaskbarChanged)
0044 
0045     //! BEGIN: Window Abitilities
0046     /*since Latte v0.9.8*/
0047     Q_PROPERTY(bool isClosable READ isClosable NOTIFY isClosableChanged)
0048     Q_PROPERTY(bool isFullScreenable READ isFullScreenable NOTIFY isFullScreenableChanged)
0049     Q_PROPERTY(bool isGroupable READ isGroupable NOTIFY isGroupableChanged)
0050     Q_PROPERTY(bool isMaximizable READ isMaximizable NOTIFY isMaximizableChanged)
0051     Q_PROPERTY(bool isMinimizable READ isMinimizable NOTIFY isMinimizableChanged)
0052     Q_PROPERTY(bool isMovable READ isMovable NOTIFY isMovableChanged)
0053     Q_PROPERTY(bool isResizable READ isResizable NOTIFY isResizableChanged)
0054     Q_PROPERTY(bool isShadeable READ isShadeable NOTIFY isShadeableChanged)
0055     Q_PROPERTY(bool isVirtualDesktopChangeable READ isVirtualDesktopChangeable NOTIFY isVirtualDesktopChangeableChanged)
0056     //! END: Window Abitilities
0057 
0058     /*since Latte v0.9.4*/
0059     Q_PROPERTY(QString colorScheme READ colorScheme NOTIFY colorSchemeChanged)
0060 
0061     Q_PROPERTY(QString appName READ appName NOTIFY appNameChanged)
0062     Q_PROPERTY(QString display READ display NOTIFY displayChanged)
0063     Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged)
0064 
0065     Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged)
0066 
0067     Q_PROPERTY(QVariant winId READ currentWinId NOTIFY currentWinIdChanged)
0068 
0069 public:
0070     LastActiveWindow(TrackedGeneralInfo *trackedInfo);
0071     ~LastActiveWindow() override;
0072 
0073     bool isValid() const;
0074     bool isActive() const;
0075     bool isMinimized() const;
0076     bool isMaximized() const;
0077     bool isFullScreen() const;
0078     bool isKeepAbove() const;
0079     bool isOnAllDesktops() const;
0080     bool isShaded() const;
0081     bool hasSkipTaskbar() const;
0082 
0083     //! BEGIN: Window Abitilities
0084     /*since Latte v0.9.8*/
0085     bool isClosable() const;
0086     bool isFullScreenable() const;
0087     bool isGroupable() const;
0088     bool isMaximizable() const;
0089     bool isMinimizable() const;
0090     bool isMovable() const;
0091     bool isResizable() const;
0092     bool isShadeable() const;
0093     bool isVirtualDesktopChangeable() const;
0094     //! END: Window Abitilities
0095 
0096     QString appName() const;
0097     QString colorScheme() const;
0098     QString display() const;    
0099 
0100     QRect geometry() const;
0101     QIcon icon() const;
0102 
0103     QVariant currentWinId() const;
0104 
0105     void setInformation(const WindowInfoWrap &info);
0106 
0107 public slots:
0108     Q_INVOKABLE void requestActivate();
0109     Q_INVOKABLE void requestClose();
0110     Q_INVOKABLE void requestToggleIsOnAllDesktops();
0111     Q_INVOKABLE void requestToggleKeepAbove();
0112     Q_INVOKABLE void requestToggleMinimized();
0113     Q_INVOKABLE void requestToggleMaximized();
0114 
0115     Q_INVOKABLE bool canBeDragged();
0116 
0117     void requestMove(Latte::View *fromView, int localX, int localY);
0118 
0119     //! Debug
0120     void printHistory();
0121 
0122 private slots:
0123     void updateInformationFromHistory();
0124 
0125     void applicationDataChanged(const WindowId &wid);
0126 
0127     void windowChanged(const WindowId &wid);
0128     void windowRemoved(const WindowId &wid);
0129 
0130 signals:
0131     void colorSchemeChanged();
0132     void iconChanged();
0133     void isActiveChanged();
0134     void isMinimizedChanged();
0135     void isMaximizedChanged();
0136     void isFullScreenChanged();
0137     void isKeepAboveChanged();
0138     void isOnAllDesktopsChanged();
0139     void isShadedChanged();
0140     void isValidChanged();
0141     void hasSkipTaskbarChanged();
0142 
0143     //! BEGIN: Window Abitilities
0144     /*since Latte v0.9.8*/
0145     void isClosableChanged();
0146     void isFullScreenableChanged();
0147     void isGroupableChanged();
0148     void isMaximizableChanged();
0149     void isMinimizableChanged();
0150     void isMovableChanged();
0151     void isResizableChanged();
0152     void isShadeableChanged();
0153     void isVirtualDesktopChangeableChanged();
0154     //! END: Window Abitilities
0155 
0156     void appNameChanged();
0157     void displayChanged();
0158 
0159     void geometryChanged();
0160     void currentWinIdChanged();
0161 
0162     //! Debug
0163     void printRequested();
0164 
0165 private:
0166     void setActive(bool active);
0167     void setIsMinimized(bool minimized);
0168     void setIsMaximized(bool maximized);
0169     void setIsFullScreen(bool fullscreen);
0170     void setIsKeepAbove(bool above);
0171     void setIsOnAllDesktops(bool all);
0172     void setIsShaded(bool shaded);
0173     void setIsValid(bool valid);
0174     void setHasSkipTaskbar(bool skip);
0175 
0176     //! BEGIN: Window Abitilities
0177     /*since Latte v0.9.8*/
0178     void setIsClosable(bool closable);
0179     void setIsFullScreenable(bool fullscreenable);
0180     void setIsGroupable(bool groupable);
0181     void setIsMaximizable(bool maximizable);
0182     void setIsMinimizable(bool minimizable);
0183     void setIsMovable(bool movable);
0184     void setIsResizable(bool resizable);
0185     void setIsShadeable(bool shadeable);
0186     void setIsVirtualDesktopsChangeable(bool virtualdestkopschangeable);
0187     //! END: Window Abitilities
0188 
0189     void setColorScheme(QString scheme);
0190 
0191     void setAppName(QString appName);
0192     void setDisplay(QString display);
0193 
0194     void setGeometry(QRect geometry);
0195     void setIcon(QIcon icon);
0196 
0197     void setCurrentWinId(QVariant winId);
0198 
0199     void cleanHistory();
0200     void appendInHistory(const QVariant &wid);
0201     void removeFromHistory(const QVariant &wid);
0202 
0203     void updateColorScheme();
0204 
0205 private:
0206     bool m_isActive{false};
0207     bool m_isMinimized{false};
0208     bool m_isMaximized{false};
0209     bool m_isFullScreen{false};
0210     bool m_isKeepAbove{false};
0211     bool m_isOnAllDesktops{false};
0212     bool m_isShaded{false};
0213     bool m_isValid{false};
0214     bool m_hasSkipTaskbar{false};
0215 
0216     //! BEGIN: Window Abitilities
0217     /*since Latte v0.9.8*/
0218     bool m_isClosable{true};
0219     bool m_isFullScreenable{true};
0220     bool m_isGroupable{true};
0221     bool m_isMaximizable{true};
0222     bool m_isMinimizable{true};
0223     bool m_isMovable{true};
0224     bool m_isResizable{true};
0225     bool m_isShadeable{true};
0226     bool m_isVirtualDesktopsChangeable{true};
0227     //! END: Window Abitilities
0228 
0229     QString m_colorScheme;
0230 
0231     QString m_appName;
0232     QString m_display;
0233 
0234     QRect m_geometry;
0235     QIcon m_icon;
0236 
0237     QVariant m_currentWinId;
0238 
0239     QList<WindowId> m_history;
0240 
0241     TrackedGeneralInfo *m_trackedInfo{nullptr};
0242     AbstractWindowInterface *m_wm{nullptr};
0243     Tracker::Windows *m_windowsTracker{nullptr};
0244 };
0245 
0246 }
0247 }
0248 }
0249 
0250 #endif