File indexing completed on 2024-12-08 04:58:28
0001 /* 0002 SPDX-FileCopyrightText: 2016 Smith AR <audoban@openmailbox.org> 0003 SPDX-FileCopyrightText: 2016 Michail Vourlakos <mvourlakos@gmail.com> 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef ABSTRACTWINDOWINTERFACE_H 0008 #define ABSTRACTWINDOWINTERFACE_H 0009 0010 // local 0011 #include <coretypes.h> 0012 #include "schemecolors.h" 0013 #include "tasktools.h" 0014 #include "windowinfowrap.h" 0015 #include "tracker/windowstracker.h" 0016 0017 // C++ 0018 #include <unordered_map> 0019 #include <list> 0020 0021 // Qt 0022 #include <QObject> 0023 #include <QWindow> 0024 #include <QDBusServiceWatcher> 0025 #include <QDialog> 0026 #include <QMap> 0027 #include <QRect> 0028 #include <QPoint> 0029 #include <QPointer> 0030 #include <QScreen> 0031 #include <QTimer> 0032 0033 // KDE 0034 #include <KSharedConfig> 0035 #include <KActivities/Consumer> 0036 0037 // Plasma 0038 #include <Plasma> 0039 0040 0041 namespace Latte { 0042 class Corona; 0043 namespace WindowSystem { 0044 namespace Tracker { 0045 class Schemes; 0046 class Windows; 0047 } 0048 } 0049 } 0050 0051 namespace Latte { 0052 namespace WindowSystem { 0053 0054 class AbstractWindowInterface : public QObject 0055 { 0056 Q_OBJECT 0057 0058 public: 0059 enum class Slide 0060 { 0061 None, 0062 Top, 0063 Left, 0064 Bottom, 0065 Right, 0066 }; 0067 0068 explicit AbstractWindowInterface(QObject *parent = nullptr); 0069 virtual ~AbstractWindowInterface(); 0070 0071 virtual void setViewExtraFlags(QObject *view,bool isPanelWindow = true, Latte::Types::Visibility mode = Latte::Types::WindowsGoBelow) = 0; 0072 virtual void setViewStruts(QWindow &view, const QRect &rect 0073 , Plasma::Types::Location location) = 0; 0074 virtual void setWindowOnActivities(const WindowId &wid, const QStringList &activities) = 0; 0075 0076 virtual void removeViewStruts(QWindow &view) = 0; 0077 0078 virtual WindowId activeWindow() = 0; 0079 virtual WindowInfoWrap requestInfo(WindowId wid) = 0; 0080 virtual WindowInfoWrap requestInfoActive() = 0; 0081 0082 virtual void skipTaskBar(const QDialog &dialog) = 0; 0083 virtual void slideWindow(QWindow &view, Slide location) = 0; 0084 virtual void enableBlurBehind(QWindow &view) = 0; 0085 virtual void setActiveEdge(QWindow *view, bool active) = 0; 0086 0087 virtual void requestActivate(WindowId wid) = 0; 0088 virtual void requestClose(WindowId wid) = 0; 0089 virtual void requestMoveWindow(WindowId wid, QPoint from) = 0; 0090 virtual void requestToggleIsOnAllDesktops(WindowId wid) = 0; 0091 virtual void requestToggleKeepAbove(WindowId wid) = 0; 0092 virtual void requestToggleMinimized(WindowId wid) = 0; 0093 virtual void requestToggleMaximized(WindowId wid) = 0; 0094 virtual void setKeepAbove(WindowId wid, bool active) = 0; 0095 virtual void setKeepBelow(WindowId wid, bool active) = 0; 0096 0097 virtual bool windowCanBeDragged(WindowId wid) = 0; 0098 virtual bool windowCanBeMaximized(WindowId wid) = 0; 0099 0100 virtual QIcon iconFor(WindowId wid) = 0; 0101 virtual WindowId winIdFor(QString appId, QRect geometry) = 0; 0102 virtual WindowId winIdFor(QString appId, QString title) = 0; 0103 virtual AppData appDataFor(WindowId wid) = 0; 0104 0105 bool isKWinRunning() const; 0106 0107 bool inCurrentDesktopActivity(const WindowInfoWrap &winfo); 0108 bool isShowingDesktop() const; 0109 0110 bool hasBlockedTracking(const WindowId &wid) const; 0111 0112 QString currentDesktop(); 0113 QString currentActivity(); 0114 0115 virtual void registerIgnoredWindow(WindowId wid); 0116 virtual void unregisterIgnoredWindow(WindowId wid); 0117 0118 void registerPlasmaIgnoredWindow(WindowId wid); 0119 void unregisterPlasmaIgnoredWindow(WindowId wid); 0120 0121 void registerWhitelistedWindow(WindowId wid); 0122 void unregisterWhitelistedWindow(WindowId wid); 0123 0124 void switchToNextActivity(); 0125 void switchToPreviousActivity(); 0126 0127 virtual void switchToNextVirtualDesktop() = 0; 0128 virtual void switchToPreviousVirtualDesktop() = 0; 0129 0130 virtual void setFrameExtents(QWindow *view, const QMargins &margins) = 0; 0131 virtual void setInputMask(QWindow *window, const QRect &rect) = 0; 0132 0133 Latte::Corona *corona(); 0134 Tracker::Schemes *schemesTracker(); 0135 Tracker::Windows *windowsTracker() const; 0136 0137 signals: 0138 void activeWindowChanged(WindowId wid); 0139 void windowChanged(WindowId winfo); 0140 void windowAdded(WindowId wid); 0141 void windowRemoved(WindowId wid); 0142 void currentDesktopChanged(); 0143 void currentActivityChanged(); 0144 0145 void isShowingDesktopChanged(); 0146 0147 void latteWindowAdded(); 0148 0149 protected: 0150 QString m_currentDesktop; 0151 QString m_currentActivity; 0152 0153 //! windows that must be ignored from tracking, a good example are Latte::Views and 0154 //! their Configuration windows 0155 QList<WindowId> m_ignoredWindows; 0156 //! identified plasma panels 0157 QList<WindowId> m_plasmaIgnoredWindows; 0158 0159 //! identified whitelisted windows that can be tracked e.g. plasma widgets explorer and activities 0160 QList<WindowId> m_whitelistedWindows; 0161 0162 QPointer<KActivities::Consumer> m_activities; 0163 0164 //! Sending too fast plenty of signals for the same window 0165 //! has no reason and can create HIGH CPU usage. This Timer 0166 //! can delay the batch sending of signals for the same window 0167 WindowId m_windowChangedWaiting; 0168 QTimer m_windowWaitingTimer; 0169 0170 //! Plasma taskmanager rules ile 0171 KSharedConfig::Ptr rulesConfig; 0172 0173 void considerWindowChanged(WindowId wid); 0174 0175 bool isIgnored(const WindowId &wid) const; 0176 bool isRegisteredPlasmaIgnoredWindow(const WindowId &wid) const; 0177 bool isWhitelistedWindow(const WindowId &wid) const; 0178 0179 bool isFullScreenWindow(const QRect &wGeometry) const; 0180 bool isPlasmaPanel(const QRect &wGeometry) const; 0181 bool isSidepanel(const QRect &wGeometry) const; 0182 0183 bool isVirtualDesktopNavigationWrappingAround() const; 0184 0185 private slots: 0186 void initKWinInterface(); 0187 void windowRemovedSlot(WindowId wid); 0188 0189 void setIsShowingDesktop(const bool &showing); 0190 0191 void onVirtualDesktopNavigationWrappingAroundChanged(bool navigationWrappingAround); 0192 0193 private: 0194 bool m_isShowingDesktop{false}; 0195 0196 bool m_isKWinInterfaceAvailable{false}; 0197 bool m_isVirtualDesktopNavigationWrappingAround{true}; 0198 0199 Latte::Corona *m_corona; 0200 Tracker::Schemes *m_schemesTracker; 0201 Tracker::Windows *m_windowsTracker; 0202 0203 QDBusServiceWatcher *m_kwinServiceWatcher{nullptr}; 0204 }; 0205 0206 } 0207 } 0208 0209 #endif // ABSTRACTWINDOWINTERFACE_H