+ gdk_threads_enter();
+}
+
+/**
+ * chimara_glk_get_running:
+ * @glk: a #ChimaraGlk widget
+ *
+ * Use this function to tell whether a program is currently running in the
+ * widget.
+ *
+ * Returns: %TRUE if @glk is executing a Glk program, %FALSE otherwise.
+ */
+gboolean
+chimara_glk_get_running(ChimaraGlk *glk)
+{
+ g_return_val_if_fail(glk || CHIMARA_IS_GLK(glk), FALSE);
+ CHIMARA_GLK_USE_PRIVATE(glk, priv);
+ return priv->running;
+}
+
+/**
+ * chimara_glk_feed_char_input:
+ * @glk: a #ChimaraGlk widget
+ * @keyval: a key symbol as defined in <filename
+ * class="headerfile">gdk/gdkkeysyms.h</filename>
+ *
+ * Pretend that a key was pressed in the Glk program as a response to a
+ * character input request. You can call this function even when no window has
+ * requested character input, in which case the key will be saved for the
+ * following window that requests character input. This has the disadvantage
+ * that if more than one window has requested character input, it is arbitrary
+ * which one gets the key press.
+ */
+void
+chimara_glk_feed_char_input(ChimaraGlk *glk, guint keyval)
+{
+ g_return_if_fail(glk || CHIMARA_IS_GLK(glk));
+ CHIMARA_GLK_USE_PRIVATE(glk, priv);
+ g_async_queue_push(priv->char_input_queue, GUINT_TO_POINTER(keyval));
+ event_throw(glk, evtype_ForcedCharInput, NULL, 0, 0);
+}
+
+/**
+ * chimara_glk_feed_line_input:
+ * @glk: a #ChimaraGlk widget
+ * @text: text to pass to the next line input request
+ *
+ * Pretend that @text was typed in the Glk program as a response to a line input
+ * request. @text does not need to end with a newline. You can call this
+ * function even when no window has requested line input, in which case the text
+ * will be saved for the following window that requests line input. This has the
+ * disadvantage that if more than one window has requested line input, it is
+ * arbitrary which one gets the text.
+ */
+void
+chimara_glk_feed_line_input(ChimaraGlk *glk, const gchar *text)
+{
+ g_return_if_fail(glk || CHIMARA_IS_GLK(glk));
+ g_return_if_fail(text);
+ CHIMARA_GLK_USE_PRIVATE(glk, priv);
+ g_async_queue_push(priv->line_input_queue, g_strdup(text));
+ event_throw(glk, evtype_ForcedLineInput, NULL, 0, 0);
+}
+
+/**
+ * chimara_glk_is_char_input_pending:
+ * @glk: a #ChimaraGlk widget
+ *
+ * Use this function to tell if character input forced by
+ * chimara_glk_feed_char_input() has been passed to an input request or not.
+ *
+ * Returns: %TRUE if forced character input is pending, %FALSE otherwise.
+ */
+gboolean
+chimara_glk_is_char_input_pending(ChimaraGlk *glk)
+{
+ g_return_val_if_fail(glk || CHIMARA_IS_GLK(glk), FALSE);
+ CHIMARA_GLK_USE_PRIVATE(glk, priv);
+ return g_async_queue_length(priv->char_input_queue) > 0;
+}
+
+/**
+ * chimara_glk_is_line_input_pending:
+ * @glk: a #ChimaraGlk widget
+ *
+ * Use this function to tell if line input forced by
+ * chimara_glk_feed_line_input() has been passed to an input request or not.
+ *
+ * Returns: %TRUE if forced line input is pending, %FALSE otherwise.
+ */
+gboolean
+chimara_glk_is_line_input_pending(ChimaraGlk *glk)
+{
+ g_return_val_if_fail(glk || CHIMARA_IS_GLK(glk), FALSE);
+ CHIMARA_GLK_USE_PRIVATE(glk, priv);
+ return g_async_queue_length(priv->line_input_queue) > 0;
+}
+
+/**
+ * chimara_glk_get_tag:
+ * @glk: a #ChimaraGlk widget
+ * @window: The type of window to retrieve the tag for
+ * @name: The name of the tag to retrieve
+ *
+ * Use this function to get a #GtkTextTag so style properties can be changed.
+ * See also chimara_glk_set_css_from_string().
+ *
+ * The layout of the text in Chimara is controlled by two sets of tags: one set
+ * describing the style in text buffers and one for text grids. See also the
+ * Glk specification for the difference between the two. The main narrative of
+ * a game is usually rendered in text buffers, whereas text grids are mostly
+ * used for status bars and in game menus.
+ *
+ * The following tag names are supported:
+ * <itemizedlist>
+ * <listitem><para>normal</para></listitem>
+ * <listitem><para>emphasized</para></listitem>
+ * <listitem><para>preformatted</para></listitem>
+ * <listitem><para>header</para></listitem>
+ * <listitem><para>subheader</para></listitem>
+ * <listitem><para>alert</para></listitem>
+ * <listitem><para>note</para></listitem>
+ * <listitem><para>block-quote</para></listitem>
+ * <listitem><para>input</para></listitem>
+ * <listitem><para>user1</para></listitem>
+ * <listitem><para>user2</para></listitem>
+ * <listitem><para>hyperlink</para></listitem>
+ * <listitem><para>pager</para></listitem>
+ * </itemizedlist>
+ *
+ * Returns: (transfer none): The #GtkTextTag corresponding to @name in the
+ * styles of @window.
+ */
+GtkTextTag *
+chimara_glk_get_tag(ChimaraGlk *glk, ChimaraGlkWindowType window, const gchar *name)
+{
+ CHIMARA_GLK_USE_PRIVATE(glk, priv);
+
+ switch(window) {
+ case CHIMARA_GLK_TEXT_BUFFER:
+ return GTK_TEXT_TAG( g_hash_table_lookup(priv->styles->text_buffer, name) );
+ break;
+ case CHIMARA_GLK_TEXT_GRID:
+ return GTK_TEXT_TAG( g_hash_table_lookup(priv->styles->text_grid, name) );
+ break;
+ default:
+ ILLEGAL_PARAM("Unknown window type: %u", window);
+ return NULL;
+ }
+}
+
+/**
+ * chimara_glk_get_tag_names:
+ * @glk: a #ChimaraGlk widget
+ * @num_tags: Return location for the number of tag names retrieved.
+ *
+ * Retrieves the possible tag names to use in chimara_glk_get_tag().
+ *
+ * Returns: (transfer none) (array length=num_tags) (element-type utf8):
+ * Array of strings containing the tag names. This array is owned by Chimara,
+ * do not free it.
+ */
+const gchar **
+chimara_glk_get_tag_names(ChimaraGlk *glk, unsigned int *num_tags)
+{
+ g_return_val_if_fail(num_tags != NULL, NULL);
+
+ *num_tags = CHIMARA_NUM_STYLES;
+ return style_get_tag_names();
+}
+
+/**
+ * chimara_glk_update_style:
+ * @glk: a #ChimaraGlk widget
+ *
+ * Processes style updates and updates the widget to reflect the new style.
+ * Call this every time you change a property of a #GtkTextTag retrieved by
+ * chimara_glk_get_tag().
+ */
+void
+chimara_glk_update_style(ChimaraGlk *glk)
+{
+ CHIMARA_GLK_USE_PRIVATE(glk, priv);
+ style_update(glk);
+
+ /* Schedule a redraw */
+ g_mutex_lock(priv->arrange_lock);
+ priv->needs_rearrange = TRUE;
+ priv->ignore_next_arrange_event = TRUE;
+ g_mutex_unlock(priv->arrange_lock);
+ gtk_widget_queue_resize( GTK_WIDGET(priv->self) );
+}
+
+/**
+ * chimara_glk_set_resource_load_callback:
+ * @glk: a #ChimaraGlk widget
+ * @func: a function to call for loading resources, or %NULL
+ * @user_data: user data to pass to @func, or %NULL
+ * @destroy_user_data: a function to call for freeing @user_data, or %NULL
+ *
+ * Sometimes it is preferable to load image and sound resources from somewhere
+ * else than a Blorb file, for example while developing a game. Section 14 of
+ * the <ulink url="http://eblong.com/zarf/blorb/blorb.html#s14">Blorb
+ * specification</ulink> allows for this possibility. This function sets @func
+ * to be called when the Glk program requests loading an image or sound without
+ * a Blorb resource map having been loaded, optionally passing @user_data as an
+ * extra parameter.
+ *
+ * Note that @func is only called if no Blorb resource map has been set; having
+ * a resource map in place overrides this function.
+ *
+ * If you pass non-%NULL for @destroy_user_data, then @glk takes ownership of
+ * @user_data. When it is not needed anymore, it will be freed by calling
+ * @destroy_user_data on it. If you wish to retain ownership of @user_data, pass
+ * %NULL for @destroy_user_data.
+ *
+ * To deactivate the callback, call this function with @func set to %NULL.
+ */
+void
+chimara_glk_set_resource_load_callback(ChimaraGlk *glk, ChimaraResourceLoadFunc func, gpointer user_data, GDestroyNotify destroy_user_data)
+{
+ CHIMARA_GLK_USE_PRIVATE(glk, priv);
+
+ if(priv->resource_load_callback == func
+ && priv->resource_load_callback_data == user_data
+ && priv->resource_load_callback_destroy_data == destroy_user_data)
+ return;
+
+ if(priv->resource_load_callback_destroy_data)
+ priv->resource_load_callback_destroy_data(priv->resource_load_callback_data);
+
+ priv->resource_load_callback = func;
+ priv->resource_load_callback_data = user_data;
+ priv->resource_load_callback_destroy_data = destroy_user_data;