-# this is as close as one can get to an enum in Python
-class RelativeScreenPosition:
- LEFT = 0
- RIGHT = 1
- EXTERNAL_ONLY = 2
- MIRROR = 3
-
- __names__ = {
- 'left': LEFT,
- 'right': RIGHT,
- 'external-only': EXTERNAL_ONLY,
- 'mirror': MIRROR
- }
-
-# storing what's necessary for screen setup
-class ScreenSetup:
- def __init__(self, relPosition, intResolution, extResolution, extIsPrimary = False):
- '''relPosition must be one of the RelativeScreenPosition members, the resolutions must be (width, height) pairs'''
- self.relPosition = relPosition
- self.intResolution = intResolution # value doesn't matter if the internal screen is disabled
- self.extResolution = extResolution
- self.extIsPrimary = extIsPrimary or self.relPosition == RelativeScreenPosition.EXTERNAL_ONLY # external is always primary if it is the only one
-
- def getInternalArgs(self):
- if self.relPosition == RelativeScreenPosition.EXTERNAL_ONLY:
- return ["--off"]
- args = ["--mode", res2xrandr(self.intResolution)] # set internal screen to desired resolution
- if not self.extIsPrimary:
- args.append('--primary')
- return args
-
- def getExternalArgs(self, intName):
- args = ["--mode", res2xrandr(self.extResolution)] # set external screen to desired resolution
- if self.extIsPrimary:
- args.append('--primary')
- # set position
- if self.relPosition == RelativeScreenPosition.LEFT:
- args += ['--left-of', intName]
- elif self.relPosition == RelativeScreenPosition.RIGHT:
- args += ['--right-of', intName]
- elif self.relPosition == RelativeScreenPosition.MIRROR:
- args += ['--same-as', intName]
- else:
- assert self.relPosition == RelativeScreenPosition.EXTERNAL_ONLY
- return args