Example #1
0
 def effective_resolution(self) -> Tuple[int, int]:
     """Computes the transformed and scaled output resolution"""
     width_ptr = ffi.new("int *")
     height_ptr = ffi.new("int *")
     lib.wlr_output_effective_resolution(self._ptr, width_ptr, height_ptr)
     width = width_ptr[0]
     height = height_ptr[0]
     return width, height
Example #2
0
    def output_coords(self, output: Output) -> tuple[float, float]:
        """Determine coordinates of the output in the layout

        Given x and y in layout coordinates, adjusts them to local output
        coordinates relative to the given reference output.
        """
        ox = ffi.new("double *")
        oy = ffi.new("double *")
        lib.wlr_output_layout_output_coords(self._ptr, output._ptr, ox, oy)

        return ox[0], oy[0]
Example #3
0
def test_ptr():
    ptr1 = ffi.new("struct wlr_box *")
    ptr2 = ffi.new("struct wlr_box *")

    box1 = PtrT(ptr1)
    box2 = PtrT(ptr1)

    assert box1 == box2
    assert hash(box1) != hash(box2)

    box1 = PtrT(ptr1)
    box2 = PtrT(ptr2)

    assert box1 != box2
    assert hash(box1) != hash(box2)
Example #4
0
    def surface_at(self, surface_x: float,
                   surface_y: float) -> Tuple[Optional[Surface], float, float]:
        """Find a surface within this xdg-surface tree at the given surface-local coordinates

        Returns the surface and coordinates in the leaf surface coordinate
        system or None if no surface is found at that location.
        """
        sub_x_data = ffi.new("double*")
        sub_y_data = ffi.new("double*")
        surface_ptr = lib.wlr_layer_surface_v1_surface_at(
            self._ptr, surface_x, surface_y, sub_x_data, sub_y_data)
        if surface_ptr == ffi.NULL:
            return None, 0.0, 0.0

        return Surface(surface_ptr), sub_x_data[0], sub_y_data[0]
Example #5
0
 def new(cls, lazy: bool, enable_wm: bool,
         no_touch_pointer_emulation: bool) -> ServerOptions:
     ptr = ffi.new("struct wlr_xwayland_server_options *")
     ptr.lazy = lazy
     ptr.enable_wm = enable_wm
     ptr.no_touch_pointer_emulation = no_touch_pointer_emulation
     return cls(ptr)
Example #6
0
 def get_monotonic_time(cls) -> Timespec:
     """Get the current monotonic time"""
     timespec = ffi.new("struct timespec *")
     ret = lib.clock_gettime(lib.CLOCK_MONOTONIC, timespec)
     if ret != 0:
         raise RuntimeError("Failed to get clock")
     return Timespec(timespec)
Example #7
0
 def __init__(self, x: int, y: int, width: int, height: int) -> None:
     """A simple box structure, represented by a coordinate and dimensions"""
     self._ptr = ffi.new("struct wlr_box *")
     self.x = x
     self.y = y
     self.width = width
     self.height = height
Example #8
0
    def closest_point(self,
                      lx: float,
                      ly: float,
                      reference: Output | None = None) -> tuple[float, float]:
        """
        Get the closest point on this layout from the given point from the reference
        output. If reference is NULL, gets the closest point from the entire layout.
        """
        if reference:
            reference_ptr = reference._ptr
        else:
            reference_ptr = ffi.NULL

        dest_lx = ffi.new("double *")
        dest_ly = ffi.new("double *")
        lib.wlr_output_layout_closest_point(self._ptr, reference_ptr, lx, ly,
                                            dest_lx, dest_ly)
        return dest_lx[0], dest_ly[0]
Example #9
0
def get_keysyms(xkb_state, keycode):
    syms_out = ffi.new("const xkb_keysym_t **")
    nsyms = lib.xkb_state_key_get_syms(xkb_state, keycode, syms_out)
    if nsyms > 0:
        assert syms_out[0] != ffi.NULL

    syms = [syms_out[0][i] for i in range(nsyms)]
    print(f"got {nsyms} syms: {syms}")
    return syms
Example #10
0
    def __init__(self, ptr=None) -> None:
        """This is a convenience wrapper around pixman_region32_t

        :param ptr:
            The pixman_region32_t cdata pointer
        """
        if ptr is None:
            self._ptr = ffi.new("struct pixman_region32 *")
        else:
            self._ptr = ptr
Example #11
0
    def get_geometry(self) -> Box:
        """Get the surface geometry

        This is either the geometry as set by the client, or defaulted to the
        bounds of the surface + the subsurfaces (as specified by the protocol).

        The x and y value can be <0
        """
        box_ptr = ffi.new("struct wlr_box *")
        lib.wlr_xdg_surface_get_geometry(self._ptr, box_ptr)
        return Box(box_ptr.x, box_ptr.y, box_ptr.width, box_ptr.height)
Example #12
0
    def set_cursor_image(self, name: str, cursor: Cursor):
        """Set the cursor image

        Set a Cursor image to the specified cursor name for all scale factors.
        The wlroots cursor will take over from this point and ensure the
        correct cursor is used on each output, assuming an output layout is
        attached to it.
        """
        name_cdata = ffi.new("char []", name.encode())
        lib.wlr_xcursor_manager_set_cursor_image(self._ptr, name_cdata,
                                                 cursor._ptr)
Example #13
0
    def rectangles_as_boxes(self) -> list[Box]:
        nrects_ptr = ffi.new("int *")
        rects = lib.pixman_region32_rectangles(self._ptr, nrects_ptr)
        nrects = nrects_ptr[0]

        boxes = []
        for i in range(nrects):
            boxes.append(
                Box(rects.x1, rects.y1, rects.x2 - rects.x1, rects.y2 - rects.y1)
            )
            rects += 1
        return boxes
Example #14
0
    def absolute_to_layout_coords(self, input_device: InputDevice | None,
                                  x: float, y: float) -> tuple[float, float]:
        """Convert absolute 0..1 coordinates to layout coordinates

        The `input_device` may be passed to respect device mapping constraints.
        If `input_device` is `None`, device mapping constraints will be
        ignored.
        """
        if input_device is None:
            input_device_ptr = ffi.NULL
        else:
            input_device_ptr = input_device._ptr

        xy_ptr = ffi.new("double[2]")
        lib.wlr_cursor_absolute_to_layout_coords(self._ptr, input_device_ptr,
                                                 x, y, xy_ptr, xy_ptr + 1)

        return xy_ptr[0], xy_ptr[1]
Example #15
0
    def __init__(
        self,
        x: int | None = None,
        y: int | None = None,
        width: int | None = None,
        height: int | None = None,
        ptr=None,
    ) -> None:
        """A simple box structure, represented by a coordinate and dimensions"""
        if ptr is None:
            self._ptr = ffi.new("struct wlr_box *")
        else:
            self._ptr = ptr

        if x is not None:
            self.x = x
        if y is not None:
            self.y = y
        if width is not None:
            self.width = width
        if height is not None:
            self.height = height
Example #16
0
    def attach_render(self, damage: PixmanRegion32) -> bool:
        """
        Attach the renderer's buffer to the output. Compositors must call this
        function before rendering. After they are done rendering, they should call
        `wlr_output_set_damage` and `wlr_output_commit` to submit the new frame.

        `needs_frame` will be set to true if a frame should be submitted. `damage`
        will be set to the region of the output that needs to be repainted, in
        output-buffer-local coordinates.

        The buffer damage region accumulates all damage since the buffer has last
        been swapped. This is not to be confused with the output surface damage,
        which only contains the changes between two frames.

        Returns a bool specifying whether the output needs a new frame rendered.
        """
        needs_frame_ptr = ffi.new("bool *")
        if not lib.wlr_output_damage_attach_render(self._ptr, needs_frame_ptr,
                                                   damage._ptr):
            raise RuntimeError("Rendering on output failed")

        return needs_frame_ptr[0]
Example #17
0
 def __init__(self, seat: Seat) -> None:
     """Setup the keyboard grab"""
     self._ptr = ffi.new("struct wlr_seat_keyboard_grab *")
     self._seat = seat
Example #18
0
 def closest_point(self, x: float, y: float) -> tuple[float, float]:
     xy_ptr = ffi.new("double[2]")
     lib.wlr_box_closest_point(self._ptr, x, y, xy_ptr, xy_ptr + 1)
     return xy_ptr[0], xy_ptr[1]
Example #19
0
def _rgb(color: ColorType) -> ffi.CData:
    """Helper to create and cache float[4] arrays for border painting"""
    if isinstance(color, ffi.CData):
        return color
    return ffi.new("float[4]", utils.rgb(color))
Example #20
0
 def clear(self, color) -> None:
     """Clear the renderer to the given RGBA color"""
     color_ptr = ffi.new("float[4]", color)
     lib.wlr_renderer_clear(self._ptr, color_ptr)
Example #21
0
 def clear(self, color: ColorType) -> None:
     """Clear the renderer to the given RGBA color"""
     if not isinstance(color, ffi.CData):
         color = ffi.new("float[4]", color)
     lib.wlr_renderer_clear(self._ptr, color)
Example #22
0
    libinput = None

if TYPE_CHECKING:
    from typing import Any

    from pywayland.server import Listener
    from wlroots.wlr_types import InputDevice
    from wlroots.wlr_types.keyboard import KeyboardKeyEvent

    from libqtile.backend.wayland.core import Core

KEY_PRESSED = WlKeyboard.key_state.pressed
KEY_RELEASED = WlKeyboard.key_state.released

# Keep this around instead of creating it on every key
xkb_keysym = ffi.new("const xkb_keysym_t **")


class InputConfig(configurable.Configurable):
    """
    This is used to configure input devices. An instance of this class represents one
    set of settings that can be applied to an input device.

    To use this, define a dictionary called ``wl_input_rules`` in your config. The keys
    are used to match input devices, and the values are instances of this class with the
    desired settings. For example:

    .. code-block:: python

        from libqtile.backend.wayland import InputConfig
Example #23
0
 def render_rect(self, box: Box, color: ColorType,
                 projection: Matrix) -> None:
     """Renders a solid rectangle in the specified color."""
     if not isinstance(color, ffi.CData):
         color = ffi.new("float[4]", color)
     lib.wlr_render_rect(self._ptr, box._ptr, color, projection._ptr)
Example #24
0
 def _build_matrix_ptr():
     return ffi.new("float [9]")