Skip to content

Commit

Permalink
Minor code formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
getreuer committed Jun 6, 2024
1 parent 1dcc54b commit d1464c4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 38 deletions.
34 changes: 21 additions & 13 deletions features/achordion.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
55 changes: 30 additions & 25 deletions features/achordion.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit d1464c4

Please sign in to comment.