// This file was generated by qtwaylandscanner
// source file is /usr/share/deepin-wayland-protocols/strut.xml

#include "qwayland-server-strut.h"

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

namespace QtWaylandServer {

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

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

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

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

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

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

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

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

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

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

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

    const struct wl_interface *com_deepin_kwin_strut::interface()
    {
        return &::com_deepin_kwin_strut_interface;
    }

    com_deepin_kwin_strut::Resource *com_deepin_kwin_strut::com_deepin_kwin_strut_allocate()
    {
        return new Resource;
    }

    void com_deepin_kwin_strut::com_deepin_kwin_strut_destroy_global()
    {
    }

    void com_deepin_kwin_strut::com_deepin_kwin_strut_bind_resource(Resource *)
    {
    }

    void com_deepin_kwin_strut::com_deepin_kwin_strut_destroy_resource(Resource *)
    {
    }

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

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

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

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


    void com_deepin_kwin_strut::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);
    }

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

    com_deepin_kwin_strut::Resource *com_deepin_kwin_strut::bind(struct ::wl_resource *handle)
    {
        Resource *resource = com_deepin_kwin_strut_allocate();
        resource->com_deepin_kwin_strut_object = this;

        wl_resource_set_implementation(handle, &m_com_deepin_kwin_strut_interface, resource, destroy_func);
        resource->handle = handle;
        com_deepin_kwin_strut_bind_resource(resource);
        return resource;
    }
    com_deepin_kwin_strut::Resource *com_deepin_kwin_strut::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::com_deepin_kwin_strut_interface, &m_com_deepin_kwin_strut_interface))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    const struct ::com_deepin_kwin_strut_interface com_deepin_kwin_strut::m_com_deepin_kwin_strut_interface = {
        com_deepin_kwin_strut::handle_set_strut_partial
    };

    void com_deepin_kwin_strut::com_deepin_kwin_strut_set_strut_partial(Resource *, struct ::wl_resource *, int32_t , int32_t , int32_t , int32_t , int32_t , int32_t , int32_t , int32_t , int32_t , int32_t , int32_t , int32_t )
    {
    }


    void com_deepin_kwin_strut::handle_set_strut_partial(
        ::wl_client *client,
        struct wl_resource *resource,
        struct ::wl_resource *surface,
        int32_t left,
        int32_t right,
        int32_t top,
        int32_t bottom,
        int32_t left_start_y,
        int32_t left_end_y,
        int32_t right_start_y,
        int32_t right_end_y,
        int32_t top_start_x,
        int32_t top_end_x,
        int32_t bottom_start_x,
        int32_t bottom_end_x)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->com_deepin_kwin_strut_object)) {
            return;
        }
        static_cast<com_deepin_kwin_strut *>(r->com_deepin_kwin_strut_object)->com_deepin_kwin_strut_set_strut_partial(
            r,
            surface,
            left,
            right,
            top,
            bottom,
            left_start_y,
            left_end_y,
            right_start_y,
            right_end_y,
            top_start_x,
            top_end_x,
            bottom_start_x,
            bottom_end_x);
    }
}

QT_WARNING_POP
QT_END_NAMESPACE
