class Display:
def __init__(self, display = None, deepclone = False):
self.outputs = []
self.fb = None
self.fbmm = None ## TODO automatically
self.dpi = None ## TODO automatically
if display is not None:
self.outputs = [Output(output) if deepclone else output for output in display.outputs]
self.fb = display.fb
self.fbmm = display.fbmm
self.dpi = display.dpi
def to_xrandr(self):
ret = ['xrandr']
if self.fb is not None: ret += ['--fb', self.mode]
if self.fbmm is not None: ret += ['--fbmm', self.pos]
if self.dpi is not None: ret += ['--dpi', self.rate]
for output in self.outputs:
ret += output.to_xrandr()
return ret
class Output:
def __init__(self, output):
isnew = not isinstance(output, Output)
self.output = output if isnew else output.output
self.mode = None if isnew else output.mode
self.pos = None if isnew else output.pos
self.rate = None if isnew else output.rate
self.reflect = None if isnew else output.reflect
self.rotate = None if isnew else output.rotate
self.off = False if isnew else output.off
self.crtc = None if isnew else output.crtc
self.gamma = None if isnew else output.gamma
self.brightness = None if isnew else output.brightness
self.panning = None if isnew else output.panning
self.transform = None if isnew else output.transform
self.scale = None if isnew else output.scale
self.scale_from = None if isnew else output.scale_from
self.relpos = None if isnew else output.relpos
self.relto = None if isnew else output.relto
self.primary = False if isnew else output.primary
def to_xrandr(self):
ret = ['--output', self.output]
if self.mode is not None: ret += ['--mode', self.mode]
if self.pos is not None: ret += ['--pos', self.pos]
if self.rate is not None: ret += ['--rate', self.rate]
if self.reflect is not None: ret += ['--reflect', self.reflect]
if self.rotate is not None: ret += ['--rotate', self.rate]
if self.crtc is not None: ret += ['--crtc', self.crtc]
if self.gamma is not None: ret += ['--gamma', self.gamma]
if self.brightness is not None: ret += ['--brightness', self.brightness]
if self.panning is not None: ret += ['--panning', self.panning]
if self.transform is not None: ret += ['--transform', self.transform]
if self.scale is not None: ret += ['--scale', self.scale]
if self.scale_from is not None: ret += ['--scale-from', self.scale_from]
if self.primary: ret += ['--primary']
if self.relpos is not None and self.relto is not None:
ret += ['--' + self.relpos, self.relto]
return ret if not self.off else ['--output', self.output, '--off']
def apply_setup(display):
import sys
from subprocess import Popen
p = Popen(display.to_xrandr(), stdin = sys.stdin, stdout = sys.stdout, stderr = sys.stderr)
return p.wait() == 0