File indexing completed on 2024-07-14 14:38:32

0001 /*
0002     SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 #include "kwindowsystem.h"
0007 #include "kstartupinfo.h"
0008 #include "kwindowsystem_dummy_p.h"
0009 #include "kwindowsystemplugininterface_p.h"
0010 #include "pluginwrapper_p.h"
0011 
0012 #include <config-kwindowsystem.h>
0013 
0014 #include <QGuiApplication>
0015 #include <QMetaMethod>
0016 #include <QPixmap>
0017 #include <QPluginLoader>
0018 #include <QTimer>
0019 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 62)
0020 #include <QWidget>
0021 #endif
0022 #include <QWindow>
0023 #if KWINDOWSYSTEM_HAVE_X11
0024 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0025 #include <private/qtx11extras_p.h>
0026 #else
0027 #include <QX11Info>
0028 #endif
0029 #endif
0030 
0031 // QPoint and QSize all have handy / operators which are useful for scaling, positions and sizes for high DPI support
0032 // QRect does not, so we create one for internal purposes within this class
0033 inline QRect operator/(const QRect &rectangle, qreal factor)
0034 {
0035     return QRect(rectangle.topLeft() / factor, rectangle.size() / factor);
0036 }
0037 
0038 class KWindowSystemStaticContainer
0039 {
0040 public:
0041     KWindowSystemStaticContainer()
0042     {
0043         d.reset(KWindowSystemPluginWrapper::self().createWindowSystem());
0044 
0045         if (QCoreApplication::instance()) {
0046             kwm.moveToThread(QCoreApplication::instance()->thread());
0047         }
0048     }
0049     KWindowSystemPrivate *xcbPlugin()
0050     {
0051         if (!xcbPrivate) {
0052             QPluginLoader loader(QStringLiteral(XCB_PLUGIN_PATH));
0053             std::unique_ptr<KWindowSystemPluginInterface> xcbPlugin(qobject_cast<KWindowSystemPluginInterface *>(loader.instance()));
0054             if (xcbPlugin) {
0055                 xcbPrivate.reset(xcbPlugin->createWindowSystem());
0056             }
0057         }
0058         return xcbPrivate.get();
0059     }
0060     KWindowSystem kwm;
0061     std::unique_ptr<KWindowSystemPrivate> d;
0062     std::unique_ptr<KWindowSystemPrivate> xcbPrivate;
0063 };
0064 
0065 Q_GLOBAL_STATIC(KWindowSystemStaticContainer, g_kwmInstanceContainer)
0066 
0067 KWindowSystemPrivate::~KWindowSystemPrivate()
0068 {
0069 }
0070 
0071 QPixmap KWindowSystemPrivate::iconFromNetWinInfo(int width, int height, bool scale, int flags, NETWinInfo *info)
0072 {
0073     Q_UNUSED(width)
0074     Q_UNUSED(height)
0075     Q_UNUSED(scale)
0076     Q_UNUSED(flags)
0077     Q_UNUSED(info)
0078     return QPixmap();
0079 }
0080 
0081 QList<WId> KWindowSystemPrivateDummy::windows()
0082 {
0083     return QList<WId>();
0084 }
0085 
0086 QList<WId> KWindowSystemPrivateDummy::stackingOrder()
0087 {
0088     return QList<WId>();
0089 }
0090 
0091 WId KWindowSystemPrivateDummy::activeWindow()
0092 {
0093     return 0;
0094 }
0095 
0096 void KWindowSystemPrivateDummy::activateWindow(WId win, long time)
0097 {
0098     Q_UNUSED(win)
0099     Q_UNUSED(time)
0100 }
0101 
0102 void KWindowSystemPrivateDummy::forceActiveWindow(WId win, long time)
0103 {
0104     Q_UNUSED(win)
0105     Q_UNUSED(time)
0106 }
0107 
0108 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0109 void KWindowSystemPrivateDummy::demandAttention(WId win, bool set)
0110 {
0111     Q_UNUSED(win)
0112     Q_UNUSED(set)
0113 }
0114 #endif
0115 
0116 bool KWindowSystemPrivateDummy::compositingActive()
0117 {
0118     return KWindowSystem::isPlatformWayland();
0119 }
0120 
0121 int KWindowSystemPrivateDummy::currentDesktop()
0122 {
0123     return 0;
0124 }
0125 
0126 int KWindowSystemPrivateDummy::numberOfDesktops()
0127 {
0128     return 0;
0129 }
0130 
0131 void KWindowSystemPrivateDummy::setCurrentDesktop(int desktop)
0132 {
0133     Q_UNUSED(desktop)
0134 }
0135 
0136 void KWindowSystemPrivateDummy::setOnAllDesktops(WId win, bool b)
0137 {
0138     Q_UNUSED(win)
0139     Q_UNUSED(b)
0140 }
0141 
0142 void KWindowSystemPrivateDummy::setOnDesktop(WId win, int desktop)
0143 {
0144     Q_UNUSED(win)
0145     Q_UNUSED(desktop)
0146 }
0147 
0148 void KWindowSystemPrivateDummy::setOnActivities(WId win, const QStringList &activities)
0149 {
0150     Q_UNUSED(win)
0151     Q_UNUSED(activities)
0152 }
0153 
0154 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
0155 WId KWindowSystemPrivateDummy::transientFor(WId window)
0156 {
0157     Q_UNUSED(window)
0158     return 0;
0159 }
0160 
0161 WId KWindowSystemPrivateDummy::groupLeader(WId window)
0162 {
0163     Q_UNUSED(window)
0164     return 0;
0165 }
0166 #endif
0167 
0168 QPixmap KWindowSystemPrivateDummy::icon(WId win, int width, int height, bool scale, int flags)
0169 {
0170     Q_UNUSED(win)
0171     Q_UNUSED(width)
0172     Q_UNUSED(height)
0173     Q_UNUSED(scale)
0174     Q_UNUSED(flags)
0175     return QPixmap();
0176 }
0177 
0178 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0179 void KWindowSystemPrivateDummy::setIcons(WId win, const QPixmap &icon, const QPixmap &miniIcon)
0180 {
0181     Q_UNUSED(win)
0182     Q_UNUSED(icon)
0183     Q_UNUSED(miniIcon)
0184 }
0185 #endif
0186 
0187 void KWindowSystemPrivateDummy::setType(WId win, NET::WindowType windowType)
0188 {
0189     Q_UNUSED(win)
0190     Q_UNUSED(windowType)
0191 }
0192 
0193 void KWindowSystemPrivateDummy::setState(WId win, NET::States state)
0194 {
0195     Q_UNUSED(win)
0196     Q_UNUSED(state)
0197 }
0198 
0199 void KWindowSystemPrivateDummy::clearState(WId win, NET::States state)
0200 {
0201     Q_UNUSED(win)
0202     Q_UNUSED(state)
0203 }
0204 
0205 void KWindowSystemPrivateDummy::minimizeWindow(WId win)
0206 {
0207     Q_UNUSED(win)
0208 }
0209 
0210 void KWindowSystemPrivateDummy::unminimizeWindow(WId win)
0211 {
0212     Q_UNUSED(win)
0213 }
0214 
0215 void KWindowSystemPrivateDummy::raiseWindow(WId win)
0216 {
0217     Q_UNUSED(win)
0218 }
0219 
0220 void KWindowSystemPrivateDummy::lowerWindow(WId win)
0221 {
0222     Q_UNUSED(win)
0223 }
0224 
0225 bool KWindowSystemPrivateDummy::icccmCompliantMappingState()
0226 {
0227     return false;
0228 }
0229 
0230 QRect KWindowSystemPrivateDummy::workArea(int desktop)
0231 {
0232     Q_UNUSED(desktop)
0233     return QRect();
0234 }
0235 
0236 QRect KWindowSystemPrivateDummy::workArea(const QList<WId> &excludes, int desktop)
0237 {
0238     Q_UNUSED(excludes)
0239     Q_UNUSED(desktop)
0240     return QRect();
0241 }
0242 
0243 QString KWindowSystemPrivateDummy::desktopName(int desktop)
0244 {
0245     Q_UNUSED(desktop)
0246     return QString();
0247 }
0248 
0249 void KWindowSystemPrivateDummy::setDesktopName(int desktop, const QString &name)
0250 {
0251     Q_UNUSED(desktop)
0252     Q_UNUSED(name)
0253 }
0254 
0255 bool KWindowSystemPrivateDummy::showingDesktop()
0256 {
0257     return false;
0258 }
0259 
0260 void KWindowSystemPrivateDummy::setShowingDesktop(bool showing)
0261 {
0262     Q_UNUSED(showing);
0263 }
0264 
0265 void KWindowSystemPrivateDummy::setUserTime(WId win, long time)
0266 {
0267     Q_UNUSED(win)
0268     Q_UNUSED(time)
0269 }
0270 
0271 void KWindowSystemPrivateDummy::setExtendedStrut(WId win,
0272                                                  int left_width,
0273                                                  int left_start,
0274                                                  int left_end,
0275                                                  int right_width,
0276                                                  int right_start,
0277                                                  int right_end,
0278                                                  int top_width,
0279                                                  int top_start,
0280                                                  int top_end,
0281                                                  int bottom_width,
0282                                                  int bottom_start,
0283                                                  int bottom_end)
0284 {
0285     Q_UNUSED(win)
0286     Q_UNUSED(left_width)
0287     Q_UNUSED(left_start)
0288     Q_UNUSED(left_end)
0289     Q_UNUSED(right_width)
0290     Q_UNUSED(right_start)
0291     Q_UNUSED(right_end)
0292     Q_UNUSED(top_width)
0293     Q_UNUSED(top_start)
0294     Q_UNUSED(top_end)
0295     Q_UNUSED(bottom_width)
0296     Q_UNUSED(bottom_start)
0297     Q_UNUSED(bottom_end)
0298 }
0299 
0300 void KWindowSystemPrivateDummy::setStrut(WId win, int left, int right, int top, int bottom)
0301 {
0302     Q_UNUSED(win)
0303     Q_UNUSED(left)
0304     Q_UNUSED(right)
0305     Q_UNUSED(top)
0306     Q_UNUSED(bottom)
0307 }
0308 
0309 bool KWindowSystemPrivateDummy::allowedActionsSupported()
0310 {
0311     return false;
0312 }
0313 
0314 QString KWindowSystemPrivateDummy::readNameProperty(WId window, unsigned long atom)
0315 {
0316     Q_UNUSED(window)
0317     Q_UNUSED(atom)
0318     return QString();
0319 }
0320 
0321 void KWindowSystemPrivateDummy::allowExternalProcessWindowActivation(int pid)
0322 {
0323     Q_UNUSED(pid)
0324 }
0325 
0326 void KWindowSystemPrivateDummy::setBlockingCompositing(WId window, bool active)
0327 {
0328     Q_UNUSED(window)
0329     Q_UNUSED(active)
0330 }
0331 
0332 bool KWindowSystemPrivateDummy::mapViewport()
0333 {
0334     return false;
0335 }
0336 
0337 int KWindowSystemPrivateDummy::viewportToDesktop(const QPoint &pos)
0338 {
0339     Q_UNUSED(pos)
0340     return 0;
0341 }
0342 
0343 int KWindowSystemPrivateDummy::viewportWindowToDesktop(const QRect &r)
0344 {
0345     Q_UNUSED(r)
0346     return 0;
0347 }
0348 
0349 QPoint KWindowSystemPrivateDummy::desktopToViewport(int desktop, bool absolute)
0350 {
0351     Q_UNUSED(desktop)
0352     Q_UNUSED(absolute)
0353     return QPoint();
0354 }
0355 
0356 QPoint KWindowSystemPrivateDummy::constrainViewportRelativePosition(const QPoint &pos)
0357 {
0358     Q_UNUSED(pos)
0359     return QPoint();
0360 }
0361 
0362 void KWindowSystemPrivateDummy::connectNotify(const QMetaMethod &signal)
0363 {
0364     Q_UNUSED(signal)
0365 }
0366 
0367 KWindowSystem *KWindowSystem::self()
0368 {
0369     return &(g_kwmInstanceContainer()->kwm);
0370 }
0371 
0372 KWindowSystemPrivate *KWindowSystem::d_func()
0373 {
0374     return g_kwmInstanceContainer()->d.get();
0375 }
0376 
0377 void KWindowSystem::connectNotify(const QMetaMethod &signal)
0378 {
0379     Q_D(KWindowSystem);
0380     d->connectNotify(signal);
0381     QObject::connectNotify(signal);
0382 }
0383 
0384 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0385 QList<WId> KWindowSystem::windows()
0386 {
0387     Q_D(KWindowSystem);
0388     return d->windows();
0389 }
0390 #endif
0391 
0392 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
0393 KWindowInfo KWindowSystem::windowInfo(WId win, NET::Properties properties, NET::Properties2 properties2)
0394 {
0395     return KWindowInfo(win, properties, properties2);
0396 }
0397 #endif
0398 
0399 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0400 bool KWindowSystem::hasWId(WId w)
0401 {
0402     return windows().contains(w);
0403 }
0404 #endif
0405 
0406 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0407 QList<WId> KWindowSystem::stackingOrder()
0408 {
0409     Q_D(KWindowSystem);
0410     return d->stackingOrder();
0411 }
0412 #endif
0413 
0414 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0415 int KWindowSystem::currentDesktop()
0416 {
0417     Q_D(KWindowSystem);
0418     return d->currentDesktop();
0419 }
0420 #endif
0421 
0422 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0423 int KWindowSystem::numberOfDesktops()
0424 {
0425     Q_D(KWindowSystem);
0426     return d->numberOfDesktops();
0427 }
0428 #endif
0429 
0430 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0431 void KWindowSystem::setCurrentDesktop(int desktop)
0432 {
0433     Q_D(KWindowSystem);
0434     d->setCurrentDesktop(desktop);
0435 }
0436 #endif
0437 
0438 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0439 void KWindowSystem::setOnAllDesktops(WId win, bool b)
0440 {
0441     Q_D(KWindowSystem);
0442     d->setOnAllDesktops(win, b);
0443 }
0444 #endif
0445 
0446 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0447 void KWindowSystem::setOnDesktop(WId win, int desktop)
0448 {
0449     Q_D(KWindowSystem);
0450     d->setOnDesktop(win, desktop);
0451 }
0452 #endif
0453 
0454 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0455 void KWindowSystem::setOnActivities(WId win, const QStringList &activities)
0456 {
0457     Q_D(KWindowSystem);
0458     d->setOnActivities(win, activities);
0459 }
0460 #endif
0461 
0462 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0463 WId KWindowSystem::activeWindow()
0464 {
0465     Q_D(KWindowSystem);
0466     return d->activeWindow();
0467 }
0468 #endif
0469 
0470 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0471 void KWindowSystem::activateWindow(WId win, long time)
0472 {
0473     Q_D(KWindowSystem);
0474     d->activateWindow(win, time);
0475 }
0476 #endif
0477 
0478 void KWindowSystem::activateWindow(QWindow *win, long time)
0479 {
0480     Q_D(KWindowSystem);
0481     d->activateWindow(win->winId(), time);
0482 }
0483 
0484 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0485 void KWindowSystem::forceActiveWindow(WId win, long time)
0486 {
0487     Q_D(KWindowSystem);
0488     d->forceActiveWindow(win, time);
0489 }
0490 #endif
0491 
0492 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0493 void KWindowSystem::demandAttention(WId win, bool set)
0494 {
0495     Q_D(KWindowSystem);
0496     d->demandAttention(win, set);
0497 }
0498 #endif
0499 
0500 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
0501 WId KWindowSystem::transientFor(WId win)
0502 {
0503     Q_D(KWindowSystem);
0504     return d->transientFor(win);
0505 }
0506 
0507 void KWindowSystem::setMainWindow(QWidget *subWidget, WId mainWindowId)
0508 {
0509     // Set the WA_NativeWindow attribute to force the creation of the QWindow.
0510     // Without this QWidget::windowHandle() returns 0.
0511     subWidget->setAttribute(Qt::WA_NativeWindow, true);
0512     QWindow *subWindow = subWidget->windowHandle();
0513     Q_ASSERT(subWindow);
0514     setMainWindow(subWindow, mainWindowId);
0515 }
0516 #endif
0517 
0518 void KWindowSystem::setMainWindow(QWindow *subWindow, WId mainWindowId)
0519 {
0520     QWindow *mainWindow = QWindow::fromWinId(mainWindowId);
0521     if (mainWindow) { // foreign windows not supported on all platforms
0522         subWindow->setTransientParent(mainWindow);
0523 
0524         // mainWindow is not the child of any object, so make sure it gets deleted at some point
0525         connect(subWindow, &QObject::destroyed, mainWindow, &QObject::deleteLater);
0526     }
0527 }
0528 
0529 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
0530 WId KWindowSystem::groupLeader(WId win)
0531 {
0532     Q_D(KWindowSystem);
0533     return d->groupLeader(win);
0534 }
0535 #endif
0536 
0537 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0538 QPixmap KWindowSystem::icon(WId win, int width, int height, bool scale)
0539 {
0540     return icon(win, width, height, scale, NETWM | WMHints | ClassHint | XApp);
0541 }
0542 #endif
0543 
0544 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0545 QPixmap KWindowSystem::icon(WId win, int width, int height, bool scale, int flags)
0546 {
0547     Q_D(KWindowSystem);
0548     return d->icon(win, width, height, scale, flags);
0549 }
0550 #endif
0551 
0552 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0553 QPixmap KWindowSystem::icon(WId win, int width, int height, bool scale, int flags, NETWinInfo *info)
0554 {
0555     Q_D(KWindowSystem);
0556     width *= qApp->devicePixelRatio();
0557     height *= qApp->devicePixelRatio();
0558 #if KWINDOWSYSTEM_HAVE_X11
0559     if (info) {
0560         if (isPlatformX11()) {
0561             // this is the xcb plugin, we can just delegate
0562             return d->iconFromNetWinInfo(width, height, scale, flags, info);
0563         } else {
0564             // other platform plugin, load xcb plugin to delegate to it
0565             if (KWindowSystemPrivate *p = g_kwmInstanceContainer()->xcbPlugin()) {
0566                 return p->iconFromNetWinInfo(width, height, scale, flags, info);
0567             }
0568         }
0569     }
0570 #else
0571     Q_UNUSED(info)
0572 #endif
0573     return d->icon(win, width, height, scale, flags);
0574 }
0575 #endif
0576 
0577 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0578 void KWindowSystem::setIcons(WId win, const QPixmap &icon, const QPixmap &miniIcon)
0579 {
0580     Q_D(KWindowSystem);
0581     d->setIcons(win, icon, miniIcon);
0582 }
0583 #endif
0584 
0585 void KWindowSystem::setType(WId win, NET::WindowType windowType)
0586 {
0587     Q_D(KWindowSystem);
0588     d->setType(win, windowType);
0589 }
0590 
0591 void KWindowSystem::setState(WId win, NET::States state)
0592 {
0593     Q_D(KWindowSystem);
0594     d->setState(win, state);
0595 }
0596 
0597 void KWindowSystem::clearState(WId win, NET::States state)
0598 {
0599     Q_D(KWindowSystem);
0600     d->clearState(win, state);
0601 }
0602 
0603 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0604 void KWindowSystem::minimizeWindow(WId win)
0605 {
0606     Q_D(KWindowSystem);
0607     d->minimizeWindow(win);
0608 }
0609 #endif
0610 
0611 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0612 void KWindowSystem::unminimizeWindow(WId win)
0613 {
0614     Q_D(KWindowSystem);
0615     d->unminimizeWindow(win);
0616 }
0617 #endif
0618 
0619 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
0620 void KWindowSystem::minimizeWindow(WId win, bool animation)
0621 {
0622     Q_UNUSED(animation)
0623     minimizeWindow(win);
0624 }
0625 #endif
0626 
0627 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
0628 void KWindowSystem::unminimizeWindow(WId win, bool animation)
0629 {
0630     Q_UNUSED(animation)
0631     unminimizeWindow(win);
0632 }
0633 #endif
0634 
0635 void KWindowSystem::raiseWindow(WId win)
0636 {
0637     Q_D(KWindowSystem);
0638     d->raiseWindow(win);
0639 }
0640 
0641 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0642 void KWindowSystem::lowerWindow(WId win)
0643 {
0644     Q_D(KWindowSystem);
0645     d->lowerWindow(win);
0646 }
0647 #endif
0648 
0649 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0650 bool KWindowSystem::compositingActive()
0651 {
0652     Q_D(KWindowSystem);
0653     return d->compositingActive();
0654 }
0655 #endif
0656 
0657 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0658 QRect KWindowSystem::workArea(int desktop)
0659 {
0660     Q_D(KWindowSystem);
0661     return d->workArea(desktop) / qApp->devicePixelRatio();
0662 }
0663 #endif
0664 
0665 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0666 QRect KWindowSystem::workArea(const QList<WId> &exclude, int desktop)
0667 {
0668     Q_D(KWindowSystem);
0669     return d->workArea(exclude, desktop) / qApp->devicePixelRatio();
0670 }
0671 #endif
0672 
0673 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0674 QString KWindowSystem::desktopName(int desktop)
0675 {
0676     Q_D(KWindowSystem);
0677     return d->desktopName(desktop);
0678 }
0679 #endif
0680 
0681 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0682 void KWindowSystem::setDesktopName(int desktop, const QString &name)
0683 {
0684     Q_D(KWindowSystem);
0685     d->setDesktopName(desktop, name);
0686 }
0687 #endif
0688 
0689 bool KWindowSystem::showingDesktop()
0690 {
0691     Q_D(KWindowSystem);
0692     return d->showingDesktop();
0693 }
0694 
0695 void KWindowSystem::setShowingDesktop(bool showing)
0696 {
0697     Q_D(KWindowSystem);
0698     return d->setShowingDesktop(showing);
0699 }
0700 
0701 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0702 void KWindowSystem::setUserTime(WId win, long time)
0703 {
0704     Q_D(KWindowSystem);
0705     d->setUserTime(win, time);
0706 }
0707 #endif
0708 
0709 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0710 void KWindowSystem::setExtendedStrut(WId win,
0711                                      int left_width,
0712                                      int left_start,
0713                                      int left_end,
0714                                      int right_width,
0715                                      int right_start,
0716                                      int right_end,
0717                                      int top_width,
0718                                      int top_start,
0719                                      int top_end,
0720                                      int bottom_width,
0721                                      int bottom_start,
0722                                      int bottom_end)
0723 {
0724     Q_D(KWindowSystem);
0725     const qreal dpr = qApp->devicePixelRatio();
0726     d->setExtendedStrut(win,
0727                         left_width * dpr,
0728                         left_start * dpr,
0729                         left_end * dpr,
0730                         right_width * dpr,
0731                         right_start * dpr,
0732                         right_end * dpr,
0733                         top_width * dpr,
0734                         top_start * dpr,
0735                         top_end * dpr,
0736                         bottom_width * dpr,
0737                         bottom_start * dpr,
0738                         bottom_end * dpr);
0739 }
0740 #endif
0741 
0742 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0743 void KWindowSystem::setStrut(WId win, int left, int right, int top, int bottom)
0744 {
0745     Q_D(KWindowSystem);
0746     const qreal dpr = qApp->devicePixelRatio();
0747     d->setStrut(win, left * dpr, right * dpr, top * dpr, bottom * dpr);
0748 }
0749 #endif
0750 
0751 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0752 bool KWindowSystem::icccmCompliantMappingState()
0753 {
0754     Q_D(KWindowSystem);
0755     return d->icccmCompliantMappingState();
0756 }
0757 #endif
0758 
0759 bool KWindowSystem::allowedActionsSupported()
0760 {
0761     Q_D(KWindowSystem);
0762     return d->allowedActionsSupported();
0763 }
0764 
0765 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0766 QString KWindowSystem::readNameProperty(WId win, unsigned long atom)
0767 {
0768     Q_D(KWindowSystem);
0769     return d->readNameProperty(win, atom);
0770 }
0771 #endif
0772 
0773 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 104)
0774 void KWindowSystem::allowExternalProcessWindowActivation(int pid)
0775 {
0776     Q_D(KWindowSystem);
0777     d->allowExternalProcessWindowActivation(pid);
0778 }
0779 #endif
0780 
0781 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0782 void KWindowSystem::setBlockingCompositing(WId window, bool active)
0783 {
0784     Q_D(KWindowSystem);
0785     d->setBlockingCompositing(window, active);
0786 }
0787 #endif
0788 
0789 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0790 bool KWindowSystem::mapViewport()
0791 {
0792     Q_D(KWindowSystem);
0793     return d->mapViewport();
0794 }
0795 #endif
0796 
0797 int KWindowSystem::viewportToDesktop(const QPoint &p)
0798 {
0799     Q_D(KWindowSystem);
0800     return d->viewportToDesktop(p / qApp->devicePixelRatio());
0801 }
0802 
0803 int KWindowSystem::viewportWindowToDesktop(const QRect &r)
0804 {
0805     Q_D(KWindowSystem);
0806     return d->viewportWindowToDesktop(r / qApp->devicePixelRatio());
0807 }
0808 
0809 QPoint KWindowSystem::desktopToViewport(int desktop, bool absolute)
0810 {
0811     Q_D(KWindowSystem);
0812     return d->desktopToViewport(desktop, absolute);
0813 }
0814 
0815 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 101)
0816 QPoint KWindowSystem::constrainViewportRelativePosition(const QPoint &pos)
0817 {
0818     Q_D(KWindowSystem);
0819     return d->constrainViewportRelativePosition(pos / qApp->devicePixelRatio());
0820 }
0821 #endif
0822 
0823 static inline KWindowSystem::Platform initPlatform()
0824 {
0825     auto platformName = QGuiApplication::platformName();
0826     if (platformName == QLatin1String("flatpak")) {
0827         // here we cannot know what is the actual windowing system, let's try it's env variable
0828         const auto flatpakPlatform = QString::fromLocal8Bit(qgetenv("QT_QPA_FLATPAK_PLATFORM"));
0829         if (!flatpakPlatform.isEmpty()) {
0830             platformName = flatpakPlatform;
0831         }
0832     }
0833 #if KWINDOWSYSTEM_HAVE_X11
0834     if (platformName == QLatin1String("xcb")) {
0835         return KWindowSystem::Platform::X11;
0836     }
0837 #endif
0838     if (platformName.startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
0839         return KWindowSystem::Platform::Wayland;
0840     }
0841     return KWindowSystem::Platform::Unknown;
0842 }
0843 
0844 KWindowSystem::Platform KWindowSystem::platform()
0845 {
0846     static Platform s_platform = initPlatform();
0847     return s_platform;
0848 }
0849 
0850 bool KWindowSystem::isPlatformX11()
0851 {
0852     return platform() == Platform::X11;
0853 }
0854 
0855 bool KWindowSystem::isPlatformWayland()
0856 {
0857     return platform() == Platform::Wayland;
0858 }
0859 
0860 void KWindowSystem::updateStartupId(QWindow *window)
0861 {
0862     // clang-format off
0863     // TODO: move to a new KWindowSystemPrivate interface
0864 #if KWINDOWSYSTEM_HAVE_X11
0865     if (isPlatformX11()) {
0866         const QByteArray startupId = QX11Info::nextStartupId();
0867         if (!startupId.isEmpty()) {
0868             KStartupInfo::setNewStartupId(window, startupId);
0869         }
0870     } else
0871 #else
0872     Q_UNUSED(window);
0873 #endif
0874     if (isPlatformWayland()) {
0875         const QString token = qEnvironmentVariable("XDG_ACTIVATION_TOKEN");
0876         if (!token.isEmpty()) {
0877             setCurrentXdgActivationToken(token);
0878             qunsetenv("XDG_ACTIVATION_TOKEN");
0879         }
0880     }
0881     // clang-format on
0882 }
0883 
0884 void KWindowSystem::requestXdgActivationToken(QWindow *win, uint32_t serial, const QString &app_id)
0885 {
0886     Q_D(KWindowSystem);
0887     auto dv2 = dynamic_cast<KWindowSystemPrivateV2 *>(d);
0888     if (!dv2) {
0889         // Ensure that xdgActivationTokenArrived is always emitted asynchronously
0890         QTimer::singleShot(0, [serial] {
0891             Q_EMIT KWindowSystem::self()->xdgActivationTokenArrived(serial, {});
0892         });
0893 
0894         return;
0895     }
0896     dv2->requestToken(win, serial, app_id);
0897 }
0898 
0899 void KWindowSystem::setCurrentXdgActivationToken(const QString &token)
0900 {
0901     Q_D(KWindowSystem);
0902     auto dv2 = dynamic_cast<KWindowSystemPrivateV2 *>(d);
0903     if (!dv2) {
0904         return;
0905     }
0906     dv2->setCurrentToken(token);
0907 }
0908 
0909 quint32 KWindowSystem::lastInputSerial(QWindow *window)
0910 {
0911     Q_D(KWindowSystem);
0912     auto dv2 = dynamic_cast<KWindowSystemPrivateV2 *>(d);
0913     if (!dv2) {
0914         return 0;
0915     }
0916     return dv2->lastInputSerial(window);
0917 }
0918 
0919 #include "moc_kwindowsystem.cpp"