From 51f7599e9127069750bd540f05f160ea1bf50f1c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 25 May 2021 17:57:39 +0200 Subject: input: keymap_lookup: remove unused argument ‘seat’ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 320b1679..5e7d3420 100644 --- a/input.c +++ b/input.c @@ -852,8 +852,7 @@ keymap_data_for_sym(xkb_keysym_t sym, size_t *count) } static const struct key_data * -keymap_lookup(struct seat *seat, struct terminal *term, - xkb_keysym_t sym, enum modifier mods) +keymap_lookup(struct terminal *term, xkb_keysym_t sym, enum modifier mods) { size_t count; const struct key_data *info = keymap_data_for_sym(sym, &count); @@ -1036,7 +1035,7 @@ key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, static const struct key_data esc = {.seq = "\033[27;1;27~"}; keymap = &esc; } else - keymap = keymap_lookup(seat, term, sym, keymap_mods); + keymap = keymap_lookup(term, sym, keymap_mods); if (keymap != NULL) { term_to_slave(term, keymap->seq, strlen(keymap->seq)); -- cgit v1.3 From 360946917cec381860cdc459e1aa4587bd4a4fb8 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 25 May 2021 17:57:53 +0200 Subject: input: regression test for escape sequence generated for ctrl+shift+tab --- input.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'input.c') diff --git a/input.c b/input.c index 5e7d3420..7c1004f9 100644 --- a/input.c +++ b/input.c @@ -884,6 +884,21 @@ keymap_lookup(struct terminal *term, xkb_keysym_t sym, enum modifier mods) return NULL; } +#if defined(_DEBUG) +static void __attribute__((constructor)) +test_keymap_lookup(void) +{ + struct terminal term = { + .num_lock_modifier = false, + .keypad_keys_mode = KEYPAD_NUMERICAL, + .cursor_keys_mode = CURSOR_KEYS_NORMAL, + }; + + const struct key_data *info = keymap_lookup(&term, XKB_KEY_ISO_Left_Tab, MOD_SHIFT | MOD_CTRL); + xassert(strcmp(info->seq, "\033[27;6;9~") == 0); +} +#endif + static void key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, uint32_t key, uint32_t state) -- cgit v1.3 From 3d9302b6f95e3bb0f00695faf8c575440c685840 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Tue, 25 May 2021 18:38:16 +0100 Subject: macros: add UNITTEST macro and use to replace test_keymap_lookup() --- input.c | 5 +---- macros.h | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'input.c') diff --git a/input.c b/input.c index 7c1004f9..96c41a15 100644 --- a/input.c +++ b/input.c @@ -884,9 +884,7 @@ keymap_lookup(struct terminal *term, xkb_keysym_t sym, enum modifier mods) return NULL; } -#if defined(_DEBUG) -static void __attribute__((constructor)) -test_keymap_lookup(void) +UNITTEST { struct terminal term = { .num_lock_modifier = false, @@ -897,7 +895,6 @@ test_keymap_lookup(void) const struct key_data *info = keymap_lookup(&term, XKB_KEY_ISO_Left_Tab, MOD_SHIFT | MOD_CTRL); xassert(strcmp(info->seq, "\033[27;6;9~") == 0); } -#endif static void key_press_release(struct seat *seat, struct terminal *term, uint32_t serial, diff --git a/macros.h b/macros.h index 52c24e0e..7cfe777e 100644 --- a/macros.h +++ b/macros.h @@ -1,5 +1,7 @@ #pragma once +#define PASTE(a, b) a##b +#define XPASTE(a, b) PASTE(a, b) #define DO_PRAGMA(x) _Pragma(#x) #define VERCMP(x, y, cx, cy) ((cx > x) || ((cx == x) && (cy >= y))) @@ -68,6 +70,7 @@ #if GNUC_AT_LEAST(3, 0) || HAS_ATTRIBUTE(constructor) #define CONSTRUCTOR __attribute__((__constructor__)) + #define HAVE_ATTR_CONSTRUCTOR 1 #else #define CONSTRUCTOR #endif @@ -175,6 +178,19 @@ #define UNROLL_LOOP(n) #endif +#ifdef __COUNTER__ + // Supported by GCC 4.3+ and Clang + #define COUNTER_ __COUNTER__ +#else + #define COUNTER_ __LINE__ +#endif + +#if defined(_DEBUG) && defined(HAVE_ATTR_CONSTRUCTOR) + #define UNITTEST static void CONSTRUCTOR XPASTE(unittest_, COUNTER_)(void) +#else + #define UNITTEST static void UNUSED XPASTE(unittest_, COUNTER_)(void) +#endif + #ifdef __clang__ #define IGNORE_WARNING(wflag) \ DO_PRAGMA(clang diagnostic push) \ -- cgit v1.3