Changeset View
Changeset View
Standalone View
Standalone View
src/plasmaquick/waylandintegration.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2020 Vlad Zahorodnii <vladzzag@gmail.com> | ||||
3 | * | ||||
4 | * Based on WaylandIntegration from kwayland-integration | ||||
5 | * | ||||
6 | * Copyright 2014 Martin Gräßlin <mgraesslin@kde.org> | ||||
7 | * Copyright 2015 Marco Martin <mart@kde.org> | ||||
8 | * | ||||
9 | * This program is free software; you can redistribute it and/or modify | ||||
10 | * it under the terms of the GNU General Public License as published by | ||||
11 | * the Free Software Foundation; either version 2 of the License, or | ||||
12 | * (at your option) any later version. | ||||
13 | * | ||||
14 | * This program is distributed in the hope that it will be useful, | ||||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
17 | * GNU General Public License for more details. | ||||
18 | * | ||||
19 | * You should have received a copy of the GNU General Public License | ||||
20 | * along with this program; if not, write to the Free Software | ||||
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
22 | */ | ||||
23 | | ||||
24 | #include "waylandintegration_p.h" | ||||
25 | #include "debug_p.h" | ||||
26 | | ||||
27 | #include <KWayland/Client/connection_thread.h> | ||||
28 | #include <KWayland/Client/plasmashell.h> | ||||
29 | #include <KWayland/Client/registry.h> | ||||
30 | #include <KWayland/Client/shadow.h> | ||||
31 | #include <KWayland/Client/shm_pool.h> | ||||
32 | | ||||
33 | #include <QCoreApplication> | ||||
34 | | ||||
35 | class WaylandIntegrationSingleton | ||||
36 | { | ||||
37 | public: | ||||
38 | WaylandIntegration self; | ||||
39 | }; | ||||
40 | | ||||
41 | Q_GLOBAL_STATIC(WaylandIntegrationSingleton, privateWaylandIntegration) | ||||
42 | | ||||
43 | WaylandIntegration::WaylandIntegration(QObject *parent) | ||||
44 | : QObject(parent) | ||||
45 | { | ||||
46 | setupKWaylandIntegration(); | ||||
47 | } | ||||
48 | | ||||
49 | WaylandIntegration::~WaylandIntegration() | ||||
50 | { | ||||
51 | } | ||||
52 | | ||||
53 | KWayland::Client::PlasmaShell *WaylandIntegration::waylandPlasmaShell() | ||||
54 | { | ||||
55 | if (!m_waylandPlasmaShell && m_registry) { | ||||
56 | const KWayland::Client::Registry::AnnouncedInterface interface = | ||||
57 | m_registry->interface(KWayland::Client::Registry::Interface::PlasmaShell); | ||||
58 | | ||||
59 | if (interface.name == 0) { | ||||
60 | qCWarning(LOG_PLASMAQUICK) << "The compositor does not support the plasma shell protocol"; | ||||
61 | return nullptr; | ||||
62 | } | ||||
63 | | ||||
64 | m_waylandPlasmaShell = m_registry->createPlasmaShell(interface.name, interface.version, qApp); | ||||
65 | | ||||
66 | connect(m_waylandPlasmaShell, &KWayland::Client::PlasmaShell::removed, this, [this]() { | ||||
67 | m_waylandPlasmaShell->deleteLater(); | ||||
68 | }); | ||||
69 | } | ||||
70 | | ||||
71 | return m_waylandPlasmaShell; | ||||
72 | } | ||||
73 | | ||||
74 | KWayland::Client::ShadowManager *WaylandIntegration::waylandShadowManager() | ||||
75 | { | ||||
76 | if (!m_waylandShadowManager && m_registry) { | ||||
77 | const KWayland::Client::Registry::AnnouncedInterface interface = | ||||
78 | m_registry->interface(KWayland::Client::Registry::Interface::Shadow); | ||||
79 | | ||||
80 | if (interface.name == 0) { | ||||
81 | qCWarning(LOG_PLASMAQUICK) << "The compositor does not support the shadow protocol"; | ||||
82 | return nullptr; | ||||
83 | } | ||||
84 | | ||||
85 | m_waylandShadowManager = m_registry->createShadowManager(interface.name, interface.version, qApp); | ||||
86 | | ||||
87 | connect(m_waylandShadowManager, &KWayland::Client::ShadowManager::removed, this, [this]() { | ||||
88 | m_waylandShadowManager->deleteLater(); | ||||
89 | }); | ||||
90 | } | ||||
91 | | ||||
92 | return m_waylandShadowManager; | ||||
93 | } | ||||
94 | | ||||
95 | KWayland::Client::ShmPool *WaylandIntegration::waylandShmPool() | ||||
96 | { | ||||
97 | if (!m_waylandShmPool && m_registry) { | ||||
98 | const KWayland::Client::Registry::AnnouncedInterface interface = | ||||
99 | m_registry->interface(KWayland::Client::Registry::Interface::Shm); | ||||
100 | | ||||
101 | if (interface.name == 0) { | ||||
102 | return nullptr; | ||||
103 | } | ||||
104 | | ||||
105 | m_waylandShmPool = m_registry->createShmPool(interface.name, interface.version, qApp); | ||||
106 | | ||||
107 | connect(m_waylandShmPool, &KWayland::Client::ShmPool::removed, this, [this]() { | ||||
108 | m_waylandShmPool->deleteLater(); | ||||
109 | }); | ||||
110 | } | ||||
111 | | ||||
112 | return m_waylandShmPool; | ||||
113 | } | ||||
114 | | ||||
115 | WaylandIntegration *WaylandIntegration::self() | ||||
116 | { | ||||
117 | return &privateWaylandIntegration()->self; | ||||
118 | } | ||||
119 | | ||||
120 | void WaylandIntegration::setupKWaylandIntegration() | ||||
121 | { | ||||
122 | KWayland::Client::ConnectionThread *connection = KWayland::Client::ConnectionThread::fromApplication(this); | ||||
123 | if (!connection) { | ||||
124 | return; | ||||
125 | } | ||||
126 | | ||||
127 | m_registry = new KWayland::Client::Registry(qApp); | ||||
128 | m_registry->create(connection); | ||||
129 | m_registry->setup(); | ||||
130 | | ||||
131 | connection->roundtrip(); | ||||
132 | } |