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 #if KWINDOWSYSTEM_HAVE_X11
19 #include "kx11extras.h"
20 #endif
21 
22 // private
23 KWindowInfoPrivate *KWindowInfoPrivate::create(WId window, NET::Properties properties, NET::Properties2 properties2)
24 {
25  return KWindowSystemPluginWrapper::self().createWindowInfo(window, properties, properties2);
26 }
27 
28 KWindowInfoPrivateDesktopFileNameExtension::KWindowInfoPrivateDesktopFileNameExtension() = default;
29 KWindowInfoPrivateDesktopFileNameExtension::~KWindowInfoPrivateDesktopFileNameExtension() = default;
30 
31 KWindowInfoPrivateGtkApplicationIdExtension::KWindowInfoPrivateGtkApplicationIdExtension() = default;
32 KWindowInfoPrivateGtkApplicationIdExtension::~KWindowInfoPrivateGtkApplicationIdExtension() = default;
33 
34 KWindowInfoPrivatePidExtension::KWindowInfoPrivatePidExtension() = default;
35 KWindowInfoPrivatePidExtension::~KWindowInfoPrivatePidExtension() = default;
36 
37 KWindowInfoPrivateAppMenuExtension::KWindowInfoPrivateAppMenuExtension() = default;
38 KWindowInfoPrivateAppMenuExtension::~KWindowInfoPrivateAppMenuExtension() = default;
39 
40 class Q_DECL_HIDDEN KWindowInfoPrivate::Private
41 {
42 public:
43  Private(WId window, NET::Properties properties, NET::Properties2 properties2);
44  WId window;
46  NET::Properties2 properties2;
47  KWindowInfoPrivateDesktopFileNameExtension *desktopFileNameExtension;
48  KWindowInfoPrivateGtkApplicationIdExtension *gtkApplicationIdExtension;
49  KWindowInfoPrivatePidExtension *pidExtension;
50  KWindowInfoPrivateAppMenuExtension *appMenuExtension;
51 };
52 
53 KWindowInfoPrivate::Private::Private(WId window, NET::Properties properties, NET::Properties2 properties2)
54  : window(window)
56  , properties2(properties2)
57  , desktopFileNameExtension(nullptr)
58  , gtkApplicationIdExtension(nullptr)
59  , pidExtension(nullptr)
60  , appMenuExtension(nullptr)
61 {
62 }
63 
64 KWindowInfoPrivate::KWindowInfoPrivate(WId window, NET::Properties properties, NET::Properties2 properties2)
65  : d(new Private(window, properties, properties2))
66 {
67 }
68 
69 KWindowInfoPrivate::~KWindowInfoPrivate()
70 {
71 }
72 
73 WId KWindowInfoPrivate::win() const
74 {
75  return d->window;
76 }
77 
78 KWindowInfoPrivateDesktopFileNameExtension *KWindowInfoPrivate::desktopFileNameExtension() const
79 {
80  return d->desktopFileNameExtension;
81 }
82 
83 void KWindowInfoPrivate::installDesktopFileNameExtension(KWindowInfoPrivateDesktopFileNameExtension *extension)
84 {
85  d->desktopFileNameExtension = extension;
86 }
87 
88 KWindowInfoPrivateGtkApplicationIdExtension *KWindowInfoPrivate::gtkApplicationIdExtension() const
89 {
90  return d->gtkApplicationIdExtension;
91 }
92 
93 void KWindowInfoPrivate::installGtkApplicationIdExtension(KWindowInfoPrivateGtkApplicationIdExtension *extension)
94 {
95  d->gtkApplicationIdExtension = extension;
96 }
97 
98 KWindowInfoPrivatePidExtension *KWindowInfoPrivate::pidExtension() const
99 {
100  return d->pidExtension;
101 }
102 
103 void KWindowInfoPrivate::installPidExtension(KWindowInfoPrivatePidExtension *extension)
104 {
105  d->pidExtension = extension;
106 }
107 
108 KWindowInfoPrivateAppMenuExtension *KWindowInfoPrivate::appMenuExtension() const
109 {
110  return d->appMenuExtension;
111 }
112 
113 void KWindowInfoPrivate::installAppMenuExtension(KWindowInfoPrivateAppMenuExtension *extension)
114 {
115  d->appMenuExtension = extension;
116 }
117 
118 KWindowInfoPrivateDummy::KWindowInfoPrivateDummy(WId window, NET::Properties properties, NET::Properties2 properties2)
119  : KWindowInfoPrivate(window, properties, properties2)
120 {
121 }
122 
123 KWindowInfoPrivateDummy::~KWindowInfoPrivateDummy()
124 {
125 }
126 
127 bool KWindowInfoPrivateDummy::valid(bool withdrawn_is_valid) const
128 {
129  Q_UNUSED(withdrawn_is_valid)
130  return false;
131 }
132 
133 NET::States KWindowInfoPrivateDummy::state() const
134 {
135  return NET::States();
136 }
137 
138 bool KWindowInfoPrivateDummy::isMinimized() const
139 {
140  return false;
141 }
142 
143 NET::MappingState KWindowInfoPrivateDummy::mappingState() const
144 {
145  return NET::Visible;
146 }
147 
148 NETExtendedStrut KWindowInfoPrivateDummy::extendedStrut() const
149 {
150  return NETExtendedStrut();
151 }
152 
153 NET::WindowType KWindowInfoPrivateDummy::windowType(NET::WindowTypes supported_types) const
154 {
155  Q_UNUSED(supported_types)
156  return NET::Unknown;
157 }
158 
159 QString KWindowInfoPrivateDummy::visibleName() const
160 {
161  return QString();
162 }
163 
164 QString KWindowInfoPrivateDummy::visibleNameWithState() const
165 {
166  return QString();
167 }
168 
169 QString KWindowInfoPrivateDummy::name() const
170 {
171  return QString();
172 }
173 
174 QString KWindowInfoPrivateDummy::visibleIconName() const
175 {
176  return QString();
177 }
178 
179 QString KWindowInfoPrivateDummy::visibleIconNameWithState() const
180 {
181  return QString();
182 }
183 
184 QString KWindowInfoPrivateDummy::iconName() const
185 {
186  return QString();
187 }
188 
189 bool KWindowInfoPrivateDummy::onAllDesktops() const
190 {
191  return false;
192 }
193 
194 bool KWindowInfoPrivateDummy::isOnDesktop(int desktop) const
195 {
196  Q_UNUSED(desktop)
197  return false;
198 }
199 
200 int KWindowInfoPrivateDummy::desktop() const
201 {
202  return 0;
203 }
204 
205 QStringList KWindowInfoPrivateDummy::activities() const
206 {
207  return QStringList();
208 }
209 
210 QRect KWindowInfoPrivateDummy::geometry() const
211 {
212  return QRect();
213 }
214 
215 QRect KWindowInfoPrivateDummy::frameGeometry() const
216 {
217  return QRect();
218 }
219 
220 WId KWindowInfoPrivateDummy::transientFor() const
221 {
222  return 0;
223 }
224 
225 WId KWindowInfoPrivateDummy::groupLeader() const
226 {
227  return 0;
228 }
229 
230 QByteArray KWindowInfoPrivateDummy::windowClassClass() const
231 {
232  return QByteArray();
233 }
234 
235 QByteArray KWindowInfoPrivateDummy::windowClassName() const
236 {
237  return QByteArray();
238 }
239 
240 QByteArray KWindowInfoPrivateDummy::windowRole() const
241 {
242  return QByteArray();
243 }
244 
245 QByteArray KWindowInfoPrivateDummy::clientMachine() const
246 {
247  return QByteArray();
248 }
249 
250 bool KWindowInfoPrivateDummy::actionSupported(NET::Action action) const
251 {
252  Q_UNUSED(action)
253  return false;
254 }
255 
256 // public
257 KWindowInfo::KWindowInfo(WId window, NET::Properties properties, NET::Properties2 properties2)
258  : d(KWindowInfoPrivate::create(window, properties, properties2))
259 {
260 }
261 
263  : d(other.d)
264 {
265 }
266 
267 KWindowInfo::~KWindowInfo()
268 {
269 }
270 
272 {
273  if (d != other.d) {
274  d = other.d;
275  }
276  return *this;
277 }
278 
279 // clang-format off
280 
281 #define DELEGATE(name, args) \
282  return d->name(args);
283 
284 bool KWindowInfo::valid(bool withdrawn_is_valid) const
285 {
286  DELEGATE(valid, withdrawn_is_valid)
287 }
288 
289 WId KWindowInfo::win() const
290 {
291  return d->win();
292 }
293 
295 {
296  DELEGATE(state, )
297 }
298 
300 {
301  return (state() & s) == s;
302 }
303 
305 {
306  DELEGATE(isMinimized, )
307 }
308 
310 {
311  DELEGATE(mappingState, )
312 }
313 
315 {
316  DELEGATE(extendedStrut, )
317 }
318 
320 {
321  DELEGATE(windowType, supported_types)
322 }
323 
325 {
326  DELEGATE(visibleName, )
327 }
328 
330 {
331  DELEGATE(visibleNameWithState, )
332 }
333 
335 {
336  DELEGATE(name, )
337 }
338 
340 {
341  DELEGATE(visibleIconName, )
342 }
343 
345 {
346  DELEGATE(visibleIconNameWithState, )
347 }
348 
350 {
351  DELEGATE(iconName, )
352 }
353 
355 {
356 #if KWINDOWSYSTEM_HAVE_X11
358 #else
359  return true;
360 #endif
361 }
362 
363 bool KWindowInfo::isOnDesktop(int desktop) const
364 {
365  DELEGATE(isOnDesktop, desktop)
366 }
367 
369 {
370  DELEGATE(onAllDesktops, )
371 }
372 
374 {
375  DELEGATE(desktop, )
376 }
377 
379 {
380  DELEGATE(activities, )
381 }
382 
384 {
385  DELEGATE(geometry, )
386 }
387 
389 {
390  DELEGATE(frameGeometry, )
391 }
392 
394 {
395  DELEGATE(transientFor, )
396 }
397 
399 {
400  DELEGATE(groupLeader, )
401 }
402 
404 {
405  DELEGATE(windowClassClass, )
406 }
407 
409 {
410  DELEGATE(windowClassName, )
411 }
412 
414 {
415  DELEGATE(windowRole, )
416 }
417 
419 {
420  DELEGATE(clientMachine, )
421 }
422 
424 {
425  DELEGATE(actionSupported, action)
426 }
427 
429 {
430  if (auto extension = d->desktopFileNameExtension()) {
431  return extension->desktopFileName();
432  }
433  return QByteArray();
434 }
435 
437 {
438  if (auto extension = d->gtkApplicationIdExtension()) {
439  return extension->gtkApplicationId();
440  }
441  return QByteArray();
442 }
443 
445 {
446  if (auto extension = d->appMenuExtension()) {
447  return extension->applicationMenuServiceName();
448  }
449  return QByteArray();
450 }
451 
453 {
454  if (auto extension = d->appMenuExtension()) {
455  return extension->applicationMenuObjectPath();
456  }
457  return QByteArray();
458 }
459 
460 int KWindowInfo::pid() const
461 {
462  if (auto extension = d->pidExtension()) {
463  return extension->pid();
464  }
465  return 0;
466 }
467 
468 #undef DELEGATE
QString visibleNameWithState() const
Returns a visible name with state.
int pid() const
Returns the process ID of the window's application if present.
QFlags< State > States
Stores a combination of State values.
Definition: netwm_def.h:587
WId groupLeader() const
Returns the leader window for the group the window is in, if any.
This class provides information about a given window in the platform specific windowing system.
Definition: kwindowinfo.h:62
NETExtendedStrut extendedStrut() const
Returns the window extended (partial) strut.
NET::WindowType windowType(NET::WindowTypes supported_types) const
Returns the window type of this window.
@ Visible
indicates the client window is visible to the user.
Definition: netwm_def.h:633
QByteArray windowClassClass() const
Returns the class component of the window class for the window.
MappingState
Client window mapping state.
Definition: netwm_def.h:629
KGuiItem properties()
QByteArray gtkApplicationId() const
Returns the GTK application id of the window if present.
QStringList activities() const
Returns the list of activity UUIDs this window belongs to.
QRect frameGeometry() const
Returns the frame geometry of the window, i.e.
QByteArray windowClassName() const
Returns the name component of the window class for the window.
KWindowInfo(WId window, NET::Properties properties, NET::Properties2 properties2=NET::Properties2())
Reads all the info about the given window.
NET::MappingState mappingState() const
Returns the mapping state of the window.
bool onAllDesktops() const
Returns true if the window is on all desktops.
QByteArray applicationMenuServiceName() const
Returns service name of a window's application menu if present.
WId transientFor() const
Returns the window identifier of the main window this window belongs to.
WId win() const
Returns the window identifier.
bool valid(bool withdrawn_is_valid=false) const
Returns false if this window info is not valid.
QString visibleIconNameWithState() const
Returns a visible icon name with state.
QString visibleIconName() const
Returns the visible name of the window that should be shown in a taskbar.
QByteArray windowRole() const
Returns the window role for the window.
QString visibleName() const
Returns the visible name of the window.
QByteArray desktopFileName() const
Returns the desktop file name of the window's application if present.
@ Unknown
indicates that the window did not define a window type.
Definition: netwm_def.h:361
QByteArray clientMachine() const
Returns the client machine for the window.
Partial strut class for NET classes.
Definition: netwm_def.h:180
bool isOnCurrentDesktop() const
Returns true if the window is on the currently active virtual desktop.
Action
Actions that can be done with a window (_NET_WM_ALLOWED_ACTIONS).
Definition: netwm_def.h:650
bool hasState(NET::States s) const
Returns true if the window has the given state flag set.
bool isOnDesktop(int desktop) const
Returns true if the window is on the given virtual desktop.
int desktop() const
Returns the virtual desktop this window is on.
QRect geometry() const
Returns the position and size of the window contents.
bool isMinimized() const
Returns true if the window is minimized.
QString name() const
Returns the name of the window, as specified by the application.
QByteArray applicationMenuObjectPath() const
Returns object path of a window's application menu if present.
KJOBWIDGETS_EXPORT QWidget * window(KJob *job)
KWindowInfo & operator=(const KWindowInfo &)
Assignment operator.
NET::States state() const
Returns the window's state flags.
QString iconName() const
Returns the name of the window that should be shown in taskbar.
WindowType
Window type.
Definition: netwm_def.h:357
static int currentDesktop()
Returns the current virtual desktop.
Definition: kx11extras.cpp:74
bool actionSupported(NET::Action action) const
Returns true if the given action is currently supported for the window.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Dec 7 2023 03:54:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.