def monitor_supports_mode(self, monitor_hsync, monitor_vsync, modename): def list_from_string(str): l = [] pieces = string.split(str, ",") for piece in pieces: tmp = string.split(piece, "-") if len(tmp) == 1: l.append((string.atof(tmp[0]), string.atof(tmp[0]))) else: l.append((string.atof(tmp[0]), string.atof(tmp[1]))) return l if not self.modelines.has_key(modename): return -1 # believe randr before believing our sync range guesses try: import _pyrandr except ImportError: _pyrandr = None if _pyrandr and _pyrandr.randrAvailable(): for num in range(0, _pyrandr.getNumRes()): res = "%sx%s" % _pyrandr.getRes(num) if res == modename: return 1 if monitor_hsync and monitor_vsync: hsync_list = list_from_string(monitor_hsync) vsync_list = list_from_string(monitor_vsync) for modeline in self.modelines[modename]: if modeline.supports(hsync_list, vsync_list): return 1 return 0
def availableModes(self): l = [] modes = {8: ["640x480", "800x600"]} # yeah, this was a bad idea. if False and _pyrandr and _pyrandr.randrAvailable(): for i in range(0, _pyrandr.getNumRes()): res = "%sx%s" % _pyrandr.getRes(i) found = 0 for item in l: if item == res: found = 1 if not found: l.append(res) l.sort(compare_resolution) modes[8] = l modes[16] = l modes[24] = l return modes # no RANDR, guess wildly ram = self.get_videocard_ram_or_probed() # If we can't probe, assume at least 32 megs. if ram == 0: ram = 32 * 1024 modes[8] = filter(lambda res: resolution_area(res) * 1 <= ram * 1024, self.all_resolutions) modes[16] = filter(lambda res: resolution_area(res) * 2 <= ram * 1024, self.all_resolutions) modes[24] = filter(lambda res: resolution_area(res) * 4 <= ram * 1024, self.all_resolutions) return modes
def set_resolution(self, res, change=False): resolution = resolution_from_string(res) # Don't change the running resolution unless asked to, because we # may not be running X yet. if change: if not _pyrandr or not _pyrandr.randrAvailable(): return for i in range(_pyrandr.getNumRes()): r = _pyrandr.getRes(i) if r[0] == resolution[0] and r[1] == resolution[1]: _pyrandr.setRes(i) break # Start with an empty list self.config_resolutions = [] # construct the config list here auto = 1 for r in self.available_resolutions(): if compare_resolution(r, res) < 1: self.config_resolutions.append(r) else: auto = 0 if auto == 0: self.config_resolutions.sort(compare_resolution) self.config_resolutions.reverse() else: self.config_resolutions = [] self.resolution = res self.recalc_mode()
def recalc_mode(self): availableRes = self.available_resolutions() if _pyrandr and _pyrandr.randrAvailable(): self.resolution = "%sx%s" % _pyrandr.getRes(_pyrandr.getCurRes()) if self.resolution not in availableRes: self.resolution = availableRes[-1] availableDepth = self.available_color_depths() if self.colordepth not in availableDepth: self.colordepth = availableDepth[-1]
def get_valid_resolution(xserver): res_supported = False if not _pyrandr or not _pyrandr.randrAvailable(): return True # See if the requested resolution is in the list of what xrandr supports. for num in range(0, _pyrandr.getNumRes()): res = _pyrandr.getRes(num) str = "%sx%s" % (res[0], res[1]) if xserver.resolution == str: res_supported = True break # If not, let's first try 1024x768, and then try 800x600 as a last resort. if not res_supported: xserver.resolution = "1024x768" if not get_valid_resolution(xserver): xserver.resolution = "800x600" get_valid_resolution(xserver) xserver.setHWState() xserver.hwstate.set_resolution(xserver.resolution)