2015-08-14 14:52:40 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2020-01-14 16:17:18 +00:00
|
|
|
Copyright (C) 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2015-08-14 14:52:40 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "integration.h"
|
|
|
|
#include "backingstore.h"
|
2019-07-01 18:34:38 +00:00
|
|
|
#include "offscreensurface.h"
|
2015-08-14 14:52:40 +00:00
|
|
|
#include "screen.h"
|
|
|
|
#include "sharingplatformcontext.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"
|
2019-06-29 00:01:07 +00:00
|
|
|
#include "../../virtualkeyboard.h"
|
2015-08-14 14:52:40 +00:00
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QtConcurrentRun>
|
|
|
|
|
2016-04-29 13:05:03 +00:00
|
|
|
#include <qpa/qplatforminputcontext.h>
|
|
|
|
#include <qpa/qplatforminputcontextfactory_p.h>
|
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())
|
2016-04-29 13:05:03 +00:00
|
|
|
, m_inputContext()
|
2015-08-14 14:52:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Integration::~Integration() = default;
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2017-10-17 17:13:50 +00:00
|
|
|
connect(kwinApp(), &Application::screensCreated, this,
|
|
|
|
[this] {
|
|
|
|
connect(screens(), &Screens::changed, this, &Integration::initScreens);
|
|
|
|
initScreens();
|
|
|
|
}
|
|
|
|
);
|
2015-08-14 14:52:40 +00:00
|
|
|
QPlatformIntegration::initialize();
|
2017-10-17 17:13:50 +00:00
|
|
|
auto dummyScreen = new Screen(-1);
|
2019-04-03 20:52:01 +00:00
|
|
|
QWindowSystemInterface::handleScreenAdded(dummyScreen);
|
2017-10-17 17:13:50 +00:00
|
|
|
m_screens << dummyScreen;
|
2016-04-29 13:05:03 +00:00
|
|
|
m_inputContext.reset(QPlatformInputContextFactory::create(QStringLiteral("qtvirtualkeyboard")));
|
|
|
|
qunsetenv("QT_IM_MODULE");
|
2016-06-02 13:25:31 +00:00
|
|
|
if (!m_inputContext.isNull()) {
|
|
|
|
connect(qApp, &QGuiApplication::focusObjectChanged, this,
|
|
|
|
[this] {
|
|
|
|
if (VirtualKeyboard::self() && qApp->focusObject() != VirtualKeyboard::self()) {
|
|
|
|
m_inputContext->setFocusObject(VirtualKeyboard::self());
|
|
|
|
}
|
2016-04-29 13:05:03 +00:00
|
|
|
}
|
2016-06-02 13:25:31 +00:00
|
|
|
);
|
|
|
|
connect(kwinApp(), &Application::workspaceCreated, this,
|
|
|
|
[this] {
|
|
|
|
if (VirtualKeyboard::self()) {
|
|
|
|
m_inputContext->setFocusObject(VirtualKeyboard::self());
|
|
|
|
}
|
2016-04-29 13:05:03 +00:00
|
|
|
}
|
2016-06-02 13:25:31 +00:00
|
|
|
);
|
|
|
|
connect(qApp->inputMethod(), &QInputMethod::visibleChanged, this,
|
2019-06-29 00:01:07 +00:00
|
|
|
[] {
|
2016-06-02 13:25:31 +00:00
|
|
|
if (qApp->inputMethod()->isVisible()) {
|
|
|
|
if (QWindow *w = VirtualKeyboard::self()->inputPanel()) {
|
|
|
|
QWindowSystemInterface::handleWindowActivated(w, Qt::ActiveWindowFocusReason);
|
|
|
|
}
|
2016-04-29 13:05:03 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-02 13:25:31 +00:00
|
|
|
);
|
|
|
|
}
|
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
|
|
|
|
{
|
2016-04-07 06:28:35 +00:00
|
|
|
if (kwinApp()->platform()->supportsQpaContext()) {
|
2017-07-31 16:09:15 +00:00
|
|
|
return new SharingPlatformContext(context);
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
2016-07-18 09:17:54 +00:00
|
|
|
if (kwinApp()->platform()->sceneEglDisplay() != EGL_NO_DISPLAY) {
|
|
|
|
auto s = kwinApp()->platform()->sceneEglSurface();
|
|
|
|
if (s != EGL_NO_SURFACE) {
|
|
|
|
// try a SharingPlatformContext with a created surface
|
2017-07-31 16:09:15 +00:00
|
|
|
return new SharingPlatformContext(context, s, kwinApp()->platform()->sceneEglConfig());
|
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
|
|
|
}
|
|
|
|
|
2017-10-17 17:13:50 +00:00
|
|
|
void Integration::initScreens()
|
2015-08-14 14:52:40 +00:00
|
|
|
{
|
2017-10-17 17:13:50 +00:00
|
|
|
QVector<Screen*> newScreens;
|
2018-10-10 10:14:13 +00:00
|
|
|
newScreens.reserve(qMax(screens()->count(), 1));
|
2017-10-17 17:13:50 +00:00
|
|
|
for (int i = 0; i < screens()->count(); i++) {
|
|
|
|
auto screen = new Screen(i);
|
2019-04-03 20:52:01 +00:00
|
|
|
QWindowSystemInterface::handleScreenAdded(screen);
|
2017-10-17 17:13:50 +00:00
|
|
|
newScreens << screen;
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
2018-10-10 10:14:13 +00:00
|
|
|
if (newScreens.isEmpty()) {
|
|
|
|
auto dummyScreen = new Screen(-1);
|
2019-04-03 20:52:01 +00:00
|
|
|
QWindowSystemInterface::handleScreenAdded(dummyScreen);
|
2018-10-10 10:14:13 +00:00
|
|
|
newScreens << dummyScreen;
|
|
|
|
}
|
2017-10-17 17:13:50 +00:00
|
|
|
while (!m_screens.isEmpty()) {
|
2019-04-03 20:52:01 +00:00
|
|
|
QWindowSystemInterface::handleScreenRemoved(m_screens.takeLast());
|
2016-03-10 16:02:06 +00:00
|
|
|
}
|
2017-10-17 17:13:50 +00:00
|
|
|
m_screens = newScreens;
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 13:05:03 +00:00
|
|
|
QPlatformInputContext *Integration::inputContext() const
|
|
|
|
{
|
|
|
|
return m_inputContext.data();
|
|
|
|
}
|
|
|
|
|
2015-08-14 14:52:40 +00:00
|
|
|
}
|
|
|
|
}
|