コード例 #1
0
ファイル: core.py プロジェクト: dpiegdon/qtile
    def focus_window(self, win: window.WindowType, surface: Surface = None):
        if self.seat.destroyed:
            return

        if surface is None and win is not None:
            surface = win.surface.surface

        previous_surface = self.seat.keyboard_state.focused_surface
        if previous_surface == surface:
            return

        if previous_surface is not None and previous_surface.is_xdg_surface:
            # Deactivate the previously focused surface
            previous_xdg_surface = XdgSurface.from_surface(previous_surface)
            previous_xdg_surface.set_activated(False)

        if not win:
            self.seat.keyboard_clear_focus()
            return

        if isinstance(win.surface, LayerSurfaceV1):
            if not win.surface.current.keyboard_interactive:
                return

        logger.debug("Focussing new window")
        if surface.is_xdg_surface and isinstance(win.surface, XdgSurface):
            win.surface.set_activated(True)
        self.seat.keyboard_notify_enter(surface, self.seat.keyboard)
コード例 #2
0
ファイル: core.py プロジェクト: lkjell/qtile
    def focus_window(
        self, win: window.WindowType, surface: Surface = None, enter: bool = True
    ) -> None:
        if self.seat.destroyed:
            return

        if surface is None and win is not None:
            if isinstance(win, base.Internal):
                self.focused_internal = win
                self.seat.keyboard_clear_focus()
                return
            surface = win.surface.surface

        if self.focused_internal:
            self.focused_internal = None

        if isinstance(win.surface, LayerSurfaceV1):
            if not win.surface.current.keyboard_interactive:
                return

        if isinstance(win.surface, xwayland.Surface):
            if not win.surface.or_surface_wants_focus():
                return

        previous_surface = self.seat.keyboard_state.focused_surface
        if previous_surface == surface:
            return

        if previous_surface is not None:
            # Deactivate the previously focused surface
            if previous_surface.is_xdg_surface:
                previous_xdg_surface = XdgSurface.from_surface(previous_surface)
                if not win or win.surface != previous_xdg_surface:
                    previous_xdg_surface.set_activated(False)
                    if previous_xdg_surface.data:
                        previous_xdg_surface.data.set_activated(False)

            elif previous_surface.is_xwayland_surface:
                prev_xwayland_surface = xwayland.Surface.from_wlr_surface(previous_surface)
                if not win or win.surface != prev_xwayland_surface:
                    prev_xwayland_surface.activate(False)
                    if prev_xwayland_surface.data:
                        prev_xwayland_surface.data.set_activated(False)

        if not win:
            self.seat.keyboard_clear_focus()
            return

        logger.debug("Focussing new window")
        if surface.is_xdg_surface and isinstance(win.surface, XdgSurface):
            win.surface.set_activated(True)
            win.ftm_handle.set_activated(True)

        elif surface.is_xwayland_surface and isinstance(win.surface, xwayland.Surface):
            win.surface.activate(True)
            win.ftm_handle.set_activated(True)

        if enter and self.seat.keyboard._ptr:  # This pointer is NULL when headless
            self.seat.keyboard_notify_enter(surface, self.seat.keyboard)
コード例 #3
0
ファイル: server.py プロジェクト: flacjacket/pywlroots
    def server_new_xdg_surface(self, listener, xdg_surface: XdgSurface) -> None:
        logger.info("new surface")

        if xdg_surface.role == XdgSurfaceRole.POPUP:
            # We must add xdg popups to the scene graph so they get rendered.
            # The wlroots scene graph provides a helper for this, but to use it
            # we must provide the proper parent scene node of the xdg popup. To
            # enable this, we always set the user data field of xdg_surfaces to
            # the corresponding scene node.
            parent_xdg_surface = XdgSurface.from_surface(xdg_surface.popup.parent)
            parent_scene_node = cast(SceneNode, parent_xdg_surface.data)
            scene_node = SceneNode.xdg_surface_create(parent_scene_node, xdg_surface)
            xdg_surface.data = scene_node
            return

        assert xdg_surface.role == XdgSurfaceRole.TOPLEVEL

        scene_node = SceneNode.xdg_surface_create(self._scene.node, xdg_surface)
        view = View(xdg_surface, self, scene_node)
        self.views.append(view)
コード例 #4
0
    def focus_view(self,
                   view: View,
                   surface: Optional[Surface] = None) -> None:
        """Focus a given XDG surface

        Moves the surface to the front of the list for rendering.  Sets the
        surface to receive keyboard events.
        """
        logging.info("focus surface")
        if surface is None:
            surface = view.xdg_surface.surface

        previous_surface = self._seat.keyboard_state.focused_surface
        if previous_surface == surface:
            # Don't re-focus an already focused surface
            logging.info("Focus unchanged, exiting")
            return

        if previous_surface is not None:
            # Deactivate the previously focused surface
            logging.info("Un-focusing previous")
            previous_xdg_surface = XdgSurface.from_surface(previous_surface)
            previous_xdg_surface.set_activated(False)

        # roll the given surface to the front of the list, copy and modify the
        # list, then save back to prevent any race conditions on list
        # modification
        views = self.views[:]
        views.remove(view)
        views.append(view)
        self.views = views
        # activate the new surface
        view.xdg_surface.set_activated(True)

        # Tell the seat to have the keyboard enter this surface. wlroots will
        # keep track of this and automatically send key events to the
        # appropriate clients without additional work on your part.
        keyboard = self._seat.keyboard
        self._seat.keyboard_notify_enter(view.xdg_surface.surface, keyboard)