#pragma once

#include "wayland-client.h"

#include <xkbcommon/xkbcommon.h>

class WaylandKeyboard
{
public:
    WaylandKeyboard(wl_keyboard* keyboard);

    ~WaylandKeyboard();

private:
    static void keyboardKeymapEvent(void *data, struct wl_keyboard *wl_keyboard, uint32_t format, int32_t fd, uint32_t size);
    static void keyboardEnterEvent(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys);
    static void keyboardPressedEvent(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state);
    static void keyboardModifierEvent(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group);

    void onKeyboardModifier(uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group);
    void onKeymapEvent(struct wl_keyboard *wl_keyboard, uint32_t format, int32_t fd, uint32_t size);
    void onEnterEvent(struct wl_array *keys);
    void onPressedEvent(uint32_t key, uint32_t state);

    wl_keyboard* mKeyboard{nullptr};
    xkb_state* mXkbState{nullptr};
    xkb_context* mXkbContext{nullptr};
    xkb_keymap* mXkbKeymap{nullptr};
    wl_keyboard_listener mKeyboardListener;
};
