Changeset View
Changeset View
Standalone View
Standalone View
plugins/qpa/integration.cpp
1 | /******************************************************************** | 1 | /******************************************************************** | ||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | 2 | KWin - the KDE window manager | ||
3 | This file is part of the KDE project. | 3 | This file is part of the KDE project. | ||
4 | 4 | | |||
5 | Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org> | 5 | Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org> | ||
6 | Copyright (C) 2019 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
6 | 7 | | |||
7 | This program is free software; you can redistribute it and/or modify | 8 | This program is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | 9 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation; either version 2 of the License, or | 10 | the Free Software Foundation; either version 2 of the License, or | ||
10 | (at your option) any later version. | 11 | (at your option) any later version. | ||
11 | 12 | | |||
12 | This program is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | 16 | GNU General Public License for more details. | ||
16 | 17 | | |||
17 | You should have received a copy of the GNU General Public License | 18 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 20 | *********************************************************************/ | ||
20 | #include "integration.h" | 21 | #include "integration.h" | ||
21 | #include "backingstore.h" | 22 | #include "backingstore.h" | ||
22 | #include "nativeinterface.h" | | |||
23 | #include "offscreensurface.h" | 23 | #include "offscreensurface.h" | ||
24 | #include "screen.h" | 24 | #include "screen.h" | ||
25 | #include "sharingplatformcontext.h" | 25 | #include "sharingplatformcontext.h" | ||
26 | #include "window.h" | 26 | #include "window.h" | ||
27 | #include "../../main.h" | 27 | #include "../../main.h" | ||
28 | #include "../../platform.h" | 28 | #include "../../platform.h" | ||
29 | #include "../../screens.h" | 29 | #include "../../screens.h" | ||
30 | #include "../../virtualkeyboard.h" | 30 | #include "../../virtualkeyboard.h" | ||
31 | #include "../../wayland_server.h" | | |||
32 | | ||||
33 | #include <KWayland/Client/compositor.h> | | |||
34 | #include <KWayland/Client/connection_thread.h> | | |||
35 | #include <KWayland/Client/registry.h> | | |||
36 | #include <KWayland/Client/shell.h> | | |||
37 | #include <KWayland/Client/surface.h> | | |||
38 | #include <KWayland/Server/clientconnection.h> | | |||
39 | 31 | | |||
40 | #include <QCoreApplication> | 32 | #include <QCoreApplication> | ||
41 | #include <QtConcurrentRun> | 33 | #include <QtConcurrentRun> | ||
42 | 34 | | |||
43 | #include <qpa/qplatforminputcontext.h> | 35 | #include <qpa/qplatforminputcontext.h> | ||
44 | #include <qpa/qplatforminputcontextfactory_p.h> | 36 | #include <qpa/qplatforminputcontextfactory_p.h> | ||
45 | #include <qpa/qplatformwindow.h> | 37 | #include <qpa/qplatformwindow.h> | ||
46 | #include <qpa/qwindowsysteminterface.h> | 38 | #include <qpa/qwindowsysteminterface.h> | ||
47 | 39 | | |||
48 | #include <QtEventDispatcherSupport/private/qunixeventdispatcher_qpa_p.h> | 40 | #include <QtEventDispatcherSupport/private/qunixeventdispatcher_qpa_p.h> | ||
49 | #include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h> | 41 | #include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h> | ||
50 | #include <QtThemeSupport/private/qgenericunixthemes_p.h> | 42 | #include <QtThemeSupport/private/qgenericunixthemes_p.h> | ||
51 | 43 | | |||
52 | namespace KWin | 44 | namespace KWin | ||
53 | { | 45 | { | ||
54 | 46 | | |||
55 | namespace QPA | 47 | namespace QPA | ||
56 | { | 48 | { | ||
57 | 49 | | |||
58 | Integration::Integration() | 50 | Integration::Integration() | ||
59 | : QObject() | 51 | : QObject() | ||
60 | , QPlatformIntegration() | 52 | , QPlatformIntegration() | ||
61 | , m_fontDb(new QGenericUnixFontDatabase()) | 53 | , m_fontDb(new QGenericUnixFontDatabase()) | ||
62 | , m_nativeInterface(new NativeInterface(this)) | | |||
63 | , m_inputContext() | 54 | , m_inputContext() | ||
64 | { | 55 | { | ||
65 | } | 56 | } | ||
66 | 57 | | |||
67 | Integration::~Integration() = default; | 58 | Integration::~Integration() = default; | ||
68 | 59 | | |||
69 | bool Integration::hasCapability(Capability cap) const | 60 | bool Integration::hasCapability(Capability cap) const | ||
70 | { | 61 | { | ||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
134 | 125 | | |||
135 | QAbstractEventDispatcher *Integration::createEventDispatcher() const | 126 | QAbstractEventDispatcher *Integration::createEventDispatcher() const | ||
136 | { | 127 | { | ||
137 | return new QUnixEventDispatcherQPA; | 128 | return new QUnixEventDispatcherQPA; | ||
138 | } | 129 | } | ||
139 | 130 | | |||
140 | QPlatformBackingStore *Integration::createPlatformBackingStore(QWindow *window) const | 131 | QPlatformBackingStore *Integration::createPlatformBackingStore(QWindow *window) const | ||
141 | { | 132 | { | ||
142 | auto registry = waylandServer()->internalClientRegistry(); | 133 | return new BackingStore(window); | ||
143 | const auto shm = registry->interface(KWayland::Client::Registry::Interface::Shm); | | |||
144 | if (shm.name == 0u) { | | |||
145 | return nullptr; | | |||
146 | } | | |||
147 | return new BackingStore(window, registry->createShmPool(shm.name, shm.version, window)); | | |||
148 | } | 134 | } | ||
149 | 135 | | |||
150 | QPlatformWindow *Integration::createPlatformWindow(QWindow *window) const | 136 | QPlatformWindow *Integration::createPlatformWindow(QWindow *window) const | ||
151 | { | 137 | { | ||
152 | auto c = compositor(); | 138 | return new Window(window); | ||
153 | auto s = shell(); | | |||
154 | if (!s || !c) { | | |||
155 | return new QPlatformWindow(window); | | |||
156 | } else { | | |||
157 | // don't set window as parent, cause infinite recursion in PlasmaQuick::Dialog | | |||
158 | auto surface = c->createSurface(c); | | |||
159 | return new Window(window, surface, s->createSurface(surface, surface), this); | | |||
160 | } | | |||
161 | } | 139 | } | ||
162 | 140 | | |||
163 | QPlatformOffscreenSurface *Integration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const | 141 | QPlatformOffscreenSurface *Integration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const | ||
164 | { | 142 | { | ||
165 | return new OffscreenSurface(surface); | 143 | return new OffscreenSurface(surface); | ||
166 | } | 144 | } | ||
167 | 145 | | |||
168 | QPlatformFontDatabase *Integration::fontDatabase() const | 146 | QPlatformFontDatabase *Integration::fontDatabase() const | ||
Show All 9 Lines | |||||
178 | QStringList Integration::themeNames() const | 156 | QStringList Integration::themeNames() const | ||
179 | { | 157 | { | ||
180 | if (qEnvironmentVariableIsSet("KDE_FULL_SESSION")) { | 158 | if (qEnvironmentVariableIsSet("KDE_FULL_SESSION")) { | ||
181 | return QStringList({QStringLiteral("kde")}); | 159 | return QStringList({QStringLiteral("kde")}); | ||
182 | } | 160 | } | ||
183 | return QStringList({QLatin1String(QGenericUnixTheme::name)}); | 161 | return QStringList({QLatin1String(QGenericUnixTheme::name)}); | ||
184 | } | 162 | } | ||
185 | 163 | | |||
186 | QPlatformNativeInterface *Integration::nativeInterface() const | | |||
187 | { | | |||
188 | return m_nativeInterface; | | |||
189 | } | | |||
190 | | ||||
191 | QPlatformOpenGLContext *Integration::createPlatformOpenGLContext(QOpenGLContext *context) const | 164 | QPlatformOpenGLContext *Integration::createPlatformOpenGLContext(QOpenGLContext *context) const | ||
192 | { | 165 | { | ||
193 | if (kwinApp()->platform()->supportsQpaContext()) { | 166 | if (kwinApp()->platform()->supportsQpaContext()) { | ||
194 | return new SharingPlatformContext(context); | 167 | return new SharingPlatformContext(context); | ||
195 | } | 168 | } | ||
196 | if (kwinApp()->platform()->sceneEglDisplay() != EGL_NO_DISPLAY) { | 169 | if (kwinApp()->platform()->sceneEglDisplay() != EGL_NO_DISPLAY) { | ||
197 | auto s = kwinApp()->platform()->sceneEglSurface(); | 170 | auto s = kwinApp()->platform()->sceneEglSurface(); | ||
198 | if (s != EGL_NO_SURFACE) { | 171 | if (s != EGL_NO_SURFACE) { | ||
Show All 31 Lines | 202 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)) | |||
230 | QWindowSystemInterface::handleScreenRemoved(m_screens.takeLast()); | 203 | QWindowSystemInterface::handleScreenRemoved(m_screens.takeLast()); | ||
231 | #else | 204 | #else | ||
232 | destroyScreen(m_screens.takeLast()); | 205 | destroyScreen(m_screens.takeLast()); | ||
233 | #endif | 206 | #endif | ||
234 | } | 207 | } | ||
235 | m_screens = newScreens; | 208 | m_screens = newScreens; | ||
236 | } | 209 | } | ||
237 | 210 | | |||
238 | KWayland::Client::Compositor *Integration::compositor() const | | |||
239 | { | | |||
240 | if (!m_compositor) { | | |||
241 | using namespace KWayland::Client; | | |||
242 | auto registry = waylandServer()->internalClientRegistry(); | | |||
243 | const auto c = registry->interface(Registry::Interface::Compositor); | | |||
244 | if (c.name != 0u) { | | |||
245 | const_cast<Integration*>(this)->m_compositor = registry->createCompositor(c.name, c.version, registry); | | |||
246 | } | | |||
247 | } | | |||
248 | return m_compositor; | | |||
249 | } | | |||
250 | | ||||
251 | KWayland::Client::Shell *Integration::shell() const | | |||
252 | { | | |||
253 | if (!m_shell) { | | |||
254 | using namespace KWayland::Client; | | |||
255 | auto registry = waylandServer()->internalClientRegistry(); | | |||
256 | const auto s = registry->interface(Registry::Interface::Shell); | | |||
257 | if (s.name != 0u) { | | |||
258 | const_cast<Integration*>(this)->m_shell = registry->createShell(s.name, s.version, registry); | | |||
259 | } | | |||
260 | } | | |||
261 | return m_shell; | | |||
262 | } | | |||
263 | | ||||
264 | EGLDisplay Integration::eglDisplay() const | | |||
265 | { | | |||
266 | return m_eglDisplay; | | |||
267 | } | | |||
268 | | ||||
269 | QPlatformInputContext *Integration::inputContext() const | 211 | QPlatformInputContext *Integration::inputContext() const | ||
270 | { | 212 | { | ||
271 | return m_inputContext.data(); | 213 | return m_inputContext.data(); | ||
272 | } | 214 | } | ||
273 | 215 | | |||
274 | } | 216 | } | ||
275 | } | 217 | } |