Got multisession to work, fixing #19.
glk.c glk.h \
glkstart.h \
glkunix.c glkunix.h \
+ init.c init.h \
input.c input.h \
magic.c magic.h \
mouse.c \
#include <math.h>
#include <gtk/gtk.h>
-#include <glib/gi18n.h>
+#include <config.h>
+#include <glib/gi18n-lib.h>
#include <gmodule.h>
#include <pango/pango.h>
#include "chimara-glk.h"
#include "window.h"
#include "glkstart.h"
#include "glkunix.h"
+#include "init.h"
#define CHIMARA_GLK_MIN_WIDTH 0
#define CHIMARA_GLK_MIN_HEIGHT 0
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);
/* 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 */
--- /dev/null
+#include <config.h>
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+
+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);
+ }
+}
+
--- /dev/null
+#ifndef __CHIMARA_INIT_H__
+#define __CHIMARA_INIT_H__
+
+G_GNUC_INTERNAL void chimara_init(void);
+
+#endif
+
if( !g_thread_supported() )
g_thread_init(NULL);
-
gdk_threads_init();
-
- gtk_set_locale();
gtk_init(&argc, &argv);
create_window();
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");
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));