1 | /******************************************************************** |
2 | KWin - the KDE window manager |
3 | This file is part of the KDE project. |
4 | |
5 | Copyright (C) 2010 Rohan Prabhu <rohan@rohanprabhu.com> |
6 | Copyright (C) 2012 Martin Gräßlin <mgraesslin@kde.org> |
7 | |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | *********************************************************************/ |
21 | |
22 | #ifndef KWIN_SCRIPTING_WORKSPACE_WRAPPER_H |
23 | #define KWIN_SCRIPTING_WORKSPACE_WRAPPER_H |
24 | |
25 | #include <QObject> |
26 | #include <QSize> |
27 | #include <QStringList> |
28 | #include <QRect> |
29 | #include <kwinglobals.h> |
30 | |
31 | namespace KWin |
32 | { |
33 | // forward declarations |
34 | class Client; |
35 | |
36 | class WorkspaceWrapper : public QObject |
37 | { |
38 | Q_OBJECT |
39 | Q_ENUMS(ClientAreaOption) |
40 | Q_ENUMS(ElectricBorder) |
41 | Q_PROPERTY(int currentDesktop READ currentDesktop WRITE setCurrentDesktop NOTIFY currentDesktopChanged) |
42 | Q_PROPERTY(KWin::Client *activeClient READ activeClient WRITE setActiveClient NOTIFY clientActivated) |
43 | // TODO: write and notify? |
44 | Q_PROPERTY(QSize desktopGridSize READ desktopGridSize NOTIFY desktopLayoutChanged) |
45 | Q_PROPERTY(int desktopGridWidth READ desktopGridWidth NOTIFY desktopLayoutChanged) |
46 | Q_PROPERTY(int desktopGridHeight READ desktopGridHeight NOTIFY desktopLayoutChanged) |
47 | Q_PROPERTY(int workspaceWidth READ workspaceWidth) |
48 | Q_PROPERTY(int workspaceHeight READ workspaceHeight) |
49 | Q_PROPERTY(QSize workspaceSize READ workspaceSize) |
50 | /** |
51 | * The number of desktops currently used. Minimum number of desktops is 1, maximum 20. |
52 | **/ |
53 | Q_PROPERTY(int desktops READ numberOfDesktops WRITE setNumberOfDesktops NOTIFY numberDesktopsChanged) |
54 | /** |
55 | * The same of the display, that is all screens. |
56 | **/ |
57 | Q_PROPERTY(QSize displaySize READ displaySize) |
58 | /** |
59 | * The width of the display, that is width of all combined screens. |
60 | **/ |
61 | Q_PROPERTY(int displayWidth READ displayWidth) |
62 | /** |
63 | * The height of the display, that is height of all combined screens. |
64 | **/ |
65 | Q_PROPERTY(int displayHeight READ displayHeight) |
66 | Q_PROPERTY(int activeScreen READ activeScreen) |
67 | Q_PROPERTY(int numScreens READ numScreens NOTIFY numberScreensChanged) |
68 | Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY currentActivityChanged) |
69 | Q_PROPERTY(QStringList activities READ activityList NOTIFY activitiesChanged) |
70 | |
71 | private: |
72 | Q_DISABLE_COPY(WorkspaceWrapper) |
73 | |
74 | signals: |
75 | void desktopPresenceChanged(KWin::Client *client, int desktop); |
76 | void currentDesktopChanged(int desktop, KWin::Client *client); |
77 | void clientAdded(KWin::Client *client); |
78 | void clientRemoved(KWin::Client *client); |
79 | void clientManaging(KWin::Client *client); |
80 | void clientMinimized(KWin::Client *client); |
81 | void clientUnminimized(KWin::Client *client); |
82 | void clientRestored(KWin::Client *client); |
83 | void clientMaximizeSet(KWin::Client *client, bool h, bool v); |
84 | void killWindowCalled(KWin::Client *client); |
85 | void clientActivated(KWin::Client *client); |
86 | void clientFullScreenSet(KWin::Client *client, bool fullScreen, bool user); |
87 | void clientSetKeepAbove(KWin::Client *client, bool keepAbove); |
88 | /** |
89 | * Signal emitted whenever the number of desktops changed. |
90 | * To get the current number of desktops use the property desktops. |
91 | * @param oldNumberOfDesktops The previous number of desktops. |
92 | **/ |
93 | void numberDesktopsChanged(uint oldNumberOfDesktops); |
94 | /** |
95 | * Signal emitted whenever the layout of virtual desktops changed. |
96 | * That is desktopGrid(Size/Width/Height) will have new values. |
97 | * @since 4.11 |
98 | **/ |
99 | void desktopLayoutChanged(); |
100 | /** |
101 | * The demands attention state for Client @p c changed to @p set. |
102 | * @param c The Client for which demands attention changed |
103 | * @param set New value of demands attention |
104 | **/ |
105 | void clientDemandsAttentionChanged(KWin::Client *client, bool set); |
106 | /** |
107 | * Signal emitted when the number of screens changes. |
108 | * @param count The new number of screens |
109 | **/ |
110 | void numberScreensChanged(int count); |
111 | /** |
112 | * This signal is emitted when the size of @p screen changes. |
113 | * Don't forget to fetch an updated client area. |
114 | **/ |
115 | void screenResized(int screen); |
116 | /** |
117 | * Signal emitted whenever the current activity changed. |
118 | * @param id id of the new activity |
119 | **/ |
120 | void currentActivityChanged(const QString &id); |
121 | /** |
122 | * Signal emitted whenever the list of activities changed. |
123 | * @param id id of the new activity |
124 | **/ |
125 | void activitiesChanged(const QString &id); |
126 | /** |
127 | * This signal is emitted when a new activity is added |
128 | * @param id id of the new activity |
129 | */ |
130 | void activityAdded(const QString &id); |
131 | /** |
132 | * This signal is emitted when the activity |
133 | * is removed |
134 | * @param id id of the removed activity |
135 | */ |
136 | void activityRemoved(const QString &id); |
137 | |
138 | public: |
139 | //------------------------------------------------------------------ |
140 | //enums copy&pasted from kwinglobals.h because qtscript is evil |
141 | |
142 | enum ClientAreaOption { |
143 | ///< geometry where a window will be initially placed after being mapped |
144 | PlacementArea, |
145 | ///< window movement snapping area? ignore struts |
146 | MovementArea, |
147 | ///< geometry to which a window will be maximized |
148 | MaximizeArea, |
149 | ///< like MaximizeArea, but ignore struts - used e.g. for topmenu |
150 | MaximizeFullArea, |
151 | ///< area for fullscreen windows |
152 | FullScreenArea, |
153 | ///< whole workarea (all screens together) |
154 | WorkArea, |
155 | ///< whole area (all screens together), ignore struts |
156 | FullArea, |
157 | ///< one whole screen, ignore struts |
158 | ScreenArea |
159 | }; |
160 | enum ElectricBorder { |
161 | ElectricTop, |
162 | ElectricTopRight, |
163 | ElectricRight, |
164 | ElectricBottomRight, |
165 | ElectricBottom, |
166 | ElectricBottomLeft, |
167 | ElectricLeft, |
168 | ElectricTopLeft, |
169 | ELECTRIC_COUNT, |
170 | ElectricNone |
171 | }; |
172 | |
173 | explicit WorkspaceWrapper(QObject* parent = 0); |
174 | #define GETTERSETTERDEF( rettype, getter, setter ) \ |
175 | rettype getter() const; \ |
176 | void setter( rettype val ); |
177 | GETTERSETTERDEF(int, numberOfDesktops, setNumberOfDesktops) |
178 | GETTERSETTERDEF(int, currentDesktop, setCurrentDesktop) |
179 | GETTERSETTERDEF(KWin::Client*, activeClient, setActiveClient) |
180 | #undef GETTERSETTERDEF |
181 | QSize desktopGridSize() const; |
182 | int desktopGridWidth() const; |
183 | int desktopGridHeight() const; |
184 | int workspaceWidth() const; |
185 | int workspaceHeight() const; |
186 | QSize workspaceSize() const; |
187 | int displayWidth() const; |
188 | int displayHeight() const; |
189 | QSize displaySize() const; |
190 | int activeScreen() const; |
191 | int numScreens() const; |
192 | QString currentActivity() const; |
193 | QStringList activityList() const; |
194 | |
195 | /** |
196 | * List of Clients currently managed by KWin. |
197 | **/ |
198 | Q_INVOKABLE QList< KWin::Client* > clientList() const; |
199 | /** |
200 | * Returns the geometry a Client can use with the specified option. |
201 | * This method should be preferred over other methods providing screen sizes as the |
202 | * various options take constraints such as struts set on panels into account. |
203 | * This method is also multi screen aware, but there are also options to get full areas. |
204 | * @param option The type of area which should be considered |
205 | * @param screen The screen for which the area should be considered |
206 | * @param desktop The desktop for which the area should be considered, in general there should not be a difference |
207 | * @returns The specified screen geometry |
208 | **/ |
209 | Q_SCRIPTABLE QRect clientArea(ClientAreaOption option, int screen, int desktop) const; |
210 | /** |
211 | * Overloaded method for convenience. |
212 | * @param option The type of area which should be considered |
213 | * @param point The coordinates which have to be included in the area |
214 | * @param desktop The desktop for which the area should be considered, in general there should not be a difference |
215 | * @returns The specified screen geometry |
216 | **/ |
217 | Q_SCRIPTABLE QRect clientArea(ClientAreaOption option, const QPoint& point, int desktop) const; |
218 | /** |
219 | * Overloaded method for convenience. |
220 | * @param client The Client for which the area should be retrieved |
221 | * @returns The specified screen geometry |
222 | **/ |
223 | Q_SCRIPTABLE QRect clientArea(ClientAreaOption option, const KWin::Client* client) const; |
224 | /** |
225 | * Returns the name for the given @p desktop. |
226 | **/ |
227 | Q_SCRIPTABLE QString desktopName(int desktop) const; |
228 | /** |
229 | * Provides support information about the currently running KWin instance. |
230 | **/ |
231 | Q_SCRIPTABLE QString supportInformation() const; |
232 | /** |
233 | * Finds the Client with the given @p windowId. |
234 | * @param windowId The window Id of the Client |
235 | * @return The found Client or @c null |
236 | **/ |
237 | Q_SCRIPTABLE KWin::Client *getClient(qulonglong windowId); |
238 | |
239 | public Q_SLOTS: |
240 | // all the available key bindings |
241 | void slotSwitchDesktopNext(); |
242 | void slotSwitchDesktopPrevious(); |
243 | void slotSwitchDesktopRight(); |
244 | void slotSwitchDesktopLeft(); |
245 | void slotSwitchDesktopUp(); |
246 | void slotSwitchDesktopDown(); |
247 | |
248 | void slotSwitchToNextScreen(); |
249 | void slotWindowToNextScreen(); |
250 | void slotToggleShowDesktop(); |
251 | |
252 | void slotWindowMaximize(); |
253 | void slotWindowMaximizeVertical(); |
254 | void slotWindowMaximizeHorizontal(); |
255 | void slotWindowMinimize(); |
256 | void slotWindowShade(); |
257 | void slotWindowRaise(); |
258 | void slotWindowLower(); |
259 | void slotWindowRaiseOrLower(); |
260 | void slotActivateAttentionWindow(); |
261 | void slotWindowPackLeft(); |
262 | void slotWindowPackRight(); |
263 | void slotWindowPackUp(); |
264 | void slotWindowPackDown(); |
265 | void slotWindowGrowHorizontal(); |
266 | void slotWindowGrowVertical(); |
267 | void slotWindowShrinkHorizontal(); |
268 | void slotWindowShrinkVertical(); |
269 | void slotWindowQuickTileLeft(); |
270 | void slotWindowQuickTileRight(); |
271 | void slotWindowQuickTileTopLeft(); |
272 | void slotWindowQuickTileTopRight(); |
273 | void slotWindowQuickTileBottomLeft(); |
274 | void slotWindowQuickTileBottomRight(); |
275 | |
276 | void slotSwitchWindowUp(); |
277 | void slotSwitchWindowDown(); |
278 | void slotSwitchWindowRight(); |
279 | void slotSwitchWindowLeft(); |
280 | |
281 | void slotIncreaseWindowOpacity(); |
282 | void slotLowerWindowOpacity(); |
283 | |
284 | void slotWindowOperations(); |
285 | void slotWindowClose(); |
286 | void slotWindowMove(); |
287 | void slotWindowResize(); |
288 | void slotWindowAbove(); |
289 | void slotWindowBelow(); |
290 | void slotWindowOnAllDesktops(); |
291 | void slotWindowFullScreen(); |
292 | void slotWindowNoBorder(); |
293 | |
294 | void slotWindowToNextDesktop(); |
295 | void slotWindowToPreviousDesktop(); |
296 | void slotWindowToDesktopRight(); |
297 | void slotWindowToDesktopLeft(); |
298 | void slotWindowToDesktopUp(); |
299 | void slotWindowToDesktopDown(); |
300 | |
301 | /** |
302 | * Shows an outline at the specified @p geometry. |
303 | * If an outline is already shown the outline is moved to the new position. |
304 | * Use @link hideOutline to remove the outline again. |
305 | **/ |
306 | void showOutline(const QRect &geometry); |
307 | /** |
308 | * Overloaded method for convenience. |
309 | **/ |
310 | void showOutline(int x, int y, int width, int height); |
311 | /** |
312 | * Hides the outline previously shown by @link showOutline. |
313 | **/ |
314 | void hideOutline(); |
315 | |
316 | private Q_SLOTS: |
317 | void setupClientConnections(KWin::Client* client); |
318 | }; |
319 | |
320 | } |
321 | |
322 | #endif |
323 | |