KWin
Loading...
Searching...
No Matches
workspace_wrapper.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2010 Rohan Prabhu <rohan@rohanprabhu.com>
6 SPDX-FileCopyrightText: 2011, 2012 Martin Gräßlin <mgraesslin@kde.org>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#include "workspace_wrapper.h"
12#include "core/output.h"
13#include "core/outputbackend.h"
14#include "cursor.h"
16#include "outline.h"
17#include "tiles/tilemanager.h"
18#include "virtualdesktops.h"
19#include "workspace.h"
20#include "x11window.h"
21#if KWIN_BUILD_ACTIVITIES
22#include "activities.h"
23#endif
24
25#include <QQmlEngine>
26
27namespace KWin
28{
29
31 : QObject(parent)
32{
34 KWin::VirtualDesktopManager *vds = KWin::VirtualDesktopManager::self();
42#if KWIN_BUILD_ACTIVITIES
43 if (KWin::Activities *activities = ws->activities()) {
49 }
50#endif
55}
56
58{
59 return VirtualDesktopManager::self()->currentDesktop();
60}
61
62QList<VirtualDesktop *> WorkspaceWrapper::desktops() const
63{
64 return VirtualDesktopManager::self()->desktops();
65}
66
68{
69 VirtualDesktopManager::self()->setCurrent(desktop);
70}
71
76
78{
79#if KWIN_BUILD_ACTIVITIES
80 if (!Workspace::self()->activities()) {
81 return QString();
82 }
83 return Workspace::self()->activities()->current();
84#else
85 return QString();
86#endif
87}
88
89void WorkspaceWrapper::setCurrentActivity(const QString &activity)
90{
91#if KWIN_BUILD_ACTIVITIES
92 if (Workspace::self()->activities()) {
93 Workspace::self()->activities()->setCurrent(activity);
94 }
95#endif
96}
97
99{
100#if KWIN_BUILD_ACTIVITIES
101 if (!Workspace::self()->activities()) {
102 return QStringList();
103 }
104 return Workspace::self()->activities()->all();
105#else
106 return QStringList();
107#endif
108}
109
111{
112 return Cursors::self()->mouse()->pos().toPoint();
113}
114
115#define SLOTWRAPPER(name) \
116 void WorkspaceWrapper::name() \
117 { \
118 Workspace::self()->name(); \
119 }
120
121SLOTWRAPPER(slotToggleShowDesktop)
122
123SLOTWRAPPER(slotWindowMaximize)
124SLOTWRAPPER(slotWindowMaximizeVertical)
125SLOTWRAPPER(slotWindowMaximizeHorizontal)
126SLOTWRAPPER(slotWindowMinimize)
127SLOTWRAPPER(slotWindowShade)
128SLOTWRAPPER(slotWindowRaise)
129SLOTWRAPPER(slotWindowLower)
130SLOTWRAPPER(slotWindowRaiseOrLower)
131SLOTWRAPPER(slotActivateAttentionWindow)
132SLOTWRAPPER(slotWindowMoveLeft)
133SLOTWRAPPER(slotWindowMoveRight)
134SLOTWRAPPER(slotWindowMoveUp)
135SLOTWRAPPER(slotWindowMoveDown)
136SLOTWRAPPER(slotWindowExpandHorizontal)
137SLOTWRAPPER(slotWindowExpandVertical)
138SLOTWRAPPER(slotWindowShrinkHorizontal)
139SLOTWRAPPER(slotWindowShrinkVertical)
140
141SLOTWRAPPER(slotIncreaseWindowOpacity)
142SLOTWRAPPER(slotLowerWindowOpacity)
143
144SLOTWRAPPER(slotWindowOperations)
145SLOTWRAPPER(slotWindowClose)
146SLOTWRAPPER(slotWindowMove)
147SLOTWRAPPER(slotWindowResize)
148SLOTWRAPPER(slotWindowAbove)
149SLOTWRAPPER(slotWindowBelow)
150SLOTWRAPPER(slotWindowOnAllDesktops)
151SLOTWRAPPER(slotWindowFullScreen)
152SLOTWRAPPER(slotWindowNoBorder)
153
154SLOTWRAPPER(slotWindowToNextDesktop)
155SLOTWRAPPER(slotWindowToPreviousDesktop)
156SLOTWRAPPER(slotWindowToDesktopRight)
157SLOTWRAPPER(slotWindowToDesktopLeft)
158SLOTWRAPPER(slotWindowToDesktopUp)
159SLOTWRAPPER(slotWindowToDesktopDown)
160
161SLOTWRAPPER(slotWindowToPrevScreen)
162SLOTWRAPPER(slotWindowToNextScreen)
163SLOTWRAPPER(slotWindowToLeftScreen)
164SLOTWRAPPER(slotWindowToRightScreen)
165SLOTWRAPPER(slotWindowToAboveScreen)
166SLOTWRAPPER(slotWindowToBelowScreen)
167
168SLOTWRAPPER(slotSwitchToPrevScreen)
169SLOTWRAPPER(slotSwitchToNextScreen)
170SLOTWRAPPER(slotSwitchToLeftScreen)
171SLOTWRAPPER(slotSwitchToRightScreen)
172SLOTWRAPPER(slotSwitchToAboveScreen)
173SLOTWRAPPER(slotSwitchToBelowScreen)
174
175#undef SLOTWRAPPER
176
177#define SLOTWRAPPER(name, modes) \
178 void WorkspaceWrapper::name() \
179 { \
180 Workspace::self()->quickTileWindow(modes); \
181 }
182
183SLOTWRAPPER(slotWindowQuickTileLeft, QuickTileFlag::Left)
184SLOTWRAPPER(slotWindowQuickTileRight, QuickTileFlag::Right)
185SLOTWRAPPER(slotWindowQuickTileTop, QuickTileFlag::Top)
186SLOTWRAPPER(slotWindowQuickTileBottom, QuickTileFlag::Bottom)
187SLOTWRAPPER(slotWindowQuickTileTopLeft, QuickTileFlag::Top | QuickTileFlag::Left)
188SLOTWRAPPER(slotWindowQuickTileTopRight, QuickTileFlag::Top | QuickTileFlag::Right)
189SLOTWRAPPER(slotWindowQuickTileBottomLeft, QuickTileFlag::Bottom | QuickTileFlag::Left)
190SLOTWRAPPER(slotWindowQuickTileBottomRight, QuickTileFlag::Bottom | QuickTileFlag::Right)
191
192#undef SLOTWRAPPER
193
194#define SLOTWRAPPER(name, direction) \
195 void WorkspaceWrapper::name() \
196 { \
197 Workspace::self()->switchWindow(Workspace::direction); \
198 }
199
200SLOTWRAPPER(slotSwitchWindowUp, DirectionNorth)
201SLOTWRAPPER(slotSwitchWindowDown, DirectionSouth)
202SLOTWRAPPER(slotSwitchWindowRight, DirectionEast)
203SLOTWRAPPER(slotSwitchWindowLeft, DirectionWest)
204
205#undef SLOTWRAPPER
206
207#define SLOTWRAPPER(name, direction) \
208 void WorkspaceWrapper::name() \
209 { \
210 VirtualDesktopManager::self()->moveTo(VirtualDesktopManager::Direction::direction, options->isRollOverDesktops()); \
211 }
212
213SLOTWRAPPER(slotSwitchDesktopNext, Next)
214SLOTWRAPPER(slotSwitchDesktopPrevious, Previous)
215SLOTWRAPPER(slotSwitchDesktopRight, Right)
216SLOTWRAPPER(slotSwitchDesktopLeft, Left)
217SLOTWRAPPER(slotSwitchDesktopUp, Up)
218SLOTWRAPPER(slotSwitchDesktopDown, Down)
219
220#undef SLOTWRAPPER
221
226
228{
229 return QSize(workspaceWidth(), workspaceHeight());
230}
231
233{
234 if (!c) {
235 return QRectF();
236 }
237 return Workspace::self()->clientArea(static_cast<clientAreaOption>(option), c);
238}
239
241{
242 if (!c) {
243 return QRectF();
244 }
245 return Workspace::self()->clientArea(static_cast<clientAreaOption>(option), c);
246}
247
249{
250 return workspace()->clientArea(static_cast<clientAreaOption>(option), output, desktop);
251}
252
253void WorkspaceWrapper::createDesktop(int position, const QString &name) const
254{
255 VirtualDesktopManager::self()->createVirtualDesktop(position, name);
256}
257
259{
260 VirtualDesktopManager::self()->removeVirtualDesktop(desktop->id());
261}
262
267
268void WorkspaceWrapper::showOutline(const QRect &geometry)
269{
270 workspace()->outline()->show(geometry);
271}
272
273void WorkspaceWrapper::showOutline(int x, int y, int width, int height)
274{
275 workspace()->outline()->show(QRect(x, y, width, height));
276}
277
282
283QList<KWin::Window *> WorkspaceWrapper::stackingOrder() const
284{
285 return workspace()->stackingOrder();
286}
287
289{
290 if (window) {
292 }
293}
294
296{
297 auto window = Workspace::self()->findClient(Predicate::WindowMatch, windowId);
298 QQmlEngine::setObjectOwnership(window, QQmlEngine::CppOwnership);
299 return window;
300}
301
302QList<KWin::Window *> WorkspaceWrapper::windowAt(const QPointF &pos, int count) const
303{
304 QList<KWin::Window *> result;
305 int found = 0;
306 const QList<Window *> &stacking = workspace()->stackingOrder();
307 if (stacking.isEmpty()) {
308 return result;
309 }
310 auto it = stacking.end();
311 do {
312 if (found == count) {
313 return result;
314 }
315 --it;
316 Window *window = (*it);
317 if (window->isDeleted()) {
318 continue;
319 }
320 if (!window->isOnCurrentActivity() || !window->isOnCurrentDesktop() || window->isMinimized() || window->isHidden() || window->isHiddenByShowDesktop()) {
321 continue;
322 }
323 if (window->hitTest(pos)) {
324 result.append(window);
325 found++;
326 }
327 } while (it != stacking.begin());
328 return result;
329}
330
331bool WorkspaceWrapper::isEffectActive(const QString &pluginId) const
332{
333 if (!effects) {
334 return false;
335 }
336 return effects->isEffectActive(pluginId);
337}
338
340{
341 return VirtualDesktopManager::self()->grid().size();
342}
343
345{
346 return desktopGridSize().width();
347}
348
350{
351 return desktopGridSize().height();
352}
353
355{
356 return desktopGridHeight() * workspace()->geometry().height();
357}
358
360{
361 return desktopGridWidth() * workspace()->geometry().width();
362}
363
368
369QList<Output *> WorkspaceWrapper::screens() const
370{
371 return workspace()->outputs();
372}
373
374Output *WorkspaceWrapper::screenAt(const QPointF &pos) const
375{
376 auto output = workspace()->outputAt(pos);
377 QQmlEngine::setObjectOwnership(output, QQmlEngine::CppOwnership);
378 return output;
379}
380
382{
383 return workspace()->geometry();
384}
385
387{
388 return workspace()->geometry().size();
389}
390
392{
393 workspace()->sendWindowToOutput(client, output);
394}
395
397{
398 Output *output = kwinApp()->outputBackend()->findOutput(screenName);
399 if (output) {
400 auto tileManager = workspace()->tileManager(output);
401 QQmlEngine::setObjectOwnership(tileManager, QQmlEngine::CppOwnership);
402 return tileManager;
403 }
404 return nullptr;
405}
406
408{
409 auto tileManager = workspace()->tileManager(output);
410 QQmlEngine::setObjectOwnership(tileManager, QQmlEngine::CppOwnership);
411 return tileManager;
412}
413
418
419QList<KWin::Window *> QtScriptWorkspaceWrapper::windowList() const
420{
421 return workspace()->windows();
422}
423
424QQmlListProperty<KWin::Window> DeclarativeScriptWorkspaceWrapper::windows()
425{
427}
428
429qsizetype DeclarativeScriptWorkspaceWrapper::countWindowList(QQmlListProperty<KWin::Window> *windows)
430{
431 return workspace()->windows().size();
432}
433
434KWin::Window *DeclarativeScriptWorkspaceWrapper::atWindowList(QQmlListProperty<KWin::Window> *windows, qsizetype index)
435{
436 return workspace()->windows().at(index);
437}
438
443
444} // KWin
445
446#include "moc_workspace_wrapper.cpp"
void added(const QString &id)
void currentChanged(const QString &id)
void removed(const QString &id)
QPointF pos()
Definition cursor.cpp:204
void posChanged(const QPointF &pos)
static Cursors * self()
Definition cursor.cpp:35
Cursor * mouse() const
Definition cursor.h:266
QQmlListProperty< KWin::Window > windows
static qsizetype countWindowList(QQmlListProperty< KWin::Window > *window)
DeclarativeScriptWorkspaceWrapper(QObject *parent=nullptr)
static KWin::Window * atWindowList(QQmlListProperty< KWin::Window > *windows, qsizetype index)
bool isEffectActive(const QString &pluginId) const
void hide()
Definition outline.cpp:52
void show()
Definition outline.cpp:38
QtScriptWorkspaceWrapper(QObject *parent=nullptr)
Q_INVOKABLE QList< KWin::Window * > windowList() const
Manages the number of available virtual desktops, the layout of those and which virtual desktop is th...
void layoutChanged(int columns, int rows)
void desktopAdded(KWin::VirtualDesktop *desktop)
void currentChanged(KWin::VirtualDesktop *previousDesktop, KWin::VirtualDesktop *newDesktop)
void desktopRemoved(KWin::VirtualDesktop *desktop)
bool isHidden() const
Definition window.cpp:4237
bool isOnCurrentActivity() const
Definition window.cpp:3097
bool isHiddenByShowDesktop() const
Definition window.cpp:4257
bool isOnCurrentDesktop() const
Definition window.cpp:848
bool isMinimized() const
Definition window.h:988
virtual bool hitTest(const QPointF &point) const
Definition window.cpp:381
bool isDeleted() const
Definition window.cpp:540
TileManager * tileManager(Output *output)
Window * activeWindow() const
Definition workspace.h:767
QRectF clientArea(clientAreaOption, const Output *output, const VirtualDesktop *desktop) const
X11Window * findClient(std::function< bool(const X11Window *)> func) const
Finds the first Client matching the condition expressed by passed in func.
void activateWindow(Window *window, bool force=false)
const QList< Window * > & stackingOrder() const
Definition workspace.h:788
void sendWindowToOutput(Window *window, Output *output)
void windowRemoved(KWin::Window *)
Output * activeOutput() const
Outline * outline() const
void raiseWindow(Window *window, bool nogroup=false)
Definition layers.cpp:354
void windowActivated(KWin::Window *)
static Workspace * self()
Definition workspace.h:91
void windowAdded(KWin::Window *)
QList< Output * > outputs() const
Definition workspace.h:762
const QList< Window * > windows() const
Definition workspace.h:248
QRect geometry() const
Output * outputAt(const QPointF &pos) const
void geometryChanged()
void outputsChanged()
QString supportInformation() const
void setCurrentActivity(const QString &activity)
Q_SCRIPTABLE QString supportInformation() const
void activitiesChanged(const QString &id)
Q_SCRIPTABLE QRectF clientArea(ClientAreaOption option, KWin::Output *output, KWin::VirtualDesktop *desktop) const
void setActiveWindow(Window *window)
WorkspaceWrapper(QObject *parent=nullptr)
void windowAdded(KWin::Window *window)
Q_INVOKABLE QList< KWin::Window * > windowAt(const QPointF &pos, int count=1) const
Q_SCRIPTABLE void createDesktop(int position, const QString &name) const
void currentDesktopChanged(KWin::VirtualDesktop *previous)
void virtualScreenGeometryChanged()
void setCurrentDesktop(VirtualDesktop *desktop)
QList< KWin::Window * > stackingOrder
Q_SCRIPTABLE void removeDesktop(KWin::VirtualDesktop *desktop) const
void showOutline(const QRect &geometry)
QList< KWin::Output * > screens
QList< KWin::VirtualDesktop * > desktops
QStringList activityList() const
void sendClientToScreen(KWin::Window *client, KWin::Output *output)
Q_SCRIPTABLE KWin::Window * getClient(qulonglong windowId)
void activityAdded(const QString &id)
void windowActivated(KWin::Window *window)
KWin::VirtualDesktop * currentDesktop
void currentActivityChanged(const QString &id)
void activityRemoved(const QString &id)
Q_INVOKABLE KWin::TileManager * tilingForScreen(const QString &screenName) const
Q_INVOKABLE KWin::Output * screenAt(const QPointF &pos) const
Q_INVOKABLE bool isEffectActive(const QString &pluginId) const
Q_INVOKABLE void raiseWindow(KWin::Window *window)
void windowRemoved(KWin::Window *window)
clientAreaOption
Definition globals.h:48
Workspace * workspace()
Definition workspace.h:830
EffectsHandler * effects
#define SLOTWRAPPER(name)