#include <wayland-client.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <xkbcommon/xkbcommon.h>
#include "xdg-shell-client-protocol.h"
#include "input.h"
#include "window.h"
#include "registry.h"


int32_t run_wayland()
{
    struct wl_display *display = wl_display_connect(0);
    if (!display)
        return -1;
    struct wl_registry *registry = wl_display_get_registry(display);
    registry_add_listener(registry);
    wl_display_roundtrip(display);
    struct wayland_window win;
    if (window_init(display, &win) < 0)
        return -1;

    while (wl_display_dispatch(display))
    {
        if (window_should_close(&win))
        {
            printf("Window closing\n");
            break;
        }
    }
    window_destroy(&win);
    input_cleanup();
    wl_display_disconnect(display);
    return 0;
}
