diff --git a/0001-Cleanup-add-brace-6545.patch b/0001-Cleanup-add-brace-6545.patch new file mode 100644 index 0000000..760229c --- /dev/null +++ b/0001-Cleanup-add-brace-6545.patch @@ -0,0 +1,249 @@ +From fb0ce375f0474501764a4bce7b609a1eab143526 Mon Sep 17 00:00:00 2001 +From: Sylvain Becker +Date: Sun, 27 Nov 2022 17:38:43 +0100 +Subject: [PATCH 1/5] Cleanup add brace (#6545) + +* Add braces after if conditions + +* More add braces after if conditions + +* Add braces after while() conditions + +* Fix compilation because of macro being modified + +* Add braces to for loop + +* Add braces after if/goto + +* Move comments up + +* Remove extra () in the 'return ...;' statements + +* More remove extra () in the 'return ...;' statements + +* More remove extra () in the 'return ...;' statements after merge + +* Fix inconsistent patterns are xxx == NULL vs !xxx + +* More "{}" for "if() break;" and "if() continue;" + +* More "{}" after if() short statement + +* More "{}" after "if () return;" statement + +* More fix inconsistent patterns are xxx == NULL vs !xxx + +* Revert some modificaion on SDL_RLEaccel.c + +* SDL_RLEaccel: no short statement + +* Cleanup 'if' where the bracket is in a new line + +* Cleanup 'while' where the bracket is in a new line + +* Cleanup 'for' where the bracket is in a new line + +* Cleanup 'else' where the bracket is in a new line + +(cherry picked from commit 6a2200823c66e53bd3cda4a25f0206b834392652 to reduce conflicts merging between SDL2 and SDL3) +--- + src/core/linux/SDL_evdev_kbd.c | 64 +++++++++++++++++++++------------- + 1 file changed, 39 insertions(+), 25 deletions(-) + +diff --git a/src/core/linux/SDL_evdev_kbd.c b/src/core/linux/SDL_evdev_kbd.c +index f090bff41..f7f01deb4 100644 +--- a/src/core/linux/SDL_evdev_kbd.c ++++ b/src/core/linux/SDL_evdev_kbd.c +@@ -270,13 +270,14 @@ static void kbd_unregister_emerg_cleanup() + old_action_p = &(old_sigaction[signum]); + + /* Examine current signal action */ +- if (sigaction(signum, NULL, &cur_action)) ++ if (sigaction(signum, NULL, &cur_action)) { + continue; ++ } + + /* Check if action installed and not modifed */ +- if (!(cur_action.sa_flags & SA_SIGINFO) +- || cur_action.sa_sigaction != &kbd_cleanup_signal_action) ++ if (!(cur_action.sa_flags & SA_SIGINFO) || cur_action.sa_sigaction != &kbd_cleanup_signal_action) { + continue; ++ } + + /* Restore original action */ + sigaction(signum, old_action_p, NULL); +@@ -320,16 +321,16 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd) + struct sigaction new_action; + signum = fatal_signals[tabidx]; + old_action_p = &(old_sigaction[signum]); +- if (sigaction(signum, NULL, old_action_p)) ++ if (sigaction(signum, NULL, old_action_p)) { + continue; ++ } + + /* Skip SIGHUP and SIGPIPE if handler is already installed + * - assume the handler will do the cleanup + */ +- if ((signum == SIGHUP || signum == SIGPIPE) +- && (old_action_p->sa_handler != SIG_DFL +- || (void (*)(int))old_action_p->sa_sigaction != SIG_DFL)) ++ if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) { + continue; ++ } + + new_action = *old_action_p; + new_action.sa_flags |= SA_SIGINFO; +@@ -347,7 +348,7 @@ SDL_EVDEV_kbd_init(void) + char shift_state[ sizeof (long) ] = {TIOCL_GETSHIFTSTATE, 0}; + + kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd)); +- if (!kbd) { ++ if (kbd == NULL) { + return NULL; + } + +@@ -413,7 +414,7 @@ SDL_EVDEV_kbd_init(void) + void + SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd) + { +- if (!kbd) { ++ if (kbd == NULL) { + return; + } + +@@ -461,10 +462,12 @@ static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c) + put_queue(kbd, 0xc0 | (c >> 6)); + put_queue(kbd, 0x80 | (c & 0x3f)); + } else if (c < 0x10000) { +- if (c >= 0xD800 && c < 0xE000) ++ if (c >= 0xD800 && c < 0xE000) { + return; +- if (c == 0xFFFF) ++ } ++ if (c == 0xFFFF) { + return; ++ } + /* 1110**** 10****** 10****** */ + put_queue(kbd, 0xe0 | (c >> 12)); + put_queue(kbd, 0x80 | ((c >> 6) & 0x3f)); +@@ -499,8 +502,9 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch) + } + } + +- if (ch == ' ' || ch == d) ++ if (ch == ' ' || ch == d) { + return d; ++ } + + put_utf8(kbd, d); + +@@ -554,24 +558,27 @@ static void fn_enter(SDL_EVDEV_keyboard_state *kbd) + + static void fn_caps_toggle(SDL_EVDEV_keyboard_state *kbd) + { +- if (kbd->rep) ++ if (kbd->rep) { + return; ++ } + + chg_vc_kbd_led(kbd, K_CAPSLOCK); + } + + static void fn_caps_on(SDL_EVDEV_keyboard_state *kbd) + { +- if (kbd->rep) ++ if (kbd->rep) { + return; ++ } + + set_vc_kbd_led(kbd, K_CAPSLOCK); + } + + static void fn_num(SDL_EVDEV_keyboard_state *kbd) + { +- if (!kbd->rep) ++ if (!kbd->rep) { + chg_vc_kbd_led(kbd, K_NUMLOCK); ++ } + } + + static void fn_compose(SDL_EVDEV_keyboard_state *kbd) +@@ -589,12 +596,15 @@ static void k_ignore(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up + + static void k_spec(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) + { +- if (up_flag) ++ if (up_flag) { + return; +- if (value >= SDL_arraysize(fn_handler)) ++ } ++ if (value >= SDL_arraysize(fn_handler)) { + return; +- if (fn_handler[value]) ++ } ++ if (fn_handler[value]) { + fn_handler[value](kbd); ++ } + } + + static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) +@@ -603,11 +613,13 @@ static void k_lowercase(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char + + static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) + { +- if (up_flag) +- return; /* no action, if this is a key release */ ++ if (up_flag) { ++ return; /* no action, if this is a key release */ ++ } + +- if (kbd->diacr) ++ if (kbd->diacr) { + value = handle_diacr(kbd, value); ++ } + + if (kbd->dead_key_next) { + kbd->dead_key_next = SDL_FALSE; +@@ -676,8 +688,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_ + */ + if (value == KVAL(K_CAPSSHIFT)) { + value = KVAL(K_SHIFT); +- if (!up_flag) ++ if (!up_flag) { + clr_vc_kbd_led(kbd, K_CAPSLOCK); ++ } + } + + if (up_flag) { +@@ -685,8 +698,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_ + * handle the case that two shift or control + * keys are depressed simultaneously + */ +- if (kbd->shift_down[value]) ++ if (kbd->shift_down[value]) { + kbd->shift_down[value]--; ++ } + } else + kbd->shift_down[value]++; + +@@ -762,7 +776,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d + unsigned short *key_map; + unsigned short keysym; + +- if (!kbd) { ++ if (kbd == NULL) { + return; + } + +@@ -770,7 +784,7 @@ SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int d + + shift_final = (kbd->shift_state | kbd->slockstate) ^ kbd->lockstate; + key_map = kbd->key_maps[shift_final]; +- if (!key_map) { ++ if (key_map == NULL) { + /* Unsupported shift state (e.g. ctrl = 4, alt = 8), just reset to the default state */ + kbd->shift_state = 0; + kbd->slockstate = 0; +-- +2.39.2 + diff --git a/0002-Update-for-SDL3-coding-style-6717.patch b/0002-Update-for-SDL3-coding-style-6717.patch new file mode 100644 index 0000000..eaf10b0 --- /dev/null +++ b/0002-Update-for-SDL3-coding-style-6717.patch @@ -0,0 +1,282 @@ +From b8d85c6939eaa3fca676af832b5d64320b2296ca Mon Sep 17 00:00:00 2001 +From: Sam Lantinga +Date: Wed, 30 Nov 2022 12:51:59 -0800 +Subject: [PATCH 2/5] Update for SDL3 coding style (#6717) + +I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. + +In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. + +The script I ran for the src directory is added as build-scripts/clang-format-src.sh + +This fixes: +#6592 +#6593 +#6594 + +(cherry picked from commit 5750bcb174300011b91d1de20edb288fcca70f8c) +--- + src/core/linux/SDL_evdev_kbd.c | 92 ++++++++++++++++------------------ + 1 file changed, 42 insertions(+), 50 deletions(-) + +diff --git a/src/core/linux/SDL_evdev_kbd.c b/src/core/linux/SDL_evdev_kbd.c +index f7f01deb4..42b634a92 100644 +--- a/src/core/linux/SDL_evdev_kbd.c ++++ b/src/core/linux/SDL_evdev_kbd.c +@@ -53,33 +53,31 @@ + * Handler Tables. + */ + +-#define K_HANDLERS\ +- k_self, k_fn, k_spec, k_pad,\ +- k_dead, k_cons, k_cur, k_shift,\ +- k_meta, k_ascii, k_lock, k_lowercase,\ +- k_slock, k_dead2, k_brl, k_ignore ++#define K_HANDLERS \ ++ k_self, k_fn, k_spec, k_pad, \ ++ k_dead, k_cons, k_cur, k_shift, \ ++ k_meta, k_ascii, k_lock, k_lowercase, \ ++ k_slock, k_dead2, k_brl, k_ignore + +-typedef void (k_handler_fn)(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag); ++typedef void(k_handler_fn)(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag); + static k_handler_fn K_HANDLERS; + static k_handler_fn *k_handler[16] = { K_HANDLERS }; + +-typedef void (fn_handler_fn)(SDL_EVDEV_keyboard_state *kbd); ++typedef void(fn_handler_fn)(SDL_EVDEV_keyboard_state *kbd); + static void fn_enter(SDL_EVDEV_keyboard_state *kbd); + static void fn_caps_toggle(SDL_EVDEV_keyboard_state *kbd); + static void fn_caps_on(SDL_EVDEV_keyboard_state *kbd); + static void fn_num(SDL_EVDEV_keyboard_state *kbd); + static void fn_compose(SDL_EVDEV_keyboard_state *kbd); + +-static fn_handler_fn *fn_handler[] = +-{ +- NULL, fn_enter, NULL, NULL, +- NULL, NULL, NULL, fn_caps_toggle, +- fn_num, NULL, NULL, NULL, +- NULL, fn_caps_on, fn_compose, NULL, +- NULL, NULL, NULL, fn_num ++static fn_handler_fn *fn_handler[] = { ++ NULL, fn_enter, NULL, NULL, ++ NULL, NULL, NULL, fn_caps_toggle, ++ fn_num, NULL, NULL, NULL, ++ NULL, fn_caps_on, fn_compose, NULL, ++ NULL, NULL, NULL, fn_num + }; + +- + /* + * Keyboard State + */ +@@ -89,12 +87,12 @@ struct SDL_EVDEV_keyboard_state + int console_fd; + int old_kbd_mode; + unsigned short **key_maps; +- unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ ++ unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ + SDL_bool dead_key_next; +- int npadch; /* -1 or number assembled on pad */ ++ int npadch; /* -1 or number assembled on pad */ + struct kbdiacrs *accents; + unsigned int diacr; +- SDL_bool rep; /* flag telling character repeat */ ++ SDL_bool rep; /* flag telling character repeat */ + unsigned char lockstate; + unsigned char slockstate; + unsigned char ledflagstate; +@@ -114,7 +112,7 @@ static void SDL_EVDEV_dump_accents(SDL_EVDEV_keyboard_state *kbd) + for (i = 0; i < kbd->accents->kb_cnt; ++i) { + struct kbdiacr *diacr = &kbd->accents->kbdiacr[i]; + printf(" { 0x%.2x, 0x%.2x, 0x%.2x },\n", +- diacr->diacr, diacr->base, diacr->result); ++ diacr->diacr, diacr->base, diacr->result); + } + while (i < 256) { + printf(" { 0x00, 0x00, 0x00 },\n"); +@@ -134,7 +132,7 @@ static void SDL_EVDEV_dump_keymap(SDL_EVDEV_keyboard_state *kbd) + if (kbd->key_maps[i]) { + printf("static unsigned short default_key_map_%d[NR_KEYS] = {", i); + for (j = 0; j < NR_KEYS; ++j) { +- if ((j%8) == 0) { ++ if ((j % 8) == 0) { + printf("\n "); + } + printf("0x%.4x, ", kbd->key_maps[i][j]); +@@ -194,23 +192,22 @@ static int SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd) + return 0; + } + +-static SDL_EVDEV_keyboard_state * kbd_cleanup_state = NULL; ++static SDL_EVDEV_keyboard_state *kbd_cleanup_state = NULL; + static int kbd_cleanup_sigactions_installed = 0; + static int kbd_cleanup_atexit_installed = 0; + + static struct sigaction old_sigaction[NSIG]; + +-static int fatal_signals[] = +-{ ++static int fatal_signals[] = { + /* Handlers for SIGTERM and SIGINT are installed in SDL_QuitInit. */ +- SIGHUP, SIGQUIT, SIGILL, SIGABRT, +- SIGFPE, SIGSEGV, SIGPIPE, SIGBUS, ++ SIGHUP, SIGQUIT, SIGILL, SIGABRT, ++ SIGFPE, SIGSEGV, SIGPIPE, SIGBUS, + SIGSYS + }; + + static void kbd_cleanup(void) + { +- SDL_EVDEV_keyboard_state* kbd = kbd_cleanup_state; ++ SDL_EVDEV_keyboard_state *kbd = kbd_cleanup_state; + if (kbd == NULL) { + return; + } +@@ -219,18 +216,17 @@ static void kbd_cleanup(void) + ioctl(kbd->console_fd, KDSKBMODE, kbd->old_kbd_mode); + } + +-static void +-SDL_EVDEV_kbd_reraise_signal(int sig) ++static void SDL_EVDEV_kbd_reraise_signal(int sig) + { + raise(sig); + } + +-siginfo_t* SDL_EVDEV_kdb_cleanup_siginfo = NULL; +-void* SDL_EVDEV_kdb_cleanup_ucontext = NULL; ++siginfo_t *SDL_EVDEV_kdb_cleanup_siginfo = NULL; ++void *SDL_EVDEV_kdb_cleanup_ucontext = NULL; + +-static void kbd_cleanup_signal_action(int signum, siginfo_t* info, void* ucontext) ++static void kbd_cleanup_signal_action(int signum, siginfo_t *info, void *ucontext) + { +- struct sigaction* old_action_p = &(old_sigaction[signum]); ++ struct sigaction *old_action_p = &(old_sigaction[signum]); + sigset_t sigset; + + /* Restore original signal handler before going any further. */ +@@ -264,7 +260,7 @@ static void kbd_unregister_emerg_cleanup() + kbd_cleanup_sigactions_installed = 0; + + for (tabidx = 0; tabidx < sizeof(fatal_signals) / sizeof(fatal_signals[0]); ++tabidx) { +- struct sigaction* old_action_p; ++ struct sigaction *old_action_p; + struct sigaction cur_action; + signum = fatal_signals[tabidx]; + old_action_p = &(old_sigaction[signum]); +@@ -293,7 +289,7 @@ static void kbd_cleanup_atexit(void) + kbd_unregister_emerg_cleanup(); + } + +-static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd) ++static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state *kbd) + { + int tabidx, signum; + +@@ -317,9 +313,9 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd) + kbd_cleanup_sigactions_installed = 1; + + for (tabidx = 0; tabidx < sizeof(fatal_signals) / sizeof(fatal_signals[0]); ++tabidx) { +- struct sigaction* old_action_p; ++ struct sigaction *old_action_p; + struct sigaction new_action; +- signum = fatal_signals[tabidx]; ++ signum = fatal_signals[tabidx]; + old_action_p = &(old_sigaction[signum]); + if (sigaction(signum, NULL, old_action_p)) { + continue; +@@ -328,7 +324,7 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd) + /* Skip SIGHUP and SIGPIPE if handler is already installed + * - assume the handler will do the cleanup + */ +- if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) { ++ if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void (*)(int))old_action_p->sa_sigaction != SIG_DFL)) { + continue; + } + +@@ -345,7 +341,7 @@ SDL_EVDEV_kbd_init(void) + SDL_EVDEV_keyboard_state *kbd; + int i; + char flag_state; +- char shift_state[ sizeof (long) ] = {TIOCL_GETSHIFTSTATE, 0}; ++ char shift_state[sizeof(long)] = { TIOCL_GETSHIFTSTATE, 0 }; + + kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd)); + if (kbd == NULL) { +@@ -411,8 +407,7 @@ SDL_EVDEV_kbd_init(void) + return kbd; + } + +-void +-SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd) ++void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd) + { + if (kbd == NULL) { + return; +@@ -447,7 +442,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd) + static void put_queue(SDL_EVDEV_keyboard_state *kbd, uint c) + { + /* c is already part of a UTF-8 sequence and safe to add as a character */ +- if (kbd->text_len < (sizeof(kbd->text)-1)) { ++ if (kbd->text_len < (sizeof(kbd->text) - 1)) { + kbd->text[kbd->text_len++] = (char)c; + } + } +@@ -615,7 +610,7 @@ static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_f + { + if (up_flag) { + return; /* no action, if this is a key release */ +- } ++ } + + if (kbd->diacr) { + value = handle_diacr(kbd, value); +@@ -639,7 +634,7 @@ static void k_deadunicode(SDL_EVDEV_keyboard_state *kbd, unsigned int value, cha + + static void k_dead(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) + { +- const unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' }; ++ const unsigned char ret_diacr[NR_DEAD] = { '`', '\'', '^', '~', '"', ',' }; + + k_deadunicode(kbd, ret_diacr[value], up_flag); + } +@@ -666,7 +661,7 @@ static void k_pad(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_fl + static const char pad_chars[] = "0123456789+-*/\015,.?()#"; + + if (up_flag) +- return; /* no action, if this is a key release */ ++ return; /* no action, if this is a key release */ + + if (!vc_kbd_led(kbd, K_NUMLOCK)) { + /* unprintable action */ +@@ -768,8 +763,7 @@ static void k_brl(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_fl + { + } + +-void +-SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int down) ++void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int down) + { + unsigned char shift_final; + unsigned char type; +@@ -841,13 +835,11 @@ SDL_EVDEV_kbd_init(void) + return NULL; + } + +-void +-SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down) ++void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down) + { + } + +-void +-SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state) ++void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state) + { + } + +-- +2.39.2 + diff --git a/0003-Clang-Tidy-fixes-6725.patch b/0003-Clang-Tidy-fixes-6725.patch new file mode 100644 index 0000000..03620c1 --- /dev/null +++ b/0003-Clang-Tidy-fixes-6725.patch @@ -0,0 +1,268 @@ +From d0bbfdbfb881e5407911d84c12899bd5b442a130 Mon Sep 17 00:00:00 2001 +From: Pierre Wendling <50808272+FtZPetruska@users.noreply.github.com> +Date: Thu, 1 Dec 2022 16:07:03 -0500 +Subject: [PATCH 3/5] Clang-Tidy fixes (#6725) + +(cherry picked from commit 3c501b963dd8f0605a6ce7978882df39ba76f9cd) +--- + src/core/linux/SDL_evdev_kbd.c | 98 ++++++++++++++++++---------------- + 1 file changed, 53 insertions(+), 45 deletions(-) + +diff --git a/src/core/linux/SDL_evdev_kbd.c b/src/core/linux/SDL_evdev_kbd.c +index 42b634a92..1f54c67db 100644 +--- a/src/core/linux/SDL_evdev_kbd.c ++++ b/src/core/linux/SDL_evdev_kbd.c +@@ -218,7 +218,7 @@ static void kbd_cleanup(void) + + static void SDL_EVDEV_kbd_reraise_signal(int sig) + { +- raise(sig); ++ (void)raise(sig); + } + + siginfo_t *SDL_EVDEV_kdb_cleanup_siginfo = NULL; +@@ -303,7 +303,7 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state *kbd) + * functions that are called when the shared library is unloaded. + * -- man atexit(3) + */ +- atexit(kbd_cleanup_atexit); ++ (void)atexit(kbd_cleanup_atexit); + kbd_cleanup_atexit_installed = 1; + } + +@@ -407,33 +407,33 @@ SDL_EVDEV_kbd_init(void) + return kbd; + } + +-void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd) ++void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state) + { +- if (kbd == NULL) { ++ if (state == NULL) { + return; + } + + kbd_unregister_emerg_cleanup(); + +- if (kbd->console_fd >= 0) { ++ if (state->console_fd >= 0) { + /* Restore the original keyboard mode */ +- ioctl(kbd->console_fd, KDSKBMODE, kbd->old_kbd_mode); ++ ioctl(state->console_fd, KDSKBMODE, state->old_kbd_mode); + +- close(kbd->console_fd); +- kbd->console_fd = -1; ++ close(state->console_fd); ++ state->console_fd = -1; + } + +- if (kbd->key_maps && kbd->key_maps != default_key_maps) { ++ if (state->key_maps && state->key_maps != default_key_maps) { + int i; + for (i = 0; i < MAX_NR_KEYMAPS; ++i) { +- if (kbd->key_maps[i]) { +- SDL_free(kbd->key_maps[i]); ++ if (state->key_maps[i]) { ++ SDL_free(state->key_maps[i]); + } + } +- SDL_free(kbd->key_maps); ++ SDL_free(state->key_maps); + } + +- SDL_free(kbd); ++ SDL_free(state); + } + + /* +@@ -449,10 +449,9 @@ static void put_queue(SDL_EVDEV_keyboard_state *kbd, uint c) + + static void put_utf8(SDL_EVDEV_keyboard_state *kbd, uint c) + { +- if (c < 0x80) +- /* 0******* */ +- put_queue(kbd, c); +- else if (c < 0x800) { ++ if (c < 0x80) { ++ put_queue(kbd, c); /* 0******* */ ++ } else if (c < 0x800) { + /* 110***** 10****** */ + put_queue(kbd, 0xc0 | (c >> 6)); + put_queue(kbd, 0x80 | (c & 0x3f)); +@@ -626,8 +625,9 @@ static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_f + + static void k_deadunicode(SDL_EVDEV_keyboard_state *kbd, unsigned int value, char up_flag) + { +- if (up_flag) ++ if (up_flag) { + return; ++ } + + kbd->diacr = (kbd->diacr ? handle_diacr(kbd, value) : value); + } +@@ -660,8 +660,9 @@ static void k_pad(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_fl + { + static const char pad_chars[] = "0123456789+-*/\015,.?()#"; + +- if (up_flag) ++ if (up_flag) { + return; /* no action, if this is a key release */ ++ } + + if (!vc_kbd_led(kbd, K_NUMLOCK)) { + /* unprintable action */ +@@ -675,8 +676,9 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_ + { + int old_state = kbd->shift_state; + +- if (kbd->rep) ++ if (kbd->rep) { + return; ++ } + /* + * Mimic typewriter: + * a CapsShift key acts like Shift but undoes CapsLock +@@ -696,13 +698,15 @@ static void k_shift(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_ + if (kbd->shift_down[value]) { + kbd->shift_down[value]--; + } +- } else ++ } else { + kbd->shift_down[value]++; ++ } + +- if (kbd->shift_down[value]) ++ if (kbd->shift_down[value]) { + kbd->shift_state |= (1 << value); +- else ++ } else { + kbd->shift_state &= ~(1 << value); ++ } + + /* kludge */ + if (up_flag && kbd->shift_state != old_state && kbd->npadch != -1) { +@@ -719,8 +723,9 @@ static void k_ascii(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_ + { + int base; + +- if (up_flag) ++ if (up_flag) { + return; ++ } + + if (value < 10) { + /* decimal input of code, while Alt depressed */ +@@ -731,16 +736,18 @@ static void k_ascii(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_ + base = 16; + } + +- if (kbd->npadch == -1) ++ if (kbd->npadch == -1) { + kbd->npadch = value; +- else ++ } else { + kbd->npadch = kbd->npadch * base + value; ++ } + } + + static void k_lock(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) + { +- if (up_flag || kbd->rep) ++ if (up_flag || kbd->rep) { + return; ++ } + + chg_vc_kbd_lock(kbd, value); + } +@@ -748,8 +755,9 @@ static void k_lock(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_f + static void k_slock(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) + { + k_shift(kbd, value, up_flag); +- if (up_flag || kbd->rep) ++ if (up_flag || kbd->rep) { + return; ++ } + + chg_vc_kbd_slock(kbd, value); + /* try to make Alt, oops, AltGr and such work */ +@@ -763,26 +771,26 @@ static void k_brl(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_fl + { + } + +-void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int down) ++void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down) + { + unsigned char shift_final; + unsigned char type; + unsigned short *key_map; + unsigned short keysym; + +- if (kbd == NULL) { ++ if (state == NULL) { + return; + } + +- kbd->rep = (down == 2); ++ state->rep = (down == 2); + +- shift_final = (kbd->shift_state | kbd->slockstate) ^ kbd->lockstate; +- key_map = kbd->key_maps[shift_final]; ++ shift_final = (state->shift_state | state->slockstate) ^ state->lockstate; ++ key_map = state->key_maps[shift_final]; + if (key_map == NULL) { + /* Unsupported shift state (e.g. ctrl = 4, alt = 8), just reset to the default state */ +- kbd->shift_state = 0; +- kbd->slockstate = 0; +- kbd->lockstate = 0; ++ state->shift_state = 0; ++ state->slockstate = 0; ++ state->lockstate = 0; + return; + } + +@@ -796,7 +804,7 @@ void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, + + if (type < 0xf0) { + if (down) { +- put_utf8(kbd, keysym); ++ put_utf8(state, keysym); + } + } else { + type -= 0xf0; +@@ -805,25 +813,25 @@ void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, + if (type == KT_LETTER) { + type = KT_LATIN; + +- if (vc_kbd_led(kbd, K_CAPSLOCK)) { +- key_map = kbd->key_maps[shift_final ^ (1 << KG_SHIFT)]; ++ if (vc_kbd_led(state, K_CAPSLOCK)) { ++ key_map = state->key_maps[shift_final ^ (1 << KG_SHIFT)]; + if (key_map) { + keysym = key_map[keycode]; + } + } + } + +- (*k_handler[type])(kbd, keysym & 0xff, !down); ++ (*k_handler[type])(state, keysym & 0xff, !down); + + if (type != KT_SLOCK) { +- kbd->slockstate = 0; ++ state->slockstate = 0; + } + } + +- if (kbd->text_len > 0) { +- kbd->text[kbd->text_len] = '\0'; +- SDL_SendKeyboardText(kbd->text); +- kbd->text_len = 0; ++ if (state->text_len > 0) { ++ state->text[state->text_len] = '\0'; ++ SDL_SendKeyboardText(state->text); ++ state->text_len = 0; + } + } + +-- +2.39.2 + diff --git a/0004-evdev_kbd-Use-current-keymap.patch b/0004-evdev_kbd-Use-current-keymap.patch new file mode 100644 index 0000000..4ca6b01 --- /dev/null +++ b/0004-evdev_kbd-Use-current-keymap.patch @@ -0,0 +1,207 @@ +From 96a2a6b94515c5a0c920d5ffd64bf83acb74d7a8 Mon Sep 17 00:00:00 2001 +From: Michal Suchanek +Date: Fri, 3 Mar 2023 19:44:11 +0100 +Subject: [PATCH] evdev_kbd: Use current keymap + +keymap can change over time, caching the keymap causes wrong keys +returned when user changes keymap during runtime + +Signed-off-by: Michal Suchanek +--- + src/core/linux/SDL_evdev_kbd.c | 126 ++++++++++++--------------------- + 1 file changed, 47 insertions(+), 79 deletions(-) + +diff --git a/src/core/linux/SDL_evdev_kbd.c b/src/core/linux/SDL_evdev_kbd.c +index f7ccca7ef..6535fdfc8 100644 +--- a/src/core/linux/SDL_evdev_kbd.c ++++ b/src/core/linux/SDL_evdev_kbd.c +@@ -153,45 +153,6 @@ static void SDL_EVDEV_dump_keymap(SDL_EVDEV_keyboard_state *kbd) + } + #endif /* DUMP_KEYMAP */ + +-static int SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd) +-{ +- int i, j; +- +- kbd->key_maps = (unsigned short **)SDL_calloc(MAX_NR_KEYMAPS, sizeof(unsigned short *)); +- if (!kbd->key_maps) { +- return -1; +- } +- +- for (i = 0; i < MAX_NR_KEYMAPS; ++i) { +- struct kbentry kbe; +- +- kbe.kb_table = i; +- kbe.kb_index = 0; +- if (ioctl(kbd->console_fd, KDGKBENT, &kbe) < 0) { +- return -1; +- } +- +- if (kbe.kb_value == K_NOSUCHMAP) { +- continue; +- } +- +- kbd->key_maps[i] = (unsigned short *)SDL_malloc(NR_KEYS * sizeof(unsigned short)); +- if (!kbd->key_maps[i]) { +- return -1; +- } +- +- for (j = 0; j < NR_KEYS; ++j) { +- kbe.kb_table = i; +- kbe.kb_index = j; +- if (ioctl(kbd->console_fd, KDGKBENT, &kbe) < 0) { +- return -1; +- } +- kbd->key_maps[i][j] = (kbe.kb_value ^ 0xf000); +- } +- } +- return 0; +-} +- + static SDL_EVDEV_keyboard_state *kbd_cleanup_state = NULL; + static int kbd_cleanup_sigactions_installed = 0; + static int kbd_cleanup_atexit_installed = 0; +@@ -339,8 +300,8 @@ SDL_EVDEV_keyboard_state * + SDL_EVDEV_kbd_init(void) + { + SDL_EVDEV_keyboard_state *kbd; +- int i; + char flag_state; ++ char kbtype; + char shift_state[sizeof(long)] = { TIOCL_GETSHIFTSTATE, 0 }; + + kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd)); +@@ -348,10 +309,14 @@ SDL_EVDEV_kbd_init(void) + return NULL; + } + +- kbd->npadch = -1; +- + /* This might fail if we're not connected to a tty (e.g. on the Steam Link) */ + kbd->console_fd = open("/dev/tty", O_RDONLY | O_CLOEXEC); ++ if (!((ioctl(kbd->console_fd, KDGKBTYPE, &kbtype) == 0) && ((kbtype == KB_101) || (kbtype == KB_84)))) { ++ close(kbd->console_fd); ++ kbd->console_fd = -1; ++ } ++ ++ kbd->npadch = -1; + + if (ioctl(kbd->console_fd, TIOCLINUX, shift_state) == 0) { + kbd->shift_state = *shift_state; +@@ -362,48 +327,27 @@ SDL_EVDEV_kbd_init(void) + } + + kbd->accents = &default_accents; +- if (ioctl(kbd->console_fd, KDGKBDIACR, kbd->accents) < 0) { +- /* No worries, we'll use the default accent table */ +- } +- + kbd->key_maps = default_key_maps; ++ + if (ioctl(kbd->console_fd, KDGKBMODE, &kbd->old_kbd_mode) == 0) { + /* Set the keyboard in UNICODE mode and load the keymaps */ + ioctl(kbd->console_fd, KDSKBMODE, K_UNICODE); ++ } + +- if (SDL_EVDEV_kbd_load_keymaps(kbd) < 0) { +- for (i = 0; i < MAX_NR_KEYMAPS; ++i) { +- if (kbd->key_maps[i]) { +- SDL_free(kbd->key_maps[i]); +- } +- } +- SDL_free(kbd->key_maps); +- +- kbd->key_maps = default_key_maps; +- } ++ /* Allow inhibiting keyboard mute with env. variable for debugging etc. */ ++ if (SDL_getenv("SDL_INPUT_LINUX_KEEP_KBD") == NULL) { ++ /* Mute the keyboard so keystrokes only generate evdev events ++ * and do not leak through to the console ++ */ ++ ioctl(kbd->console_fd, KDSKBMODE, K_OFF); + +- /* Allow inhibiting keyboard mute with env. variable for debugging etc. */ +- if (SDL_getenv("SDL_INPUT_LINUX_KEEP_KBD") == NULL) { +- /* Mute the keyboard so keystrokes only generate evdev events +- * and do not leak through to the console +- */ +- ioctl(kbd->console_fd, KDSKBMODE, K_OFF); +- +- /* Make sure to restore keyboard if application fails to call +- * SDL_Quit before exit or fatal signal is raised. +- */ +- if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, SDL_FALSE)) { +- kbd_register_emerg_cleanup(kbd); +- } ++ /* Make sure to restore keyboard if application fails to call ++ * SDL_Quit before exit or fatal signal is raised. ++ */ ++ if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, SDL_FALSE)) { ++ kbd_register_emerg_cleanup(kbd); + } + } +- +-#ifdef DUMP_ACCENTS +- SDL_EVDEV_dump_accents(kbd); +-#endif +-#ifdef DUMP_KEYMAP +- SDL_EVDEV_dump_keymap(kbd); +-#endif + return kbd; + } + +@@ -489,6 +433,11 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch) + + kbd->diacr = 0; + ++ if (kbd->console_fd >= 0) ++ if (ioctl(kbd->console_fd, KDGKBDIACR, kbd->accents) < 0) { ++ /* No worries, we'll use the default accent table */ ++ } ++ + for (i = 0; i < kbd->accents->kb_cnt; i++) { + if (kbd->accents->kbdiacr[i].diacr == d && + kbd->accents->kbdiacr[i].base == ch) { +@@ -795,7 +744,17 @@ void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode + } + + if (keycode < NR_KEYS) { +- keysym = key_map[keycode]; ++ if (state->console_fd < 0) { ++ keysym = key_map[keycode]; ++ } else { ++ struct kbentry kbe; ++ kbe.kb_table = shift_final; ++ kbe.kb_index = keycode; ++ if (ioctl(state->console_fd, KDGKBENT, &kbe) == 0) ++ keysym = (kbe.kb_value ^ 0xf000); ++ else ++ return; ++ } + } else { + return; + } +@@ -814,9 +773,18 @@ void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode + type = KT_LATIN; + + if (vc_kbd_led(state, K_CAPSLOCK)) { +- key_map = state->key_maps[shift_final ^ (1 << KG_SHIFT)]; ++ shift_final = shift_final ^ (1 << KG_SHIFT); ++ key_map = state->key_maps[shift_final]; + if (key_map) { +- keysym = key_map[keycode]; ++ if (state->console_fd < 0) { ++ keysym = key_map[keycode]; ++ } else { ++ struct kbentry kbe; ++ kbe.kb_table = shift_final; ++ kbe.kb_index = keycode; ++ if (ioctl(state->console_fd, KDGKBENT, &kbe) == 0) ++ keysym = (kbe.kb_value ^ 0xf000); ++ } + } + } + } +-- +2.39.2 + diff --git a/SDL2.changes b/SDL2.changes index f55d265..73da62a 100644 --- a/SDL2.changes +++ b/SDL2.changes @@ -1,3 +1,12 @@ +------------------------------------------------------------------- +Fri Mar 3 22:41:23 UTC 2023 - Michal Suchanek + +- Use current keypap on console https://github.com/libsdl-org/SDL/pull/7400 + + 0001-Cleanup-add-brace-6545.patch + + 0002-Update-for-SDL3-coding-style-6717.patch + + 0003-Clang-Tidy-fixes-6725.patch + + 0004-evdev_kbd-Use-current-keymap.patch + ------------------------------------------------------------------- Tue Feb 7 00:16:26 UTC 2023 - Jan Engelhardt diff --git a/SDL2.spec b/SDL2.spec index 40ccaff..b09299b 100644 --- a/SDL2.spec +++ b/SDL2.spec @@ -31,6 +31,10 @@ Source2: https://libsdl.org/release/%name-%version.tar.gz.sig Source3: %name.keyring Source4: baselibs.conf Patch1: sdl2-symvers.patch +Patch2: 0001-Cleanup-add-brace-6545.patch +Patch3: 0002-Update-for-SDL3-coding-style-6717.patch +Patch4: 0003-Clang-Tidy-fixes-6725.patch +Patch5: 0004-evdev_kbd-Use-current-keymap.patch BuildRequires: cmake BuildRequires: gcc-c++ BuildRequires: libdecor-devel