From 9632360caa5e6511b0ec13cb4c55eb64408232b5 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 30 Aug 2022 03:20:04 -0500 Subject: Use a macro to compute the size of arrays at compile time (#18044) * Add ARRAY_SIZE and CEILING utility macros * Apply a coccinelle patch to use ARRAY_SIZE * fix up some straggling items * Fix 'make test:secure' * Enhance ARRAY_SIZE macro to reject acting on pointers The previous definition would not produce a diagnostic for ``` int *p; size_t num_elem = ARRAY_SIZE(p) ``` but the new one will. * explicitly get definition of ARRAY_SIZE * Convert to ARRAY_SIZE when const is involved The following spatch finds additional instances where the array is const and the division is by the size of the type, not the size of the first element: ``` @ rule5a using "empty.iso" @ type T; const T[] E; @@ - (sizeof(E)/sizeof(T)) + ARRAY_SIZE(E) @ rule6a using "empty.iso" @ type T; const T[] E; @@ - sizeof(E)/sizeof(T) + ARRAY_SIZE(E) ``` * New instances of ARRAY_SIZE added since initial spatch run * Use `ARRAY_SIZE` in docs (found by grep) * Manually use ARRAY_SIZE hs_set is expected to be the same size as uint16_t, though it's made of two 8-bit integers * Just like char, sizeof(uint8_t) is guaranteed to be 1 This is at least true on any plausible system where qmk is actually used. Per my understanding it's universally true, assuming that uint8_t exists: https://stackoverflow.com/questions/48655310/can-i-assume-that-sizeofuint8-t-1 * Run qmk-format on core C files touched in this branch Co-authored-by: Stefan Kerkmann --- users/uqs/uqs.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'users/uqs') diff --git a/users/uqs/uqs.c b/users/uqs/uqs.c index 72284143c6..7e2d09e0f6 100644 --- a/users/uqs/uqs.c +++ b/users/uqs/uqs.c @@ -78,9 +78,9 @@ const rgblight_segment_t* const PROGMEM my_rgb_layers[] = { my_rgb_segments[L_MOUSE], }; -_Static_assert(sizeof(my_rgb_layers) / sizeof(my_rgb_layers[0]) == - sizeof(my_rgb_segments) / sizeof(my_rgb_segments[0]), - "Number of rgb_segment definitions does not match up!"); +_Static_assert(ARRAY_SIZE(my_rgb_layers) == + ARRAY_SIZE(my_rgb_segments), + "Number of rgb_segment definitions does not match up!"); #endif #ifdef COMBO_ENABLE @@ -125,7 +125,7 @@ const uint16_t PROGMEM my_combos[][4] = { {KC_BTN1, KC_BTN2, KC_BTN3, COMBO_END}, }; -const uint16_t COMBO_LEN = sizeof(my_action_combos) / sizeof(my_action_combos[0]) + sizeof(my_combos) / sizeof(my_combos[0]); +const uint16_t COMBO_LEN = ARRAY_SIZE(my_action_combos) + ARRAY_SIZE(my_combos); #define MY_ACTION_COMBO(ck) \ [ck] = { .keys = &(my_action_combos[ck][0]) } @@ -162,11 +162,11 @@ combo_t key_combos[] = { MY_COMBO(14), }; -_Static_assert(sizeof(key_combos) / sizeof(key_combos[0]) == - (sizeof(my_action_combos) / sizeof(my_action_combos[0]) + sizeof(my_combos) / sizeof(my_combos[0])), - "Number of combo definitions does not match up!"); +_Static_assert(ARRAY_SIZE(key_combos) == + (ARRAY_SIZE(my_action_combos) + ARRAY_SIZE(my_combos)), + "Number of combo definitions does not match up!"); #else -combo_t key_combos[sizeof(my_action_combos) / sizeof(my_action_combos[0]) + sizeof(my_combos) / sizeof(my_combos[0])]; +combo_t key_combos[ARRAY_SIZE(my_action_combos) + ARRAY_SIZE(my_combos)]; #endif void process_combo_event(uint16_t combo_index, bool pressed) { @@ -235,10 +235,10 @@ void keyboard_post_init_user(void) { #endif #if defined(COMBO_ENABLE) && !defined(COMBO_STATICALLY) uint8_t i = 0; - for (; i < sizeof(my_action_combos) / sizeof(my_action_combos[0]); i++) { + for (; i < ARRAY_SIZE(my_action_combos); i++) { key_combos[i].keys = &(my_action_combos[i][0]); } - for (uint8_t j = 0; j < sizeof(my_combos) / sizeof(my_combos[0]); j++, i++) { + for (uint8_t j = 0; j < ARRAY_SIZE(my_combos); j++, i++) { key_combos[i].keycode = my_combos[j][0]; key_combos[i].keys = &(my_combos[j][1]); } -- cgit v1.2.3 From ad8630bd7229937877aa9a29693bbb8942a27abe Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sat, 15 Oct 2022 09:59:31 -0700 Subject: Remove RGBLIGHT_ANIMATION and clean up effect defines for layouts+users (#18729) --- users/uqs/config.h | 1 - 1 file changed, 1 deletion(-) (limited to 'users/uqs') diff --git a/users/uqs/config.h b/users/uqs/config.h index b8a140fe87..5530417de1 100644 --- a/users/uqs/config.h +++ b/users/uqs/config.h @@ -4,7 +4,6 @@ #ifdef RGBLIGHT_ENABLE # define RGBLIGHT_SLEEP -//# define RGBLIGHT_ANIMATIONS // disabled to save space # define RGBLIGHT_LAYERS # define RGBLIGHT_MAX_LAYERS 8 // default is 16 # define RGBLIGHT_DISABLE_KEYCODES // RGB_foo keys no longer work, saves 600 bytes -- cgit v1.2.3 From bad8c5992bf68b6f2218b9b7a0b31c6ee7a03796 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 17 Oct 2022 23:45:23 +1100 Subject: Remove legacy sendstring keycodes (#18749) --- users/uqs/uqs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'users/uqs') diff --git a/users/uqs/uqs.c b/users/uqs/uqs.c index 7e2d09e0f6..ede34d4556 100644 --- a/users/uqs/uqs.c +++ b/users/uqs/uqs.c @@ -502,10 +502,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { /* * Obsoleted by making tmux understand Ctrl-(Shift)-Tab natively. case TM_NEXT: - if (record->event.pressed) SEND_STRING(SS_LCTRL("a") "n"); + if (record->event.pressed) SEND_STRING(SS_LCTL("a") "n"); break; case TM_PREV: - if (record->event.pressed) SEND_STRING(SS_LCTRL("a") "p"); + if (record->event.pressed) SEND_STRING(SS_LCTL("a") "p"); break; */ // TODO: use key overrides to turn, e.g. Win+Ctrl-Tab into VIM_NEXT. @@ -517,16 +517,16 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) SEND_STRING(SS_TAP(X_ESC) SS_TAP(X_G) SS_LSFT("t")); break; case WIN_LEFT: - if (record->event.pressed) SEND_STRING(SS_LCTRL("w") SS_TAP(X_H)); + if (record->event.pressed) SEND_STRING(SS_LCTL("w") SS_TAP(X_H)); break; case WIN_DN: - if (record->event.pressed) SEND_STRING(SS_LCTRL("w") SS_TAP(X_J)); + if (record->event.pressed) SEND_STRING(SS_LCTL("w") SS_TAP(X_J)); break; case WIN_UP: - if (record->event.pressed) SEND_STRING(SS_LCTRL("w") SS_TAP(X_K)); + if (record->event.pressed) SEND_STRING(SS_LCTL("w") SS_TAP(X_K)); break; case WIN_RGHT: - if (record->event.pressed) SEND_STRING(SS_LCTRL("w") SS_TAP(X_L)); + if (record->event.pressed) SEND_STRING(SS_LCTL("w") SS_TAP(X_L)); break; } -- cgit v1.2.3 From b33fc349671148bff6f0a60172b53c51e59cda49 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 22 Oct 2022 00:25:54 +1100 Subject: Deprecate `KC_LEAD` for `QK_LEAD` (#18792) --- users/uqs/uqs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'users/uqs') diff --git a/users/uqs/uqs.h b/users/uqs/uqs.h index f8b30caf79..b5026e5b59 100644 --- a/users/uqs/uqs.h +++ b/users/uqs/uqs.h @@ -52,7 +52,7 @@ enum custom_keycodes { }; #ifndef LEADER_ENABLE -#define KC_LEAD KC_NO +#define QK_LEAD KC_NO #endif // Shorter names -- cgit v1.2.3 From 5974d989fe72f6c576901a065bee4487a58c351d Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 1 Nov 2022 08:15:12 +1100 Subject: Normalise Unicode keycodes (#18898) * `UC_MOD`/`UC_RMOD` -> `UC_NEXT`/`UC_PREV` * `UNICODE_MODE_*` -> `QK_UNICODE_MODE_*` * `UC_MAC` -> `UNICODE_MODE_MACOS` * `UC_LNX` -> `UNICODE_MODE_LINUX` * `UC_WIN` -> `UNICODE_MODE_WINDOWS` * `UC_BSD` -> `UNICODE_MODE_BSD` * `UC_WINC` -> `UNICODE_MODE_WINCOMPOSE` * `UC_EMACS` -> `UNICODE_MODE_EMACS` * `UC__COUNT` -> `UNICODE_MODE_COUNT` * `UC_M_MA` -> `UC_MAC` * `UC_M_LN` -> `UC_LINX` * `UC_M_WI` -> `UC_WIN` * `UC_M_BS` -> `UC_BSD` * `UC_M_WC` -> `UC_WINC` * `UC_M_EM` -> `UC_EMAC` * Docs * Update quantum/unicode/unicode.h --- users/uqs/config.h | 2 +- users/uqs/uqs.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'users/uqs') diff --git a/users/uqs/config.h b/users/uqs/config.h index 5530417de1..4bb793532b 100644 --- a/users/uqs/config.h +++ b/users/uqs/config.h @@ -22,7 +22,7 @@ #define LEADER_TIMEOUT 400 #define LEADER_PER_KEY_TIMING -#define UNICODE_SELECTED_MODES UC_LNX +#define UNICODE_SELECTED_MODES UNICODE_MODE_LINUX // make KC_ACL0 et al work when held. #define MK_COMBINED diff --git a/users/uqs/uqs.c b/users/uqs/uqs.c index ede34d4556..82cf70c439 100644 --- a/users/uqs/uqs.c +++ b/users/uqs/uqs.c @@ -560,13 +560,13 @@ void matrix_scan_user(void) { } // tableflip (LEADER - TF) SEQ_TWO_KEYS(KC_T, KC_F) { - //set_unicode_input_mode(UC_LNX); + //set_unicode_input_mode(UNICODE_MODE_LINUX); //send_unicode_hex_string("0028 30CE 0CA0 75CA 0CA0 0029 30CE 5F61 253B 2501 253B"); send_unicode_string("(╯°□°)╯︵ ┻━┻"); } // untableflip SEQ_THREE_KEYS(KC_U, KC_T, KC_F) { - //set_unicode_input_mode(UC_LNX); + //set_unicode_input_mode(UNICODE_MODE_LINUX); //send_unicode_hex_string("0028 30CE 0CA0 75CA 0CA0 0029 30CE 5F61 253B 2501 253B"); send_unicode_string("┬─┬ノ( º _ ºノ)"); } -- cgit v1.2.3