File indexing completed on 2024-12-22 05:09:24
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 0007 #include "surface_p.h" 0008 #include "surface.h" 0009 0010 #include <QGuiApplication> 0011 #include <private/qwaylandwindow_p.h> 0012 #include <qpa/qplatformnativeinterface.h> 0013 0014 namespace KWayland 0015 { 0016 namespace Client 0017 { 0018 0019 // The file split from surface.cpp because QtWaylandClient private headers require to unset QT_NO_KEYWORDS. 0020 Surface *Surface::fromWindow(QWindow *window) 0021 { 0022 if (!window) { 0023 return nullptr; 0024 } 0025 QPlatformNativeInterface *native = qApp->platformNativeInterface(); 0026 if (!native) { 0027 return nullptr; 0028 } 0029 window->create(); 0030 wl_surface *s = reinterpret_cast<wl_surface *>(native->nativeResourceForWindow(QByteArrayLiteral("surface"), window)); 0031 if (!s) { 0032 return nullptr; 0033 } 0034 if (auto surface = get(s)) { 0035 return surface; 0036 } 0037 Surface *surface = new Surface(window); 0038 surface->d->surface.setup(s, true); 0039 0040 auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle()); 0041 if (waylandWindow) { 0042 connect(waylandWindow, &QtWaylandClient::QWaylandWindow::wlSurfaceDestroyed, surface, &QObject::deleteLater); 0043 } 0044 return surface; 0045 } 0046 0047 Surface *Surface::fromQtWinId(WId wid) 0048 { 0049 QWindow *window = nullptr; 0050 0051 for (auto win : qApp->allWindows()) { 0052 if (win->winId() == wid) { 0053 window = win; 0054 break; 0055 } 0056 } 0057 0058 if (!window) { 0059 return nullptr; 0060 } 0061 return fromWindow(window); 0062 } 0063 0064 } 0065 }