From: Philip Chimento Date: Sat, 26 Oct 2013 23:03:36 +0000 (-0700) Subject: Change I/O signals to pass a unique window ID X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=3e1486e070255caf90c098d4195134438e7250dc;p=projects%2Fchimara%2Fchimara.git Change I/O signals to pass a unique window ID Change the 'char-input', 'line-input', and 'text-buffer-output' signals to pass a unique window ID string as well as the window rock value. If a client program wants to keep track of input and output in all windows, then the window rock will not do by itself - all open windows might have rock 0, for example. The string ID is guaranteed to be unique for each window, though its contents are implementation-defined. --- diff --git a/libchimara/chimara-glk.c b/libchimara/chimara-glk.c index 08d34f5..448ceb1 100644 --- a/libchimara/chimara-glk.c +++ b/libchimara/chimara-glk.c @@ -741,46 +741,64 @@ chimara_glk_class_init(ChimaraGlkClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); /** * ChimaraGlk::char-input: - * @glk: The widget that received the signal + * @self: The widget that received the signal * @window_rock: The rock value of the window that received character input * (see Rocks) - * @keysym: The key that was typed, in the form of a key symbol from + * @window_id_string: A string value uniquely identifying the window that + * received character input + * @keysym: The key that was typed, in the form of a key symbol from * gdk/gdkkeysyms.h - * + * * Emitted when a Glk window receives character input. + * The @window_rock can be used to identify the window. + * However, rock values in Glk are allowed to be identical for different + * windows, so Chimara also provides a string value with which the window + * can be uniquely identified. */ chimara_glk_signals[CHAR_INPUT] = g_signal_new("char-input", G_OBJECT_CLASS_TYPE(klass), 0, G_STRUCT_OFFSET(ChimaraGlkClass, char_input), NULL, NULL, - _chimara_marshal_VOID__UINT_UINT, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); + _chimara_marshal_VOID__UINT_STRING_UINT, + G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_UINT); /** * ChimaraGlk::line-input: - * @glk: The widget that received the signal + * @self: The widget that received the signal * @window_rock: The rock value of the window that received line input (see * Rocks) + * @window_id_string: A string value uniquely identifying the window that + * received the input * @text: The text that was typed - * + * * Emitted when a Glk window receives line input. + * The @window_rock can be used to identify the window. + * However, rock values in Glk are allowed to be identical for different + * windows, so Chimara also provides a string value with which the window + * can be uniquely identified. */ chimara_glk_signals[LINE_INPUT] = g_signal_new("line-input", G_OBJECT_CLASS_TYPE(klass), 0, G_STRUCT_OFFSET(ChimaraGlkClass, line_input), NULL, NULL, - _chimara_marshal_VOID__UINT_STRING, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); + _chimara_marshal_VOID__UINT_STRING_STRING, + G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING); /** * ChimaraGlk::text-buffer-output: - * @glk: The widget that received the signal + * @self: The widget that received the signal * @window_rock: The rock value of the window that was printed to (see Rocks) - * + * @window_id_string: A string value uniquely identifying the window that + * was printed to + * * Emitted when text is printed to a text buffer window. + * The @window_rock can be used to identify the window. + * However, rock values in Glk are allowed to be identical for different + * windows, so Chimara also provides a string value with which the window + * can be uniquely identified. */ chimara_glk_signals[TEXT_BUFFER_OUTPUT] = g_signal_new("text-buffer-output", G_OBJECT_CLASS_TYPE(klass), 0, G_STRUCT_OFFSET(ChimaraGlkClass, text_buffer_output), NULL, NULL, - _chimara_marshal_VOID__UINT_STRING, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); + _chimara_marshal_VOID__UINT_STRING_STRING, + G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING); /** * ChimaraGlk::iliad-screen-update: * @self: The widget that received the signal diff --git a/libchimara/chimara-glk.h b/libchimara/chimara-glk.h index 8001ada..953f84e 100644 --- a/libchimara/chimara-glk.h +++ b/libchimara/chimara-glk.h @@ -33,9 +33,9 @@ typedef struct { void(* stopped) (ChimaraGlk *self); void(* started) (ChimaraGlk *self); void(* waiting) (ChimaraGlk *self); - void(* char_input) (ChimaraGlk *self, guint32 window_rock, guint keysym); - void(* line_input) (ChimaraGlk *self, guint32 window_rock, gchar *text); - void(* text_buffer_output) (ChimaraGlk *self, guint32 window_rock, gchar *text); + void(* char_input) (ChimaraGlk *self, guint32 window_rock, char *string_id, unsigned keysym); + void(* line_input) (ChimaraGlk *self, guint32 window_rock, char *string_id, char *text); + void(* text_buffer_output) (ChimaraGlk *self, guint32 window_rock, char *string_id, char *text); void(* iliad_screen_update) (ChimaraGlk *self, gboolean typing); } ChimaraGlkClass; diff --git a/libchimara/chimara-if.c b/libchimara/chimara-if.c index 0d99797..2fb74c8 100644 --- a/libchimara/chimara-if.c +++ b/libchimara/chimara-if.c @@ -131,7 +131,7 @@ chimara_if_stopped(ChimaraGlk *glk) } static void -chimara_if_char_input(ChimaraGlk *glk, guint32 win_rock, guint keysym) +chimara_if_char_input(ChimaraGlk *glk, guint32 win_rock, char *string_id, unsigned keysym) { CHIMARA_IF_USE_PRIVATE(glk, priv); g_assert(priv->input == NULL); @@ -142,7 +142,7 @@ chimara_if_char_input(ChimaraGlk *glk, guint32 win_rock, guint keysym) } static void -chimara_if_line_input(ChimaraGlk *glk, guint32 win_rock, gchar *input) +chimara_if_line_input(ChimaraGlk *glk, guint32 win_rock, char *string_id, char *input) { CHIMARA_IF_USE_PRIVATE(glk, priv); g_assert(priv->input == NULL); @@ -150,7 +150,7 @@ chimara_if_line_input(ChimaraGlk *glk, guint32 win_rock, gchar *input) } static void -chimara_if_text_buffer_output(ChimaraGlk *glk, guint32 win_rock, gchar *output) +chimara_if_text_buffer_output(ChimaraGlk *glk, guint32 win_rock, char *string_id, char *output) { CHIMARA_IF_USE_PRIVATE(glk, priv); g_string_append(priv->response, output); diff --git a/libchimara/chimara-marshallers.txt b/libchimara/chimara-marshallers.txt index 559ccfc..235640f 100644 --- a/libchimara/chimara-marshallers.txt +++ b/libchimara/chimara-marshallers.txt @@ -1,6 +1,6 @@ # Extra callback marshallers for chimara # Run this file through glib-genmarshal to create chimara-marshallers.c -VOID:UINT,UINT -VOID:UINT,STRING +VOID:UINT,STRING,UINT +VOID:UINT,STRING,STRING VOID:STRING,STRING VOID:BOOLEAN diff --git a/libchimara/input.c b/libchimara/input.c index f6b7fb5..7a75214 100644 --- a/libchimara/input.c +++ b/libchimara/input.c @@ -466,7 +466,7 @@ on_char_input_key_press_event(GtkWidget *widget, GdkEventKey *event, winid_t win ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(widget, CHIMARA_TYPE_GLK)); g_assert(glk); event_throw(glk, evtype_CharInput, win, keycode, 0); - g_signal_emit_by_name(glk, "char-input", win->rock, event->keyval); + g_signal_emit_by_name(glk, "char-input", win->rock, win->librock, event->keyval); /* Only one keypress will be handled */ win->input_request_type = INPUT_REQUEST_NONE; @@ -687,7 +687,7 @@ finish_text_buffer_line_input(winid_t win, gboolean emit_signal) { ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK)); g_assert(glk); - g_signal_emit_by_name(glk, "line-input", win->rock, inserted_text); + g_signal_emit_by_name(glk, "line-input", win->rock, win->librock, inserted_text); } /* Add the text to the window input history */ @@ -742,7 +742,7 @@ finish_text_grid_line_input(winid_t win, gboolean emit_signal) { ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK)); g_assert(glk); - g_signal_emit_by_name(glk, "line-input", win->rock, text); + g_signal_emit_by_name(glk, "line-input", win->rock, win->librock, text); } /* Add the text to the window input history */ @@ -924,7 +924,7 @@ force_char_input_from_queue(winid_t win, event_t *event) gdk_threads_enter(); ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK)); g_assert(glk); - g_signal_emit_by_name(glk, "char-input", win->rock, keyval); + g_signal_emit_by_name(glk, "char-input", win->rock, win->librock, keyval); gdk_threads_leave(); event->type = evtype_CharInput; diff --git a/libchimara/strio.c b/libchimara/strio.c index b6e8f32..2a2f231 100644 --- a/libchimara/strio.c +++ b/libchimara/strio.c @@ -77,7 +77,7 @@ flush_window_buffer(winid_t win) ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK)); g_assert(glk); - g_signal_emit_by_name(glk, "text-buffer-output", win->rock, win->buffer->str); + g_signal_emit_by_name(glk, "text-buffer-output", win->rock, win->librock, win->buffer->str); } break; diff --git a/libchimara/window.c b/libchimara/window.c index 7d597b7..04ffbe0 100644 --- a/libchimara/window.c +++ b/libchimara/window.c @@ -15,6 +15,7 @@ window_new_common(glui32 rock) win->magic = MAGIC_WINDOW; win->rock = rock; + win->librock = g_strdup_printf("%p", win); if(glk_data->register_obj) win->disprock = (*glk_data->register_obj)(win, gidisp_Class_Window); @@ -64,7 +65,8 @@ window_close_common(winid_t win, gboolean destroy_node) g_node_destroy(win->window_node); win->magic = MAGIC_FREE; - + + g_free(win->librock); g_list_foreach(win->history, (GFunc)g_free, NULL); g_list_free(win->history); g_slist_free(win->extra_line_terminators); diff --git a/libchimara/window.h b/libchimara/window.h index 72ee91b..85b8db7 100644 --- a/libchimara/window.h +++ b/libchimara/window.h @@ -32,6 +32,7 @@ struct glk_window_struct { /*< private >*/ glui32 magic, rock; + char *librock; /* "library rock" - unique string identifier */ gidispatch_rock_t disprock; /* Pointer to the node in the global tree that contains this window */ GNode *window_node;