#include <stdio.h>
#include <gtk/gtk.h>

static gboolean
delete_event_cb (GtkWidget *widget,
                 GdkEvent  *event,
                 gpointer   user_data)
{
        gtk_main_quit ();

        return TRUE;
}

static gboolean
expose_event_cb (GtkWidget      *widget,
                 GdkEventExpose *event,
                 gpointer        user_data)
{
        GdkWindow *window;
        cairo_t *context;

        window = gtk_widget_get_window (widget);
        context = gdk_cairo_create (GDK_DRAWABLE (window));

        cairo_set_source_rgb (context, 1.0, 1.0, 1.0);
        cairo_paint (context);

        cairo_set_source_rgb (context, 0.0, 0.0, 0.0);
        cairo_set_line_width (context, 4.0);
        cairo_set_line_cap (context, CAIRO_LINE_CAP_ROUND);

        cairo_move_to (context, 50.0, 50.0);
        cairo_line_to (context, 100.0, 100.0);

        cairo_stroke (context);

        cairo_destroy (context);

        return TRUE;
}

static gboolean
motion_notify_event_cb (GtkWidget      *widget,
                        GdkEventMotion *event,
                        gpointer        user_data)
{
        g_message ("Motion notify event");

        return TRUE;
}

int
main (int argc, char *argv[])
{
        GtkWidget *window;
        GtkWidget *da;

        gtk_init (&argc, &argv);

        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title (GTK_WINDOW (window), "Button motion test");
        g_signal_connect (window, "delete-event",
                          G_CALLBACK (delete_event_cb), NULL);

        da = gtk_drawing_area_new ();
        gtk_container_add (GTK_CONTAINER (window), da);

        gtk_widget_add_events (da,
			       GDK_BUTTON_PRESS_MASK      |
			       GDK_BUTTON_RELEASE_MASK    |
                               GDK_BUTTON1_MOTION_MASK);

        g_signal_connect (da, "motion-notify-event",
                          G_CALLBACK (motion_notify_event_cb), NULL);
        g_signal_connect (da, "expose-event",
                          G_CALLBACK (expose_event_cb), NULL);

        gtk_widget_show_all (window);

        gtk_main ();

        return 0;
}
