def connect(): runtime.con = xcb.connect() runtime.viewport = runtime.con.get_setup().roots[0] runtime.xrandr = runtime.con(xcb.randr.key) runtime.keyboard = Keyboard(runtime.con) runtime.mouse = Mouse(runtime.con)
def from_xpyb(): """Get the I3 socket path using xpyb. I tried to keep this as close to the actual implementation as possible. """ try: import xcb import xcb.xproto except ImportError: return None conn = xcb.connect() setup = conn.get_setup() root = setup.roots[conn.pref_screen].root atom_cookie = conn.core.InternAtom(0, len(I3_SOCK_X_ATOM), I3_SOCK_X_ATOM) atom = atom_cookie.reply().atom PATH_MAX = 4096 prop_cookie = conn.core.GetPropertyUnchecked(False, root, atom, xcb.xproto.GetPropertyType.Any, 0, PATH_MAX) prop_reply = prop_cookie.reply() return xcb_unpack_prop_reply_value(prop_reply)
def main(): import time import xcb, xcb.xproto, xcb.screensaver conn = xcb.connect() setup = conn.get_setup() root = setup.roots[0].root scr = conn(xcb.screensaver.key) # time in seconds REST_TIME = 60 * 5 CHECK_PERIOD = REST_TIME / 2 WORKING_TIME = 60 * 50 working_time = 0 while True: time.sleep(CHECK_PERIOD) cookie = scr.QueryInfo(root) info = cookie.reply() if info.ms_since_user_input / 1000 < CHECK_PERIOD: working_time += CHECK_PERIOD if working_time > WORKING_TIME: send_notify(working_time) elif info.ms_since_user_input / 1000 >= REST_TIME: working_time = 0 send_ok()
def __init__(self, geometry, screen=None, event_mask=0): super(TestClient, self).__init__(name="Client") self.conn = xcb.connect() if screen is None: screen = self.conn.pref_screen self.screen = self.conn.get_setup().roots[screen] self.atoms = AtomCache(self.conn, ["WM_STATE"]) self.window = self.conn.generate_id() self.mapped = False self.managed = False self.destroyed = False self.reparented = False self.parent = self.screen.root self.geometry = geometry self.synthetic_geometry = None event_mask |= (EventMask.StructureNotify | EventMask.PropertyChange) self.conn.core.CreateWindowChecked(self.screen.root_depth, self.window, self.screen.root, geometry.x, geometry.y, geometry.width, geometry.height, geometry.border_width, WindowClass.InputOutput, self.screen.root_visual, (CW.BackPixel | CW.BorderPixel | CW.EventMask), [self.screen.white_pixel, self.screen.black_pixel, event_mask]).check()
def main(): conn = xcb.connect() conn.render = conn(xcb.render.key) setup = conn.get_setup() root = setup.roots[0].root depth = setup.roots[0].root_depth visual = setup.roots[0].root_visual white = setup.roots[0].white_pixel window = conn.generate_id() conn.core.CreateWindow(depth, window, root, 0, 0, 640, 480, 0, WindowClass.InputOutput, visual, CW.BackPixel | CW.EventMask, [white, EventMask.Exposure | EventMask.KeyPress]) conn.core.MapWindow(window) conn.flush() while True: event = conn.wait_for_event() if isinstance(event, ExposeEvent): color = (0, 0, 65535, 65535) rectangle = (20, 20, 40, 40) # TODO, fixme: # I haven't been able to find what I should put for the parameter "op" #conn.render.FillRectangles(op, window, color, 1, rectangle) conn.flush() elif isinstance(event, KeyPressEvent): break conn.disconnect()
def __init__(self, display=None, screen=None, key_bindings={}, button_bindings={}, **kwargs): self.conn = xcb.connect(display) self.screen_number = (screen if screen is not None else self.conn.pref_screen) self.screen = self.conn.get_setup().roots[self.screen_number] self.window = self.screen.root self.screen_geometry = get_geometry(self.conn, self.window) log.debug("Screen geometry: %s.", self.screen_geometry) self.events = deque([]) # event queue self.window_handlers = {} # event handlers, indexed by window ID self.clients = {} # managed clients, indexed by window ID self.frames = {} # client frames, indexed by window ID self.client_update = None # for move/resize self.parents = {self.screen.root: None} self.atoms = AtomCache(self.conn) self.colors = ColorCache(self.conn, self.screen.default_colormap) self.cursors = FontCursor(self.conn) self.fonts = FontCache(self.conn) self.font_infos = FontInfoCache(self.conn, self.atoms) self.modmap = ModifierMap(self.conn) self.keymap = KeyboardMap(self.conn, modmap=self.modmap) self.key_bindings = KeyBindings(key_bindings, self.keymap, self.modmap) self.button_bindings = ButtonBindings(button_bindings, self.keymap, self.modmap) self.heads = HeadManager(self.conn, self.screen, self) self.shape = query_extension(self.conn, "SHAPE", xcb.shape.key) super(WindowManager, self).__init__(**kwargs)
def setUp(self): self.conn = xcb.connect() # We don't want other clients changing the mappings during these # tests, and it's not worth processing MappingNotify events just # to detect such an eventuality. So we'll lazy out and run them # with the whole server grabbed. self.conn.core.GrabServer()
def main(): signal.signal(signal.SIGTERM, lambda s, f: sys.exit(0)) cfg = parse_args(sys.argv[1:]) conn = xcb.connect(cfg.display) dpms = conn(xcb.dpms.key) while True: main_iteration(dpms, cfg)
def __init__(self): self.conn = xcb.connect() self.setup = self.conn.get_setup() self.root = self.setup.roots[0].root self.conn.render = self.conn(xcb.render.key) self.conn.record = self.conn(xcb.record.key) self.conn.xtest = self.conn(xcb.xtest.key) self.catching = None
def _x_init(self): """initialize window with x server """ # connect to x server self._x_con = xcb.connect() # get the current x server root setup self._x_root = self._x_con.get_setup().roots[0] # generate x ids for our window and xcb graphics context self._window = self._x_con.generate_id() self._xgc = self._x_con.generate_id() # create a new window self._x_con.core.CreateWindow( self._x_root.root_depth, self._window, self._x_root.root, # parent is the root window 0, 0, self._sish[1], # width self._sish[0], # height 0, WindowClass.InputOutput, self._x_root.root_visual, CW.BackPixel | CW.EventMask, [ self._x_root.white_pixel, # request events here EventMask.PointerMotion | EventMask.ButtonPress | EventMask.ButtonRelease #| EventMask.KeyPress # heks key model is instant on release | EventMask.KeyRelease | EventMask.Exposure | EventMask.StructureNotify # get resize events? #| EventMask.ResizeRedirect ]) # simple xcb graphics context for copying the pixmap buffer to window self._x_con.core.CreateGC( self._xgc, self._x_root.root, GC.Foreground | GC.Background, [ self._x_root.black_pixel, self._x_root.white_pixel ]) # set the window ti_tl self._sfek_ti_tl(self._ti_tl) # generate drawing buffer and surface and draw contents of window self._rii_sr_ffes(*self._sish) # map the window on the screen so it is actually displayed self._x_con.core.MapWindow(self._window) # flush requests to x server self._x_con.flush()
def __init__(self): self.conn = xcb.connect() self.logger = logging.getLogger(__name__) try: self.conn.render = self.conn(xcb.render.key) except xcb.ExtensionException as e: print e self.logger.exception("Server has no XRender extension.") exit(2) self.setup = self.conn.get_setup() self.root = self.setup.roots[0]
def __init__(self, mods=None, key=None, action=None, args=None): self.mods = mods self.key = key self.action = action if args is None: self.args = [] else: self.args = args # TODO: this could cause problems when we get a bunch of conns open. # Refactor. self._keysyms = keysyms.Keysyms(xcb.connect()) self._keycode = None self._modmask = None
def setUp(self, screen=None, start_wm=True, **kwargs): self.conn = xcb.connect() self.xtest = self.conn(xcb.xtest.key) if screen is None: screen = self.conn.pref_screen self.screen = self.conn.get_setup().roots[screen] self.atoms = AtomCache(self.conn) self.modmap = ModifierMap(self.conn) self.keymap = KeyboardMap(self.conn, None, self.modmap) self.buttons = PointerMap(self.conn) self.clients = [] self.wm_thread = WindowManagerThread(self.wm_class, screen=screen, **kwargs) if start_wm: self.wm_thread.start()
def main(): conn = xcb.connect() conn.randr = conn(xcb.randr.key) setup = conn.get_setup() root = setup.roots[0].root print "XRRSelectInput" conn.randr.SelectInput(root, RRScreenChangeNotifyMask) # as seen in http://www.mail-archive.com/[email protected]/msg03630.html conn.flush() while True: e = conn.wait_for_event() print e, vars(e)
def __init__(self): self.xserver = xcb.connect() self.xclient = self.xserver.core self.setup = self.xserver.get_setup() self.canvas = self.setup.roots[0] self.root_window = self.canvas.root self.depth = self.setup.roots[0].root_depth self.visual = self.setup.roots[0].root_visual print('Desktop size and depth') root_window_info = self.xclient.GetGeometry(self.root_window).reply() print(root_window_info.width, root_window_info.height, root_window_info.depth) self.extension_xinerama() self.extension_randr()
def set_X_window_properties(win_id, **properties): ' Set X Window properties on the window with the specified id. Only string values are supported. ' import xcb, xcb.xproto conn = xcb.connect() atoms = {name:conn.core.InternAtom(False, len(name), name) for name in properties} utf8_string_atom = None for name, val in iteritems(properties): atom = atoms[name].reply().atom type_atom = xcb.xproto.Atom.STRING if isinstance(val, unicode_type): if utf8_string_atom is None: utf8_string_atom = conn.core.InternAtom(True, len(b'UTF8_STRING'), b'UTF8_STRING').reply().atom type_atom = utf8_string_atom val = val.encode('utf-8') conn.core.ChangePropertyChecked(xcb.xproto.PropMode.Replace, win_id, atom, type_atom, 8, len(val), val) conn.flush() conn.disconnect()
def main(): conn = xcb.connect() conn.randr = conn(xcb.randr.key) setup = conn.get_setup() root = setup.roots[0].root print "XRRSelectInput" conn.randr.SelectInput( root, RRScreenChangeNotifyMask ) # as seen in http://www.mail-archive.com/[email protected]/msg03630.html conn.flush() while True: e = conn.wait_for_event() print e, vars(e)
def xcb_fetch_windows(): """ Returns an array of rects of currently visible windows. """ x = xcb.connect() root = x.get_setup().roots[0].root rects = [] # iterate through top-level windows for child in x.core.QueryTree(root).reply().children: # make sure we only consider windows that are actually visible attributes = x.core.GetWindowAttributes(child).reply() if attributes.map_state != XCB_MAP_STATE_VIEWABLE: continue rects += [x.core.GetGeometry(child).reply()] return rects
def __init__(self, config): self.config = config self.conn = xcb.connect() self.setup = self.conn.get_setup() self.window = self.conn.generate_id() self.pixmap = self.conn.generate_id() self.gc = self.conn.generate_id() self.cache = AtomCache(self.conn) self.conn.core.CreateWindow(self.setup.roots[0].root_depth, self.window, self.setup.roots[0].root, 0, 0, self.setup.roots[0].width_in_pixels, self.config.height, 0, xproto.WindowClass.InputOutput, self.setup.roots[0].root_visual, xproto.CW.BackPixel | xproto.CW.EventMask, [self.setup.roots[0].white_pixel, xproto.EventMask.ButtonPress | xproto.EventMask.EnterWindow | xproto.EventMask.LeaveWindow | xproto.EventMask.Exposure]) self.conn.core.CreatePixmap(self.setup.roots[0].root_depth, self.pixmap, self.setup.roots[0].root, self.setup.roots[0].width_in_pixels, self.config.height) self.conn.core.CreateGC(self.gc, self.setup.roots[0].root, xproto.GC.Foreground | xproto.GC.Background, [self.setup.roots[0].black_pixel, self.setup.roots[0].white_pixel]) self.surf = cairo.XCBSurface(self.conn, self.pixmap, self.setup.roots[0].allowed_depths[0].visuals[0], self.setup.roots[0].width_in_pixels, self.config.height) self.winAttr = self.conn.core.GetGeometry(self.window).reply() self.setEMWH() self.setupCairo() self.setupPangoCairo() self.conn.core.MapWindow(self.window) self.conn.flush()
def main(): conn = xcb.connect() conn.render = conn(xcb.render.key) setup = conn.get_setup() root = setup.roots[0].root depth = setup.roots[0].root_depth visual = setup.roots[0].root_visual white = setup.roots[0].white_pixel window = conn.generate_id() conn.core.CreateWindow(depth, window, root, 0, 0, 640, 480, 0, WindowClass.InputOutput, visual, CW.BackPixel | CW.EventMask, [ white, EventMask.Exposure | EventMask.KeyPress ]) conn.core.MapWindow(window) conn.flush() while True: event = conn.wait_for_event() if isinstance(event, ExposeEvent): color = (0, 0, 65535, 65535) rectangle = (20, 20, 40, 40) # TODO, fixme: # I haven't been able to find what I should put for the parameter "op" # conn.render.FillRectangles(op, window, color, 1, rectangle) conn.flush() elif isinstance(event, KeyPressEvent): break conn.disconnect()
def setUp(self): self.conn = xcb.connect() self.modmap = ModifierMap(self.conn) self.keymap = KeyboardMap(self.conn, modmap=self.modmap)
def __init__(self): conn = xcb.connect(display=os.environ['DISPLAY']) self.wm = WindowManager(conn) self.cmd = CommandDispatcher(self.wm) self.evd = EventDispatcher(self.wm)
#!/usr/bin/python # -*- coding: utf-8 -*- import xcb from xcb.xproto import * import xcb.randr from displaysettings.device import Output try: conn = xcb.connect() conn.randr = conn(xcb.randr.key) except xcb.ExtensionException: conn.randr = None class Interface: def __init__(self, window=None): self.ready = conn.randr is not None if window is None: self.window = conn.get_setup().roots[0].root else: self.window = window def query(self): cookie = conn.randr.GetScreenResources(self.window) self.resources = cookie.reply() def queryCurrent(self): cookie = conn.randr.GetScreenResourcesCurrent(self.window) self.resources = cookie.reply()
def wm_setup(display=':0'): conn = xcb.connect(display=display) winman = wm.WindowManager(conn) winman.start_managing() return winman
def setUp(self): self.conn = xcb.connect()
def reconnect(): global conn conn = xcb.connect()
import xcb import xcb.xproto authname = "MIT-MAGIC-COOKIE-1" authdata = "\xa5\xcf\x95\xfa\x19\x49\x03\x60\xaf\xe4\x1e\xcd\xa3\xe2\xad\x47" authstr = authname + ':' + authdata conn = xcb.connect(display=":0",auth=authstr) print conn.get_setup().roots[0].root
width = screen.width_in_pixels height = screen.height_in_pixels root = screen.root # GetImage requires an output format as the first arg. We want ZPixmap: output_format = xcb.xproto.ImageFormat.ZPixmap plane_mask = 2**32 - 1 # No idea what this is but it works! reply = conn.core.GetImage(output_format, root, 0, 0, width, height, plane_mask).reply() # The reply contains the image data in ZPixmap format. We need to convert # it into something PIL can use: image_data = reply.data.buf() im = Image.frombuffer("RGBX", (width, height), image_data, "raw", "BGRX").convert("RGB") with open(path, 'w') as f: im.save(f, format='png') if __name__ == "__main__": x11_display = os.environ['DISPLAY'] print("Taking screenshot...") try: conn = xcb.connect(display=x11_display) xcb_screenshot_full(conn) except Exception as e: print("Got an exception trying to take a screenshot!") print("This might be helpful:") print(e) import traceback traceback.print_exc(file=sys.stdout) sys.exit(1) sys.exit(0)
parser = optparse.OptionParser() parser.add_option("-d", "--directory", dest="directory", default=".", help="search for images in DIRECTORY", metavar="DIRECTORY") parser.add_option("-t", "--target", dest="target", default="background.jpg", help="write background to FILE", metavar="FILE") parser.add_option("-c", "--crop", dest="crop", action="store_true", help="crop image instead of centering them") options, args = parser.parse_args() assert not args, "No additional arguments are accepted" background = None # Get display size display = xcb.connect() root = display.get_setup().roots[0] background = Image.new('RGB', (root.width_in_pixels, root.height_in_pixels)) # Query xinerama (not randr since the query is longer) try: xinerama = display(xcb.xinerama.key) except xcb.ExtensionException: xinerama = None if not xinerama or not xinerama.IsActive().reply().state: screens = [(background.size[0], background.size[1], 0, 0)] else: screens = [(screen.width, screen.height, screen.x_org, screen.y_org) for screen in xinerama.QueryScreens().reply().screen_info] screens.sort(key=lambda screen: -screen[0]*screen[1])
#!/usr/bin/env python # -*- coding: utf-8 -*- import xcb from xcb.xproto import * import xcb.randr from displaysettings.device import Output try: conn = xcb.connect() conn.randr = conn(xcb.randr.key) except xcb.ExtensionException: conn.randr = None class Interface: def __init__(self, window=None): self.ready = conn.randr is not None if window is None: self.window = conn.get_setup().roots[0].root else: self.window = window def query(self): cookie = conn.randr.GetScreenResources(self.window) self.resources = cookie.reply() def queryCurrent(self): cookie = conn.randr.GetScreenResourcesCurrent(self.window)
def __init__(self, name): self.name = name self.conn = xcb.connect() self.xdpyinfo()
def setUp(self): self.conn = xcb.connect() self.atoms = AtomCache(self.conn)
def setUp(self): conn = xcb.connect() cmap = conn.get_setup().roots[conn.pref_screen].default_colormap self.color_cache = ColorCache(conn, cmap)