Bug 350657 - from ExtendToRight directly switch to TurnOffEmbeded cause libkscreen error
Summary: from ExtendToRight directly switch to TurnOffEmbeded cause libkscreen error
Status: RESOLVED FIXED
Alias: None
Product: KScreen
Classification: Plasma
Component: kded (show other bugs)
Version: git
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Leslie Zhai
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-27 09:42 UTC by Leslie Zhai
Modified: 2015-08-07 04:06 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
0001-turnoff-embedded-disable-outputs.patch (489 bytes, patch)
2015-08-07 04:01 UTC, Leslie Zhai
Details
reproduce-outputs-disabled-issue.patch (990 bytes, patch)
2015-08-07 04:05 UTC, Leslie Zhai
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Leslie Zhai 2015-07-27 09:42:26 UTC
from ExtendToRight directly switch to TurnOffEmbeded (by changing kscreen kded source code) cause libkscreen error: There are no enabled screens, at least one required

Reproducible: Always

Steps to Reproduce:
1. change the enum DisplaySwitchAction order to ExtendToRight = 1, TurnOffEmbedded = 2 ...
2. change m_iteration max value to Generator::ExtendToLeft
3. build && install kscreen
4. relogin plasma
5. plugged in a new monitor, press Qt::Key_Display hot key, it switch to ExtendToRight at first, then repress it again

Actual Results:  
All outputs are disabled!
libkscreen config canBeAppled`s log info: There are no enabled screens, at least one required

Expected Results:  
it is able to switch to TurnOffEmbeded directly from ExtendToRight

how to change enum DisplaySwitchAction and m_iteration max value

diff --git a/kded/daemon.cpp b/kded/daemon.cpp
index ed889ca..8452eaa 100644
--- a/kded/daemon.cpp
+++ b/kded/daemon.cpp
@@ -246,7 +246,7 @@ void KScreenDaemon::resetDisplaySwitch()
 
 void KScreenDaemon::applyGenericConfig()
 {
-    if (m_iteration == Generator::ExtendToRight) {
+    if (m_iteration == Generator::ExtendToLeft) {
         m_iteration = Generator::None;
     }
 
diff --git a/kded/generator.h b/kded/generator.h
index 36669fd..bf0ddec 100644
--- a/kded/generator.h
+++ b/kded/generator.h
@@ -35,11 +35,11 @@ class Generator : public QObject
     public:
         enum DisplaySwitchAction {
             None = 0,
-            Clone = 1,
-            ExtendToLeft = 2,
-            TurnOffEmbedded = 3,
-            TurnOffExternal = 4,
-            ExtendToRight = 5,
+            ExtendToRight = 1,
+            TurnOffEmbedded = 2,
+            TurnOffExternal = 3,
+            Clone = 4,
+            ExtendToLeft = 5,
         };
 
         static Generator* self();
Comment 1 Leslie Zhai 2015-08-07 04:01:47 UTC
Created attachment 93923 [details]
0001-turnoff-embedded-disable-outputs.patch

when press Qt::Key_Display hot key, TurnOffExternal is always able to work, because it sets the position for the primary && enabled output:

```
case Generator::TurnOffExternal: {                                             
        qCDebug(KSCREEN_KDED) << "Turn off external screen";                       
        embedded->setPos(QPoint(0,0));                                             
        embedded->setEnabled(true);                                                
        embedded->setPrimary(true);                                                
        const KScreen::ModePtr embeddedMode = bestModeForOutput(embedded);         
        Q_ASSERT(embeddedMode);                                                    
        embedded->setCurrentModeId(embeddedMode->id());
```

so I also set the position when TurnOffEmbedded:

```
case Generator::TurnOffEmbedded: {                                             
        qCDebug(KSCREEN_KDED) << "Turn off embedded (laptop)";                     
        embedded->setEnabled(false);                                               
        embedded->setPrimary(false);                                               
                                                                                   
        external->setPos(QPoint(0, 0));                                            
        external->setEnabled(true);                                                
        external->setPrimary(true);                                                
        const KScreen::ModePtr extMode = bestModeForOutput(external);              
        Q_ASSERT(extMode);                                                         
        external->setCurrentModeId(extMode->id());                                 
        return config;
```

it is able to work correctly switch display from ExtendToRight to TurnOffEmbedded directly.
Comment 2 Leslie Zhai 2015-08-07 04:05:46 UTC
Created attachment 93924 [details]
reproduce-outputs-disabled-issue.patch

If you want to reproduce the issue easily, just patch it, then press Qt::Key_Display hot key, it might be Meta+P in your laptop to experience all outputs are disabled! when just want to TurnOffEmbedded.