From b819ae3d803bc45f2084513d356b9e6369c582fe Mon Sep 17 00:00:00 2001 From: "R. Steve McKown" Date: Fri, 23 Jan 2015 03:29:43 -0700 Subject: [PATCH] Place functions before if __name__ --- README | 18 ++++++++++++ configure_displays | 69 ++++++++++++++++++++++++---------------------- 2 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..390ab85 --- /dev/null +++ b/README @@ -0,0 +1,18 @@ +configure_displays should be ran here: + +* On resume from suspend +* On key press from window manager (shortcut) -- currently $mod+p in ~/.i3/config +* On login startup -- currently ~/.i3/startup + +The simple /etc/pm/sleep.d/50_configure-displays script: +---- +#!/bin/sh + +# Configure displays on resume and thaw + +case "$1" in + resume|thaw) + configure_displays + ;; +esac +---- diff --git a/configure_displays b/configure_displays index 40a3ff2..5d122a1 100755 --- a/configure_displays +++ b/configure_displays @@ -1,10 +1,9 @@ #!/usr/bin/python """ -Parse xrandr current information +Configure displays by looking at xrandr information -TODO: -* Cannot seem to undock notebook then recover displays without causing a logout - event. Could it be that i3 is finding there are no displays? +Select the best 1 or 2 xrandr outputs to use as displays, based on xrandr +information, then reconfigure outputs via xrandr. """ import sys @@ -108,6 +107,39 @@ def output_by_name(outputs, name): return None +def print_outputs(header, outputs): + print '%s:' % header + for output in outputs: + 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 + + if __name__ == '__main__': def print_output(output): print 'name:%s connected:%r enabled:%r width:%d height:%d pos:%dx%d' % ( @@ -115,35 +147,6 @@ if __name__ == '__main__': output['width'], output['height'], output['posx'], output['posy']) - def print_outputs(header, outputs): - print '%s:' % header - for output in outputs: - 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': -- 2.39.2