Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix functions when NO_ACTION_TAPPING is defined #11528

Merged
merged 11 commits into from
Feb 19, 2023
Merged
44 changes: 32 additions & 12 deletions quantum/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ void process_action(keyrecord_t *record, action_t action) {
}
}
} break;
#ifndef NO_ACTION_TAPPING
case ACT_LMODS_TAP:
case ACT_RMODS_TAP: {
#ifndef NO_ACTION_TAPPING
uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : action.key.mods << 4;
switch (action.layer_tap.code) {
# ifndef NO_ACTION_ONESHOT
Expand Down Expand Up @@ -519,8 +519,8 @@ void process_action(keyrecord_t *record, action_t action) {
}
break;
}
#endif // NO_ACTION_TAPPING
} break;
#endif
#ifdef EXTRAKEY_ENABLE
/* other HID usage */
case ACT_USAGE:
Expand All @@ -533,7 +533,7 @@ void process_action(keyrecord_t *record, action_t action) {
break;
}
break;
#endif
#endif // EXTRAKEY_ENABLE
/* Mouse key */
case ACT_MOUSEKEY:
register_mouse(action.key.code, event.pressed);
Expand Down Expand Up @@ -593,10 +593,10 @@ void process_action(keyrecord_t *record, action_t action) {
layer_off(action.layer_mods.layer);
}
break;
# ifndef NO_ACTION_TAPPING
case ACT_LAYER_TAP:
case ACT_LAYER_TAP_EXT:
switch (action.layer_tap.code) {
# ifndef NO_ACTION_TAPPING
case OP_TAP_TOGGLE:
/* tap toggle */
if (event.pressed) {
Expand All @@ -609,6 +609,7 @@ void process_action(keyrecord_t *record, action_t action) {
}
}
break;
# endif
case OP_ON_OFF:
event.pressed ? layer_on(action.layer_tap.val) : layer_off(action.layer_tap.val);
break;
Expand All @@ -618,7 +619,7 @@ void process_action(keyrecord_t *record, action_t action) {
case OP_SET_CLEAR:
event.pressed ? layer_move(action.layer_tap.val) : layer_clear();
break;
# ifndef NO_ACTION_ONESHOT
# if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
case OP_ONESHOT:
// Oneshot modifier
if (!keymap_config.oneshot_enable) {
Expand All @@ -628,7 +629,7 @@ void process_action(keyrecord_t *record, action_t action) {
layer_off(action.layer_tap.val);
}
} else {
# if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
# if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
do_release_oneshot = false;
if (event.pressed) {
if (get_oneshot_layer_state() == ONESHOT_TOGGLED) {
Expand All @@ -647,7 +648,7 @@ void process_action(keyrecord_t *record, action_t action) {
clear_oneshot_layer_state(ONESHOT_PRESSED);
}
}
# else
# else
if (event.pressed) {
layer_on(action.layer_tap.val);
set_oneshot_layer(action.layer_tap.val, ONESHOT_START);
Expand All @@ -657,12 +658,18 @@ void process_action(keyrecord_t *record, action_t action) {
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
}
}
# endif
# endif
}
# else // NO_ACTION_ONESHOT && NO_ACTION_TAPPING
if (event.pressed) {
layer_on(action.layer_tap.val);
} else {
layer_off(action.layer_tap.val);
}
# endif // !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
break;
# endif
default:
/* tap key */
# ifndef NO_ACTION_TAPPING /* tap key */
if (event.pressed) {
if (tap_count > 0) {
ac_dprintf("KEYMAP_TAP_KEY: Tap: register_code\n");
Expand All @@ -685,11 +692,24 @@ void process_action(keyrecord_t *record, action_t action) {
layer_off(action.layer_tap.val);
}
}
# else
if (event.pressed) {
ac_dprintf("KEYMAP_TAP_KEY: Tap: register_code\n");
register_code(action.layer_tap.code);
} else {
ac_dprintf("KEYMAP_TAP_KEY: Tap: unregister_code\n");
if (action.layer_tap.code == KC_CAPS) {
wait_ms(TAP_HOLD_CAPS_DELAY);
} else {
wait_ms(TAP_CODE_DELAY);
}
unregister_code(action.layer_tap.code);
}
# endif
break;
}
break;
# endif
#endif
#endif // NO_ACTION_LAYER

#ifdef SWAP_HANDS_ENABLE
case ACT_SWAP_HANDS:
Expand Down
4 changes: 2 additions & 2 deletions quantum/action_tapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record);
extern uint16_t g_tapping_term;
#endif

#ifdef TAPPING_TERM_PER_KEY
#if defined(TAPPING_TERM_PER_KEY) && !defined(NO_ACTION_TAPPING)
# define GET_TAPPING_TERM(keycode, record) get_tapping_term(keycode, record)
#elif defined(DYNAMIC_TAPPING_TERM_ENABLE)
#elif defined(DYNAMIC_TAPPING_TERM_ENABLE) && !defined(NO_ACTION_TAPPING)
# define GET_TAPPING_TERM(keycode, record) g_tapping_term
#else
# define GET_TAPPING_TERM(keycode, record) (TAPPING_TERM)
Expand Down
40 changes: 34 additions & 6 deletions quantum/keymap_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,20 @@ action_t action_for_keycode(uint16_t keycode) {
action.code = ACTION_MODS_KEY(mod_config(QK_MODS_GET_MODS(keycode)), keycode_config(QK_MODS_GET_BASIC_KEYCODE(keycode))); // adds modifier to key
#endif // LEGACY_MAGIC_HANDLING
break;
#ifndef NO_ACTION_LAYER
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
#if !defined(NO_ACTION_LAYER) && !defined(NO_ACTION_TAPPING)
# ifdef LEGACY_MAGIC_HANDLING
action.code = ACTION_LAYER_TAP_KEY(QK_LAYER_TAP_GET_LAYER(keycode), QK_LAYER_TAP_GET_TAP_KEYCODE(keycode));
# else // LEGACY_MAGIC_HANDLING
action.code = ACTION_LAYER_TAP_KEY(QK_LAYER_TAP_GET_LAYER(keycode), keycode_config(QK_LAYER_TAP_GET_TAP_KEYCODE(keycode)));
# endif // LEGACY_MAGIC_HANDLING
#else
// pass through keycode_config again, since it previously missed it
// and then only send as ACTION_KEY to bypass most of action.c handling
action.code = ACTION_KEY(keycode_config(QK_LAYER_TAP_GET_TAP_KEYCODE(keycode)));
#endif
break;
#ifndef NO_ACTION_LAYER
case QK_TO ... QK_TO_MAX:;
// Layer set "GOTO"
action_layer = QK_TO_GET_LAYER(keycode);
Expand Down Expand Up @@ -115,32 +121,54 @@ action_t action_for_keycode(uint16_t keycode) {
action_layer = QK_ONE_SHOT_LAYER_GET_LAYER(keycode);
action.code = ACTION_LAYER_ONESHOT(action_layer);
break;
#endif // NO_ACTION_ONESHOT
case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:;
// OSM(mod) - One-shot mod
mod = mod_config(QK_ONE_SHOT_MOD_GET_MODS(keycode));
mod = mod_config(QK_ONE_SHOT_MOD_GET_MODS(keycode));
#if defined(NO_ACTION_TAPPING) || defined(NO_ACTION_ONESHOT)
action.code = ACTION_MODS(mod);
#else // defined(NO_ACTION_TAPPING) || defined(NO_ACTION_ONESHOT)
action.code = ACTION_MODS_ONESHOT(mod);
#endif // defined(NO_ACTION_TAPPING) || defined(NO_ACTION_ONESHOT)
break;
#endif
#ifndef NO_ACTION_LAYER
case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
# ifndef NO_ACTION_TAPPING
action.code = ACTION_LAYER_TAP_TOGGLE(QK_LAYER_TAP_TOGGLE_GET_LAYER(keycode));
# else // NO_ACTION_TAPPING
# ifdef NO_ACTION_TAPPING_TAP_TOGGLE_MO
action.code = ACTION_LAYER_MOMENTARY(QK_LAYER_TAP_TOGGLE_GET_LAYER(keycode));
# else // NO_ACTION_TAPPING_TAP_TOGGLE_MO
action.code = ACTION_LAYER_TOGGLE(QK_LAYER_TAP_TOGGLE_GET_LAYER(keycode));
# endif // NO_ACTION_TAPPING_TAP_TOGGLE_MO
# endif // NO_ACTION_TAPPING
break;
case QK_LAYER_MOD ... QK_LAYER_MOD_MAX:
mod = mod_config(QK_LAYER_MOD_GET_MODS(keycode));
action_layer = QK_LAYER_MOD_GET_LAYER(keycode);
action.code = ACTION_LAYER_MODS(action_layer, mod);
break;
#endif
#ifndef NO_ACTION_TAPPING
#endif // NO_ACTION_LAYER
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
#ifndef NO_ACTION_TAPPING
mod = mod_config(QK_MOD_TAP_GET_MODS(keycode));
# ifdef LEGACY_MAGIC_HANDLING
action.code = ACTION_MODS_TAP_KEY(mod, QK_MOD_TAP_GET_TAP_KEYCODE(keycode));
# else // LEGACY_MAGIC_HANDLING
action.code = ACTION_MODS_TAP_KEY(mod, keycode_config(QK_MOD_TAP_GET_TAP_KEYCODE(keycode)));
# endif // LEGACY_MAGIC_HANDLING
#else // NO_ACTION_TAPPING
# ifdef NO_ACTION_TAPPING_MODTAP_MODS
// pass through mod_config again, since it previously missed it
// and then only send as ACTION_KEY to bypass most of action.c handling
action.code = ACTION_MODS(mod_config(QK_MOD_TAP_GET_MODS(keycode)));
# else // NO_ACTION_TAPPING_MODTAP_MODS
// pass through keycode_config again, since it previously missed it
// and then only send as ACTION_KEY to bypass most of action.c handling
action.code = ACTION_KEY(keycode_config(QK_MOD_TAP_GET_TAP_KEYCODE(keycode)));
# endif // NO_ACTION_TAPPING_MODTAP_MODS
#endif // NO_ACTION_TAPPING
break;
#endif
#ifdef SWAP_HANDS_ENABLE
case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
# ifdef LEGACY_MAGIC_HANDLING
Expand Down
6 changes: 5 additions & 1 deletion quantum/process_keycode/process_autocorrect.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ __attribute__((weak)) bool process_autocorrect_user(uint16_t *keycode, keyrecord
#ifdef SWAP_HANDS_ENABLE
// Note: IS_SWAP_HANDS_KEYCODE() actually tests for the special action keycodes like SH_TOGG, SH_TT, ...,
// which currently overlap the SH_T(kc) range.
if (IS_SWAP_HANDS_KEYCODE(*keycode) || !record->tap.count) {
if (IS_SWAP_HANDS_KEYCODE(*keycode)
# ifndef NO_ACTION_TAPPING
|| !record->tap.count
# endif // NO_ACTION_TAPPING
) {
return false;
}
*keycode = QK_SWAP_HANDS_GET_TAP_KEYCODE(*keycode);
Expand Down
6 changes: 5 additions & 1 deletion quantum/process_keycode/process_caps_word.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
// Note: IS_SWAP_HANDS_KEYCODE() actually tests for the special action keycodes like SH_TOGG, SH_TT, ...,
// which currently overlap the SH_T(kc) range.
if (IS_SWAP_HANDS_KEYCODE(keycode) || record->tap.count == 0) {
if (IS_SWAP_HANDS_KEYCODE(keycode)
# ifndef NO_ACTION_TAPPING
|| record->tap.count == 0
# endif // NO_ACTION_TAPPING
) {
return true;
}
keycode = QK_SWAP_HANDS_GET_TAP_KEYCODE(keycode);
Expand Down
21 changes: 21 additions & 0 deletions tests/no_tapping/no_action_tapping/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright 2017 Fred Sundvik
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "test_common.h"

#define NO_ACTION_TAPPING
18 changes: 18 additions & 0 deletions tests/no_tapping/no_action_tapping/test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2017 Fred Sundvik
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# --------------------------------------------------------------------------------
# Keep this file, even if it is empty, as a marker that this folder contains tests
# --------------------------------------------------------------------------------
63 changes: 63 additions & 0 deletions tests/no_tapping/no_action_tapping/test_layer_tap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* Copyright 2017 Fred Sundvik
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "keyboard_report_util.hpp"
#include "keycode.h"
#include "test_common.hpp"
#include "action_tapping.h"
#include "test_keymap_key.hpp"

using testing::_;
using testing::InSequence;

class Tapping : public TestFixture {};

TEST_F(Tapping, TapP_Layer_Tap_KeyReportsKey) {
TestDriver driver;
InSequence s;
auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, LT(1, KC_P));

set_keymap({key_shift_hold_p_tap});

key_shift_hold_p_tap.press();
EXPECT_REPORT(driver, (KC_P));
run_one_scan_loop();

key_shift_hold_p_tap.release();
EXPECT_EMPTY_REPORT(driver);
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}

TEST_F(Tapping, HoldP_Layer_Tap_KeyReportsKey) {
TestDriver driver;
InSequence s;
auto mod_tap_hold_key = KeymapKey(0, 7, 0, LT(1, KC_P));

set_keymap({mod_tap_hold_key});

mod_tap_hold_key.press();
EXPECT_REPORT(driver, (KC_P));

idle_for(TAPPING_TERM);
run_one_scan_loop();
EXPECT_NO_REPORT(driver);

mod_tap_hold_key.release();
EXPECT_EMPTY_REPORT(driver);
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}
Loading