summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid King <amigadave@amigadave.com>2015-05-07 09:54:59 +0700
committerDavid King <amigadave@amigadave.com>2015-05-07 09:54:59 +0700
commit348a01d86cee6fd90eea413465ec4449e23b3dd8 (patch)
tree0f727595bc0d2fc35288a3d1797d173ba09f48bd
parent135afdb38912b0350de8d827c8307e432fd25234 (diff)
downloadc-gnome-app-348a01d86cee6fd90eea413465ec4449e23b3dd8.tar.gz
c-gnome-app-348a01d86cee6fd90eea413465ec4449e23b3dd8.tar.xz
c-gnome-app-348a01d86cee6fd90eea413465ec4449e23b3dd8.zip
Terminate the application when closing the window
Use GtkApplication to manage the application lifecycle, and quit the application when the window is closed.
-rw-r--r--c-gnome-app.c23
1 files 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 <gtk/gtk.h>
+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;
}