Debian Codegraph @

wayland/wayland-shell/main.cpp

raw
1 // SPDX-FileCopyrightText: 2022 Uniontech Software Technology Co.,Ltd.
2 //
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4
5 #ifndef USE_DEEPIN_WAYLAND
6 #include "QtWaylandClient/private/qwaylandintegration_p.h"
7 #include "QtWaylandClient/private/qwaylandshellintegrationplugin_p.h"
8 namespace QtWaylandClient {
9 class QKWaylandShellIntegrationPlugin : public QWaylandShellIntegrationPlugin
10 {
11 Q_OBJECT
12 Q_PLUGIN_METADATA(IID QWaylandShellIntegrationFactoryInterface_iid FILE "kwayland-shell.json")
13
14 public:
15 QWaylandShellIntegration *create(const QString &key, const QStringList &paramList) override {
16 Q_UNUSED(key);
17 Q_UNUSED(paramList);
18 return nullptr;
19 }
20 };
21 }
22
23 #else
24
25 #include "vtablehook.h"
26 #include "dwaylandshellmanager.h"
27
28 #define private public
29 #include "QtWaylandClient/private/qwaylandintegration_p.h"
30 #include "QtWaylandClient/private/qwaylandshellintegrationplugin_p.h"
31 #include "QtWaylandClient/private/qwaylandshellintegration_p.h"
32 #include "QtWaylandClient/private/qwaylandshellsurface_p.h"
33 #include "QtWaylandClient/private/qwaylandwindow_p.h"
34 #undef private
35
36 #ifndef D_DEEPIN_IS_DWAYLAND
37 #include <KWayland/Client/registry.h>
38 #include <KWayland/Client/plasmashell.h>
39 #include <KWayland/Client/server_decoration.h>
40 #include <KWayland/Client/ddeshell.h>
41 #else
42 #include <DWayland/Client/registry.h>
43 #include <DWayland/Client/plasmashell.h>
44 #include <DWayland/Client/server_decoration.h>
45 #include <DWayland/Client/ddeshell.h>
46 #endif
47
48 #include <QGuiApplication>
49 #include <QPointer>
50 #include <QDebug>
51 #include <qpa/qplatformnativeinterface.h>
52 #include <private/qguiapplication_p.h>
53 #include <private/qwidgetwindow_p.h>
54
55 // 用于窗口设置和dwayland相关的特殊属性的前缀
56 // 以_d_dwayland_开头的属性需要做特殊处理,一般是用于和kwayland的交互
57 #define _DWAYALND_ "_d_dwayland_"
58
59 #define platformNativeDisplay \
60 QGuiApplication::platformNativeInterface()-> \
61 nativeResourceForIntegration(QByteArrayLiteral("display"))
62
63 DPP_USE_NAMESPACE
64
65 namespace QtWaylandClient {
66
67 class QKWaylandShellIntegrationPlugin : public QWaylandShellIntegrationPlugin
68 {
69 Q_OBJECT
70 Q_PLUGIN_METADATA(IID QWaylandShellIntegrationFactoryInterface_iid FILE "kwayland-shell.json")
71
72 public:
73 QWaylandShellIntegration *create(const QString &key, const QStringList &paramList) override;
74 };
75
76 QWaylandShellIntegration *QKWaylandShellIntegrationPlugin::create(const QString &key, const QStringList &paramList)
77 {
78 Q_UNUSED(key)
79 Q_UNUSED(paramList)
80
81 Registry *registry = DWaylandShellManager::registry();
82
83 connect(registry, &Registry::plasmaShellAnnounced,
84 &DWaylandShellManager::createKWaylandShell);
85
86 connect(registry, &Registry::serverSideDecorationManagerAnnounced,
87 &DWaylandShellManager::createKWaylandSSD);
88
89 //创建ddeshell
90 connect(registry, &Registry::ddeShellAnnounced,
91 &DWaylandShellManager::createDDEShell);
92
93 //创建ddeseat
94 connect(registry, &Registry::ddeSeatAnnounced,
95 &DWaylandShellManager::createDDESeat);
96
97 connect(registry, &Registry::interfacesAnnounced, [] {
98 DWaylandShellManager::createDDEPointer();
99 DWaylandShellManager::createDDEKeyboard();
100 DWaylandShellManager::createDDEFakeInput();
101 });
102
103 connect(registry, &Registry::strutAnnounced,
104 &DWaylandShellManager::createStrut);
105
106 connect(registry, &Registry::blurAnnounced, [](quint32 name, quint32 version) {
107 DWaylandShellManager::createBlurManager(name, version);
108 });
109
110 connect(registry, &Registry::compositorAnnounced, [](quint32 name, quint32 version){
111 DWaylandShellManager::createCompositor(name, version);
112 DWaylandShellManager::createSurface();
113 });
114
115 connect(registry, &KWayland::Client::Registry::plasmaWindowManagementAnnounced, [registry](quint32 name, quint32 version) {
116 DWaylandShellManager::createPlasmaWindowManagement(registry, name, version);
117 });
118
119 wl_display *wlDisplay = reinterpret_cast<wl_display*>(platformNativeDisplay);
120
121 registry->create(wlDisplay);
122 registry->setup();
123
124 wl_display_roundtrip(wlDisplay);
125
126 auto wayland_integration = static_cast<QWaylandIntegration *>(QGuiApplicationPrivate::platformIntegration());
127 QString shellVersion = registry->hasInterface(Registry::Interface::XdgShellUnstableV6) ? "xdg-shell-v6" : "xdg-shell";
128 QWaylandShellIntegration *shell = wayland_integration->createShellIntegration(shellVersion);
129
130 if (!shell) {
131 qInfo() << "Failed to create kwayland-shell and the shell is nullptr.";
132 return nullptr;
133 }
134
135 HookOverride(shell, &QWaylandShellIntegration::createShellSurface, DWaylandShellManager::createShellSurface);
136
137 return shell;
138 }
139
140 }
141
142 #include "main.moc"
143 #endif