Remove input timeout if inputbox was changed meanwhile.
authorDaniel Carl <danielcarl@gmx.de>
Thu, 11 Dec 2014 20:59:53 +0000 (21:59 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Thu, 11 Dec 2014 20:59:53 +0000 (21:59 +0100)
If the user started a command that failed with error state, the input timeout
was started. In case this was followed by a good command that prints output to
inputbox, the output was cleared by the previous set timeout function.
To fix this behaviour, the timeout is removed if the timer was started and the
inputbox is changed.

src/main.c

index 5f4cc4d..509d214 100644 (file)
@@ -145,6 +145,8 @@ void vb_echo(const MessageType type, gboolean hide, const char *error, ...)
 static void input_print(gboolean force, const MessageType type, gboolean hide,
     const char *message)
 {
+    static guint timer = 0;
+
     /* don't print message if the input is focussed */
     if (!force && gtk_widget_is_focus(GTK_WIDGET(vb.gui.input))) {
         return;
@@ -157,7 +159,14 @@ static void input_print(gboolean force, const MessageType type, gboolean hide,
     }
     vb_set_input_text(message);
     if (hide) {
-        g_timeout_add_seconds(MESSAGE_TIMEOUT, (GSourceFunc)hide_message, NULL);
+        /* add timeout function */
+        timer = g_timeout_add_seconds(MESSAGE_TIMEOUT, (GSourceFunc)hide_message, NULL);
+    } else if (timer > 0) {
+        /* If there is already a timeout function but the input box content is
+         * changed - remove the timeout. Seems the user started another
+         * command or typed into inputbox. */
+        g_source_remove(timer);
+        timer = 0;
     }
 }