term: implement MOUSE_SGR mouse event reporting style

This style is enabled with the \e[?1006h sequence, and changes how
mouse events (button presses, releases and motion events).
This commit is contained in:
Daniel Eklöf 2019-07-05 15:29:16 +02:00
parent a959c89b7f
commit 1b07015d49
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -426,10 +426,28 @@ static void
report_mouse_click(struct terminal *term, int encoded_button, int row, int col,
bool release)
{
char response[16];
snprintf(response, sizeof(response), "\033[M%c%c%c",
32 + encoded_button, 32 + col + 1, 32 + row + 1);
write(term->ptmx, response, strlen(response));
switch (term->mouse_reporting) {
case MOUSE_NORMAL: {
char response[16];
snprintf(response, sizeof(response), "\033[M%c%c%c",
32 + (release ? 3 : encoded_button), 32 + col + 1, 32 + row + 1);
write(term->ptmx, response, strlen(response));
break;
}
case MOUSE_SGR: {
char response[128];
snprintf(response, sizeof(response), "\033[<%d;%d;%d%c",
encoded_button, col + 1, row + 1, release ? 'm' : 'M');
write(term->ptmx, response, strlen(response));
break;
}
case MOUSE_UTF8:
case MOUSE_URXVT:
/* Unimplemented */
break;
}
}
static void
@ -480,7 +498,10 @@ term_mouse_up(struct terminal *term, int button, int row, int col,
return;
}
int encoded = 3;
int encoded = encode_xbutton(xbutton);
if (encoded == -1)
return;
encoded += (shift ? 4 : 0) + (alt ? 8 : 0) + (ctrl ? 16 : 0);
switch (term->mouse_tracking) {