Create a new QAbstractItemModel for our CompoBox.
In the feature we will need to hanlde some Wayland stuff so we need our model to be smarter. Also remove some left overs from the graphics system
This commit is contained in:
parent
ff08041bed
commit
67144780bd
4 changed files with 168 additions and 30 deletions
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QHash>
|
||||
#include <QDebug>
|
||||
|
||||
namespace KWin {
|
||||
|
@ -63,9 +64,116 @@ bool Compositing::OpenGLIsBroken()
|
|||
return false;
|
||||
}
|
||||
|
||||
void Compositing::syncConfig(int openGLType, int graphicsSystem)
|
||||
CompositingType::CompositingType(QObject *parent)
|
||||
: QAbstractItemModel(parent) {
|
||||
|
||||
generateCompositing();
|
||||
}
|
||||
|
||||
|
||||
void CompositingType::generateCompositing()
|
||||
{
|
||||
QHash<QString, CompositingType::CompositingTypeIndex> compositingTypes;
|
||||
|
||||
compositingTypes["OpenGL 31"] = CompositingType::OPENGL31_INDEX;
|
||||
compositingTypes["OpenGL 20"] = CompositingType::OPENGL20_INDEX;
|
||||
compositingTypes["OpenGL 12"] = CompositingType::OPENGL12_INDEX;
|
||||
compositingTypes["XRender"] = CompositingType::XRENDER_INDEX;
|
||||
|
||||
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";
|
||||
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;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
int CompositingType::currentOpenGLType()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
void CompositingType::syncConfig(int openGLType)
|
||||
{
|
||||
QString graphicsSystemType;
|
||||
QString backend;
|
||||
bool glLegacy;
|
||||
bool glCore;
|
||||
|
@ -101,28 +209,5 @@ void Compositing::syncConfig(int openGLType, int graphicsSystem)
|
|||
kwinConfig.sync();
|
||||
}
|
||||
|
||||
int Compositing::currentOpenGLType()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}//end namespace Compositing
|
||||
}//end namespace KWin
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#ifndef COMPOSITING_H
|
||||
#define COMPOSITING_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QObject>
|
||||
|
||||
namespace KWin {
|
||||
|
@ -36,8 +38,6 @@ public:
|
|||
|
||||
Q_INVOKABLE bool OpenGLIsUnsafe();
|
||||
Q_INVOKABLE bool OpenGLIsBroken();
|
||||
Q_INVOKABLE void syncConfig(int openGLType, int graphicsSystem);
|
||||
Q_INVOKABLE int currentOpenGLType();
|
||||
|
||||
private:
|
||||
|
||||
|
@ -48,6 +48,53 @@ private:
|
|||
XRENDER_INDEX
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct CompositingData;
|
||||
|
||||
class CompositingType : public QAbstractItemModel
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
enum CompositingTypeIndex {
|
||||
OPENGL31_INDEX = 0,
|
||||
OPENGL20_INDEX,
|
||||
OPENGL12_INDEX,
|
||||
XRENDER_INDEX
|
||||
};
|
||||
|
||||
enum CompositingTypeRoles {
|
||||
NameRole = Qt::UserRole +1,
|
||||
};
|
||||
|
||||
explicit CompositingType(QObject *parent = 0);
|
||||
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||
QModelIndex parent(const QModelIndex &child) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
virtual QHash< int, QByteArray > roleNames() const override;
|
||||
|
||||
Q_INVOKABLE int currentOpenGLType();
|
||||
Q_INVOKABLE void syncConfig(int openGLType);
|
||||
|
||||
private:
|
||||
void generateCompositing();
|
||||
QList<CompositingData> m_compositingList;
|
||||
|
||||
};
|
||||
|
||||
struct CompositingData {
|
||||
QString name;
|
||||
CompositingType::CompositingTypeIndex type;
|
||||
};
|
||||
|
||||
|
||||
}//end namespace Compositing
|
||||
}//end namespace KWin
|
||||
#endif
|
||||
|
|
|
@ -378,6 +378,7 @@ EffectView::EffectView(QWindow *parent)
|
|||
qmlRegisterType<EffectConfig>("org.kde.kwin.kwincompositing", 1, 0, "EffectConfig");
|
||||
qmlRegisterType<EffectFilterModel>("org.kde.kwin.kwincompositing", 1, 0, "EffectFilterModel");
|
||||
qmlRegisterType<Compositing>("org.kde.kwin.kwincompositing", 1, 0, "Compositing");
|
||||
qmlRegisterType<CompositingType>("org.kde.kwin.kwincompositing", 1, 0, "CompositingType");
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ Item {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
CompositingType {
|
||||
id: compositingType
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
id: row
|
||||
width: parent.width
|
||||
|
@ -56,8 +61,8 @@ Item {
|
|||
|
||||
ComboBox {
|
||||
id: openGLType
|
||||
model: ["OpenGL 3.1", "OpenGL 2.1", "OpenGL 1.2", "XRender"]
|
||||
currentIndex: compositing.currentOpenGLType()
|
||||
model: compositingType
|
||||
currentIndex: compositingType.currentOpenGLType()
|
||||
anchors.top: windowManagement.bottom
|
||||
anchors.left: col.right
|
||||
onCurrentIndexChanged: apply.enabled = true
|
||||
|
@ -131,7 +136,7 @@ Item {
|
|||
onClicked: {
|
||||
searchModel.syncConfig();
|
||||
apply.enabled = false;
|
||||
compositing.syncConfig(openGLType.currentIndex, graphicsSystem.currentIndex);
|
||||
compositingType.syncConfig(openGLType.currentIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue