Changeset View
Changeset View
Standalone View
Standalone View
virtualdesktops.h
Show All 21 Lines | |||||
22 | // KWin | 22 | // KWin | ||
23 | #include <kwinglobals.h> | 23 | #include <kwinglobals.h> | ||
24 | #include <kwin_export.h> | 24 | #include <kwin_export.h> | ||
25 | // Qt includes | 25 | // Qt includes | ||
26 | #include <QObject> | 26 | #include <QObject> | ||
27 | #include <QPoint> | 27 | #include <QPoint> | ||
28 | #include <QPointer> | 28 | #include <QPointer> | ||
29 | #include <QSize> | 29 | #include <QSize> | ||
30 | | ||||
30 | // KDE includes | 31 | // KDE includes | ||
31 | #include <KConfig> | 32 | #include <KConfig> | ||
32 | #include <KSharedConfig> | 33 | #include <KSharedConfig> | ||
33 | 34 | | |||
34 | class KLocalizedString; | 35 | class KLocalizedString; | ||
35 | class NETRootInfo; | 36 | class NETRootInfo; | ||
36 | class QAction; | 37 | class QAction; | ||
37 | 38 | | |||
39 | namespace KWayland | ||||
40 | { | ||||
41 | namespace Server | ||||
42 | { | ||||
43 | class PlasmaVirtualDesktopManagementInterface; | ||||
44 | } | ||||
45 | } | ||||
46 | | ||||
38 | namespace KWin { | 47 | namespace KWin { | ||
39 | 48 | | |||
40 | class KWIN_EXPORT VirtualDesktop : public QObject | 49 | class KWIN_EXPORT VirtualDesktop : public QObject | ||
41 | { | 50 | { | ||
42 | Q_OBJECT | 51 | Q_OBJECT | ||
43 | Q_PROPERTY(QByteArray id READ id CONSTANT) | 52 | Q_PROPERTY(QByteArray id READ id CONSTANT) | ||
44 | Q_PROPERTY(uint x11DesktopNumber READ x11DesktopNumber CONSTANT) | 53 | Q_PROPERTY(uint x11DesktopNumber READ x11DesktopNumber NOTIFY x11DesktopNumberChanged) | ||
45 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) | 54 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) | ||
46 | public: | 55 | public: | ||
47 | explicit VirtualDesktop(QObject *parent = nullptr); | 56 | explicit VirtualDesktop(QObject *parent = nullptr); | ||
48 | virtual ~VirtualDesktop(); | 57 | virtual ~VirtualDesktop(); | ||
49 | 58 | | |||
50 | void setId(const QByteArray &id); | 59 | void setId(const QByteArray &id); | ||
51 | QByteArray id() const { | 60 | QByteArray id() const { | ||
52 | return m_id; | 61 | return m_id; | ||
53 | } | 62 | } | ||
54 | 63 | | |||
55 | void setName(const QString &name); | 64 | void setName(const QString &name); | ||
56 | QString name() const { | 65 | QString name() const { | ||
57 | return m_name; | 66 | return m_name; | ||
58 | } | 67 | } | ||
59 | 68 | | |||
60 | void setX11DesktopNumber(uint number); | 69 | void setX11DesktopNumber(uint number); | ||
61 | uint x11DesktopNumber() const { | 70 | uint x11DesktopNumber() const { | ||
62 | return m_x11DesktopNumber; | 71 | return m_x11DesktopNumber; | ||
63 | } | 72 | } | ||
64 | 73 | | |||
65 | Q_SIGNALS: | 74 | Q_SIGNALS: | ||
66 | void nameChanged(); | 75 | void nameChanged(); | ||
76 | void x11DesktopNumberChanged(); | ||||
67 | /** | 77 | /** | ||
68 | * Emitted just before the desktop gets destroyed. | 78 | * Emitted just before the desktop gets destroyed. | ||
69 | **/ | 79 | **/ | ||
70 | void aboutToBeDestroyed(); | 80 | void aboutToBeDestroyed(); | ||
71 | 81 | | |||
72 | private: | 82 | private: | ||
73 | QByteArray m_id; | 83 | QByteArray m_id; | ||
74 | QString m_name; | 84 | QString m_name; | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 143 | { | |||
143 | Q_PROPERTY(uint current READ current WRITE setCurrent NOTIFY currentChanged) | 153 | Q_PROPERTY(uint current READ current WRITE setCurrent NOTIFY currentChanged) | ||
144 | /** | 154 | /** | ||
145 | * Whether navigation in the desktop layout wraps around at the borders. | 155 | * Whether navigation in the desktop layout wraps around at the borders. | ||
146 | **/ | 156 | **/ | ||
147 | Q_PROPERTY(bool navigationWrappingAround READ isNavigationWrappingAround WRITE setNavigationWrappingAround NOTIFY navigationWrappingAroundChanged) | 157 | Q_PROPERTY(bool navigationWrappingAround READ isNavigationWrappingAround WRITE setNavigationWrappingAround NOTIFY navigationWrappingAroundChanged) | ||
148 | public: | 158 | public: | ||
149 | virtual ~VirtualDesktopManager(); | 159 | virtual ~VirtualDesktopManager(); | ||
150 | /** | 160 | /** | ||
151 | * @internal | 161 | * @internal, for X11 case | ||
152 | **/ | 162 | **/ | ||
153 | void setRootInfo(NETRootInfo *info); | 163 | void setRootInfo(NETRootInfo *info); | ||
154 | /** | 164 | /** | ||
165 | * @internal, for Wayland case | ||||
166 | **/ | ||||
167 | void setVirtualDesktopManagement(KWayland::Server::PlasmaVirtualDesktopManagementInterface *management); | ||||
168 | /** | ||||
155 | * @internal | 169 | * @internal | ||
156 | **/ | 170 | **/ | ||
157 | void setConfig(KSharedConfig::Ptr config); | 171 | void setConfig(KSharedConfig::Ptr config); | ||
158 | /** | 172 | /** | ||
159 | * @returns Total number of desktops currently in existence. | 173 | * @returns Total number of desktops currently in existence. | ||
160 | * @see setCount | 174 | * @see setCount | ||
161 | * @see countChanged | 175 | * @see countChanged | ||
162 | */ | 176 | */ | ||
163 | uint count() const; | 177 | uint count() const; | ||
164 | /** | 178 | /** | ||
179 | * @returns the number of rows the layout has. | ||||
180 | * @see setRows | ||||
181 | * @see rowsChanged | ||||
182 | */ | ||||
183 | uint rows() const; | ||||
184 | /** | ||||
165 | * @returns The ID of the current desktop. | 185 | * @returns The ID of the current desktop. | ||
166 | * @see setCurrent | 186 | * @see setCurrent | ||
167 | * @see currentChanged | 187 | * @see currentChanged | ||
168 | */ | 188 | */ | ||
169 | uint current() const; | 189 | uint current() const; | ||
170 | /** | 190 | /** | ||
171 | * @returns The current desktop | 191 | * @returns The current desktop | ||
172 | * @see setCurrent | 192 | * @see setCurrent | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | |||||
259 | } | 279 | } | ||
260 | 280 | | |||
261 | /** | 281 | /** | ||
262 | * @returns The VirtualDesktop for the x11 @p id, if no such VirtualDesktop @c null is returned | 282 | * @returns The VirtualDesktop for the x11 @p id, if no such VirtualDesktop @c null is returned | ||
263 | **/ | 283 | **/ | ||
264 | VirtualDesktop *desktopForX11Id(uint id) const; | 284 | VirtualDesktop *desktopForX11Id(uint id) const; | ||
265 | 285 | | |||
266 | /** | 286 | /** | ||
287 | * @returns The VirtualDesktop for the internal desktop string @p id, if no such VirtualDesktop @c null is returned | ||||
288 | **/ | ||||
289 | VirtualDesktop *desktopForId(const QByteArray &id) const; | ||||
290 | | ||||
291 | /** | ||||
292 | * Create a new virtual desktop at the requested position. | ||||
293 | * The difference with setCount is that setCount always adds new desktops at the end of the chain. The Id is automatically generated. | ||||
294 | * @param x11DesktopNumber number for the desktop. The desktop created will have an | ||||
295 | * x11DesktopNumber guaranteed to be between 1 and numberOfDesktops(). | ||||
296 | * Existing desktops will eventually have their x11DesktopNumber increased. | ||||
297 | * @param name The name for the new desktop, if empty the default name will be used. | ||||
298 | * @returns the new VirtualDesktop, nullptr if we reached the maximum number of desktops | ||||
299 | */ | ||||
300 | VirtualDesktop *createVirtualDesktop(uint x11DesktopNumber, const QString &name = QString()); | ||||
301 | | ||||
302 | /** | ||||
303 | * Remove the virtual desktop identified by id, if it exists | ||||
304 | * difference with setCount is that is possible to remove an arbitrary desktop, | ||||
305 | * not only the last one. | ||||
306 | * @param id the string id of the desktop to remove | ||||
307 | */ | ||||
308 | void removeVirtualDesktop(const QByteArray &id); | ||||
309 | | ||||
310 | /** | ||||
267 | * Updates the net root info for new number of desktops | 311 | * Updates the net root info for new number of desktops | ||
268 | **/ | 312 | **/ | ||
269 | void updateRootInfo(); | 313 | void updateRootInfo(); | ||
270 | 314 | | |||
271 | /** | 315 | /** | ||
272 | * @returns The maximum number of desktops that KWin supports. | 316 | * @returns The maximum number of desktops that KWin supports. | ||
273 | */ | 317 | */ | ||
274 | static uint maximum(); | 318 | static uint maximum(); | ||
Show All 29 Lines | 320 | public Q_SLOTS: | |||
304 | * Set the current desktop to @a current. | 348 | * Set the current desktop to @a current. | ||
305 | * @returns True on success, false otherwise. | 349 | * @returns True on success, false otherwise. | ||
306 | * @see current | 350 | * @see current | ||
307 | * @see currentChanged | 351 | * @see currentChanged | ||
308 | * @see moveTo | 352 | * @see moveTo | ||
309 | **/ | 353 | **/ | ||
310 | bool setCurrent(VirtualDesktop *current); | 354 | bool setCurrent(VirtualDesktop *current); | ||
311 | /** | 355 | /** | ||
356 | * Updates the layout to a new number of rows. The number of columns will be calculated accordingly | ||||
357 | */ | ||||
358 | void setRows(uint rows); | ||||
359 | /** | ||||
312 | * Called from within setCount() to ensure the desktop layout is still valid. | 360 | * Called from within setCount() to ensure the desktop layout is still valid. | ||
313 | */ | 361 | */ | ||
314 | void updateLayout(); | 362 | void updateLayout(); | ||
315 | /** | 363 | /** | ||
316 | * @param enable wrapping around borders for navigation in desktop layout | 364 | * @param enable wrapping around borders for navigation in desktop layout | ||
317 | * @see isNavigationWrappingAround | 365 | * @see isNavigationWrappingAround | ||
318 | * @see navigationWrappingAroundChanged | 366 | * @see navigationWrappingAroundChanged | ||
319 | **/ | 367 | **/ | ||
Show All 9 Lines | |||||
329 | 377 | | |||
330 | Q_SIGNALS: | 378 | Q_SIGNALS: | ||
331 | /** | 379 | /** | ||
332 | * Signal emitted whenever the number of virtual desktops changes. | 380 | * Signal emitted whenever the number of virtual desktops changes. | ||
333 | * @param previousCount The number of desktops prior to the change | 381 | * @param previousCount The number of desktops prior to the change | ||
334 | * @param newCount The new current number of desktops | 382 | * @param newCount The new current number of desktops | ||
335 | **/ | 383 | **/ | ||
336 | void countChanged(uint previousCount, uint newCount); | 384 | void countChanged(uint previousCount, uint newCount); | ||
385 | | ||||
337 | /** | 386 | /** | ||
338 | * Signal emitted whenever the number of virtual desktops changes in a way | 387 | * Signal when the number of rows in the layout changes | ||
339 | * that existing desktops are removed. | 388 | * @param new number of rows | ||
340 | * | 389 | */ | ||
341 | * The signal is emitted after the @c count property has been updated but prior | 390 | void rowsChanged(uint rows); | ||
342 | * to the @link countChanged signal being emitted. | 391 | | ||
343 | * @param previousCount The number of desktops prior to the change. | 392 | /** | ||
344 | * @see countChanged | 393 | * A new desktop has been created | ||
345 | * @see setCount | 394 | * @param desktop the new just crated desktop | ||
346 | * @see count | 395 | */ | ||
347 | **/ | 396 | void desktopCreated(KWin::VirtualDesktop *desktop); | ||
348 | void desktopsRemoved(uint previousCount); | 397 | | ||
398 | /** | ||||
399 | * A desktop has been removed and is about to be deleted | ||||
400 | * @param desktop the desktop that has been removed. | ||||
401 | * It's guaranteed to stil la valid pointer when the signal arrives, | ||||
402 | * but it's about to be deleted. | ||||
403 | */ | ||||
404 | void desktopRemoved(KWin::VirtualDesktop *desktop); | ||||
405 | | ||||
349 | /** | 406 | /** | ||
350 | * Signal emitted whenever the current desktop changes. | 407 | * Signal emitted whenever the current desktop changes. | ||
351 | * @param previousDesktop The virtual desktop changed from | 408 | * @param previousDesktop The virtual desktop changed from | ||
352 | * @param newDesktop The virtual desktop changed to | 409 | * @param newDesktop The virtual desktop changed to | ||
353 | **/ | 410 | **/ | ||
354 | void currentChanged(uint previousDesktop, uint newDesktop); | 411 | void currentChanged(uint previousDesktop, uint newDesktop); | ||
355 | /** | 412 | /** | ||
356 | * Signal emitted whenever the desktop layout changes. | 413 | * Signal emitted whenever the desktop layout changes. | ||
Show All 35 Lines | 423 | private Q_SLOTS: | |||
392 | void slotUp(); | 449 | void slotUp(); | ||
393 | /** | 450 | /** | ||
394 | * Slot for switch to desktop below action. | 451 | * Slot for switch to desktop below action. | ||
395 | **/ | 452 | **/ | ||
396 | void slotDown(); | 453 | void slotDown(); | ||
397 | 454 | | |||
398 | private: | 455 | private: | ||
399 | /** | 456 | /** | ||
400 | * This method is called when the number of desktops is updated in a way that desktops | | |||
401 | * are removed. At the time when this method is invoked the count property is already | | |||
402 | * updated but the corresponding signal has not been emitted yet. | | |||
403 | * | | |||
404 | * Ensures that in case the current desktop is on one of the removed | | |||
405 | * desktops the last desktop after the change becomes the new desktop. | | |||
406 | * Emits the signal @link desktopsRemoved. | | |||
407 | * | | |||
408 | * @param previousCount The number of desktops prior to the change. | | |||
409 | * @param previousCurrent The number of the previously current desktop. | | |||
410 | * @see setCount | | |||
411 | * @see desktopsRemoved | | |||
412 | **/ | | |||
413 | void handleDesktopsRemoved(uint previousCount, uint previousCurrent); | | |||
414 | /** | | |||
415 | * Generate a desktop layout from EWMH _NET_DESKTOP_LAYOUT property parameters. | 457 | * Generate a desktop layout from EWMH _NET_DESKTOP_LAYOUT property parameters. | ||
416 | */ | 458 | */ | ||
417 | void setNETDesktopLayout(Qt::Orientation orientation, uint width, uint height, int startingCorner); | 459 | void setNETDesktopLayout(Qt::Orientation orientation, uint width, uint height, int startingCorner); | ||
418 | /** | 460 | /** | ||
419 | * @returns A default name for the given @p desktop | 461 | * @returns A default name for the given @p desktop | ||
420 | **/ | 462 | **/ | ||
421 | QString defaultName(int desktop) const; | 463 | QString defaultName(int desktop) const; | ||
422 | /** | 464 | /** | ||
Show All 22 Lines | |||||
445 | QAction *addAction(const QString &name, const QString &label, void (VirtualDesktopManager::*slot)()); | 487 | QAction *addAction(const QString &name, const QString &label, void (VirtualDesktopManager::*slot)()); | ||
446 | 488 | | |||
447 | QVector<VirtualDesktop*> m_desktops; | 489 | QVector<VirtualDesktop*> m_desktops; | ||
448 | QPointer<VirtualDesktop> m_current; | 490 | QPointer<VirtualDesktop> m_current; | ||
449 | bool m_navigationWrapsAround; | 491 | bool m_navigationWrapsAround; | ||
450 | VirtualDesktopGrid m_grid; | 492 | VirtualDesktopGrid m_grid; | ||
451 | // TODO: QPointer | 493 | // TODO: QPointer | ||
452 | NETRootInfo *m_rootInfo; | 494 | NETRootInfo *m_rootInfo; | ||
495 | KWayland::Server::PlasmaVirtualDesktopManagementInterface *m_virtualDesktopManagement = nullptr; | ||||
453 | KSharedConfig::Ptr m_config; | 496 | KSharedConfig::Ptr m_config; | ||
497 | bool m_isLoading = false; | ||||
454 | 498 | | |||
455 | KWIN_SINGLETON_VARIABLE(VirtualDesktopManager, s_manager) | 499 | KWIN_SINGLETON_VARIABLE(VirtualDesktopManager, s_manager) | ||
456 | }; | 500 | }; | ||
457 | 501 | | |||
458 | /** | 502 | /** | ||
459 | * Function object to select the desktop above in the layout. | 503 | * Function object to select the desktop above in the layout. | ||
460 | * Note: does not switch to the desktop! | 504 | * Note: does not switch to the desktop! | ||
461 | **/ | 505 | **/ | ||
▲ Show 20 Lines • Show All 232 Lines • Show Last 20 Lines |