# This file has been autogenerated by the pywayland scanner

# Copyright © 2021-2023 Andri Yngvason
# Copyright © 2024 Simon Ser
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from __future__ import annotations

import enum

from pywayland.protocol_core import Argument, ArgumentType, Global, Interface, Proxy, Resource

from .ext_image_capture_source_v1 import ExtImageCaptureSourceV1
from .ext_image_capture_source_v1 import ExtImageCaptureSourceV1Proxy
from .wayland import WlBuffer
from .wayland import WlBufferProxy
from .wayland import WlPointer
from .wayland import WlPointerProxy


class ExtImageCopyCaptureCursorSessionV1(Interface):
    """Cursor capture session

    This object represents a cursor capture session. It extends the base
    capture session with cursor-specific metadata.
    """

    name = "ext_image_copy_capture_cursor_session_v1"
    version = 1

    class error(enum.IntEnum):
        duplicate_session = 1


class ExtImageCopyCaptureFrameV1(Interface):
    """Image capture frame

    This object represents an image capture frame.

    The client should attach a buffer, damage the buffer, and then send a
    capture request.

    If the capture is successful, the compositor must send the frame metadata
    (transform, damage, presentation_time in any order) followed by the ready
    event.

    If the capture fails, the compositor must send the failed event.
    """

    name = "ext_image_copy_capture_frame_v1"
    version = 1

    class error(enum.IntEnum):
        no_buffer = 1
        invalid_buffer_damage = 2
        already_captured = 3

    class failure_reason(enum.IntEnum):
        unknown = 0
        buffer_constraints = 1
        stopped = 2


class ExtImageCopyCaptureManagerV1(Interface):
    """Manager to inform clients and begin capturing

    This object is a manager which offers requests to start capturing from a
    source.
    """

    name = "ext_image_copy_capture_manager_v1"
    version = 1

    class error(enum.IntEnum):
        invalid_option = 1

    class options(enum.IntFlag):
        paint_cursors = 1


class ExtImageCopyCaptureSessionV1(Interface):
    """Image copy capture session

    This object represents an active image copy capture session.

    After a capture session is created, buffer constraint events will be
    emitted from the compositor to tell the client which buffer types and
    formats are supported for reading from the session. The compositor may re-
    send buffer constraint events whenever they change.

    To advertise buffer constraints, the compositor must send in no particular
    order: zero or more shm_format and dmabuf_format events, zero or one
    dmabuf_device event, and exactly one buffer_size event. Then the compositor
    must send a done event.

    When the client has received all the buffer constraints, it can create a
    buffer accordingly, attach it to the capture session using the
    attach_buffer request, set the buffer damage using the damage_buffer
    request and then send the capture request.
    """

    name = "ext_image_copy_capture_session_v1"
    version = 1

    class error(enum.IntEnum):
        duplicate_frame = 1


class ExtImageCopyCaptureCursorSessionV1Resource(Resource[ExtImageCopyCaptureCursorSessionV1]):
    interface = ExtImageCopyCaptureCursorSessionV1

    @ExtImageCopyCaptureCursorSessionV1.event()
    def enter(self) -> None:
        """Cursor entered captured area

        Sent when a cursor enters the captured area. It shall be generated
        before the "position" and "hotspot" events when and only when a cursor
        enters the area.

        The cursor enters the captured area when the cursor image intersects
        with the captured area. Note, this is different from e.g.
        :func:`WlPointer.enter() <pywayland.protocol.wayland.WlPointer.enter>`.
        """
        self._post_event(0)

    @ExtImageCopyCaptureCursorSessionV1.event()
    def leave(self) -> None:
        """Cursor left captured area

        Sent when a cursor leaves the captured area. No "position" or "hotspot"
        event is generated for the cursor until the cursor enters the captured
        area again.
        """
        self._post_event(1)

    @ExtImageCopyCaptureCursorSessionV1.event(
        Argument(ArgumentType.Int),
        Argument(ArgumentType.Int),
    )
    def position(self, x: int, y: int) -> None:
        """Position changed

        Cursors outside the image capture source do not get captured and no
        event will be generated for them.

        The given position is the position of the cursor's hotspot and it is
        relative to the main buffer's top left corner in transformed buffer
        pixel coordinates. The coordinates may be negative or greater than the
        main buffer size.

        :param x:
            position x coordinates
        :type x:
            `ArgumentType.Int`
        :param y:
            position y coordinates
        :type y:
            `ArgumentType.Int`
        """
        self._post_event(2, x, y)

    @ExtImageCopyCaptureCursorSessionV1.event(
        Argument(ArgumentType.Int),
        Argument(ArgumentType.Int),
    )
    def hotspot(self, x: int, y: int) -> None:
        """Hotspot changed

        The hotspot describes the offset between the cursor image and the
        position of the input device.

        The given coordinates are the hotspot's offset from the origin in
        buffer coordinates.

        Clients should not apply the hotspot immediately: the hotspot becomes
        effective when the next :func:`ExtImageCopyCaptureFrameV1.ready()
        <pywayland.protocol.ext_image_copy_capture_v1.ExtImageCopyCaptureFrameV1.ready>`
        event is received.

        Compositors may delay this event until the client captures a new frame.

        :param x:
            hotspot x coordinates
        :type x:
            `ArgumentType.Int`
        :param y:
            hotspot y coordinates
        :type y:
            `ArgumentType.Int`
        """
        self._post_event(3, x, y)


class ExtImageCopyCaptureFrameV1Resource(Resource[ExtImageCopyCaptureFrameV1]):
    interface = ExtImageCopyCaptureFrameV1

    @ExtImageCopyCaptureFrameV1.event(
        Argument(ArgumentType.Uint),
    )
    def transform(self, transform: int) -> None:
        """Buffer transform

        This event is sent before the ready event and holds the transform that
        the compositor has applied to the buffer contents.

        :param transform:
        :type transform:
            `ArgumentType.Uint`
        """
        self._post_event(0, transform)

    @ExtImageCopyCaptureFrameV1.event(
        Argument(ArgumentType.Int),
        Argument(ArgumentType.Int),
        Argument(ArgumentType.Int),
        Argument(ArgumentType.Int),
    )
    def damage(self, x: int, y: int, width: int, height: int) -> None:
        """Buffer damaged region

        This event is sent before the ready event. It may be generated multiple
        times to describe a region.

        The first captured frame in a session will always carry full damage.
        Subsequent frames' damaged regions describe which parts of the buffer
        have changed since the last ready event.

        These coordinates originate in the upper left corner of the buffer.

        :param x:
            damage x coordinate
        :type x:
            `ArgumentType.Int`
        :param y:
            damage y coordinate
        :type y:
            `ArgumentType.Int`
        :param width:
            damage width
        :type width:
            `ArgumentType.Int`
        :param height:
            damage height
        :type height:
            `ArgumentType.Int`
        """
        self._post_event(1, x, y, width, height)

    @ExtImageCopyCaptureFrameV1.event(
        Argument(ArgumentType.Uint),
        Argument(ArgumentType.Uint),
        Argument(ArgumentType.Uint),
    )
    def presentation_time(self, tv_sec_hi: int, tv_sec_lo: int, tv_nsec: int) -> None:
        """Presentation time of the frame

        This event indicates the time at which the frame is presented to the
        output in system monotonic time. This event is sent before the ready
        event.

        The timestamp is expressed as tv_sec_hi, tv_sec_lo, tv_nsec triples,
        each component being an unsigned 32-bit value. Whole seconds are in
        tv_sec which is a 64-bit value combined from tv_sec_hi and tv_sec_lo,
        and the additional fractional part in tv_nsec as nanoseconds. Hence,
        for valid timestamps tv_nsec must be in [0, 999999999].

        :param tv_sec_hi:
            high 32 bits of the seconds part of the timestamp
        :type tv_sec_hi:
            `ArgumentType.Uint`
        :param tv_sec_lo:
            low 32 bits of the seconds part of the timestamp
        :type tv_sec_lo:
            `ArgumentType.Uint`
        :param tv_nsec:
            nanoseconds part of the timestamp
        :type tv_nsec:
            `ArgumentType.Uint`
        """
        self._post_event(2, tv_sec_hi, tv_sec_lo, tv_nsec)

    @ExtImageCopyCaptureFrameV1.event()
    def ready(self) -> None:
        """Frame is available for reading

        Called as soon as the frame is copied, indicating it is available for
        reading.

        The buffer may be re-used by the client after this event.

        After receiving this event, the client must destroy the object.
        """
        self._post_event(3)

    @ExtImageCopyCaptureFrameV1.event(
        Argument(ArgumentType.Uint),
    )
    def failed(self, reason: int) -> None:
        """Capture failed

        This event indicates that the attempted frame copy has failed.

        After receiving this event, the client must destroy the object.

        :param reason:
        :type reason:
            `ArgumentType.Uint`
        """
        self._post_event(4, reason)


class ExtImageCopyCaptureManagerV1Resource(Resource[ExtImageCopyCaptureManagerV1]):
    interface = ExtImageCopyCaptureManagerV1


class ExtImageCopyCaptureSessionV1Resource(Resource[ExtImageCopyCaptureSessionV1]):
    interface = ExtImageCopyCaptureSessionV1

    @ExtImageCopyCaptureSessionV1.event(
        Argument(ArgumentType.Uint),
        Argument(ArgumentType.Uint),
    )
    def buffer_size(self, width: int, height: int) -> None:
        """Image capture source dimensions

        Provides the dimensions of the source image in buffer pixel
        coordinates.

        The client must attach buffers that match this size.

        :param width:
            buffer width
        :type width:
            `ArgumentType.Uint`
        :param height:
            buffer height
        :type height:
            `ArgumentType.Uint`
        """
        self._post_event(0, width, height)

    @ExtImageCopyCaptureSessionV1.event(
        Argument(ArgumentType.Uint),
    )
    def shm_format(self, format: int) -> None:
        """Shm buffer format

        Provides the format that must be used for shared-memory buffers.

        This event may be emitted multiple times, in which case the client may
        choose any given format.

        :param format:
            shm format
        :type format:
            `ArgumentType.Uint`
        """
        self._post_event(1, format)

    @ExtImageCopyCaptureSessionV1.event(
        Argument(ArgumentType.Array),
    )
    def dmabuf_device(self, device: list) -> None:
        """Dma-buf device

        This event advertises the device buffers must be allocated on for dma-
        buf buffers.

        In general the device is a DRM node. The DRM node type (primary vs.
        render) is unspecified. Clients must not rely on the compositor sending
        a particular node type. Clients cannot check two devices for equality
        by comparing the dev_t value.

        :param device:
            device dev_t value
        :type device:
            `ArgumentType.Array`
        """
        self._post_event(2, device)

    @ExtImageCopyCaptureSessionV1.event(
        Argument(ArgumentType.Uint),
        Argument(ArgumentType.Array),
    )
    def dmabuf_format(self, format: int, modifiers: list) -> None:
        """Dma-buf format

        Provides the format that must be used for dma-buf buffers.

        The client may choose any of the modifiers advertised in the array of
        64-bit unsigned integers.

        This event may be emitted multiple times, in which case the client may
        choose any given format.

        :param format:
            drm format code
        :type format:
            `ArgumentType.Uint`
        :param modifiers:
            drm format modifiers
        :type modifiers:
            `ArgumentType.Array`
        """
        self._post_event(3, format, modifiers)

    @ExtImageCopyCaptureSessionV1.event()
    def done(self) -> None:
        """All constraints have been sent

        This event is sent once when all buffer constraint events have been
        sent.

        The compositor must always end a batch of buffer constraint events with
        this event, regardless of whether it sends the initial constraints or
        an update.
        """
        self._post_event(4)

    @ExtImageCopyCaptureSessionV1.event()
    def stopped(self) -> None:
        """Session is no longer available

        This event indicates that the capture session has stopped and is no
        longer available. This can happen in a number of cases, e.g. when the
        underlying source is destroyed, if the user decides to end the image
        capture, or if an unrecoverable runtime error has occurred.

        The client should destroy the session after receiving this event.
        """
        self._post_event(5)


class ExtImageCopyCaptureCursorSessionV1Proxy(Proxy[ExtImageCopyCaptureCursorSessionV1]):
    interface = ExtImageCopyCaptureCursorSessionV1

    @ExtImageCopyCaptureCursorSessionV1.request()
    def destroy(self) -> None:
        """Delete this object

        Destroys the session. This request can be sent at any time by the
        client.

        This request doesn't affect
        :class:`~pywayland.protocol.ext_image_copy_capture_v1.ExtImageCopyCaptureFrameV1`
        objects created by this object.
        """
        self._marshal(0)
        self._destroy()

    @ExtImageCopyCaptureCursorSessionV1.request(
        Argument(ArgumentType.NewId, interface=ExtImageCopyCaptureSessionV1),
    )
    def get_capture_session(self) -> ExtImageCopyCaptureSessionV1Proxy:
        """Get image copy capturer session

        Gets the image copy capture session for this cursor session.

        The session will produce frames of the cursor image. The compositor may
        pause the session when the cursor leaves the captured area.

        This request must not be sent more than once, or else the
        duplicate_session protocol error is raised.

        :returns:
            :class:`~pywayland.protocol.ext_image_copy_capture_v1.ExtImageCopyCaptureSessionV1`
        """
        session = self._marshal_constructor(1, ExtImageCopyCaptureSessionV1)
        return session


class ExtImageCopyCaptureFrameV1Proxy(Proxy[ExtImageCopyCaptureFrameV1]):
    interface = ExtImageCopyCaptureFrameV1

    @ExtImageCopyCaptureFrameV1.request()
    def destroy(self) -> None:
        """Destroy this object

        Destroys the frame. This request can be sent at any time by the client.
        """
        self._marshal(0)
        self._destroy()

    @ExtImageCopyCaptureFrameV1.request(
        Argument(ArgumentType.Object, interface=WlBuffer),
    )
    def attach_buffer(self, buffer: WlBufferProxy) -> None:
        """Attach buffer to session

        Attach a buffer to the session.

        The :func:`WlBuffer.release()
        <pywayland.protocol.wayland.WlBuffer.release>` request is unused.

        The new buffer replaces any previously attached buffer.

        This request must not be sent after capture, or else the
        already_captured protocol error is raised.

        :param buffer:
        :type buffer:
            :class:`~pywayland.protocol.wayland.WlBuffer`
        """
        self._marshal(1, buffer)

    @ExtImageCopyCaptureFrameV1.request(
        Argument(ArgumentType.Int),
        Argument(ArgumentType.Int),
        Argument(ArgumentType.Int),
        Argument(ArgumentType.Int),
    )
    def damage_buffer(self, x: int, y: int, width: int, height: int) -> None:
        """Damage buffer

        Apply damage to the buffer which is to be captured next. This request
        may be sent multiple times to describe a region.

        The client indicates the accumulated damage since this
        :class:`~pywayland.protocol.wayland.WlBuffer` was last captured. During
        capture, the compositor will update the buffer with at least the union
        of the region passed by the client and the region advertised by
        :func:`ExtImageCopyCaptureFrameV1.damage()`.

        When a :class:`~pywayland.protocol.wayland.WlBuffer` is captured for
        the first time, or when the client doesn't track damage, the client
        must damage the whole buffer.

        This is for optimisation purposes. The compositor may use this
        information to reduce copying.

        These coordinates originate from the upper left corner of the buffer.

        If x or y are strictly negative, or if width or height are negative or
        zero, the invalid_buffer_damage protocol error is raised.

        This request must not be sent after capture, or else the
        already_captured protocol error is raised.

        :param x:
            region x coordinate
        :type x:
            `ArgumentType.Int`
        :param y:
            region y coordinate
        :type y:
            `ArgumentType.Int`
        :param width:
            region width
        :type width:
            `ArgumentType.Int`
        :param height:
            region height
        :type height:
            `ArgumentType.Int`
        """
        self._marshal(2, x, y, width, height)

    @ExtImageCopyCaptureFrameV1.request()
    def capture(self) -> None:
        """Capture a frame

        Capture a frame.

        Unless this is the first successful captured frame performed in this
        session, the compositor may wait an indefinite amount of time for the
        source content to change before performing the copy.

        This request may only be sent once, or else the already_captured
        protocol error is raised. A buffer must be attached before this request
        is sent, or else the no_buffer protocol error is raised.
        """
        self._marshal(3)


class ExtImageCopyCaptureManagerV1Proxy(Proxy[ExtImageCopyCaptureManagerV1]):
    interface = ExtImageCopyCaptureManagerV1

    @ExtImageCopyCaptureManagerV1.request(
        Argument(ArgumentType.NewId, interface=ExtImageCopyCaptureSessionV1),
        Argument(ArgumentType.Object, interface=ExtImageCaptureSourceV1),
        Argument(ArgumentType.Uint),
    )
    def create_session(self, source: ExtImageCaptureSourceV1Proxy, options: int) -> ExtImageCopyCaptureSessionV1Proxy:
        """Capture an image capture source

        Create a capturing session for an image capture source.

        If the paint_cursors option is set, cursors shall be composited onto
        the captured frame. The cursor must not be composited onto the frame if
        this flag is not set.

        If the options bitfield is invalid, the invalid_option protocol error
        is sent.

        :param source:
        :type source:
            :class:`~pywayland.protocol.ext_image_capture_source_v1.ExtImageCaptureSourceV1`
        :param options:
        :type options:
            `ArgumentType.Uint`
        :returns:
            :class:`~pywayland.protocol.ext_image_copy_capture_v1.ExtImageCopyCaptureSessionV1`
        """
        session = self._marshal_constructor(0, ExtImageCopyCaptureSessionV1, source, options)
        return session

    @ExtImageCopyCaptureManagerV1.request(
        Argument(ArgumentType.NewId, interface=ExtImageCopyCaptureCursorSessionV1),
        Argument(ArgumentType.Object, interface=ExtImageCaptureSourceV1),
        Argument(ArgumentType.Object, interface=WlPointer),
    )
    def create_pointer_cursor_session(self, source: ExtImageCaptureSourceV1Proxy, pointer: WlPointerProxy) -> ExtImageCopyCaptureCursorSessionV1Proxy:
        """Capture the pointer cursor of an image capture source

        Create a cursor capturing session for the pointer of an image capture
        source.

        :param source:
        :type source:
            :class:`~pywayland.protocol.ext_image_capture_source_v1.ExtImageCaptureSourceV1`
        :param pointer:
        :type pointer:
            :class:`~pywayland.protocol.wayland.WlPointer`
        :returns:
            :class:`~pywayland.protocol.ext_image_copy_capture_v1.ExtImageCopyCaptureCursorSessionV1`
        """
        session = self._marshal_constructor(1, ExtImageCopyCaptureCursorSessionV1, source, pointer)
        return session

    @ExtImageCopyCaptureManagerV1.request()
    def destroy(self) -> None:
        """Destroy the manager

        Destroy the manager object.

        Other objects created via this interface are unaffected.
        """
        self._marshal(2)
        self._destroy()


class ExtImageCopyCaptureSessionV1Proxy(Proxy[ExtImageCopyCaptureSessionV1]):
    interface = ExtImageCopyCaptureSessionV1

    @ExtImageCopyCaptureSessionV1.request(
        Argument(ArgumentType.NewId, interface=ExtImageCopyCaptureFrameV1),
    )
    def create_frame(self) -> ExtImageCopyCaptureFrameV1Proxy:
        """Create a frame

        Create a capture frame for this session.

        At most one frame object can exist for a given session at any time. If
        a client sends a create_frame request before a previous frame object
        has been destroyed, the duplicate_frame protocol error is raised.

        :returns:
            :class:`~pywayland.protocol.ext_image_copy_capture_v1.ExtImageCopyCaptureFrameV1`
        """
        frame = self._marshal_constructor(0, ExtImageCopyCaptureFrameV1)
        return frame

    @ExtImageCopyCaptureSessionV1.request()
    def destroy(self) -> None:
        """Delete this object

        Destroys the session. This request can be sent at any time by the
        client.

        This request doesn't affect
        :class:`~pywayland.protocol.ext_image_copy_capture_v1.ExtImageCopyCaptureFrameV1`
        objects created by this object.
        """
        self._marshal(1)
        self._destroy()


class ExtImageCopyCaptureCursorSessionV1Global(Global[ExtImageCopyCaptureCursorSessionV1]):
    interface = ExtImageCopyCaptureCursorSessionV1


class ExtImageCopyCaptureFrameV1Global(Global[ExtImageCopyCaptureFrameV1]):
    interface = ExtImageCopyCaptureFrameV1


class ExtImageCopyCaptureManagerV1Global(Global[ExtImageCopyCaptureManagerV1]):
    interface = ExtImageCopyCaptureManagerV1


class ExtImageCopyCaptureSessionV1Global(Global[ExtImageCopyCaptureSessionV1]):
    interface = ExtImageCopyCaptureSessionV1


ExtImageCopyCaptureCursorSessionV1._gen_c()
ExtImageCopyCaptureCursorSessionV1.proxy_class = ExtImageCopyCaptureCursorSessionV1Proxy
ExtImageCopyCaptureCursorSessionV1.resource_class = ExtImageCopyCaptureCursorSessionV1Resource
ExtImageCopyCaptureCursorSessionV1.global_class = ExtImageCopyCaptureCursorSessionV1Global


ExtImageCopyCaptureFrameV1._gen_c()
ExtImageCopyCaptureFrameV1.proxy_class = ExtImageCopyCaptureFrameV1Proxy
ExtImageCopyCaptureFrameV1.resource_class = ExtImageCopyCaptureFrameV1Resource
ExtImageCopyCaptureFrameV1.global_class = ExtImageCopyCaptureFrameV1Global


ExtImageCopyCaptureManagerV1._gen_c()
ExtImageCopyCaptureManagerV1.proxy_class = ExtImageCopyCaptureManagerV1Proxy
ExtImageCopyCaptureManagerV1.resource_class = ExtImageCopyCaptureManagerV1Resource
ExtImageCopyCaptureManagerV1.global_class = ExtImageCopyCaptureManagerV1Global


ExtImageCopyCaptureSessionV1._gen_c()
ExtImageCopyCaptureSessionV1.proxy_class = ExtImageCopyCaptureSessionV1Proxy
ExtImageCopyCaptureSessionV1.resource_class = ExtImageCopyCaptureSessionV1Resource
ExtImageCopyCaptureSessionV1.global_class = ExtImageCopyCaptureSessionV1Global
