Skip to content

Commit

Permalink
vte: send escape sequence when ALT key is held
Browse files Browse the repository at this point in the history
XTerm's altSendsEscape resource controls whether an escape character is
prepended to any output that is generated by keyboard input. We enable it
by default now.

Keyboard handling becomes kind of ugly now in the VTE layer. We should
definitely change this into some kind of lookup table or a more
sophisticated switch() handler in vte_input.c or similar.

Thanks to Tobias Wolf, "Etam" and Ran Benita for reporting this to the
bug-tracker and figuring out how this is correctly handled.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
  • Loading branch information
David Herrmann committed Sep 16, 2012
1 parent 93c553c commit 8deb82f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/vte.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ enum parser_action {
#define FLAG_AUTO_REPEAT_MODE 0x00002000 /* Auto repeat key press; TODO: implement */
#define FLAG_NATIONAL_CHARSET_MODE 0x00004000 /* Send keys from nation charsets; TODO: implement */
#define FLAG_BACKGROUND_COLOR_ERASE_MODE 0x00008000 /* Set background color on erase (bce) */
#define FLAG_PREPEND_ESCAPE 0x00010000 /* Prepend escape character to next output */

struct vte_saved_state {
unsigned int cursor_x;
Expand Down Expand Up @@ -470,10 +471,17 @@ static void vte_write_debug(struct kmscon_vte *vte, const char *u8, size_t len,
#endif

/* in local echo mode, directly parse the data again */
if (!vte->parse_cnt && !(vte->flags & FLAG_SEND_RECEIVE_MODE))
if (!vte->parse_cnt && !(vte->flags & FLAG_SEND_RECEIVE_MODE)) {
if (vte->flags & FLAG_PREPEND_ESCAPE)
kmscon_vte_input(vte, "\e", 1);
kmscon_vte_input(vte, u8, len);
}

if (vte->flags & FLAG_PREPEND_ESCAPE)
vte->write_cb(vte, "\e", 1, vte->data);
vte->write_cb(vte, u8, len, vte->data);

vte->flags &= ~FLAG_PREPEND_ESCAPE;
}

#define vte_write(_vte, _u8, _len) \
Expand Down Expand Up @@ -2124,6 +2132,16 @@ bool kmscon_vte_handle_keyboard(struct kmscon_vte *vte, uint32_t keysym,
size_t len;
const char *u8;

/* MOD1 (mostly labeled 'Alt') prepends an escape character to every
* input that is sent by a key.
* TODO: Transform this huge handler into a lookup table to save a lot
* of code and make such modifiers easier to implement.
* Also check whether altSendsEscape should be the default (xterm
* disables this by default, why?) and whether we should implement the
* fallback shifting that xterm does. */
if (mods & UTERM_MOD1_MASK)
vte->flags |= FLAG_PREPEND_ESCAPE;

if (mods & UTERM_CONTROL_MASK) {
switch (keysym) {
case XKB_KEY_2:
Expand Down Expand Up @@ -2561,5 +2579,6 @@ bool kmscon_vte_handle_keyboard(struct kmscon_vte *vte, uint32_t keysym,
return true;
}

vte->flags &= ~FLAG_PREPEND_ESCAPE;
return false;
}

0 comments on commit 8deb82f

Please sign in to comment.