From: Philip Chimento Date: Sun, 13 Sep 2009 18:26:02 +0000 (+0000) Subject: Added an initialization function, which must be called at every entry point of the... X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=337ecd489f8430655aff7b567f383efb3a720d1c;p=rodin%2Fchimara.git Added an initialization function, which must be called at every entry point of the library. Got multisession to work, fixing #19. git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@122 ddfedd41-794f-dd11-ae45-00112f111e67 --- diff --git a/libchimara/Makefile.am b/libchimara/Makefile.am index 00d856c..bbaf6a7 100644 --- a/libchimara/Makefile.am +++ b/libchimara/Makefile.am @@ -17,6 +17,7 @@ libchimara_la_SOURCES = \ glk.c glk.h \ glkstart.h \ glkunix.c glkunix.h \ + init.c init.h \ input.c input.h \ magic.c magic.h \ mouse.c \ diff --git a/libchimara/chimara-glk.c b/libchimara/chimara-glk.c index f7887a9..ae39f16 100644 --- a/libchimara/chimara-glk.c +++ b/libchimara/chimara-glk.c @@ -2,7 +2,8 @@ #include #include -#include +#include +#include #include #include #include "chimara-glk.h" @@ -12,6 +13,7 @@ #include "window.h" #include "glkstart.h" #include "glkunix.h" +#include "init.h" #define CHIMARA_GLK_MIN_WIDTH 0 #define CHIMARA_GLK_MIN_HEIGHT 0 @@ -673,6 +675,9 @@ chimara_glk_class_init(ChimaraGlkClass *klass) GtkWidget * chimara_glk_new(void) { + /* This is a library entry point; initialize the library */ + chimara_init(); + ChimaraGlk *self = CHIMARA_GLK(g_object_new(CHIMARA_TYPE_GLK, NULL)); ChimaraGlkPrivate *priv = CHIMARA_GLK_PRIVATE(self); @@ -1021,10 +1026,6 @@ chimara_glk_run(ChimaraGlk *glk, gchar *plugin, int argc, char *argv[], GError * /* Set the program name */ startup->args.argv[0] = g_strdup(plugin); } - - /* Initialize thread-private data */ - extern GPrivate *glk_data_key; - glk_data_key = g_private_new(NULL); startup->glk_data = priv; /* Run in a separate thread */ diff --git a/libchimara/init.c b/libchimara/init.c new file mode 100644 index 0000000..bfc67dd --- /dev/null +++ b/libchimara/init.c @@ -0,0 +1,30 @@ +#include +#include +#include + +static gboolean chimara_initialized = FALSE; + +/* This function is called at every entry point of the library, to set up +threads and gettext. It is NOT called from Glk functions. */ +void +chimara_init(void) +{ + if( G_UNLIKELY(!chimara_initialized) ) + { + /* Setup gettext */ + bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + + /* Make sure threads have been initialized */ + if(!g_thread_supported()) + g_error(_("In order to use the Chimara library, you must initialize" + " the thread system by calling g_threads_init() and " + "gdk_threads_init() BEFORE the initial call to gtk_init() in " + "your main program.")); + + /* Initialize thread-private data */ + extern GPrivate *glk_data_key; + glk_data_key = g_private_new(NULL); + } +} + diff --git a/libchimara/init.h b/libchimara/init.h new file mode 100644 index 0000000..8ccf344 --- /dev/null +++ b/libchimara/init.h @@ -0,0 +1,7 @@ +#ifndef __CHIMARA_INIT_H__ +#define __CHIMARA_INIT_H__ + +G_GNUC_INTERNAL void chimara_init(void); + +#endif + diff --git a/tests/main.c b/tests/main.c index 62adca9..94755c8 100644 --- a/tests/main.c +++ b/tests/main.c @@ -145,10 +145,7 @@ main(int argc, char *argv[]) if( !g_thread_supported() ) g_thread_init(NULL); - gdk_threads_init(); - - gtk_set_locale(); gtk_init(&argc, &argv); create_window(); diff --git a/tests/test-multisession.c b/tests/test-multisession.c index 7f984c8..0bf7a3e 100644 --- a/tests/test-multisession.c +++ b/tests/test-multisession.c @@ -17,25 +17,30 @@ on_stopped(ChimaraGlk *glk, const gchar *data) g_printerr("%s stopped!\n", data); } +static gboolean +on_delete_event(void) +{ + gtk_main_quit(); + return TRUE; +} + int main(int argc, char **argv) { if( !g_thread_supported() ) g_thread_init(NULL); - gdk_threads_init(); - - gtk_set_locale(); gtk_init(&argc, &argv); GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request(window, 800, 500); + g_signal_connect(window, "delete_event", G_CALLBACK(on_delete_event), NULL); GtkWidget *hpaned = gtk_hpaned_new(); gtk_paned_set_position(GTK_PANED(hpaned), 400); GtkWidget *frotz = chimara_glk_new(); - chimara_glk_set_default_font_string(CHIMARA_GLK(frotz), "Lucida Sans Unicode 12"); + chimara_glk_set_default_font_string(CHIMARA_GLK(frotz), "Lucida Sans 12"); chimara_glk_set_monospace_font_string(CHIMARA_GLK(frotz), "Lucida Console 12"); g_signal_connect(frotz, "started", G_CALLBACK(on_started), "Frotz"); g_signal_connect(frotz, "stopped", G_CALLBACK(on_stopped), "Frotz"); @@ -56,11 +61,11 @@ main(int argc, char **argv) return 1; if(!chimara_glk_run(CHIMARA_GLK(nitfol), "../interpreters/nitfol/.libs/nitfol.so", argc, argv, NULL)) return 1; - + gdk_threads_enter(); gtk_main(); gdk_threads_leave(); - + chimara_glk_stop(CHIMARA_GLK(frotz)); chimara_glk_stop(CHIMARA_GLK(nitfol));