// This file was generated by qtwaylandscanner
// source file is //usr/share/wayland-protocols/staging/xdg-activation/xdg-activation-v1.xml

#include "qwayland-server-xdg-activation-v1.h"

QT_BEGIN_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wmissing-field-initializers")

namespace QtWaylandServer {

    int xdg_activation_v1::deferred_destroy_global_func(void *data) {
        auto object = static_cast<xdg_activation_v1 *>(data);
        wl_global_destroy(object->m_global);
        object->m_global = nullptr;
        wl_event_source_remove(object->m_globalRemovedEvent);
        object->m_globalRemovedEvent = nullptr;
        wl_list_remove(&object->m_displayDestroyedListener.link);
        object->xdg_activation_v1_destroy_global();
        return 0;
    }

    xdg_activation_v1::xdg_activation_v1(struct ::wl_client *client, int id, int version)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
        , m_display(nullptr)
        , m_globalRemovedEvent(nullptr)
    {
        init(client, id, version);
    }

    xdg_activation_v1::xdg_activation_v1(struct ::wl_display *display, int version)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
        , m_display(nullptr)
        , m_globalRemovedEvent(nullptr)
    {
        init(display, version);
    }

    xdg_activation_v1::xdg_activation_v1(struct ::wl_resource *resource)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
        , m_display(nullptr)
        , m_globalRemovedEvent(nullptr)
    {
        init(resource);
    }

    xdg_activation_v1::xdg_activation_v1()
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
        , m_display(nullptr)
        , m_globalRemovedEvent(nullptr)
    {
    }

    xdg_activation_v1::~xdg_activation_v1()
    {
        for (auto resource : std::as_const(m_resource_map))
            resource->xdg_activation_v1_object = nullptr;

        if (m_resource)
            m_resource->xdg_activation_v1_object = nullptr;

        if (m_global) {
            if (m_globalRemovedEvent)
                wl_event_source_remove(m_globalRemovedEvent);
            wl_global_destroy(m_global);
            wl_list_remove(&m_displayDestroyedListener.link);
        }
    }

    void xdg_activation_v1::init(struct ::wl_client *client, int id, int version)
    {
        m_resource = bind(client, id, version);
    }

    void xdg_activation_v1::init(struct ::wl_resource *resource)
    {
        m_resource = bind(resource);
    }

    xdg_activation_v1::Resource *xdg_activation_v1::add(struct ::wl_client *client, int version)
    {
        Resource *resource = bind(client, 0, version);
        m_resource_map.insert(client, resource);
        return resource;
    }

    xdg_activation_v1::Resource *xdg_activation_v1::add(struct ::wl_client *client, int id, int version)
    {
        Resource *resource = bind(client, id, version);
        m_resource_map.insert(client, resource);
        return resource;
    }

    void xdg_activation_v1::init(struct ::wl_display *display, int version)
    {
        m_display = display;
        m_global = wl_global_create(display, &::xdg_activation_v1_interface, version, this, bind_func);
        m_displayDestroyedListener.notify = xdg_activation_v1::display_destroy_func;
        m_displayDestroyedListener.parent = this;
        wl_display_add_destroy_listener(display, &m_displayDestroyedListener);
    }

    const struct wl_interface *xdg_activation_v1::interface()
    {
        return &::xdg_activation_v1_interface;
    }

    xdg_activation_v1::Resource *xdg_activation_v1::xdg_activation_v1_allocate()
    {
        return new Resource;
    }

    void xdg_activation_v1::xdg_activation_v1_destroy_global()
    {
    }

    void xdg_activation_v1::xdg_activation_v1_bind_resource(Resource *)
    {
    }

    void xdg_activation_v1::xdg_activation_v1_destroy_resource(Resource *)
    {
    }

    void xdg_activation_v1::bind_func(struct ::wl_client *client, void *data, uint32_t version, uint32_t id)
    {
        xdg_activation_v1 *that = static_cast<xdg_activation_v1 *>(data);
        that->add(client, id, version);
    }

    void xdg_activation_v1::display_destroy_func(struct ::wl_listener *listener, void *data)
    {
        Q_UNUSED(data);
        xdg_activation_v1 *that = static_cast<xdg_activation_v1::DisplayDestroyedListener *>(listener)->parent;
        that->m_global = nullptr;
        that->m_globalRemovedEvent = nullptr;
    }

    void xdg_activation_v1::destroy_func(struct ::wl_resource *client_resource)
    {
        Resource *resource = Resource::fromResource(client_resource);
        Q_ASSERT(resource);
        xdg_activation_v1 *that = resource->xdg_activation_v1_object;
        if (Q_LIKELY(that)) {
            that->m_resource_map.remove(resource->client(), resource);
            that->xdg_activation_v1_destroy_resource(resource);

            that = resource->xdg_activation_v1_object;
            if (that && that->m_resource == resource)
                that->m_resource = nullptr;
        }
        delete resource;
    }


    void xdg_activation_v1::globalRemove()
    {
        if (!m_global || m_globalRemovedEvent)
            return;

        wl_global_remove(m_global);

        struct wl_event_loop *event_loop = wl_display_get_event_loop(m_display);
        m_globalRemovedEvent = wl_event_loop_add_timer(event_loop, deferred_destroy_global_func, this);
        wl_event_source_timer_update(m_globalRemovedEvent, 10000);
    }

    xdg_activation_v1::Resource *xdg_activation_v1::bind(struct ::wl_client *client, uint32_t id, int version)
    {
        Q_ASSERT_X(!wl_client_get_object(client, id), "QWaylandObject bind", QStringLiteral("binding to object %1 more than once").arg(id).toLocal8Bit().constData());
        struct ::wl_resource *handle = wl_resource_create(client, &::xdg_activation_v1_interface, version, id);
        return bind(handle);
    }

    xdg_activation_v1::Resource *xdg_activation_v1::bind(struct ::wl_resource *handle)
    {
        Resource *resource = xdg_activation_v1_allocate();
        resource->xdg_activation_v1_object = this;

        wl_resource_set_implementation(handle, &m_xdg_activation_v1_interface, resource, destroy_func);
        resource->handle = handle;
        xdg_activation_v1_bind_resource(resource);
        return resource;
    }
    xdg_activation_v1::Resource *xdg_activation_v1::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::xdg_activation_v1_interface, &m_xdg_activation_v1_interface))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    const struct ::xdg_activation_v1_interface xdg_activation_v1::m_xdg_activation_v1_interface = {
        xdg_activation_v1::handle_destroy,
        xdg_activation_v1::handle_get_activation_token,
        xdg_activation_v1::handle_activate
    };

    void xdg_activation_v1::xdg_activation_v1_destroy(Resource *)
    {
    }

    void xdg_activation_v1::xdg_activation_v1_get_activation_token(Resource *, uint32_t)
    {
    }

    void xdg_activation_v1::xdg_activation_v1_activate(Resource *, const QString &, struct ::wl_resource *)
    {
    }


    void xdg_activation_v1::handle_destroy(
        ::wl_client *client,
        struct wl_resource *resource)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->xdg_activation_v1_object)) {
            wl_resource_destroy(resource);
            return;
        }
        static_cast<xdg_activation_v1 *>(r->xdg_activation_v1_object)->xdg_activation_v1_destroy(
            r);
    }

    void xdg_activation_v1::handle_get_activation_token(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t id)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->xdg_activation_v1_object)) {
            return;
        }
        static_cast<xdg_activation_v1 *>(r->xdg_activation_v1_object)->xdg_activation_v1_get_activation_token(
            r,
            id);
    }

    void xdg_activation_v1::handle_activate(
        ::wl_client *client,
        struct wl_resource *resource,
        const char *token,
        struct ::wl_resource *surface)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->xdg_activation_v1_object)) {
            return;
        }
        static_cast<xdg_activation_v1 *>(r->xdg_activation_v1_object)->xdg_activation_v1_activate(
            r,
            QString::fromUtf8(token),
            surface);
    }


    int xdg_activation_token_v1::deferred_destroy_global_func(void *data) {
        auto object = static_cast<xdg_activation_token_v1 *>(data);
        wl_global_destroy(object->m_global);
        object->m_global = nullptr;
        wl_event_source_remove(object->m_globalRemovedEvent);
        object->m_globalRemovedEvent = nullptr;
        wl_list_remove(&object->m_displayDestroyedListener.link);
        object->xdg_activation_token_v1_destroy_global();
        return 0;
    }

    xdg_activation_token_v1::xdg_activation_token_v1(struct ::wl_client *client, int id, int version)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
        , m_display(nullptr)
        , m_globalRemovedEvent(nullptr)
    {
        init(client, id, version);
    }

    xdg_activation_token_v1::xdg_activation_token_v1(struct ::wl_display *display, int version)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
        , m_display(nullptr)
        , m_globalRemovedEvent(nullptr)
    {
        init(display, version);
    }

    xdg_activation_token_v1::xdg_activation_token_v1(struct ::wl_resource *resource)
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
        , m_display(nullptr)
        , m_globalRemovedEvent(nullptr)
    {
        init(resource);
    }

    xdg_activation_token_v1::xdg_activation_token_v1()
        : m_resource_map()
        , m_resource(nullptr)
        , m_global(nullptr)
        , m_display(nullptr)
        , m_globalRemovedEvent(nullptr)
    {
    }

    xdg_activation_token_v1::~xdg_activation_token_v1()
    {
        for (auto resource : std::as_const(m_resource_map))
            resource->xdg_activation_token_v1_object = nullptr;

        if (m_resource)
            m_resource->xdg_activation_token_v1_object = nullptr;

        if (m_global) {
            if (m_globalRemovedEvent)
                wl_event_source_remove(m_globalRemovedEvent);
            wl_global_destroy(m_global);
            wl_list_remove(&m_displayDestroyedListener.link);
        }
    }

    void xdg_activation_token_v1::init(struct ::wl_client *client, int id, int version)
    {
        m_resource = bind(client, id, version);
    }

    void xdg_activation_token_v1::init(struct ::wl_resource *resource)
    {
        m_resource = bind(resource);
    }

    xdg_activation_token_v1::Resource *xdg_activation_token_v1::add(struct ::wl_client *client, int version)
    {
        Resource *resource = bind(client, 0, version);
        m_resource_map.insert(client, resource);
        return resource;
    }

    xdg_activation_token_v1::Resource *xdg_activation_token_v1::add(struct ::wl_client *client, int id, int version)
    {
        Resource *resource = bind(client, id, version);
        m_resource_map.insert(client, resource);
        return resource;
    }

    void xdg_activation_token_v1::init(struct ::wl_display *display, int version)
    {
        m_display = display;
        m_global = wl_global_create(display, &::xdg_activation_token_v1_interface, version, this, bind_func);
        m_displayDestroyedListener.notify = xdg_activation_token_v1::display_destroy_func;
        m_displayDestroyedListener.parent = this;
        wl_display_add_destroy_listener(display, &m_displayDestroyedListener);
    }

    const struct wl_interface *xdg_activation_token_v1::interface()
    {
        return &::xdg_activation_token_v1_interface;
    }

    xdg_activation_token_v1::Resource *xdg_activation_token_v1::xdg_activation_token_v1_allocate()
    {
        return new Resource;
    }

    void xdg_activation_token_v1::xdg_activation_token_v1_destroy_global()
    {
    }

    void xdg_activation_token_v1::xdg_activation_token_v1_bind_resource(Resource *)
    {
    }

    void xdg_activation_token_v1::xdg_activation_token_v1_destroy_resource(Resource *)
    {
    }

    void xdg_activation_token_v1::bind_func(struct ::wl_client *client, void *data, uint32_t version, uint32_t id)
    {
        xdg_activation_token_v1 *that = static_cast<xdg_activation_token_v1 *>(data);
        that->add(client, id, version);
    }

    void xdg_activation_token_v1::display_destroy_func(struct ::wl_listener *listener, void *data)
    {
        Q_UNUSED(data);
        xdg_activation_token_v1 *that = static_cast<xdg_activation_token_v1::DisplayDestroyedListener *>(listener)->parent;
        that->m_global = nullptr;
        that->m_globalRemovedEvent = nullptr;
    }

    void xdg_activation_token_v1::destroy_func(struct ::wl_resource *client_resource)
    {
        Resource *resource = Resource::fromResource(client_resource);
        Q_ASSERT(resource);
        xdg_activation_token_v1 *that = resource->xdg_activation_token_v1_object;
        if (Q_LIKELY(that)) {
            that->m_resource_map.remove(resource->client(), resource);
            that->xdg_activation_token_v1_destroy_resource(resource);

            that = resource->xdg_activation_token_v1_object;
            if (that && that->m_resource == resource)
                that->m_resource = nullptr;
        }
        delete resource;
    }


    void xdg_activation_token_v1::globalRemove()
    {
        if (!m_global || m_globalRemovedEvent)
            return;

        wl_global_remove(m_global);

        struct wl_event_loop *event_loop = wl_display_get_event_loop(m_display);
        m_globalRemovedEvent = wl_event_loop_add_timer(event_loop, deferred_destroy_global_func, this);
        wl_event_source_timer_update(m_globalRemovedEvent, 10000);
    }

    xdg_activation_token_v1::Resource *xdg_activation_token_v1::bind(struct ::wl_client *client, uint32_t id, int version)
    {
        Q_ASSERT_X(!wl_client_get_object(client, id), "QWaylandObject bind", QStringLiteral("binding to object %1 more than once").arg(id).toLocal8Bit().constData());
        struct ::wl_resource *handle = wl_resource_create(client, &::xdg_activation_token_v1_interface, version, id);
        return bind(handle);
    }

    xdg_activation_token_v1::Resource *xdg_activation_token_v1::bind(struct ::wl_resource *handle)
    {
        Resource *resource = xdg_activation_token_v1_allocate();
        resource->xdg_activation_token_v1_object = this;

        wl_resource_set_implementation(handle, &m_xdg_activation_token_v1_interface, resource, destroy_func);
        resource->handle = handle;
        xdg_activation_token_v1_bind_resource(resource);
        return resource;
    }
    xdg_activation_token_v1::Resource *xdg_activation_token_v1::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::xdg_activation_token_v1_interface, &m_xdg_activation_token_v1_interface))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    const struct ::xdg_activation_token_v1_interface xdg_activation_token_v1::m_xdg_activation_token_v1_interface = {
        xdg_activation_token_v1::handle_set_serial,
        xdg_activation_token_v1::handle_set_app_id,
        xdg_activation_token_v1::handle_set_surface,
        xdg_activation_token_v1::handle_commit,
        xdg_activation_token_v1::handle_destroy
    };

    void xdg_activation_token_v1::xdg_activation_token_v1_set_serial(Resource *, uint32_t , struct ::wl_resource *)
    {
    }

    void xdg_activation_token_v1::xdg_activation_token_v1_set_app_id(Resource *, const QString &)
    {
    }

    void xdg_activation_token_v1::xdg_activation_token_v1_set_surface(Resource *, struct ::wl_resource *)
    {
    }

    void xdg_activation_token_v1::xdg_activation_token_v1_commit(Resource *)
    {
    }

    void xdg_activation_token_v1::xdg_activation_token_v1_destroy(Resource *)
    {
    }


    void xdg_activation_token_v1::handle_set_serial(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t serial,
        struct ::wl_resource *seat)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->xdg_activation_token_v1_object)) {
            return;
        }
        static_cast<xdg_activation_token_v1 *>(r->xdg_activation_token_v1_object)->xdg_activation_token_v1_set_serial(
            r,
            serial,
            seat);
    }

    void xdg_activation_token_v1::handle_set_app_id(
        ::wl_client *client,
        struct wl_resource *resource,
        const char *app_id)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->xdg_activation_token_v1_object)) {
            return;
        }
        static_cast<xdg_activation_token_v1 *>(r->xdg_activation_token_v1_object)->xdg_activation_token_v1_set_app_id(
            r,
            QString::fromUtf8(app_id));
    }

    void xdg_activation_token_v1::handle_set_surface(
        ::wl_client *client,
        struct wl_resource *resource,
        struct ::wl_resource *surface)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->xdg_activation_token_v1_object)) {
            return;
        }
        static_cast<xdg_activation_token_v1 *>(r->xdg_activation_token_v1_object)->xdg_activation_token_v1_set_surface(
            r,
            surface);
    }

    void xdg_activation_token_v1::handle_commit(
        ::wl_client *client,
        struct wl_resource *resource)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->xdg_activation_token_v1_object)) {
            return;
        }
        static_cast<xdg_activation_token_v1 *>(r->xdg_activation_token_v1_object)->xdg_activation_token_v1_commit(
            r);
    }

    void xdg_activation_token_v1::handle_destroy(
        ::wl_client *client,
        struct wl_resource *resource)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->xdg_activation_token_v1_object)) {
            wl_resource_destroy(resource);
            return;
        }
        static_cast<xdg_activation_token_v1 *>(r->xdg_activation_token_v1_object)->xdg_activation_token_v1_destroy(
            r);
    }

    void xdg_activation_token_v1::send_done(const QString &token)
    {
        Q_ASSERT_X(m_resource, "xdg_activation_token_v1::done", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call xdg_activation_token_v1::done as it's not initialised");
            return;
        }
        send_done(
            m_resource->handle,
            token);
    }

    void xdg_activation_token_v1::send_done(struct ::wl_resource *resource, const QString &token)
    {
        xdg_activation_token_v1_send_done(
            resource,
            token.toUtf8().constData());
    }

}

QT_WARNING_POP
QT_END_NAMESPACE
