// build by gcc -o test2 -g -O0 test2.c `pkg-config --libs --cflags gtk+-3.0`

#include <gtk/gtk.h>

GtkWidget *window;
GtkWidget *shell;
GtkWidget *drawing;
GdkWindow *gdkwindow;

static void draw_tooltip_cb(GtkWidget *widget, cairo_t* cr,
                            gpointer   data )
{

    int width = gtk_widget_get_allocated_width(widget);
    int height = gtk_widget_get_allocated_height(widget);
    cairo_rectangle(cr, 0, 0, width, height);
    cairo_set_source_rgb(cr, 1, 0, 0);
    cairo_fill(cr);

/*
    cairo_rectangle (cr, 0, 0, 100, 100);
    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_fill (cr);

    cairo_t* cr3 = gdk_cairo_create(gtk_widget_get_window(widget));
    cairo_rectangle (cr3, 0, 0, 70, 70);
    cairo_set_source_rgb (cr3, 0, 0, 1);
    cairo_fill (cr3);

    cairo_region_t* dirtyArea = gdk_window_get_update_area(gtk_widget_get_window(widget));
    cairo_region_t* dirtyArea2 = gdk_window_get_update_area(gdkwindow);
*/
    return FALSE;
}

static void visibility_notify_event_cb(GtkWidget *widget, cairo_t* cr,
                            gpointer   data )
{
    return TRUE;
}

/* Another callback */
static void destroy( GtkWidget *widget,
                     gpointer   data )
{
    gtk_main_quit ();
}

int main( int   argc,
          char *argv[] )
{
    gtk_init (&argc, &argv);

    /* create a new window */
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    drawing = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
    gtk_container_add(GTK_CONTAINER(window), drawing);
    gtk_window_move(window,0,0);
    gtk_window_resize(window,1000,500);

    g_signal_connect (window, "destroy",
          G_CALLBACK (destroy), NULL);

    g_signal_connect (drawing, "draw",
          G_CALLBACK (draw_tooltip_cb), NULL);

    g_signal_connect (window, "visibility-notify-event",
                     G_CALLBACK(visibility_notify_event_cb), 0);

    gtk_widget_show_all (GTK_WIDGET(window));
    gdkwindow = gtk_widget_get_window(window);

    gtk_widget_set_double_buffered(window, FALSE);

/*
    shell = gtk_window_new(GTK_WINDOW_POPUP);
    gtk_window_set_type_hint (GTK_WINDOW(shell), GDK_WINDOW_TYPE_HINT_POPUP_MENU);
    gtk_grab_add(GTK_WINDOW(shell));
    gtk_window_set_transient_for(GTK_WINDOW(shell),window);
    gtk_widget_set_app_paintable(shell, FALSE);
    gtk_window_move(shell,0,0);
    gtk_window_resize(shell,500,500);
    gtk_widget_show_all (GTK_WIDGET(shell));
*/
    gtk_main ();

    return 0;
}
