KWindowSystem

kwindowinfo.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 #include "kwindowinfo.h"
8 #include "kwindowinfo_p.h"
9 #include "kwindowsystem.h"
10 #include "pluginwrapper_p.h"
11 
12 #include <config-kwindowsystem.h>
13 
14 #include "kwindowinfo_dummy_p.h"
15 
16 #include <QRect>
17 
18 // private
19 KWindowInfoPrivate *KWindowInfoPrivate::create(WId window, NET::Properties properties, NET::Properties2 properties2)
20 {
21  return KWindowSystemPluginWrapper::self().createWindowInfo(window, properties, properties2);
22 }
23 
24 KWindowInfoPrivateDesktopFileNameExtension::KWindowInfoPrivateDesktopFileNameExtension() = default;
25 KWindowInfoPrivateDesktopFileNameExtension::~KWindowInfoPrivateDesktopFileNameExtension() = default;
26 
27 KWindowInfoPrivatePidExtension::KWindowInfoPrivatePidExtension() = default;
28 KWindowInfoPrivatePidExtension::~KWindowInfoPrivatePidExtension() = default;
29 
30 KWindowInfoPrivateAppMenuExtension::KWindowInfoPrivateAppMenuExtension() = default;
31 KWindowInfoPrivateAppMenuExtension::~KWindowInfoPrivateAppMenuExtension() = default;
32 
33 class Q_DECL_HIDDEN KWindowInfoPrivate::Private
34 {
35 public:
36  Private(WId window, NET::Properties properties, NET::Properties2 properties2);
37  WId window;
38  NET::Properties properties;
39  NET::Properties2 properties2;
40  KWindowInfoPrivateDesktopFileNameExtension *desktopFileNameExtension;
41  KWindowInfoPrivatePidExtension *pidExtension;
42  KWindowInfoPrivateAppMenuExtension *appMenuExtension;
43 };
44 
45 KWindowInfoPrivate::Private::Private(WId window, NET::Properties properties, NET::Properties2 properties2)
46  : window(window)
47  , properties(properties)
48  , properties2(properties2)
49  , desktopFileNameExtension(nullptr)
50  , pidExtension(nullptr)
51  , appMenuExtension(nullptr)
52 {
53 }
54 
55 KWindowInfoPrivate::KWindowInfoPrivate(WId window, NET::Properties properties, NET::Properties2 properties2)
56  : d(new Private(window, properties, properties2))
57 {
58 }
59 
60 KWindowInfoPrivate::~KWindowInfoPrivate()
61 {
62 }
63 
64 WId KWindowInfoPrivate::win() const
65 {
66  return d->window;
67 }
68 
69 KWindowInfoPrivateDesktopFileNameExtension *KWindowInfoPrivate::desktopFileNameExtension() const
70 {
71  return d->desktopFileNameExtension;
72 }
73 
74 void KWindowInfoPrivate::installDesktopFileNameExtension(KWindowInfoPrivateDesktopFileNameExtension *extension)
75 {
76  d->desktopFileNameExtension = extension;
77 }
78 
79 KWindowInfoPrivatePidExtension *KWindowInfoPrivate::pidExtension() const
80 {
81  return d->pidExtension;
82 }
83 
84 void KWindowInfoPrivate::installPidExtension(KWindowInfoPrivatePidExtension *extension)
85 {
86  d->pidExtension = extension;
87 }
88 
89 KWindowInfoPrivateAppMenuExtension *KWindowInfoPrivate::appMenuExtension() const
90 {
91  return d->appMenuExtension;
92 }
93 
94 void KWindowInfoPrivate::installAppMenuExtension(KWindowInfoPrivateAppMenuExtension *extension)
95 {
96  d->appMenuExtension = extension;
97 }
98 
99 KWindowInfoPrivateDummy::KWindowInfoPrivateDummy(WId window, NET::Properties properties, NET::Properties2 properties2)
100  : KWindowInfoPrivate(window, properties, properties2)
101 {
102 }
103 
104 KWindowInfoPrivateDummy::~KWindowInfoPrivateDummy()
105 {
106 }
107 
108 bool KWindowInfoPrivateDummy::valid(bool withdrawn_is_valid) const
109 {
110  Q_UNUSED(withdrawn_is_valid)
111  return false;
112 }
113 
114 NET::States KWindowInfoPrivateDummy::state() const
115 {
116  return NET::States();
117 }
118 
119 bool KWindowInfoPrivateDummy::isMinimized() const
120 {
121  return false;
122 }
123 
124 NET::MappingState KWindowInfoPrivateDummy::mappingState() const
125 {
126  return NET::Visible;
127 }
128 
129 NETExtendedStrut KWindowInfoPrivateDummy::extendedStrut() const
130 {
131  return NETExtendedStrut();
132 }
133 
134 NET::WindowType KWindowInfoPrivateDummy::windowType(NET::WindowTypes supported_types) const
135 {
136  Q_UNUSED(supported_types)
137  return NET::Unknown;
138 }
139 
140 QString KWindowInfoPrivateDummy::visibleName() const
141 {
142  return QString();
143 }
144 
145 QString KWindowInfoPrivateDummy::visibleNameWithState() const
146 {
147  return QString();
148 }
149 
150 QString KWindowInfoPrivateDummy::name() const
151 {
152  return QString();
153 }
154 
155 QString KWindowInfoPrivateDummy::visibleIconName() const
156 {
157  return QString();
158 }
159 
160 QString KWindowInfoPrivateDummy::visibleIconNameWithState() const
161 {
162  return QString();
163 }
164 
165 QString KWindowInfoPrivateDummy::iconName() const
166 {
167  return QString();
168 }
169 
170 bool KWindowInfoPrivateDummy::onAllDesktops() const
171 {
172  return false;
173 }
174 
175 bool KWindowInfoPrivateDummy::isOnDesktop(int desktop) const
176 {
177  Q_UNUSED(desktop)
178  return false;
179 }
180 
181 int KWindowInfoPrivateDummy::desktop() const
182 {
183  return 0;
184 }
185 
186 QStringList KWindowInfoPrivateDummy::activities() const
187 {
188  return QStringList();
189 }
190 
191 QRect KWindowInfoPrivateDummy::geometry() const
192 {
193  return QRect();
194 }
195 
196 QRect KWindowInfoPrivateDummy::frameGeometry() const
197 {
198  return QRect();
199 }
200 
201 WId KWindowInfoPrivateDummy::transientFor() const
202 {
203  return 0;
204 }
205 
206 WId KWindowInfoPrivateDummy::groupLeader() const
207 {
208  return 0;
209 }
210 
211 QByteArray KWindowInfoPrivateDummy::windowClassClass() const
212 {
213  return QByteArray();
214 }
215 
216 QByteArray KWindowInfoPrivateDummy::windowClassName() const
217 {
218  return QByteArray();
219 }
220 
221 QByteArray KWindowInfoPrivateDummy::windowRole() const
222 {
223  return QByteArray();
224 }
225 
226 QByteArray KWindowInfoPrivateDummy::clientMachine() const
227 {
228  return QByteArray();
229 }
230 
231 bool KWindowInfoPrivateDummy::actionSupported(NET::Action action) const
232 {
233  Q_UNUSED(action)
234  return false;
235 }
236 
237 // public
238 KWindowInfo::KWindowInfo(WId window, NET::Properties properties, NET::Properties2 properties2)
239  : d(KWindowInfoPrivate::create(window, properties, properties2))
240 {
241 }
242 
244  : d(other.d)
245 {
246 }
247 
248 KWindowInfo::~KWindowInfo()
249 {
250 }
251 
253 {
254  if (d != other.d) {
255  d = other.d;
256  }
257  return *this;
258 }
259 
260 // clang-format off
261 
262 #define DELEGATE(name, args) \
263  return d->name(args);
264 
265 bool KWindowInfo::valid(bool withdrawn_is_valid) const
266 {
267  DELEGATE(valid, withdrawn_is_valid)
268 }
269 
270 WId KWindowInfo::win() const
271 {
272  return d->win();
273 }
274 
276 {
277  DELEGATE(state, )
278 }
279 
281 {
282  return (state() & s) == s;
283 }
284 
286 {
287  DELEGATE(isMinimized, )
288 }
289 
291 {
292  DELEGATE(mappingState, )
293 }
294 
296 {
297  DELEGATE(extendedStrut, )
298 }
299 
301 {
302  DELEGATE(windowType, supported_types)
303 }
304 
306 {
307  DELEGATE(visibleName, )
308 }
309 
311 {
312  DELEGATE(visibleNameWithState, )
313 }
314 
316 {
317  DELEGATE(name, )
318 }
319 
321 {
322  DELEGATE(visibleIconName, )
323 }
324 
326 {
327  DELEGATE(visibleIconNameWithState, )
328 }
329 
331 {
332  DELEGATE(iconName, )
333 }
334 
336 {
338 }
339 
340 bool KWindowInfo::isOnDesktop(int desktop) const
341 {
342  DELEGATE(isOnDesktop, desktop)
343 }
344 
346 {
347  DELEGATE(onAllDesktops, )
348 }
349 
351 {
352  DELEGATE(desktop, )
353 }
354 
356 {
357  DELEGATE(activities, )
358 }
359 
361 {
362  DELEGATE(geometry, )
363 }
364 
366 {
367  DELEGATE(frameGeometry, )
368 }
369 
371 {
372  DELEGATE(transientFor, )
373 }
374 
376 {
377  DELEGATE(groupLeader, )
378 }
379 
381 {
382  DELEGATE(windowClassClass, )
383 }
384 
386 {
387  DELEGATE(windowClassName, )
388 }
389 
391 {
392  DELEGATE(windowRole, )
393 }
394 
396 {
397  DELEGATE(clientMachine, )
398 }
399 
401 {
402  DELEGATE(actionSupported, action)
403 }
404 
406 {
407  if (auto extension = d->desktopFileNameExtension()) {
408  return extension->desktopFileName();
409  }
410  return QByteArray();
411 }
412 
414 {
415  if (auto extension = d->appMenuExtension()) {
416  return extension->applicationMenuServiceName();
417  }
418  return QByteArray();
419 }
420 
422 {
423  if (auto extension = d->appMenuExtension()) {
424  return extension->applicationMenuObjectPath();
425  }
426  return QByteArray();
427 }
428 
429 int KWindowInfo::pid() const
430 {
431  if (auto extension = d->pidExtension()) {
432  return extension->pid();
433  }
434  return 0;
435 }
436 
437 #undef DELEGATE
QFlags< State > States
Stores a combination of State values.
Definition: netwm_def.h:582
QString iconName() const
Returns the name of the window that should be shown in taskbar.
int pid() const
Returns the process ID of the window&#39;s application if present.
QString visibleName() const
Returns the visible name of the window.
KWindowInfo & operator=(const KWindowInfo &)
Assignment operator.
QString visibleIconName() const
Returns the visible name of the window that should be shown in a taskbar.
QRect frameGeometry() const
Returns the frame geometry of the window, i.e.
This class provides information about a given window in the platform specific windowing system...
Definition: kwindowinfo.h:62
QStringList activities() const
Returns the list of activity UUIDs this window belongs to.
Partial strut class for NET classes.
Definition: netwm_def.h:180
NET::States state() const
Returns the window&#39;s state flags.
NET::WindowType windowType(NET::WindowTypes supported_types) const
Returns the window type of this window.
QString visibleNameWithState() const
Returns a visible name with state.
QByteArray clientMachine() const
Returns the client machine for the window.
QByteArray applicationMenuObjectPath() const
Returns object path of a window&#39;s application menu if present.
bool isMinimized() const
Returns true if the window is minimized.
bool onAllDesktops() const
Returns true if the window is on all desktops.
MappingState
Client window mapping state.
Definition: netwm_def.h:624
bool actionSupported(NET::Action action) const
Returns true if the given action is currently supported for the window.
NET::MappingState mappingState() const
Returns the mapping state of the window.
static int currentDesktop()
Returns the current virtual desktop.
NETExtendedStrut extendedStrut() const
Returns the window extended (partial) strut.
bool valid(bool withdrawn_is_valid=false) const
Returns false if this window info is not valid.
WindowType
Window type.
Definition: netwm_def.h:357
QByteArray windowRole() const
Returns the window role for the window.
WId groupLeader() const
Returns the leader window for the group the window is in, if any.
bool isOnDesktop(int desktop) const
Returns true if the window is on the given virtual desktop.
KWindowInfo(WId window, NET::Properties properties, NET::Properties2 properties2=NET::Properties2())
Reads all the info about the given window.
QRect geometry() const
Returns the position and size of the window contents.
WId win() const
Returns the window identifier.
Base namespace class.
Definition: netwm_def.h:334
bool hasState(NET::States s) const
Returns true if the window has the given state flag set.
QByteArray applicationMenuServiceName() const
Returns service name of a window&#39;s application menu if present.
indicates the client window is visible to the user.
Definition: netwm_def.h:628
WId transientFor() const
Returns the window identifier of the main window this window belongs to.
QByteArray windowClassName() const
Returns the name component of the window class for the window.
QString name() const
Returns the name of the window, as specified by the application.
Action
Actions that can be done with a window (_NET_WM_ALLOWED_ACTIONS).
Definition: netwm_def.h:645
QByteArray desktopFileName() const
Returns the desktop file name of the window&#39;s application if present.
int desktop() const
Returns the virtual desktop this window is on.
bool isOnCurrentDesktop() const
Returns true if the window is on the currently active virtual desktop.
QByteArray windowClassClass() const
Returns the class component of the window class for the window.
QString visibleIconNameWithState() const
Returns a visible icon name with state.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Oct 15 2021 22:41:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.