summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wayland/qwaylandplatformservices.cpp
blob: 74d8c2e2e3be63b21908d91a13ef30977ea6b4d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qwaylandappmenu_p.h"
#include "qwaylandplatformservices_p.h"
#include "qwaylandwindow_p.h"
#include "qwaylanddisplay_p.h"
#include "qwaylandshellsurface_p.h"
#include "qwaylandwindowmanagerintegration_p.h"

QT_BEGIN_NAMESPACE

namespace QtWaylandClient {

QWaylandPlatformServices::QWaylandPlatformServices(QWaylandDisplay *display)
    : m_display(display) { }

QWaylandPlatformServices::~QWaylandPlatformServices()
{
    qDeleteAll(m_appMenus);
}

bool QWaylandPlatformServices::openUrl(const QUrl &url)
{
    if (auto windowManagerIntegration = m_display->windowManagerIntegration()) {
        windowManagerIntegration->openUrl(url);
        return true;
    }
    return QDesktopUnixServices::openUrl(url);
}

bool QWaylandPlatformServices::openDocument(const QUrl &url)
{
    if (auto windowManagerIntegration = m_display->windowManagerIntegration()) {
        windowManagerIntegration->openUrl(url);
        return true;
    }
    return QDesktopUnixServices::openDocument(url);
}

QString QWaylandPlatformServices::portalWindowIdentifier(QWindow *window)
{
    if (window && window->handle()) {
        auto shellSurface = static_cast<QWaylandWindow *>(window->handle())->shellSurface();
        if (shellSurface) {
            const QString handle = shellSurface->externWindowHandle();
            return QLatin1String("wayland:") + handle;
        }
    }
    return QString();
}

void QWaylandPlatformServices::registerDBusMenuForWindow(QWindow *window, const QString &service,
                                                         const QString &path)
{
    if (!m_display->appMenuManager())
        return;
    if (!window)
        return;
    if (!window->handle())
        window->create();
    auto waylandWindow = static_cast<QWaylandWindow *>(window->handle());
    auto menu = *m_appMenus.insert(window, new QWaylandAppMenu);

    auto createAppMenu = [waylandWindow, menu, service, path] {
        menu->init(waylandWindow->display()->appMenuManager()->create(waylandWindow->wlSurface()));
        menu->set_address(service, path);
    };

    if (waylandWindow->wlSurface())
        createAppMenu();

    QObject::connect(waylandWindow, &QWaylandWindow::wlSurfaceCreated, menu, createAppMenu);
    QObject::connect(waylandWindow, &QWaylandWindow::wlSurfaceDestroyed, menu,
                     [menu] { menu->release(); });
}

void QWaylandPlatformServices::unregisterDBusMenuForWindow(QWindow *window)
{
    delete m_appMenus.take(window);
}
} // namespace QtWaylandClient

QT_END_NAMESPACE