sync with OpenBSD -current

This commit is contained in:
purplerain 2024-10-03 15:29:20 +00:00
parent 00180dc79b
commit 074e641852
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
75 changed files with 2693 additions and 2103 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: tty-keys.c,v 1.179 2024/09/30 08:10:20 nicm Exp $ */
/* $OpenBSD: tty-keys.c,v 1.181 2024/10/03 05:41:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@ -944,9 +944,6 @@ complete_key:
if (bspace != _POSIX_VDISABLE && (key & KEYC_MASK_KEY) == bspace)
key = (key & KEYC_MASK_MODIFIERS)|KEYC_BSPACE;
/* Remove data from buffer. */
evbuffer_drain(tty->in, size);
/* Remove key timer. */
if (event_initialized(&tty->key_timer))
evtimer_del(&tty->key_timer);
@ -965,13 +962,23 @@ complete_key:
/* Fire the key. */
if (key != KEYC_UNKNOWN) {
event = xmalloc(sizeof *event);
event = xcalloc(1, sizeof *event);
event->key = key;
memcpy(&event->m, &m, sizeof event->m);
if (!server_client_handle_key(c, event))
event->buf = xmalloc(size);
event->len = size;
memcpy (event->buf, buf, event->len);
if (!server_client_handle_key(c, event)) {
free(event->buf);
free(event);
}
}
/* Remove data from buffer. */
evbuffer_drain(tty->in, size);
return (1);
discard_key:
@ -1009,7 +1016,7 @@ tty_keys_extended_key(struct tty *tty, const char *buf, size_t len,
u_int number, modifiers;
char tmp[64];
cc_t bspace;
key_code nkey;
key_code nkey, onlykey;
struct utf8_data ud;
utf8_char uc;
@ -1073,13 +1080,7 @@ tty_keys_extended_key(struct tty *tty, const char *buf, size_t len,
/* Update the modifiers. */
if (modifiers > 0) {
modifiers--;
/*
* The Shift modifier may not be reported in some input modes,
* which is unfortunate, as in general case determining if a
* character is shifted or not requires knowing the input
* keyboard layout. So we only fix up the trivial case.
*/
if (modifiers & 1 || (nkey >= 'A' && nkey <= 'Z'))
if (modifiers & 1)
nkey |= KEYC_SHIFT;
if (modifiers & 2)
nkey |= (KEYC_META|KEYC_IMPLIED_META); /* Alt */
@ -1093,6 +1094,26 @@ tty_keys_extended_key(struct tty *tty, const char *buf, size_t len,
if ((nkey & KEYC_MASK_KEY) == '\011' && (nkey & KEYC_SHIFT))
nkey = KEYC_BTAB | (nkey & ~KEYC_MASK_KEY & ~KEYC_SHIFT);
/*
* Deal with the Shift modifier when present alone. The problem is that
* in mode 2 some terminals would report shifted keys, like S-a, as
* just A, and some as S-A.
*
* Because we need an unambiguous internal representation, and because
* restoring the Shift modifier when it's missing would require knowing
* the keyboard layout, and because S-A would cause a lot of issues
* downstream, we choose to lose the Shift for all printable
* characters.
*
* That still leaves some ambiguity, such as C-S-A vs. C-A, but that's
* OK, and applications can handle that.
*/
onlykey = nkey & KEYC_MASK_KEY;
if (((onlykey > 0x20 && onlykey < 0x7f) ||
KEYC_IS_UNICODE(nkey)) &&
(nkey & KEYC_MASK_MODIFIERS) == KEYC_SHIFT)
nkey &= ~KEYC_SHIFT;
if (log_get_level() != 0) {
log_debug("%s: extended key %.*s is %llx (%s)", c->name,
(int)*size, buf, nkey, key_string_lookup_key(nkey, 1));