- preferred_order = list(reversed([output['name'] for output in outputs]))
- print 'preferred order:', preferred_order
- print
-
- tmp = outputs
- outputs = []
- for name in preferred_order:
- output = output_by_name(tmp, name)
- if output:
- outputs.append(output)
- print_outputs('Sorted outputs', outputs)
-
- connected_outputs = [output for output in outputs if output['connected']]
- print_outputs('Connected outputs', connected_outputs)
-
- enabled_outputs = [output for output in outputs if output['enabled']]
- print_outputs('Enabled outputs', enabled_outputs)
-
- # The outputs to use will be a subset of connected outputs
- touse_outputs = connected_outputs
-
- # If there are more then 2 connected outputs, start removing them by
- # order of desirability. The LCD panel is least desirable under the
- # assumption that having more than two means the LCD panel shouldn't be
- # used.
- while len(touse_outputs) > 2:
- print 'trim', touse_outputs[-1]['name']
- touse_outputs = touse_outputs[:-1]
- print_outputs('To use outputs', touse_outputs)
-
- # Determine which outputs to turn off, and which to turn on
- off_outputs = [output for output in enabled_outputs if output not in
- touse_outputs]
- print_outputs('Turn these off', off_outputs)
- on_outputs = [output for output in touse_outputs if output not in
- enabled_outputs]
- print_outputs('Turn these on', on_outputs)
-
- if len(enabled_outputs) < 1 or len(enabled_outputs) > 2 or \
- len(touse_outputs) < 1 or len(touse_outputs) > 2:
- print 'Something is wrong; doing nothing'
- return
-
- # Compute positions for final 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