def list_screens(method=None, display=None): ''' Retrieve informantion about all screens, outputs and CRTC:s @param method:str? The listing method: 'randr' for RandR (under X), 'drm' for DRM (under TTY) `None` for automatic @param display:str? The display to use, `None` for the current one @return :Screens An instance of a datastructure with the relevant information ''' method = libgammaman.get_method(method) display_ = libgammaman.get_display(display, method) screen_n = display_.partitions_available rc = Screens() rc.screens = [None] * screen_n for screen_i in range(screen_n): screen = libgammaman.get_screen(screen_i, display, method) # And add it to the table rc.screens[screen_i] = s = Screen() # Store the number of CRTC:s s.crtc_count = crtc_n = screen.crtcs_available # Prepare the current screens output table when we know how many outputs it has s.outputs = [None] * crtc_n for crtc_i in range(crtc_n): crtc = libgamma.CRTC(screen, crtc_i) (info, _) = crtc.information(~0) s.outputs[crtc_i] = o = Output() # Store the screen index for the output so that it is easy # to look it up when iterating over outputs o.screen = screen_i # Store the name of the output o.name = info.connector_name if info.connector_name_error == 0 else None # Store the connection status of the output's connector o.connected = info.active if info.active_error == 0 else None # Store the physical dimensions of the monitor o.widthmm, o.heightmm = info.width_mm, info.height_mm # But if it is zero or less it is unknown if (o.widthmm <= 0) or (o.heightmm <= 0): o.widthmm, o.heightmm = None, None # Store the CRTC index of the output o.crtc = crtc_i # Store the output's extended dislay identification data o.edid = None if info.edid is None or not info.edid_error == 0 else libgamma.behex_edid( info.edid) return rc
def get_crtc(crtc, screen, display, method): ''' Get a CRTC @param crtc:int The CRTC index @param screen:int The screen index @param display:str? The display ID @param method:int The adjustment method @return :libgamma.CRTC CRTC object ''' screen = get_screen(screen, display, method) cache_crtcs = screen.cache_crtcs if crtc not in cache_crtcs: monitor = libgamma.CRTC(screen, crtc) cache_crtcs[crtc] = monitor (monitor.info, _) = monitor.information(~0) return cache_crtcs[crtc]
def __init__(self, screen, crtc): ''' Constructor The user should not use this, but use `get_outputs` instead @param screen:LibgammaScreen The screen of the CRTC, using the libgamma backend @param crtc:int The index of the CRTC ''' import libgamma CRTC.__init__(self) self.crtc = libgamma.CRTC(screen, crtc) if screen.display.caps.crtc_restore: self.restore = self.crtc.restore else: self.restore = None info = libgamma.information(~0)[0] connector_types = { libgamma.LIBGAMMA_CONNECTOR_TYPE_9PinDIN = '9PinDIN', libgamma.LIBGAMMA_CONNECTOR_TYPE_Component = 'Component', libgamma.LIBGAMMA_CONNECTOR_TYPE_Composite = 'Composite', libgamma.LIBGAMMA_CONNECTOR_TYPE_DSI = 'DSI', libgamma.LIBGAMMA_CONNECTOR_TYPE_DVI = 'DVI', libgamma.LIBGAMMA_CONNECTOR_TYPE_DVIA = 'DVIA', libgamma.LIBGAMMA_CONNECTOR_TYPE_DVID = 'DVID', libgamma.LIBGAMMA_CONNECTOR_TYPE_DVII = 'DVII', libgamma.LIBGAMMA_CONNECTOR_TYPE_DisplayPort = 'DisplayPort', libgamma.LIBGAMMA_CONNECTOR_TYPE_HDMI = 'HDMI', libgamma.LIBGAMMA_CONNECTOR_TYPE_HDMIA = 'HDMIA', libgamma.LIBGAMMA_CONNECTOR_TYPE_HDMIB = 'HDMIB', libgamma.LIBGAMMA_CONNECTOR_TYPE_LFP = 'LFP', libgamma.LIBGAMMA_CONNECTOR_TYPE_LVDS = 'LVDS', libgamma.LIBGAMMA_CONNECTOR_TYPE_SVIDEO = 'SVIDEO', libgamma.LIBGAMMA_CONNECTOR_TYPE_TV = 'TV', libgamma.LIBGAMMA_CONNECTOR_TYPE_VGA = 'VGA', libgamma.LIBGAMMA_CONNECTOR_TYPE_VIRTUAL = 'VIRTUAL', libgamma.LIBGAMMA_CONNECTOR_TYPE_eDP = 'eDP' } subpixel_orders = { libgamma.LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_BGR = 'BGR', libgamma.LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB = 'RGB', libgamma.LIBGAMMA_SUBPIXEL_ORDER_NONE = 'None', libgamma.LIBGAMMA_SUBPIXEL_ORDER_VERTICAL_BGR = 'vBGR', libgamma.LIBGAMMA_SUBPIXEL_ORDER_VERTICAL_RGB = 'vRGB' } self.edid = None if info.edid_error else libgamma.behex_edid_uppercase(info.edid) self.width_mm = None if info.width_mm_error else info.width_mm self.height_mm = None if info.height_mm_error else info.height_mm self.red_gamma_size = None if info.gamma_size_error else info.red_gamma_size self.green_gamma_size = None if info.gamma_size_error else info.green_gamma_size self.blue_gamma_size = None if info.gamma_size_error else info.blue_gamma_size self.gamma_depth = None if info.gamma_depth_error else info.gamma_depth self.gamma_support = None if info.gamma_support_error else info.gamma_support self.subpixel_order = None if info.subpixel_order_error else info.subpixel_order if self.subpixel_order in subpixel_orders: self.subpixel_order = subpixel_orders[self.subpixel_order] self.active = None if info.active_error else info.active self.connector_name = None if info.connector_name_error else info.connector_name self.connector_type = None if info.connector_type_error else info.connector_type if self.connector_type in connector_types: self.connector_type = connector_types[self.connector_type] if not info.gamma_size_error and not info.gamma_depth_error: self.ramps = libgamma.GammaRamps(self.red_gamma_size, self.green_gamma_size, self.blue_gamma_size, depth = self.gamma_depth)