#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <wayland-client.h>

struct wl_display* display = NULL;
struct wl_compositor* compositor = NULL;
struct wl_shell* shell = NULL;

static void
global_registry_handler(void *data, struct wl_registry *registry, uint32_t id,
	       const char *interface, uint32_t version)
{
    if (strcmp(interface, "wl_compositor") == 0)
        compositor = wl_registry_bind(registry, 
				      id, 
				      &wl_compositor_interface, 
				      1);
    if (strcmp(interface, "wl_shell") == 0)
	shell = wl_registry_bind(registry, id, &wl_shell_interface, 1);
}

static const struct wl_registry_listener registry_listener = {
    global_registry_handler,
    NULL
};


int main()
{
	display = wl_display_connect(NULL);
	assert(display);
	struct wl_registry* registry = wl_display_get_registry(display);
	wl_registry_add_listener(registry, &registry_listener, NULL);
	assert(registry);
	wl_display_roundtrip(display);

	assert(compositor);
	struct wl_surface* surface = wl_compositor_create_surface(compositor);
	assert(surface);
	struct wl_shell_surface* shell_surface = wl_shell_get_shell_surface(shell, surface);
	assert(shell_surface);
	wl_shell_surface_set_transient(shell_surface, surface, 0, 0, 0);
	wl_display_roundtrip(display);

	while(1)
	{
		sleep(1);
	}

	return 0;
}
