// This file was generated by qtwaylandscanner
// source file is wlr-data-control-unstable-v1.xml

#include "qwayland-server-wlr-data-control-unstable-v1.h"

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

namespace QtWaylandServer {

    int zwlr_data_control_manager_v1::deferred_destroy_global_func(void *data) {
        auto object = static_cast<zwlr_data_control_manager_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->zwlr_data_control_manager_v1_destroy_global();
        return 0;
    }

    zwlr_data_control_manager_v1::zwlr_data_control_manager_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);
    }

    zwlr_data_control_manager_v1::zwlr_data_control_manager_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);
    }

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

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

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

        if (m_resource)
            m_resource->zwlr_data_control_manager_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 zwlr_data_control_manager_v1::init(struct ::wl_client *client, int id, int version)
    {
        m_resource = bind(client, id, version);
    }

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

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

    zwlr_data_control_manager_v1::Resource *zwlr_data_control_manager_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 zwlr_data_control_manager_v1::init(struct ::wl_display *display, int version)
    {
        m_display = display;
        m_global = wl_global_create(display, &::zwlr_data_control_manager_v1_interface, version, this, bind_func);
        m_displayDestroyedListener.notify = zwlr_data_control_manager_v1::display_destroy_func;
        m_displayDestroyedListener.parent = this;
        wl_display_add_destroy_listener(display, &m_displayDestroyedListener);
    }

    const struct wl_interface *zwlr_data_control_manager_v1::interface()
    {
        return &::zwlr_data_control_manager_v1_interface;
    }

    zwlr_data_control_manager_v1::Resource *zwlr_data_control_manager_v1::zwlr_data_control_manager_v1_allocate()
    {
        return new Resource;
    }

    void zwlr_data_control_manager_v1::zwlr_data_control_manager_v1_destroy_global()
    {
    }

    void zwlr_data_control_manager_v1::zwlr_data_control_manager_v1_bind_resource(Resource *)
    {
    }

    void zwlr_data_control_manager_v1::zwlr_data_control_manager_v1_destroy_resource(Resource *)
    {
    }

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

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

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

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


    void zwlr_data_control_manager_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, 5000);
    }

    zwlr_data_control_manager_v1::Resource *zwlr_data_control_manager_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, &::zwlr_data_control_manager_v1_interface, version, id);
        return bind(handle);
    }

    zwlr_data_control_manager_v1::Resource *zwlr_data_control_manager_v1::bind(struct ::wl_resource *handle)
    {
        Resource *resource = zwlr_data_control_manager_v1_allocate();
        resource->zwlr_data_control_manager_v1_object = this;

        wl_resource_set_implementation(handle, &m_zwlr_data_control_manager_v1_interface, resource, destroy_func);
        resource->handle = handle;
        zwlr_data_control_manager_v1_bind_resource(resource);
        return resource;
    }
    zwlr_data_control_manager_v1::Resource *zwlr_data_control_manager_v1::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::zwlr_data_control_manager_v1_interface, &m_zwlr_data_control_manager_v1_interface))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    const struct ::zwlr_data_control_manager_v1_interface zwlr_data_control_manager_v1::m_zwlr_data_control_manager_v1_interface = {
        zwlr_data_control_manager_v1::handle_create_data_source,
        zwlr_data_control_manager_v1::handle_get_data_device,
        zwlr_data_control_manager_v1::handle_destroy
    };

    void zwlr_data_control_manager_v1::zwlr_data_control_manager_v1_create_data_source(Resource *, uint32_t)
    {
    }

    void zwlr_data_control_manager_v1::zwlr_data_control_manager_v1_get_data_device(Resource *, uint32_t, struct ::wl_resource *)
    {
    }

    void zwlr_data_control_manager_v1::zwlr_data_control_manager_v1_destroy(Resource *)
    {
    }


    void zwlr_data_control_manager_v1::handle_create_data_source(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t id)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->zwlr_data_control_manager_v1_object)) {
            return;
        }
        static_cast<zwlr_data_control_manager_v1 *>(r->zwlr_data_control_manager_v1_object)->zwlr_data_control_manager_v1_create_data_source(
            r,
            id);
    }

    void zwlr_data_control_manager_v1::handle_get_data_device(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t id,
        struct ::wl_resource *seat)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->zwlr_data_control_manager_v1_object)) {
            return;
        }
        static_cast<zwlr_data_control_manager_v1 *>(r->zwlr_data_control_manager_v1_object)->zwlr_data_control_manager_v1_get_data_device(
            r,
            id,
            seat);
    }

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


    int zwlr_data_control_device_v1::deferred_destroy_global_func(void *data) {
        auto object = static_cast<zwlr_data_control_device_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->zwlr_data_control_device_v1_destroy_global();
        return 0;
    }

    zwlr_data_control_device_v1::zwlr_data_control_device_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);
    }

    zwlr_data_control_device_v1::zwlr_data_control_device_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);
    }

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

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

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

        if (m_resource)
            m_resource->zwlr_data_control_device_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 zwlr_data_control_device_v1::init(struct ::wl_client *client, int id, int version)
    {
        m_resource = bind(client, id, version);
    }

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

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

    zwlr_data_control_device_v1::Resource *zwlr_data_control_device_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 zwlr_data_control_device_v1::init(struct ::wl_display *display, int version)
    {
        m_display = display;
        m_global = wl_global_create(display, &::zwlr_data_control_device_v1_interface, version, this, bind_func);
        m_displayDestroyedListener.notify = zwlr_data_control_device_v1::display_destroy_func;
        m_displayDestroyedListener.parent = this;
        wl_display_add_destroy_listener(display, &m_displayDestroyedListener);
    }

    const struct wl_interface *zwlr_data_control_device_v1::interface()
    {
        return &::zwlr_data_control_device_v1_interface;
    }

    zwlr_data_control_device_v1::Resource *zwlr_data_control_device_v1::zwlr_data_control_device_v1_allocate()
    {
        return new Resource;
    }

    void zwlr_data_control_device_v1::zwlr_data_control_device_v1_destroy_global()
    {
    }

    void zwlr_data_control_device_v1::zwlr_data_control_device_v1_bind_resource(Resource *)
    {
    }

    void zwlr_data_control_device_v1::zwlr_data_control_device_v1_destroy_resource(Resource *)
    {
    }

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

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

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

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


    void zwlr_data_control_device_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, 5000);
    }

    zwlr_data_control_device_v1::Resource *zwlr_data_control_device_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, &::zwlr_data_control_device_v1_interface, version, id);
        return bind(handle);
    }

    zwlr_data_control_device_v1::Resource *zwlr_data_control_device_v1::bind(struct ::wl_resource *handle)
    {
        Resource *resource = zwlr_data_control_device_v1_allocate();
        resource->zwlr_data_control_device_v1_object = this;

        wl_resource_set_implementation(handle, &m_zwlr_data_control_device_v1_interface, resource, destroy_func);
        resource->handle = handle;
        zwlr_data_control_device_v1_bind_resource(resource);
        return resource;
    }
    zwlr_data_control_device_v1::Resource *zwlr_data_control_device_v1::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::zwlr_data_control_device_v1_interface, &m_zwlr_data_control_device_v1_interface))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    const struct ::zwlr_data_control_device_v1_interface zwlr_data_control_device_v1::m_zwlr_data_control_device_v1_interface = {
        zwlr_data_control_device_v1::handle_set_selection,
        zwlr_data_control_device_v1::handle_destroy,
        zwlr_data_control_device_v1::handle_set_primary_selection
    };

    void zwlr_data_control_device_v1::zwlr_data_control_device_v1_set_selection(Resource *, struct ::wl_resource *)
    {
    }

    void zwlr_data_control_device_v1::zwlr_data_control_device_v1_destroy(Resource *)
    {
    }

    void zwlr_data_control_device_v1::zwlr_data_control_device_v1_set_primary_selection(Resource *, struct ::wl_resource *)
    {
    }


    void zwlr_data_control_device_v1::handle_set_selection(
        ::wl_client *client,
        struct wl_resource *resource,
        struct ::wl_resource *source)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->zwlr_data_control_device_v1_object)) {
            return;
        }
        static_cast<zwlr_data_control_device_v1 *>(r->zwlr_data_control_device_v1_object)->zwlr_data_control_device_v1_set_selection(
            r,
            source);
    }

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

    void zwlr_data_control_device_v1::handle_set_primary_selection(
        ::wl_client *client,
        struct wl_resource *resource,
        struct ::wl_resource *source)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->zwlr_data_control_device_v1_object)) {
            return;
        }
        static_cast<zwlr_data_control_device_v1 *>(r->zwlr_data_control_device_v1_object)->zwlr_data_control_device_v1_set_primary_selection(
            r,
            source);
    }

    void zwlr_data_control_device_v1::send_data_offer(struct ::wl_resource *id)
    {
        Q_ASSERT_X(m_resource, "zwlr_data_control_device_v1::data_offer", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call zwlr_data_control_device_v1::data_offer as it's not initialised");
            return;
        }
        send_data_offer(
            m_resource->handle,
            id);
    }

    void zwlr_data_control_device_v1::send_data_offer(struct ::wl_resource *resource, struct ::wl_resource *id)
    {
        zwlr_data_control_device_v1_send_data_offer(
            resource,
            id);
    }


    void zwlr_data_control_device_v1::send_selection(struct ::wl_resource *id)
    {
        Q_ASSERT_X(m_resource, "zwlr_data_control_device_v1::selection", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call zwlr_data_control_device_v1::selection as it's not initialised");
            return;
        }
        send_selection(
            m_resource->handle,
            id);
    }

    void zwlr_data_control_device_v1::send_selection(struct ::wl_resource *resource, struct ::wl_resource *id)
    {
        zwlr_data_control_device_v1_send_selection(
            resource,
            id);
    }


    void zwlr_data_control_device_v1::send_finished()
    {
        Q_ASSERT_X(m_resource, "zwlr_data_control_device_v1::finished", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call zwlr_data_control_device_v1::finished as it's not initialised");
            return;
        }
        send_finished(
            m_resource->handle);
    }

    void zwlr_data_control_device_v1::send_finished(struct ::wl_resource *resource)
    {
        zwlr_data_control_device_v1_send_finished(
            resource);
    }


    void zwlr_data_control_device_v1::send_primary_selection(struct ::wl_resource *id)
    {
        Q_ASSERT_X(m_resource, "zwlr_data_control_device_v1::primary_selection", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call zwlr_data_control_device_v1::primary_selection as it's not initialised");
            return;
        }
        send_primary_selection(
            m_resource->handle,
            id);
    }

    void zwlr_data_control_device_v1::send_primary_selection(struct ::wl_resource *resource, struct ::wl_resource *id)
    {
        zwlr_data_control_device_v1_send_primary_selection(
            resource,
            id);
    }



    int zwlr_data_control_source_v1::deferred_destroy_global_func(void *data) {
        auto object = static_cast<zwlr_data_control_source_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->zwlr_data_control_source_v1_destroy_global();
        return 0;
    }

    zwlr_data_control_source_v1::zwlr_data_control_source_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);
    }

    zwlr_data_control_source_v1::zwlr_data_control_source_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);
    }

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

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

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

        if (m_resource)
            m_resource->zwlr_data_control_source_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 zwlr_data_control_source_v1::init(struct ::wl_client *client, int id, int version)
    {
        m_resource = bind(client, id, version);
    }

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

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

    zwlr_data_control_source_v1::Resource *zwlr_data_control_source_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 zwlr_data_control_source_v1::init(struct ::wl_display *display, int version)
    {
        m_display = display;
        m_global = wl_global_create(display, &::zwlr_data_control_source_v1_interface, version, this, bind_func);
        m_displayDestroyedListener.notify = zwlr_data_control_source_v1::display_destroy_func;
        m_displayDestroyedListener.parent = this;
        wl_display_add_destroy_listener(display, &m_displayDestroyedListener);
    }

    const struct wl_interface *zwlr_data_control_source_v1::interface()
    {
        return &::zwlr_data_control_source_v1_interface;
    }

    zwlr_data_control_source_v1::Resource *zwlr_data_control_source_v1::zwlr_data_control_source_v1_allocate()
    {
        return new Resource;
    }

    void zwlr_data_control_source_v1::zwlr_data_control_source_v1_destroy_global()
    {
    }

    void zwlr_data_control_source_v1::zwlr_data_control_source_v1_bind_resource(Resource *)
    {
    }

    void zwlr_data_control_source_v1::zwlr_data_control_source_v1_destroy_resource(Resource *)
    {
    }

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

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

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

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


    void zwlr_data_control_source_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, 5000);
    }

    zwlr_data_control_source_v1::Resource *zwlr_data_control_source_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, &::zwlr_data_control_source_v1_interface, version, id);
        return bind(handle);
    }

    zwlr_data_control_source_v1::Resource *zwlr_data_control_source_v1::bind(struct ::wl_resource *handle)
    {
        Resource *resource = zwlr_data_control_source_v1_allocate();
        resource->zwlr_data_control_source_v1_object = this;

        wl_resource_set_implementation(handle, &m_zwlr_data_control_source_v1_interface, resource, destroy_func);
        resource->handle = handle;
        zwlr_data_control_source_v1_bind_resource(resource);
        return resource;
    }
    zwlr_data_control_source_v1::Resource *zwlr_data_control_source_v1::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::zwlr_data_control_source_v1_interface, &m_zwlr_data_control_source_v1_interface))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    const struct ::zwlr_data_control_source_v1_interface zwlr_data_control_source_v1::m_zwlr_data_control_source_v1_interface = {
        zwlr_data_control_source_v1::handle_offer,
        zwlr_data_control_source_v1::handle_destroy
    };

    void zwlr_data_control_source_v1::zwlr_data_control_source_v1_offer(Resource *, const QString &)
    {
    }

    void zwlr_data_control_source_v1::zwlr_data_control_source_v1_destroy(Resource *)
    {
    }


    void zwlr_data_control_source_v1::handle_offer(
        ::wl_client *client,
        struct wl_resource *resource,
        const char *mime_type)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->zwlr_data_control_source_v1_object)) {
            return;
        }
        static_cast<zwlr_data_control_source_v1 *>(r->zwlr_data_control_source_v1_object)->zwlr_data_control_source_v1_offer(
            r,
            QString::fromUtf8(mime_type));
    }

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

    void zwlr_data_control_source_v1::send_send(const QString &mime_type, int32_t fd)
    {
        Q_ASSERT_X(m_resource, "zwlr_data_control_source_v1::send", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call zwlr_data_control_source_v1::send as it's not initialised");
            return;
        }
        send_send(
            m_resource->handle,
            mime_type,
            fd);
    }

    void zwlr_data_control_source_v1::send_send(struct ::wl_resource *resource, const QString &mime_type, int32_t fd)
    {
        zwlr_data_control_source_v1_send_send(
            resource,
            mime_type.toUtf8().constData(),
            fd);
    }


    void zwlr_data_control_source_v1::send_cancelled()
    {
        Q_ASSERT_X(m_resource, "zwlr_data_control_source_v1::cancelled", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call zwlr_data_control_source_v1::cancelled as it's not initialised");
            return;
        }
        send_cancelled(
            m_resource->handle);
    }

    void zwlr_data_control_source_v1::send_cancelled(struct ::wl_resource *resource)
    {
        zwlr_data_control_source_v1_send_cancelled(
            resource);
    }



    int zwlr_data_control_offer_v1::deferred_destroy_global_func(void *data) {
        auto object = static_cast<zwlr_data_control_offer_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->zwlr_data_control_offer_v1_destroy_global();
        return 0;
    }

    zwlr_data_control_offer_v1::zwlr_data_control_offer_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);
    }

    zwlr_data_control_offer_v1::zwlr_data_control_offer_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);
    }

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

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

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

        if (m_resource)
            m_resource->zwlr_data_control_offer_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 zwlr_data_control_offer_v1::init(struct ::wl_client *client, int id, int version)
    {
        m_resource = bind(client, id, version);
    }

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

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

    zwlr_data_control_offer_v1::Resource *zwlr_data_control_offer_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 zwlr_data_control_offer_v1::init(struct ::wl_display *display, int version)
    {
        m_display = display;
        m_global = wl_global_create(display, &::zwlr_data_control_offer_v1_interface, version, this, bind_func);
        m_displayDestroyedListener.notify = zwlr_data_control_offer_v1::display_destroy_func;
        m_displayDestroyedListener.parent = this;
        wl_display_add_destroy_listener(display, &m_displayDestroyedListener);
    }

    const struct wl_interface *zwlr_data_control_offer_v1::interface()
    {
        return &::zwlr_data_control_offer_v1_interface;
    }

    zwlr_data_control_offer_v1::Resource *zwlr_data_control_offer_v1::zwlr_data_control_offer_v1_allocate()
    {
        return new Resource;
    }

    void zwlr_data_control_offer_v1::zwlr_data_control_offer_v1_destroy_global()
    {
    }

    void zwlr_data_control_offer_v1::zwlr_data_control_offer_v1_bind_resource(Resource *)
    {
    }

    void zwlr_data_control_offer_v1::zwlr_data_control_offer_v1_destroy_resource(Resource *)
    {
    }

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

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

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

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


    void zwlr_data_control_offer_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, 5000);
    }

    zwlr_data_control_offer_v1::Resource *zwlr_data_control_offer_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, &::zwlr_data_control_offer_v1_interface, version, id);
        return bind(handle);
    }

    zwlr_data_control_offer_v1::Resource *zwlr_data_control_offer_v1::bind(struct ::wl_resource *handle)
    {
        Resource *resource = zwlr_data_control_offer_v1_allocate();
        resource->zwlr_data_control_offer_v1_object = this;

        wl_resource_set_implementation(handle, &m_zwlr_data_control_offer_v1_interface, resource, destroy_func);
        resource->handle = handle;
        zwlr_data_control_offer_v1_bind_resource(resource);
        return resource;
    }
    zwlr_data_control_offer_v1::Resource *zwlr_data_control_offer_v1::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::zwlr_data_control_offer_v1_interface, &m_zwlr_data_control_offer_v1_interface))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    const struct ::zwlr_data_control_offer_v1_interface zwlr_data_control_offer_v1::m_zwlr_data_control_offer_v1_interface = {
        zwlr_data_control_offer_v1::handle_receive,
        zwlr_data_control_offer_v1::handle_destroy
    };

    void zwlr_data_control_offer_v1::zwlr_data_control_offer_v1_receive(Resource *, const QString &, int32_t )
    {
    }

    void zwlr_data_control_offer_v1::zwlr_data_control_offer_v1_destroy(Resource *)
    {
    }


    void zwlr_data_control_offer_v1::handle_receive(
        ::wl_client *client,
        struct wl_resource *resource,
        const char *mime_type,
        int32_t fd)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->zwlr_data_control_offer_v1_object)) {
        close(fd);
            return;
        }
        static_cast<zwlr_data_control_offer_v1 *>(r->zwlr_data_control_offer_v1_object)->zwlr_data_control_offer_v1_receive(
            r,
            QString::fromUtf8(mime_type),
            fd);
    }

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

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

    void zwlr_data_control_offer_v1::send_offer(struct ::wl_resource *resource, const QString &mime_type)
    {
        zwlr_data_control_offer_v1_send_offer(
            resource,
            mime_type.toUtf8().constData());
    }

}

QT_WARNING_POP
QT_END_NAMESPACE
