/* SPDX-FileCopyrightText: 2014 Martin Gräßlin SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "surface_p.h" #include "surface.h" #include #include #include namespace KWayland { namespace Client { // The file split from surface.cpp because QtWaylandClient private headers require to unset QT_NO_KEYWORDS. Surface *Surface::fromWindow(QWindow *window) { if (!window) { return nullptr; } QPlatformNativeInterface *native = qApp->platformNativeInterface(); if (!native) { return nullptr; } window->create(); wl_surface *s = reinterpret_cast(native->nativeResourceForWindow(QByteArrayLiteral("surface"), window)); if (!s) { return nullptr; } if (auto surface = get(s)) { return surface; } Surface *surface = new Surface(window); surface->d->surface.setup(s, true); auto waylandWindow = dynamic_cast(window->handle()); if (waylandWindow) { connect(waylandWindow, &QtWaylandClient::QWaylandWindow::wlSurfaceDestroyed, surface, &QObject::deleteLater); } return surface; } Surface *Surface::fromQtWinId(WId wid) { QWindow *window = nullptr; for (auto win : qApp->allWindows()) { if (win->winId() == wid) { window = win; break; } } if (!window) { return nullptr; } return fromWindow(window); } } }