diff options
author | Philippe Normand <philn@igalia.com> | 2018-06-08 18:03:22 +0100 |
---|---|---|
committer | Philippe Normand <philn@igalia.com> | 2018-06-08 18:39:38 +0100 |
commit | 542ad4fdc579e689e3e0486e45f4ba7b0c6ee433 (patch) | |
tree | a01b17f031f1c9ffb0938e1d8a963cdf5d3a8254 | |
parent | 085368eb93ecbe2d973fb36c6a8801617d5eaccb (diff) | |
download | gtk+-542ad4fdc579e689e3e0486e45f4ba7b0c6ee433.tar.gz |
gtkmain: Add gtk_is_initialized()
This utility function can be useful to check whether GTK+ was already
initialized or not.
-rw-r--r-- | gtk/gtkmain.c | 14 | ||||
-rw-r--r-- | gtk/gtkmain.h | 3 | ||||
-rw-r--r-- | testsuite/gtk/main.c | 24 | ||||
-rw-r--r-- | testsuite/gtk/meson.build | 1 |
4 files changed, 42 insertions, 0 deletions
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index 85bcc3865c..f0bbb899e8 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -885,6 +885,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: * * Get the direction of the current locale. This is the expected diff --git a/gtk/gtkmain.h b/gtk/gtkmain.h index deacf59b32..438e5985e0 100644 --- a/gtk/gtkmain.h +++ b/gtk/gtkmain.h @@ -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 index 0000000000..dc5e249069 --- /dev/null +++ b/testsuite/gtk/main.c @@ -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 (); +} diff --git a/testsuite/gtk/meson.build b/testsuite/gtk/meson.build index 116a945ebd..d2febc485c 100644 --- a/testsuite/gtk/meson.build +++ b/testsuite/gtk/meson.build @@ -27,6 +27,7 @@ tests = [ ['icontheme'], ['keyhash', ['../../gtk/gtkkeyhash.c', gtkresources, '../../gtk/gtkprivate.c'], gtk_cargs], ['listbox'], + ['main'], ['notify'], ['no-gtk-init'], ['object'], |