1 | /* |
2 | SPDX-FileCopyrightText: 2015 Eike Hein <hein.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | #ifndef WAYLAND_PLASMAWINDOWMODEL_H |
7 | #define WAYLAND_PLASMAWINDOWMODEL_H |
8 | |
9 | #include <QAbstractListModel> |
10 | |
11 | #include "KWayland/Client/kwaylandclient_export.h" |
12 | |
13 | namespace KWayland |
14 | { |
15 | namespace Client |
16 | { |
17 | class PlasmaWindowManagement; |
18 | class Surface; |
19 | |
20 | /** |
21 | * @short Exposes the window list and window state as a Qt item model. |
22 | * |
23 | * This class is a QAbstractListModel implementation that exposes information |
24 | * from a PlasmaWindowManagement instance passed as parent and enables convenient |
25 | * calls to PlasmaWindow methods through a model row index. |
26 | * |
27 | * The model is destroyed when the PlasmaWindowManagement parent is. |
28 | * |
29 | * The model resets when the PlasmaWindowManagement parent signals that its |
30 | * interface is about to be destroyed. |
31 | * |
32 | * To use this class you can create an instance yourself, or preferably use the |
33 | * convenience method in PlasmaWindowManagement: |
34 | * @code |
35 | * PlasmaWindowModel *model = wm->createWindowModel(); |
36 | * @endcode |
37 | * |
38 | * @see PlasmaWindowManagement |
39 | * @see PlasmaWindow |
40 | **/ |
41 | |
42 | class KWAYLANDCLIENT_EXPORT PlasmaWindowModel : public QAbstractListModel |
43 | { |
44 | Q_OBJECT |
45 | |
46 | public: |
47 | enum AdditionalRoles { |
48 | AppId = Qt::UserRole + 1, |
49 | IsActive, |
50 | IsFullscreenable, |
51 | IsFullscreen, |
52 | IsMaximizable, |
53 | IsMaximized, |
54 | IsMinimizable, |
55 | IsMinimized, |
56 | IsKeepAbove, |
57 | IsKeepBelow, |
58 | IsOnAllDesktops, |
59 | IsDemandingAttention, |
60 | SkipTaskbar, |
61 | /** |
62 | * @since 5.22 |
63 | */ |
64 | IsShadeable, |
65 | /** |
66 | * @since 5.22 |
67 | */ |
68 | IsShaded, |
69 | /** |
70 | * @since 5.22 |
71 | */ |
72 | IsMovable, |
73 | /** |
74 | * @since 5.22 |
75 | */ |
76 | IsResizable, |
77 | /** |
78 | * @since 5.22 |
79 | */ |
80 | IsVirtualDesktopChangeable, |
81 | /** |
82 | * @since 5.22 |
83 | */ |
84 | IsCloseable, |
85 | /** |
86 | * @since 5.25 |
87 | */ |
88 | Geometry, |
89 | /** |
90 | * @since 5.35 |
91 | */ |
92 | Pid, |
93 | /** |
94 | * @since 5.47 |
95 | */ |
96 | SkipSwitcher, |
97 | /** |
98 | * @since 5.53 |
99 | */ |
100 | VirtualDesktops, |
101 | /** |
102 | * @since 5.73 |
103 | */ |
104 | Uuid, |
105 | LastRole, |
106 | }; |
107 | Q_ENUM(AdditionalRoles) |
108 | |
109 | explicit PlasmaWindowModel(PlasmaWindowManagement *parent); |
110 | ~PlasmaWindowModel() override; |
111 | |
112 | QHash<int, QByteArray> roleNames() const override; |
113 | |
114 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
115 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
116 | |
117 | /** |
118 | * Returns an index with internalPointer() pointing to a PlasmaWindow instance. |
119 | **/ |
120 | QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override; |
121 | |
122 | QMap<int, QVariant> itemData(const QModelIndex &index) const override; |
123 | |
124 | /** |
125 | * Request the window at this model row index be activated. |
126 | **/ |
127 | Q_INVOKABLE void requestActivate(int row); |
128 | |
129 | /** |
130 | * Request the window at this model row index be closed. |
131 | **/ |
132 | Q_INVOKABLE void requestClose(int row); |
133 | |
134 | /** |
135 | * Request an interactive move for the window at this model row index. |
136 | * @since 5.22 |
137 | **/ |
138 | Q_INVOKABLE void requestMove(int row); |
139 | |
140 | /** |
141 | * Request an interactive resize for the window at this model row index. |
142 | * @since 5.22 |
143 | **/ |
144 | Q_INVOKABLE void requestResize(int row); |
145 | |
146 | /** |
147 | * Request the window at the model index @p row to be moved to the virtual desktop @p id. |
148 | * |
149 | * @since 5.90 |
150 | **/ |
151 | Q_INVOKABLE void requestEnterVirtualDesktop(int row, const QString &id); |
152 | |
153 | /** |
154 | * Requests the window at this model row index have its keep above state toggled. |
155 | * @since 5.35 |
156 | */ |
157 | Q_INVOKABLE void requestToggleKeepAbove(int row); |
158 | |
159 | /** |
160 | * Requests the window at this model row index have its keep above state toggled. |
161 | * @since 5.35 |
162 | */ |
163 | Q_INVOKABLE void requestToggleKeepBelow(int row); |
164 | |
165 | /** |
166 | * Requests the window at this model row index have its minimized state toggled. |
167 | */ |
168 | Q_INVOKABLE void requestToggleMinimized(int row); |
169 | |
170 | /** |
171 | * Requests the window at this model row index have its maximized state toggled. |
172 | */ |
173 | Q_INVOKABLE void requestToggleMaximized(int row); |
174 | |
175 | /** |
176 | * Requests the window at this model row index have its fullscreen state toggled. |
177 | * @since 6.0 |
178 | */ |
179 | Q_INVOKABLE void requestToggleFullscreen(int row); |
180 | |
181 | /** |
182 | * Sets the geometry of the taskbar entry for the window at the model row |
183 | * relative to a panel in particular. QRectF, intended for use from QML |
184 | * @since 5.5 |
185 | */ |
186 | Q_INVOKABLE void setMinimizedGeometry(int row, Surface *panel, const QRect &geom); |
187 | |
188 | /** |
189 | * Requests the window at this model row index have its shaded state toggled. |
190 | * @since 5.22 |
191 | */ |
192 | Q_INVOKABLE void requestToggleShaded(int row); |
193 | |
194 | private: |
195 | class Private; |
196 | QScopedPointer<Private> d; |
197 | }; |
198 | |
199 | } |
200 | } |
201 | |
202 | #endif |
203 | |