-
- # 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]
- extPosition = PositionSelection(usedExternalConnector, map(res2user, internalResolutions), map(res2user, externalResolutions))
- extPosition.exec_()
- if not extPosition.result(): sys.exit(1) # the user canceled
- extResolution = res2xrandr(externalResolutions[extPosition.extResolutions.currentIndex()])
- intResolution = res2xrandr(internalResolutions[extPosition.intResolutions.currentIndex()])
- # build command-line
- args[usedExternalConnector] = ["--mode", extResolution] # set external screen to desired resolution
- if extPosition.extOnly.isChecked():
- args[usedExternalConnector] += ["--primary"]
- else:
- # there are two screens
- args[internalConnector] = ["--mode", intResolution] # set internal screen to desired resolution
- # set position
- if extPosition.posLeft.isChecked():
- args[usedExternalConnector] += ["--left-of", internalConnector]
- else:
- args[usedExternalConnector] += ["--right-of", internalConnector]
- # set primary screen
- if extPosition.primExt.isChecked():
- 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)