From: R. Steve McKown Date: Fri, 23 Jan 2015 09:48:55 +0000 (-0700) Subject: Close but mirrors dual ext when coming from laptop X-Git-Url: https://oss.titaniummirror.com/gitweb?p=dispcfg.git;a=commitdiff_plain;h=2f31887ef07272b1ed04f01256adbd9262041da7 Close but mirrors dual ext when coming from laptop Apparently position isn't valid unless it is 0x0 or right at the edge of an existing enabled window. --- diff --git a/xrandr_configure_outputs.py b/xrandr_configure_outputs.py index d03e9b5..608dfb7 100644 --- a/xrandr_configure_outputs.py +++ b/xrandr_configure_outputs.py @@ -36,7 +36,8 @@ class OutputInfo(): if self.complete(): return {'name':self.name, 'enabled':self.enabled, 'connected':self.connected, 'width':self.width, - 'height':self.height, 'posx':self.posx, 'posy':self.posy} + 'height':self.height, 'posx':self.posx, 'posy':self.posy, + 'use':False, 'done':False} else: raise ValueError @@ -128,85 +129,67 @@ if __name__ == '__main__': outputs = parse() #outputs[1]['connected'] = False #outputs[2]['connected'] = False - print_outputs('Raw outputs', outputs) + print_outputs('Outputs', outputs) - 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 posx = 0 - for output in touse_outputs: - output['posx'] = posx - output['posy'] = 0 - posx += output['width'] - print_outputs('touse, with positions', touse_outputs) - - if touse_outputs != enabled_outputs: - # Remove all enabled outputs save one - while len(enabled_outputs) > 1: - output = enabled_outputs[0] - enabled_outputs = enabled_outputs[1:] - xrandr_off(output) - - # Move the remaining output to a safe position - last_old_output = enabled_outputs[0] - tmp = last_old_output['posx'] - last_old_output['posx'] = posx # from above - xrandr_on(last_old_output) - last_old_output['posx'] = tmp - - # Add the first touse output - first_new_output = touse_outputs[0] - touse_outputs = touse_outputs[1:] - xrandr_on(first_new_output) - - # If last old is not to be used, remove it - if not output_by_name(touse_outputs, last_old_output['name']): - xrandr_off(last_old_output) - - # Now add the remaining touse outputs - for output in touse_outputs: - xrandr_on(output) + for output in reversed(outputs): + if output['connected']: + output['use'] = True + output['posx'] = posx + posx += output['width'] + used_count += 1 + if used_count >= 2: + break + + # How many outputs are currently enabled? + enabled_count = 0 + for output in outputs: + 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 main(sys.argv)