2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2015-08-14 14:52:40 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2015-08-14 14:52:40 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2015-08-14 14:52:40 +00:00
|
|
|
#include "integration.h"
|
2020-12-03 19:47:42 +00:00
|
|
|
#include "abstract_output.h"
|
2015-08-14 14:52:40 +00:00
|
|
|
#include "backingstore.h"
|
2020-10-12 06:27:27 +00:00
|
|
|
#include "eglplatformcontext.h"
|
2020-10-16 14:57:35 +00:00
|
|
|
#include "logging.h"
|
2019-07-01 18:34:38 +00:00
|
|
|
#include "offscreensurface.h"
|
2015-08-14 14:52:40 +00:00
|
|
|
#include "screen.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include "../../main.h"
|
2019-06-29 00:01:07 +00:00
|
|
|
#include "../../platform.h"
|
2017-10-17 17:13:50 +00:00
|
|
|
#include "../../screens.h"
|
2015-08-14 14:52:40 +00:00
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QtConcurrentRun>
|
|
|
|
|
2019-06-29 00:01:07 +00:00
|
|
|
#include <qpa/qplatformwindow.h>
|
2016-04-29 13:05:03 +00:00
|
|
|
#include <qpa/qwindowsysteminterface.h>
|
2016-10-27 00:43:21 +00:00
|
|
|
|
2019-06-29 00:01:07 +00:00
|
|
|
#include <QtEventDispatcherSupport/private/qunixeventdispatcher_qpa_p.h>
|
2016-10-27 00:43:21 +00:00
|
|
|
#include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h>
|
|
|
|
#include <QtThemeSupport/private/qgenericunixthemes_p.h>
|
2015-08-14 14:52:40 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace QPA
|
|
|
|
{
|
|
|
|
|
|
|
|
Integration::Integration()
|
|
|
|
: QObject()
|
|
|
|
, QPlatformIntegration()
|
|
|
|
, m_fontDb(new QGenericUnixFontDatabase())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-14 14:50:39 +00:00
|
|
|
Integration::~Integration()
|
|
|
|
{
|
2020-08-18 13:10:02 +00:00
|
|
|
for (QPlatformScreen *platformScreen : m_screens) {
|
|
|
|
QWindowSystemInterface::handleScreenRemoved(platformScreen);
|
|
|
|
}
|
2020-12-03 19:47:42 +00:00
|
|
|
if (m_dummyScreen) {
|
|
|
|
QWindowSystemInterface::handleScreenRemoved(m_dummyScreen);
|
|
|
|
}
|
2020-08-14 14:50:39 +00:00
|
|
|
}
|
2015-08-14 14:52:40 +00:00
|
|
|
|
|
|
|
bool Integration::hasCapability(Capability cap) const
|
|
|
|
{
|
|
|
|
switch (cap) {
|
|
|
|
case ThreadedPixmaps:
|
|
|
|
return true;
|
|
|
|
case OpenGL:
|
|
|
|
return true;
|
|
|
|
case ThreadedOpenGL:
|
|
|
|
return false;
|
|
|
|
case BufferQueueingOpenGL:
|
|
|
|
return false;
|
|
|
|
case MultipleWindows:
|
|
|
|
case NonFullScreenWindows:
|
|
|
|
return true;
|
|
|
|
case RasterGLSurface:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return QPlatformIntegration::hasCapability(cap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Integration::initialize()
|
|
|
|
{
|
2020-12-03 19:47:42 +00:00
|
|
|
// The QPA is initialized before the platform plugin is loaded.
|
|
|
|
connect(kwinApp(), &Application::platformCreated, this, &Integration::handlePlatformCreated);
|
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
QPlatformIntegration::initialize();
|
2020-12-03 19:47:42 +00:00
|
|
|
|
|
|
|
m_dummyScreen = new PlaceholderScreen();
|
|
|
|
QWindowSystemInterface::handleScreenAdded(m_dummyScreen);
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QAbstractEventDispatcher *Integration::createEventDispatcher() const
|
|
|
|
{
|
2015-08-20 12:31:13 +00:00
|
|
|
return new QUnixEventDispatcherQPA;
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPlatformBackingStore *Integration::createPlatformBackingStore(QWindow *window) const
|
|
|
|
{
|
2019-08-26 07:44:04 +00:00
|
|
|
return new BackingStore(window);
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPlatformWindow *Integration::createPlatformWindow(QWindow *window) const
|
|
|
|
{
|
2019-08-26 07:44:04 +00:00
|
|
|
return new Window(window);
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
2019-07-01 18:34:38 +00:00
|
|
|
QPlatformOffscreenSurface *Integration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
|
|
|
|
{
|
|
|
|
return new OffscreenSurface(surface);
|
|
|
|
}
|
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
QPlatformFontDatabase *Integration::fontDatabase() const
|
|
|
|
{
|
2020-07-27 17:53:08 +00:00
|
|
|
return m_fontDb.data();
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPlatformTheme *Integration::createPlatformTheme(const QString &name) const
|
|
|
|
{
|
|
|
|
return QGenericUnixTheme::createUnixTheme(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList Integration::themeNames() const
|
|
|
|
{
|
|
|
|
if (qEnvironmentVariableIsSet("KDE_FULL_SESSION")) {
|
|
|
|
return QStringList({QStringLiteral("kde")});
|
|
|
|
}
|
|
|
|
return QStringList({QLatin1String(QGenericUnixTheme::name)});
|
|
|
|
}
|
|
|
|
|
|
|
|
QPlatformOpenGLContext *Integration::createPlatformOpenGLContext(QOpenGLContext *context) const
|
|
|
|
{
|
2020-10-16 14:57:35 +00:00
|
|
|
if (kwinApp()->platform()->sceneEglGlobalShareContext() == EGL_NO_CONTEXT) {
|
|
|
|
qCWarning(KWIN_QPA) << "Attempting to create a QOpenGLContext before the scene is initialized";
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-10-12 06:27:27 +00:00
|
|
|
const EGLDisplay eglDisplay = kwinApp()->platform()->sceneEglDisplay();
|
|
|
|
if (eglDisplay != EGL_NO_DISPLAY) {
|
|
|
|
EGLPlatformContext *platformContext = new EGLPlatformContext(context, eglDisplay);
|
|
|
|
return platformContext;
|
2016-07-18 09:17:54 +00:00
|
|
|
}
|
2019-02-14 16:45:03 +00:00
|
|
|
return nullptr;
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 19:47:42 +00:00
|
|
|
void Integration::handlePlatformCreated()
|
2015-08-14 14:52:40 +00:00
|
|
|
{
|
2020-12-03 19:47:42 +00:00
|
|
|
connect(kwinApp()->platform(), &Platform::outputEnabled,
|
|
|
|
this, &Integration::handleOutputEnabled);
|
|
|
|
connect(kwinApp()->platform(), &Platform::outputDisabled,
|
|
|
|
this, &Integration::handleOutputDisabled);
|
|
|
|
|
|
|
|
const QVector<AbstractOutput *> outputs = kwinApp()->platform()->enabledOutputs();
|
|
|
|
for (AbstractOutput *output : outputs) {
|
|
|
|
handleOutputEnabled(output);
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
2020-12-03 19:47:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Integration::handleOutputEnabled(AbstractOutput *output)
|
|
|
|
{
|
|
|
|
Screen *platformScreen = new Screen(output);
|
|
|
|
QWindowSystemInterface::handleScreenAdded(platformScreen);
|
|
|
|
|
|
|
|
if (m_dummyScreen) {
|
|
|
|
QWindowSystemInterface::handleScreenRemoved(m_dummyScreen);
|
|
|
|
m_dummyScreen = nullptr;
|
2018-10-10 10:14:13 +00:00
|
|
|
}
|
2020-12-03 19:47:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Integration::handleOutputDisabled(AbstractOutput *output)
|
|
|
|
{
|
|
|
|
Screen *platformScreen = m_screens.take(output);
|
|
|
|
if (!platformScreen) {
|
|
|
|
qCWarning(KWIN_QPA) << "Unknown output" << output;
|
|
|
|
return;
|
2016-03-10 16:02:06 +00:00
|
|
|
}
|
2020-12-03 19:47:42 +00:00
|
|
|
|
|
|
|
if (m_screens.isEmpty()) {
|
|
|
|
m_dummyScreen = new PlaceholderScreen();
|
|
|
|
QWindowSystemInterface::handleScreenAdded(m_dummyScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
QWindowSystemInterface::handleScreenRemoved(platformScreen);
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|