Justin Bradford's patch for increased proxy robustness.
[u/mdw/putty] / terminal.c
index de6a2e9..dc1793c 100644 (file)
@@ -328,10 +328,9 @@ void term_update(void)
     ctx = get_ctx();
     if (ctx) {
        int need_sbar_update = seen_disp_event;
-       if ((seen_key_event && (cfg.scroll_on_key)) ||
-           (seen_disp_event && (cfg.scroll_on_disp))) {
+       if (seen_disp_event && cfg.scroll_on_disp) {
            disptop = 0;               /* return to main screen */
-           seen_disp_event = seen_key_event = 0;
+           seen_disp_event = 0;
            need_sbar_update = TRUE;
        }
        if (need_sbar_update)
@@ -343,6 +342,37 @@ void term_update(void)
 }
 
 /*
+ * Called from front end when a keypress occurs, to trigger
+ * anything magical that needs to happen in that situation.
+ */
+void term_seen_key_event(void)
+{
+    /*
+     * On any keypress, clear the bell overload mechanism
+     * completely, on the grounds that large numbers of
+     * beeps coming from deliberate key action are likely
+     * to be intended (e.g. beeps from filename completion
+     * blocking repeatedly).
+     */
+    beep_overloaded = FALSE;
+    while (beephead) {
+       struct beeptime *tmp = beephead;
+       beephead = tmp->next;
+       sfree(tmp);
+    }
+    beeptail = NULL;
+    nbeeps = 0;
+
+    /*
+     * Reset the scrollback on keypress, if we're doing that.
+     */
+    if (cfg.scroll_on_key) {
+       disptop = 0;                   /* return to main screen */
+       seen_disp_event = 1;
+    }
+}
+
+/*
  * Same as power_on(), but an external function.
  */
 void term_pwron(void)
@@ -1133,7 +1163,6 @@ void term_out(void)
                else
                    print_state = 0;
                if (print_state == 4) {
-                   printing = only_printing = FALSE;
                    term_print_finish();
                }
                continue;
@@ -1915,8 +1944,6 @@ void term_out(void)
                                print_state = 0;
                                term_print_setup();
                            } else if (esc_args[0] == 4 && printing) {
-                               printing = FALSE;
-                               only_printing = FALSE;
                                term_print_finish();
                            }
                        }
@@ -3453,9 +3480,11 @@ void term_do_paste(void)
     int len;
 
     get_clip(&data, &len);
-    if (data) {
+    if (data && len > 0) {
         wchar_t *p, *q;
 
+       term_seen_key_event();         /* pasted data counts */
+
         if (paste_buffer)
             sfree(paste_buffer);
         paste_pos = paste_hold = paste_len = 0;