/* gcc `pkg-config --cflags --libs gtk+-3.0` -g test.c -o test && ./test */

#include <gtk/gtk.h>

static guint candy;

static gboolean
call_uninhibit_and_quit (gpointer app)
{
        gtk_application_uninhibit (app, candy);

        g_application_quit (app);

        return FALSE;
}

static gboolean
call_inhibit (gpointer app)
{
        candy = gtk_application_inhibit (app, NULL,
                GTK_APPLICATION_INHIBIT_SWITCH |
                GTK_APPLICATION_INHIBIT_LOGOUT |
                GTK_APPLICATION_INHIBIT_SUSPEND,
                "Preparing to quit");

        g_timeout_add (500, call_uninhibit_and_quit, app);

        return FALSE;
}

static void
activate_cb (GApplication *app,
             gpointer user_data)
{
       	GtkWidget *dlg;

        g_timeout_add (500, call_inhibit, app);

        dlg = gtk_dialog_new_with_buttons ("My dialog", NULL, 0, "Bye", 1, NULL);
        gtk_application_add_window ((GtkApplication *) app, GTK_WINDOW (dlg));
       	gtk_widget_show (dlg);
}

int
main (int argc, char *argv[])
{
        GtkApplication *app;

        gtk_init (&argc, &argv);

        app = gtk_application_new (NULL, G_APPLICATION_FLAGS_NONE);
        g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL);

        g_application_run (G_APPLICATION (app), argc, argv);

       	g_object_unref (app);

        return 0;
}
