Save complete state in Compositing QObject

* all properties extended to be writable and emit change signals
* contains load from and save to config functionality
* Compositing object in qml view is connected to the values of the
  components. So changes are directly mapped from UI to business logic
remotes/origin/Plasma/5.0
Martin Gräßlin 12 years ago
parent bfab98839c
commit 3a8a0d73ea
  1. 193
      kcmkwin/kwincompositing/compositing.cpp
  2. 51
      kcmkwin/kwincompositing/compositing.h
  3. 35
      kcmkwin/kwincompositing/qml/EffectView.qml
  4. 13
      kcmkwin/kwincompositing/qml/main.qml

@ -35,7 +35,50 @@ namespace Compositing {
Compositing::Compositing(QObject *parent)
: QObject(parent)
, m_animationSpeed(0)
, m_windowThumbnail(0)
, m_glScaleFilter(0)
, m_xrScaleFilter(false)
, m_unredirectFullscreen(false)
, m_glSwapStrategy(0)
, m_glColorCorrection(false)
{
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::unredirectFullscreenChanged, this, &Compositing::changed);
connect(this, &Compositing::glSwapStrategyChanged, this, &Compositing::changed);
connect(this, &Compositing::glColorCorrectionChanged, this, &Compositing::changed);
}
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));
setUnredirectFullscreen(kwinConfig.readEntry("UnredirectFullscreen", false));
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;
}
};
setGlSwapStrategy(swapStrategy());
setGlColorCorrection(kwinConfig.readEntry("GLColorCorrection", false));
}
bool Compositing::OpenGLIsUnsafe() const
@ -67,56 +110,128 @@ bool Compositing::OpenGLIsBroken()
int Compositing::animationSpeed() const
{
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
return kwinConfig.readEntry("AnimationSpeed", 3);
return m_animationSpeed;
}
int Compositing::windowThumbnail() const
{
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
return kwinConfig.readEntry("HiddenPreviews", 5) - 4;
return m_windowThumbnail;
}
int Compositing::glScaleFilter() const
{
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
return kwinConfig.readEntry("GLTextureFilter", 2);
return m_glScaleFilter;
}
bool Compositing::xrScaleFilter() const
{
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
return kwinConfig.readEntry("XRenderSmoothScale", false);
return m_xrScaleFilter;
}
bool Compositing::unredirectFullscreen() const
{
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
return kwinConfig.readEntry("UnredirectFullscreen", false);
return m_unredirectFullscreen;
}
int Compositing::glSwapStrategy() const
{
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
const QString glSwapStrategyValue = kwinConfig.readEntry("GLPreferBufferSwap", "a");
return m_glSwapStrategy;
}
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;
bool Compositing::glColorCorrection() const
{
return m_glColorCorrection;
}
void Compositing::setAnimationSpeed(int speed)
{
if (speed == m_animationSpeed) {
return;
}
m_animationSpeed = speed;
emit animationSpeedChanged();
}
bool Compositing::glColorCorrection() const
void Compositing::setGlColorCorrection(bool correction)
{
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
return kwinConfig.readEntry("GLColorCorrection", false);
if (correction == m_glColorCorrection) {
return;
}
m_glColorCorrection = correction;
emit glColorCorrectionChanged();
}
void Compositing::setGlScaleFilter(int index)
{
if (index == m_glScaleFilter) {
return;
}
m_glScaleFilter = index;
emit glScaleFilterChanged();
}
void Compositing::setGlSwapStrategy(int strategy)
{
if (strategy == m_glSwapStrategy) {
return;
}
m_glSwapStrategy = strategy;
emit glSwapStrategyChanged();
}
void Compositing::setUnredirectFullscreen(bool unredirect)
{
if (unredirect == m_unredirectFullscreen) {
return;
}
m_unredirectFullscreen = unredirect;
emit unredirectFullscreenChanged();
}
void Compositing::setWindowThumbnail(int index)
{
if (index == m_windowThumbnail) {
return;
}
m_windowThumbnail = index;
emit windowThumbnailChanged();
}
void Compositing::setXrScaleFilter(bool filter)
{
if (filter == m_xrScaleFilter) {
return;
}
m_xrScaleFilter = filter;
emit xrScaleFilterChanged();
}
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());
kwinConfig.writeEntry("UnredirectFullscreen", unredirectFullscreen());
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());
kwinConfig.sync();
}
CompositingType::CompositingType(QObject *parent)
@ -229,7 +344,6 @@ int CompositingType::currentOpenGLType()
void CompositingType::syncConfig(int openGLType, int animationSpeed, int windowThumbnail, int glSclaleFilter, bool xrSclaleFilter,
bool unredirectFullscreen, int glSwapStrategy, bool glColorCorrection)
{
QString glSwapStrategyValue;
QString backend;
bool glLegacy;
bool glCore;
@ -258,37 +372,10 @@ void CompositingType::syncConfig(int openGLType, int animationSpeed, int windowT
break;
}
switch (glSwapStrategy) {
case 0:
glSwapStrategyValue = "n";
break;
case 1:
glSwapStrategyValue = "a";
break;
case 2:
glSwapStrategyValue = "e";
break;
case 3:
glSwapStrategyValue = "p";
break;
case 4:
glSwapStrategyValue = "c";
break;
default:
glSwapStrategyValue = "a";
}
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Compositing");
kwinConfig.writeEntry("Backend", backend);
kwinConfig.writeEntry("GLLegacy", glLegacy);
kwinConfig.writeEntry("GLCore", glCore);
kwinConfig.writeEntry("AnimationSpeed", animationSpeed);
kwinConfig.writeEntry("HiddenPreviews", windowThumbnail + 4);
kwinConfig.writeEntry("GLTextureFilter", glSclaleFilter);
kwinConfig.writeEntry("XRenderSmoothScale", xrSclaleFilter);
kwinConfig.writeEntry("UnredirectFullscreen", unredirectFullscreen);
kwinConfig.writeEntry("GLPreferBufferSwap", glSwapStrategyValue);
kwinConfig.writeEntry("GLColorCorrection", glColorCorrection);
kwinConfig.sync();
}

@ -32,13 +32,13 @@ class Compositing : public QObject
{
Q_OBJECT
Q_PROPERTY(int animationSpeed READ animationSpeed CONSTANT);
Q_PROPERTY(int windowThumbnail READ windowThumbnail CONSTANT);
Q_PROPERTY(int glScaleFilter READ glScaleFilter CONSTANT);
Q_PROPERTY(bool xrScaleFilter READ xrScaleFilter CONSTANT);
Q_PROPERTY(bool unredirectFullscreen READ unredirectFullscreen CONSTANT);
Q_PROPERTY(int glSwapStrategy READ glSwapStrategy CONSTANT);
Q_PROPERTY(bool glColorCorrection READ glColorCorrection CONSTANT);
Q_PROPERTY(int animationSpeed READ animationSpeed WRITE setAnimationSpeed NOTIFY animationSpeedChanged)
Q_PROPERTY(int windowThumbnail READ windowThumbnail WRITE setWindowThumbnail NOTIFY windowThumbnailChanged)
Q_PROPERTY(int glScaleFilter READ glScaleFilter WRITE setGlScaleFilter NOTIFY glScaleFilterChanged)
Q_PROPERTY(bool xrScaleFilter READ xrScaleFilter WRITE setXrScaleFilter NOTIFY xrScaleFilterChanged)
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)
public:
explicit Compositing(QObject *parent = 0);
@ -52,14 +52,37 @@ public:
int glSwapStrategy() const;
bool glColorCorrection() const;
private:
void setAnimationSpeed(int speed);
void setWindowThumbnail(int index);
void setGlScaleFilter(int index);
void setXrScaleFilter(bool filter);
void setUnredirectFullscreen(bool unredirect);
void setGlSwapStrategy(int strategy);
void setGlColorCorrection(bool correction);
void save();
public Q_SLOTS:
void reset();
Q_SIGNALS:
void changed();
void animationSpeedChanged();
void windowThumbnailChanged();
void glScaleFilterChanged();
void xrScaleFilterChanged();
void unredirectFullscreenChanged();
void glSwapStrategyChanged();
void glColorCorrectionChanged();
enum OpenGLTypeIndex {
OPENGL31_INDEX = 0,
OPENGL20_INDEX,
OPENGL12_INDEX,
XRENDER_INDEX
};
private:
int m_animationSpeed;
int m_windowThumbnail;
int m_glScaleFilter;
bool m_xrScaleFilter;
bool m_unredirectFullscreen;
int m_glSwapStrategy;
bool m_glColorCorrection;
};

@ -26,6 +26,13 @@ import org.kde.plasma.components 2.0 as PlasmaComponents
Item {
signal changed
property alias animationSpeedValue: animationSpeed.value
property alias windowThumbnailIndex: windowThumbnail.currentIndex
property alias glScaleFilterIndex: glScaleFilter.currentIndex
property bool xrScaleFilterChecked: xrScaleFilter.currentIndex > 0
property alias unredirectFullScreenChecked: unredirectFullScreen.checked
property alias glSwapStrategyIndex: glSwapStrategy.currentIndex
property alias glColorCorrectionChecked: glColorCorrection.checked
Component {
id: sectionHeading
@ -283,32 +290,4 @@ Item {
target: openGLType
onCurrentIndexChanged: changed()
}
Connections {
target: animationSpeed
onValueChanged: changed()
}
Connections {
target: windowThumbnail
onCurrentIndexChanged: changed()
}
Connections {
target: glScaleFilter
onCurrentIndexChanged: changed()
}
Connections {
target: xrScaleFilter
onCurrentIndexChanged: changed()
}
Connections {
target: unredirectFullScreen
onCheckedChanged: changed()
}
Connections {
target: glSwapStrategy
onCurrentIndexChanged: changed()
}
Connections {
target: glColorCorrection
onCheckedChanged: changed()
}
}//End item

@ -69,6 +69,18 @@ Rectangle {
Compositing {
id: compositing
objectName: "compositing"
animationSpeed: view.animationSpeedValue
windowThumbnail: view.windowThumbnailIndex
glScaleFilter: view.glScaleFilterIndex
xrScaleFilter: view.xrScaleFilterChecked
unredirectFullscreen: view.unredirectFullScreenChecked
glSwapStrategy: view.glSwapStrategyIndex
glColorCorrection: view.glColorCorrectionChecked
}
Connections {
target: compositing
onChanged: window.changed()
}
Component.onCompleted: {
@ -78,5 +90,6 @@ Rectangle {
openGLError.visible = false;
view.visible = true;
}
compositing.reset();
}
}

Loading…
Cancel
Save