From: fliep Date: Sun, 11 Oct 2009 22:18:31 +0000 (+0000) Subject: Implemented the 'waiting' signal on the ChimaraGlk widget to let listeners know when... X-Git-Tag: v0.9~323 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=aa81cab268d6b17079c9d04226bdfc47a1b6a289;p=projects%2Fchimara%2Fchimara.git Implemented the 'waiting' signal on the ChimaraGlk widget to let listeners know when glk_select() is waiting for input. --- diff --git a/libchimara/chimara-glk.c b/libchimara/chimara-glk.c index 3f5c71b..da44193 100644 --- a/libchimara/chimara-glk.c +++ b/libchimara/chimara-glk.c @@ -59,6 +59,7 @@ enum { enum { STOPPED, STARTED, + WAITING, CHAR_INPUT, LINE_INPUT, TEXT_BUFFER_OUTPUT, @@ -549,6 +550,12 @@ chimara_glk_started(ChimaraGlk *self) /* TODO: Add default signal handler implementation here */ } +static void +chimara_glk_waiting(ChimaraGlk *self) +{ + /* TODO: Add default signal handler */ +} + static void chimara_glk_char_input(ChimaraGlk *self, guint window_rock, guint keysym) { @@ -591,6 +598,7 @@ chimara_glk_class_init(ChimaraGlkClass *klass) /* Signals */ klass->stopped = chimara_glk_stopped; klass->started = chimara_glk_started; + klass->waiting = chimara_glk_waiting; klass->char_input = chimara_glk_char_input; klass->line_input = chimara_glk_line_input; klass->text_buffer_output = chimara_glk_text_buffer_output; @@ -603,6 +611,7 @@ chimara_glk_class_init(ChimaraGlkClass *klass) */ chimara_glk_signals[STOPPED] = g_signal_new("stopped", G_OBJECT_CLASS_TYPE(klass), 0, + /* FIXME: Should be G_SIGNAL_RUN_CLEANUP but that segfaults??! */ G_STRUCT_OFFSET(ChimaraGlkClass, stopped), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); /** @@ -613,9 +622,14 @@ chimara_glk_class_init(ChimaraGlkClass *klass) * the widget. */ chimara_glk_signals[STARTED] = g_signal_new ("started", - G_OBJECT_CLASS_TYPE (klass), 0, + G_OBJECT_CLASS_TYPE(klass), 0, G_STRUCT_OFFSET(ChimaraGlkClass, started), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + chimara_glk_signals[WAITING] = g_signal_new("waiting", + G_OBJECT_CLASS_TYPE(klass), 0, + G_STRUCT_OFFSET(ChimaraGlkClass, waiting), NULL, NULL, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); chimara_glk_signals[CHAR_INPUT] = g_signal_new("char-input", G_OBJECT_CLASS_TYPE(klass), 0, diff --git a/libchimara/chimara-glk.h b/libchimara/chimara-glk.h index 78ea8de..32725de 100644 --- a/libchimara/chimara-glk.h +++ b/libchimara/chimara-glk.h @@ -3,7 +3,7 @@ #ifndef __CHIMARA_GLK_H__ #define __CHIMARA_GLK_H__ -#include +#include #include #include @@ -32,6 +32,7 @@ typedef struct _ChimaraGlkClass { /* Signals */ 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); diff --git a/libchimara/event.c b/libchimara/event.c index ca5e21a..5da6dd8 100644 --- a/libchimara/event.c +++ b/libchimara/event.c @@ -70,6 +70,9 @@ glk_select(event_t *event) ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + /* Emit the "waiting" signal to let listeners know we are ready for input */ + g_signal_emit_by_name(glk_data->self, "waiting"); + g_mutex_lock(glk_data->event_lock); /* Wait for an event */ @@ -200,4 +203,4 @@ glk_select_poll(event_t *event) /* If an abort event was generated, the thread should have exited by now */ g_assert(event->type != evtype_Abort); -} \ No newline at end of file +} diff --git a/tests/main.c b/tests/main.c index 9ed6158..e73df82 100644 --- a/tests/main.c +++ b/tests/main.c @@ -62,6 +62,12 @@ on_stopped(ChimaraGlk *glk) g_printerr("Stopped!\n"); } +static void +on_waiting(ChimaraGlk *glk) +{ + g_printerr("Waiting!\n"); +} + static void on_char_input(ChimaraGlk *glk, guint32 window_rock, guint keysym) { @@ -125,14 +131,13 @@ create_window(void) return; } - gtk_builder_connect_signals(builder, NULL); - glk = chimara_glk_new(); g_object_set(glk, "border-width", 6, "spacing", 6, NULL); chimara_glk_set_default_font_string(CHIMARA_GLK(glk), "Serif 12"); chimara_glk_set_monospace_font_string(CHIMARA_GLK(glk), "Monospace 12"); g_signal_connect(glk, "started", G_CALLBACK(on_started), NULL); g_signal_connect(glk, "stopped", G_CALLBACK(on_stopped), NULL); + g_signal_connect(glk, "waiting", G_CALLBACK(on_waiting), NULL); g_signal_connect(glk, "char-input", G_CALLBACK(on_char_input), NULL); g_signal_connect(glk, "line-input", G_CALLBACK(on_line_input), NULL); g_signal_connect(glk, "text-buffer-output", G_CALLBACK(on_text_buffer_output), NULL); @@ -151,6 +156,8 @@ create_window(void) gtk_box_pack_end(vbox, glk, TRUE, TRUE, 0); gtk_box_pack_start(vbox, menubar, FALSE, FALSE, 0); gtk_box_pack_start(vbox, toolbar, FALSE, FALSE, 0); + + gtk_builder_connect_signals(builder, NULL); } int