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

List:       kde-commits
Subject:    [kscreen/osd] kded: kded/osdwidget: Remove apply config thread
From:       Leslie Zhai <xiangzhai83 () gmail ! com>
Date:       2015-07-17 4:43:25
Message-ID: E1ZFxUb-0008WO-Ro () scm ! kde ! org
[Download RAW message or body]

Git commit df179e85598d532f9aca92d0259ca8e367c94953 by Leslie Zhai.
Committed on 17/07/2015 at 04:42.
Pushed by lesliezhai into branch 'osd'.

kded/osdwidget: Remove apply config thread

M  +61   -50   kded/osdwidget.cpp
M  +1    -15   kded/osdwidget.h

http://commits.kde.org/kscreen/df179e85598d532f9aca92d0259ca8e367c94953

diff --git a/kded/osdwidget.cpp b/kded/osdwidget.cpp
index bf40ea2..17cd4bd 100644
--- a/kded/osdwidget.cpp
+++ b/kded/osdwidget.cpp
@@ -94,11 +94,20 @@ void OsdWidget::showAll()
     }
 }
 
+void OsdWidget::m_doApplyConfig()
+{
+    connect(new KScreen::SetConfigOperation(m_config), &KScreen::SetConfigOperation::finished,
+            [&]() {
+                qDebug() << "Config applied";
+            });
+}
+
 void OsdWidget::m_pcScreenOnly() 
 {
-    SetConfigOpThread *thread = nullptr;
-    
     for (KScreen::OutputPtr &output : m_config->outputs()) {
+        if (!output->isConnected())
+            continue;
+
         // if there is NO primary set, isPrimary is unreliable!
         if (output->isPrimary() || output->name().contains(lvdsPrefix))
             output->setEnabled(true);
@@ -106,66 +115,82 @@ void OsdWidget::m_pcScreenOnly()
             output->setEnabled(false);
     }
 
-    thread = new SetConfigOpThread(m_config);
-    thread->start();
+    m_doApplyConfig();
 }
 
 void OsdWidget::m_mirror() 
 {
-    KScreen::OutputPtr primaryOutput;
-    QPoint primaryPos(0, 0);
-    SetConfigOpThread *thread = nullptr;
+    QString primaryName = "";
+    QString secondName = "";
 
     // TODO: it needs to find the same resoluation, if there is none?
     for (KScreen::OutputPtr &output : m_config->outputs()) {
-        if (output->isPrimary() || output->name().contains(lvdsPrefix)) {
-            primaryOutput = output;
-            output->setPos(primaryPos);
-        } else {
-            output->setPos(primaryPos);
-        }
+        if (!output->isConnected())
+            continue;
+
+        if (output->isPrimary() || output->name().contains(lvdsPrefix))
+            primaryName = output->name();
+        else
+            secondName = output->name();
     }
 
-    thread = new SetConfigOpThread(m_config);
-    thread->start();
+    if (primaryName == "" || secondName == "")
+        return;
+
+    // xrandr --output LVDS1 --auto --output VGA1 --auto --same-as LVDS1
+    KToolInvocation::kdeinitExec(QString("xrandr"), QStringList()
+        << QString("--output") << primaryName << QString("--auto")
+        << QString("--output") << secondName << QString("--auto")
+        << QString("--same-as") << primaryName);
 }
 
 void OsdWidget::m_extend() 
 {
-    QPoint secondPos(0, 0);
-    SetConfigOpThread *thread = nullptr;
+    QString primaryName = "";
+    QString secondName = "";
 
     for (KScreen::OutputPtr &output : m_config->outputs()) {
-        if (output->isPrimary() || output->name().contains(lvdsPrefix)) {
-            output->setPos(secondPos);
-            secondPos.setX(output->pos().x() + output->size().width());
-        } else {
-            output->setPos(secondPos);
-        }
+        if (!output->isConnected())
+            continue;
+
+        if (output->isPrimary() || output->name().contains(lvdsPrefix))
+            primaryName = output->name();
+        else
+            secondName = output->name();
     }
 
-    if (secondPos.isNull())
+    if (primaryName == "" || secondName == "")
         return;
 
-    thread = new SetConfigOpThread(m_config);
-    thread->start();
+    // xrandr --output LVDS1 --auto --output VGA1 --auto --right-of LVDS1
+    KToolInvocation::kdeinitExec(QString("xrandr"), QStringList()
+        << QString("--output") << primaryName << QString("--auto")
+        << QString("--output") << secondName << QString("--auto")
+        << QString("--right-of") << primaryName);
 }
 
 void OsdWidget::m_secondScreenOnly() 
 {
-    SetConfigOpThread *thread = nullptr;
-    
+    QString primaryName = "";
+    QString secondName = "";
+
     for (KScreen::OutputPtr &output : m_config->outputs()) {
-        if (output->isPrimary() || output->name().contains(lvdsPrefix)) {
-            output->setPrimary(false);
-            output->setEnabled(false);
-        } else {
-            output->setEnabled(true);
-        }
+        if (!output->isConnected())
+            continue;
+
+        if (output->isPrimary() || output->name().contains(lvdsPrefix))
+            primaryName = output->name();
+        else
+            secondName = output->name();
     }
 
-    thread = new SetConfigOpThread(m_config);
-    thread->start();
+    if (primaryName == "" || secondName == "")
+        return;
+
+    // xrandr --output LVDS1 --off --output VGA1 --auto
+    KToolInvocation::kdeinitExec(QString("xrandr"), QStringList()
+        << QString("--output") << primaryName << QString("--off")
+        << QString("--output") << secondName << QString("--auto"));
 }
 
 void OsdWidget::slotItemClicked(QListWidgetItem *item) 
@@ -182,17 +207,3 @@ void OsdWidget::slotItemClicked(QListWidgetItem *item)
         m_secondScreenOnly();
     }
 }
-
-SetConfigOpThread::SetConfigOpThread(KScreen::ConfigPtr config) 
-  : m_config(config) 
-{
-}
-
-void SetConfigOpThread::run() 
-{
-    //if (!KScreen::Config::canBeApplied(m_config))
-    //    return;
-
-    auto *op = new KScreen::SetConfigOperation(m_config);
-    op->exec();
-}
diff --git a/kded/osdwidget.h b/kded/osdwidget.h
index 442f978..1f4221c 100644
--- a/kded/osdwidget.h
+++ b/kded/osdwidget.h
@@ -21,7 +21,6 @@
 
 #include <QWidget>
 #include <QListWidgetItem>
-#include <QThread>
 
 #include <kscreen/config.h>
 
@@ -43,6 +42,7 @@ private slots:
     void slotItemClicked(QListWidgetItem*);
 
 private:
+    void m_doApplyConfig();
     void m_pcScreenOnly();
     void m_mirror();
     void m_extend();
@@ -51,18 +51,4 @@ private:
     KScreen::ConfigPtr m_config;
 };
 
-class SetConfigOpThread : public QThread
-{
-    Q_OBJECT
-
-public:
-    explicit SetConfigOpThread(KScreen::ConfigPtr);
-
-protected:
-    void run();
-
-private:
-    KScreen::ConfigPtr m_config;
-};
-
 #endif /* __OSD_WIDGET_H__ */
[prev in list] [next in list] [prev in thread] [next in thread] 

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