Fixed minor bug - wait for event queue condition IF the queue is empty, not WHILE...
[rodin/chimara.git] / libchimara / event.c
index 4bbb391b597bb028dc7e5a75994de54ee188858f..88b09f02c1f31ce0fba2dfec6c35e2eb2f15432b 100644 (file)
@@ -1,6 +1,7 @@
 #include "event.h"
 #include "magic.h"
 #include "glk.h"
+#include "window.h"
 #include <string.h>
 
 #include "chimara-glk.h"
@@ -69,10 +70,13 @@ 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 */
-       while( g_queue_is_empty(glk_data->event_queue) )
+       if( g_queue_is_empty(glk_data->event_queue) )
                g_cond_wait(glk_data->event_queue_not_empty, glk_data->event_lock);
 
        event_t *retrieved_event = g_queue_pop_tail(glk_data->event_queue);
@@ -92,6 +96,15 @@ glk_select(event_t *event)
        
        /* Check for interrupt */
        glk_tick();
+
+       /* If the event was a line input event, the library must release the buffer */
+       if(event->type == evtype_LineInput && glk_data->unregister_arr) 
+       {
+        if(event->win->input_request_type == INPUT_REQUEST_LINE_UNICODE)
+                       (*glk_data->unregister_arr)(event->win->line_input_buffer_unicode, event->win->line_input_buffer_max_len, "&+#!Iu", event->win->buffer_rock);
+               else
+            (*glk_data->unregister_arr)(event->win->line_input_buffer, event->win->line_input_buffer_max_len, "&+#!Cn", event->win->buffer_rock);
+    }
        
        /* If an abort event was generated, the thread should have exited by now */
        g_assert(event->type != evtype_Abort);
@@ -190,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
+}