Created
August 31, 2017 18:06
-
-
Save frozencemetery/26e3c90153e9f2881fac6f7e5f9722c4 to your computer and use it in GitHub Desktop.
File: beam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import subprocess | |
import sys | |
PRIMARIES = {"eDP1", "eDP-1", "LVDS1", "LVDS-1"} | |
def getoutputs(): | |
res = subprocess.getoutput("xrandr") | |
outputs = {l.split()[0] for l in res.split("\n") if " connected" in l} | |
primary = PRIMARIES.intersection(outputs) | |
if len(primary) != 1: | |
print("No primary found!", file=sys.stderr) | |
exit(1) | |
primary = primary.pop() | |
outputs.discard(primary) | |
return primary, outputs | |
def beamdown(): | |
subprocess.check_call(["xrandr", "--auto"]) | |
_, secondaries = getoutputs() | |
cmd = "xrandr " + " ".join(["--output %s --off" % o for o in secondaries]) | |
subprocess.check_output(cmd.split(" ")) | |
return | |
def beamup(): | |
subprocess.check_call(["xrandr", "--auto"]) | |
primary, secondaries = getoutputs() | |
if len(secondaries) > 1: | |
print("Warning: multiple secondaries detected!", file=sys.stderr) | |
subprocess.check_output(["xrandr", "--output", primary, "--off"]) | |
return | |
def usage(): | |
print("Usage: %s [up|down]" % sys.argv[0], file=sys.stderr) | |
exit(1) | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
usage() | |
pass | |
elif sys.argv[1] == "up": | |
beamup() | |
pass | |
elif sys.argv[1] == "down": | |
beamdown() | |
pass | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment