File indexing completed on 2024-04-28 16:49:32

0001 /*
0002 *  Copyright 2019  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 WINDOWSYSTEMWINDOWSTRACKER_H
0021 #define WINDOWSYSTEMWINDOWSTRACKER_H
0022 
0023 // local
0024 #include "../windowinfowrap.h"
0025 
0026 // Qt
0027 #include <QObject>
0028 
0029 #include <QHash>
0030 #include <QMap>
0031 #include <QTimer>
0032 
0033 namespace Latte {
0034 class View;
0035 namespace Layout {
0036 class GenericLayout;
0037 }
0038 namespace WindowSystem {
0039 class AbstractWindowInterface;
0040 class SchemeColors;
0041 namespace Tracker {
0042 class LastActiveWindow;
0043 class TrackedLayoutInfo;
0044 class TrackedViewInfo;
0045 }
0046 }
0047 }
0048 
0049 namespace Latte {
0050 namespace WindowSystem {
0051 namespace Tracker {
0052 
0053 class Windows : public QObject {
0054     Q_OBJECT
0055 
0056 public:
0057     Windows(AbstractWindowInterface *parent);
0058     ~Windows() override;
0059 
0060     void addView(Latte::View *view);
0061     void removeView(Latte::View *view);
0062 
0063     //! Views Tracking (current screen specific)
0064     bool enabled(Latte::View *view);
0065     void setEnabled(Latte::View *view, const bool enabled);
0066 
0067     bool activeWindowMaximized(Latte::View *view) const;
0068     bool activeWindowTouching(Latte::View *view) const;
0069     bool existsWindowActive(Latte::View *view) const;
0070     bool existsWindowMaximized(Latte::View *view) const;
0071     bool existsWindowTouching(Latte::View *view) const;
0072     bool isTouchingBusyVerticalView(Latte::View *view) const;
0073     SchemeColors *activeWindowScheme(Latte::View *view) const;
0074     SchemeColors *touchingWindowScheme(Latte::View *view) const;
0075     LastActiveWindow *lastActiveWindow(Latte::View *view);
0076 
0077     //! Layouts Tracking (all screens)
0078     bool enabled(Latte::Layout::GenericLayout *layout);
0079     bool activeWindowMaximized(Latte::Layout::GenericLayout *layout) const;
0080     bool existsWindowActive(Latte::Layout::GenericLayout *layout) const;
0081     bool existsWindowMaximized(Latte::Layout::GenericLayout *layout) const;
0082     SchemeColors *activeWindowScheme(Latte::Layout::GenericLayout *layout) const;
0083     LastActiveWindow *lastActiveWindow(Latte::Layout::GenericLayout *layout);
0084 
0085     //! Windows management
0086     bool isValidFor(const WindowId &wid) const;
0087     QIcon iconFor(const WindowId &wid);
0088     QString appNameFor(const WindowId &wid);
0089     WindowInfoWrap infoFor(const WindowId &wid) const;
0090 
0091     void setPlasmaDesktop(WindowId wid);
0092 
0093     AbstractWindowInterface *wm();
0094 
0095 signals:
0096     //! Views
0097     void enabledChanged(const Latte::View *view);
0098     void activeWindowMaximizedChanged(const Latte::View *view);
0099     void activeWindowTouchingChanged(const Latte::View *view);
0100     void existsWindowActiveChanged(const Latte::View *view);
0101     void existsWindowMaximizedChanged(const Latte::View *view);
0102     void existsWindowTouchingChanged(const Latte::View *view);
0103     void isTouchingBusyVerticalViewChanged(const Latte::View *view);
0104     void activeWindowSchemeChanged(const Latte::View *view);
0105     void touchingWindowSchemeChanged(const Latte::View *view);
0106     void informationAnnounced(const Latte::View *view);
0107 
0108     //! Layouts
0109     void enabledChangedForLayout(const Latte::Layout::GenericLayout *layout);
0110     void activeWindowMaximizedChangedForLayout(const Latte::Layout::GenericLayout *layout);
0111     void existsWindowActiveChangedForLayout(const Latte::Layout::GenericLayout *layout);
0112     void existsWindowMaximizedChangedForLayout(const Latte::Layout::GenericLayout *layout);
0113     void activeWindowSchemeChangedForLayout(const Latte::Layout::GenericLayout *layout);
0114     void informationAnnouncedForLayout(const Latte::Layout::GenericLayout *layout);
0115 
0116     //! overloading WM signals in order to update first m_windows and afterwards
0117     //! inform consumers for window changes
0118     void activeWindowChanged(const WindowId &wid);
0119     void windowChanged(const WindowId &wid);
0120     void windowRemoved(const WindowId &wid);
0121 
0122     void applicationDataChanged(const WindowId &wid);
0123 
0124 private slots:
0125     void updateAvailableScreenGeometries();
0126 
0127     void addRelevantLayout(Latte::View *view);
0128 
0129     void updateApplicationData();
0130     void updateRelevantLayouts();
0131     void updateExtraViewHints();
0132 
0133 private:
0134     void init();
0135     void initLayoutHints(Latte::Layout::GenericLayout *layout);
0136     void initViewHints(Latte::View *view);
0137     void cleanupFaultyWindows();
0138 
0139     void updateAllHints();
0140 
0141     //! Views
0142     void updateHints(Latte::View *view);
0143     void updateHints(Latte::Layout::GenericLayout *layout);
0144 
0145     void setActiveWindowMaximized(Latte::View *view, bool activeMaximized);
0146     void setActiveWindowTouching(Latte::View *view, bool activeTouching);
0147     void setExistsWindowActive(Latte::View *view, bool windowActive);
0148     void setExistsWindowMaximized(Latte::View *view, bool windowMaximized);
0149     void setExistsWindowTouching(Latte::View *view, bool windowTouching);
0150     void setIsTouchingBusyVerticalView(Latte::View *view, bool viewTouching);
0151     void setActiveWindowScheme(Latte::View *view, WindowSystem::SchemeColors *scheme);
0152     void setTouchingWindowScheme(Latte::View *view, WindowSystem::SchemeColors *scheme);
0153 
0154     //! Layouts
0155     void setActiveWindowMaximized(Latte::Layout::GenericLayout *layout, bool activeMaximized);
0156     void setExistsWindowActive(Latte::Layout::GenericLayout *layout, bool windowActive);
0157     void setExistsWindowMaximized(Latte::Layout::GenericLayout *layout, bool windowMaximized);
0158     void setActiveWindowScheme(Latte::Layout::GenericLayout *layout, WindowSystem::SchemeColors *scheme);
0159 
0160     //! Windows
0161     bool intersects(Latte::View *view, const WindowInfoWrap &winfo);
0162     bool isActive(const WindowInfoWrap &winfo);
0163     bool isActiveInViewScreen(Latte::View *view, const WindowInfoWrap &winfo);
0164     bool isMaximizedInViewScreen(Latte::View *view, const WindowInfoWrap &winfo);
0165     bool isTouchingView(Latte::View *view, const WindowSystem::WindowInfoWrap &winfo);
0166     bool isTouchingViewEdge(Latte::View *view, const WindowInfoWrap &winfo);
0167 
0168 private:
0169     //! a timer in order to not overload the views extra hints checking because it is not
0170     //! really needed that often
0171     QTimer m_extraViewHintsTimer;
0172 
0173     AbstractWindowInterface *m_wm;
0174     QHash<Latte::View *, TrackedViewInfo *> m_views;
0175     QHash<Latte::Layout::GenericLayout *, TrackedLayoutInfo *> m_layouts;
0176 
0177     QMap<WindowId, WindowInfoWrap> m_windows;
0178 
0179     //! Some applications delay their application name/icon identification
0180     //! such as Libreoffice that updates its StartupWMClass after
0181     //! its startup
0182     QTimer m_updateApplicationDataTimer;
0183     QList<WindowId> m_delayedApplicationData;
0184     QList<WindowId> m_initializedApplicationData;
0185 };
0186 
0187 }
0188 }
0189 }
0190 
0191 #endif