// SPDX-FileCopyrightText: 2024 KylinSoft Co., Ltd.
//
// SPDX-License-Identifier: GPL-1.0-or-later

#include "xdgactivationv1.h"

#include <QtWaylandClient/private/qwaylanddisplay_p.h>
#include <QtWaylandClient/private/qwaylandinputdevice_p.h>

namespace QtWaylandClient
{

XdgActivationV1::XdgActivationV1(wl_registry *registry, uint32_t id, uint32_t availableVersion)
    : xdg_activation_v1(registry, id, availableVersion)
{
}

XdgActivationV1::~XdgActivationV1()
{
    Q_ASSERT(isInitialized());
    destroy();
}

XdgActivationTokenV1 *XdgActivationV1::requestXdgActivationToken(QWaylandDisplay *display, struct ::wl_surface *surface, uint32_t serial, const QString &app_id)
{
    auto wl = get_activation_token();
    auto provider = new XdgActivationTokenV1;
    provider->init(wl);

    if (surface)
        provider->set_surface(surface);

    if (!app_id.isEmpty())
        provider->set_app_id(app_id);

    if (serial && display->lastInputDevice())
        provider->set_serial(serial, display->lastInputDevice()->wl_seat());
    provider->commit();
    return provider;
}

XdgActivationTokenV1::~XdgActivationTokenV1()
{
    destroy();
}

} // namespace QtWaylandClient