From d1464c4e7c7320a2ca4ece4ef27492b87639a620 Mon Sep 17 00:00:00 2001 From: Pascal Getreuer Date: Thu, 6 Jun 2024 10:38:36 -0700 Subject: [PATCH] Minor code formatting. --- features/achordion.c | 34 ++++++++++++++++----------- features/achordion.h | 55 ++++++++++++++++++++++++-------------------- 2 files changed, 51 insertions(+), 38 deletions(-) diff --git a/features/achordion.c b/features/achordion.c index 1d08bae..4833d1a 100644 --- a/features/achordion.c +++ b/features/achordion.c @@ -1,4 +1,4 @@ -// Copyright 2022-2023 Google LLC +// Copyright 2022-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -86,7 +86,7 @@ static void settle_as_hold(void) { #ifdef ACHORDION_STREAK static void update_streak_timer(uint16_t keycode, keyrecord_t* record) { if (achordion_streak_continue(keycode)) { - // The | 1 is because 0 is a possible time state, but we want 0 to mean unset + // We use 0 to represent an unset timer, so `| 1` to force a nonzero value. streak_timer = record->event.time | 1; } else { streak_timer = 0; @@ -184,8 +184,11 @@ bool process_achordion(uint16_t keycode, keyrecord_t* record) { if (achordion_state == STATE_UNSETTLED && record->event.pressed) { #ifdef ACHORDION_STREAK - const uint16_t s_timeout = achordion_streak_chord_timeout(tap_hold_keycode, keycode); - const bool is_streak = streak_timer && s_timeout && !timer_expired(record->event.time, (streak_timer + s_timeout)); + const uint16_t s_timeout = + achordion_streak_chord_timeout(tap_hold_keycode, keycode); + const bool is_streak = + streak_timer && s_timeout && + !timer_expired(record->event.time, (streak_timer + s_timeout)); #endif // Press event occurred on a key other than the active tap-hold key. @@ -200,8 +203,10 @@ bool process_achordion(uint16_t keycode, keyrecord_t* record) { // events back into the handling pipeline so that QMK features and other // user code can see them. This is done by calling `process_record()`, which // in turn calls most handlers including `process_record_user()`. - if (!is_streak && (!is_key_event || (is_tap_hold && record->tap.count == 0) || - achordion_chord(tap_hold_keycode, &tap_hold_record, keycode, record))) { + if (!is_streak && + (!is_key_event || (is_tap_hold && record->tap.count == 0) || + achordion_chord(tap_hold_keycode, &tap_hold_record, keycode, + record))) { dprintln("Achordion: Plumbing hold press."); settle_as_hold(); @@ -269,8 +274,9 @@ void achordion_task(void) { } #ifdef ACHORDION_STREAK - #define MAX_STREAK_TIMEOUT 800 - if (streak_timer && timer_expired(timer_read(), (streak_timer + MAX_STREAK_TIMEOUT))) { +#define MAX_STREAK_TIMEOUT 800 + if (streak_timer && + timer_expired(timer_read(), (streak_timer + MAX_STREAK_TIMEOUT))) { streak_timer = 0; // Expired. } #endif @@ -315,10 +321,11 @@ __attribute__((weak)) bool achordion_eager_mod(uint8_t mod) { __attribute__((weak)) bool achordion_streak_continue(uint16_t keycode) { // If any mods other than shift or AltGr are held, don't continue the streak if (get_mods() & (MOD_MASK_CG | MOD_BIT_LALT)) return false; - // This function doesn't get called for holds, so convert to tap version of keycodes + // This function doesn't get called for holds, so convert to tap version of + // keycodes if (IS_QK_MOD_TAP(keycode)) keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode); if (IS_QK_LAYER_TAP(keycode)) keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode); - // Regular letters and punctuation contiune the streak + // Regular letters and punctuation continue the streak. if (keycode >= KC_A && keycode <= KC_Z) return true; switch (keycode) { case KC_DOT: @@ -331,12 +338,13 @@ __attribute__((weak)) bool achordion_streak_continue(uint16_t keycode) { return false; } -__attribute__((weak)) uint16_t achordion_streak_chord_timeout(uint16_t tap_hold_keycode, uint16_t next_keycode) { +__attribute__((weak)) uint16_t achordion_streak_chord_timeout( + uint16_t tap_hold_keycode, uint16_t next_keycode) { return achordion_streak_timeout(tap_hold_keycode); } -/** @deprecated Use `achordion_streak_chord_timeout()` instead. */ -__attribute__((weak)) uint16_t achordion_streak_timeout(uint16_t tap_hold_keycode) { +__attribute__((weak)) uint16_t +achordion_streak_timeout(uint16_t tap_hold_keycode) { return 200; } #endif diff --git a/features/achordion.h b/features/achordion.h index 5e4ddb9..5430c0e 100644 --- a/features/achordion.h +++ b/features/achordion.h @@ -1,4 +1,4 @@ -// Copyright 2022-2023 Google LLC +// Copyright 2022-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -53,30 +53,6 @@ #include "quantum.h" -/** - * Suppress tap-hold mods within a *typing streak* by defining - * ACHORDION_STREAK. This can help preventing accidental mod - * activation when performing a fast tapping sequence. - * This is inspired by https://sunaku.github.io/home-row-mods.html#typing-streaks - * - * Enable with: - * - * #define ACHORDION_STREAK - * - * Adjust the maximum time between key events before modifiers can be enabled - * by defining the following callback in your keymap.c: - * - * uint16_t achordion_streak_chord_timeout( - * uint16_t tap_hold_keycode, uint16_t next_keycode) { - * return 200; // Default of 200 ms. - * } - */ -#ifdef ACHORDION_STREAK -bool achordion_streak_continue(uint16_t keycode); -uint16_t achordion_streak_chord_timeout(uint16_t tap_hold_keycode, uint16_t next_keycode); -uint16_t achordion_streak_timeout(uint16_t tap_hold_keycode); -#endif - #ifdef __cplusplus extern "C" { #endif @@ -183,6 +159,35 @@ bool achordion_eager_mod(uint8_t mod); bool achordion_opposite_hands(const keyrecord_t* tap_hold_record, const keyrecord_t* other_record); +/** + * Suppress tap-hold mods within a *typing streak* by defining + * ACHORDION_STREAK. This can help preventing accidental mod + * activation when performing a fast tapping sequence. + * This is inspired by + * https://sunaku.github.io/home-row-mods.html#typing-streaks + * + * Enable with: + * + * #define ACHORDION_STREAK + * + * Adjust the maximum time between key events before modifiers can be enabled + * by defining the following callback in your keymap.c: + * + * uint16_t achordion_streak_chord_timeout( + * uint16_t tap_hold_keycode, uint16_t next_keycode) { + * return 200; // Default of 200 ms. + * } + */ +#ifdef ACHORDION_STREAK +uint16_t achordion_streak_chord_timeout(uint16_t tap_hold_keycode, + uint16_t next_keycode); + +bool achordion_streak_continue(uint16_t keycode); + +/** @deprecated Use `achordion_streak_chord_timeout()` instead. */ +uint16_t achordion_streak_timeout(uint16_t tap_hold_keycode); +#endif + #ifdef __cplusplus } #endif