// This file was generated by qtwaylandscanner
// source file is server-decoration.xml

#include "qwayland-server-server-decoration.h"

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

namespace QtWaylandServer {

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

    org_kde_kwin_server_decoration_manager::org_kde_kwin_server_decoration_manager(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);
    }

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

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

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

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

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

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

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

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

    org_kde_kwin_server_decoration_manager::Resource *org_kde_kwin_server_decoration_manager::add(struct ::wl_resource *resource)
    {
        return *m_resource_map.insert(wl_resource_get_client(resource), bind(resource));
    }

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

    const struct wl_interface *org_kde_kwin_server_decoration_manager::interface()
    {
        return &::org_kde_kwin_server_decoration_manager_interface;
    }

    org_kde_kwin_server_decoration_manager::Resource *org_kde_kwin_server_decoration_manager::org_kde_kwin_server_decoration_manager_allocate()
    {
        return new Resource;
    }

    void org_kde_kwin_server_decoration_manager::org_kde_kwin_server_decoration_manager_destroy_global()
    {
    }

    void org_kde_kwin_server_decoration_manager::org_kde_kwin_server_decoration_manager_bind_resource(Resource *)
    {
    }

    void org_kde_kwin_server_decoration_manager::org_kde_kwin_server_decoration_manager_destroy_resource(Resource *)
    {
    }

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

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

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

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


    void org_kde_kwin_server_decoration_manager::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, 300000);
    }

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

    org_kde_kwin_server_decoration_manager::Resource *org_kde_kwin_server_decoration_manager::bind(struct ::wl_resource *handle)
    {
        Resource *resource = org_kde_kwin_server_decoration_manager_allocate();
        resource->org_kde_kwin_server_decoration_manager_object = this;

        wl_resource_set_implementation(handle, &m_org_kde_kwin_server_decoration_manager_interface, resource, destroy_func);
        resource->handle = handle;
        org_kde_kwin_server_decoration_manager_bind_resource(resource);
        return resource;
    }
    org_kde_kwin_server_decoration_manager::Resource *org_kde_kwin_server_decoration_manager::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::org_kde_kwin_server_decoration_manager_interface, &m_org_kde_kwin_server_decoration_manager_interface))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    const struct ::org_kde_kwin_server_decoration_manager_interface org_kde_kwin_server_decoration_manager::m_org_kde_kwin_server_decoration_manager_interface = {
        org_kde_kwin_server_decoration_manager::handle_create
    };

    void org_kde_kwin_server_decoration_manager::org_kde_kwin_server_decoration_manager_create(Resource *, uint32_t, struct ::wl_resource *)
    {
    }


    void org_kde_kwin_server_decoration_manager::handle_create(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t id,
        struct ::wl_resource *surface)
    {
        Q_UNUSED(client);
        Resource *qtResource = Resource::fromResource(resource);
        if (Q_UNLIKELY(!qtResource->org_kde_kwin_server_decoration_manager_object)) {
            return;
        }
        static_cast<org_kde_kwin_server_decoration_manager *>(qtResource->org_kde_kwin_server_decoration_manager_object)->org_kde_kwin_server_decoration_manager_create(
            qtResource,
            id,
            surface);
    }

    void org_kde_kwin_server_decoration_manager::send_default_mode(uint32_t mode)
    {
        Q_ASSERT_X(m_resource, "org_kde_kwin_server_decoration_manager::default_mode", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call org_kde_kwin_server_decoration_manager::default_mode as it's not initialised");
            return;
        }
        send_default_mode(
            m_resource->handle,
            mode);
    }

    void org_kde_kwin_server_decoration_manager::send_default_mode(struct ::wl_resource *resource, uint32_t mode)
    {
        org_kde_kwin_server_decoration_manager_send_default_mode(
            resource,
            mode);
    }



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

    org_kde_kwin_server_decoration::org_kde_kwin_server_decoration(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);
    }

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

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

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

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

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

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

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

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

    org_kde_kwin_server_decoration::Resource *org_kde_kwin_server_decoration::add(struct ::wl_resource *resource)
    {
        return *m_resource_map.insert(wl_resource_get_client(resource), bind(resource));
    }

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

    const struct wl_interface *org_kde_kwin_server_decoration::interface()
    {
        return &::org_kde_kwin_server_decoration_interface;
    }

    org_kde_kwin_server_decoration::Resource *org_kde_kwin_server_decoration::org_kde_kwin_server_decoration_allocate()
    {
        return new Resource;
    }

    void org_kde_kwin_server_decoration::org_kde_kwin_server_decoration_destroy_global()
    {
    }

    void org_kde_kwin_server_decoration::org_kde_kwin_server_decoration_bind_resource(Resource *)
    {
    }

    void org_kde_kwin_server_decoration::org_kde_kwin_server_decoration_destroy_resource(Resource *)
    {
    }

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

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

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

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


    void org_kde_kwin_server_decoration::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, 300000);
    }

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

    org_kde_kwin_server_decoration::Resource *org_kde_kwin_server_decoration::bind(struct ::wl_resource *handle)
    {
        Resource *resource = org_kde_kwin_server_decoration_allocate();
        resource->org_kde_kwin_server_decoration_object = this;

        wl_resource_set_implementation(handle, &m_org_kde_kwin_server_decoration_interface, resource, destroy_func);
        resource->handle = handle;
        org_kde_kwin_server_decoration_bind_resource(resource);
        return resource;
    }
    org_kde_kwin_server_decoration::Resource *org_kde_kwin_server_decoration::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::org_kde_kwin_server_decoration_interface, &m_org_kde_kwin_server_decoration_interface))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    const struct ::org_kde_kwin_server_decoration_interface org_kde_kwin_server_decoration::m_org_kde_kwin_server_decoration_interface = {
        org_kde_kwin_server_decoration::handle_release,
        org_kde_kwin_server_decoration::handle_request_mode
    };

    void org_kde_kwin_server_decoration::org_kde_kwin_server_decoration_release(Resource *)
    {
    }

    void org_kde_kwin_server_decoration::org_kde_kwin_server_decoration_request_mode(Resource *, uint32_t )
    {
    }


    void org_kde_kwin_server_decoration::handle_release(
        ::wl_client *client,
        struct wl_resource *resource)
    {
        Q_UNUSED(client);
        Resource *qtResource = Resource::fromResource(resource);
        if (Q_UNLIKELY(!qtResource->org_kde_kwin_server_decoration_object)) {
            wl_resource_destroy(resource);
            return;
        }
        static_cast<org_kde_kwin_server_decoration *>(qtResource->org_kde_kwin_server_decoration_object)->org_kde_kwin_server_decoration_release(
            qtResource);
    }

    void org_kde_kwin_server_decoration::handle_request_mode(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t mode)
    {
        Q_UNUSED(client);
        Resource *qtResource = Resource::fromResource(resource);
        if (Q_UNLIKELY(!qtResource->org_kde_kwin_server_decoration_object)) {
            return;
        }
        static_cast<org_kde_kwin_server_decoration *>(qtResource->org_kde_kwin_server_decoration_object)->org_kde_kwin_server_decoration_request_mode(
            qtResource,
            mode);
    }

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

    void org_kde_kwin_server_decoration::send_mode(struct ::wl_resource *resource, uint32_t mode)
    {
        org_kde_kwin_server_decoration_send_mode(
            resource,
            mode);
    }

}

QT_WARNING_POP
QT_END_NAMESPACE
