Skip to content

Commit

Permalink
add swap hands unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlK90 committed May 5, 2023
1 parent 79fa530 commit 4c4392f
Show file tree
Hide file tree
Showing 8 changed files with 611 additions and 50 deletions.
46 changes: 2 additions & 44 deletions quantum/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,35 +236,6 @@ __attribute__((weak)) bool process_record_quantum(keyrecord_t *record) {

__attribute__((weak)) void post_process_record_quantum(keyrecord_t *record) {}

#ifndef NO_ACTION_TAPPING
/** \brief Allows for handling tap-hold actions immediately instead of waiting for TAPPING_TERM or another keypress.
*
* FIXME: Needs documentation.
*/
void process_record_tap_hint(keyrecord_t *record) {
if (!IS_KEYEVENT(record->event)) {
return;
}

action_t action = layer_switch_get_action(record->event.key);

switch (action.kind.id) {
# ifdef SWAP_HANDS_ENABLE
case ACT_SWAP_HANDS:
switch (action.swap.code) {
case OP_SH_ONESHOT:
break;
case OP_SH_TAP_TOGGLE:
default:
swap_hands = !swap_hands;
swap_held = true;
}
break;
# endif
}
}
#endif

/** \brief Take a key event (key press or key release) and processes it.
*
* FIXME: Needs documentation.
Expand Down Expand Up @@ -765,11 +736,8 @@ void process_action(keyrecord_t *record, action_t action) {
# ifndef NO_ACTION_TAPPING
case OP_SH_TAP_TOGGLE:
/* tap toggle */

if (event.pressed) {
if (swap_held) {
swap_held = false;
} else {
if (tap_count <= TAPPING_TOGGLE) {
swap_hands = !swap_hands;
}
} else {
Expand All @@ -781,22 +749,14 @@ void process_action(keyrecord_t *record, action_t action) {
default:
/* tap key */
if (tap_count > 0) {
if (swap_held) {
swap_hands = !swap_hands; // undo hold set up in _tap_hint
swap_held = false;
}
if (event.pressed) {
register_code(action.swap.code);
} else {
wait_ms(TAP_CODE_DELAY);
unregister_code(action.swap.code);
*record = (keyrecord_t){}; // hack: reset tap mode
}
} else {
if (swap_held && !event.pressed) {
swap_hands = !swap_hands; // undo hold set up in _tap_hint
swap_held = false;
}
swap_hands = !swap_hands;
}
# endif
}
Expand Down Expand Up @@ -1141,14 +1101,12 @@ bool is_tap_action(action_t action) {
case OP_ONESHOT:
return true;
}
return false;
case ACT_SWAP_HANDS:
switch (action.swap.code) {
case KC_NO ... KC_RIGHT_GUI:
case OP_SH_TAP_TOGGLE:
return true;
}
return false;
}
return false;
}
Expand Down
4 changes: 0 additions & 4 deletions quantum/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ void layer_switch(uint8_t new_layer);
bool is_tap_record(keyrecord_t *record);
bool is_tap_action(action_t action);

#ifndef NO_ACTION_TAPPING
void process_record_tap_hint(keyrecord_t *record);
#endif

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helpers

Expand Down
1 change: 0 additions & 1 deletion quantum/action_tapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ bool process_tapping(keyrecord_t *keyp) {
// into the "pressed" tapping key state
ac_dprintf("Tapping: Start(Press tap key).\n");
tapping_key = *keyp;
process_record_tap_hint(&tapping_key);
waiting_buffer_scan_tap();
debug_tapping_key();
} else {
Expand Down
4 changes: 3 additions & 1 deletion tests/basic/test_keycode_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ ::testing::Values(
std::make_pair(ALT_T(KC_TAB), "MT(MOD_LALT, KC_TAB)"),
// Mods
std::make_pair(LCTL(KC_A), "QK_MODS(KC_A, QK_LCTL)"),
std::make_pair(HYPR(KC_SPACE), "QK_MODS(KC_SPACE, QK_LCTL | QK_LSFT | QK_LALT | QK_LGUI)")
std::make_pair(HYPR(KC_SPACE), "QK_MODS(KC_SPACE, QK_LCTL | QK_LSFT | QK_LALT | QK_LGUI)"),
// Swap Hands
std::make_pair(SH_T(KC_A), "SH_T(KC_A)")
));
// clang-format on
9 changes: 9 additions & 0 deletions tests/swap_hands/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2023 Stefan Kerkmann (@KarlK90)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "test_common.h"

#define TAPPING_TERM 200
#define HOLD_ON_OTHER_KEY_PRESS_PER_KEY
4 changes: 4 additions & 0 deletions tests/swap_hands/test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 Stefan Kerkmann (@KarlK90)
# SPDX-License-Identifier: GPL-2.0-or-later

SWAP_HANDS_ENABLE = yes
Loading

0 comments on commit 4c4392f

Please sign in to comment.