def apply_output_config(self): """Used for instantly applying RandR 1.2 changes""" xrandr._check_required_version((1,2)) self._arrange_outputs() self._calculate_size() # Assign all active outputs to crtcs for output in self.outputs.values(): if not output._mode or output._crtc: continue for crtc in output.get_crtcs(): if crtc and crtc.supports_output(output): crtc.add_output(output) output._changes = output._changes | xrandr.CHANGES_CRTC break if not output._crtc: #FIXME: Take a look at the pick_crtc code in xrandr.c raise RRError("There is no matching crtc for the output") # Disable any crtcs whose size won't fit the new one for crtc in self.crtcs: if not crtc.fits_size(self._width, self._height): crtc.disable() self.set_size(self._width, self._height, self._width_mm, self._height_mm) # Apply stored changes of crtcs for crtc in self.crtcs: if crtc.has_changed(): crtc.apply_changes()
def apply_output_config(self): """Used for instantly applying RandR 1.2 changes""" xrandr._check_required_version((1,2)) self._arrange_outputs() self._calculate_size() # Assign all active outputs to crtcs for output in self.outputs.values(): if not output._mode or output._crtc: continue for crtc in output.get_crtcs(): if crtc and crtc.supports_output(output): crtc.add_output(output) output._changes = output._changes | xrandr.CHANGES_CRTC break if not output._crtc: #FIXME: Take a look at the pick_crtc code in xrandr.c raise RRError("There is no matching crtc for the output") # Apply stored changes of crtcs for crtc in self.crtcs: if crtc.has_changed(): crtc.apply_changes() # Seems that this line should go here, because: # "All active monitors must be configured to display a # subset of the specified size, else a Match error results." # (from XrandR protocol specification, # http://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt) self.set_size(self._width, self._height, self._width_mm, self._height_mm)
def set_size(self, width, height, width_mm, height_mm): """Apply the given pixel and physical size to the screen""" xrandr._check_required_version((1, 2)) # Check if we really need to apply the changes if (width, height, width_mm, height_mm) == self.get_size(): return rr.XRRSetScreenSize(self._display, self._root, c_int(width), c_int(height), c_int(width_mm), c_int(height_mm))
def get_current_rotation(self): """Returns the currently used rotation. Can be RR_ROTATE_0, RR_ROTATE_90, RR_ROTATE_180 or RR_ROTATE_270""" xrandr._check_required_version((1,0)) current = c_ushort() rotations = rr.XRRConfigRotations(self._config, byref(current)) return current.value
def apply_config(self): """Used for instantly applying RandR 1.0 changes""" xrandr._check_required_version((1, 0)) status = rr.XRRSetScreenConfigAndRate(self._display, self._config, self._root, self._size_index, self._rotation, self._rate, self.get_timestamp())
def get_current_size_index(self): """Returns the position of the currently used resolution size in the list of available resolutions. See get_available_sizes""" xrandr._check_required_version((1, 0)) rotation = c_ushort() size = rr.XRRConfigCurrentConfiguration(self._config, byref(rotation)) return size
def set_config(self, size_index, rate, rotation): """Configures the screen with the given resolution at the given size index, rotation and refresh rate. To get in effect call Screen.apply_config()""" xrandr._check_required_version((1,0)) self.set_size_index(size_index) self.set_refresh_rate(rate) self.set_rotation(rotation)
def get_current_size_index(self): """Returns the position of the currently used resolution size in the list of available resolutions. See get_available_sizes""" xrandr._check_required_version((1,0)) rotation = c_ushort() size = rr.XRRConfigCurrentConfiguration(self._config, byref(rotation)) return size
def set_size(self, width, height, width_mm, height_mm): """Apply the given pixel and physical size to the screen""" xrandr._check_required_version((1,2)) # Check if we really need to apply the changes if (width, height, width_mm, height_mm) == self.get_size(): return rr.XRRSetScreenSize(self._display, self._root, c_int(width), c_int(height), c_int(width_mm), c_int(height_mm))
def apply_config(self): """Used for instantly applying RandR 1.0 changes""" xrandr._check_required_version((1,0)) status = rr.XRRSetScreenConfigAndRate(self._display, self._config, self._root, self._size_index, self._rotation, self._rate, self.get_timestamp())
def get_available_sizes(self): """Returns the available resolution sizes of the screen. The size index points to the corresponding resolution of this list""" xrandr._check_required_version((1,0)) sizes = [] nsizes = c_int() xcs = rr.XRRConfigSizes xcs.restype = POINTER(_XRRScreenSize) _sizes = xcs(self._config, byref(nsizes)) for r in range(nsizes.value): sizes.append(_sizes[r]) return sizes
def get_available_rates_for_size_index(self, size_index): """Returns the refresh rates that are supported by the screen for the given resolution. See get_available_sizes for the resolution to which size_index points""" xrandr._check_required_version((1,0)) rates = [] nrates = c_int() rr.XRRConfigRates.restype = POINTER(c_ushort) _rates = rr.XRRConfigRates(self._config, size_index, byref(nrates)) for r in range(nrates.value): rates.append(_rates[r]) return rates
def apply_output_config(self): """Used for instantly applying RandR 1.2 changes""" xrandr._check_required_version((1,2)) self._arrange_outputs() self._calculate_size() self.set_size(self._width, self._height, self._width_mm, self._height_mm) # Assign all active outputs to crtcs for output in self.outputs.values(): if not output._mode or output._crtc: continue for crtc in output.get_crtcs(): if crtc and crtc.supports_output(output): crtc.add_output(output) output._changes = output._changes | xrandr.CHANGES_CRTC break if not output._crtc: #FIXME: Take a look at the pick_crtc code in xrandr.c raise RRError("There is no matching crtc for the output") # Apply stored changes of crtcs for crtc in self.crtcs: if crtc.has_changed(): crtc.apply_changes()
def get_output_names(self): xrandr._check_required_version((1,2)) return self.outputs.keys()
def get_outputs(self): """Returns the outputs of the screen""" xrandr._check_required_version((1,2)) return self.outputs.values()
def print_info(self, verbose=False): """Prints some information about the detected screen and its outputs""" xrandr._check_required_version((1,0)) print "Screen %s: minimum %s x %s, current %s x %s, maximum %s x %s" %\ (self._screen, self._width_min, self._height_min, self._width, self._height, self._width_max, self._height_max) print " %smm x %smm" % (self._width_mm, self._height_mm) print "Crtcs: %s" % len(self.crtcs) if verbose: print "Modes (%s):" % self._resources.contents.nmode modes = self._resources.contents.modes for i in range(self._resources.contents.nmode): print " %s - %sx%s" % (modes[i].name, modes[i].width, modes[i].height) i = 0 print "Sizes @ Refresh Rates:" for s in self.get_available_sizes(): print " [%s] %s x %s @ %s" % (i, s.width, s.height, self.get_available_rates_for_size_index(i)) i += 1 print "Rotations:", rots = self.get_available_rotations() if rots & xrandr.RR_ROTATE_0: print "normal", if rots & xrandr.RR_ROTATE_90: print "right", if rots & xrandr.RR_ROTATE_180: print "inverted", if rots & xrandr.RR_ROTATE_270: print "left", print "" print "Outputs:" for o in self.outputs.keys(): output = self.outputs[o] print " %s" % o, if output.is_connected(): print "(%smm x %smm)" % (output.get_physical_width(), output.get_physical_height()) modes = output.get_available_modes() print " Modes:" for m in range(len(modes)): mode = modes[m] refresh = mode.dotClock / (mode.hTotal * mode.vTotal) print " [%s] %s x %s @ %s" % (m, mode.width, mode.height, refresh), if mode.id == output._mode: print "*", if m == output.get_preferred_mode(): print "(preferred)", print "" print " Rotations:", rots = output.get_available_rotations() if rots & xrandr.RR_ROTATE_0: print "normal", if rots & xrandr.RR_ROTATE_90: print "right", if rots & xrandr.RR_ROTATE_180: print "inverted", if rots & xrandr.RR_ROTATE_270: print "left", print "" else: print "(not connected)" if verbose: print " Core properties:" for (f,t) in output._info.contents._fields_: print " %s: %s" % (f, getattr(output._info.contents, f))
def get_available_rotations(self): """Returns a binary flag that holds the available resolutions""" xrandr._check_required_version((1,0)) current = c_ushort() rotations = rr.XRRConfigRotations(self._config, byref(current)) return rotations
def get_current_rate(self): """Returns the currently used refresh rate""" xrandr._check_required_version((1,0)) xccr = rr.XRRConfigCurrentRate xccr.restype = c_int return xccr(self._config)