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 KWindowInfoPrivateGtkApplicationIdExtension::KWindowInfoPrivateGtkApplicationIdExtension() = default;
28 KWindowInfoPrivateGtkApplicationIdExtension::~KWindowInfoPrivateGtkApplicationIdExtension() = default;
29 
30 KWindowInfoPrivatePidExtension::KWindowInfoPrivatePidExtension() = default;
31 KWindowInfoPrivatePidExtension::~KWindowInfoPrivatePidExtension() = default;
32 
33 KWindowInfoPrivateAppMenuExtension::KWindowInfoPrivateAppMenuExtension() = default;
34 KWindowInfoPrivateAppMenuExtension::~KWindowInfoPrivateAppMenuExtension() = default;
35 
36 class Q_DECL_HIDDEN KWindowInfoPrivate::Private
37 {
38 public:
39  Private(WId window, NET::Properties properties, NET::Properties2 properties2);
40  WId window;
41  NET::Properties properties;
42  NET::Properties2 properties2;
43  KWindowInfoPrivateDesktopFileNameExtension *desktopFileNameExtension;
44  KWindowInfoPrivateGtkApplicationIdExtension *gtkApplicationIdExtension;
45  KWindowInfoPrivatePidExtension *pidExtension;
46  KWindowInfoPrivateAppMenuExtension *appMenuExtension;
47 };
48 
49 KWindowInfoPrivate::Private::Private(WId window, NET::Properties properties, NET::Properties2 properties2)
50  : window(window)
51  , properties(properties)
52  , properties2(properties2)
53  , desktopFileNameExtension(nullptr)
54  , gtkApplicationIdExtension(nullptr)
55  , pidExtension(nullptr)
56  , appMenuExtension(nullptr)
57 {
58 }
59 
60 KWindowInfoPrivate::KWindowInfoPrivate(WId window, NET::Properties properties, NET::Properties2 properties2)
61  : d(new Private(window, properties, properties2))
62 {
63 }
64 
65 KWindowInfoPrivate::~KWindowInfoPrivate()
66 {
67 }
68 
69 WId KWindowInfoPrivate::win() const
70 {
71  return d->window;
72 }
73 
74 KWindowInfoPrivateDesktopFileNameExtension *KWindowInfoPrivate::desktopFileNameExtension() const
75 {
76  return d->desktopFileNameExtension;
77 }
78 
79 void KWindowInfoPrivate::installDesktopFileNameExtension(KWindowInfoPrivateDesktopFileNameExtension *extension)
80 {
81  d->desktopFileNameExtension = extension;
82 }
83 
84 KWindowInfoPrivateGtkApplicationIdExtension *KWindowInfoPrivate::gtkApplicationIdExtension() const
85 {
86  return d->gtkApplicationIdExtension;
87 }
88 
89 void KWindowInfoPrivate::installGtkApplicationIdExtension(KWindowInfoPrivateGtkApplicationIdExtension *extension)
90 {
91  d->gtkApplicationIdExtension = extension;
92 }
93 
94 KWindowInfoPrivatePidExtension *KWindowInfoPrivate::pidExtension() const
95 {
96  return d->pidExtension;
97 }
98 
99 void KWindowInfoPrivate::installPidExtension(KWindowInfoPrivatePidExtension *extension)
100 {
101  d->pidExtension = extension;
102 }
103 
104 KWindowInfoPrivateAppMenuExtension *KWindowInfoPrivate::appMenuExtension() const
105 {
106  return d->appMenuExtension;
107 }
108 
109 void KWindowInfoPrivate::installAppMenuExtension(KWindowInfoPrivateAppMenuExtension *extension)
110 {
111  d->appMenuExtension = extension;
112 }
113 
114 KWindowInfoPrivateDummy::KWindowInfoPrivateDummy(WId window, NET::Properties properties, NET::Properties2 properties2)
115  : KWindowInfoPrivate(window, properties, properties2)
116 {
117 }
118 
119 KWindowInfoPrivateDummy::~KWindowInfoPrivateDummy()
120 {
121 }
122 
123 bool KWindowInfoPrivateDummy::valid(bool withdrawn_is_valid) const
124 {
125  Q_UNUSED(withdrawn_is_valid)
126  return false;
127 }
128 
129 NET::States KWindowInfoPrivateDummy::state() const
130 {
131  return NET::States();
132 }
133 
134 bool KWindowInfoPrivateDummy::isMinimized() const
135 {
136  return false;
137 }
138 
139 NET::MappingState KWindowInfoPrivateDummy::mappingState() const
140 {
141  return NET::Visible;
142 }
143 
144 NETExtendedStrut KWindowInfoPrivateDummy::extendedStrut() const
145 {
146  return NETExtendedStrut();
147 }
148 
149 NET::WindowType KWindowInfoPrivateDummy::windowType(NET::WindowTypes supported_types) const
150 {
151  Q_UNUSED(supported_types)
152  return NET::Unknown;
153 }
154 
155 QString KWindowInfoPrivateDummy::visibleName() const
156 {
157  return QString();
158 }
159 
160 QString KWindowInfoPrivateDummy::visibleNameWithState() const
161 {
162  return QString();
163 }
164 
165 QString KWindowInfoPrivateDummy::name() const
166 {
167  return QString();
168 }
169 
170 QString KWindowInfoPrivateDummy::visibleIconName() const
171 {
172  return QString();
173 }
174 
175 QString KWindowInfoPrivateDummy::visibleIconNameWithState() const
176 {
177  return QString();
178 }
179 
180 QString KWindowInfoPrivateDummy::iconName() const
181 {
182  return QString();
183 }
184 
185 bool KWindowInfoPrivateDummy::onAllDesktops() const
186 {
187  return false;
188 }
189 
190 bool KWindowInfoPrivateDummy::isOnDesktop(int desktop) const
191 {
192  Q_UNUSED(desktop)
193  return false;
194 }
195 
196 int KWindowInfoPrivateDummy::desktop() const
197 {
198  return 0;
199 }
200 
201 QStringList KWindowInfoPrivateDummy::activities() const
202 {
203  return QStringList();
204 }
205 
206 QRect KWindowInfoPrivateDummy::geometry() const
207 {
208  return QRect();
209 }
210 
211 QRect KWindowInfoPrivateDummy::frameGeometry() const
212 {
213  return QRect();
214 }
215 
216 WId KWindowInfoPrivateDummy::transientFor() const
217 {
218  return 0;
219 }
220 
221 WId KWindowInfoPrivateDummy::groupLeader() const
222 {
223  return 0;
224 }
225 
226 QByteArray KWindowInfoPrivateDummy::windowClassClass() const
227 {
228  return QByteArray();
229 }
230 
231 QByteArray KWindowInfoPrivateDummy::windowClassName() const
232 {
233  return QByteArray();
234 }
235 
236 QByteArray KWindowInfoPrivateDummy::windowRole() const
237 {
238  return QByteArray();
239 }
240 
241 QByteArray KWindowInfoPrivateDummy::clientMachine() const
242 {
243  return QByteArray();
244 }
245 
246 bool KWindowInfoPrivateDummy::actionSupported(NET::Action action) const
247 {
248  Q_UNUSED(action)
249  return false;
250 }
251 
252 // public
253 KWindowInfo::KWindowInfo(WId window, NET::Properties properties, NET::Properties2 properties2)
254  : d(KWindowInfoPrivate::create(window, properties, properties2))
255 {
256 }
257 
259  : d(other.d)
260 {
261 }
262 
263 KWindowInfo::~KWindowInfo()
264 {
265 }
266 
268 {
269  if (d != other.d) {
270  d = other.d;
271  }
272  return *this;
273 }
274 
275 // clang-format off
276 
277 #define DELEGATE(name, args) \
278  return d->name(args);
279 
280 bool KWindowInfo::valid(bool withdrawn_is_valid) const
281 {
282  DELEGATE(valid, withdrawn_is_valid)
283 }
284 
285 WId KWindowInfo::win() const
286 {
287  return d->win();
288 }
289 
291 {
292  DELEGATE(state, )
293 }
294 
296 {
297  return (state() & s) == s;
298 }
299 
301 {
302  DELEGATE(isMinimized, )
303 }
304 
306 {
307  DELEGATE(mappingState, )
308 }
309 
311 {
312  DELEGATE(extendedStrut, )
313 }
314 
316 {
317  DELEGATE(windowType, supported_types)
318 }
319 
321 {
322  DELEGATE(visibleName, )
323 }
324 
326 {
327  DELEGATE(visibleNameWithState, )
328 }
329 
331 {
332  DELEGATE(name, )
333 }
334 
336 {
337  DELEGATE(visibleIconName, )
338 }
339 
341 {
342  DELEGATE(visibleIconNameWithState, )
343 }
344 
346 {
347  DELEGATE(iconName, )
348 }
349 
351 {
353 }
354 
355 bool KWindowInfo::isOnDesktop(int desktop) const
356 {
357  DELEGATE(isOnDesktop, desktop)
358 }
359 
361 {
362  DELEGATE(onAllDesktops, )
363 }
364 
366 {
367  DELEGATE(desktop, )
368 }
369 
371 {
372  DELEGATE(activities, )
373 }
374 
376 {
377  DELEGATE(geometry, )
378 }
379 
381 {
382  DELEGATE(frameGeometry, )
383 }
384 
386 {
387  DELEGATE(transientFor, )
388 }
389 
391 {
392  DELEGATE(groupLeader, )
393 }
394 
396 {
397  DELEGATE(windowClassClass, )
398 }
399 
401 {
402  DELEGATE(windowClassName, )
403 }
404 
406 {
407  DELEGATE(windowRole, )
408 }
409 
411 {
412  DELEGATE(clientMachine, )
413 }
414 
416 {
417  DELEGATE(actionSupported, action)
418 }
419 
421 {
422  if (auto extension = d->desktopFileNameExtension()) {
423  return extension->desktopFileName();
424  }
425  return QByteArray();
426 }
427 
429 {
430  if (auto extension = d->gtkApplicationIdExtension()) {
431  return extension->gtkApplicationId();
432  }
433  return QByteArray();
434 }
435 
437 {
438  if (auto extension = d->appMenuExtension()) {
439  return extension->applicationMenuServiceName();
440  }
441  return QByteArray();
442 }
443 
445 {
446  if (auto extension = d->appMenuExtension()) {
447  return extension->applicationMenuObjectPath();
448  }
449  return QByteArray();
450 }
451 
452 int KWindowInfo::pid() const
453 {
454  if (auto extension = d->pidExtension()) {
455  return extension->pid();
456  }
457  return 0;
458 }
459 
460 #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.
QByteArray gtkApplicationId() const
Returns the GTK application id of the window if present.
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-2022 The KDE developers.
Generated on Wed Jan 26 2022 22:37:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.