-
- # default: screen off
- args = {} # maps connector names to xrand arguments
- for c in externalConnectors+[internalConnector]:
- args[c] = ["--off"]
-
- # Check what to do
- usedExternalConnector = findAvailableConnector(externalConnectors, connectors) # *the* external connector which is actually used
- if usedExternalConnector is not None: # there's an external screen connected, we need to ask what to do
- internalResolutions = connectors[internalConnector]
- externalResolutions = connectors[usedExternalConnector]
- dialogue = gui.getDialogue(usedExternalConnector, map(res2user, internalResolutions), map(res2user, externalResolutions))
- if not dialogue.run(): sys.exit(1) # the user canceled
- extResolution = res2xrandr(externalResolutions[dialogue.getExtResolutionIndex()])
- intResolution = res2xrandr(internalResolutions[dialogue.getIntResolutionIndex()])
- relPosition = dialogue.getRelativeScreenPosition()
- # build command-line
- args[usedExternalConnector] = ["--mode", extResolution] # set external screen to desired resolution
- if relPosition == RelativeScreenPosition.EXTERNAL_ONLY:
- args[usedExternalConnector] += ["--primary"]
- else:
- # there are two screens
- args[internalConnector] = ["--mode", intResolution] # set internal screen to desired resolution
- # set position
- if relPosition == RelativeScreenPosition.LEFT:
- args[usedExternalConnector] += ["--left-of", internalConnector]
- else:
- args[usedExternalConnector] += ["--right-of", internalConnector]
- # set primary screen
- if dialogue.externalIsPrimary():
- args[usedExternalConnector] += ["--primary"]
- else:
- args[internalConnector] += ["--primary"]
- else:
- # use first resolution
- args[internalConnector] = ["--mode", res2xrandr(connectors[internalConnector][0]), "--primary"]
- # and do it
- call = ["xrandr"]
- for name in args:
- call += ["--output", name] + args[name]
- print "Call that will be made:",call
- subprocess.check_call(call)