# This file has been autogenerated by the pywayland scanner

# Copyright © 2018 NXP
# Copyright © 2019 Status Research & Development GmbH.
# Copyright © 2021 Xaver Hugl
#
# 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


class WpDrmLeaseConnectorV1(Interface):
    """A leasable drm connector

    Represents a DRM connector which is available for lease. These objects are
    created via :func:`WpDrmLeaseDeviceV1.connector()
    <pywayland.protocol.drm_lease_v1.WpDrmLeaseDeviceV1.connector>` events, and
    should be passed to lease requests via
    :func:`WpDrmLeaseRequestV1.request_connector()
    <pywayland.protocol.drm_lease_v1.WpDrmLeaseRequestV1.request_connector>`.
    Immediately after the :class:`WpDrmLeaseConnectorV1` object is created the
    compositor will send a name, a description, a connector_id and a done
    event. When the description is updated the compositor will send a
    description event followed by a done event.
    """

    name = "wp_drm_lease_connector_v1"
    version = 1


class WpDrmLeaseDeviceV1(Interface):
    """Lease device

    This protocol is used by Wayland compositors which act as Direct Rendering
    Manager (DRM) masters to lease DRM resources to Wayland clients.

    The compositor will advertise one :class:`WpDrmLeaseDeviceV1` global for
    each DRM node. Some time after a client binds to the
    :class:`WpDrmLeaseDeviceV1` global, the compositor will send a drm_fd event
    followed by zero, one or more connector events. After all currently
    available connectors have been sent, the compositor will send a
    :func:`WpDrmLeaseDeviceV1.done()` event.

    When the list of connectors available for lease changes the compositor will
    send :func:`WpDrmLeaseDeviceV1.connector()` events for added connectors and
    :func:`WpDrmLeaseConnectorV1.withdrawn()
    <pywayland.protocol.drm_lease_v1.WpDrmLeaseConnectorV1.withdrawn>` events
    for removed connectors, followed by a :func:`WpDrmLeaseDeviceV1.done()`
    event.

    The compositor will indicate when a device is gone by removing the global
    via a :func:`WlRegistry.global_remove()
    <pywayland.protocol.wayland.WlRegistry.global_remove>` event. Upon
    receiving this event, the client should destroy any matching
    :class:`WpDrmLeaseDeviceV1` object.

    To destroy a :class:`WpDrmLeaseDeviceV1` object, the client must first
    issue a release request. Upon receiving this request, the compositor will
    immediately send a released event and destroy the object. The client must
    continue to process and discard drm_fd and connector events until it
    receives the released event. Upon receiving the released event, the client
    can safely cleanup any client-side resources.

    Warning! The protocol described in this file is currently in the testing
    phase. Backward compatible changes may be added together with the
    corresponding interface version bump. Backward incompatible changes can
    only be done by creating a new major version of the extension.
    """

    name = "wp_drm_lease_device_v1"
    version = 1


class WpDrmLeaseRequestV1(Interface):
    """Drm lease request

    A client that wishes to lease DRM resources will attach the list of
    connectors advertised with :func:`WpDrmLeaseDeviceV1.connector()
    <pywayland.protocol.drm_lease_v1.WpDrmLeaseDeviceV1.connector>` that they
    wish to lease, then use :func:`WpDrmLeaseRequestV1.submit()` to submit the
    request.
    """

    name = "wp_drm_lease_request_v1"
    version = 1

    class error(enum.IntEnum):
        wrong_device = 0
        duplicate_connector = 1
        empty_lease = 2


class WpDrmLeaseV1(Interface):
    """A drm lease

    A DRM lease object is used to transfer the DRM file descriptor to the
    client and manage the lifetime of the lease.

    Some time after the :class:`WpDrmLeaseV1` object is created, the compositor
    will reply with the lease request's result. If the lease request is
    granted, the compositor will send a lease_fd event. If the lease request is
    denied, the compositor will send a finished event without a lease_fd event.
    """

    name = "wp_drm_lease_v1"
    version = 1


class WpDrmLeaseConnectorV1Resource(Resource[WpDrmLeaseConnectorV1]):
    interface = WpDrmLeaseConnectorV1

    @WpDrmLeaseConnectorV1.event(
        Argument(ArgumentType.String),
    )
    def name(self, name: str) -> None:
        """Name

        The compositor sends this event once the connector is created to
        indicate the name of this connector. This will not change for the
        duration of the Wayland session, but is not guaranteed to be consistent
        between sessions.

        If the compositor supports
        :class:`~pywayland.protocol.wayland.WlOutput` version 4 and this
        connector corresponds to a
        :class:`~pywayland.protocol.wayland.WlOutput`, the compositor should
        use the same name as for the
        :class:`~pywayland.protocol.wayland.WlOutput`.

        :param name:
            connector name
        :type name:
            `ArgumentType.String`
        """
        self._post_event(0, name)

    @WpDrmLeaseConnectorV1.event(
        Argument(ArgumentType.String),
    )
    def description(self, description: str) -> None:
        """Description

        The compositor sends this event once the connector is created to
        provide a human-readable description for this connector, which may be
        presented to the user. The compositor may send this event multiple
        times over the lifetime of this object to reflect changes in the
        description.

        :param description:
            connector description
        :type description:
            `ArgumentType.String`
        """
        self._post_event(1, description)

    @WpDrmLeaseConnectorV1.event(
        Argument(ArgumentType.Uint),
    )
    def connector_id(self, connector_id: int) -> None:
        """Connector_id

        The compositor sends this event once the connector is created to
        indicate the DRM object ID which represents the underlying connector
        that is being offered. Note that the final lease may include additional
        object IDs, such as CRTCs and planes.

        :param connector_id:
            DRM connector ID
        :type connector_id:
            `ArgumentType.Uint`
        """
        self._post_event(2, connector_id)

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

        This event is sent after all properties of a connector have been sent.
        This allows changes to the properties to be seen as atomic even if they
        happen via multiple events.
        """
        self._post_event(3)

    @WpDrmLeaseConnectorV1.event()
    def withdrawn(self) -> None:
        """Lease offer withdrawn

        Sent to indicate that the compositor will no longer honor requests for
        DRM leases which include this connector. The client may still issue a
        lease request including this connector, but the compositor will send
        :func:`WpDrmLeaseV1.finished()
        <pywayland.protocol.drm_lease_v1.WpDrmLeaseV1.finished>` without
        issuing a lease fd. Compositors are encouraged to send this event when
        they lose access to connector, for example when the connector is hot-
        unplugged, when the connector gets leased to a client or when the
        compositor loses DRM master.

        If a client holds a lease for the connector, the status of the lease
        remains the same. The client should destroy the object after receiving
        this event.
        """
        self._post_event(4)


class WpDrmLeaseDeviceV1Resource(Resource[WpDrmLeaseDeviceV1]):
    interface = WpDrmLeaseDeviceV1

    @WpDrmLeaseDeviceV1.event(
        Argument(ArgumentType.FileDescriptor),
    )
    def drm_fd(self, fd: int) -> None:
        """Open a non-master fd for this drm node

        The compositor will send this event when the
        :class:`WpDrmLeaseDeviceV1` global is bound, although there are no
        guarantees as to how long this takes - the compositor might need to
        wait until regaining DRM master. The included fd is a non-master DRM
        file descriptor opened for this device and the compositor must not
        authenticate it. The purpose of this event is to give the client the
        ability to query DRM and discover information which may help them pick
        the appropriate DRM device or select the appropriate connectors
        therein.

        :param fd:
            DRM file descriptor
        :type fd:
            `ArgumentType.FileDescriptor`
        """
        self._post_event(0, fd)

    @WpDrmLeaseDeviceV1.event(
        Argument(ArgumentType.NewId, interface=WpDrmLeaseConnectorV1),
    )
    def connector(self, id: WpDrmLeaseConnectorV1) -> None:
        """Advertise connectors available for leases

        The compositor will use this event to advertise connectors available
        for lease by clients. This object may be passed into a lease request to
        indicate the client would like to lease that connector, see
        :func:`WpDrmLeaseRequestV1.request_connector()
        <pywayland.protocol.drm_lease_v1.WpDrmLeaseRequestV1.request_connector>`
        for details. While the compositor will make a best effort to not send
        disconnected connectors, no guarantees can be made.

        The compositor must send the drm_fd event before sending connectors.
        After the drm_fd event it will send all available connectors but may
        send additional connectors at any time.

        :param id:
        :type id:
            :class:`~pywayland.protocol.drm_lease_v1.WpDrmLeaseConnectorV1`
        """
        self._post_event(1, id)

    @WpDrmLeaseDeviceV1.event()
    def done(self) -> None:
        """Signals grouping of connectors

        The compositor will send this event to indicate that it has sent all
        currently available connectors after the client binds to the global or
        when it updates the connector list, for example on hotplug, drm master
        change or when a leased connector becomes available again. It will
        similarly send this event to group
        :func:`WpDrmLeaseConnectorV1.withdrawn()
        <pywayland.protocol.drm_lease_v1.WpDrmLeaseConnectorV1.withdrawn>`
        events of connectors of this device.
        """
        self._post_event(2)

    @WpDrmLeaseDeviceV1.event()
    def released(self) -> None:
        """The compositor has finished using the device

        This event is sent in response to the release request and indicates
        that the compositor is done sending connector events. The compositor
        will destroy this object immediately after sending the event and it
        will become invalid. The client should release any resources associated
        with this device after receiving this event.
        """
        self._post_event(3)


class WpDrmLeaseRequestV1Resource(Resource[WpDrmLeaseRequestV1]):
    interface = WpDrmLeaseRequestV1


class WpDrmLeaseV1Resource(Resource[WpDrmLeaseV1]):
    interface = WpDrmLeaseV1

    @WpDrmLeaseV1.event(
        Argument(ArgumentType.FileDescriptor),
    )
    def lease_fd(self, leased_fd: int) -> None:
        """Shares the drm file descriptor

        This event returns a file descriptor suitable for use with DRM-related
        ioctls. The client should use drmModeGetLease to enumerate the DRM
        objects which have been leased to them. The compositor guarantees it
        will not use the leased DRM objects itself until it sends the finished
        event. If the compositor cannot or will not grant a lease for the
        requested connectors, it will not send this event, instead sending the
        finished event.

        The compositor will send this event at most once during this objects
        lifetime.

        :param leased_fd:
            leased DRM file descriptor
        :type leased_fd:
            `ArgumentType.FileDescriptor`
        """
        self._post_event(0, leased_fd)

    @WpDrmLeaseV1.event()
    def finished(self) -> None:
        """Sent when the lease has been revoked

        The compositor uses this event to either reject a lease request, or if
        it previously sent a lease_fd, to notify the client that the lease has
        been revoked. If the client requires a new lease, they should destroy
        this object and submit a new lease request. The compositor will send no
        further events for this object after sending the finish event.
        Compositors should revoke the lease when any of the leased resources
        become unavailable, namely when a hot-unplug occurs or when the
        compositor loses DRM master. Compositors may advertise the connector
        for leasing again, if the resource is available, by sending the
        connector event through the
        :class:`~pywayland.protocol.drm_lease_v1.WpDrmLeaseDeviceV1` interface.
        """
        self._post_event(1)


class WpDrmLeaseConnectorV1Proxy(Proxy[WpDrmLeaseConnectorV1]):
    interface = WpDrmLeaseConnectorV1

    @WpDrmLeaseConnectorV1.request()
    def destroy(self) -> None:
        """Destroy connector

        The client may send this request to indicate that it will not use this
        connector. Clients are encouraged to send this after receiving the
        "withdrawn" event so that the server can release the resources
        associated with this connector offer. Neither existing lease requests
        nor leases will be affected.
        """
        self._marshal(0)
        self._destroy()


class WpDrmLeaseDeviceV1Proxy(Proxy[WpDrmLeaseDeviceV1]):
    interface = WpDrmLeaseDeviceV1

    @WpDrmLeaseDeviceV1.request(
        Argument(ArgumentType.NewId, interface=WpDrmLeaseRequestV1),
    )
    def create_lease_request(self) -> WpDrmLeaseRequestV1Proxy:
        """Create a lease request object

        Creates a lease request object.

        See the documentation for
        :class:`~pywayland.protocol.drm_lease_v1.WpDrmLeaseRequestV1` for
        details.

        :returns:
            :class:`~pywayland.protocol.drm_lease_v1.WpDrmLeaseRequestV1`
        """
        id = self._marshal_constructor(0, WpDrmLeaseRequestV1)
        return id

    @WpDrmLeaseDeviceV1.request()
    def release(self) -> None:
        """Release this object

        Indicates the client no longer wishes to use this object. In response
        the compositor will immediately send the released event and destroy
        this object. It can however not guarantee that the client won't receive
        connector events before the released event. The client must not send
        any requests after this one, doing so will raise a
        :class:`~pywayland.protocol.wayland.WlDisplay` error. Existing
        connectors, lease request and leases will not be affected.
        """
        self._marshal(1)


class WpDrmLeaseRequestV1Proxy(Proxy[WpDrmLeaseRequestV1]):
    interface = WpDrmLeaseRequestV1

    @WpDrmLeaseRequestV1.request(
        Argument(ArgumentType.Object, interface=WpDrmLeaseConnectorV1),
    )
    def request_connector(self, connector: WpDrmLeaseConnectorV1Proxy) -> None:
        """Request a connector for this lease

        Indicates that the client would like to lease the given connector. This
        is only used as a suggestion, the compositor may choose to include any
        resources in the lease it issues, or change the set of leased resources
        at any time. Compositors are however encouraged to include the
        requested connector and other resources necessary to drive the
        connected output in the lease.

        Requesting a connector that was created from a different lease device
        than this lease request raises the wrong_device error. Requesting a
        connector twice will raise the duplicate_connector error.

        :param connector:
        :type connector:
            :class:`~pywayland.protocol.drm_lease_v1.WpDrmLeaseConnectorV1`
        """
        self._marshal(0, connector)

    @WpDrmLeaseRequestV1.request(
        Argument(ArgumentType.NewId, interface=WpDrmLeaseV1),
    )
    def submit(self) -> WpDrmLeaseV1Proxy:
        """Submit the lease request

        Submits the lease request and creates a new
        :class:`~pywayland.protocol.drm_lease_v1.WpDrmLeaseV1` object. After
        calling submit the compositor will immediately destroy this object,
        issuing any more requests will cause a
        :class:`~pywayland.protocol.wayland.WlDisplay` error. The compositor
        doesn't make any guarantees about the events of the lease object,
        clients cannot expect an immediate response. Not requesting any
        connectors before submitting the lease request will raise the
        empty_lease error.

        :returns:
            :class:`~pywayland.protocol.drm_lease_v1.WpDrmLeaseV1`
        """
        id = self._marshal_constructor(1, WpDrmLeaseV1)
        return id


class WpDrmLeaseV1Proxy(Proxy[WpDrmLeaseV1]):
    interface = WpDrmLeaseV1

    @WpDrmLeaseV1.request()
    def destroy(self) -> None:
        """Destroys the lease object

        The client should send this to indicate that it no longer wishes to use
        this lease. The compositor should use drmModeRevokeLease on the
        appropriate file descriptor, if necessary.

        Upon destruction, the compositor should advertise the connector for
        leasing again by sending the connector event through the
        :class:`~pywayland.protocol.drm_lease_v1.WpDrmLeaseDeviceV1` interface.
        """
        self._marshal(0)
        self._destroy()


class WpDrmLeaseConnectorV1Global(Global[WpDrmLeaseConnectorV1]):
    interface = WpDrmLeaseConnectorV1


class WpDrmLeaseDeviceV1Global(Global[WpDrmLeaseDeviceV1]):
    interface = WpDrmLeaseDeviceV1


class WpDrmLeaseRequestV1Global(Global[WpDrmLeaseRequestV1]):
    interface = WpDrmLeaseRequestV1


class WpDrmLeaseV1Global(Global[WpDrmLeaseV1]):
    interface = WpDrmLeaseV1


WpDrmLeaseConnectorV1._gen_c()
WpDrmLeaseConnectorV1.proxy_class = WpDrmLeaseConnectorV1Proxy
WpDrmLeaseConnectorV1.resource_class = WpDrmLeaseConnectorV1Resource
WpDrmLeaseConnectorV1.global_class = WpDrmLeaseConnectorV1Global


WpDrmLeaseDeviceV1._gen_c()
WpDrmLeaseDeviceV1.proxy_class = WpDrmLeaseDeviceV1Proxy
WpDrmLeaseDeviceV1.resource_class = WpDrmLeaseDeviceV1Resource
WpDrmLeaseDeviceV1.global_class = WpDrmLeaseDeviceV1Global


WpDrmLeaseRequestV1._gen_c()
WpDrmLeaseRequestV1.proxy_class = WpDrmLeaseRequestV1Proxy
WpDrmLeaseRequestV1.resource_class = WpDrmLeaseRequestV1Resource
WpDrmLeaseRequestV1.global_class = WpDrmLeaseRequestV1Global


WpDrmLeaseV1._gen_c()
WpDrmLeaseV1.proxy_class = WpDrmLeaseV1Proxy
WpDrmLeaseV1.resource_class = WpDrmLeaseV1Resource
WpDrmLeaseV1.global_class = WpDrmLeaseV1Global
