From c5c8a22402dc7a525312518cade0639272a763aa Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 10 Jun 2021 07:38:28 +0000 Subject: [PATCH] Move "special" keys into the Unicode PUA rather than making them top bit set, some compilers do not allow enums that are larger than int. GitHub issue 2673. --- usr.bin/tmux/input-keys.c | 4 ++-- usr.bin/tmux/key-string.c | 8 ++++---- usr.bin/tmux/status.c | 4 ++-- usr.bin/tmux/tmux.h | 35 +++++++++++++++++++++++++---------- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/usr.bin/tmux/input-keys.c b/usr.bin/tmux/input-keys.c index 93865e7e4f0..bb605a2f1a2 100644 --- a/usr.bin/tmux/input-keys.c +++ b/usr.bin/tmux/input-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: input-keys.c,v 1.83 2021/04/09 07:02:00 nicm Exp $ */ +/* $OpenBSD: input-keys.c,v 1.84 2021/06/10 07:38:28 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -477,7 +477,7 @@ input_key(struct screen *s, struct bufferevent *bev, key_code key) input_key_write(__func__, bev, &ud.data[0], 1); return (0); } - if (justkey > 0x7f && justkey < KEYC_BASE) { + if (KEYC_IS_UNICODE(justkey)) { if (key & KEYC_META) input_key_write(__func__, bev, "\033", 1); utf8_to_data(justkey, &ud); diff --git a/usr.bin/tmux/key-string.c b/usr.bin/tmux/key-string.c index 017b8290b18..ccf4022f7f5 100644 --- a/usr.bin/tmux/key-string.c +++ b/usr.bin/tmux/key-string.c @@ -1,4 +1,4 @@ -/* $OpenBSD: key-string.c,v 1.66 2021/06/10 07:21:09 nicm Exp $ */ +/* $OpenBSD: key-string.c,v 1.67 2021/06/10 07:38:28 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -238,7 +238,7 @@ key_string_lookup_string(const char *string) } /* Convert the standard control keys. */ - if (key < KEYC_BASE && + if (key <= 127 && (modifiers & KEYC_CTRL) && strchr(other, key) == NULL && key != 9 && @@ -368,8 +368,8 @@ key_string_lookup_key(key_code key, int with_flags) goto out; } - /* Is this a UTF-8 key? */ - if (key > 127 && key < KEYC_BASE) { + /* Is this a Unicode key? */ + if (KEYC_IS_UNICODE(key)) { utf8_to_data(key, &ud); off = strlen(out); memcpy(out + off, ud.data, ud.size); diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index 7e3a22f3ae0..2e7b21a5685 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.222 2021/06/10 07:24:45 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.223 2021/06/10 07:38:28 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1300,7 +1300,7 @@ process_key: return (0); append_key: - if (key <= 0x1f || key >= KEYC_BASE) + if (key <= 0x1f || (key >= KEYC_BASE && key < KEYC_BASE_END)) return (0); if (key <= 0x7f) utf8_set(&tmp, key); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 67f7d0eeb21..93992171bbf 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1106 2021/06/10 07:36:47 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1107 2021/06/10 07:38:28 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -108,11 +108,16 @@ struct winlink; #define VISUAL_ON 1 #define VISUAL_BOTH 2 -/* Special key codes. */ -#define KEYC_NONE 0x00ff000000000ULL -#define KEYC_UNKNOWN 0x00fe000000000ULL -#define KEYC_BASE 0x0001000000000ULL -#define KEYC_USER 0x0002000000000ULL +/* No key or unknown key. */ +#define KEYC_NONE 0x000ff000000000ULL +#define KEYC_UNKNOWN 0x000fe000000000ULL + +/* + * Base for special (that is, not Unicode) keys. An enum must be at most a + * signed int, so these are based in the highest Unicode PUA. + */ +#define KEYC_BASE 0x0000000010e000ULL +#define KEYC_USER 0x0000000010f000ULL /* Key modifier bits. */ #define KEYC_META 0x00100000000000ULL @@ -135,8 +140,15 @@ struct winlink; #define KEYC_NUSER 1000 /* Is this a mouse key? */ -#define KEYC_IS_MOUSE(key) (((key) & KEYC_MASK_KEY) >= KEYC_MOUSE && \ - ((key) & KEYC_MASK_KEY) < KEYC_BSPACE) +#define KEYC_IS_MOUSE(key) \ + (((key) & KEYC_MASK_KEY) >= KEYC_MOUSE && \ + ((key) & KEYC_MASK_KEY) < KEYC_BSPACE) + +/* Is this a Unicode key? */ +#define KEYC_IS_UNICODE(key) \ + (((key) & KEYC_MASK_KEY) > 0x7f && \ + (((key) & KEYC_MASK_KEY) < KEYC_BASE || \ + ((key) & KEYC_MASK_KEY) >= KEYC_BASE_END)) /* Multiple click timeout. */ #define KEYC_CLICK_TIMEOUT 300 @@ -158,8 +170,8 @@ struct winlink; { #s "Border", KEYC_ ## name ## _BORDER } /* - * A single key. This can be ASCII or Unicode or one of the keys starting at - * KEYC_BASE. + * A single key. This can be ASCII or Unicode or one of the keys between + * KEYC_BASE and KEYC_BASE_END. */ typedef unsigned long long key_code; @@ -252,6 +264,9 @@ enum { KEYC_KP_ENTER, KEYC_KP_ZERO, KEYC_KP_PERIOD, + + /* End of special keys. */ + KEYC_BASE_END }; /* Termcap codes. */ -- 2.20.1