From: R. Steve McKown Date: Fri, 23 Jan 2015 10:11:31 +0000 (-0700) Subject: To LVDS and back to dualext X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=dispcfg.git;a=commitdiff_plain;h=7906d8605d282e11e0a1463cb7ae5a7c98840787 To LVDS and back to dualext --- diff --git a/xrandr_configure_outputs.py b/xrandr_configure_outputs.py index 608dfb7..40a3ff2 100644 --- a/xrandr_configure_outputs.py +++ b/xrandr_configure_outputs.py @@ -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)