1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 09:27:59 +00:00

Remove frontend_keypress().

This was used by ldisc to communicate back to the front end that a key
had been pressed (or rather, that a keypress had caused a nonzero
amount of session input data). Its only nontrivial implementation was
in gtkwin.c, which used that notification to implement the Unix GUI's
"close window on keypress, if the session was already over" policy.

(Which in turn is Unix-specific, because the rationale is that
sometimes X servers don't have a functioning window manager, so it's
useful to have a way of telling any application to close without using
WM-provided facilities like a close button.)

But gtkwin.c doesn't need to be told by the ldisc that a keypress
happened - it's the one _sending_ those keypresses to ldisc in the
first place! So I've thrown away the three stub implementations of
frontend_keypress, removed the call to it in ldisc.c, and replaced it
with calls in gtkwin.c at all the points during keypress handling
that call ldisc_send.

A visible effect is that pterm's close-on-keypress behaviour will now
only trigger on an actual (input-generating) _keypress_, and not on
other input generation such as a paste action. I think that's an
improvement.
This commit is contained in:
Simon Tatham 2018-10-11 18:14:05 +01:00
parent e053ea9a2e
commit 109df9f46b
6 changed files with 19 additions and 36 deletions

View File

@ -135,13 +135,6 @@ void ldisc_send(Ldisc *ldisc, const void *vbuf, int len, int interactive)
assert(ldisc->term);
assert(len);
/*
* Notify the front end that something was pressed, in case
* it's depending on finding out (e.g. keypress termination for
* Close On Exit).
*/
frontend_keypress(ldisc->frontend);
if (interactive) {
/*
* Interrupt a paste from the clipboard, if one was in

View File

@ -730,7 +730,6 @@ void modalfatalbox(const char *, ...);
void do_beep(Frontend *frontend, int);
void sys_cursor(Frontend *frontend, int x, int y);
void frontend_request_paste(Frontend *frontend, int clipboard);
void frontend_keypress(Frontend *frontend);
void frontend_echoedit_update(Frontend *frontend, int echo, int edit);
/* It's the backend's responsibility to invoke this at the start of a
* connection, if necessary; it can also invoke it later if the set of

View File

@ -923,6 +923,7 @@ char *dup_keyval_name(guint keyval)
#endif
static void change_font_size(Frontend *inst, int increment);
static void key_pressed(Frontend *inst);
gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
@ -931,6 +932,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
wchar_t ucsoutput[2];
int ucsval, start, end, special, output_charset, use_ucsoutput;
int nethack_mode, app_keypad_mode;
int generated_something = FALSE;
#ifdef OSX_META_KEY_CONFIG
if (event->state & inst->system_mod_mask)
@ -2076,6 +2078,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
* should never matter.
*/
output[end] = '\0'; /* NUL-terminate */
generated_something = TRUE;
if (inst->ldisc)
ldisc_send(inst->ldisc, output+start, -2, 1);
} else if (!inst->direct_to_font) {
@ -2095,6 +2098,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
charset_to_localenc(output_charset), string_string));
sfree(string_string);
#endif
generated_something = TRUE;
if (inst->ldisc)
lpage_send(inst->ldisc, output_charset, output+start,
end-start, 1);
@ -2119,6 +2123,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
* We generated our own Unicode key data from the
* keysym, so use that instead.
*/
generated_something = TRUE;
if (inst->ldisc)
luni_send(inst->ldisc, ucsoutput+start, end-start, 1);
}
@ -2142,6 +2147,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
string_string));
sfree(string_string);
#endif
generated_something = TRUE;
if (inst->ldisc)
ldisc_send(inst->ldisc, output+start, end-start, 1);
}
@ -2150,6 +2156,8 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
term_seen_key_event(inst->term);
}
if (generated_something)
key_pressed(inst);
return TRUE;
}
@ -2177,6 +2185,7 @@ void input_method_commit_event(GtkIMContext *imc, gchar *str, gpointer data)
lpage_send(inst->ldisc, CS_UTF8, str, strlen(str), 1);
show_mouseptr(inst, 0);
term_seen_key_event(inst->term);
key_pressed(inst);
}
#endif
@ -2390,11 +2399,20 @@ gint motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
return TRUE;
}
void frontend_keypress(Frontend *inst)
static void key_pressed(Frontend *inst)
{
/*
* If our child process has exited but not closed, terminate on
* any keypress.
*
* This is a UI feature specific to GTK PuTTY, because GTK PuTTY
* will (at least sometimes) be running under X, and under X the
* window manager is sometimes absent (very occasionally on
* purpose, more usually temporarily because it's crashed). So
* it's useful to have a way to close an application window
* without depending on protocols like WM_DELETE_WINDOW that are
* typically generated by the WM (e.g. in response to a close
* button in the window frame).
*/
if (inst->exited)
gtk_widget_destroy(inst->window);

View File

@ -554,14 +554,6 @@ int console_get_userpass_input(prompts_t *p)
return 1; /* success */
}
void frontend_keypress(Frontend *frontend)
{
/*
* This is nothing but a stub, in console code.
*/
return;
}
int is_interactive(void)
{
return isatty(0);

View File

@ -480,14 +480,6 @@ int console_get_userpass_input(prompts_t *p)
return 1; /* success */
}
void frontend_keypress(Frontend *frontend)
{
/*
* This is nothing but a stub, in console code.
*/
return;
}
static const LogPolicyVtable default_logpolicy_vt = {
console_eventlog,
console_askappend,

View File

@ -5907,17 +5907,6 @@ static void flip_full_screen()
}
}
void frontend_keypress(Frontend *frontend)
{
/*
* Keypress termination in non-Close-On-Exit mode is not
* currently supported in PuTTY proper, because the window
* always has a perfectly good Close button anyway. So we do
* nothing here.
*/
return;
}
int from_backend(Frontend *frontend, int is_stderr, const void *data, int len)
{
return term_data(term, is_stderr, data, len);