#include <QObject>

#include <wayland-client.hpp>

class UkuiDisplay;

UkuiDisplay *ukuiDisplay();

class UkuiDisplay : public QObject
{
    Q_OBJECT
public:
    ~UkuiDisplay();

    bool isInitialized() const;

    const wayland::display_t &display() const;
    const wayland::seat_t &seat() const;

    wayland::proxy_t bind(const std::string &name, wayland::proxy_t &interface, uint32_t minVersion = 1);

private:
    explicit UkuiDisplay(QObject *parent = nullptr);
    bool init();
    void handle_global(uint32_t name, const std::string &interface, uint32_t version);
    void handle_global_remove(uint32_t name);

    struct WaylandInterface
    {
        uint32_t name;
        std::string interface;
        uint32_t version;
    };
    QList<WaylandInterface> globalInterfaces();

    std::unique_ptr<wayland::display_t> m_display;
    wayland::seat_t m_seat;
    wayland::registry_t m_registry;

    QList<WaylandInterface> m_globalInterfaces;

    bool m_initialized = false;

    friend UkuiDisplay * ::ukuiDisplay();
};
