#include <QtWaylandClient/private/qwayland-qt-windowmanager.h>

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

namespace QtWayland {

static inline void *wlRegistryBind(struct ::wl_registry *registry, uint32_t name, const struct ::wl_interface *interface, uint32_t version)
{
    const uint32_t bindOpCode = 0;
#if (WAYLAND_VERSION_MAJOR == 1 && WAYLAND_VERSION_MINOR > 10) || WAYLAND_VERSION_MAJOR > 1
    return (void *) wl_proxy_marshal_constructor_versioned((struct wl_proxy *) registry,
        bindOpCode, interface, version, name, interface->name, version, nullptr);
#else
    return (void *) wl_proxy_marshal_constructor((struct wl_proxy *) registry,
        bindOpCode, interface, name, interface->name, version, nullptr);
#endif
}

    qt_windowmanager::qt_windowmanager(struct ::wl_registry *registry, int id, int version)
    {
        init(registry, id, version);
    }

    qt_windowmanager::qt_windowmanager(struct ::qt_windowmanager *obj)
        : m_qt_windowmanager(obj)
    {
        init_listener();
    }

    qt_windowmanager::qt_windowmanager()
        : m_qt_windowmanager(nullptr)
    {
    }

    qt_windowmanager::~qt_windowmanager()
    {
    }

    void qt_windowmanager::init(struct ::wl_registry *registry, int id, int version)
    {
        m_qt_windowmanager = static_cast<struct ::qt_windowmanager *>(wlRegistryBind(registry, id, &qt_windowmanager_interface, version));
        init_listener();
    }

    void qt_windowmanager::init(struct ::qt_windowmanager *obj)
    {
        m_qt_windowmanager = obj;
        init_listener();
    }

    qt_windowmanager *qt_windowmanager::fromObject(struct ::qt_windowmanager *object)
    {
        if (wl_proxy_get_listener((struct ::wl_proxy *)object) != (void *)&m_qt_windowmanager_listener)
            return nullptr;
        return static_cast<qt_windowmanager *>(qt_windowmanager_get_user_data(object));
    }

    bool qt_windowmanager::isInitialized() const
    {
        return m_qt_windowmanager != nullptr;
    }

    const struct wl_interface *qt_windowmanager::interface()
    {
        return &::qt_windowmanager_interface;
    }

    void qt_windowmanager::open_url(uint32_t remaining, const QString &url)
    {
        qt_windowmanager_open_url(
            m_qt_windowmanager,
            remaining,
            url.toUtf8().constData());
    }

    void qt_windowmanager::windowmanager_hints(int32_t )
    {
    }

    void qt_windowmanager::handle_hints(
        void *data,
        struct ::qt_windowmanager *object,
        int32_t show_is_fullscreen)
    {
        Q_UNUSED(object);
        static_cast<qt_windowmanager *>(data)->windowmanager_hints(
            show_is_fullscreen);
    }

    void qt_windowmanager::windowmanager_quit()
    {
    }

    void qt_windowmanager::handle_quit(
        void *data,
        struct ::qt_windowmanager *object)
    {
        Q_UNUSED(object);
        static_cast<qt_windowmanager *>(data)->windowmanager_quit();
    }

    const struct qt_windowmanager_listener qt_windowmanager::m_qt_windowmanager_listener = {
        qt_windowmanager::handle_hints,
        qt_windowmanager::handle_quit
    };

    void qt_windowmanager::init_listener()
    {
        qt_windowmanager_add_listener(m_qt_windowmanager, &m_qt_windowmanager_listener, this);
    }
}

QT_WARNING_POP
QT_END_NAMESPACE
