mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-16 12:03:03 -05:00
Centralise generation of the control sequences for arrow keys into a
function in terminal.c, and replace the cloned-and-hacked handling code in all our front ends with calls to that. This was intended for code cleanliness, but a side effect is to make the GTK arrow-key handling support disabling of application cursor key mode in the Features panel. Previously that checkbox was accidentally ignored, and nobody seems to have noticed before! [originally from svn r8896]
This commit is contained in:
parent
c347755f87
commit
4d77b65677
@ -737,23 +737,8 @@
|
|||||||
case NSLeftArrowFunctionKey: xkey = 'D'; break;
|
case NSLeftArrowFunctionKey: xkey = 'D'; break;
|
||||||
}
|
}
|
||||||
if (xkey) {
|
if (xkey) {
|
||||||
/*
|
end += format_arrow_key(output+end, term, xkey,
|
||||||
* The arrow keys normally do ESC [ A and so on. In
|
m & NSControlKeyMask);
|
||||||
* app cursor keys mode they do ESC O A instead.
|
|
||||||
* Ctrl toggles the two modes.
|
|
||||||
*/
|
|
||||||
if (term->vt52_mode) {
|
|
||||||
output[end++] = '\033';
|
|
||||||
output[end++] = xkey;
|
|
||||||
} else if (!term->app_cursor_keys ^ !(m & NSControlKeyMask)) {
|
|
||||||
output[end++] = '\033';
|
|
||||||
output[end++] = 'O';
|
|
||||||
output[end++] = xkey;
|
|
||||||
} else {
|
|
||||||
output[end++] = '\033';
|
|
||||||
output[end++] = '[';
|
|
||||||
output[end++] = xkey;
|
|
||||||
}
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
putty.h
2
putty.h
@ -854,6 +854,8 @@ char *term_get_ttymode(Terminal *term, const char *mode);
|
|||||||
int term_get_userpass_input(Terminal *term, prompts_t *p,
|
int term_get_userpass_input(Terminal *term, prompts_t *p,
|
||||||
unsigned char *in, int inlen);
|
unsigned char *in, int inlen);
|
||||||
|
|
||||||
|
int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Exports from logging.c.
|
* Exports from logging.c.
|
||||||
*/
|
*/
|
||||||
|
51
terminal.c
51
terminal.c
@ -5844,6 +5844,42 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked,
|
|||||||
term_update(term);
|
term_update(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl)
|
||||||
|
{
|
||||||
|
char *p = buf;
|
||||||
|
|
||||||
|
if (term->vt52_mode)
|
||||||
|
p += sprintf((char *) p, "\x1B%c", xkey);
|
||||||
|
else {
|
||||||
|
int app_flg = (term->app_cursor_keys && !term->cfg.no_applic_c);
|
||||||
|
#if 0
|
||||||
|
/*
|
||||||
|
* RDB: VT100 & VT102 manuals both state the app cursor
|
||||||
|
* keys only work if the app keypad is on.
|
||||||
|
*
|
||||||
|
* SGT: That may well be true, but xterm disagrees and so
|
||||||
|
* does at least one application, so I've #if'ed this out
|
||||||
|
* and the behaviour is back to PuTTY's original: app
|
||||||
|
* cursor and app keypad are independently switchable
|
||||||
|
* modes. If anyone complains about _this_ I'll have to
|
||||||
|
* put in a configurable option.
|
||||||
|
*/
|
||||||
|
if (!term->app_keypad_keys)
|
||||||
|
app_flg = 0;
|
||||||
|
#endif
|
||||||
|
/* Useful mapping of Ctrl-arrows */
|
||||||
|
if (ctrl)
|
||||||
|
app_flg = !app_flg;
|
||||||
|
|
||||||
|
if (app_flg)
|
||||||
|
p += sprintf((char *) p, "\x1BO%c", xkey);
|
||||||
|
else
|
||||||
|
p += sprintf((char *) p, "\x1B[%c", xkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return p - buf;
|
||||||
|
}
|
||||||
|
|
||||||
void term_key(Terminal *term, Key_Sym keysym, wchar_t *text, size_t tlen,
|
void term_key(Terminal *term, Key_Sym keysym, wchar_t *text, size_t tlen,
|
||||||
unsigned int modifiers, unsigned int flags)
|
unsigned int modifiers, unsigned int flags)
|
||||||
{
|
{
|
||||||
@ -6220,20 +6256,7 @@ void term_key(Terminal *term, Key_Sym keysym, wchar_t *text, size_t tlen,
|
|||||||
case PK_REST: xkey = 'G'; break; /* centre key on number pad */
|
case PK_REST: xkey = 'G'; break; /* centre key on number pad */
|
||||||
default: xkey = 0; break; /* else gcc warns `enum value not used' */
|
default: xkey = 0; break; /* else gcc warns `enum value not used' */
|
||||||
}
|
}
|
||||||
if (term->vt52_mode)
|
p += format_arrow_key(p, term, xkey, modifiers == PKM_CONTROL);
|
||||||
p += sprintf((char *) p, "\x1B%c", xkey);
|
|
||||||
else {
|
|
||||||
int app_flg = (term->app_cursor_keys && !term->cfg.no_applic_c);
|
|
||||||
|
|
||||||
/* Useful mapping of Ctrl-arrows */
|
|
||||||
if (modifiers == PKM_CONTROL)
|
|
||||||
app_flg = !app_flg;
|
|
||||||
|
|
||||||
if (app_flg)
|
|
||||||
p += sprintf((char *) p, "\x1BO%c", xkey);
|
|
||||||
else
|
|
||||||
p += sprintf((char *) p, "\x1B[%c", xkey);
|
|
||||||
}
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1052,19 +1052,8 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
|||||||
case GDK_Begin: case GDK_KP_Begin: xkey = 'G'; break;
|
case GDK_Begin: case GDK_KP_Begin: xkey = 'G'; break;
|
||||||
}
|
}
|
||||||
if (xkey) {
|
if (xkey) {
|
||||||
/*
|
end = 1 + format_arrow_key(output+1, inst->term, xkey,
|
||||||
* The arrow keys normally do ESC [ A and so on. In
|
event->state & GDK_CONTROL_MASK);
|
||||||
* app cursor keys mode they do ESC O A instead.
|
|
||||||
* Ctrl toggles the two modes.
|
|
||||||
*/
|
|
||||||
if (inst->term->vt52_mode) {
|
|
||||||
end = 1 + sprintf(output+1, "\033%c", xkey);
|
|
||||||
} else if (!inst->term->app_cursor_keys ^
|
|
||||||
!(event->state & GDK_CONTROL_MASK)) {
|
|
||||||
end = 1 + sprintf(output+1, "\033O%c", xkey);
|
|
||||||
} else {
|
|
||||||
end = 1 + sprintf(output+1, "\033[%c", xkey);
|
|
||||||
}
|
|
||||||
use_ucsoutput = FALSE;
|
use_ucsoutput = FALSE;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
@ -4214,37 +4214,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (xkey) {
|
if (xkey) {
|
||||||
if (term->vt52_mode)
|
p += format_arrow_key(p, term, xkey, shift_state);
|
||||||
p += sprintf((char *) p, "\x1B%c", xkey);
|
|
||||||
else {
|
|
||||||
int app_flg = (term->app_cursor_keys && !cfg.no_applic_c);
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* RDB: VT100 & VT102 manuals both state the
|
|
||||||
* app cursor keys only work if the app keypad
|
|
||||||
* is on.
|
|
||||||
*
|
|
||||||
* SGT: That may well be true, but xterm
|
|
||||||
* disagrees and so does at least one
|
|
||||||
* application, so I've #if'ed this out and the
|
|
||||||
* behaviour is back to PuTTY's original: app
|
|
||||||
* cursor and app keypad are independently
|
|
||||||
* switchable modes. If anyone complains about
|
|
||||||
* _this_ I'll have to put in a configurable
|
|
||||||
* option.
|
|
||||||
*/
|
|
||||||
if (!term->app_keypad_keys)
|
|
||||||
app_flg = 0;
|
|
||||||
#endif
|
|
||||||
/* Useful mapping of Ctrl-arrows */
|
|
||||||
if (shift_state == 2)
|
|
||||||
app_flg = !app_flg;
|
|
||||||
|
|
||||||
if (app_flg)
|
|
||||||
p += sprintf((char *) p, "\x1BO%c", xkey);
|
|
||||||
else
|
|
||||||
p += sprintf((char *) p, "\x1B[%c", xkey);
|
|
||||||
}
|
|
||||||
return p - output;
|
return p - output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user