| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qwaylandappmenu_p.h" |
| 5 | #include "qwaylandplatformservices_p.h" |
| 6 | #include "qwaylandwindow_p.h" |
| 7 | #include "qwaylanddisplay_p.h" |
| 8 | #include "qwaylandshellsurface_p.h" |
| 9 | #include "qwaylandwindowmanagerintegration_p.h" |
| 10 | |
| 11 | QT_BEGIN_NAMESPACE |
| 12 | |
| 13 | namespace QtWaylandClient { |
| 14 | |
| 15 | QWaylandPlatformServices::QWaylandPlatformServices(QWaylandDisplay *display) |
| 16 | : m_display(display) { } |
| 17 | |
| 18 | QWaylandPlatformServices::~QWaylandPlatformServices() |
| 19 | { |
| 20 | qDeleteAll(c: m_appMenus); |
| 21 | } |
| 22 | |
| 23 | bool QWaylandPlatformServices::openUrl(const QUrl &url) |
| 24 | { |
| 25 | if (auto windowManagerIntegration = m_display->windowManagerIntegration()) { |
| 26 | windowManagerIntegration->openUrl(url); |
| 27 | return true; |
| 28 | } |
| 29 | return QDesktopUnixServices::openUrl(url); |
| 30 | } |
| 31 | |
| 32 | bool QWaylandPlatformServices::openDocument(const QUrl &url) |
| 33 | { |
| 34 | if (auto windowManagerIntegration = m_display->windowManagerIntegration()) { |
| 35 | windowManagerIntegration->openUrl(url); |
| 36 | return true; |
| 37 | } |
| 38 | return QDesktopUnixServices::openDocument(url); |
| 39 | } |
| 40 | |
| 41 | QString QWaylandPlatformServices::portalWindowIdentifier(QWindow *window) |
| 42 | { |
| 43 | if (window && window->handle()) { |
| 44 | auto shellSurface = static_cast<QWaylandWindow *>(window->handle())->shellSurface(); |
| 45 | if (shellSurface) { |
| 46 | const QString handle = shellSurface->externWindowHandle(); |
| 47 | return QLatin1String("wayland:" ) + handle; |
| 48 | } |
| 49 | } |
| 50 | return QString(); |
| 51 | } |
| 52 | |
| 53 | void QWaylandPlatformServices::registerDBusMenuForWindow(QWindow *window, const QString &service, |
| 54 | const QString &path) |
| 55 | { |
| 56 | if (!m_display->appMenuManager()) |
| 57 | return; |
| 58 | if (!window) |
| 59 | return; |
| 60 | if (!window->handle()) |
| 61 | window->create(); |
| 62 | auto waylandWindow = static_cast<QWaylandWindow *>(window->handle()); |
| 63 | auto = *m_appMenus.insert(key: window, value: new QWaylandAppMenu); |
| 64 | |
| 65 | auto = [waylandWindow, menu, service, path] { |
| 66 | menu->init(waylandWindow->display()->appMenuManager()->create(waylandWindow->wlSurface())); |
| 67 | menu->set_address(service, path); |
| 68 | }; |
| 69 | |
| 70 | if (waylandWindow->wlSurface()) |
| 71 | createAppMenu(); |
| 72 | |
| 73 | QObject::connect(sender: waylandWindow, signal: &QWaylandWindow::wlSurfaceCreated, context: menu, slot&: createAppMenu); |
| 74 | QObject::connect(sender: waylandWindow, signal: &QWaylandWindow::wlSurfaceDestroyed, context: menu, |
| 75 | slot: [menu] { menu->release(); }); |
| 76 | } |
| 77 | |
| 78 | void QWaylandPlatformServices::unregisterDBusMenuForWindow(QWindow *window) |
| 79 | { |
| 80 | delete m_appMenus.take(key: window); |
| 81 | } |
| 82 | } // namespace QtWaylandClient |
| 83 | |
| 84 | QT_END_NAMESPACE |
| 85 | |