How to use the xcffib.connect function in xcffib

To help you get started, we’ve selected a few xcffib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qtile / qtile / test / scripts / window.py View on Github external
import xcffib.xproto


def configure(window):
    window.configure(
        width=100,
        height=100,
        x=0,
        y=0,
        border_width=1,
    )


for i in range(20):
    try:
        conn = xcffib.connect(display=sys.argv[1])
    except xcffib.ConnectionException:
        time.sleep(0.1)
        continue
    except Exception as v:
        print("Error opening test window: ", type(v), v, file=sys.stderr)
        sys.exit(1)
    break
else:
    print("Could not open window on display %s" % (sys.argv[1]), file=sys.stderr)
    sys.exit(1)

screen = conn.get_setup().roots[conn.pref_screen]

window = conn.generate_id()
background = conn.core.AllocColor(screen.default_colormap, 0x2828, 0x8383, 0xCECE).reply().pixel  # Color "#2883ce"
conn.core.CreateWindow(xcffib.CopyFromParent, window, screen.root,
github qtile / qtile / test / utils.py View on Github external
def _waitForXephyr(self):
        # Wait until Xephyr process dies
        while self.xephyr.poll() is None:
            try:
                conn = xcffib.connect(self.display)
                break
            except xcffib.ConnectionException:
                pass
            time.sleep(0.1)
        else:
            (stdout_data, stderr_data) = self.xephyr.communicate()
            raise AssertionError("Error launching Xephyr, quit with return code: {:d}\n"
                                 "stderr: {}\n"
                                 "stdout: {}".format(
                                     self.xephyr.returncode,
                                     stderr_data.decode(),
                                     stdout_data.decode()
                                 )
            )

        conn.disconnect()
github ssokolow / quicktile / test_functional.py View on Github external
# Launch the X server
    argv += [':%d' % display_num]
    if verbose:
        xproc = subprocess.Popen(argv)
    else:
        with open(os.devnull, 'w') as devnull:
            xproc = subprocess.Popen(argv,
                                     stderr=subprocess.STDOUT, stdout=devnull)

    # Wait for the process to die, start accepting connections, or for
    # 5 seconds to pass
    # TODO: Refactor to be cleaner
    started = time.time()
    while xproc.poll() is None and (time.time() - started < 5):
        try:
            conn = xcffib.connect(display=':%d' % display_num,
                                  auth=b'MIT-MAGIC-COOKIE-1:' + magic_cookie)
        except xcffib.ConnectionException:
            time.sleep(0.1)  # Limit spinning when the server is slow to start
            continue
        else:
            if not xproc.poll():
                conn.disconnect()
                log.debug("X server on :%d accepting connections", display_num)
                return xproc

    if (time.time() - started) > 5:
        log.warning("Timed out while waiting for X server")
        if xproc.poll() is None:
            return xproc

    if xproc.returncode == 1 and os.path.exists(lock_path):
github asrp / guitktk / xcb_doc.py View on Github external
def __init__(self, width, height):
        self.width = width
        self.height = height
        self.connection = xcb.connect()
        self.xsetup = self.connection.get_setup()
        self.window = self.connection.generate_id()
        self.pixmap = self.connection.generate_id()
        self.gc = self.connection.generate_id()
        events = [self.xsetup.roots[0].white_pixel,
                  EventMask.ButtonPress | EventMask.ButtonRelease | EventMask.EnterWindow | EventMask.LeaveWindow | EventMask.Exposure | EventMask.PointerMotion | EventMask.ButtonMotion | EventMask.KeyPress | EventMask.KeyRelease]
        self.connection.core.CreateWindow(self.xsetup.roots[0].root_depth,
                                          self.window,
                                          # Parent is the root window
                                          self.xsetup.roots[0].root,
                                          0, 0, self.width, self.height,
                                          0, WindowClass.InputOutput,
                                          self.xsetup.roots[0].root_visual,
                                          CW.BackPixel | CW.EventMask,
                                          events)
github qtile / qtile / libqtile / backend / x11 / xcbq.py View on Github external
def __init__(self, display):
        self.conn = xcffib.connect(display=display)
        self._connected = True
        self.cursors = Cursors(self)
        self.setup = self.conn.get_setup()
        extensions = self.extensions()
        self.screens = [Screen(self, i) for i in self.setup.roots]
        self.default_screen = self.screens[self.conn.pref_screen]

        self.xfixes = XFixes(self)
        for i in extensions:
            if i in self._extmap:
                setattr(self, i, self._extmap[i](self))

        self.pseudoscreens = []
        if "xinerama" in extensions:
            for i, s in enumerate(self.xinerama.query_screens()):
                scr = PseudoScreen(
github rbn42 / freetile / freetile / helper / xcb.py View on Github external
import os

import xcffib
from xcffib.testing import XvfbTest
from xcffib.xproto import Atom, ConfigWindow, EventMask, GetPropertyType

conn = xcffib.connect(os.environ['DISPLAY'])
xproto = xcffib.xproto.xprotoExtension(conn)


def arrange(layout, windowids):
    for lay, winid in zip(layout, windowids):
        xproto.ConfigureWindow(winid, ConfigWindow.X | ConfigWindow.Y | ConfigWindow.Width | ConfigWindow.Height, lay)
    conn.flush()


def move(winid, x, y, sync=True):
    xproto.ConfigureWindow(winid, ConfigWindow.X | ConfigWindow.Y, [x, y])
    if sync:
        conn.flush()
github QubesOS / qubes-core-admin-client / qubesadmin / tools / qvm_start_gui.py View on Github external
loop = asyncio.get_event_loop()
            # pylint: disable=no-member
            events = qubesadmin.events.EventsDispatcher(args.app)
            # pylint: enable=no-member
            launcher.register_events(events)

            events_listener = asyncio.ensure_future(events.listen_for_events())

            for signame in ('SIGINT', 'SIGTERM'):
                loop.add_signal_handler(getattr(signal, signame),
                    events_listener.cancel)  # pylint: disable=no-member

            loop.add_signal_handler(signal.SIGHUP,
                launcher.send_monitor_layout_all)

            conn = xcffib.connect()
            x_fd = conn.get_file_descriptor()
            loop.add_reader(x_fd, x_reader, conn, events_listener.cancel)

            try:
                loop.run_until_complete(events_listener)
            except asyncio.CancelledError:
                pass
            loop.remove_reader(x_fd)
            loop.stop()
            loop.run_forever()
            loop.close()
    elif args.notify_monitor_layout:
        try:
            with open(pidfile_path, 'r') as pidfile:
                pid = int(pidfile.read().strip())
            os.kill(pid, signal.SIGHUP)