2013-08-17 08:28:09 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* KWin - the KDE window manager *
|
|
|
|
* This file is part of the KDE project. *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2013 Antonis Tsiapaliokas <kok3rs@gmail.com> *
|
2013-12-02 14:24:43 +00:00
|
|
|
* Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org> *
|
2013-08-17 08:28:09 +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 "compositing.h"
|
2014-03-07 13:41:05 +00:00
|
|
|
#include <kwin_compositing_interface.h>
|
2013-08-17 08:28:09 +00:00
|
|
|
|
2014-01-08 17:06:08 +00:00
|
|
|
#include <KCModuleProxy>
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KSharedConfig>
|
2013-08-17 08:28:09 +00:00
|
|
|
|
|
|
|
#include <QDBusInterface>
|
|
|
|
#include <QDBusReply>
|
2013-08-29 16:58:51 +00:00
|
|
|
#include <QHash>
|
2013-08-22 15:49:49 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2013-08-17 08:28:09 +00:00
|
|
|
namespace KWin {
|
|
|
|
namespace Compositing {
|
|
|
|
|
|
|
|
Compositing::Compositing(QObject *parent)
|
|
|
|
: QObject(parent)
|
2013-12-02 12:25:28 +00:00
|
|
|
, m_animationSpeed(0)
|
|
|
|
, m_windowThumbnail(0)
|
|
|
|
, m_glScaleFilter(0)
|
|
|
|
, m_xrScaleFilter(false)
|
|
|
|
, m_glSwapStrategy(0)
|
|
|
|
, m_glColorCorrection(false)
|
2013-12-02 14:24:43 +00:00
|
|
|
, m_compositingType(0)
|
2013-12-15 14:20:06 +00:00
|
|
|
, m_compositingEnabled(true)
|
2013-12-03 06:13:44 +00:00
|
|
|
, m_changed(false)
|
2014-04-23 06:21:35 +00:00
|
|
|
, m_openGLPlatformInterfaceModel(new OpenGLPlatformInterfaceModel(this))
|
|
|
|
, m_openGLPlatformInterface(0)
|
2016-08-26 06:56:42 +00:00
|
|
|
, m_windowsBlockCompositing(true)
|
2016-08-26 10:56:25 +00:00
|
|
|
, m_compositingInterface(new OrgKdeKwinCompositingInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Compositor"), QDBusConnection::sessionBus(), this))
|
2013-08-17 08:28:09 +00:00
|
|
|
{
|
2013-12-02 12:25:28 +00:00
|
|
|
reset();
|
|
|
|
connect(this, &Compositing::animationSpeedChanged, this, &Compositing::changed);
|
|
|
|
connect(this, &Compositing::windowThumbnailChanged, this, &Compositing::changed);
|
|
|
|
connect(this, &Compositing::glScaleFilterChanged, this, &Compositing::changed);
|
|
|
|
connect(this, &Compositing::xrScaleFilterChanged, this, &Compositing::changed);
|
|
|
|
connect(this, &Compositing::glSwapStrategyChanged, this, &Compositing::changed);
|
|
|
|
connect(this, &Compositing::glColorCorrectionChanged, this, &Compositing::changed);
|
2013-12-02 14:24:43 +00:00
|
|
|
connect(this, &Compositing::compositingTypeChanged, this, &Compositing::changed);
|
2013-12-15 14:20:06 +00:00
|
|
|
connect(this, &Compositing::compositingEnabledChanged, this, &Compositing::changed);
|
2014-04-23 06:21:35 +00:00
|
|
|
connect(this, &Compositing::openGLPlatformInterfaceChanged, this, &Compositing::changed);
|
2016-08-26 06:56:42 +00:00
|
|
|
connect(this, &Compositing::windowsBlockCompositingChanged, this, &Compositing::changed);
|
2013-12-03 06:13:44 +00:00
|
|
|
|
|
|
|
connect(this, &Compositing::changed, [this]{
|
|
|
|
m_changed = true;
|
|
|
|
});
|
2013-12-02 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Compositing::reset()
|
|
|
|
{
|
|
|
|
KConfigGroup kwinConfig(KSharedConfig::openConfig(QStringLiteral("kwinrc")), QStringLiteral("Compositing"));
|
|
|
|
setAnimationSpeed(kwinConfig.readEntry("AnimationSpeed", 3));
|
|
|
|
setWindowThumbnail(kwinConfig.readEntry("HiddenPreviews", 5) - 4);
|
|
|
|
setGlScaleFilter(kwinConfig.readEntry("GLTextureFilter", 2));
|
|
|
|
setXrScaleFilter(kwinConfig.readEntry("XRenderSmoothScale", false));
|
2013-12-15 14:20:06 +00:00
|
|
|
setCompositingEnabled(kwinConfig.readEntry("Enabled", true));
|
2013-12-02 12:25:28 +00:00
|
|
|
|
|
|
|
auto swapStrategy = [&kwinConfig]() {
|
|
|
|
const QString glSwapStrategyValue = kwinConfig.readEntry("GLPreferBufferSwap", "a");
|
|
|
|
|
|
|
|
if (glSwapStrategyValue == "n") {
|
|
|
|
return 0;
|
|
|
|
} else if (glSwapStrategyValue == "a") {
|
|
|
|
return 1;
|
|
|
|
} else if (glSwapStrategyValue == "e") {
|
|
|
|
return 2;
|
|
|
|
} else if (glSwapStrategyValue == "p") {
|
|
|
|
return 3;
|
|
|
|
} else if (glSwapStrategyValue == "c") {
|
|
|
|
return 4;
|
|
|
|
}
|
2014-04-02 10:02:36 +00:00
|
|
|
return 0;
|
2013-12-02 12:25:28 +00:00
|
|
|
};
|
|
|
|
setGlSwapStrategy(swapStrategy());
|
|
|
|
setGlColorCorrection(kwinConfig.readEntry("GLColorCorrection", false));
|
2013-12-02 14:24:43 +00:00
|
|
|
|
|
|
|
auto type = [&kwinConfig]{
|
|
|
|
const QString backend = kwinConfig.readEntry("Backend", "OpenGL");
|
|
|
|
const bool glCore = kwinConfig.readEntry("GLCore", false);
|
|
|
|
|
|
|
|
if (backend == QStringLiteral("OpenGL")) {
|
2014-03-06 14:45:42 +00:00
|
|
|
if (glCore) {
|
2013-12-02 14:24:43 +00:00
|
|
|
return CompositingType::OPENGL31_INDEX;
|
|
|
|
} else {
|
|
|
|
return CompositingType::OPENGL20_INDEX;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return CompositingType::XRENDER_INDEX;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
setCompositingType(type());
|
2014-04-23 06:21:35 +00:00
|
|
|
|
|
|
|
const QModelIndex index = m_openGLPlatformInterfaceModel->indexForKey(kwinConfig.readEntry("GLPlatformInterface", "glx"));
|
|
|
|
setOpenGLPlatformInterface(index.isValid() ? index.row() : 0);
|
|
|
|
|
2016-08-26 06:56:42 +00:00
|
|
|
setWindowsBlockCompositing(kwinConfig.readEntry("WindowsBlockCompositing", true));
|
|
|
|
|
2013-12-03 06:13:44 +00:00
|
|
|
m_changed = false;
|
2013-08-17 08:28:09 +00:00
|
|
|
}
|
|
|
|
|
2013-12-02 14:59:31 +00:00
|
|
|
void Compositing::defaults()
|
|
|
|
{
|
|
|
|
setAnimationSpeed(3);
|
|
|
|
setWindowThumbnail(1);
|
|
|
|
setGlScaleFilter(2);
|
|
|
|
setXrScaleFilter(false);
|
|
|
|
setGlSwapStrategy(1);
|
|
|
|
setGlColorCorrection(false);
|
|
|
|
setCompositingType(CompositingType::OPENGL20_INDEX);
|
2014-04-23 06:21:35 +00:00
|
|
|
const QModelIndex index = m_openGLPlatformInterfaceModel->indexForKey(QStringLiteral("glx"));
|
|
|
|
setOpenGLPlatformInterface(index.isValid() ? index.row() : 0);
|
2016-08-26 06:56:42 +00:00
|
|
|
setWindowsBlockCompositing(true);
|
2013-12-03 06:13:44 +00:00
|
|
|
m_changed = true;
|
2013-12-02 14:59:31 +00:00
|
|
|
}
|
|
|
|
|
2013-09-10 07:46:14 +00:00
|
|
|
bool Compositing::OpenGLIsUnsafe() const
|
2013-08-28 07:36:53 +00:00
|
|
|
{
|
2013-08-17 08:28:09 +00:00
|
|
|
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
|
|
|
|
return kwinConfig.readEntry("OpenGLIsUnsafe", true);
|
|
|
|
}
|
|
|
|
|
2013-08-28 07:36:53 +00:00
|
|
|
bool Compositing::OpenGLIsBroken()
|
|
|
|
{
|
2013-08-17 08:28:09 +00:00
|
|
|
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
|
|
|
|
|
|
|
|
QString oldBackend = kwinConfig.readEntry("Backend", "OpenGL");
|
|
|
|
kwinConfig.writeEntry("Backend", "OpenGL");
|
|
|
|
kwinConfig.sync();
|
|
|
|
|
2016-08-26 10:56:25 +00:00
|
|
|
if (m_compositingInterface->openGLIsBroken()) {
|
2013-08-17 08:28:09 +00:00
|
|
|
kwinConfig.writeEntry("Backend", oldBackend);
|
|
|
|
kwinConfig.sync();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
kwinConfig.writeEntry("OpenGLIsUnsafe", false);
|
|
|
|
kwinConfig.sync();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-03 09:39:10 +00:00
|
|
|
void Compositing::reenableOpenGLDetection()
|
|
|
|
{
|
|
|
|
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
|
|
|
|
kwinConfig.writeEntry("OpenGLIsUnsafe", false);
|
|
|
|
kwinConfig.sync();
|
|
|
|
}
|
|
|
|
|
2013-09-11 08:54:09 +00:00
|
|
|
int Compositing::animationSpeed() const
|
|
|
|
{
|
2013-12-02 12:25:28 +00:00
|
|
|
return m_animationSpeed;
|
2013-09-11 08:54:09 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 11:11:39 +00:00
|
|
|
int Compositing::windowThumbnail() const
|
|
|
|
{
|
2013-12-02 12:25:28 +00:00
|
|
|
return m_windowThumbnail;
|
2013-09-11 11:11:39 +00:00
|
|
|
}
|
|
|
|
|
2013-12-02 10:46:52 +00:00
|
|
|
int Compositing::glScaleFilter() const
|
2013-09-11 12:20:12 +00:00
|
|
|
{
|
2013-12-02 12:25:28 +00:00
|
|
|
return m_glScaleFilter;
|
2013-09-11 12:20:12 +00:00
|
|
|
}
|
|
|
|
|
2013-12-02 10:46:52 +00:00
|
|
|
bool Compositing::xrScaleFilter() const
|
2013-09-11 12:20:12 +00:00
|
|
|
{
|
2013-12-02 12:25:28 +00:00
|
|
|
return m_xrScaleFilter;
|
2013-09-11 12:20:12 +00:00
|
|
|
}
|
|
|
|
|
2013-09-12 11:42:18 +00:00
|
|
|
int Compositing::glSwapStrategy() const
|
|
|
|
{
|
2013-12-02 12:25:28 +00:00
|
|
|
return m_glSwapStrategy;
|
|
|
|
}
|
2013-09-12 11:42:18 +00:00
|
|
|
|
2013-12-02 12:25:28 +00:00
|
|
|
bool Compositing::glColorCorrection() const
|
|
|
|
{
|
|
|
|
return m_glColorCorrection;
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:24:43 +00:00
|
|
|
int Compositing::compositingType() const
|
|
|
|
{
|
|
|
|
return m_compositingType;
|
|
|
|
}
|
|
|
|
|
2013-12-15 14:20:06 +00:00
|
|
|
bool Compositing::compositingEnabled() const
|
|
|
|
{
|
|
|
|
return m_compositingEnabled;
|
|
|
|
}
|
|
|
|
|
2013-12-02 12:25:28 +00:00
|
|
|
void Compositing::setAnimationSpeed(int speed)
|
|
|
|
{
|
|
|
|
if (speed == m_animationSpeed) {
|
|
|
|
return;
|
2013-09-12 11:42:18 +00:00
|
|
|
}
|
2013-12-02 12:25:28 +00:00
|
|
|
m_animationSpeed = speed;
|
2014-05-30 06:18:25 +00:00
|
|
|
emit animationSpeedChanged(speed);
|
2013-09-12 11:42:18 +00:00
|
|
|
}
|
|
|
|
|
2013-12-02 12:25:28 +00:00
|
|
|
void Compositing::setGlColorCorrection(bool correction)
|
2013-09-12 11:55:25 +00:00
|
|
|
{
|
2013-12-02 12:25:28 +00:00
|
|
|
if (correction == m_glColorCorrection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_glColorCorrection = correction;
|
2014-05-30 06:18:25 +00:00
|
|
|
emit glColorCorrectionChanged(correction);
|
2013-12-02 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Compositing::setGlScaleFilter(int index)
|
|
|
|
{
|
|
|
|
if (index == m_glScaleFilter) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_glScaleFilter = index;
|
2014-05-30 06:18:25 +00:00
|
|
|
emit glScaleFilterChanged(index);
|
2013-12-02 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Compositing::setGlSwapStrategy(int strategy)
|
|
|
|
{
|
|
|
|
if (strategy == m_glSwapStrategy) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_glSwapStrategy = strategy;
|
2014-05-30 06:18:25 +00:00
|
|
|
emit glSwapStrategyChanged(strategy);
|
2013-12-02 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Compositing::setWindowThumbnail(int index)
|
|
|
|
{
|
|
|
|
if (index == m_windowThumbnail) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_windowThumbnail = index;
|
2014-05-30 06:18:25 +00:00
|
|
|
emit windowThumbnailChanged(index);
|
2013-12-02 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Compositing::setXrScaleFilter(bool filter)
|
|
|
|
{
|
|
|
|
if (filter == m_xrScaleFilter) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_xrScaleFilter = filter;
|
2014-05-30 06:18:25 +00:00
|
|
|
emit xrScaleFilterChanged(filter);
|
2013-12-02 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2013-12-02 14:24:43 +00:00
|
|
|
void Compositing::setCompositingType(int index)
|
|
|
|
{
|
|
|
|
if (index == m_compositingType) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_compositingType = index;
|
2014-05-30 06:18:25 +00:00
|
|
|
emit compositingTypeChanged(index);
|
2013-12-02 14:24:43 +00:00
|
|
|
}
|
|
|
|
|
2013-12-15 14:20:06 +00:00
|
|
|
void Compositing::setCompositingEnabled(bool enabled)
|
|
|
|
{
|
2016-08-26 10:56:25 +00:00
|
|
|
if (compositingRequired()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-15 14:20:06 +00:00
|
|
|
if (enabled == m_compositingEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_compositingEnabled = enabled;
|
2014-05-30 06:18:25 +00:00
|
|
|
emit compositingEnabledChanged(enabled);
|
2013-12-15 14:20:06 +00:00
|
|
|
}
|
|
|
|
|
2013-12-02 12:25:28 +00:00
|
|
|
void Compositing::save()
|
|
|
|
{
|
|
|
|
KConfigGroup kwinConfig(KSharedConfig::openConfig(QStringLiteral("kwinrc")), "Compositing");
|
|
|
|
kwinConfig.writeEntry("AnimationSpeed", animationSpeed());
|
|
|
|
kwinConfig.writeEntry("HiddenPreviews", windowThumbnail() + 4);
|
|
|
|
kwinConfig.writeEntry("GLTextureFilter", glScaleFilter());
|
|
|
|
kwinConfig.writeEntry("XRenderSmoothScale", xrScaleFilter());
|
2016-08-26 10:56:25 +00:00
|
|
|
if (!compositingRequired()) {
|
|
|
|
kwinConfig.writeEntry("Enabled", compositingEnabled());
|
|
|
|
}
|
2013-12-02 12:25:28 +00:00
|
|
|
auto swapStrategy = [this] {
|
|
|
|
switch (glSwapStrategy()) {
|
|
|
|
case 0:
|
|
|
|
return QStringLiteral("n");
|
|
|
|
case 2:
|
|
|
|
return QStringLiteral("e");
|
|
|
|
case 3:
|
|
|
|
return QStringLiteral("p");
|
|
|
|
case 4:
|
|
|
|
return QStringLiteral("c");
|
|
|
|
case 1:
|
|
|
|
default:
|
|
|
|
return QStringLiteral("a");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
kwinConfig.writeEntry("GLPreferBufferSwap", swapStrategy());
|
|
|
|
kwinConfig.writeEntry("GLColorCorrection", glColorCorrection());
|
2013-12-02 14:24:43 +00:00
|
|
|
QString backend;
|
|
|
|
bool glCore = false;
|
|
|
|
switch (compositingType()) {
|
|
|
|
case CompositingType::OPENGL31_INDEX:
|
|
|
|
backend = "OpenGL";
|
|
|
|
glCore = true;
|
|
|
|
break;
|
|
|
|
case CompositingType::OPENGL20_INDEX:
|
|
|
|
backend = "OpenGL";
|
|
|
|
glCore = false;
|
|
|
|
break;
|
|
|
|
case CompositingType::XRENDER_INDEX:
|
|
|
|
backend = "XRender";
|
|
|
|
glCore = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
kwinConfig.writeEntry("Backend", backend);
|
|
|
|
kwinConfig.writeEntry("GLCore", glCore);
|
2014-04-23 06:21:35 +00:00
|
|
|
const QModelIndex glIndex = m_openGLPlatformInterfaceModel->index(m_openGLPlatformInterface);
|
|
|
|
if (glIndex.isValid()) {
|
|
|
|
kwinConfig.writeEntry("GLPlatformInterface", glIndex.data(Qt::UserRole).toString());
|
|
|
|
}
|
2016-08-26 10:56:25 +00:00
|
|
|
if (!compositingRequired()) {
|
|
|
|
kwinConfig.writeEntry("WindowsBlockCompositing", windowsBlockCompositing());
|
|
|
|
}
|
2013-12-02 12:25:28 +00:00
|
|
|
kwinConfig.sync();
|
2013-12-03 06:13:44 +00:00
|
|
|
|
|
|
|
if (m_changed) {
|
|
|
|
// Send signal to all kwin instances
|
|
|
|
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Compositor"),
|
|
|
|
QStringLiteral("org.kde.kwin.Compositing"),
|
|
|
|
QStringLiteral("reinit"));
|
2014-04-23 06:43:35 +00:00
|
|
|
QDBusConnection::sessionBus().send(message);
|
2013-12-03 06:13:44 +00:00
|
|
|
m_changed = false;
|
|
|
|
}
|
2013-09-12 11:55:25 +00:00
|
|
|
}
|
|
|
|
|
2014-04-23 06:21:35 +00:00
|
|
|
OpenGLPlatformInterfaceModel *Compositing::openGLPlatformInterfaceModel() const
|
|
|
|
{
|
|
|
|
return m_openGLPlatformInterfaceModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Compositing::openGLPlatformInterface() const
|
|
|
|
{
|
|
|
|
return m_openGLPlatformInterface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositing::setOpenGLPlatformInterface(int interface)
|
|
|
|
{
|
|
|
|
if (m_openGLPlatformInterface == interface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_openGLPlatformInterface = interface;
|
2014-05-30 06:18:25 +00:00
|
|
|
emit openGLPlatformInterfaceChanged(interface);
|
2014-04-23 06:21:35 +00:00
|
|
|
}
|
|
|
|
|
2016-08-26 06:56:42 +00:00
|
|
|
bool Compositing::windowsBlockCompositing() const
|
|
|
|
{
|
|
|
|
return m_windowsBlockCompositing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compositing::setWindowsBlockCompositing(bool set)
|
|
|
|
{
|
2016-08-26 10:56:25 +00:00
|
|
|
if (compositingRequired()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-26 06:56:42 +00:00
|
|
|
if (m_windowsBlockCompositing == set) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_windowsBlockCompositing = set;
|
|
|
|
emit windowsBlockCompositingChanged(set);
|
|
|
|
}
|
|
|
|
|
2016-08-26 10:56:25 +00:00
|
|
|
bool Compositing::compositingRequired() const
|
|
|
|
{
|
|
|
|
return m_compositingInterface->platformRequiresCompositing();
|
|
|
|
}
|
|
|
|
|
2013-08-29 16:58:51 +00:00
|
|
|
CompositingType::CompositingType(QObject *parent)
|
|
|
|
: QAbstractItemModel(parent) {
|
|
|
|
|
|
|
|
generateCompositing();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositingType::generateCompositing()
|
|
|
|
{
|
|
|
|
QHash<QString, CompositingType::CompositingTypeIndex> compositingTypes;
|
|
|
|
|
2013-09-10 10:29:50 +00:00
|
|
|
compositingTypes[i18n("OpenGL 3.1")] = CompositingType::OPENGL31_INDEX;
|
|
|
|
compositingTypes[i18n("OpenGL 2.0")] = CompositingType::OPENGL20_INDEX;
|
|
|
|
compositingTypes[i18n("XRender")] = CompositingType::XRENDER_INDEX;
|
2013-08-29 16:58:51 +00:00
|
|
|
|
|
|
|
CompositingData data;
|
|
|
|
beginResetModel();
|
|
|
|
auto it = compositingTypes.begin();
|
|
|
|
while (it != compositingTypes.end()) {
|
|
|
|
data.name = it.key();
|
|
|
|
data.type = it.value();
|
|
|
|
m_compositingList << data;
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
qSort(m_compositingList.begin(), m_compositingList.end(), [](const CompositingData &a, const CompositingData &b) {
|
|
|
|
return a.type < b.type;
|
|
|
|
});
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash< int, QByteArray > CompositingType::roleNames() const
|
|
|
|
{
|
|
|
|
QHash<int, QByteArray> roleNames;
|
|
|
|
roleNames[NameRole] = "NameRole";
|
2013-12-02 14:24:43 +00:00
|
|
|
roleNames[TypeRole] = QByteArrayLiteral("type");
|
2013-08-29 16:58:51 +00:00
|
|
|
return roleNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex CompositingType::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
|
|
|
|
if (parent.isValid() || column > 0 || column < 0 || row < 0 || row >= m_compositingList.count()) {
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
return createIndex(row, column);
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex CompositingType::parent(const QModelIndex &child) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(child)
|
|
|
|
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CompositingType::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CompositingType::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
if (parent.isValid()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return m_compositingList.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CompositingType::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
case NameRole:
|
|
|
|
return m_compositingList.at(index.row()).name;
|
2013-12-02 14:24:43 +00:00
|
|
|
case TypeRole:
|
|
|
|
return m_compositingList.at(index.row()).type;
|
2013-08-29 16:58:51 +00:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:24:43 +00:00
|
|
|
int CompositingType::compositingTypeForIndex(int row) const
|
2013-08-29 16:58:51 +00:00
|
|
|
{
|
2013-12-02 14:24:43 +00:00
|
|
|
return index(row, 0).data(TypeRole).toInt();
|
2013-08-29 16:58:51 +00:00
|
|
|
}
|
|
|
|
|
2013-12-02 14:24:43 +00:00
|
|
|
int CompositingType::indexForCompositingType(int type) const
|
2013-08-28 07:36:53 +00:00
|
|
|
{
|
2013-12-02 14:24:43 +00:00
|
|
|
for (int i = 0; i < m_compositingList.count(); ++i) {
|
|
|
|
if (m_compositingList.at(i).type == type) {
|
|
|
|
return i;
|
|
|
|
}
|
2013-08-22 15:49:49 +00:00
|
|
|
}
|
2013-12-02 14:24:43 +00:00
|
|
|
return -1;
|
2013-08-22 15:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-23 06:21:35 +00:00
|
|
|
OpenGLPlatformInterfaceModel::OpenGLPlatformInterfaceModel(QObject *parent)
|
|
|
|
: QAbstractListModel(parent)
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
OrgKdeKwinCompositingInterface interface(QStringLiteral("org.kde.KWin"),
|
|
|
|
QStringLiteral("/Compositor"),
|
|
|
|
QDBusConnection::sessionBus());
|
|
|
|
m_keys << interface.supportedOpenGLPlatformInterfaces();
|
|
|
|
for (const QString &key : m_keys) {
|
|
|
|
if (key == QStringLiteral("egl")) {
|
|
|
|
m_names << i18nc("OpenGL Platform Interface", "EGL");
|
|
|
|
} else if (key == QStringLiteral("glx")) {
|
|
|
|
m_names << i18nc("OpenGL Platform Interface", "GLX");
|
|
|
|
} else {
|
|
|
|
m_names << key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenGLPlatformInterfaceModel::~OpenGLPlatformInterfaceModel() = default;
|
|
|
|
|
|
|
|
int OpenGLPlatformInterfaceModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
if (parent.isValid()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return m_keys.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash< int, QByteArray > OpenGLPlatformInterfaceModel::roleNames() const
|
|
|
|
{
|
|
|
|
return QHash<int, QByteArray>({
|
|
|
|
{Qt::DisplayRole, QByteArrayLiteral("display")},
|
|
|
|
{Qt::UserRole, QByteArrayLiteral("openglPlatformInterface")}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant OpenGLPlatformInterfaceModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid() || index.row() < 0 || index.row() >= m_keys.size() || index.column() != 0) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
return m_names.at(index.row());
|
|
|
|
case Qt::UserRole:
|
|
|
|
return m_keys.at(index.row());
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex OpenGLPlatformInterfaceModel::indexForKey(const QString &key) const
|
|
|
|
{
|
|
|
|
const int keyIndex = m_keys.indexOf(key);
|
|
|
|
if (keyIndex < 0) {
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
return createIndex(keyIndex, 0);
|
|
|
|
}
|
|
|
|
|
2013-08-17 08:28:09 +00:00
|
|
|
}//end namespace Compositing
|
|
|
|
}//end namespace KWin
|