/*
    Compile with
    cc -g -Wall `pkg-config gtk+-2.0 --cflags --libs` ./sample.c -o ./sample
*/

#include <gtk/gtk.h>

#define DEFAULT_WIDTH  400
#define DEFAULT_HEIGHT 200

static gboolean
event_enter (GtkWidget      *widget)
{
    printf("enter_notify_event\n");
    
    return TRUE;
}

static gboolean
event_leave (GtkWidget      *widget)
{
    printf("leave_notify_event\n");
    
    return TRUE;
}

gint
main (gint    argc,
      gchar **argv)
{
  GtkWidget     *window;
  GtkWidget     *canvas;

  gtk_init (&argc, &argv);

  window   = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL);

  canvas = gtk_drawing_area_new ();
  gtk_widget_set_size_request (canvas, DEFAULT_WIDTH, DEFAULT_HEIGHT);
  
  /* add additional events the canvas widget will listen for
   */
  gtk_widget_add_events (canvas, GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK);
  
  // Uncomment this and the wrong behavior goes away.
  //~ gtk_widget_add_events (canvas, GDK_BUTTON_PRESS_MASK);
  
  g_signal_connect (G_OBJECT (canvas), "enter_notify_event", G_CALLBACK (event_enter), NULL);

  g_signal_connect (G_OBJECT (canvas), "leave_notify_event", G_CALLBACK (event_leave), NULL);

  gtk_container_add (GTK_CONTAINER (window), canvas);
  gtk_widget_show_all (window);
  
  GtkWidget *transient_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_transient_for(GTK_WINDOW(transient_window), GTK_WINDOW(window));
  gtk_widget_show_all (transient_window);
  
  gtk_main ();

  return 0;
}
