From 348a01d86cee6fd90eea413465ec4449e23b3dd8 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 7 May 2015 09:54:59 +0700 Subject: Terminate the application when closing the window Use GtkApplication to manage the application lifecycle, and quit the application when the window is closed. --- c-gnome-app.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/c-gnome-app.c b/c-gnome-app.c index f0d9998..fabfece 100644 --- a/c-gnome-app.c +++ b/c-gnome-app.c @@ -1,17 +1,28 @@ /* Build with "gcc `pkg-config --cflags --libs gtk+-3.0` c-gnome-app.c */ #include +static void +on_activate (GApplication *app, + gpointer user_data) +{ + GtkWidget *window; + + window = gtk_application_window_new (GTK_APPLICATION (app)); + gtk_widget_show_all (window); +} + int main (int argc, char *argv[]) { - GtkWidget *window; + GtkApplication *app; + gint status; - gtk_init (&argc, &argv); - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_widget_show_all (window); + app = gtk_application_new ("org.example.CGnome", G_APPLICATION_FLAGS_NONE); + g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL); + status = g_application_run (G_APPLICATION (app), argc, argv); - gtk_main (); + g_object_unref (app); - return 0; + return status; } -- cgit