#include <gtk/gtk.h>
#include <cairo/cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

/* MOZ_CURSOR_ZOOM_IN */
static const unsigned char moz_zoom_in_bits[] = {
  0xf0, 0x00, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00,
  0x62, 0x04, 0x00, 0x00, 0x61, 0x08, 0x00, 0x00, 0xf9, 0x09, 0x00, 0x00,
  0xf9, 0x09, 0x00, 0x00, 0x61, 0x08, 0x00, 0x00, 0x62, 0x04, 0x00, 0x00,
  0x02, 0x04, 0x00, 0x00, 0x0c, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00,
  0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
  0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

static const unsigned char moz_zoom_in_mask_bits[] = {
  0xf0, 0x00, 0x00, 0x00, 0xfc, 0x03, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00,
  0xfe, 0x07, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00,
  0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00,
  0xfe, 0x07, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00,
  0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
  0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

typedef struct {
    const char* name;
    const unsigned char* bits;
    const unsigned char* mask_bits;
    int hot_x;
    int hot_y;
} CustomCursor;

// create custom pixmap cursor from cursors in nsGTKCursorData.h
static const CustomCursor CustomCursors[] = {
    { "zoom-in", moz_zoom_in_bits, moz_zoom_in_mask_bits, 6, 6 },
};

int
main (int argc, char** argv)
{
	gtk_init(NULL, NULL);

	CustomCursor cursor = CustomCursors[0];
	GdkCursor* default_cursor = gdk_cursor_new_for_display (gdk_display_get_default(), GDK_ARROW);
	g_print("%i\n", cairo_format_stride_for_width (CAIRO_FORMAT_A1, 32));
	cairo_surface_t* source = cairo_image_surface_create_for_data((unsigned char*)cursor.bits, CAIRO_FORMAT_A1, 32, 32, 4);
	cairo_surface_t* mask = cairo_image_surface_create_for_data((unsigned char*)cursor.mask_bits, CAIRO_FORMAT_A1, 32, 32, 4);
	cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 32, 32);
	cairo_t* cr = cairo_create(surface);

	cairo_set_source_surface(cr, source, 0, 0);
	cairo_mask_surface(cr, mask, 0, 0);

	GdkPixbuf* pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, 32, 32);
	GdkCursor *gdk_cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, cursor.hot_x, cursor.hot_y);

	gdk_window_set_cursor(gdk_screen_get_root_window (gdk_screen_get_default()), argc > 1 && *argv[1] == '1' ? gdk_cursor : default_cursor);

	gtk_main();
	return 0;
}
