# This file has been autogenerated by the pywayland scanner

# Copyright 2018 Mike Blumenkrantz
# Copyright 2018 Samsung Electronics Co., Ltd
# Copyright 2018 Red Hat Inc.
#
# 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 .xdg_shell import XdgToplevel
from .xdg_shell import XdgToplevelProxy


class XdgSessionManagerV1(Interface):
    """Manage sessions for applications

    The :class:`XdgSessionManagerV1` interface defines base requests for
    creating and managing a session for an application. Sessions persist across
    application and compositor restarts unless explicitly destroyed. A session
    is created for the purpose of maintaining an application's
    :class:`~pywayland.protocol.xdg_shell.XdgToplevel` surfaces across
    compositor or application restarts. The compositor should remember as many
    states as possible for surfaces in a given session, but there is no
    requirement for which states must be remembered.

    Policies such as cache eviction are declared an implementation detail of
    the compositor. Clients should account for no longer existing sessions.
    """

    name = "xdg_session_manager_v1"
    version = 1

    class error(enum.IntEnum):
        in_use = 1
        invalid_session_id = 2
        invalid_reason = 3

    class reason(enum.IntEnum):
        launch = 1
        recover = 2
        session_restore = 3


class XdgSessionV1(Interface):
    """A session for an application

    A :class:`XdgSessionV1` object represents a session for an application.
    While the object exists, all surfaces which have been added to the session
    will have states stored by the compositor which can be reapplied at a later
    time. Two sessions cannot exist for the same identifier string.

    States for surfaces added to a session are automatically updated by the
    compositor when they are changed.
    """

    name = "xdg_session_v1"
    version = 1

    class error(enum.IntEnum):
        name_in_use = 1
        already_mapped = 2
        invalid_name = 3
        already_added = 4


class XdgToplevelSessionV1(Interface):
    """A session for an application

    A :class:`XdgToplevelSessionV1` resource acts as a handle for the given
    toplevel in the session. It allows for receiving events after a toplevel
    state was restored, and has the requests to manage them.
    """

    name = "xdg_toplevel_session_v1"
    version = 1


class XdgSessionManagerV1Resource(Resource[XdgSessionManagerV1]):
    interface = XdgSessionManagerV1


class XdgSessionV1Resource(Resource[XdgSessionV1]):
    interface = XdgSessionV1

    @XdgSessionV1.event(
        Argument(ArgumentType.String),
    )
    def created(self, session_id: str) -> None:
        """Newly-created session id

        Emitted at most once some time after getting a new session object. It
        means that no previous state was restored, and a new session was
        created. The passed id can be persistently stored and used to restore
        previous sessions.

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

    @XdgSessionV1.event()
    def restored(self) -> None:
        """The session has been restored

        Emitted at most once some time after getting a new session object. It
        means that previous state was at least partially restored. The same id
        can again be used to restore previous sessions.
        """
        self._post_event(1)

    @XdgSessionV1.event()
    def replaced(self) -> None:
        """The session has been replaced

        Emitted at most once, if the session was taken over by some other
        client. When this happens, the session and all its toplevel session
        objects become inert, and should be destroyed.
        """
        self._post_event(2)


class XdgToplevelSessionV1Resource(Resource[XdgToplevelSessionV1]):
    interface = XdgToplevelSessionV1

    @XdgToplevelSessionV1.event()
    def restored(self) -> None:
        """A toplevel's session has been restored

        The "restored" event is emitted prior to the first
        :func:`XdgToplevel.configure()
        <pywayland.protocol.xdg_shell.XdgToplevel.configure>` for the toplevel.
        It will only be emitted after :func:`XdgSessionV1.restore_toplevel()
        <pywayland.protocol.xdg_session_management_v1.XdgSessionV1.restore_toplevel>`,
        and the initial empty surface state has been applied, and it indicates
        that the surface's session is being restored with this configure event.
        """
        self._post_event(0)


class XdgSessionManagerV1Proxy(Proxy[XdgSessionManagerV1]):
    interface = XdgSessionManagerV1

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

        Destroy the manager object. The existing session objects will be
        unaffected.
        """
        self._marshal(0)
        self._destroy()

    @XdgSessionManagerV1.request(
        Argument(ArgumentType.NewId, interface=XdgSessionV1),
        Argument(ArgumentType.Uint),
        Argument(ArgumentType.String, nullable=True),
    )
    def get_session(self, reason: int, session_id: str | None) -> XdgSessionV1Proxy:
        """Create or restore a session

        Create a session object corresponding to either an existing session
        identified by the given session identifier string or a new session.
        While the session object exists, the session is considered to be "in
        use".

        If an identifier string represents a session that is currently actively
        in use by the the same client, an 'in_use' error is raised. If some
        other client is currently using the same session, the new session will
        replace managing the associated state.

        If the reason is not a valid enum entry, the 'invalid_reason' protocol
        error is raised.

        NULL is passed to initiate a new session. If a session_id is passed
        which does not represent a valid session, the compositor treats it as
        if NULL had been passed.

        The session id string must be UTF-8 encoded. It is also limited by the
        maximum length of wayland messages (around 4KB). The
        'invalid_session_id' protocol error will be raised if an invalid string
        is provided.

        A client is allowed to have any number of in use sessions at the same
        time.

        :param reason:
            reason for session
        :type reason:
            `ArgumentType.Uint`
        :param session_id:
            the session to restore
        :type session_id:
            `ArgumentType.String` or `None`
        :returns:
            :class:`~pywayland.protocol.xdg_session_management_v1.XdgSessionV1`
        """
        id = self._marshal_constructor(1, XdgSessionV1, reason, session_id)
        return id


class XdgSessionV1Proxy(Proxy[XdgSessionV1]):
    interface = XdgSessionV1

    @XdgSessionV1.request()
    def destroy(self) -> None:
        """Destroy the session

        Destroy a session object, preserving the current state but not
        continuing to make further updates if state changes occur. This makes
        the associated
        :class:`~pywayland.protocol.xdg_session_management_v1.XdgToplevelSessionV1`
        objects inert.
        """
        self._marshal(0)
        self._destroy()

    @XdgSessionV1.request()
    def remove(self) -> None:
        """Remove the session

        Remove the session, making it no longer available for restoration. A
        compositor should in response to this request remove the data related
        to this session from its storage.
        """
        self._marshal(1)
        self._destroy()

    @XdgSessionV1.request(
        Argument(ArgumentType.NewId, interface=XdgToplevelSessionV1),
        Argument(ArgumentType.Object, interface=XdgToplevel),
        Argument(ArgumentType.String),
    )
    def add_toplevel(self, toplevel: XdgToplevelProxy, name: str) -> XdgToplevelSessionV1Proxy:
        """Add a new surface to the session

        Attempt to add a given surface to the session. The passed name is used
        to identify what window is being restored, and may be used to store
        window specific state within the session.

        The name given to the toplevel must not correspond to any previously
        existing toplevel names in the session. If the name matches an already
        known toplevel name in the session, a 'name_in_use' protocol error will
        be raised.

        The toplevel object must not be added more than once to any session
        created by the client, otherwise the 'already_added' protocol error
        will be raised.

        This request will return a
        :class:`~pywayland.protocol.xdg_session_management_v1.XdgToplevelSessionV1`
        for later manipulation. As this resource is created from an empty
        initial state, compositors must not emit a
        :func:`XdgToplevelSessionV1.restored()
        <pywayland.protocol.xdg_session_management_v1.XdgToplevelSessionV1.restored>`
        event for resources created through this request.

        The name string must be UTF-8 encoded. It is also limited by the
        maximum length of wayland messages (around 4KB). The 'invalid_name'
        protocol error will be raised if an invalid string is provided.

        :param toplevel:
        :type toplevel:
            :class:`~pywayland.protocol.xdg_shell.XdgToplevel`
        :param name:
            name identifying the toplevel
        :type name:
            `ArgumentType.String`
        :returns:
            :class:`~pywayland.protocol.xdg_session_management_v1.XdgToplevelSessionV1`
        """
        id = self._marshal_constructor(2, XdgToplevelSessionV1, toplevel, name)
        return id

    @XdgSessionV1.request(
        Argument(ArgumentType.NewId, interface=XdgToplevelSessionV1),
        Argument(ArgumentType.Object, interface=XdgToplevel),
        Argument(ArgumentType.String),
    )
    def restore_toplevel(self, toplevel: XdgToplevelProxy, name: str) -> XdgToplevelSessionV1Proxy:
        """Restore a surface state

        Inform the compositor that the toplevel associated with the passed name
        should have its window management state restored.

        If the toplevel name was previously granted to another
        :class:`~pywayland.protocol.xdg_shell.XdgToplevel`, the 'name_in_use'
        protocol error will be raised.

        The toplevel object must not be added more than once to any session
        created by the client, otherwise the 'already_added' protocol error
        will be raised.

        This request must be called prior to the first commit on the associated
        :class:`~pywayland.protocol.wayland.WlSurface` after creating the
        toplevel, otherwise an 'already_mapped' error is raised.

        As part of the initial configure sequence, if the toplevel was
        successfully restored, a :func:`XdgToplevelSessionV1.restored()
        <pywayland.protocol.xdg_session_management_v1.XdgToplevelSessionV1.restored>`
        event is emitted. If the toplevel name was not known in the session,
        this request will be equivalent to the
        :func:`XdgToplevelSessionV1.add_toplevel()
        <pywayland.protocol.xdg_session_management_v1.XdgToplevelSessionV1.add_toplevel>`
        request, and no such event will be emitted. See the
        :func:`XdgToplevelSessionV1.restored()
        <pywayland.protocol.xdg_session_management_v1.XdgToplevelSessionV1.restored>`
        event for further details.

        The name string must be UTF-8 encoded. It is also limited by the
        maximum length of wayland messages (around 4KB). The 'invalid_name'
        protocol error will be raised if an invalid string is provided.

        :param toplevel:
        :type toplevel:
            :class:`~pywayland.protocol.xdg_shell.XdgToplevel`
        :param name:
            name identifying the toplevel
        :type name:
            `ArgumentType.String`
        :returns:
            :class:`~pywayland.protocol.xdg_session_management_v1.XdgToplevelSessionV1`
        """
        id = self._marshal_constructor(3, XdgToplevelSessionV1, toplevel, name)
        return id

    @XdgSessionV1.request(
        Argument(ArgumentType.String),
    )
    def remove_toplevel(self, name: str) -> None:
        """Remove a surface from the session

        Remove a specified surface from the session and render any related
        :class:`~pywayland.protocol.xdg_session_management_v1.XdgToplevelSessionV1`
        object inert. The compositor should remove any data related to the
        toplevel in the corresponding session from its internal storage.

        The window is specified by its name in the session. The name string
        must be encoded in UTF-8, and it is limited in size by the maximum
        length of wayland messages (around 4KB).

        :param name:
            name identifying the toplevel
        :type name:
            `ArgumentType.String`
        """
        self._marshal(4, name)


class XdgToplevelSessionV1Proxy(Proxy[XdgToplevelSessionV1]):
    interface = XdgToplevelSessionV1

    @XdgToplevelSessionV1.request()
    def destroy(self) -> None:
        """Destroy the object

        Destroy the object. This has no effect over window management of the
        associated toplevel.
        """
        self._marshal(0)
        self._destroy()

    @XdgToplevelSessionV1.request(
        Argument(ArgumentType.String),
    )
    def rename(self, name: str) -> None:
        """Change the name of toplevel session

        Renames the toplevel session. The new name can be used in subsequent
        requests to identify this session object. The state associated with
        this toplevel session will be preserved.

        If the
        :class:`~pywayland.protocol.xdg_session_management_v1.XdgSessionV1`
        already contains a toplevel with the specified name, the 'name_in_use'
        protocol error will be raised.

        :param name:
            new name to identify the toplevel
        :type name:
            `ArgumentType.String`
        """
        self._marshal(1, name)


class XdgSessionManagerV1Global(Global[XdgSessionManagerV1]):
    interface = XdgSessionManagerV1


class XdgSessionV1Global(Global[XdgSessionV1]):
    interface = XdgSessionV1


class XdgToplevelSessionV1Global(Global[XdgToplevelSessionV1]):
    interface = XdgToplevelSessionV1


XdgSessionManagerV1._gen_c()
XdgSessionManagerV1.proxy_class = XdgSessionManagerV1Proxy
XdgSessionManagerV1.resource_class = XdgSessionManagerV1Resource
XdgSessionManagerV1.global_class = XdgSessionManagerV1Global


XdgSessionV1._gen_c()
XdgSessionV1.proxy_class = XdgSessionV1Proxy
XdgSessionV1.resource_class = XdgSessionV1Resource
XdgSessionV1.global_class = XdgSessionV1Global


XdgToplevelSessionV1._gen_c()
XdgToplevelSessionV1.proxy_class = XdgToplevelSessionV1Proxy
XdgToplevelSessionV1.resource_class = XdgToplevelSessionV1Resource
XdgToplevelSessionV1.global_class = XdgToplevelSessionV1Global
