File indexing completed on 2026-08-09 14:49:40
0001 /* 0002 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "virtualdesktops.h" 0010 0011 #include <QAbstractListModel> 0012 #include <QPointer> 0013 #include <QSortFilterProxyModel> 0014 0015 #include <optional> 0016 0017 namespace KWin 0018 { 0019 class Window; 0020 class Output; 0021 0022 namespace ScriptingModels::V3 0023 { 0024 0025 class ClientModel : public QAbstractListModel 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 enum Roles { 0031 ClientRole = Qt::UserRole + 1, 0032 ScreenRole, 0033 DesktopRole, 0034 ActivityRole 0035 }; 0036 0037 explicit ClientModel(QObject *parent = nullptr); 0038 0039 QHash<int, QByteArray> roleNames() const override; 0040 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0041 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0042 0043 private: 0044 void markRoleChanged(Window *client, int role); 0045 0046 void handleClientAdded(Window *client); 0047 void handleClientRemoved(Window *client); 0048 void setupClientConnections(Window *client); 0049 0050 QList<Window *> m_clients; 0051 }; 0052 0053 class ClientFilterModel : public QSortFilterProxyModel 0054 { 0055 Q_OBJECT 0056 Q_PROPERTY(ClientModel *clientModel READ clientModel WRITE setClientModel NOTIFY clientModelChanged) 0057 Q_PROPERTY(QString activity READ activity WRITE setActivity RESET resetActivity NOTIFY activityChanged) 0058 Q_PROPERTY(KWin::VirtualDesktop *desktop READ desktop WRITE setDesktop RESET resetDesktop NOTIFY desktopChanged) 0059 Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) 0060 Q_PROPERTY(QString screenName READ screenName WRITE setScreenName RESET resetScreenName NOTIFY screenNameChanged) 0061 Q_PROPERTY(WindowTypes windowType READ windowType WRITE setWindowType RESET resetWindowType NOTIFY windowTypeChanged) 0062 Q_PROPERTY(bool minimizedWindows READ minimizedWindows WRITE setMinimizedWindows NOTIFY minimizedWindowsChanged) 0063 0064 public: 0065 enum WindowType { 0066 Normal = 0x1, 0067 Dialog = 0x2, 0068 Dock = 0x4, 0069 Desktop = 0x8, 0070 Notification = 0x10, 0071 CriticalNotification = 0x20, 0072 }; 0073 Q_DECLARE_FLAGS(WindowTypes, WindowType) 0074 Q_FLAG(WindowTypes) 0075 0076 explicit ClientFilterModel(QObject *parent = nullptr); 0077 0078 ClientModel *clientModel() const; 0079 void setClientModel(ClientModel *clientModel); 0080 0081 QString activity() const; 0082 void setActivity(const QString &activity); 0083 void resetActivity(); 0084 0085 VirtualDesktop *desktop() const; 0086 void setDesktop(VirtualDesktop *desktop); 0087 void resetDesktop(); 0088 0089 QString filter() const; 0090 void setFilter(const QString &filter); 0091 0092 QString screenName() const; 0093 void setScreenName(const QString &screenName); 0094 void resetScreenName(); 0095 0096 WindowTypes windowType() const; 0097 void setWindowType(WindowTypes windowType); 0098 void resetWindowType(); 0099 0100 void setMinimizedWindows(bool show); 0101 bool minimizedWindows() const; 0102 0103 protected: 0104 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; 0105 0106 Q_SIGNALS: 0107 void activityChanged(); 0108 void desktopChanged(); 0109 void screenNameChanged(); 0110 void clientModelChanged(); 0111 void filterChanged(); 0112 void windowTypeChanged(); 0113 void minimizedWindowsChanged(); 0114 0115 private: 0116 WindowTypes windowTypeMask(Window *client) const; 0117 0118 ClientModel *m_clientModel = nullptr; 0119 std::optional<QString> m_activity; 0120 QPointer<Output> m_output; 0121 QPointer<VirtualDesktop> m_desktop; 0122 QString m_filter; 0123 std::optional<WindowTypes> m_windowType; 0124 bool m_showMinimizedWindows = true; 0125 }; 0126 0127 } // namespace ScriptingModels::V3 0128 } // namespace KWin