Ejemplo n.º 1
0
def get_core(backend, *args):
    if backend not in CORES:
        raise QtileError(f"Backend {backend} does not exist")

    return importlib.import_module(f"libqtile.backend.{backend}.core").Core(
        *args)
Ejemplo n.º 2
0
    def __init__(self, display_name: str = None) -> None:
        """Setup the X11 core backend

        :param display_name:
            The display name to setup the X11 connection to.  Uses the DISPLAY
            environment variable if not given.
        """
        if display_name is None:
            display_name = os.environ.get("DISPLAY")
            if not display_name:
                raise QtileError("No DISPLAY set")

        self.conn = xcbq.Connection(display_name)
        self._display_name = display_name

        # Because we only do Xinerama multi-screening,
        # we can assume that the first
        # screen's root is _the_ root.
        self._root = self.conn.default_screen.root
        self._root.set_attribute(
            eventmask=(xcffib.xproto.EventMask.StructureNotify
                       | xcffib.xproto.EventMask.SubstructureNotify
                       | xcffib.xproto.EventMask.SubstructureRedirect
                       | xcffib.xproto.EventMask.EnterWindow
                       | xcffib.xproto.EventMask.LeaveWindow))

        self._root.set_property(
            "_NET_SUPPORTED",
            [self.conn.atoms[x] for x in xcbq.SUPPORTED_ATOMS])

        self._last_event_timestamp = xcffib.CurrentTime

        self._wmname = "qtile"
        self._supporting_wm_check_window = self.conn.create_window(
            -1, -1, 1, 1)
        self._supporting_wm_check_window.set_property("_NET_WM_NAME",
                                                      self._wmname)
        self._supporting_wm_check_window.set_property(
            "_NET_SUPPORTING_WM_CHECK", self._supporting_wm_check_window.wid)
        self._root.set_property("_NET_SUPPORTING_WM_CHECK",
                                self._supporting_wm_check_window.wid)

        self._selection = {
            "PRIMARY": {
                "owner": None,
                "selection": ""
            },
            "CLIPBOARD": {
                "owner": None,
                "selection": ""
            },
        }
        self._selection_window = self.conn.create_window(-1, -1, 1, 1)
        self._selection_window.set_attribute(
            eventmask=xcffib.xproto.EventMask.PropertyChange)
        self.conn.xfixes.select_selection_input(self._selection_window,
                                                "PRIMARY")
        self.conn.xfixes.select_selection_input(self._selection_window,
                                                "CLIPBOARD")

        primary_atom = self.conn.atoms["PRIMARY"]
        reply = self.conn.conn.core.GetSelectionOwner(primary_atom).reply()
        self._selection["PRIMARY"]["owner"] = reply.owner

        clipboard_atom = self.conn.atoms["CLIPBOARD"]
        reply = self.conn.conn.core.GetSelectionOwner(primary_atom).reply()
        self._selection["CLIPBOARD"]["owner"] = reply.owner

        # ask for selection on start-up
        self.convert_selection(primary_atom)
        self.convert_selection(clipboard_atom)

        # setup the default cursor
        self._root.set_cursor("left_ptr")

        self.qtile = None  # type: Optional[Qtile]
        self._painter = None

        numlock_code = self.conn.keysym_to_keycode(xcbq.keysyms["Num_Lock"])
        self._numlock_mask = xcbq.ModMasks.get(
            self.conn.get_modifier(numlock_code), 0)
        self._valid_mask = ~(self._numlock_mask | xcbq.ModMasks["lock"])
Ejemplo n.º 3
0
    def __init__(self, display_name: str = None) -> None:
        """Setup the X11 core backend

        :param display_name:
            The display name to setup the X11 connection to.  Uses the DISPLAY
            environment variable if not given.
        """
        if display_name is None:
            display_name = os.environ.get("DISPLAY")
            if not display_name:
                raise QtileError("No DISPLAY set")

        self.conn = xcbq.Connection(display_name)
        self._display_name = display_name

        # Because we only do Xinerama multi-screening,
        # we can assume that the first
        # screen's root is _the_ root.
        self._root = self.conn.default_screen.root

        supporting_wm_wid = self._root.get_property("_NET_SUPPORTING_WM_CHECK",
                                                    "WINDOW",
                                                    unpack=int)
        if len(supporting_wm_wid) > 0:
            supporting_wm_wid = supporting_wm_wid[0]

            supporting_wm = window.XWindow(self.conn, supporting_wm_wid)
            existing_wmname = supporting_wm.get_property("_NET_WM_NAME",
                                                         "UTF8_STRING",
                                                         unpack=str)
            if existing_wmname:
                logger.error("not starting; existing window manager {}".format(
                    existing_wmname))
                raise ExistingWMException(existing_wmname)

        self.eventmask = (EventMask.StructureNotify
                          | EventMask.SubstructureNotify
                          | EventMask.SubstructureRedirect
                          | EventMask.EnterWindow
                          | EventMask.LeaveWindow
                          | EventMask.ButtonPress)
        self._root.set_attribute(eventmask=self.eventmask)

        self._root.set_property(
            "_NET_SUPPORTED",
            [self.conn.atoms[x] for x in xcbq.SUPPORTED_ATOMS])

        self._wmname = "qtile"
        self._supporting_wm_check_window = self.conn.create_window(
            -1, -1, 1, 1)
        self._supporting_wm_check_window.set_property("_NET_WM_NAME",
                                                      self._wmname)
        self._supporting_wm_check_window.set_property(
            "_NET_SUPPORTING_WM_CHECK", self._supporting_wm_check_window.wid)
        self._root.set_property("_NET_SUPPORTING_WM_CHECK",
                                self._supporting_wm_check_window.wid)

        self._selection = {
            "PRIMARY": {
                "owner": None,
                "selection": ""
            },
            "CLIPBOARD": {
                "owner": None,
                "selection": ""
            },
        }
        self._selection_window = self.conn.create_window(-1, -1, 1, 1)
        self._selection_window.set_attribute(
            eventmask=EventMask.PropertyChange)
        if hasattr(self.conn, "xfixes"):
            self.conn.xfixes.select_selection_input(self._selection_window,
                                                    "PRIMARY")  # type: ignore
            self.conn.xfixes.select_selection_input(
                self._selection_window, "CLIPBOARD")  # type: ignore

        primary_atom = self.conn.atoms["PRIMARY"]
        reply = self.conn.conn.core.GetSelectionOwner(primary_atom).reply()
        self._selection["PRIMARY"]["owner"] = reply.owner

        clipboard_atom = self.conn.atoms["CLIPBOARD"]
        reply = self.conn.conn.core.GetSelectionOwner(primary_atom).reply()
        self._selection["CLIPBOARD"]["owner"] = reply.owner

        # ask for selection on start-up
        self.convert_selection(primary_atom)
        self.convert_selection(clipboard_atom)

        # setup the default cursor
        self._root.set_cursor("left_ptr")

        self.qtile = None  # type: Optional[Qtile]
        self._painter = None

        numlock_code = self.conn.keysym_to_keycode(xcbq.keysyms["Num_Lock"])[0]
        self._numlock_mask = xcbq.ModMasks.get(
            self.conn.get_modifier(numlock_code), 0)
        self._valid_mask = ~(self._numlock_mask | xcbq.ModMasks["lock"]
                             | xcbq.AllButtonsMask)