/* Compile with:
 *  gcc -o withdrawn-windows $(pkg-config --cflags --libs gtk+-2.0) withdrawn-windows.c
 */

#include <gtk/gtk.h>

static gboolean clicked (GtkWidget *button, GdkEventButton *event, gpointer data)
{
        GtkWidget *window = data;

        if (GTK_WIDGET_VISIBLE (window)) {
                g_print ("Hiding\n");

                gtk_widget_hide (window);
        } else {
                g_print ("Showing\n");

                gtk_widget_show (window);
                gdk_window_focus (window->window, GDK_CURRENT_TIME);
        }
	return FALSE;
}

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

        gtk_init (&argc, &argv);

        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_window_set_type_hint (GTK_WINDOW (window),
                                  GDK_WINDOW_TYPE_HINT_DIALOG);
        gtk_window_set_title (GTK_WINDOW (window), "Popup");
        gtk_container_add (GTK_CONTAINER (window),
                           gtk_label_new ("Label"));
        gtk_widget_show_all (window);

        button = gtk_event_box_new ();
        gtk_container_add (GTK_CONTAINER (button),
                           gtk_label_new ("Click me"));
        g_signal_connect (button, "button_press_event",
                          G_CALLBACK (clicked), window);

        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_window_set_type_hint (GTK_WINDOW (window),
                                  GDK_WINDOW_TYPE_HINT_DIALOG);
        gtk_window_set_title (GTK_WINDOW (window), "Main");
        gtk_container_add (GTK_CONTAINER (window), button);
        gtk_widget_show_all (window);
        gtk_window_move (GTK_WINDOW (window), 100, 100);

        gtk_main ();

        return 0;
}
