From 2cb502506f9a85b821564075645daf778188d2f4 Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 20 Oct 2002 13:23:30 +0000 Subject: [PATCH] Implement Richard's really clever idea about bell overload mode: 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 | 7 ++++++- putty.h | 2 +- terminal.c | 40 ++++++++++++++++++++++++++++++++++++---- unix/pterm.1 | 5 +++++ unix/pterm.c | 2 +- window.c | 23 +++++++++++++---------- 6 files changed, 62 insertions(+), 17 deletions(-) diff --git a/doc/config.but b/doc/config.but index 6af3546e..7191e848 100644 --- a/doc/config.but +++ b/doc/config.but @@ -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 @@ -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. +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 diff --git a/putty.h b/putty.h index cbccef76..4b151def 100644 --- 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 seen_key_event; 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 term_seen_key_event(void); /* * Exports from logging.c. diff --git a/terminal.c b/terminal.c index b0ad3565..dc1793c1 100644 --- a/terminal.c +++ b/terminal.c @@ -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) @@ -3450,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; diff --git a/unix/pterm.1 b/unix/pterm.1 index 8c9fb338..ff8e5123 100644 --- a/unix/pterm.1 +++ b/unix/pterm.1 @@ -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. + +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 diff --git a/unix/pterm.c b/unix/pterm.c index 541e733a..e2830588 100644 --- a/unix/pterm.c +++ b/unix/pterm.c @@ -786,7 +786,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) ldisc_send(output+start, end-start, 1); show_mouseptr(0); - seen_key_event = 1; + term_seen_key_event(); term_out(); } diff --git a/window.c b/window.c index ddd7aa92..3b601544 100644 --- 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. */ + term_seen_key_event(); 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. */ - 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); + } free(buff); } ImmReleaseContext(hwnd, hIMC); @@ -2499,9 +2502,11 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, buf[1] = wParam; buf[0] = wParam >> 8; + term_seen_key_event(); 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); @@ -2515,6 +2520,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, */ { char c = (unsigned char)wParam; + term_seen_key_event(); 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; - /* - * 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; @@ -3769,6 +3766,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, return 0; } keybuf = nc; + term_seen_key_event(); 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; + term_seen_key_event(); 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. */ + term_seen_key_event(); 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); + term_seen_key_event(); 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); } } -- 2.11.0