Started using thread-private data. Multisession still doesn't work, but regular opera...
authorPhilip Chimento <philip.chimento@gmail.com>
Sun, 13 Sep 2009 17:07:59 +0000 (17:07 +0000)
committerPhilip Chimento <philip.chimento@gmail.com>
Sun, 13 Sep 2009 17:07:59 +0000 (17:07 +0000)
git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@121 ddfedd41-794f-dd11-ae45-00112f111e67

15 files changed:
libchimara/abort.c
libchimara/abort.h
libchimara/chimara-glk.c
libchimara/event.c
libchimara/event.h
libchimara/fileref.c
libchimara/glk.c
libchimara/glkunix.c
libchimara/input.c
libchimara/resource.c
libchimara/stream.c
libchimara/style.c
libchimara/timer.c
libchimara/timer.h
libchimara/window.c

index 61234a06f5743747687e6fbf397763dae528598c..18b2725da810fbb143fc44dd173dd54a35ad35db 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "chimara-glk-private.h"
 
-extern ChimaraGlkPrivate *glk_data;
+extern GPrivate *glk_data_key;
 
 /**
  * glk_set_interrupt_handler:
@@ -29,6 +29,7 @@ extern ChimaraGlkPrivate *glk_data;
 void
 glk_set_interrupt_handler(void (*func)(void))
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        glk_data->interrupt_handler = func;
 }
 
@@ -37,30 +38,18 @@ user's interrupt handler. */
 static void
 abort_glk()
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        if(glk_data->interrupt_handler)
                (*(glk_data->interrupt_handler))();
        g_signal_emit_by_name(glk_data->self, "stopped");
        g_thread_exit(NULL);
 }
 
-/* Internal function: Signal this Glk thread to abort. Does nothing if the abort
-mutex has already been freed. (That means the thread already ended.) */
-void
-signal_abort()
-{
-       if(glk_data && glk_data->abort_lock) {
-               g_mutex_lock(glk_data->abort_lock);
-               glk_data->abort_signalled = TRUE;
-               g_mutex_unlock(glk_data->abort_lock);
-               /* Stop blocking on the event queue condition */
-               event_throw(evtype_Abort, NULL, 0, 0);
-       }
-}
-
 /* Internal function: check if the Glk program has been interrupted. */
 void
 check_for_abort()
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        g_mutex_lock(glk_data->abort_lock);
        if(glk_data->abort_signalled) 
        {
index 1ba2bcceb14b7ca475e161d04d3497a54b2714a2..f075550c4d194e3c7792f78fd0d1faa7d1b77670 100644 (file)
@@ -2,7 +2,6 @@
 #define ABORT_H
 
 G_GNUC_INTERNAL void check_for_abort();
-G_GNUC_INTERNAL void signal_abort();
 
 #endif
 
index b9e0437e3249a48eda74b6016eb2ace27a020e71..f7887a94a7485a5e434e2a3e8345f0d0d3539c22 100644 (file)
@@ -484,7 +484,7 @@ chimara_glk_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
                if(!priv->ignore_next_arrange_event)
                {
                        if(arrange)
-                               event_throw(evtype_Arrange, arrange == priv->root_window->data? NULL : arrange, 0, 0);
+                               event_throw(CHIMARA_GLK(widget), evtype_Arrange, arrange == priv->root_window->data? NULL : arrange, 0, 0);
                }
                else
                        priv->ignore_next_arrange_event = FALSE;
@@ -929,19 +929,21 @@ struct StartupData {
        glk_main_t glk_main;
        glkunix_startup_code_t glkunix_startup_code;
        glkunix_startup_t args;
+       ChimaraGlkPrivate *glk_data;
 };
 
 /* glk_enter() is the actual function called in the new thread in which glk_main() runs.  */
 static gpointer
 glk_enter(struct StartupData *startup)
 {
-    extern ChimaraGlkPrivate *glk_data;
+       extern GPrivate *glk_data_key;
+       g_private_set(glk_data_key, startup->glk_data);
        
        /* Run startup function */
        if(startup->glkunix_startup_code) {
-               glk_data->in_startup = TRUE;
+               startup->glk_data->in_startup = TRUE;
                int result = startup->glkunix_startup_code(&startup->args);
-               glk_data->in_startup = FALSE;
+               startup->glk_data->in_startup = FALSE;
                
                int i = 0;
                while(i < startup->args.argc)
@@ -953,10 +955,10 @@ glk_enter(struct StartupData *startup)
        }
        
        /* Run main function */
-    g_signal_emit_by_name(glk_data->self, "started");
+    g_signal_emit_by_name(startup->glk_data->self, "started");
        (startup->glk_main)();
-       g_slice_free(struct StartupData, startup);      
-       g_signal_emit_by_name(glk_data->self, "stopped");
+       g_signal_emit_by_name(startup->glk_data->self, "stopped");
+       g_slice_free(struct StartupData, startup);
        return NULL;
 }
 
@@ -1020,10 +1022,10 @@ chimara_glk_run(ChimaraGlk *glk, gchar *plugin, int argc, char *argv[], GError *
                startup->args.argv[0] = g_strdup(plugin);
     }
 
-       extern ChimaraGlkPrivate *glk_data;
-    /* Set the thread's private data */
-    /* TODO: Do this with a GPrivate */
-    glk_data = priv;
+       /* 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 */
        priv->thread = g_thread_create((GThreadFunc)glk_enter, startup, TRUE, error);
@@ -1044,7 +1046,14 @@ chimara_glk_stop(ChimaraGlk *glk)
 {
     g_return_if_fail(glk || CHIMARA_IS_GLK(glk));
     /* TODO: check if glk is actually running a program */
-       signal_abort();
+       ChimaraGlkPrivate *priv = CHIMARA_GLK_PRIVATE(glk);
+       if(priv->abort_lock) {
+               g_mutex_lock(priv->abort_lock);
+               priv->abort_signalled = TRUE;
+               g_mutex_unlock(priv->abort_lock);
+               /* Stop blocking on the event queue condition */
+               event_throw(glk, evtype_Abort, NULL, 0, 0);
+       }
 }
 
 /**
index 1a24f28d9792ec7b9f1f82136e4aab92f980f9db..4bbb391b597bb028dc7e5a75994de54ee188858f 100644 (file)
@@ -3,9 +3,10 @@
 #include "glk.h"
 #include <string.h>
 
+#include "chimara-glk.h"
 #include "chimara-glk-private.h"
 
-extern ChimaraGlkPrivate *glk_data;
+extern GPrivate *glk_data_key;
 
 #define EVENT_TIMEOUT_MICROSECONDS (3000000)
 
@@ -13,23 +14,25 @@ extern ChimaraGlkPrivate *glk_data;
 full, wait for max three seconds and then drop the event. If the event queue is
 NULL, i.e. freed, then fail silently. */
 void
-event_throw(glui32 type, winid_t win, glui32 val1, glui32 val2)
+event_throw(ChimaraGlk *glk, glui32 type, winid_t win, glui32 val1, glui32 val2)
 {
-       if(!glk_data->event_queue)
+       ChimaraGlkPrivate *priv = CHIMARA_GLK_PRIVATE(glk);
+       
+       if(!priv->event_queue)
                return;
 
        GTimeVal timeout;
        g_get_current_time(&timeout);
        g_time_val_add(&timeout, EVENT_TIMEOUT_MICROSECONDS);
 
-       g_mutex_lock(glk_data->event_lock);
+       g_mutex_lock(priv->event_lock);
 
        /* Wait for room in the event queue */
-       while( g_queue_get_length(glk_data->event_queue) >= EVENT_QUEUE_MAX_LENGTH )
-               if( !g_cond_timed_wait(glk_data->event_queue_not_full, glk_data->event_lock, &timeout) ) 
+       while( g_queue_get_length(priv->event_queue) >= EVENT_QUEUE_MAX_LENGTH )
+               if( !g_cond_timed_wait(priv->event_queue_not_full, priv->event_lock, &timeout) ) 
                {
                        /* Drop the event after 3 seconds */
-                       g_mutex_unlock(glk_data->event_lock);
+                       g_mutex_unlock(priv->event_lock);
                        return;
                }
 
@@ -38,12 +41,12 @@ event_throw(glui32 type, winid_t win, glui32 val1, glui32 val2)
        event->win = win;
        event->val1 = val1;
        event->val2 = val2;
-       g_queue_push_head(glk_data->event_queue, event);
+       g_queue_push_head(priv->event_queue, event);
 
        /* Signal that there is an event */
-       g_cond_signal(glk_data->event_queue_not_empty);
+       g_cond_signal(priv->event_queue_not_empty);
 
-       g_mutex_unlock(glk_data->event_lock);
+       g_mutex_unlock(priv->event_lock);
 }
 
 /**
@@ -64,6 +67,8 @@ glk_select(event_t *event)
 {
        g_return_if_fail(event != NULL);
 
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
        g_mutex_lock(glk_data->event_lock);
 
        /* Wait for an event */
@@ -154,6 +159,8 @@ glk_select_poll(event_t *event)
 {
        g_return_if_fail(event != NULL);
 
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
        event->type = evtype_None;
        
        g_mutex_lock(glk_data->event_lock);
index 7cf80bdf7fb5ee4e0d0ebc823a8c5fa4165ead62..32e5bb92b8ba2bc7441514d28a7aa1c6a2d55f08 100644 (file)
@@ -3,10 +3,11 @@
 
 #include <glib.h>
 #include "glk.h"
+#include "chimara-glk.h"
 
 #define EVENT_QUEUE_MAX_LENGTH (100)
 #define evtype_Abort (-1)
 
-G_GNUC_INTERNAL void event_throw(glui32 type, winid_t win, glui32 val1, glui32 val2);
+G_GNUC_INTERNAL void event_throw(ChimaraGlk *glk, glui32 type, winid_t win, glui32 val1, glui32 val2);
 
 #endif
index d20e1f24da228aea4af649af28fe8c5b1c15e4e2..97c6e487bb62a02c79b4af9c8665a50f220b9edd 100644 (file)
@@ -7,7 +7,7 @@
 #include "magic.h"
 #include "chimara-glk-private.h"
 
-extern ChimaraGlkPrivate *glk_data;
+extern GPrivate *glk_data_key;
 
 /**
  * glk_fileref_iterate:
@@ -24,7 +24,8 @@ frefid_t
 glk_fileref_iterate(frefid_t fref, glui32 *rockptr)
 {
        VALID_FILEREF_OR_NULL(fref, return NULL);
-       
+
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        GList *retnode;
        
        if(fref == NULL)
@@ -62,6 +63,8 @@ fileref_new(gchar *filename, glui32 rock, glui32 usage, glui32 orig_filemode)
 {
        g_return_val_if_fail(filename != NULL, NULL);
 
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
        frefid_t f = g_new0(struct glk_fileref_struct, 1);
        f->magic = MAGIC_FILEREF;
        f->rock = rock;
@@ -185,6 +188,8 @@ glk_fileref_create_by_prompt(glui32 usage, glui32 fmode, glui32 rock)
        for each usage */
        GtkWidget *chooser;
 
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
        gdk_threads_enter();
 
        switch(fmode)
@@ -289,13 +294,11 @@ glk_fileref_create_by_name(glui32 usage, char *name, glui32 rock)
 {
        g_return_val_if_fail(name != NULL && strlen(name) > 0, NULL);
 
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
        /* Do any string-munging here to remove illegal Latin-1 characters from 
        filename. On ext3, the only illegal characters are '/' and '\0'. */
-       
-       char *ptr = name;
-       while(*ptr++)
-               if(*ptr == '/')
-                       *ptr = '_';
+       g_strdelimit(name, "/", '_');
        
        /* Find out what encoding filenames are in */
        const gchar **charsets; /* Do not free */
@@ -377,6 +380,8 @@ void
 glk_fileref_destroy(frefid_t fref)
 {
        VALID_FILEREF(fref, return);
+
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        
        glk_data->fileref_list = g_list_delete_link(glk_data->fileref_list, fref->fileref_list);
        if(fref->filename)
index 2f7e10f719184cfcba5094948d034599c0553d02..27e30072769198e0ec2a0ec2959ca0a0a5fee8d6 100644 (file)
@@ -6,7 +6,7 @@
 #include "chimara-glk-private.h"
 #include "gi_blorb.h"
 
-G_GNUC_INTERNAL ChimaraGlkPrivate *glk_data = NULL;
+G_GNUC_INTERNAL GPrivate *glk_data_key = NULL;
 
 /**
  * glk_exit:
@@ -42,6 +42,8 @@ G_GNUC_INTERNAL ChimaraGlkPrivate *glk_data = NULL;
 void
 glk_exit(void)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
        if(!glk_data->in_startup)
                g_signal_emit_by_name(glk_data->self, "stopped");
 
@@ -54,7 +56,6 @@ glk_exit(void)
                glk_stream_close(glk_data->resource_file, NULL);
        }
 
-    glk_data = NULL;
        g_thread_exit(NULL);
 }
 
index ee1194357682a1b8ae619006663a136c013989b0..704ac0c8acba757550cd38488d3d09a639983b78 100644 (file)
@@ -7,7 +7,7 @@
 #include "fileref.h"
 #include "stream.h"
 
-extern ChimaraGlkPrivate *glk_data;
+extern GPrivate *glk_data_key;
 
 /**
  * glkunix_stream_open_pathname:
@@ -25,6 +25,8 @@ extern ChimaraGlkPrivate *glk_data;
 strid_t
 glkunix_stream_open_pathname(char *pathname, glui32 usage, glui32 rock)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
        if(!glk_data->in_startup)
                ILLEGAL("glkunix_stream_open_pathname() may only be called from "
                                "glkunix_startup_code().");
@@ -53,6 +55,8 @@ glkunix_set_base_file(char *filename)
 {
        g_return_if_fail(filename);
        g_return_if_fail(strlen(filename) > 0);
+
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        
        gchar *dirname = g_path_get_dirname(filename);
        if(!g_file_test(dirname, G_FILE_TEST_IS_DIR))
index 8400998f22f057b0bc59fb2ce5bdb0007d279988..ab1eef52de587023d18f79cd14ec81fa5abcfb06 100644 (file)
@@ -400,7 +400,7 @@ on_window_key_press_event(GtkWidget *widget, GdkEventKey *event, winid_t win)
                                keycode = keycode_Unknown;      
        }
 
-       event_throw(evtype_CharInput, win, keycode, 0);
+       event_throw(CHIMARA_GLK(gtk_widget_get_ancestor(widget, CHIMARA_TYPE_GLK)), evtype_CharInput, win, keycode, 0);
        
        /* Only one keypress will be handled */
        win->input_request_type = INPUT_REQUEST_NONE;
@@ -542,7 +542,7 @@ after_window_insert_text(GtkTextBuffer *textbuffer, GtkTextIter *location, gchar
         gtk_text_view_set_editable(GTK_TEXT_VIEW(win->widget), FALSE);
 
         int chars_written = flush_text_buffer(win);
-               event_throw(evtype_LineInput, win, chars_written, 0);
+               event_throw(CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK)), evtype_LineInput, win, chars_written, 0);
        }
 }
 
@@ -554,6 +554,6 @@ on_input_entry_activate(GtkEntry *input_entry, winid_t win)
        g_signal_handler_block( G_OBJECT(win->widget), win->keypress_handler );
 
        int chars_written = flush_text_grid(win);
-       event_throw(evtype_LineInput, win, chars_written, 0);
+       event_throw(CHIMARA_GLK(gtk_widget_get_ancestor(GTK_WIDGET(input_entry), CHIMARA_TYPE_GLK)), evtype_LineInput, win, chars_written, 0);
 }
 
index ad5dbf115d1c4a7fc6a3ecb436ba9b61e7c697c5..b3c98ecbdc1ee9724daed6849b2bee1ad1f46136 100644 (file)
@@ -1,6 +1,6 @@
 #include "resource.h"
 
-extern ChimaraGlkPrivate *glk_data;
+extern GPrivate *glk_data_key;
 
 /**
  * giblorb_set_resource_map:
@@ -19,6 +19,7 @@ extern ChimaraGlkPrivate *glk_data;
 giblorb_err_t
 giblorb_set_resource_map(strid_t file)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        giblorb_map_t *newmap; /* create map allocates memory */
        giblorb_err_t error = giblorb_create_map(file, &newmap);
 
@@ -50,6 +51,8 @@ giblorb_set_resource_map(strid_t file)
 giblorb_map_t*
 giblorb_get_resource_map()
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
        if(glk_data->resource_map == NULL) {
                WARNING("Resource map not set yet.\n");
        }
index aa27a39cf5ca5d8047ede38f072d0eb05b048bc1..72b36a84087eadbdb0f54662e40c4779a6263947 100644 (file)
@@ -7,12 +7,14 @@
 #include <glib/gstdio.h>
 
 #include "chimara-glk-private.h"
-extern ChimaraGlkPrivate *glk_data;
+extern GPrivate *glk_data_key;
 
 /* Internal function: create a stream with a specified rock value */
 static strid_t
 stream_new_common(glui32 rock, glui32 fmode, enum StreamType type)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
        strid_t str = g_new0(struct glk_stream_struct, 1);
        str->magic = MAGIC_STREAM;
        str->rock = rock;
@@ -52,7 +54,8 @@ strid_t
 glk_stream_iterate(strid_t str, glui32 *rockptr)
 {
        VALID_STREAM_OR_NULL(str, return NULL);
-       
+
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        GList *retnode;
        
        if(str == NULL)
@@ -96,6 +99,8 @@ void
 glk_stream_set_current(strid_t str)
 {
        VALID_STREAM_OR_NULL(str, return);
+
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        
        if(str != NULL && str->file_mode == filemode_Read)
        {
@@ -116,6 +121,7 @@ glk_stream_set_current(strid_t str)
 strid_t
 glk_stream_get_current()
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        return glk_data->current_stream;
 }
 
@@ -130,6 +136,7 @@ glk_stream_get_current()
 void
 glk_put_char(unsigned char ch)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        VALID_STREAM(glk_data->current_stream, return);
        glk_put_char_stream(glk_data->current_stream, ch);
 }
@@ -145,6 +152,7 @@ glk_put_char(unsigned char ch)
 void
 glk_put_char_uni(glui32 ch)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        VALID_STREAM(glk_data->current_stream, return);
        glk_put_char_stream_uni(glk_data->current_stream, ch);
 }
@@ -164,6 +172,7 @@ glk_put_char_uni(glui32 ch)
 void
 glk_put_string(char *s)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        VALID_STREAM(glk_data->current_stream, return);
        glk_put_string_stream(glk_data->current_stream, s);
 }
@@ -179,6 +188,7 @@ glk_put_string(char *s)
 void
 glk_put_string_uni(glui32 *s)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        VALID_STREAM(glk_data->current_stream, return);
        glk_put_string_stream_uni(glk_data->current_stream, s);
 }
@@ -199,6 +209,7 @@ glk_put_string_uni(glui32 *s)
 void
 glk_put_buffer(char *buf, glui32 len)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        VALID_STREAM(glk_data->current_stream, return);
        glk_put_buffer_stream(glk_data->current_stream, buf, len);
 }
@@ -214,6 +225,7 @@ glk_put_buffer(char *buf, glui32 len)
 void
 glk_put_buffer_uni(glui32 *buf, glui32 len)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        VALID_STREAM(glk_data->current_stream, return);
        glk_put_buffer_stream_uni(glk_data->current_stream, buf, len);
 }
@@ -452,6 +464,8 @@ glk_stream_close(strid_t str, stream_result_t *result)
 void
 stream_close_common(strid_t str, stream_result_t *result)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
        /* Remove the stream from the global stream list */
        glk_data->stream_list = g_list_delete_link(glk_data->stream_list, str->stream_list);
        
index 2db2e09e45fcd8395f9cdf46476340adb25606a0..3826ebfc4d1fcf482de4fc8c8ee7cb81f97166f6 100644 (file)
@@ -1,6 +1,6 @@
 #include "style.h"
 
-extern ChimaraGlkPrivate *glk_data;
+extern GPrivate *glk_data_key;
 
 /**
  * glk_set_style:
@@ -18,6 +18,7 @@ extern ChimaraGlkPrivate *glk_data;
 void
 glk_set_style(glui32 styl)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        g_return_if_fail(glk_data->current_stream != NULL);
        glk_set_style_stream(glk_data->current_stream, styl);
 }
@@ -62,6 +63,8 @@ style_init_textbuffer(GtkTextBuffer *buffer)
 {
        g_return_if_fail(buffer != NULL);
 
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+
        gtk_text_buffer_create_tag(buffer, "normal", NULL);
        gtk_text_buffer_create_tag(buffer, "emphasized", "style", PANGO_STYLE_ITALIC, NULL);
        gtk_text_buffer_create_tag(buffer, "preformatted", "font-desc", glk_data->monospace_font_desc, NULL);
@@ -91,6 +94,7 @@ apply_stylehint_to_tag(GtkTextTag *tag, glui32 hint, glsi32 val)
 {
        g_return_if_fail(tag != NULL);
 
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        GObject *tag_object = G_OBJECT(tag);
        gint reverse_color = 0;
 
index f063defdbe60834dd1cf3c7a6fc55980560e5c6b..400f5062f1d6dd86fc764daf8399f8f8834af377 100644 (file)
@@ -1,6 +1,6 @@
 #include "timer.h"
 
-extern ChimaraGlkPrivate *glk_data;
+extern GPrivate *glk_data_key;
 
 /**
  * glk_request_timer_events:
@@ -46,6 +46,8 @@ extern ChimaraGlkPrivate *glk_data;
 void
 glk_request_timer_events(glui32 millisecs)
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
        // Stop any existing timer
        if(glk_data->timer_id != 0) {
                g_source_remove(glk_data->timer_id);
@@ -55,7 +57,7 @@ glk_request_timer_events(glui32 millisecs)
        if(millisecs == 0)
                return;
        
-       glk_data->timer_id = g_timeout_add(millisecs, push_timer_event, NULL);
+       glk_data->timer_id = g_timeout_add(millisecs, (GSourceFunc)push_timer_event, glk_data->self);
 }
 
 /*
@@ -63,9 +65,9 @@ glk_request_timer_events(glui32 millisecs)
  * Will always return TRUE
  */
 gboolean
-push_timer_event(gpointer data)
+push_timer_event(ChimaraGlk *glk)
 {
-       event_throw(evtype_Timer, NULL, 0, 0);
+       event_throw(glk, evtype_Timer, NULL, 0, 0);
 
        return TRUE;
 }
index 1edb670e2c322432af5daf8abc08ffd82267fdd9..b3baf7beabfbd5165969b3a3e01f8313c81dc6d8 100644 (file)
@@ -3,8 +3,9 @@
 
 #include <glib.h>
 #include "event.h"
+#include "chimara-glk.h"
 #include "chimara-glk-private.h"
 
-G_GNUC_INTERNAL gboolean push_timer_event(gpointer  data);
+G_GNUC_INTERNAL gboolean push_timer_event(ChimaraGlk *glk);
 
 #endif
index 5e0ec5015ff95cfded035c18a4b5882d08499a5d..bbfe49db68658f134ee667503044a19b5117ceb3 100644 (file)
@@ -1,8 +1,9 @@
+#include <glib.h>
 #include "window.h"
 #include "magic.h"
 #include "chimara-glk-private.h"
 
-extern ChimaraGlkPrivate *glk_data;
+extern GPrivate *glk_data_key;
 
 /**
  * glk_window_iterate:
@@ -25,6 +26,7 @@ glk_window_iterate(winid_t win, glui32 *rockptr)
 {
        VALID_WINDOW_OR_NULL(win, return NULL);
        
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        GNode *retnode;
        
        if(win == NULL)
@@ -135,6 +137,7 @@ glk_window_get_sibling(winid_t win)
 winid_t
 glk_window_get_root()
 {
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        if(glk_data->root_window == NULL)
                return NULL;
        return (winid_t)glk_data->root_window->data;
@@ -377,6 +380,8 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype,
        g_return_val_if_fail(method == (method & (winmethod_DirMask | winmethod_DivisionMask)), NULL);
        g_return_val_if_fail(!(((method & winmethod_DivisionMask) == winmethod_Proportional) && size > 100), NULL);     
 
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
        if(split == NULL && glk_data->root_window != NULL)
        {
                ILLEGAL("Tried to open a new root window, but there is already a root window");
@@ -701,6 +706,8 @@ void
 glk_window_close(winid_t win, stream_result_t *result)
 {
        VALID_WINDOW(win, return);
+
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        
        gdk_threads_enter(); /* Prevent redraw while we're trashing the window */
        
@@ -810,6 +817,8 @@ glk_window_clear(winid_t win)
 {
        VALID_WINDOW(win, return);
        g_return_if_fail(win->input_request_type != INPUT_REQUEST_LINE && win->input_request_type != INPUT_REQUEST_LINE_UNICODE);
+
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        
        switch(win->type)
        {
@@ -976,6 +985,8 @@ glk_window_get_size(winid_t win, glui32 *widthptr, glui32 *heightptr)
 {
        VALID_WINDOW(win, return);
 
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
+       
     switch(win->type)
     {
         case wintype_Blank:
@@ -1103,6 +1114,8 @@ glk_window_set_arrangement(winid_t win, glui32 method, glui32 size, winid_t keyw
        }
        g_return_if_fail(method == (method & (winmethod_DirMask | winmethod_DivisionMask)));
        g_return_if_fail(!(((method & winmethod_DivisionMask) == winmethod_Proportional) && size > 100));
+
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        
        win->split_method = method;
        win->constraint_size = size;
@@ -1177,6 +1190,8 @@ glk_window_move_cursor(winid_t win, glui32 xpos, glui32 ypos)
 {
        VALID_WINDOW(win, return);
        g_return_if_fail(win->type == wintype_TextGrid);
+
+       ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
        
        /* Wait until the window's size is current */
        g_mutex_lock(glk_data->arrange_lock);