* #include <gtk/gtk.h>
* #include <libchimara/chimara-glk.h>
*
- * static gboolean
- * quit(void)
- * {
- * gtk_main_quit();
- * return TRUE;
- * }
- *
* int
* main(int argc, char *argv[])
* {
* /<!---->* Construct the window and its contents. We quit the GTK main loop
* * when the window's close button is clicked. *<!---->/
* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- * g_signal_connect(window, "delete-event", G_CALLBACK(quit), NULL);
+ * g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
* glk = chimara_glk_new();
* gtk_container_add(GTK_CONTAINER(window), glk);
* gtk_widget_show_all(window);
+ *
+ * /<!---->* Add a reference to the ChimaraGlk widget, since we want it to
+ * * persist after the window's delete-event -- otherwise it will be destroyed
+ * * with the window. *<!---->/
+ * g_object_ref(glk);
*
* /<!---->* Start the Glk program in a separate thread *<!---->/
* if(!chimara_glk_run(CHIMARA_GLK(glk), "./plugin.so", 2, plugin_argv, &error))
* * it is still running, and wait for it to exit. *<!---->/
* chimara_glk_stop(CHIMARA_GLK(glk));
* chimara_glk_wait(CHIMARA_GLK(glk));
+ * g_object_unref(glk);
*
* return 0;
* }
priv->char_input_queue = g_async_queue_new();
priv->line_input_queue = g_async_queue_new();
/* Should be g_async_queue_new_full(g_free); but only in GTK >= 2.16 */
+ priv->resource_map = NULL;
priv->resource_lock = g_mutex_new();
priv->resource_loaded = g_cond_new();
priv->resource_info_available = g_cond_new();
g_free(priv->program_name);
g_free(priv->program_info);
g_free(priv->story_name);
+ g_free(priv->styles);
+ g_free(priv->glk_styles);
/* Chain up to parent */
G_OBJECT_CLASS(chimara_glk_parent_class)->finalize(object);
* 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 character input, it
- * is arbitrary which one gets the text.
+ * 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)
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 #ChimarGlk widget