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


#include <errno.h>
#include <stdlib.h>

static guint32 time;

gboolean
focus_win(GtkWidget *window)
{
   printf( "Focusing window with user time of %d\n", time);

   /* Basically gtk_window_present */
   gdk_window_show (window->window);
   gdk_window_focus (window->window, time);

   return FALSE;
}

static gboolean
update_time( GtkWidget *widget, GdkEvent *event, GtkWidget* window)
{
   time = gtk_get_current_event_time();

   g_timeout_add (5000,  (GSourceFunc)focus_win, window);

   printf( "Ok, got %d, now interact with another window\n", time );

   return FALSE;
}

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

   gtk_init( &argc, &argv );
   
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   button = gtk_button_new_with_label( "Click me" );
   gtk_widget_show (button);
   gtk_container_add(GTK_CONTAINER (window), button);

   g_signal_connect (button, "button-press-event", G_CALLBACK (update_time), window);
   g_signal_connect_swapped (window, "destroy", gtk_main_quit, NULL);
   
   gtk_widget_show_now (window);

   printf( "Now press click inside the window\n" );
   gtk_main();

   return 0;
}
