def info(self): try: return self._info except AttributeError: pass with get_window() as win: self._info = randr.get_output_info(win, self.idx, 0)._data return self._info
def display_count(self): res = randr.get_screen_resources(self.root) n = 0 for i in res.outputs: o = randr.get_output_info(self.root, i, config_timestamp=0) if o.modes: # has modes, empty if there's no monitor connected here n += 1 return n
def get_connected_outputs(i_screen=0): "Yield the X11-index for each connected monitor" with get_window(i_screen) as window: res = randr.get_screen_resources(window) outputs = res.outputs for output in outputs: info = randr.get_output_info(window, output, 0) if info.connection == 0: yield output
def get_screen_count(): count = 0 d = display.Display() s = d.screen() window = s.root.create_window(0, 0, 1, 1, 1, s.root_depth) res = randr.get_screen_resources(window) for id in res.outputs: output = randr.get_output_info(window, id, 0) count += output.connection ^ 1 # connection = 0 means display active window.destroy() return count
def get_monitors(): resources = get_screen_resources(display.screen().root) monitors = {} for crtc in resources.crtcs: crtc_info = display.xrandr_get_crtc_info( crtc, resources.config_timestamp) for output_id in crtc_info.outputs: monitor = Monitor(output_id, crtc_info.x, crtc_info.y, crtc_info.width, crtc_info.height) monitors[output_id] = monitor output_ids = resources.outputs for monitor in monitors.values(): output_info = get_output_info(display.screen().root, monitor.id, 0) monitor.name = output_info.name return monitors.values()
def __init__(self, configManager): self.configManager = configManager self.display = display.Display() self.screen = self.display.screen( ) # Screen as an X11 screen, not the actual output self.window = self.screen.root.create_window(0, 0, 1, 1, 1, self.screen.root_depth) outputs = randr.get_screen_resources(self.window).outputs self.logger.debug('Found [{}] outputs available'.format(len(outputs))) # Detect the outputs self.outputs = [] for output in outputs: outInfo = randr.get_output_info(self.window, output, 0) if outInfo.connection == 0: self.logger.debug('Output [{}] is connected'.format( outInfo.name)) if outInfo.crtc > 0: self.logger.debug('Output [{}] is rendered'.format( outInfo.name)) edid = self.__getEDID(output) if edid is None: self.logger.info( 'Output [{}] cannot be identified, skipping ...'. format(outInfo.name)) else: crtc = self.__getCRTC(outInfo) self.outputs.append({ 'output': output, 'info': outInfo, 'crtc': crtc, 'meta': { 'edid': edid, 'name': outInfo.name, 'height': crtc.height, 'width': crtc.width, 'crtc': outInfo.crtc, 'x': crtc.x, 'y': crtc.y, 'mode': crtc.mode, 'rotation': crtc.rotation } })
def output_list_names(): s = display.Display().screen() window = s.root.create_window(0, 0, 1, 1, 1, s.root_depth) outputs = randr.get_screen_resources(window).outputs return [randr.get_output_info(window, o, 0).name for o in outputs]
#!/bin/env python # coding: utf8 # copyright: Cyrille Pontvieux # license: MIT from __future__ import print_function, division from Xlib import display from Xlib.ext import randr d = display.Display() s = d.screen() w = s.root.create_window(0, 0, 1, 1, 1, s.root_depth) res = randr.get_screen_resources(w) modes = {} offset = 0 for mode in res.modes: nextoffset = offset + mode.name_length modes[mode.id] = (res.mode_names[offset:nextoffset], mode) offset = nextoffset for info in [randr.get_output_info(w, id, 0) for id in res.outputs]: for modeId in info.modes: (name, mode) = modes[modeId] refresh = round(mode.dot_clock / (mode.h_total * mode.v_total), 1) print(info.name, name, mode.width, mode.height, refresh)
loglevel = 'verbose' if args.verbose else 'error' monitors_list = dict() monitors_list_inactive = list() primary_monitor = None if 'DISPLAY' not in os.environ: print("error: DISPLAY variable not set") sys.exit(1) # list monitors and get active monitor display_num = os.environ['DISPLAY'] d = display.Display(display_num) root_window = d.screen().root primary_output_id = randr.get_output_primary(root_window).output for output_id in randr.get_screen_resources(root_window).outputs: o = randr.get_output_info(root_window, output_id, 0) if o.crtc != 0: c = randr.get_crtc_info(root_window, o.crtc, 0) monitors_list[o.name] = { 'width': c.width, 'height': c.height, 'x': c.x, 'y': c.y, 'primary': False } if output_id == primary_output_id: monitors_list[o.name]['primary'] = True primary_monitor = o.name else: monitors_list_inactive.append(o.name) # list windows xdo = Xdo() windows_list = xdo.search_windows(winname = b'.*') windows_list.sort() # getting informations about monitor / window to capture
from Xlib import X, display from Xlib.ext import randr d = display.Display() s = d.screen() window = s.root.create_window(0, 0, 1, 1, 1, s.root_depth) res = randr.get_screen_resources(window) for mode in res.modes: w, h = mode.width, mode.height print("Width: {}, height: {}".format(w, h)) outputs = randr.get_screen_resources(window).outputs print(outputs) for index, output in enumerate(outputs): print(output) print(randr.get_output_info(window, outputs[index], 0))
import pdb d = display.Display() s = d.screen() window = s.root.create_window(0, 0, 1, 1, 1, s.root_depth) res = randr.get_screen_resources(window) for mode in res.modes: w, h = mode.width, mode.height print("Width: {}, height: {}".format(w, h)) outputs = randr.get_screen_resources(window).outputs for output in outputs: outInfo = randr.get_output_info(window, output, 0) if outInfo.connection == 0: print("{} connected".format(outInfo.name)) if outInfo.crtc > 0: print("{} rendered".format(outInfo.name)) print("OUT PROPERTY") availableProps = randr.list_output_properties(window, output) for atom in availableProps.atoms: atomName = d.get_atom_name(atom) if atomName == randr.PROPERTY_RANDR_EDID: print("{} - {}".format(atom, atomName)) out = randr.get_output_property(window, output, atom, X.AnyPropertyType, 0, 100,