Пример #1
0
 def run_qtile():
     llvl = logging.DEBUG if pytest.config.getoption("--debuglog") else logging.INFO
     kore = xcore.XCore()
     try:
         init_log(llvl, log_path=None, log_color=False)
         q = QtileManager(kore, config_class(), self.display, self.sockfile)
         q.loop()
     except Exception:
         wpipe.send(traceback.format_exc())
Пример #2
0
    def create_manager(self, config_class):
        """Create a Qtile manager instance in this thread

        This should only be used when it is known that the manager will throw
        an error and the returned manager should not be started, otherwise this
        will likely block the thread.
        """
        init_log(self.log_level, log_path=None, log_color=False)
        kore = self.backend.create()
        config = config_class()
        for attr in dir(default_config):
            if not hasattr(config, attr):
                setattr(config, attr, getattr(default_config, attr))

        return Qtile(kore, config, socket_path=self.sockfile)
Пример #3
0
 def run_qtile():
     try:
         os.environ.pop("DISPLAY", None)
         os.environ.pop("WAYLAND_DISPLAY", None)
         kore = self.backend.create()
         os.environ.update(self.backend.env)
         init_log(self.log_level, log_path=None, log_color=False)
         Qtile(
             kore,
             config_class(),
             socket_path=self.sockfile,
             no_spawn=no_spawn,
         ).loop()
     except Exception:
         wpipe.send(traceback.format_exc())
Пример #4
0
 def run_qtile():
     try:
         os.environ.pop("DISPLAY", None)
         os.environ.pop("WAYLAND_DISPLAY", None)
         kore = self.backend.create()
         os.environ.update(self.backend.env)
         logger = init_log(self.log_level, log_path=None, log_color=False)
         if hasattr(self, "log_queue"):
             logger.addHandler(logging.handlers.QueueHandler(self.log_queue))
         Qtile(
             kore,
             config_class(),
             socket_path=self.sockfile,
             no_spawn=no_spawn,
             state=state,
         ).loop()
     except Exception:
         wpipe.send(traceback.format_exc())
Пример #5
0
class SessionManager:
    def __init__(
        self,
        kore: base.Core,
        config,
        *,
        socket_path: str = None,
        no_spawn=False,
        state=None,
    ) -> None:
        """Manages a qtile session

        :param kore:
            The core backend to use for the session.
        :param config:
            The configuration to use for the qtile instance.
        :param socket_path:
            The file name to use as the qtile socket file.
        :param no_spawn:
            If the instance has already been started, then don't re-run the
            startup once hook.
        :param state:
            The state to restart the qtile instance with.
        """
        lifecycle.behavior = lifecycle.behavior.TERMINATE

        self.qtile = Qtile(kore, config, no_spawn=no_spawn, state=state)
        self.server = ipc.Server(
            self._prepare_socket_path(socket_path),
            self.qtile.server.call,
        )

    def _prepare_socket_path(self, socket_path: Optional[str] = None) -> str:
        if socket_path is None:
            # Dots might appear in the host part of the display name
            # during remote X sessions. Let's strip the host part first
            display_name = self.qtile.core.display_name
            display_number = display_name.partition(":")[2]
            if "." not in display_number:
                display_name += ".0"
            socket_path = ipc.find_sockfile(display_name)

        if os.path.exists(socket_path):
            os.unlink(socket_path)

        return socket_path

    def _restart(self):
        lifecycle.behavior = lifecycle.behavior.RESTART
        state_file = os.path.join(tempfile.gettempdir(), 'qtile-state')
        with open(state_file, 'wb') as f:
            self.qtile.dump_state(f)
        lifecycle.state_file = state_file

    def loop(self) -> None:
        try:
            asyncio.run(self.async_loop())
        finally:
            if self.qtile.should_restart:
                self._restart()

    async def async_loop(self) -> None:
        async with QtileLoop(self.qtile), self.server:
            await self.qtile.async_loop()
Пример #6
0
def focus_smart(qtile: Qtile, key):
    if key is None or qtile.current_screen is None:
        return

    win = qtile.current_window
    if win is None:
        x, y = qtile.current_screen.x, qtile.current_screen.y
    else:
        x, y = win.info()["x"], win.info()["y"]

    screens = qtile.screens
    candidates = []
    candidates_screens = get_candidates_screens(qtile, x, y, key)
    screens_helper = []
    for screen in screens:
        group = screen.group
        if group is None or screen.x is None or screen.y is None:
            continue
        layout = group.layout
        clients = list(layout.clients)

        if group.floating_layout is not None:
            for client in group.floating_layout.clients:
                if client.info()["name"] == "Kodi":
                    continue
                if client.fullscreen and int(
                        client.info()["group"][-1]) == screen.index:
                    clients = [client]
                    break
            else:
                clients.extend([
                    c for c in list(group.floating_layout.clients)
                    if int(c.info()["group"][-1]) == screen.index
                ])

        for c in clients:
            if c.info()["name"] == "Kodi":
                continue
            if key == "h":
                if c.info()["x"] < x:
                    candidates.append(c)
                    screens_helper.append(screen)
            elif key == "j":
                if c.info()["y"] > y:
                    candidates.append(c)
                    screens_helper.append(screen)
            elif key == "k":
                if c.info()["y"] < y:
                    candidates.append(c)
                    screens_helper.append(screen)
            elif key == "l":
                if c.info()["x"] > x:
                    candidates.append(c)
                    screens_helper.append(screen)

    selected_idx, selected = get_closest(x, y, candidates)
    if selected is None or selected_idx is None:
        screen = closest_screen(x, y, candidates_screens)
        if screen is not None:
            qtile.focus_screen(screen.index, warp=False)
        return

    selected_screen = screens_helper[selected_idx]
    qtile.focus_screen(selected_screen.index)
    selected_screen.group.focus(selected)