KWindowSystem

kwindowsystem.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 #include "kwindowsystem.h"
7 #include "kstartupinfo.h"
8 #include "kwindowsystem_dummy_p.h"
9 #include "kwindowsystemplugininterface_p.h"
10 #include "pluginwrapper_p.h"
11 
12 #include <config-kwindowsystem.h>
13 
14 #include <QGuiApplication>
15 #include <QMetaMethod>
16 #include <QPixmap>
17 #include <QPluginLoader>
18 #include <QTimer>
19 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 62)
20 #include <QWidget>
21 #endif
22 #include <QWindow>
23 #if KWINDOWSYSTEM_HAVE_X11
24 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
25 #include <private/qtx11extras_p.h>
26 #else
27 #include <QX11Info>
28 #endif
29 #endif
30 
31 // QPoint and QSize all have handy / operators which are useful for scaling, positions and sizes for high DPI support
32 // QRect does not, so we create one for internal purposes within this class
33 inline QRect operator/(const QRect &rectangle, qreal factor)
34 {
35  return QRect(rectangle.topLeft() / factor, rectangle.size() / factor);
36 }
37 
38 class KWindowSystemStaticContainer
39 {
40 public:
41  KWindowSystemStaticContainer()
42  {
43  d.reset(KWindowSystemPluginWrapper::self().createWindowSystem());
44 
46  kwm.moveToThread(QCoreApplication::instance()->thread());
47  }
48  }
49  KWindowSystemPrivate *xcbPlugin()
50  {
51  if (!xcbPrivate) {
52  QPluginLoader loader(QStringLiteral(XCB_PLUGIN_PATH));
53  std::unique_ptr<KWindowSystemPluginInterface> xcbPlugin(qobject_cast<KWindowSystemPluginInterface *>(loader.instance()));
54  if (xcbPlugin) {
55  xcbPrivate.reset(xcbPlugin->createWindowSystem());
56  }
57  }
58  return xcbPrivate.get();
59  }
60  KWindowSystem kwm;
61  std::unique_ptr<KWindowSystemPrivate> d;
62  std::unique_ptr<KWindowSystemPrivate> xcbPrivate;
63 };
64 
65 Q_GLOBAL_STATIC(KWindowSystemStaticContainer, g_kwmInstanceContainer)
66 
67 KWindowSystemPrivate::~KWindowSystemPrivate()
68 {
69 }
70 
71 QPixmap KWindowSystemPrivate::iconFromNetWinInfo(int width, int height, bool scale, int flags, NETWinInfo *info)
72 {
73  Q_UNUSED(width)
74  Q_UNUSED(height)
75  Q_UNUSED(scale)
76  Q_UNUSED(flags)
77  Q_UNUSED(info)
78  return QPixmap();
79 }
80 
81 QList<WId> KWindowSystemPrivateDummy::windows()
82 {
83  return QList<WId>();
84 }
85 
86 QList<WId> KWindowSystemPrivateDummy::stackingOrder()
87 {
88  return QList<WId>();
89 }
90 
91 WId KWindowSystemPrivateDummy::activeWindow()
92 {
93  return 0;
94 }
95 
96 void KWindowSystemPrivateDummy::activateWindow(WId win, long time)
97 {
98  Q_UNUSED(win)
99  Q_UNUSED(time)
100 }
101 
102 void KWindowSystemPrivateDummy::forceActiveWindow(WId win, long time)
103 {
104  Q_UNUSED(win)
105  Q_UNUSED(time)
106 }
107 
108 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
109 void KWindowSystemPrivateDummy::demandAttention(WId win, bool set)
110 {
111  Q_UNUSED(win)
112  Q_UNUSED(set)
113 }
114 #endif
115 
116 bool KWindowSystemPrivateDummy::compositingActive()
117 {
118  return KWindowSystem::isPlatformWayland();
119 }
120 
121 int KWindowSystemPrivateDummy::currentDesktop()
122 {
123  return 0;
124 }
125 
126 int KWindowSystemPrivateDummy::numberOfDesktops()
127 {
128  return 0;
129 }
130 
131 void KWindowSystemPrivateDummy::setCurrentDesktop(int desktop)
132 {
133  Q_UNUSED(desktop)
134 }
135 
136 void KWindowSystemPrivateDummy::setOnAllDesktops(WId win, bool b)
137 {
138  Q_UNUSED(win)
139  Q_UNUSED(b)
140 }
141 
142 void KWindowSystemPrivateDummy::setOnDesktop(WId win, int desktop)
143 {
144  Q_UNUSED(win)
145  Q_UNUSED(desktop)
146 }
147 
148 void KWindowSystemPrivateDummy::setOnActivities(WId win, const QStringList &activities)
149 {
150  Q_UNUSED(win)
151  Q_UNUSED(activities)
152 }
153 
154 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
155 WId KWindowSystemPrivateDummy::transientFor(WId window)
156 {
157  Q_UNUSED(window)
158  return 0;
159 }
160 
161 WId KWindowSystemPrivateDummy::groupLeader(WId window)
162 {
163  Q_UNUSED(window)
164  return 0;
165 }
166 #endif
167 
168 QPixmap KWindowSystemPrivateDummy::icon(WId win, int width, int height, bool scale, int flags)
169 {
170  Q_UNUSED(win)
171  Q_UNUSED(width)
172  Q_UNUSED(height)
173  Q_UNUSED(scale)
174  Q_UNUSED(flags)
175  return QPixmap();
176 }
177 
178 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
179 void KWindowSystemPrivateDummy::setIcons(WId win, const QPixmap &icon, const QPixmap &miniIcon)
180 {
181  Q_UNUSED(win)
182  Q_UNUSED(icon)
183  Q_UNUSED(miniIcon)
184 }
185 #endif
186 
187 void KWindowSystemPrivateDummy::setType(WId win, NET::WindowType windowType)
188 {
189  Q_UNUSED(win)
190  Q_UNUSED(windowType)
191 }
192 
193 void KWindowSystemPrivateDummy::setState(WId win, NET::States state)
194 {
195  Q_UNUSED(win)
196  Q_UNUSED(state)
197 }
198 
199 void KWindowSystemPrivateDummy::clearState(WId win, NET::States state)
200 {
201  Q_UNUSED(win)
202  Q_UNUSED(state)
203 }
204 
205 void KWindowSystemPrivateDummy::minimizeWindow(WId win)
206 {
207  Q_UNUSED(win)
208 }
209 
210 void KWindowSystemPrivateDummy::unminimizeWindow(WId win)
211 {
212  Q_UNUSED(win)
213 }
214 
215 void KWindowSystemPrivateDummy::raiseWindow(WId win)
216 {
217  Q_UNUSED(win)
218 }
219 
220 void KWindowSystemPrivateDummy::lowerWindow(WId win)
221 {
222  Q_UNUSED(win)
223 }
224 
225 bool KWindowSystemPrivateDummy::icccmCompliantMappingState()
226 {
227  return false;
228 }
229 
230 QRect KWindowSystemPrivateDummy::workArea(int desktop)
231 {
232  Q_UNUSED(desktop)
233  return QRect();
234 }
235 
236 QRect KWindowSystemPrivateDummy::workArea(const QList<WId> &excludes, int desktop)
237 {
238  Q_UNUSED(excludes)
239  Q_UNUSED(desktop)
240  return QRect();
241 }
242 
243 QString KWindowSystemPrivateDummy::desktopName(int desktop)
244 {
245  Q_UNUSED(desktop)
246  return QString();
247 }
248 
249 void KWindowSystemPrivateDummy::setDesktopName(int desktop, const QString &name)
250 {
251  Q_UNUSED(desktop)
252  Q_UNUSED(name)
253 }
254 
255 bool KWindowSystemPrivateDummy::showingDesktop()
256 {
257  return false;
258 }
259 
260 void KWindowSystemPrivateDummy::setShowingDesktop(bool showing)
261 {
262  Q_UNUSED(showing);
263 }
264 
265 void KWindowSystemPrivateDummy::setUserTime(WId win, long time)
266 {
267  Q_UNUSED(win)
268  Q_UNUSED(time)
269 }
270 
271 void KWindowSystemPrivateDummy::setExtendedStrut(WId win,
272  int left_width,
273  int left_start,
274  int left_end,
275  int right_width,
276  int right_start,
277  int right_end,
278  int top_width,
279  int top_start,
280  int top_end,
281  int bottom_width,
282  int bottom_start,
283  int bottom_end)
284 {
285  Q_UNUSED(win)
286  Q_UNUSED(left_width)
287  Q_UNUSED(left_start)
288  Q_UNUSED(left_end)
289  Q_UNUSED(right_width)
290  Q_UNUSED(right_start)
291  Q_UNUSED(right_end)
292  Q_UNUSED(top_width)
293  Q_UNUSED(top_start)
294  Q_UNUSED(top_end)
295  Q_UNUSED(bottom_width)
296  Q_UNUSED(bottom_start)
297  Q_UNUSED(bottom_end)
298 }
299 
300 void KWindowSystemPrivateDummy::setStrut(WId win, int left, int right, int top, int bottom)
301 {
302  Q_UNUSED(win)
303  Q_UNUSED(left)
304  Q_UNUSED(right)
305  Q_UNUSED(top)
306  Q_UNUSED(bottom)
307 }
308 
309 bool KWindowSystemPrivateDummy::allowedActionsSupported()
310 {
311  return false;
312 }
313 
314 QString KWindowSystemPrivateDummy::readNameProperty(WId window, unsigned long atom)
315 {
316  Q_UNUSED(window)
317  Q_UNUSED(atom)
318  return QString();
319 }
320 
321 void KWindowSystemPrivateDummy::allowExternalProcessWindowActivation(int pid)
322 {
323  Q_UNUSED(pid)
324 }
325 
326 void KWindowSystemPrivateDummy::setBlockingCompositing(WId window, bool active)
327 {
328  Q_UNUSED(window)
329  Q_UNUSED(active)
330 }
331 
332 bool KWindowSystemPrivateDummy::mapViewport()
333 {
334  return false;
335 }
336 
337 int KWindowSystemPrivateDummy::viewportToDesktop(const QPoint &pos)
338 {
339  Q_UNUSED(pos)
340  return 0;
341 }
342 
343 int KWindowSystemPrivateDummy::viewportWindowToDesktop(const QRect &r)
344 {
345  Q_UNUSED(r)
346  return 0;
347 }
348 
349 QPoint KWindowSystemPrivateDummy::desktopToViewport(int desktop, bool absolute)
350 {
351  Q_UNUSED(desktop)
352  Q_UNUSED(absolute)
353  return QPoint();
354 }
355 
356 QPoint KWindowSystemPrivateDummy::constrainViewportRelativePosition(const QPoint &pos)
357 {
358  Q_UNUSED(pos)
359  return QPoint();
360 }
361 
362 void KWindowSystemPrivateDummy::connectNotify(const QMetaMethod &signal)
363 {
364  Q_UNUSED(signal)
365 }
366 
368 {
369  return &(g_kwmInstanceContainer()->kwm);
370 }
371 
372 KWindowSystemPrivate *KWindowSystem::d_func()
373 {
374  return g_kwmInstanceContainer()->d.get();
375 }
376 
377 void KWindowSystem::connectNotify(const QMetaMethod &signal)
378 {
380  d->connectNotify(signal);
381  QObject::connectNotify(signal);
382 }
383 
384 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
386 {
388  return d->windows();
389 }
390 #endif
391 
392 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
394 {
395  return KWindowInfo(win, properties, properties2);
396 }
397 #endif
398 
399 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
401 {
402  return windows().contains(w);
403 }
404 #endif
405 
406 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
408 {
410  return d->stackingOrder();
411 }
412 #endif
413 
414 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
416 {
418  return d->currentDesktop();
419 }
420 #endif
421 
422 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
424 {
426  return d->numberOfDesktops();
427 }
428 #endif
429 
430 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
432 {
434  d->setCurrentDesktop(desktop);
435 }
436 #endif
437 
438 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
439 void KWindowSystem::setOnAllDesktops(WId win, bool b)
440 {
442  d->setOnAllDesktops(win, b);
443 }
444 #endif
445 
446 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
447 void KWindowSystem::setOnDesktop(WId win, int desktop)
448 {
450  d->setOnDesktop(win, desktop);
451 }
452 #endif
453 
454 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
455 void KWindowSystem::setOnActivities(WId win, const QStringList &activities)
456 {
458  d->setOnActivities(win, activities);
459 }
460 #endif
461 
462 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
464 {
466  return d->activeWindow();
467 }
468 #endif
469 
470 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
471 void KWindowSystem::activateWindow(WId win, long time)
472 {
474  d->activateWindow(win, time);
475 }
476 #endif
477 
479 {
481  d->activateWindow(win->winId(), time);
482 }
483 
484 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
485 void KWindowSystem::forceActiveWindow(WId win, long time)
486 {
488  d->forceActiveWindow(win, time);
489 }
490 #endif
491 
492 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
493 void KWindowSystem::demandAttention(WId win, bool set)
494 {
496  d->demandAttention(win, set);
497 }
498 #endif
499 
500 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
502 {
504  return d->transientFor(win);
505 }
506 
507 void KWindowSystem::setMainWindow(QWidget *subWidget, WId mainWindowId)
508 {
509  // Set the WA_NativeWindow attribute to force the creation of the QWindow.
510  // Without this QWidget::windowHandle() returns 0.
511  subWidget->setAttribute(Qt::WA_NativeWindow, true);
512  QWindow *subWindow = subWidget->windowHandle();
513  Q_ASSERT(subWindow);
514  setMainWindow(subWindow, mainWindowId);
515 }
516 #endif
517 
518 void KWindowSystem::setMainWindow(QWindow *subWindow, WId mainWindowId)
519 {
520  QWindow *mainWindow = QWindow::fromWinId(mainWindowId);
521  if (mainWindow) { // foreign windows not supported on all platforms
522  subWindow->setTransientParent(mainWindow);
523 
524  // mainWindow is not the child of any object, so make sure it gets deleted at some point
525  connect(subWindow, &QObject::destroyed, mainWindow, &QObject::deleteLater);
526  }
527 }
528 
529 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
531 {
533  return d->groupLeader(win);
534 }
535 #endif
536 
537 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
538 QPixmap KWindowSystem::icon(WId win, int width, int height, bool scale)
539 {
540  return icon(win, width, height, scale, NETWM | WMHints | ClassHint | XApp);
541 }
542 #endif
543 
544 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
545 QPixmap KWindowSystem::icon(WId win, int width, int height, bool scale, int flags)
546 {
548  return d->icon(win, width, height, scale, flags);
549 }
550 #endif
551 
552 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
553 QPixmap KWindowSystem::icon(WId win, int width, int height, bool scale, int flags, NETWinInfo *info)
554 {
556  width *= qApp->devicePixelRatio();
557  height *= qApp->devicePixelRatio();
558 #if KWINDOWSYSTEM_HAVE_X11
559  if (info) {
560  if (isPlatformX11()) {
561  // this is the xcb plugin, we can just delegate
562  return d->iconFromNetWinInfo(width, height, scale, flags, info);
563  } else {
564  // other platform plugin, load xcb plugin to delegate to it
565  if (KWindowSystemPrivate *p = g_kwmInstanceContainer()->xcbPlugin()) {
566  return p->iconFromNetWinInfo(width, height, scale, flags, info);
567  }
568  }
569  }
570 #else
571  Q_UNUSED(info)
572 #endif
573  return d->icon(win, width, height, scale, flags);
574 }
575 #endif
576 
577 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
578 void KWindowSystem::setIcons(WId win, const QPixmap &icon, const QPixmap &miniIcon)
579 {
581  d->setIcons(win, icon, miniIcon);
582 }
583 #endif
584 
585 void KWindowSystem::setType(WId win, NET::WindowType windowType)
586 {
588  d->setType(win, windowType);
589 }
590 
592 {
594  d->setState(win, state);
595 }
596 
598 {
600  d->clearState(win, state);
601 }
602 
603 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
605 {
607  d->minimizeWindow(win);
608 }
609 #endif
610 
611 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
613 {
615  d->unminimizeWindow(win);
616 }
617 #endif
618 
619 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
620 void KWindowSystem::minimizeWindow(WId win, bool animation)
621 {
622  Q_UNUSED(animation)
623  minimizeWindow(win);
624 }
625 #endif
626 
627 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
628 void KWindowSystem::unminimizeWindow(WId win, bool animation)
629 {
630  Q_UNUSED(animation)
631  unminimizeWindow(win);
632 }
633 #endif
634 
636 {
638  d->raiseWindow(win);
639 }
640 
641 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
643 {
645  d->lowerWindow(win);
646 }
647 #endif
648 
649 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
651 {
653  return d->compositingActive();
654 }
655 #endif
656 
657 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
659 {
661  return d->workArea(desktop) / qApp->devicePixelRatio();
662 }
663 #endif
664 
665 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
666 QRect KWindowSystem::workArea(const QList<WId> &exclude, int desktop)
667 {
669  return d->workArea(exclude, desktop) / qApp->devicePixelRatio();
670 }
671 #endif
672 
673 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
675 {
677  return d->desktopName(desktop);
678 }
679 #endif
680 
681 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
682 void KWindowSystem::setDesktopName(int desktop, const QString &name)
683 {
685  d->setDesktopName(desktop, name);
686 }
687 #endif
688 
690 {
692  return d->showingDesktop();
693 }
694 
696 {
698  return d->setShowingDesktop(showing);
699 }
700 
701 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
702 void KWindowSystem::setUserTime(WId win, long time)
703 {
705  d->setUserTime(win, time);
706 }
707 #endif
708 
709 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
711  int left_width,
712  int left_start,
713  int left_end,
714  int right_width,
715  int right_start,
716  int right_end,
717  int top_width,
718  int top_start,
719  int top_end,
720  int bottom_width,
721  int bottom_start,
722  int bottom_end)
723 {
725  const qreal dpr = qApp->devicePixelRatio();
726  d->setExtendedStrut(win,
727  left_width * dpr,
728  left_start * dpr,
729  left_end * dpr,
730  right_width * dpr,
731  right_start * dpr,
732  right_end * dpr,
733  top_width * dpr,
734  top_start * dpr,
735  top_end * dpr,
736  bottom_width * dpr,
737  bottom_start * dpr,
738  bottom_end * dpr);
739 }
740 #endif
741 
742 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
743 void KWindowSystem::setStrut(WId win, int left, int right, int top, int bottom)
744 {
746  const qreal dpr = qApp->devicePixelRatio();
747  d->setStrut(win, left * dpr, right * dpr, top * dpr, bottom * dpr);
748 }
749 #endif
750 
751 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
753 {
755  return d->icccmCompliantMappingState();
756 }
757 #endif
758 
760 {
762  return d->allowedActionsSupported();
763 }
764 
765 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
766 QString KWindowSystem::readNameProperty(WId win, unsigned long atom)
767 {
769  return d->readNameProperty(win, atom);
770 }
771 #endif
772 
773 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 104)
775 {
777  d->allowExternalProcessWindowActivation(pid);
778 }
779 #endif
780 
781 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
782 void KWindowSystem::setBlockingCompositing(WId window, bool active)
783 {
785  d->setBlockingCompositing(window, active);
786 }
787 #endif
788 
789 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
791 {
793  return d->mapViewport();
794 }
795 #endif
796 
798 {
800  return d->viewportToDesktop(p / qApp->devicePixelRatio());
801 }
802 
804 {
806  return d->viewportWindowToDesktop(r / qApp->devicePixelRatio());
807 }
808 
809 QPoint KWindowSystem::desktopToViewport(int desktop, bool absolute)
810 {
812  return d->desktopToViewport(desktop, absolute);
813 }
814 
815 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
817 {
819  return d->constrainViewportRelativePosition(pos / qApp->devicePixelRatio());
820 }
821 #endif
822 
823 static inline KWindowSystem::Platform initPlatform()
824 {
825  auto platformName = QGuiApplication::platformName();
826  if (platformName == QLatin1String("flatpak")) {
827  // here we cannot know what is the actual windowing system, let's try it's env variable
828  const auto flatpakPlatform = QString::fromLocal8Bit(qgetenv("QT_QPA_FLATPAK_PLATFORM"));
829  if (!flatpakPlatform.isEmpty()) {
830  platformName = flatpakPlatform;
831  }
832  }
833 #if KWINDOWSYSTEM_HAVE_X11
834  if (platformName == QLatin1String("xcb")) {
836  }
837 #endif
838  if (platformName.startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
840  }
842 }
843 
845 {
846  static Platform s_platform = initPlatform();
847  return s_platform;
848 }
849 
850 bool KWindowSystem::isPlatformX11()
851 {
852  return platform() == Platform::X11;
853 }
854 
855 bool KWindowSystem::isPlatformWayland()
856 {
857  return platform() == Platform::Wayland;
858 }
859 
861 {
862  // clang-format off
863  // TODO: move to a new KWindowSystemPrivate interface
864 #if KWINDOWSYSTEM_HAVE_X11
865  if (isPlatformX11()) {
866  const QByteArray startupId = QX11Info::nextStartupId();
867  if (!startupId.isEmpty()) {
868  KStartupInfo::setNewStartupId(window, startupId);
869  }
870  } else
871 #else
872  Q_UNUSED(window);
873 #endif
874  if (isPlatformWayland()) {
875  const QString token = qEnvironmentVariable("XDG_ACTIVATION_TOKEN");
876  if (!token.isEmpty()) {
878  qunsetenv("XDG_ACTIVATION_TOKEN");
879  }
880  }
881  // clang-format on
882 }
883 
884 void KWindowSystem::requestXdgActivationToken(QWindow *win, uint32_t serial, const QString &app_id)
885 {
887  auto dv2 = dynamic_cast<KWindowSystemPrivateV2 *>(d);
888  if (!dv2) {
889  // Ensure that xdgActivationTokenArrived is always emitted asynchronously
890  QTimer::singleShot(0, [serial] {
892  });
893 
894  return;
895  }
896  dv2->requestToken(win, serial, app_id);
897 }
898 
900 {
902  auto dv2 = dynamic_cast<KWindowSystemPrivateV2 *>(d);
903  if (!dv2) {
904  return;
905  }
906  dv2->setCurrentToken(token);
907 }
908 
910 {
912  auto dv2 = dynamic_cast<KWindowSystemPrivateV2 *>(d);
913  if (!dv2) {
914  return 0;
915  }
916  return dv2->lastInputSerial(window);
917 }
918 
919 #include "moc_kwindowsystem.cpp"
Platform
Enum describing the windowing system platform used by the QGuiApplication.
static void demandAttention(WId win, bool set=true)
When application finishes some operation and wants to notify the user about it, it can call demandAtt...
static bool allowedActionsSupported()
Returns true if the WM announces which actions it allows for windows.
static void setOnDesktop(WId win, int desktop)
Moves window win to desktop desktop.
@ Unknown
A platform unknown to the application is used.
static Q_INVOKABLE void setCurrentXdgActivationToken(const QString &token)
Sets the token that will be used when activateWindow is called next.
static void setMainWindow(QWindow *subwindow, WId mainwindow)
Sets the parent window of subwindow to be mainwindow.
QPoint topLeft() const const
static void setDesktopName(int desktop, const QString &name)
Sets the name of the specified desktop.
CaseInsensitive
QSize size() const const
Q_EMITQ_EMIT
static bool showingDesktop()
Returns the state of showing the desktop.
This class provides information about a given window in the platform specific windowing system.
Definition: kwindowinfo.h:62
static QPoint constrainViewportRelativePosition(const QPoint &pos)
static void setBlockingCompositing(WId window, bool active)
Sets whether the client wishes to block compositing (for better performance)
@ X11
The xcb/X11 windowing system platorm.
static int viewportWindowToDesktop(const QRect &r)
static KWindowInfo windowInfo(WId win, NET::Properties properties, NET::Properties2 properties2=NET::Properties2())
Returns information about window win.
static WId groupLeader(WId window)
Returns the leader window for the group the given window is in, if any.
static void setCurrentDesktop(int desktop)
Convenience function to set the current desktop to desktop.
@ ClassHint
load icon after getting name from the classhint
static void setOnAllDesktops(WId win, bool b)
Sets window win to be present on all virtual desktops if is true.
void setAttribute(Qt::WidgetAttribute attribute, bool on)
static void raiseWindow(WId win)
Raises the given window.
bool contains(const T &value) const const
static QPixmap icon(WId win, int width=-1, int height=-1, bool scale=false)
Returns an icon for window win.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Q_GLOBAL_STATIC(Internal::StaticControl, s_instance) class ControlPrivate
void destroyed(QObject *obj)
void deleteLater()
static void setUserTime(WId win, long time)
Sets user timestamp time on window win.
static void setExtendedStrut(WId win, int left_width, int left_start, int left_end, int right_width, int right_start, int right_end, int top_width, int top_start, int top_end, int bottom_width, int bottom_start, int bottom_end)
Sets the strut of window win to left_width ranging from left_start to left_end on the left edge,...
static void forceActiveWindow(WId win, long time=0)
Sets window win to be the active window.
QString fromLocal8Bit(const char *str, int size)
static int numberOfDesktops()
Returns the number of virtual desktops.
static void unminimizeWindow(WId win)
Unminimizes the window with id win.
void xdgActivationTokenArrived(int serial, const QString &token)
Activation token to pass to the client.
static Q_INVOKABLE quint32 lastInputSerial(QWindow *window)
Offers the seat's current serial.
@ WMHints
read from WMHints property
@ NETWM
read from property from the window manager specification
bool isEmpty() const const
QCoreApplication * instance()
WId winId() const const
static void setState(WId win, NET::States state)
Sets the state of window win to state.
static void lowerWindow(WId win)
Lowers the given window.
static bool icccmCompliantMappingState()
static void clearState(WId win, NET::States state)
Clears the state of window win from state.
static void setIcons(WId win, const QPixmap &icon, const QPixmap &miniIcon)
Sets an icon and a miniIcon on window win.
static QString readNameProperty(WId window, unsigned long atom)
Function that reads and returns the contents of the given text property (WM_NAME, WM_ICON_NAME,...
static void setShowingDesktop(bool showing)
Sets the state of the "showing desktop" mode of the window manager.
static KWindowSystem * self()
Access to the singleton instance.
QWindow * fromWinId(WId id)
static Q_INVOKABLE void requestXdgActivationToken(QWindow *win, uint32_t serial, const QString &app_id)
Requests an xdg_activation_v1 token for a specific window.
Convenience access to certain properties and features of the window manager.
Definition: kwindowsystem.h:44
QWindow * windowHandle() const const
bool isEmpty() const const
static bool hasWId(WId id)
Test to see if id still managed at present.
static void updateStartupId(QWindow *window)
Updates the platform-specific startup id, if any.
static Platform platform()
Returns the Platform used by the QGuiApplication.
static QList< WId > windows()
Returns the list of all toplevel windows currently managed by the window manager in the order of crea...
Common API for application window properties/protocols.
Definition: netwm.h:974
static int currentDesktop()
Returns the current virtual desktop.
static QPoint desktopToViewport(int desktop, bool absolute)
static QRect workArea(int desktop=-1)
Returns the workarea for the specified desktop, or the current work area if no desktop has been speci...
static QList< WId > stackingOrder()
Returns the list of all toplevel windows currently managed by the window manager in the current stack...
static void setNewStartupId(QWindow *window, const QByteArray &startup_id)
Use this function if the application got a request with startup notification from outside (for exampl...
static bool mapViewport()
static void setType(WId win, NET::WindowType windowType)
Sets the type of window win to windowType.
static WId transientFor(WId window)
Returns the WM_TRANSIENT_FOR property for the given window, i.e.
static void allowExternalProcessWindowActivation(int pid=-1)
Allows a window from another process to raise and activate itself.
static WId activeWindow()
Returns the currently active window, or 0 if no window is active.
static QString desktopName(int desktop)
Returns the name of the specified desktop.
virtual void connectNotify(const QMetaMethod &signal)
static void setOnActivities(WId win, const QStringList &activities)
Moves window win to activities activities.
static void setStrut(WId win, int left, int right, int top, int bottom)
Convenience function for setExtendedStrut() that automatically makes struts as wide/high as the scree...
@ Wayland
The Wayland windowing system platform.
static void activateWindow(WId win, long time=0)
Requests that window win is activated.
static int viewportToDesktop(const QPoint &pos)
static bool compositingActive()
Returns true if a compositing manager is running (i.e.
WA_NativeWindow
WindowType
Window type.
Definition: netwm_def.h:357
Q_D(Todo)
@ XApp
load the standard X icon (last fallback)
static void minimizeWindow(WId win)
Minimizes the window with id win.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Dec 11 2023 04:10:43 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.