Some cosmetic fixes, like giving a window the focus when it asks for character input
authorfliep <fliep@ddfedd41-794f-dd11-ae45-00112f111e67>
Sun, 13 Sep 2009 19:27:16 +0000 (19:27 +0000)
committerfliep <fliep@ddfedd41-794f-dd11-ae45-00112f111e67>
Sun, 13 Sep 2009 19:27:16 +0000 (19:27 +0000)
libchimara/input.c
tests/main.c

index 8ab3f41fce4a03a8bdaad1137e93f334fd18a389..804bb083bd715782314d7bcf4a1e836be49d2713 100644 (file)
@@ -6,6 +6,36 @@
 static int flush_text_buffer(winid_t win);
 static int flush_text_grid(winid_t win);
 
+/* Internal function: code common to both flavors of char event request */
+void
+request_char_event_common(winid_t win, gboolean unicode)
+{
+       VALID_WINDOW(win, return);
+       g_return_if_fail(win->input_request_type == INPUT_REQUEST_NONE);
+       g_return_if_fail(win->type != wintype_TextBuffer || win->type != wintype_TextGrid);
+
+       win->input_request_type = unicode? INPUT_REQUEST_CHARACTER_UNICODE : INPUT_REQUEST_CHARACTER;
+       g_signal_handler_unblock( G_OBJECT(win->widget), win->keypress_handler );
+
+       gdk_threads_enter();
+       
+       /* If the request is in a text buffer window, scroll to the end of the
+        text buffer. TODO: This may scroll text off the top of the window that the
+        user hasn't read yet. We need to implement a paging mechanism. */
+       if(win->type == wintype_TextBuffer)
+       {
+               GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
+               GtkTextIter iter;
+               gtk_text_buffer_get_end_iter(buffer, &iter);
+               gtk_text_buffer_place_cursor(buffer, &iter);
+               gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(win->widget), gtk_text_buffer_get_insert(buffer));
+               /* Why doesn't this always work?? */
+       }
+       
+       gtk_widget_grab_focus( GTK_WIDGET(win->widget) );
+       gdk_threads_leave();
+}
+
 /** 
  * glk_request_char_event:
  * @win: A window to request char events from.
@@ -19,12 +49,7 @@ static int flush_text_grid(winid_t win);
 void
 glk_request_char_event(winid_t win)
 {
-       VALID_WINDOW(win, return);
-       g_return_if_fail(win->input_request_type == INPUT_REQUEST_NONE);
-       g_return_if_fail(win->type != wintype_TextBuffer || win->type != wintype_TextGrid);
-
-       win->input_request_type = INPUT_REQUEST_CHARACTER;
-       g_signal_handler_unblock( G_OBJECT(win->widget), win->keypress_handler );
+       request_char_event_common(win, FALSE);
 }
 
 /** 
@@ -37,12 +62,7 @@ glk_request_char_event(winid_t win)
 void
 glk_request_char_event_uni(winid_t win)
 {
-       VALID_WINDOW(win, return);
-       g_return_if_fail(win->input_request_type == INPUT_REQUEST_NONE);
-       g_return_if_fail(win->type != wintype_TextBuffer || win->type != wintype_TextGrid);
-
-       win->input_request_type = INPUT_REQUEST_CHARACTER_UNICODE;
-       g_signal_handler_unblock( G_OBJECT(win->widget), win->keypress_handler );
+       request_char_event_common(win, TRUE);
 }
 
 /**
@@ -128,6 +148,8 @@ text_grid_request_line_event_common(winid_t win, glui32 maxlen, gboolean insert,
     gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(win->widget), win->input_entry, win->input_anchor);
        
        g_signal_handler_unblock( G_OBJECT(win->widget), win->keypress_handler );
+
+       gtk_widget_grab_focus(win->input_entry);
        
        gdk_threads_leave();
 }
@@ -162,6 +184,8 @@ text_buffer_request_line_event_common(winid_t win, glui32 maxlen, gboolean inser
     
     gtk_text_view_set_editable(GTK_TEXT_VIEW(win->widget), TRUE);
     g_signal_handler_unblock(buffer, win->insert_text_handler);
+
+       gtk_widget_grab_focus(win->widget);
        
        gdk_threads_leave();
 }
index 5fbd624ab529c65e8f2a227f27e9a165585fb7e7..94755c8a6c2b0c33fbc74b270caa4cccd5e6a56c 100644 (file)
@@ -154,7 +154,7 @@ main(int argc, char *argv[])
        g_object_unref( G_OBJECT(builder) );
        g_object_unref( G_OBJECT(uimanager) );
 
-    if( !chimara_glk_run(CHIMARA_GLK(glk), ".libs/gridtest.so"/*"../interpreters/frotz/.libs/frotz.so"*/, argc, argv, &error) ) {
+    if( !chimara_glk_run(CHIMARA_GLK(glk), "../interpreters/frotz/.libs/frotz.so", argc, argv, &error) ) {
                error_dialog(GTK_WINDOW(window), error, "Error starting Glk library: ");
                return 1;
        }