Implement Richard's really clever idea about bell overload mode:
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 20 Oct 2002 13:23:30 +0000 (13:23 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 20 Oct 2002 13:23:30 +0000 (13:23 +0000)
it's automatically deactivated by any keypress, so that command-line
beeps from (e.g.) filename completion don't suddenly stop occurring,
but it still provides a rapid response to an accidental spewing of a
binary to your terminal.

git-svn-id: svn://svn.tartarus.org/sgt/putty@2107 cda61777-01e9-0310-a592-d414129be87e

doc/config.but
putty.h
terminal.c
unix/pterm.1
unix/pterm.c
window.c

index 6af3546..7191e84 100644 (file)
@@ -1,4 +1,4 @@
-\versionid $Id: config.but,v 1.42 2002/09/26 18:37:33 simon Exp $
+\versionid $Id: config.but,v 1.43 2002/10/20 13:23:30 simon Exp $
 
 \C{config} Configuring PuTTY
 
 
 \C{config} Configuring PuTTY
 
@@ -686,6 +686,11 @@ constitute an overload, how short a time period they have to arrive
 in to do so, and how much silent time is required before the
 overload feature will deactivate itself.
 
 in to do so, and how much silent time is required before the
 overload feature will deactivate itself.
 
+Bell overload mode is always deactivated by any keypress in the
+terminal. This means it can respond to large unexpected streams of
+data, but does not interfere with ordinary command-line activities
+that generate beeps (such as filename completion).
+
 \H{config-features} The Features panel
 
 PuTTY's terminal emulation is very highly featured, and can do a lot
 \H{config-features} The Features panel
 
 PuTTY's terminal emulation is very highly featured, and can do a lot
diff --git a/putty.h b/putty.h
index cbccef7..4b151de 100644 (file)
--- a/putty.h
+++ b/putty.h
@@ -109,7 +109,6 @@ GLOBAL unsigned long vbell_startpoint;
 GLOBAL int app_cursor_keys, app_keypad_keys, vt52_mode;
 GLOBAL int repeat_off, cr_lf_return;
 
 GLOBAL int app_cursor_keys, app_keypad_keys, vt52_mode;
 GLOBAL int repeat_off, cr_lf_return;
 
-GLOBAL int seen_key_event;
 GLOBAL int seen_disp_event;
 GLOBAL int alt_pressed;
 
 GLOBAL int seen_disp_event;
 GLOBAL int alt_pressed;
 
@@ -499,6 +498,7 @@ void logfopen(void);
 void logfclose(void);
 void term_copyall(void);
 void term_reconfig(void);
 void logfclose(void);
 void term_copyall(void);
 void term_reconfig(void);
+void term_seen_key_event(void);
 
 /*
  * Exports from logging.c.
 
 /*
  * Exports from logging.c.
index b0ad356..dc1793c 100644 (file)
@@ -328,10 +328,9 @@ void term_update(void)
     ctx = get_ctx();
     if (ctx) {
        int need_sbar_update = seen_disp_event;
     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 */
            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)
            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)
  * Same as power_on(), but an external function.
  */
 void term_pwron(void)
@@ -3450,9 +3480,11 @@ void term_do_paste(void)
     int len;
 
     get_clip(&data, &len);
     int len;
 
     get_clip(&data, &len);
-    if (data) {
+    if (data && len > 0) {
         wchar_t *p, *q;
 
         wchar_t *p, *q;
 
+       term_seen_key_event();         /* pasted data counts */
+
         if (paste_buffer)
             sfree(paste_buffer);
         paste_pos = paste_hold = paste_len = 0;
         if (paste_buffer)
             sfree(paste_buffer);
         paste_pos = paste_hold = paste_len = 0;
index 8c9fb33..ff8e512 100644 (file)
@@ -218,6 +218,11 @@ not drive you crazy.
 The bell overload mode is activated by receiving N bells in time T;
 after a further time S without any bells, overload mode will turn
 itself off again.
 The bell overload mode is activated by receiving N bells in time T;
 after a further time S without any bells, overload mode will turn
 itself off again.
+
+Bell overload mode is always deactivated by any keypress in the
+terminal. This means it can respond to large unexpected streams of
+data, but does not interfere with ordinary command-line activities
+that generate beeps (such as filename completion).
 .IP "\fBpterm.BellOverloadN\fP"
 This option counts the number of bell characters which will activate
 bell overload if they are received within a length of time T. The
 .IP "\fBpterm.BellOverloadN\fP"
 This option counts the number of bell characters which will activate
 bell overload if they are received within a length of time T. The
index 541e733..e283058 100644 (file)
@@ -786,7 +786,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
 
        ldisc_send(output+start, end-start, 1);
        show_mouseptr(0);
 
        ldisc_send(output+start, end-start, 1);
        show_mouseptr(0);
-       seen_key_event = 1;
+       term_seen_key_event();
        term_out();
     }
 
        term_out();
     }
 
index ddd7aa9..3b60154 100644 (file)
--- a/window.c
+++ b/window.c
@@ -2439,6 +2439,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                     * messages. We _have_ to buffer everything
                     * we're sent.
                     */
                     * messages. We _have_ to buffer everything
                     * we're sent.
                     */
+                   term_seen_key_event();
                    ldisc_send(buf, len, 1);
                    show_mouseptr(0);
                }
                    ldisc_send(buf, len, 1);
                    show_mouseptr(0);
                }
@@ -2485,8 +2486,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                 * luni_send() covering the whole of buff. So
                 * instead we luni_send the characters one by one.
                 */
                 * luni_send() covering the whole of buff. So
                 * instead we luni_send the characters one by one.
                 */
-               for (i = 0; i < n; i += 2)
+               term_seen_key_event();
+               for (i = 0; i < n; i += 2) {
                    luni_send((unsigned short *)(buff+i), 1, 1);
                    luni_send((unsigned short *)(buff+i), 1, 1);
+               }
                free(buff);
            }
            ImmReleaseContext(hwnd, hIMC);
                free(buff);
            }
            ImmReleaseContext(hwnd, hIMC);
@@ -2499,9 +2502,11 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
 
            buf[1] = wParam;
            buf[0] = wParam >> 8;
 
            buf[1] = wParam;
            buf[0] = wParam >> 8;
+           term_seen_key_event();
            lpage_send(kbd_codepage, buf, 2, 1);
        } else {
            char c = (unsigned char) wParam;
            lpage_send(kbd_codepage, buf, 2, 1);
        } else {
            char c = (unsigned char) wParam;
+           term_seen_key_event();
            lpage_send(kbd_codepage, &c, 1, 1);
        }
        return (0);
            lpage_send(kbd_codepage, &c, 1, 1);
        }
        return (0);
@@ -2515,6 +2520,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
         */
        {
            char c = (unsigned char)wParam;
         */
        {
            char c = (unsigned char)wParam;
+           term_seen_key_event();
            lpage_send(CP_ACP, &c, 1, 1);
        }
        return 0;
            lpage_send(CP_ACP, &c, 1, 1);
        }
        return 0;
@@ -3184,15 +3190,6 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
     } else if (compose_state == 1 && wParam != VK_CONTROL)
        compose_state = 0;
 
     } else if (compose_state == 1 && wParam != VK_CONTROL)
        compose_state = 0;
 
-    /* 
-     * Record that we pressed key so the scroll window can be reset, but
-     * be careful to avoid Shift-UP/Down
-     */
-    if (wParam != VK_SHIFT && wParam != VK_PRIOR && wParam != VK_NEXT &&
-       wParam != VK_MENU && wParam != VK_CONTROL) {
-       seen_key_event = 1;
-    }
-
     if (compose_state > 1 && left_alt)
        compose_state = 0;
 
     if (compose_state > 1 && left_alt)
        compose_state = 0;
 
@@ -3769,6 +3766,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
                        return 0;
                    }
                    keybuf = nc;
                        return 0;
                    }
                    keybuf = nc;
+                   term_seen_key_event();
                    luni_send(&keybuf, 1, 1);
                    continue;
                }
                    luni_send(&keybuf, 1, 1);
                    continue;
                }
@@ -3779,6 +3777,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
                    if (alt_sum) {
                        if (in_utf || dbcs_screenfont) {
                            keybuf = alt_sum;
                    if (alt_sum) {
                        if (in_utf || dbcs_screenfont) {
                            keybuf = alt_sum;
+                           term_seen_key_event();
                            luni_send(&keybuf, 1, 1);
                        } else {
                            ch = (char) alt_sum;
                            luni_send(&keybuf, 1, 1);
                        } else {
                            ch = (char) alt_sum;
@@ -3791,21 +3790,25 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
                             * messages. We _have_ to buffer
                             * everything we're sent.
                             */
                             * messages. We _have_ to buffer
                             * everything we're sent.
                             */
+                           term_seen_key_event();
                            ldisc_send(&ch, 1, 1);
                        }
                        alt_sum = 0;
                    } else
                            ldisc_send(&ch, 1, 1);
                        }
                        alt_sum = 0;
                    } else
+                       term_seen_key_event();
                        lpage_send(kbd_codepage, &ch, 1, 1);
                } else {
                    if(capsOn && ch < 0x80) {
                        WCHAR cbuf[2];
                        cbuf[0] = 27;
                        cbuf[1] = xlat_uskbd2cyrllic(ch);
                        lpage_send(kbd_codepage, &ch, 1, 1);
                } else {
                    if(capsOn && ch < 0x80) {
                        WCHAR cbuf[2];
                        cbuf[0] = 27;
                        cbuf[1] = xlat_uskbd2cyrllic(ch);
+                       term_seen_key_event();
                        luni_send(cbuf+!left_alt, 1+!!left_alt, 1);
                    } else {
                        char cbuf[2];
                        cbuf[0] = '\033';
                        cbuf[1] = ch;
                        luni_send(cbuf+!left_alt, 1+!!left_alt, 1);
                    } else {
                        char cbuf[2];
                        cbuf[0] = '\033';
                        cbuf[1] = ch;
+                       term_seen_key_event();
                        lpage_send(kbd_codepage, cbuf+!left_alt, 1+!!left_alt, 1);
                    }
                }
                        lpage_send(kbd_codepage, cbuf+!left_alt, 1+!!left_alt, 1);
                    }
                }