[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kscreen/saveWhenNeeded] kded: Do not monitor for changes when apply known configurations
From:       Àlex_Fiestas <afiestas () kde ! org>
Date:       2013-01-02 11:52:30
Message-ID: 20130102115230.2FDFDA6091 () git ! kde ! org
[Download RAW message or body]

Git commit 040d45c1384b237ad11c45c731979b48b37b3612 by Àlex Fiestas.
Committed on 02/01/2013 at 12:49.
Pushed by afiestas into branch 'saveWhenNeeded'.

Do not monitor for changes when apply known configurations

It is quite stupid to monitor for changes when we apply a config that we
already know resulting in a lot of noise and operations that are not
needed.

M  +52   -19   kded/daemon.cpp
M  +12   -1    kded/daemon.h

http://commits.kde.org/kscreen/040d45c1384b237ad11c45c731979b48b37b3612

diff --git a/kded/daemon.cpp b/kded/daemon.cpp
index 287021b..24742e4 100644
--- a/kded/daemon.cpp
+++ b/kded/daemon.cpp
@@ -39,7 +39,9 @@ K_EXPORT_PLUGIN(KScreenDaemonFactory("kscreen", "kscreen"))
 KScreenDaemon::KScreenDaemon(QObject* parent, const QList< QVariant >& )
  : KDEDModule(parent)
  , m_iteration(0)
+ , m_monitoredConfig(0)
  , m_pendingSave(false)
+ , m_monitoring(false)
  , m_timer(new QTimer())
 {
     setenv("KSCREEN_BACKEND", "XRandR", 1);
@@ -66,20 +68,30 @@ KScreenDaemon::~KScreenDaemon()
 void KScreenDaemon::init()
 {
     applyConfig();
-    monitorForChanges();
 }
 
 void KScreenDaemon::applyConfig()
 {
     qDebug() << "Applying config";
-    KScreen::Config* config = 0;
     if (Serializer::configExists()) {
-        config = Serializer::config(Serializer::currentId());
-    } else {
-        config = Generator::self()->idealConfig();
+        applyKnownConfig();
+        return;
     }
 
-    KScreen::Config::setConfig(config);
+    applyIdealConfig();
+}
+
+void KScreenDaemon::applyKnownConfig()
+{
+    setMonitorForChanges(false);
+    KScreen::Config::setConfig(Serializer::config(Serializer::currentId()));
+    setMonitorForChanges(true);
+}
+
+void KScreenDaemon::applyIdealConfig()
+{
+    setMonitorForChanges(true);
+    KScreen::Config::setConfig(Generator::self()->idealConfig());
 }
 
 void KScreenDaemon::configChanged()
@@ -128,21 +140,42 @@ void KScreenDaemon::lidClosedChanged()
     KScreen::Config::setConfig(Generator::self()->idealConfig());
 }
 
-void KScreenDaemon::monitorForChanges()
+void KScreenDaemon::setMonitorForChanges(bool enabled)
 {
-    KScreen::Config* config = KScreen::Config::current();
-    KScreen::ConfigMonitor::instance()->addConfig(config);
+    if (m_monitoring == enabled) {
+        return;
+    }
+    if (!m_monitoredConfig) {
+        m_monitoredConfig = KScreen::Config::current();
+        KScreen::ConfigMonitor::instance()->addConfig(m_monitoredConfig);
+    }
+
+    m_monitoring = enabled;
 
-    KScreen::OutputList outputs = config->outputs();
+    KScreen::OutputList outputs = m_monitoredConfig->outputs();
     Q_FOREACH(KScreen::Output* output, outputs) {
-        connect(output, SIGNAL(isConnectedChanged()), SLOT(applyConfig()));
-
-        connect(output, SIGNAL(currentModeChanged()), SLOT(configChanged()));
-        connect(output, SIGNAL(isEnabledChanged()), SLOT(configChanged()));
-        connect(output, SIGNAL(isPrimaryChanged()), SLOT(configChanged()));
-        connect(output, SIGNAL(outputChanged()), SLOT(configChanged()));
-        connect(output, SIGNAL(clonesChanged()), SLOT(configChanged()));
-        connect(output, SIGNAL(posChanged()), SLOT(configChanged()));
-        connect(output, SIGNAL(rotationChanged()), SLOT(configChanged()));
+        if (m_monitoring) {
+            enableMonitor(output);
+        } else {
+            disableMonitor(output);
+        }
     }
+}
+
+void KScreenDaemon::enableMonitor(KScreen::Output* output)
+{
+    connect(output, SIGNAL(isConnectedChanged()), SLOT(applyConfig()));
+
+    connect(output, SIGNAL(currentModeChanged()), SLOT(configChanged()));
+    connect(output, SIGNAL(isEnabledChanged()), SLOT(configChanged()));
+    connect(output, SIGNAL(isPrimaryChanged()), SLOT(configChanged()));
+    connect(output, SIGNAL(outputChanged()), SLOT(configChanged()));
+    connect(output, SIGNAL(clonesChanged()), SLOT(configChanged()));
+    connect(output, SIGNAL(posChanged()), SLOT(configChanged()));
+    connect(output, SIGNAL(rotationChanged()), SLOT(configChanged()));
+}
+
+void KScreenDaemon::disableMonitor(KScreen::Output* output)
+{
+    output->disconnect();
 }
\ No newline at end of file
diff --git a/kded/daemon.h b/kded/daemon.h
index 852038d..d94d18b 100644
--- a/kded/daemon.h
+++ b/kded/daemon.h
@@ -24,6 +24,11 @@
 #include <kdedmodule.h>
 
 class QTimer;
+class KScreen
+{
+    class Config;
+    class Output;
+};
 class KDE_EXPORT KScreenDaemon : public KDEDModule
 {
     Q_OBJECT
@@ -36,6 +41,8 @@ class KDE_EXPORT KScreenDaemon : public KDEDModule
     public Q_SLOTS:
         void init();
         void applyConfig();
+        void applyKnownConfig();
+        void applyIdealConfig();
         void configChanged();
         void saveCurrentConfig();
         void displayButton();
@@ -43,10 +50,14 @@ class KDE_EXPORT KScreenDaemon : public KDEDModule
         void lidClosedChanged();
 
     private:
-        void monitorForChanges();
+        void setMonitorForChanges(bool enabled);
+        void enableMonitor(KScreen::Output *output);
+        void disableMonitor(KScreen::Output *output);
 
+        KScreen::Config* m_monitoredConfig;
         quint8 m_iteration;
         bool m_pendingSave;
+        bool m_monitoring;
         QTimer* m_timer;
 };
 

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic