KWin
Loading...
Searching...
No Matches
integration.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
6 SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#include "integration.h"
12#include "backingstore.h"
13#include "eglplatformcontext.h"
14#include "logging.h"
15#include "offscreensurface.h"
16#include "screen.h"
17#include "window.h"
18
19#include "core/output.h"
20#include "core/outputbackend.h"
21#include "main.h"
22#include "workspace.h"
23
24#include <QCoreApplication>
25#include <QTimer>
26#include <QtConcurrentRun>
27
28#include <qpa/qplatformaccessibility.h>
29#include <qpa/qplatformnativeinterface.h>
30#include <qpa/qplatformwindow.h>
31#include <qpa/qwindowsysteminterface.h>
32
33#include <QtGui/private/qgenericunixeventdispatcher_p.h>
34#include <QtGui/private/qgenericunixfontdatabase_p.h>
35#include <QtGui/private/qgenericunixthemes_p.h>
36#include <QtGui/private/qspiaccessiblebridge_p.h>
37#include <QtGui/private/qunixeventdispatcher_qpa_p.h>
38
39namespace KWin
40{
41
42namespace QPA
43{
44
46 : QObject()
47 , QPlatformIntegration()
48 , m_fontDb(new QGenericUnixFontDatabase())
49 , m_nativeInterface(new QPlatformNativeInterface())
50 , m_services(new QGenericUnixServices())
51{
52}
53
55{
56 for (QPlatformScreen *platformScreen : std::as_const(m_screens)) {
57 QWindowSystemInterface::handleScreenRemoved(platformScreen);
58 }
59 if (m_dummyScreen) {
60 QWindowSystemInterface::handleScreenRemoved(m_dummyScreen);
61 }
62}
63
64QHash<Output *, Screen *> Integration::screens() const
65{
66 return m_screens;
67}
68
69bool Integration::hasCapability(Capability cap) const
70{
71 switch (cap) {
72 case ThreadedPixmaps:
73 return true;
74 case OpenGL:
75 return true;
76 case ThreadedOpenGL:
77 return false;
78 case BufferQueueingOpenGL:
79 return false;
80 case MultipleWindows:
81 case NonFullScreenWindows:
82 return true;
83 case RasterGLSurface:
84 return false;
85 default:
86 return QPlatformIntegration::hasCapability(cap);
87 }
88}
89
91{
92 // This method is called from QGuiApplication's constructor, before kwinApp is built
93 QTimer::singleShot(0, this, [this] {
94 // The QPA is initialized before the workspace is created.
95 if (workspace()) {
96 handleWorkspaceCreated();
97 } else {
98 connect(kwinApp(), &Application::workspaceCreated, this, &Integration::handleWorkspaceCreated);
99 }
100 });
101
102 QPlatformIntegration::initialize();
103
104 m_dummyScreen = new PlaceholderScreen();
105 QWindowSystemInterface::handleScreenAdded(m_dummyScreen);
106}
107
108QAbstractEventDispatcher *Integration::createEventDispatcher() const
109{
110 return new QUnixEventDispatcherQPA;
111}
112
113QPlatformBackingStore *Integration::createPlatformBackingStore(QWindow *window) const
114{
115 return new BackingStore(window);
116}
117
118QPlatformWindow *Integration::createPlatformWindow(QWindow *window) const
119{
120 return new Window(window);
121}
122
123QPlatformOffscreenSurface *Integration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
124{
125 return new OffscreenSurface(surface);
126}
127
128QPlatformFontDatabase *Integration::fontDatabase() const
129{
130 return m_fontDb.get();
131}
132
133QPlatformTheme *Integration::createPlatformTheme(const QString &name) const
134{
135 return QGenericUnixTheme::createUnixTheme(name);
136}
137
138QStringList Integration::themeNames() const
139{
140 if (qEnvironmentVariableIsSet("KDE_FULL_SESSION")) {
141 return QStringList({QStringLiteral("kde")});
142 }
143 return QStringList({QLatin1String(QGenericUnixTheme::name)});
144}
145
146QPlatformOpenGLContext *Integration::createPlatformOpenGLContext(QOpenGLContext *context) const
147{
148 if (kwinApp()->outputBackend()->sceneEglGlobalShareContext() == EGL_NO_CONTEXT) {
149 qCWarning(KWIN_QPA) << "Attempting to create a QOpenGLContext before the scene is initialized";
150 return nullptr;
151 }
152 EglDisplay *const eglDisplay = kwinApp()->outputBackend()->sceneEglDisplayObject();
153 if (eglDisplay) {
154 EGLPlatformContext *platformContext = new EGLPlatformContext(context, eglDisplay);
155 return platformContext;
156 }
157 return nullptr;
158}
159
160QPlatformAccessibility *Integration::accessibility() const
161{
162 if (!m_accessibility) {
163 m_accessibility.reset(new QSpiAccessibleBridge());
164 }
165 return m_accessibility.get();
166}
167
168void Integration::handleWorkspaceCreated()
169{
171 this, &Integration::handleOutputEnabled);
173 this, &Integration::handleOutputDisabled);
174
175 const QList<Output *> outputs = workspace()->outputs();
176 for (Output *output : outputs) {
177 handleOutputEnabled(output);
178 }
179}
180
181void Integration::handleOutputEnabled(Output *output)
182{
183 Screen *platformScreen = new Screen(output, this);
184 QWindowSystemInterface::handleScreenAdded(platformScreen);
185 m_screens.insert(output, platformScreen);
186
187 if (m_dummyScreen) {
188 QWindowSystemInterface::handleScreenRemoved(m_dummyScreen);
189 m_dummyScreen = nullptr;
190 }
191}
192
193void Integration::handleOutputDisabled(Output *output)
194{
195 Screen *platformScreen = m_screens.take(output);
196 if (!platformScreen) {
197 qCWarning(KWIN_QPA) << "Unknown output" << output;
198 return;
199 }
200
201 if (m_screens.isEmpty()) {
202 m_dummyScreen = new PlaceholderScreen();
203 QWindowSystemInterface::handleScreenAdded(m_dummyScreen);
204 }
205
206 QWindowSystemInterface::handleScreenRemoved(platformScreen);
207}
208
209QPlatformNativeInterface *Integration::nativeInterface() const
210{
211 return m_nativeInterface.get();
212}
213
214QPlatformServices *Integration::services() const
215{
216 return m_services.get();
217}
218
219}
220}
221
222#include "moc_integration.cpp"
QPlatformWindow * createPlatformWindow(QWindow *window) const override
QAbstractEventDispatcher * createEventDispatcher() const override
bool hasCapability(Capability cap) const override
QPlatformBackingStore * createPlatformBackingStore(QWindow *window) const override
QPlatformOpenGLContext * createPlatformOpenGLContext(QOpenGLContext *context) const override
QPlatformNativeInterface * nativeInterface() const override
QPlatformTheme * createPlatformTheme(const QString &name) const override
void initialize() override
QPlatformFontDatabase * fontDatabase() const override
QPlatformAccessibility * accessibility() const override
QPlatformServices * services() const override
QHash< Output *, Screen * > screens() const
QStringList themeNames() const override
QPlatformOffscreenSurface * createPlatformOffscreenSurface(QOffscreenSurface *surface) const override
void outputAdded(KWin::Output *)
QList< Output * > outputs() const
Definition workspace.h:762
void outputRemoved(KWin::Output *)
Workspace * workspace()
Definition workspace.h:830