-# load connectors and options
-connectors = getXrandrInformation()
-config = loadConfigFile(os.getenv('HOME') + '/.dsl.conf')
-# find internal connector
-if 'internalConnector' in config:
- if len(config['internalConnector']) != 1:
- raise Exception("You must specify exactly one internal connector")
- internalConnector = config['internalConnector'][0]
- if not internalConnector in connectors:
- raise Exception("Connector %s does not exist, there is an error in your config file" % internalConnector)
-else:
- # auto-config
- internalConnector = findAvailableConnector(commonInternalConnectorNames)
- if internalConnector is None:
- raise Exception("Could not automatically find internal connector, please use ~/.dsl.conf to specify it manually")
-# all the rest is external then, obviously - unless the user wants to do that manually
-if 'externalConnectors' in config:
- externalConnectors = config['externalConnectors']
- for connector in externalConnectors:
- if not connector in connectors:
- raise Exception("Connector %s does not exist, there is an error in your config file" % internalConnector)
-else:
- externalConnectors = connectors.keys()
- externalConnectors.remove(internalConnector)
-if not externalConnectors:
- raise Exception("No external connector found - either your config is wrong, or your machine has only one connector")
-
-# 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) # *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"]
+# Return a (internalConnector, externalConnectors) pair: The name of the internal connector, and a list of external connectors.
+# Use the config file at ~/.dsl.conf and fall back to auto-detection
+def classifyConnectors(allConnectors):
+ config = loadConfigFile(os.getenv('HOME') + '/.dsl.conf')
+ # find internal connector
+ if 'internalConnector' in config:
+ if len(config['internalConnector']) != 1:
+ raise Exception("You must specify exactly one internal connector.")
+ internalConnector = config['internalConnector'][0]
+ if not internalConnector in allConnectors:
+ raise Exception("Connector %s does not exist, there is an error in your config file." % internalConnector)