KCM/Compositing: Use KConfig XT to store values

Summary:
 * Clean a little the code
 * Improve a little the UI

Test Plan:
Before:
{F8167763}
After:
{F8167764}

Reviewers: #kwin, ervin, bport, crossi, hchain, zzag

Reviewed By: #kwin, ervin, zzag

Subscribers: zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27955
This commit is contained in:
Méven Car 2020-03-20 10:34:08 +01:00 committed by Méven Car
parent 4cfdb33005
commit 519c4df57c
7 changed files with 193 additions and 133 deletions

View file

@ -8,18 +8,20 @@ remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_STRICT_ITERATORS -DQT_NO_CAST_FR
################# configure checks and create the configured files #################
set(kwincomposing_SRC
set(kwincompositing_SRC
main.cpp
compositing.cpp
)
qt5_add_dbus_interface(kwincomposing_SRC
kconfig_add_kcfg_files(kwincompositing_SRC kwincompositing_setting.kcfgc GENERATE_MOC)
qt5_add_dbus_interface(kwincompositing_SRC
${KWin_SOURCE_DIR}/org.kde.kwin.Compositing.xml kwin_compositing_interface
)
ki18n_wrap_ui(kwincomposing_SRC compositing.ui)
ki18n_wrap_ui(kwincompositing_SRC compositing.ui)
add_library(kwincompositing MODULE ${kwincomposing_SRC})
add_library(kwincompositing MODULE ${kwincompositing_SRC})
target_link_libraries(kwincompositing
Qt5::DBus

View file

@ -32,6 +32,8 @@
#include <QHash>
#include <QDebug>
#include "kwincompositing_setting.h"
namespace KWin {
namespace Compositing {
@ -44,63 +46,50 @@ Compositing::Compositing(QObject *parent)
, m_glSwapStrategy(0)
, m_compositingType(0)
, m_compositingEnabled(true)
, m_changed(false)
, m_openGLPlatformInterfaceModel(new OpenGLPlatformInterfaceModel(this))
, m_openGLPlatformInterface(0)
, m_windowsBlockCompositing(true)
, m_compositingInterface(new OrgKdeKwinCompositingInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Compositor"), QDBusConnection::sessionBus(), this))
, m_config(KSharedConfig::openConfig("kwinrc"))
, m_settings(new KWinCompositingSetting(this))
{
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::compositingTypeChanged, this, &Compositing::changed);
connect(this, &Compositing::compositingEnabledChanged, this, &Compositing::changed);
connect(this, &Compositing::openGLPlatformInterfaceChanged, this, &Compositing::changed);
connect(this, &Compositing::windowsBlockCompositingChanged, this, &Compositing::changed);
connect(this, &Compositing::changed, [this]{
m_changed = true;
});
load();
connect(this, &Compositing::animationSpeedChanged, this, &Compositing::updateSettings);
connect(this, &Compositing::windowThumbnailChanged, this, &Compositing::updateSettings);
connect(this, &Compositing::glScaleFilterChanged, this, &Compositing::updateSettings);
connect(this, &Compositing::xrScaleFilterChanged, this, &Compositing::updateSettings);
connect(this, &Compositing::glSwapStrategyChanged, this, &Compositing::updateSettings);
connect(this, &Compositing::compositingTypeChanged, this, &Compositing::updateSettings);
connect(this, &Compositing::compositingEnabledChanged, this, &Compositing::updateSettings);
connect(this, &Compositing::openGLPlatformInterfaceChanged, this, &Compositing::updateSettings);
connect(this, &Compositing::windowsBlockCompositingChanged, this, &Compositing::updateSettings);
}
void Compositing::reset()
void Compositing::load()
{
KConfigGroup globalConfig(m_config, QStringLiteral("KDE"));
setAnimationSpeed(globalConfig.readEntry("AnimationDurationFactor", 1.0));
m_settings->load();
KConfigGroup kwinConfig(m_config, QStringLiteral("Compositing"));
setWindowThumbnail(kwinConfig.readEntry("HiddenPreviews", 5) - 4);
setGlScaleFilter(kwinConfig.readEntry("GLTextureFilter", 2));
setXrScaleFilter(kwinConfig.readEntry("XRenderSmoothScale", false));
setCompositingEnabled(kwinConfig.readEntry("Enabled", true));
applyValues();
auto swapStrategy = [&kwinConfig]() {
const QString glSwapStrategyValue = kwinConfig.readEntry("GLPreferBufferSwap", "a");
emit changed(false);
emit defaulted(m_settings->isDefaults());
}
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;
}
return 0;
};
setGlSwapStrategy(swapStrategy());
void Compositing::applyValues()
{
setAnimationSpeed(m_settings->animationDurationFactor());
// from options.cpp Options::reloadCompositingSettings
// 4 - off, 5 - shown, 6 - always, other are old values
setWindowThumbnail(m_settings->hiddenPreviews() - 4);
setGlScaleFilter(m_settings->glTextureFilter());
setXrScaleFilter(m_settings->xRenderSmoothScale());
setCompositingEnabled(m_settings->enabled());
setGlSwapStrategy(m_settings->glPreferBufferSwap());
auto type = [&kwinConfig]{
const QString backend = kwinConfig.readEntry("Backend", "OpenGL");
const bool glCore = kwinConfig.readEntry("GLCore", false);
const auto type = [this]{
const int backend = m_settings->backend();
const bool glCore = m_settings->glCore();
if (backend == QStringLiteral("OpenGL")) {
if (backend == KWinCompositingSetting::EnumBackend::OpenGL) {
if (glCore) {
return CompositingType::OPENGL31_INDEX;
} else {
@ -112,58 +101,48 @@ void Compositing::reset()
};
setCompositingType(type());
const QModelIndex index = m_openGLPlatformInterfaceModel->indexForKey(kwinConfig.readEntry("GLPlatformInterface", "glx"));
const QModelIndex index = m_openGLPlatformInterfaceModel->indexForKey(m_settings->glPlatformInterface());
setOpenGLPlatformInterface(index.isValid() ? index.row() : 0);
setWindowsBlockCompositing(kwinConfig.readEntry("WindowsBlockCompositing", true));
m_changed = false;
setWindowsBlockCompositing(m_settings->windowsBlockCompositing());
}
void Compositing::defaults()
{
setAnimationSpeed(1.0);
setWindowThumbnail(1);
setGlScaleFilter(2);
setXrScaleFilter(false);
setGlSwapStrategy(1);
setCompositingType(CompositingType::OPENGL20_INDEX);
const QModelIndex index = m_openGLPlatformInterfaceModel->indexForKey(QStringLiteral("glx"));
setOpenGLPlatformInterface(index.isValid() ? index.row() : 0);
setWindowsBlockCompositing(true);
m_changed = true;
m_settings->setDefaults();
applyValues();
emit changed(m_settings->isSaveNeeded());
emit defaulted(m_settings->isDefaults());
}
bool Compositing::OpenGLIsUnsafe() const
{
KConfigGroup kwinConfig(m_config, "Compositing");
return kwinConfig.readEntry("OpenGLIsUnsafe", true);
return m_settings->openGLIsUnsafe();
}
bool Compositing::OpenGLIsBroken()
{
KConfigGroup kwinConfig(m_config, "Compositing");
QString oldBackend = kwinConfig.readEntry("Backend", "OpenGL");
kwinConfig.writeEntry("Backend", "OpenGL");
kwinConfig.sync();
const int oldBackend = m_settings->backend();
m_settings->setBackend(KWinCompositingSetting::EnumBackend::OpenGL);
m_settings->save();
if (m_compositingInterface->openGLIsBroken()) {
kwinConfig.writeEntry("Backend", oldBackend);
kwinConfig.sync();
m_settings->setBackend(oldBackend);
m_settings->save();
return true;
}
kwinConfig.writeEntry("OpenGLIsUnsafe", false);
kwinConfig.sync();
m_settings->setOpenGLIsUnsafe(false);
m_settings->save();
return false;
}
void Compositing::reenableOpenGLDetection()
{
KConfigGroup kwinConfig(m_config, "Compositing");
kwinConfig.writeEntry("OpenGLIsUnsafe", false);
kwinConfig.sync();
m_settings->setOpenGLIsUnsafe(false);
m_settings->save();
}
qreal Compositing::animationSpeed() const
@ -268,68 +247,58 @@ void Compositing::setCompositingEnabled(bool enabled)
emit compositingEnabledChanged(enabled);
}
void Compositing::save()
void Compositing::updateSettings()
{
// this writes to the KDE group of the kwinrc, when loading we rely on kconfig cascading to
// load a global value, or allow a kwin override
KConfigGroup generalConfig(m_config, "KDE");
if (!isRunningPlasma()) {
generalConfig.writeEntry("AnimationDurationFactor", animationSpeed());
m_settings->setAnimationDurationFactor(animationSpeed());
}
KConfigGroup kwinConfig(m_config, "Compositing");
kwinConfig.writeEntry("HiddenPreviews", windowThumbnail() + 4);
kwinConfig.writeEntry("GLTextureFilter", glScaleFilter());
kwinConfig.writeEntry("XRenderSmoothScale", xrScaleFilter());
m_settings->setHiddenPreviews(windowThumbnail() + 4);
m_settings->setGlTextureFilter(glScaleFilter());
m_settings->setXRenderSmoothScale(xrScaleFilter());
if (!compositingRequired()) {
kwinConfig.writeEntry("Enabled", compositingEnabled());
m_settings->setEnabled(compositingEnabled());
}
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());
QString backend;
m_settings->setGlPreferBufferSwap(glSwapStrategy());
int backend = KWinCompositingSetting::EnumBackend::OpenGL;
bool glCore = false;
switch (compositingType()) {
case CompositingType::OPENGL31_INDEX:
backend = "OpenGL";
backend = KWinCompositingSetting::EnumBackend::OpenGL;
glCore = true;
break;
case CompositingType::OPENGL20_INDEX:
backend = "OpenGL";
backend = KWinCompositingSetting::EnumBackend::OpenGL;
glCore = false;
break;
case CompositingType::XRENDER_INDEX:
backend = "XRender";
backend = KWinCompositingSetting::EnumBackend::XRender;
glCore = false;
break;
}
kwinConfig.writeEntry("Backend", backend);
kwinConfig.writeEntry("GLCore", glCore);
m_settings->setBackend(backend);
m_settings->setGlCore(glCore);
if (!compositingRequired()) {
kwinConfig.writeEntry("WindowsBlockCompositing", windowsBlockCompositing());
m_settings->setWindowsBlockCompositing(windowsBlockCompositing());
}
kwinConfig.sync();
if (m_changed) {
emit changed(m_settings->isSaveNeeded());
emit defaulted(m_settings->isDefaults());
}
void Compositing::save()
{
if (m_settings->isSaveNeeded()) {
m_settings->save();
// Send signal to all kwin instances
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Compositor"),
QStringLiteral("org.kde.kwin.Compositing"),
QStringLiteral("reinit"));
QDBusConnection::sessionBus().send(message);
m_changed = false;
}
}
@ -404,7 +373,7 @@ void CompositingType::generateCompositing()
}
std::sort(m_compositingList.begin(), m_compositingList.end(), [](const CompositingData &a, const CompositingData &b) {
return a.type < b.type;
return a.type < b.type;
});
endResetModel();
}
@ -419,8 +388,7 @@ QHash< int, QByteArray > CompositingType::roleNames() const
QModelIndex CompositingType::index(int row, int column, const QModelIndex &parent) const
{
if (parent.isValid() || column > 0 || column < 0 || row < 0 || row >= m_compositingList.count()) {
if (parent.isValid() || column > 0 || column < 0 || row < 0 || row >= m_compositingList.count()) {
return QModelIndex();
}

View file

@ -28,6 +28,8 @@
class OrgKdeKwinCompositingInterface;
class KWinCompositingSetting;
namespace KWin {
namespace Compositing {
@ -82,11 +84,12 @@ public:
static bool isRunningPlasma();
public Q_SLOTS:
void reset();
void load();
void defaults();
Q_SIGNALS:
void changed();
void changed(bool changed);
void defaulted(bool defaulted);
void animationSpeedChanged(qreal);
void windowThumbnailChanged(int);
void glScaleFilterChanged(int);
@ -97,7 +100,12 @@ Q_SIGNALS:
void openGLPlatformInterfaceChanged(int);
void windowsBlockCompositingChanged(bool);
private Q_SLOTS:
void updateSettings();
private:
void applyValues();
qreal m_animationSpeed;
int m_windowThumbnail;
int m_glScaleFilter;
@ -105,13 +113,13 @@ private:
int m_glSwapStrategy;
int m_compositingType;
bool m_compositingEnabled;
bool m_changed;
OpenGLPlatformInterfaceModel *m_openGLPlatformInterfaceModel;
int m_openGLPlatformInterface;
bool m_windowsBlockCompositing;
bool m_windowsBlockingCompositing;
OrgKdeKwinCompositingInterface *m_compositingInterface;
KSharedConfigPtr m_config;
KWinCompositingSetting *m_settings;
};

View file

@ -14,6 +14,9 @@
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<item row="0" column="0" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
@ -71,13 +74,6 @@ Alternatively, you might want to use the XRender backend instead.</string>
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="compositingEnabled">
<property name="text">
<string>Enable compositor on startup</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="animationSpeedLabel">
<property name="text">
@ -292,6 +288,13 @@ Alternatively, you might want to use the XRender backend instead.</string>
</layout>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="compositingEnabled">
<property name="text">
<string>Enable compositor on startup</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kwinrc"/>
<group name="KDE">
<entry name="AnimationDurationFactor" type="Double">
<default>1.0</default>
</entry>
</group>
<group name="Compositing">
<entry name="HiddenPreviews" type="Int">
<default>5</default>
</entry>
<entry name="glTextureFilter" key="GLTextureFilter" type="Int">
<default>2</default>
</entry>
<entry name="XRenderSmoothScale" type="Bool">
<default>false</default>
</entry>
<entry name="Enabled" type="Bool">
<default>true</default>
</entry>
<entry name="OpenGLIsUnsafe" type="Bool">
<default>true</default>
</entry>
<entry name="glPreferBufferSwap" key="GLPreferBufferSwap" type="Enum">
<default>a</default>
<choices>
<choice name="n" />
<choice name="a" />
<choice name="e" />
<choice name="p" />
<choice name="c" />
</choices>
</entry>
<entry name="Backend" type="Enum">
<default>OpenGL</default>
<choices>
<choice name="OpenGL" />
<choice name="XRender" />
</choices>
</entry>
<entry name="glCore" key="GLCore" type="Bool">
<default>false</default>
</entry>
<entry name="WindowsBlockCompositing" type="Bool">
<default>true</default>
</entry>
<entry name="glPlatformInterface" key="GLPlatformInterface" type="String">
<default>glx</default>
<choices>
<choice name="glx" />
<choice name="egl" />
</choices>
</entry>
</group>
</kcfg>

View file

@ -0,0 +1,5 @@
File=kwincompositing_setting.kcfg
ClassName=KWinCompositingSetting
Mutators=true
DefaultValueGetters=true
ParentInConstructor=true

View file

@ -32,11 +32,11 @@
#include <algorithm>
#include <functional>
class KWinCompositingSettings : public KCModule
class KWinCompositingKCM : public KCModule
{
Q_OBJECT
public:
explicit KWinCompositingSettings(QWidget *parent = nullptr, const QVariantList &args = QVariantList());
explicit KWinCompositingKCM(QWidget *parent = nullptr, const QVariantList &args = QVariantList());
public Q_SLOTS:
void load() override;
@ -51,7 +51,7 @@ private:
static const QVector<qreal> s_animationMultipliers = {8, 4, 2, 1, 0.5, 0.25, 0.125, 0};
KWinCompositingSettings::KWinCompositingSettings(QWidget *parent, const QVariantList &args)
KWinCompositingKCM::KWinCompositingKCM(QWidget *parent, const QVariantList &args)
: KCModule(parent, args)
, m_compositing(new KWin::Compositing::Compositing(this))
{
@ -71,12 +71,13 @@ KWinCompositingSettings::KWinCompositingSettings(QWidget *parent, const QVariant
init();
}
void KWinCompositingSettings::init()
void KWinCompositingKCM::init()
{
using namespace KWin::Compositing;
auto currentIndexChangedSignal = static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
connect(m_compositing, &Compositing::changed, this, &KWinCompositingSettings::markAsChanged);
connect(m_compositing, &Compositing::changed, this, qOverload<bool>(&KCModule::changed));
connect(m_compositing, &Compositing::defaulted, this, qOverload<bool>(&KCModule::defaulted));
// enabled check box
m_form.compositingEnabled->setChecked(m_compositing->compositingEnabled());
@ -202,26 +203,26 @@ void KWinCompositingSettings::init()
}
}
void KWinCompositingSettings::load()
void KWinCompositingKCM::load()
{
KCModule::load();
m_compositing->reset();
m_compositing->load();
}
void KWinCompositingSettings::defaults()
void KWinCompositingKCM::defaults()
{
KCModule::defaults();
m_compositing->defaults();
}
void KWinCompositingSettings::save()
void KWinCompositingKCM::save()
{
KCModule::save();
m_compositing->save();
}
K_PLUGIN_FACTORY(KWinCompositingConfigFactory,
registerPlugin<KWinCompositingSettings>("compositing");
registerPlugin<KWinCompositingKCM>("compositing");
)
#include "main.moc"