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

List:       kde-commits
Subject:    [kscreen/osd] /: kded/daemon: FIXME why set second screen only failed?
From:       Leslie Zhai <xiangzhai83 () gmail ! com>
Date:       2015-07-16 4:19:11
Message-ID: E1ZFadb-0006UU-Qg () scm ! kde ! org
[Download RAW message or body]

Git commit 43b1f7881364b705d797b721b2c657e860e8e4cb by Leslie Zhai.
Committed on 16/07/2015 at 04:18.
Pushed by lesliezhai into branch 'osd'.

kded/daemon: FIXME why set second screen only failed?

M  +1    -1    CMakeLists.txt
M  +1    -1    kded/CMakeLists.txt
M  +126  -3    kded/daemon.cpp
M  +20   -0    kded/daemon.h

http://commits.kde.org/kscreen/43b1f7881364b705d797b721b2c657e860e8e4cb

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e157a5e..1a05702 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ find_package(ECM 1.6.0 REQUIRED NO_MODULE)
 set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
 
 find_package(Qt5 REQUIRED COMPONENTS QuickWidgets Test)
-find_package(KF5 REQUIRED COMPONENTS DBusAddons ConfigWidgets I18n XmlGui \
GlobalAccel) +find_package(KF5 REQUIRED COMPONENTS DBusAddons ConfigWidgets I18n \
XmlGui GlobalAccel Service)  
 set(MIN_LIBKSCREEN_VERSION "5.2.91")
 find_package(KF5Screen ${MIN_LIBKSCREEN_VERSION} REQUIRED)
diff --git a/kded/CMakeLists.txt b/kded/CMakeLists.txt
index 3d24aa7..ddd1923 100644
--- a/kded/CMakeLists.txt
+++ b/kded/CMakeLists.txt
@@ -22,7 +22,7 @@ qt5_add_dbus_adaptor(kscreen_daemon_SRCS
 
 add_library(kded_kscreen MODULE ${kscreen_daemon_SRCS})
 
-target_link_libraries(kded_kscreen Qt5::Widgets Qt5::DBus KF5::Screen \
KF5::DBusAddons KF5::I18n KF5::XmlGui KF5::GlobalAccel) \
+target_link_libraries(kded_kscreen Qt5::Widgets Qt5::DBus KF5::Screen \
KF5::DBusAddons KF5::I18n KF5::XmlGui KF5::GlobalAccel KF5::Service)  
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/kscreen.desktop.cmake
                ${CMAKE_CURRENT_BINARY_DIR}/kscreen.desktop
diff --git a/kded/daemon.cpp b/kded/daemon.cpp
index fb903d1..ad8335d 100644
--- a/kded/daemon.cpp
+++ b/kded/daemon.cpp
@@ -32,6 +32,7 @@
 #include <KActionCollection>
 #include <KPluginFactory>
 #include <KGlobalAccel>
+#include <KToolInvocation>
 
 #include <kscreen/config.h>
 #include <kscreen/output.h>
@@ -81,6 +82,8 @@ KScreenDaemon::~KScreenDaemon()
     delete m_saveTimer;
     delete m_buttonTimer;
     delete m_lidClosedTimer;
+    delete m_osdWidget;
+    m_osdWidget = nullptr;
 
     Generator::destroy();
     Device::destroy();
@@ -132,6 +135,13 @@ void KScreenDaemon::init()
     connect(Generator::self(), &Generator::ready,
             this, &KScreenDaemon::applyConfig);
 
+    connect(m_osdWidget, &OsdWidget::pcScreenOnly, 
+            this, &KScreenDaemon::slotPcScreenOnly);
+    connect(m_osdWidget, &OsdWidget::mirror, this, &KScreenDaemon::slotMirror);
+    connect(m_osdWidget, &OsdWidget::extend, this, &KScreenDaemon::slotExtend);
+    connect(m_osdWidget, &OsdWidget::secondScreenOnly, 
+            this, &KScreenDaemon::slotSecondScreenOnly);
+
     Generator::self()->setCurrentConfig(m_monitoredConfig);
     monitorConnectedChange();
 }
@@ -201,7 +211,7 @@ void KScreenDaemon::saveCurrentConfig()
 
 void KScreenDaemon::displayButton()
 {
-    m_osdWidget->show();
+    m_osdWidget->showAll();
     
     qCDebug(KSCREEN_KDED) << "displayBtn triggered";
     if (m_buttonTimer->isActive()) {
@@ -311,8 +321,14 @@ void KScreenDaemon::outputConnectedChanged()
         }
     }
 
-    if (m_monitoredConfig->outputs().size() > 1)
-        m_osdWidget->show();
+    unsigned int outputConnected = 0;
+    for (KScreen::OutputPtr &output : m_monitoredConfig->outputs()) {
+        if (output->isConnected())
+            outputConnected++;
+    }
+
+    if (outputConnected > 1)
+        m_osdWidget->showAll();
 }
 
 
@@ -366,6 +382,101 @@ void KScreenDaemon::disableOutput(KScreen::ConfigPtr &config, \
KScreen::OutputPtr  output->setEnabled(false);
 }
 
+void KScreenDaemon::slotPcScreenOnly() 
+{
+    SetConfigOpThread *thread = nullptr;
+    
+    for (KScreen::OutputPtr &output : m_monitoredConfig->outputs()) {
+        if (output->isPrimary())
+            output->setEnabled(true);
+        else
+            output->setEnabled(false);
+    }
+
+    thread = new SetConfigOpThread(m_monitoredConfig);
+    thread->start();
+}
+
+void KScreenDaemon::slotMirror() 
+{
+    KScreen::OutputPtr primaryOutput;
+    QPoint primaryPos;
+    QList<int> outputlist;
+    SetConfigOpThread *thread = nullptr;
+
+    for (KScreen::OutputPtr &output : m_monitoredConfig->outputs()) {
+        // FIXME: it can not setEnabled for output when disabled by pcScreenOnly 
+        // or secondScreenOnly, the same story for slotExtend
+        //output->setEnabled(true);
+        
+        // so just use xrandr, for example, xrandr --output LVDS1 --auto
+        KToolInvocation::kdeinitExec(QString("xrandr"), QStringList() << 
+            QString("--output") << output->name() << QString("--auto"));
+
+        if (output->isPrimary()) {
+            primaryOutput = output;
+            primaryPos = output->pos();
+        } else {
+            outputlist << output->id();
+            output->setPos(primaryPos);
+        }
+    }
+
+    primaryOutput->setClones(outputlist);
+
+    thread = new SetConfigOpThread(m_monitoredConfig);
+    thread->start();
+}
+
+void KScreenDaemon::slotExtend() 
+{
+    QPoint secondPos;
+    SetConfigOpThread *thread = nullptr;
+
+    for (KScreen::OutputPtr &output : m_monitoredConfig->outputs()) {
+        KToolInvocation::kdeinitExec(QString("xrandr"), QStringList() <<
+            QString("--output") << output->name() << QString("--auto"));
+
+        if (output->isPrimary()) {
+            secondPos = output->pos();
+            secondPos.setX(output->pos().x() + output->size().width());
+        } else {
+            output->setPos(secondPos);
+        }
+    }
+
+    thread = new SetConfigOpThread(m_monitoredConfig);
+    thread->start();
+}
+
+void KScreenDaemon::slotSecondScreenOnly() 
+{
+    // FIXME: fail to set second screen only
+    SetConfigOpThread *thread = nullptr;
+    QString primaryName;
+    QString secondName;
+    
+    for (KScreen::OutputPtr &output : m_monitoredConfig->outputs()) {
+        if (output->isPrimary()) {
+            output->setEnabled(false);
+            primaryName = output->name();
+        } else {
+            output->setEnabled(true);
+            secondName = output->name();
+            break;
+        }
+    }
+
+    thread = new SetConfigOpThread(m_monitoredConfig);
+    thread->start();
+
+    // so just use xrandr command, for example, 
+    // xrandr --output LVDS1 --off --output VGA1 --auto
+    KToolInvocation::kdeinitExec(QString("xrandr"), 
+        QStringList() << QString("--output") << primaryName << QString("--off") 
+        << QString("--output") << secondName << QString("--auto"));
+}
+
 KScreen::OutputPtr KScreenDaemon::findEmbeddedOutput(const KScreen::ConfigPtr \
&config)  {
     Q_FOREACH (const KScreen::OutputPtr &output, config->outputs()) {
@@ -377,6 +488,18 @@ KScreen::OutputPtr KScreenDaemon::findEmbeddedOutput(const \
KScreen::ConfigPtr &c  return KScreen::OutputPtr();
 }
 
+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();
+}
 
 #include "daemon.moc"
diff --git a/kded/daemon.h b/kded/daemon.h
index 9b939b1..4fcf19a 100644
--- a/kded/daemon.h
+++ b/kded/daemon.h
@@ -20,6 +20,7 @@
 #define KSCREN_DAEMON_H
 
 #include <QVariant>
+#include <QThread>
 
 #include <kdedmodule.h>
 
@@ -62,6 +63,11 @@ class Q_DECL_EXPORT KScreenDaemon : public KDEDModule
         void setMonitorForChanges(bool enabled);
         void outputConnectedChanged();
 
+        void slotPcScreenOnly();
+        void slotMirror();
+        void slotExtend();
+        void slotSecondScreenOnly();
+
     Q_SIGNALS:
         void outputConnected(const QString &outputName);
         void unknownOutputConnected(const QString &outputName);
@@ -83,4 +89,18 @@ class Q_DECL_EXPORT KScreenDaemon : public KDEDModule
         OsdWidget* m_osdWidget;
 };
 
+class SetConfigOpThread : public QThread 
+{
+    Q_OBJECT
+
+public:
+    explicit SetConfigOpThread(KScreen::ConfigPtr);
+
+protected:
+    void run();
+
+private:
+    KScreen::ConfigPtr m_config;
+};
+
 #endif /*KSCREN_DAEMON_H*/


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

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