1// Copyright (C) 2017 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 "qwaylandxdgshell_p.h"
5#include "qwaylandxdgshellintegration_p.h"
6#include "qwaylandxdgdecorationv1_p.h"
7
8#include <QtWaylandClient/private/qwaylandwindow_p.h>
9#include <QtWaylandClient/private/qwaylanddisplay_p.h>
10
11#include <qpa/qwindowsysteminterface.h>
12
13QT_BEGIN_NAMESPACE
14
15namespace QtWaylandClient {
16
17QWaylandXdgShellIntegration::QWaylandXdgShellIntegration() : QWaylandShellIntegrationTemplate(6)
18{
19 connect(sender: this, signal: &QWaylandShellIntegrationTemplate::activeChanged, context: this, slot: [this] {
20 if (isActive()) {
21 mXdgShell.reset(new QWaylandXdgShell(mDisplay, this));
22 } else {
23 mXdgShell.reset(other: nullptr);
24 destroy();
25 }
26 });
27}
28
29QWaylandXdgShellIntegration::~QWaylandXdgShellIntegration()
30{
31 if (isActive())
32 destroy();
33}
34
35bool QWaylandXdgShellIntegration::initialize(QWaylandDisplay *display)
36{
37 mDisplay = display;
38 return QWaylandShellIntegrationTemplate::initialize(display);
39}
40
41void QWaylandXdgShellIntegration::xdg_wm_base_ping(uint32_t serial)
42{
43 pong(serial);
44}
45
46QWaylandShellSurface *QWaylandXdgShellIntegration::createShellSurface(QWaylandWindow *window)
47{
48 QWaylandDisplay *display = window->display();
49 Qt::WindowType type = static_cast<Qt::WindowType>(int(window->windowFlags() & Qt::WindowType_Mask));
50 auto *transientParent = window->transientParent();
51
52 if (type == Qt::ToolTip && !transientParent) {
53 qCWarning(lcQpaWayland) << "Failed to create popup. Ensure popup " << window->window() << "has a transientParent set.";
54 QWindowSystemInterface::handleCloseEvent<QWindowSystemInterface::AsynchronousDelivery>(window->window());
55 return new QWaylandShellSurface(window);
56 }
57
58 if (type == Qt::Popup && (!transientParent || !display->lastInputDevice())) {
59 qCWarning(lcQpaWayland) << "Failed to create grabbing popup. Ensure popup " << window->window() << "has a transientParent set and that parent window has received input.";
60 QWindowSystemInterface::handleCloseEvent<QWindowSystemInterface::AsynchronousDelivery>(window->window());
61 return new QWaylandShellSurface(window);
62 }
63
64 return new QWaylandXdgSurface(mXdgShell.get(), get_xdg_surface(window->wlSurface()), window);
65}
66
67void *QWaylandXdgShellIntegration::nativeResourceForWindow(const QByteArray &resource, QWindow *window)
68{
69 if (auto waylandWindow = static_cast<QWaylandWindow *>(window->handle())) {
70 if (auto xdgSurface = qobject_cast<QWaylandXdgSurface *>(object: waylandWindow->shellSurface())) {
71 return xdgSurface->nativeResource(resource);
72 }
73 }
74 return nullptr;
75}
76
77}
78
79QT_END_NAMESPACE
80

source code of qtbase/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshellintegration.cpp