/* gcc -Wall `pkg-config --libs --cflags gtk+-2.0` test.c && ./a.out */

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


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

static guint32 time;

gboolean
create_win(GtkWidget *parent)
{
   GtkWidget *window, *label;

   printf( "Creating new window with user time of %d\n", time);

   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

   label = gtk_label_new ("This is a transient window");

   gtk_container_add(GTK_CONTAINER (window), label);

   gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (parent));
   gtk_window_set_destroy_with_parent (GTK_WINDOW (window), TRUE);

   gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), TRUE);

   g_signal_connect_swapped (window, "destroy", G_CALLBACK (gtk_widget_destroy), window);

   gtk_widget_realize (window);
   gdk_x11_window_set_user_time (window->window, time);

   gtk_widget_show_all (window);

   return FALSE;
}

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

   g_timeout_add (5000,  (GSourceFunc)create_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;
}
