# This file has been autogenerated by the pywayland scanner

# Copyright © 2018 Simon Ser
# Copyright © 2019 Ivan Molodetskikh
# Copyright © 2024 Neal Gompa
#
# Permission to use, copy, modify, distribute, and sell this
# software and its documentation for any purpose is hereby granted
# without fee, provided that the above copyright notice appear in
# all copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of
# the copyright holders not be used in advertising or publicity
# pertaining to distribution of the software without specific,
# written prior permission.  The copyright holders make no
# representations about the suitability of this software for any
# purpose.  It is provided "as is" without express or implied
# warranty.
#
# THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
# SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
# AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
# THIS SOFTWARE.

from __future__ import annotations

import enum

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

from .wayland import WlSeat
from .wayland import WlSeatProxy


class ExtDataControlDeviceV1(Interface):
    """Manage a data device for a seat

    This interface allows a client to manage a seat's selection.

    When the seat is destroyed, this object becomes inert.
    """

    name = "ext_data_control_device_v1"
    version = 1

    class error(enum.IntEnum):
        used_source = 1


class ExtDataControlManagerV1(Interface):
    """Manager to control data devices

    This interface is a manager that allows creating per-seat data device
    controls.
    """

    name = "ext_data_control_manager_v1"
    version = 1


class ExtDataControlOfferV1(Interface):
    """Offer to transfer data

    A ext_data_control_offer represents a piece of data offered for transfer by
    another client (the source client). The offer describes the different MIME
    types that the data can be converted to and provides the mechanism for
    transferring the data directly from the source client.
    """

    name = "ext_data_control_offer_v1"
    version = 1


class ExtDataControlSourceV1(Interface):
    """Offer to transfer data

    The ext_data_control_source object is the source side of a
    ext_data_control_offer. It is created by the source client in a data
    transfer and provides a way to describe the offered data and a way to
    respond to requests to transfer the data.
    """

    name = "ext_data_control_source_v1"
    version = 1

    class error(enum.IntEnum):
        invalid_offer = 1


class ExtDataControlDeviceV1Resource(Resource[ExtDataControlDeviceV1]):
    interface = ExtDataControlDeviceV1

    @ExtDataControlDeviceV1.event(
        Argument(ArgumentType.NewId, interface=ExtDataControlOfferV1),
    )
    def data_offer(self, id: ExtDataControlOfferV1) -> None:
        """Introduce a new ext_data_control_offer

        The data_offer event introduces a new ext_data_control_offer object,
        which will subsequently be used in either the
        ext_data_control_device.selection event (for the regular clipboard
        selections) or the ext_data_control_device.primary_selection event (for
        the primary clipboard selections). Immediately following the
        ext_data_control_device.data_offer event, the new data_offer object
        will send out ext_data_control_offer.offer events to describe the MIME
        types it offers.

        :param id:
        :type id:
            :class:`~pywayland.protocol.ext_data_control_v1.ExtDataControlOfferV1`
        """
        self._post_event(0, id)

    @ExtDataControlDeviceV1.event(
        Argument(ArgumentType.Object, interface=ExtDataControlOfferV1, nullable=True),
    )
    def selection(self, id: ExtDataControlOfferV1 | None) -> None:
        """Advertise new selection

        The selection event is sent out to notify the client of a new
        ext_data_control_offer for the selection for this device. The
        ext_data_control_device.data_offer and the ext_data_control_offer.offer
        events are sent out immediately before this event to introduce the data
        offer object. The selection event is sent to a client when a new
        selection is set. The ext_data_control_offer is valid until a new
        ext_data_control_offer or NULL is received. The client must destroy the
        previous selection ext_data_control_offer, if any, upon receiving this
        event. Regardless, the previous selection will be ignored once a new
        selection ext_data_control_offer is received.

        The first selection event is sent upon binding the
        ext_data_control_device object.

        :param id:
        :type id:
            :class:`~pywayland.protocol.ext_data_control_v1.ExtDataControlOfferV1` or `None`
        """
        self._post_event(1, id)

    @ExtDataControlDeviceV1.event()
    def finished(self) -> None:
        """This data control is no longer valid

        This data control object is no longer valid and should be destroyed by
        the client.
        """
        self._post_event(2)

    @ExtDataControlDeviceV1.event(
        Argument(ArgumentType.Object, interface=ExtDataControlOfferV1, nullable=True),
    )
    def primary_selection(self, id: ExtDataControlOfferV1 | None) -> None:
        """Advertise new primary selection

        The primary_selection event is sent out to notify the client of a new
        ext_data_control_offer for the primary selection for this device. The
        ext_data_control_device.data_offer and the ext_data_control_offer.offer
        events are sent out immediately before this event to introduce the data
        offer object. The primary_selection event is sent to a client when a
        new primary selection is set. The ext_data_control_offer is valid until
        a new ext_data_control_offer or NULL is received. The client must
        destroy the previous primary selection ext_data_control_offer, if any,
        upon receiving this event. Regardless, the previous primary selection
        will be ignored once a new primary selection ext_data_control_offer is
        received.

        If the compositor supports primary selection, the first
        primary_selection event is sent upon binding the
        ext_data_control_device object.

        :param id:
        :type id:
            :class:`~pywayland.protocol.ext_data_control_v1.ExtDataControlOfferV1` or `None`
        """
        self._post_event(3, id)


class ExtDataControlManagerV1Resource(Resource[ExtDataControlManagerV1]):
    interface = ExtDataControlManagerV1


class ExtDataControlOfferV1Resource(Resource[ExtDataControlOfferV1]):
    interface = ExtDataControlOfferV1

    @ExtDataControlOfferV1.event(
        Argument(ArgumentType.String),
    )
    def offer(self, mime_type: str) -> None:
        """Advertise offered mime type

        Sent immediately after creating the ext_data_control_offer object. One
        event per offered MIME type.

        :param mime_type:
            offered MIME type
        :type mime_type:
            `ArgumentType.String`
        """
        self._post_event(0, mime_type)


class ExtDataControlSourceV1Resource(Resource[ExtDataControlSourceV1]):
    interface = ExtDataControlSourceV1

    @ExtDataControlSourceV1.event(
        Argument(ArgumentType.String),
        Argument(ArgumentType.FileDescriptor),
    )
    def send(self, mime_type: str, fd: int) -> None:
        """Send the data

        Request for data from the client. Send the data as the specified MIME
        type over the passed file descriptor, then close it.

        :param mime_type:
            MIME type for the data
        :type mime_type:
            `ArgumentType.String`
        :param fd:
            file descriptor for the data
        :type fd:
            `ArgumentType.FileDescriptor`
        """
        self._post_event(0, mime_type, fd)

    @ExtDataControlSourceV1.event()
    def cancelled(self) -> None:
        """Selection was cancelled

        This data source is no longer valid. The data source has been replaced
        by another data source.

        The client should clean up and destroy this data source.
        """
        self._post_event(1)


class ExtDataControlDeviceV1Proxy(Proxy[ExtDataControlDeviceV1]):
    interface = ExtDataControlDeviceV1

    @ExtDataControlDeviceV1.request(
        Argument(ArgumentType.Object, interface=ExtDataControlSourceV1, nullable=True),
    )
    def set_selection(self, source: ExtDataControlSourceV1Proxy | None) -> None:
        """Copy data to the selection

        This request asks the compositor to set the selection to the data from
        the source on behalf of the client.

        The given source may not be used in any further set_selection or
        set_primary_selection requests. Attempting to use a previously used
        source triggers the used_source protocol error.

        To unset the selection, set the source to NULL.

        :param source:
        :type source:
            :class:`~pywayland.protocol.ext_data_control_v1.ExtDataControlSourceV1` or `None`
        """
        self._marshal(0, source)

    @ExtDataControlDeviceV1.request()
    def destroy(self) -> None:
        """Destroy this data device

        Destroys the data device object.
        """
        self._marshal(1)
        self._destroy()

    @ExtDataControlDeviceV1.request(
        Argument(ArgumentType.Object, interface=ExtDataControlSourceV1, nullable=True),
    )
    def set_primary_selection(self, source: ExtDataControlSourceV1Proxy | None) -> None:
        """Copy data to the primary selection

        This request asks the compositor to set the primary selection to the
        data from the source on behalf of the client.

        The given source may not be used in any further set_selection or
        set_primary_selection requests. Attempting to use a previously used
        source triggers the used_source protocol error.

        To unset the primary selection, set the source to NULL.

        The compositor will ignore this request if it does not support primary
        selection.

        :param source:
        :type source:
            :class:`~pywayland.protocol.ext_data_control_v1.ExtDataControlSourceV1` or `None`
        """
        self._marshal(2, source)


class ExtDataControlManagerV1Proxy(Proxy[ExtDataControlManagerV1]):
    interface = ExtDataControlManagerV1

    @ExtDataControlManagerV1.request(
        Argument(ArgumentType.NewId, interface=ExtDataControlSourceV1),
    )
    def create_data_source(self) -> ExtDataControlSourceV1Proxy:
        """Create a new data source

        Create a new data source.

        :returns:
            :class:`~pywayland.protocol.ext_data_control_v1.ExtDataControlSourceV1`
            -- data source to create
        """
        id = self._marshal_constructor(0, ExtDataControlSourceV1)
        return id

    @ExtDataControlManagerV1.request(
        Argument(ArgumentType.NewId, interface=ExtDataControlDeviceV1),
        Argument(ArgumentType.Object, interface=WlSeat),
    )
    def get_data_device(self, seat: WlSeatProxy) -> ExtDataControlDeviceV1Proxy:
        """Get a data device for a seat

        Create a data device that can be used to manage a seat's selection.

        :param seat:
        :type seat:
            :class:`~pywayland.protocol.wayland.WlSeat`
        :returns:
            :class:`~pywayland.protocol.ext_data_control_v1.ExtDataControlDeviceV1`
        """
        id = self._marshal_constructor(1, ExtDataControlDeviceV1, seat)
        return id

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

        All objects created by the manager will still remain valid, until their
        appropriate destroy request has been called.
        """
        self._marshal(2)
        self._destroy()


class ExtDataControlOfferV1Proxy(Proxy[ExtDataControlOfferV1]):
    interface = ExtDataControlOfferV1

    @ExtDataControlOfferV1.request(
        Argument(ArgumentType.String),
        Argument(ArgumentType.FileDescriptor),
    )
    def receive(self, mime_type: str, fd: int) -> None:
        """Request that the data is transferred

        To transfer the offered data, the client issues this request and
        indicates the MIME type it wants to receive. The transfer happens
        through the passed file descriptor (typically created with the pipe
        system call). The source client writes the data in the MIME type
        representation requested and then closes the file descriptor.

        The receiving client reads from the read end of the pipe until EOF and
        then closes its end, at which point the transfer is complete.

        This request may happen multiple times for different MIME types.

        :param mime_type:
            MIME type desired by receiver
        :type mime_type:
            `ArgumentType.String`
        :param fd:
            file descriptor for data transfer
        :type fd:
            `ArgumentType.FileDescriptor`
        """
        self._marshal(0, mime_type, fd)

    @ExtDataControlOfferV1.request()
    def destroy(self) -> None:
        """Destroy this offer

        Destroys the data offer object.
        """
        self._marshal(1)
        self._destroy()


class ExtDataControlSourceV1Proxy(Proxy[ExtDataControlSourceV1]):
    interface = ExtDataControlSourceV1

    @ExtDataControlSourceV1.request(
        Argument(ArgumentType.String),
    )
    def offer(self, mime_type: str) -> None:
        """Add an offered mime type

        This request adds a MIME type to the set of MIME types advertised to
        targets. Can be called several times to offer multiple types.

        Calling this after ext_data_control_device.set_selection is a protocol
        error.

        :param mime_type:
            MIME type offered by the data source
        :type mime_type:
            `ArgumentType.String`
        """
        self._marshal(0, mime_type)

    @ExtDataControlSourceV1.request()
    def destroy(self) -> None:
        """Destroy this source

        Destroys the data source object.
        """
        self._marshal(1)
        self._destroy()


class ExtDataControlDeviceV1Global(Global[ExtDataControlDeviceV1]):
    interface = ExtDataControlDeviceV1


class ExtDataControlManagerV1Global(Global[ExtDataControlManagerV1]):
    interface = ExtDataControlManagerV1


class ExtDataControlOfferV1Global(Global[ExtDataControlOfferV1]):
    interface = ExtDataControlOfferV1


class ExtDataControlSourceV1Global(Global[ExtDataControlSourceV1]):
    interface = ExtDataControlSourceV1


ExtDataControlDeviceV1._gen_c()
ExtDataControlDeviceV1.proxy_class = ExtDataControlDeviceV1Proxy
ExtDataControlDeviceV1.resource_class = ExtDataControlDeviceV1Resource
ExtDataControlDeviceV1.global_class = ExtDataControlDeviceV1Global


ExtDataControlManagerV1._gen_c()
ExtDataControlManagerV1.proxy_class = ExtDataControlManagerV1Proxy
ExtDataControlManagerV1.resource_class = ExtDataControlManagerV1Resource
ExtDataControlManagerV1.global_class = ExtDataControlManagerV1Global


ExtDataControlOfferV1._gen_c()
ExtDataControlOfferV1.proxy_class = ExtDataControlOfferV1Proxy
ExtDataControlOfferV1.resource_class = ExtDataControlOfferV1Resource
ExtDataControlOfferV1.global_class = ExtDataControlOfferV1Global


ExtDataControlSourceV1._gen_c()
ExtDataControlSourceV1.proxy_class = ExtDataControlSourceV1Proxy
ExtDataControlSourceV1.resource_class = ExtDataControlSourceV1Resource
ExtDataControlSourceV1.global_class = ExtDataControlSourceV1Global
