gtkmain: Add gtk_is_initialized()
authorPhilippe Normand <philn@igalia.com>
Fri, 8 Jun 2018 17:03:22 +0000 (18:03 +0100)
committerPhilippe Normand <philn@igalia.com>
Fri, 8 Jun 2018 17:39:38 +0000 (18:39 +0100)
This utility function can be useful to check whether GTK+ was already
initialized or not.

gtk/gtkmain.c
gtk/gtkmain.h
testsuite/gtk/main.c [new file with mode: 0644]
testsuite/gtk/meson.build

index 85bcc3865c065cf7dcf61cf74a20e2092d151b36..f0bbb899e8af6c2d21aae3fc99a6fc34398a0e1d 100644 (file)
@@ -884,6 +884,20 @@ gtk_init_check_abi_check (int num_checks, size_t sizeof_GtkWindow, size_t sizeof
 
 #endif
 
+/**
+ * gtk_is_initialized:
+ *
+ * Use this function to check if GTK+ has been initialized with gtk_init()
+ * or gtk_init_check().
+ *
+ * Returns: the initialization status
+ */
+gboolean
+gtk_is_initialized (void)
+{
+  return gtk_initialized;
+}
+
 /**
  * gtk_get_locale_direction:
  *
index deacf59b32243e8dc37ee5557b844c99e1b0ee2f..438e5985e0334966b3e75c08b52979577e0b0f60 100644 (file)
@@ -78,6 +78,9 @@ void     gtk_init                 (void);
 GDK_AVAILABLE_IN_ALL
 gboolean gtk_init_check           (void);
 
+GDK_AVAILABLE_IN_ALL
+gboolean gtk_is_initialized       (void);
+
 #ifdef G_OS_WIN32
 
 /* Variants that are used to check for correct struct packing
diff --git a/testsuite/gtk/main.c b/testsuite/gtk/main.c
new file mode 100644 (file)
index 0000000..dc5e249
--- /dev/null
@@ -0,0 +1,24 @@
+#include <gtk/gtk.h>
+#include <locale.h>
+
+static void
+test_init (void)
+{
+  g_assert (gtk_is_initialized () == FALSE);
+  g_assert (gtk_init_check ());
+  g_assert (gtk_is_initialized () == TRUE);
+}
+
+int
+main (int argc, char *argv[])
+{
+  /* Don't use gtk_test_init here because it implicitely initializes GTK+. */
+  g_test_init (&argc, &argv, NULL);
+  gtk_disable_setlocale();
+  setlocale (LC_ALL, "C");
+  g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=%s");
+
+  g_test_add_func ("/main/init", test_init);
+
+  return g_test_run ();
+}
index 116a945ebd52e1c1c830509e9890307db3b672f3..d2febc485c8b15ecfca88ca4eaaf5287d8ab0e99 100644 (file)
@@ -27,6 +27,7 @@ tests = [
   ['icontheme'],
   ['keyhash', ['../../gtk/gtkkeyhash.c', gtkresources, '../../gtk/gtkprivate.c'], gtk_cargs],
   ['listbox'],
+  ['main'],
   ['notify'],
   ['no-gtk-init'],
   ['object'],