#include <gtk/gtk.h>

static GdkColor green = { 0, 0x0000, 0xffff, 0x0000 };
static GdkColor yellow = { 0, 0xffff, 0xffff, 0x0000 };

gboolean visibility_event_callback( GtkWidget *widget, GdkEventVisibility *event, gpointer user_data )
{
	if( event->state == GDK_VISIBILITY_UNOBSCURED )
	{
		gtk_widget_modify_bg( widget, GTK_STATE_NORMAL, &green );
	}
	else if( event->state == GDK_VISIBILITY_PARTIAL )
	{
		gtk_widget_modify_bg( widget, GTK_STATE_NORMAL, &yellow );
	}
	else if( event->state == GDK_VISIBILITY_FULLY_OBSCURED )
	{
		gtk_window_present( GTK_WINDOW( widget ) );
	}
}

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

	gtk_init( &argc, &argv );

	window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
	gtk_container_set_border_width( GTK_CONTAINER( window ), 20 );
	label = gtk_label_new( "Visibility test" );
	gtk_container_add( GTK_CONTAINER( window ), label );

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

	g_signal_connect( G_OBJECT( window ), "visibility-notify-event", G_CALLBACK( visibility_event_callback ), NULL );
	gtk_widget_add_events( window, GDK_VISIBILITY_NOTIFY_MASK );

	gtk_widget_show_all( window );

	gtk_main();

	return 0;
}
