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

#include "qwayland-server-dde-shell.h"

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

namespace QtWaylandServer {

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

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

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

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

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

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

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

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

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

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

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

    const struct wl_interface *dde_shell::interface()
    {
        return &::dde_shell_interface;
    }

    dde_shell::Resource *dde_shell::dde_shell_allocate()
    {
        return new Resource;
    }

    void dde_shell::dde_shell_destroy_global()
    {
    }

    void dde_shell::dde_shell_bind_resource(Resource *)
    {
    }

    void dde_shell::dde_shell_destroy_resource(Resource *)
    {
    }

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

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

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

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


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

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

    dde_shell::Resource *dde_shell::bind(struct ::wl_resource *handle)
    {
        Resource *resource = dde_shell_allocate();
        resource->dde_shell_object = this;

        wl_resource_set_implementation(handle, &m_dde_shell_interface, resource, destroy_func);
        resource->handle = handle;
        dde_shell_bind_resource(resource);
        return resource;
    }
    dde_shell::Resource *dde_shell::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::dde_shell_interface, &m_dde_shell_interface))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    const struct ::dde_shell_interface dde_shell::m_dde_shell_interface = {
        dde_shell::handle_get_shell_surface
    };

    void dde_shell::dde_shell_get_shell_surface(Resource *, uint32_t, struct ::wl_resource *)
    {
    }


    void dde_shell::handle_get_shell_surface(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t id,
        struct ::wl_resource *surface)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->dde_shell_object)) {
            return;
        }
        static_cast<dde_shell *>(r->dde_shell_object)->dde_shell_get_shell_surface(
            r,
            id,
            surface);
    }


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

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

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

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

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

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

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

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

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

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

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

    const struct wl_interface *dde_shell_surface::interface()
    {
        return &::dde_shell_surface_interface;
    }

    dde_shell_surface::Resource *dde_shell_surface::dde_shell_surface_allocate()
    {
        return new Resource;
    }

    void dde_shell_surface::dde_shell_surface_destroy_global()
    {
    }

    void dde_shell_surface::dde_shell_surface_bind_resource(Resource *)
    {
    }

    void dde_shell_surface::dde_shell_surface_destroy_resource(Resource *)
    {
    }

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

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

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

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


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

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

    dde_shell_surface::Resource *dde_shell_surface::bind(struct ::wl_resource *handle)
    {
        Resource *resource = dde_shell_surface_allocate();
        resource->dde_shell_surface_object = this;

        wl_resource_set_implementation(handle, &m_dde_shell_surface_interface, resource, destroy_func);
        resource->handle = handle;
        dde_shell_surface_bind_resource(resource);
        return resource;
    }
    dde_shell_surface::Resource *dde_shell_surface::Resource::fromResource(struct ::wl_resource *resource)
    {
        if (Q_UNLIKELY(!resource))
            return nullptr;
        if (wl_resource_instance_of(resource, &::dde_shell_surface_interface, &m_dde_shell_surface_interface))
            return static_cast<Resource *>(wl_resource_get_user_data(resource));
        return nullptr;
    }

    const struct ::dde_shell_surface_interface dde_shell_surface::m_dde_shell_surface_interface = {
        dde_shell_surface::handle_get_geometry,
        dde_shell_surface::handle_request_active,
        dde_shell_surface::handle_set_state,
        dde_shell_surface::handle_set_property,
        dde_shell_surface::handle_request_split_window,
        dde_shell_surface::handle_request_window_effect,
        dde_shell_surface::handle_request_window_startup_effect
    };

    void dde_shell_surface::dde_shell_surface_get_geometry(Resource *)
    {
    }

    void dde_shell_surface::dde_shell_surface_request_active(Resource *)
    {
    }

    void dde_shell_surface::dde_shell_surface_set_state(Resource *, uint32_t , uint32_t )
    {
    }

    void dde_shell_surface::dde_shell_surface_set_property(Resource *, uint32_t , wl_array *)
    {
    }

    void dde_shell_surface::dde_shell_surface_request_split_window(Resource *, uint32_t )
    {
    }

    void dde_shell_surface::dde_shell_surface_request_window_effect(Resource *, uint32_t )
    {
    }

    void dde_shell_surface::dde_shell_surface_request_window_startup_effect(Resource *, uint32_t )
    {
    }


    void dde_shell_surface::handle_get_geometry(
        ::wl_client *client,
        struct wl_resource *resource)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->dde_shell_surface_object)) {
            return;
        }
        static_cast<dde_shell_surface *>(r->dde_shell_surface_object)->dde_shell_surface_get_geometry(
            r);
    }

    void dde_shell_surface::handle_request_active(
        ::wl_client *client,
        struct wl_resource *resource)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->dde_shell_surface_object)) {
            return;
        }
        static_cast<dde_shell_surface *>(r->dde_shell_surface_object)->dde_shell_surface_request_active(
            r);
    }

    void dde_shell_surface::handle_set_state(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t flags,
        uint32_t state)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->dde_shell_surface_object)) {
            return;
        }
        static_cast<dde_shell_surface *>(r->dde_shell_surface_object)->dde_shell_surface_set_state(
            r,
            flags,
            state);
    }

    void dde_shell_surface::handle_set_property(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t property,
        wl_array *dataArr)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->dde_shell_surface_object)) {
            return;
        }
        static_cast<dde_shell_surface *>(r->dde_shell_surface_object)->dde_shell_surface_set_property(
            r,
            property,
            dataArr);
    }

    void dde_shell_surface::handle_request_split_window(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t split_type)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->dde_shell_surface_object)) {
            return;
        }
        static_cast<dde_shell_surface *>(r->dde_shell_surface_object)->dde_shell_surface_request_split_window(
            r,
            split_type);
    }

    void dde_shell_surface::handle_request_window_effect(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t effectscene)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->dde_shell_surface_object)) {
            return;
        }
        static_cast<dde_shell_surface *>(r->dde_shell_surface_object)->dde_shell_surface_request_window_effect(
            r,
            effectscene);
    }

    void dde_shell_surface::handle_request_window_startup_effect(
        ::wl_client *client,
        struct wl_resource *resource,
        uint32_t effecttype)
    {
        Q_UNUSED(client);
        Resource *r = Resource::fromResource(resource);
        if (Q_UNLIKELY(!r->dde_shell_surface_object)) {
            return;
        }
        static_cast<dde_shell_surface *>(r->dde_shell_surface_object)->dde_shell_surface_request_window_startup_effect(
            r,
            effecttype);
    }

    void dde_shell_surface::send_geometry(int32_t x, int32_t y, uint32_t w, uint32_t h)
    {
        Q_ASSERT_X(m_resource, "dde_shell_surface::geometry", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call dde_shell_surface::geometry as it's not initialised");
            return;
        }
        send_geometry(
            m_resource->handle,
            x,
            y,
            w,
            h);
    }

    void dde_shell_surface::send_geometry(struct ::wl_resource *resource, int32_t x, int32_t y, uint32_t w, uint32_t h)
    {
        dde_shell_surface_send_geometry(
            resource,
            x,
            y,
            w,
            h);
    }


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

    void dde_shell_surface::send_state_changed(struct ::wl_resource *resource, uint32_t flags)
    {
        dde_shell_surface_send_state_changed(
            resource,
            flags);
    }


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

    void dde_shell_surface::send_splitable(struct ::wl_resource *resource, uint32_t flags)
    {
        dde_shell_surface_send_splitable(
            resource,
            flags);
    }


    void dde_shell_surface::send_workarea(struct ::wl_resource *output, uint32_t x, uint32_t y, uint32_t width, uint32_t height)
    {
        Q_ASSERT_X(m_resource, "dde_shell_surface::workarea", "Uninitialised resource");
        if (Q_UNLIKELY(!m_resource)) {
            qWarning("could not call dde_shell_surface::workarea as it's not initialised");
            return;
        }
        send_workarea(
            m_resource->handle,
            output,
            x,
            y,
            width,
            height);
    }

    void dde_shell_surface::send_workarea(struct ::wl_resource *resource, struct ::wl_resource *output, uint32_t x, uint32_t y, uint32_t width, uint32_t height)
    {
        dde_shell_surface_send_workarea(
            resource,
            output,
            x,
            y,
            width,
            height);
    }

}

QT_WARNING_POP
QT_END_NAMESPACE
