]> oss.titaniummirror.com Git - dispcfg.git/commitdiff
To LVDS and back to dualext
authorR. Steve McKown <rsmckown@gmail.com>
Fri, 23 Jan 2015 10:11:31 +0000 (03:11 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Fri, 23 Jan 2015 10:11:31 +0000 (03:11 -0700)
xrandr_configure_outputs.py

index 608dfb7c86fccf18dbefc7714b98581c8fa040da..40a3ff27134cb73ddea50ce3cddf053ee5a5d5c9 100644 (file)
@@ -121,29 +121,51 @@ if __name__ == '__main__':
             print_output(output)
         print
 
+    def all_done(outputs):
+        for output in outputs:
+            if not output['done']:
+                return False
+        return True
+
+    def disable_an_entry(outputs):
+        for output in outputs:
+            if not output['done'] and not output['use'] and output['enabled']:
+                xrandr_off(output)
+                output['done'] = True
+                return 1
+        return 0
+
+    def enable_an_entry(outputs):
+        enables = 0
+        for output in reversed(outputs):
+            if not output['done'] and output['use']:
+                xrandr_on(output)
+                output['done'] = True
+                return 1
+        return 0
+
     def main(argv):
         global dry_run
         if len(argv) >= 2 and argv[1] == '--dry-run':
             dry_run = True
 
         outputs = parse()
-        #outputs[1]['connected'] = False
-        #outputs[2]['connected'] = False
         print_outputs('Outputs', outputs)
 
         # Find the first two connected devices, in reverse list order.  On the
         # Thinkpad X201, the reversed list order is the preferred order of
         # precedence, highest quality external display first, down to internal
         # LVDS panel used as a last resort.  Also find new posx values.
-        used_count = 0
+        use_count = 0
         posx = 0
         for output in reversed(outputs):
             if output['connected']:
+                print 'use', output['name']
                 output['use'] = True
                 output['posx'] = posx
                 posx += output['width']
-                used_count += 1
-                if used_count >= 2:
+                use_count += 1
+                if use_count >= 2:
                     break
 
         # How many outputs are currently enabled?
@@ -152,44 +174,17 @@ if __name__ == '__main__':
             if output['enabled']:
                 enabled_count += 1
 
-        done = 0
-        while done < len(outputs):
-            done = 0
-            for output in outputs:
-                print 'output', output['name']
-                if output['done']:
-                    print '  already done'
-                    done += 1
-                else:
-                    if not output['use'] and not output['enabled']:
-                        print '  not enabled, not used'
-                        output['done'] = True
-                        done += 1
-                    elif output['use'] and not output['enabled']:
-                        if enabled_count < 2:
-                            print '  use previously unused'
-                            enabled_count += 1
-                            xrandr_on(output)
-                            output['done'] = True
-                            done += 1
-                            break
-                        else:
-                            print '  (skip) use previously unused'
-                    elif not output['use'] and output['enabled']:
-                        if enabled_count > 1:
-                            print '  unused, previously used'
-                            enabled_count -= 1
-                            xrandr_off(output)
-                            output['done'] = True
-                            done += 1
-                            break
-                        else:
-                            print '  (skip) unused, previously used'
-                    else:
-                        print '  used before, used again'
-                        xrandr_on(output)
-                        output['done'] = True
-                        done += 1
+        # Mark outputs that receive no change as done
+        for output in outputs:
+            if not output['use'] and not output['enabled']:
+                # Nothing to do for this output, mark as done
+                output['done'] = True
+
+        while not all_done(outputs):
+            if enabled_count > 1:
+                enabled_count -= disable_an_entry(outputs)
+            if enabled_count < 2:
+                enabled_count += enable_an_entry(outputs)
 
 
     main(sys.argv)