Add the compositingType as another property to Compositing
Methods added to the Model to map from row index to the backend identifier and vice versa. That way the Compositing object can do all the saving and loading.
This commit is contained in:
parent
3a8a0d73ea
commit
1dd1c8e51d
4 changed files with 97 additions and 58 deletions
|
@ -3,6 +3,7 @@
|
|||
* This file is part of the KDE project. *
|
||||
* *
|
||||
* Copyright (C) 2013 Antonis Tsiapaliokas <kok3rs@gmail.com> *
|
||||
* Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org> *
|
||||
* *
|
||||
* 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 *
|
||||
|
@ -42,6 +43,7 @@ Compositing::Compositing(QObject *parent)
|
|||
, m_unredirectFullscreen(false)
|
||||
, m_glSwapStrategy(0)
|
||||
, m_glColorCorrection(false)
|
||||
, m_compositingType(0)
|
||||
{
|
||||
reset();
|
||||
connect(this, &Compositing::animationSpeedChanged, this, &Compositing::changed);
|
||||
|
@ -51,6 +53,7 @@ Compositing::Compositing(QObject *parent)
|
|||
connect(this, &Compositing::unredirectFullscreenChanged, this, &Compositing::changed);
|
||||
connect(this, &Compositing::glSwapStrategyChanged, this, &Compositing::changed);
|
||||
connect(this, &Compositing::glColorCorrectionChanged, this, &Compositing::changed);
|
||||
connect(this, &Compositing::compositingTypeChanged, this, &Compositing::changed);
|
||||
}
|
||||
|
||||
void Compositing::reset()
|
||||
|
@ -79,6 +82,25 @@ void Compositing::reset()
|
|||
};
|
||||
setGlSwapStrategy(swapStrategy());
|
||||
setGlColorCorrection(kwinConfig.readEntry("GLColorCorrection", false));
|
||||
|
||||
auto type = [&kwinConfig]{
|
||||
const QString backend = kwinConfig.readEntry("Backend", "OpenGL");
|
||||
const bool glLegacy = kwinConfig.readEntry("GLLegacy", false);
|
||||
const bool glCore = kwinConfig.readEntry("GLCore", false);
|
||||
|
||||
if (backend == QStringLiteral("OpenGL")) {
|
||||
if (glLegacy) {
|
||||
return CompositingType::OPENGL12_INDEX;
|
||||
} else if (glCore) {
|
||||
return CompositingType::OPENGL31_INDEX;
|
||||
} else {
|
||||
return CompositingType::OPENGL20_INDEX;
|
||||
}
|
||||
} else {
|
||||
return CompositingType::XRENDER_INDEX;
|
||||
}
|
||||
};
|
||||
setCompositingType(type());
|
||||
}
|
||||
|
||||
bool Compositing::OpenGLIsUnsafe() const
|
||||
|
@ -143,6 +165,11 @@ bool Compositing::glColorCorrection() const
|
|||
return m_glColorCorrection;
|
||||
}
|
||||
|
||||
int Compositing::compositingType() const
|
||||
{
|
||||
return m_compositingType;
|
||||
}
|
||||
|
||||
void Compositing::setAnimationSpeed(int speed)
|
||||
{
|
||||
if (speed == m_animationSpeed) {
|
||||
|
@ -206,6 +233,15 @@ void Compositing::setXrScaleFilter(bool filter)
|
|||
emit xrScaleFilterChanged();
|
||||
}
|
||||
|
||||
void Compositing::setCompositingType(int index)
|
||||
{
|
||||
if (index == m_compositingType) {
|
||||
return;
|
||||
}
|
||||
m_compositingType = index;
|
||||
emit compositingTypeChanged();
|
||||
}
|
||||
|
||||
void Compositing::save()
|
||||
{
|
||||
KConfigGroup kwinConfig(KSharedConfig::openConfig(QStringLiteral("kwinrc")), "Compositing");
|
||||
|
@ -231,6 +267,34 @@ void Compositing::save()
|
|||
};
|
||||
kwinConfig.writeEntry("GLPreferBufferSwap", swapStrategy());
|
||||
kwinConfig.writeEntry("GLColorCorrection", glColorCorrection());
|
||||
QString backend;
|
||||
bool glLegacy = false;
|
||||
bool glCore = false;
|
||||
switch (compositingType()) {
|
||||
case CompositingType::OPENGL31_INDEX:
|
||||
backend = "OpenGL";
|
||||
glLegacy = false;
|
||||
glCore = true;
|
||||
break;
|
||||
case CompositingType::OPENGL20_INDEX:
|
||||
backend = "OpenGL";
|
||||
glLegacy = false;
|
||||
glCore = false;
|
||||
break;
|
||||
case CompositingType::OPENGL12_INDEX:
|
||||
backend = "OpenGL";
|
||||
glLegacy = true;
|
||||
glCore = false;
|
||||
break;
|
||||
case CompositingType::XRENDER_INDEX:
|
||||
backend = "XRender";
|
||||
glLegacy = false;
|
||||
glCore = false;
|
||||
break;
|
||||
}
|
||||
kwinConfig.writeEntry("Backend", backend);
|
||||
kwinConfig.writeEntry("GLLegacy", glLegacy);
|
||||
kwinConfig.writeEntry("GLCore", glCore);
|
||||
kwinConfig.sync();
|
||||
}
|
||||
|
||||
|
@ -269,6 +333,7 @@ QHash< int, QByteArray > CompositingType::roleNames() const
|
|||
{
|
||||
QHash<int, QByteArray> roleNames;
|
||||
roleNames[NameRole] = "NameRole";
|
||||
roleNames[TypeRole] = QByteArrayLiteral("type");
|
||||
return roleNames;
|
||||
}
|
||||
|
||||
|
@ -313,70 +378,26 @@ QVariant CompositingType::data(const QModelIndex &index, int role) const
|
|||
case Qt::DisplayRole:
|
||||
case NameRole:
|
||||
return m_compositingList.at(index.row()).name;
|
||||
case TypeRole:
|
||||
return m_compositingList.at(index.row()).type;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
int CompositingType::currentOpenGLType()
|
||||
int CompositingType::compositingTypeForIndex(int row) const
|
||||
{
|
||||
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
|
||||
QString backend = kwinConfig.readEntry("Backend", "OpenGL");
|
||||
bool glLegacy = kwinConfig.readEntry("GLLegacy", false);
|
||||
bool glCore = kwinConfig.readEntry("GLCore", false);
|
||||
int currentIndex = OPENGL20_INDEX;
|
||||
|
||||
if (backend == "OpenGL") {
|
||||
if (glLegacy) {
|
||||
currentIndex = OPENGL12_INDEX;
|
||||
} else if (glCore) {
|
||||
currentIndex = OPENGL31_INDEX;
|
||||
} else {
|
||||
currentIndex = OPENGL20_INDEX;
|
||||
}
|
||||
} else {
|
||||
currentIndex = XRENDER_INDEX;
|
||||
}
|
||||
|
||||
return currentIndex;
|
||||
return index(row, 0).data(TypeRole).toInt();
|
||||
}
|
||||
|
||||
void CompositingType::syncConfig(int openGLType, int animationSpeed, int windowThumbnail, int glSclaleFilter, bool xrSclaleFilter,
|
||||
bool unredirectFullscreen, int glSwapStrategy, bool glColorCorrection)
|
||||
int CompositingType::indexForCompositingType(int type) const
|
||||
{
|
||||
QString backend;
|
||||
bool glLegacy;
|
||||
bool glCore;
|
||||
|
||||
|
||||
switch (openGLType) {
|
||||
case OPENGL31_INDEX:
|
||||
backend = "OpenGL";
|
||||
glLegacy = false;
|
||||
glCore = true;
|
||||
break;
|
||||
case OPENGL20_INDEX:
|
||||
backend = "OpenGL";
|
||||
glLegacy = false;
|
||||
glCore = false;
|
||||
break;
|
||||
case OPENGL12_INDEX:
|
||||
backend = "OpenGL";
|
||||
glLegacy = true;
|
||||
glCore = false;
|
||||
break;
|
||||
case XRENDER_INDEX:
|
||||
backend = "XRender";
|
||||
glLegacy = false;
|
||||
glCore = false;
|
||||
break;
|
||||
for (int i = 0; i < m_compositingList.count(); ++i) {
|
||||
if (m_compositingList.at(i).type == type) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
|
||||
kwinConfig.writeEntry("Backend", backend);
|
||||
kwinConfig.writeEntry("GLLegacy", glLegacy);
|
||||
kwinConfig.writeEntry("GLCore", glCore);
|
||||
kwinConfig.sync();
|
||||
return -1;
|
||||
}
|
||||
|
||||
}//end namespace Compositing
|
||||
|
|
|
@ -39,6 +39,7 @@ class Compositing : public QObject
|
|||
Q_PROPERTY(bool unredirectFullscreen READ unredirectFullscreen WRITE setUnredirectFullscreen NOTIFY unredirectFullscreenChanged)
|
||||
Q_PROPERTY(int glSwapStrategy READ glSwapStrategy WRITE setGlSwapStrategy NOTIFY glSwapStrategyChanged)
|
||||
Q_PROPERTY(bool glColorCorrection READ glColorCorrection WRITE setGlColorCorrection NOTIFY glColorCorrectionChanged)
|
||||
Q_PROPERTY(int compositingType READ compositingType WRITE setCompositingType NOTIFY compositingTypeChanged)
|
||||
public:
|
||||
explicit Compositing(QObject *parent = 0);
|
||||
|
||||
|
@ -51,6 +52,7 @@ public:
|
|||
bool unredirectFullscreen() const;
|
||||
int glSwapStrategy() const;
|
||||
bool glColorCorrection() const;
|
||||
int compositingType() const;
|
||||
|
||||
void setAnimationSpeed(int speed);
|
||||
void setWindowThumbnail(int index);
|
||||
|
@ -59,6 +61,7 @@ public:
|
|||
void setUnredirectFullscreen(bool unredirect);
|
||||
void setGlSwapStrategy(int strategy);
|
||||
void setGlColorCorrection(bool correction);
|
||||
void setCompositingType(int index);
|
||||
|
||||
void save();
|
||||
|
||||
|
@ -74,6 +77,7 @@ Q_SIGNALS:
|
|||
void unredirectFullscreenChanged();
|
||||
void glSwapStrategyChanged();
|
||||
void glColorCorrectionChanged();
|
||||
void compositingTypeChanged();
|
||||
|
||||
private:
|
||||
int m_animationSpeed;
|
||||
|
@ -83,6 +87,7 @@ private:
|
|||
bool m_unredirectFullscreen;
|
||||
int m_glSwapStrategy;
|
||||
bool m_glColorCorrection;
|
||||
int m_compositingType;
|
||||
};
|
||||
|
||||
|
||||
|
@ -104,6 +109,7 @@ public:
|
|||
|
||||
enum CompositingTypeRoles {
|
||||
NameRole = Qt::UserRole +1,
|
||||
TypeRole = Qt::UserRole +2
|
||||
};
|
||||
|
||||
explicit CompositingType(QObject *parent = 0);
|
||||
|
@ -116,9 +122,8 @@ public:
|
|||
|
||||
virtual QHash< int, QByteArray > roleNames() const override;
|
||||
|
||||
Q_INVOKABLE int currentOpenGLType();
|
||||
Q_INVOKABLE void syncConfig(int openGLType, int animationSpeed, int windowThumbnail, int glSclaleFilter, bool xrSclaleFilter,
|
||||
bool unredirectFullscreen, int glSwapStrategy, bool glColorCorrection);
|
||||
Q_INVOKABLE int compositingTypeForIndex(int row) const;
|
||||
Q_INVOKABLE int indexForCompositingType(int type) const;
|
||||
|
||||
private:
|
||||
void generateCompositing();
|
||||
|
|
|
@ -33,6 +33,7 @@ Item {
|
|||
property alias unredirectFullScreenChecked: unredirectFullScreen.checked
|
||||
property alias glSwapStrategyIndex: glSwapStrategy.currentIndex
|
||||
property alias glColorCorrectionChecked: glColorCorrection.checked
|
||||
property alias compositingTypeIndex: openGLType.type
|
||||
|
||||
Component {
|
||||
id: sectionHeading
|
||||
|
@ -70,14 +71,25 @@ Item {
|
|||
|
||||
ComboBox {
|
||||
id: openGLType
|
||||
property int type: 0
|
||||
model: compositingType
|
||||
currentIndex: compositingType.currentOpenGLType()
|
||||
textRole: "NameRole"
|
||||
anchors.top: windowManagement.bottom
|
||||
anchors.left: col.right
|
||||
onCurrentIndexChanged: {
|
||||
glScaleFilter.visible = currentIndex != 3;
|
||||
xrScaleFilter.visible = currentIndex == 3;
|
||||
glColorCorrection.enabled = currentIndex !=3 && glColorCorrection !=4;
|
||||
type = compositingType.compositingTypeForIndex(currentIndex);
|
||||
}
|
||||
Component.onCompleted: {
|
||||
type = compositingType.compositingTypeForIndex(currentIndex);
|
||||
}
|
||||
Connections {
|
||||
target: compositing
|
||||
onCompositingTypeChanged: {
|
||||
openGLType.currentIndex = compositingType.indexForCompositingType(compositing.compositingType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ Rectangle {
|
|||
unredirectFullscreen: view.unredirectFullScreenChecked
|
||||
glSwapStrategy: view.glSwapStrategyIndex
|
||||
glColorCorrection: view.glColorCorrectionChecked
|
||||
compositingType: view.compositingTypeIndex
|
||||
}
|
||||
Connections {
|
||||
target: compositing
|
||||
|
|
Loading…
Reference in a new issue