forked from qmk/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix layer switching from tap dances by redoing the keymap lookup (qmk…
- Loading branch information
Showing
8 changed files
with
874 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright 2022 Sergey Vlasov (@sigprof) | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#pragma once | ||
|
||
#include "test_common.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2022 Sergey Vlasov (@sigprof) | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#include "quantum.h" | ||
#include "tap_dance_defs.h" | ||
|
||
// Implement custom keycodes which are used to check that the layer switching | ||
// behaves properly. | ||
bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
switch (keycode) { | ||
case FAST_AB: | ||
case SLOW_AB: | ||
if (record->event.pressed) { | ||
tap_code(KC_A); | ||
} else { | ||
tap_code(KC_B); | ||
} | ||
return keycode == SLOW_AB; | ||
case FAST_CD: | ||
case SLOW_CD: | ||
if (record->event.pressed) { | ||
tap_code(KC_C); | ||
} else { | ||
tap_code(KC_D); | ||
} | ||
return keycode == SLOW_CD; | ||
} | ||
return true; | ||
} | ||
|
||
// Implement a custom tap dance with the following behavior: | ||
// - single tap: KC_APP | ||
// - single hold: MO(1) | ||
// - double tap/hold: KC_RCTL | ||
// (The single tap and hold actions are mostly equivalent to LT(1, KC_APP).) | ||
|
||
enum lt_app_state { | ||
LTA_NONE, | ||
LTA_SINGLE_TAP, | ||
LTA_SINGLE_HOLD, | ||
LTA_DOUBLE_HOLD, | ||
}; | ||
|
||
static enum lt_app_state saved_lt_app_state; | ||
|
||
static enum lt_app_state get_lt_app_state(qk_tap_dance_state_t *state) { | ||
if (state->count == 1) { | ||
if (!state->pressed) { | ||
return LTA_SINGLE_TAP; | ||
} else { | ||
return LTA_SINGLE_HOLD; | ||
} | ||
} else if (state->count == 2) { | ||
return LTA_DOUBLE_HOLD; | ||
} else { | ||
return LTA_NONE; | ||
} | ||
} | ||
|
||
static void lt_app_finished(qk_tap_dance_state_t *state, void *user_data) { | ||
saved_lt_app_state = get_lt_app_state(state); | ||
switch (saved_lt_app_state) { | ||
case LTA_NONE: | ||
break; | ||
case LTA_SINGLE_TAP: | ||
register_code(KC_APP); | ||
break; | ||
case LTA_SINGLE_HOLD: | ||
layer_on(1); | ||
break; | ||
case LTA_DOUBLE_HOLD: | ||
register_code(KC_RCTL); | ||
break; | ||
} | ||
} | ||
|
||
static void lt_app_reset(qk_tap_dance_state_t *state, void *user_data) { | ||
switch (saved_lt_app_state) { | ||
case LTA_NONE: | ||
break; | ||
case LTA_SINGLE_TAP: | ||
unregister_code(KC_APP); | ||
break; | ||
case LTA_SINGLE_HOLD: | ||
layer_off(1); | ||
break; | ||
case LTA_DOUBLE_HOLD: | ||
unregister_code(KC_RCTL); | ||
break; | ||
} | ||
} | ||
|
||
qk_tap_dance_action_t tap_dance_actions[] = { | ||
[TD_L_MOVE] = ACTION_TAP_DANCE_LAYER_MOVE(KC_APP, 1), | ||
[TD_L_TOGG] = ACTION_TAP_DANCE_LAYER_TOGGLE(KC_APP, 1), | ||
[TD_LT_APP] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, lt_app_finished, lt_app_reset), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2022 Sergey Vlasov (@sigprof) | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
enum custom_keycodes { | ||
// (FAST|SLOW)_xy = tap KC_x on press, tap KC_y on release. For FAST_xy | ||
// process_record_user() returns false to stop processing early; for | ||
// SLOW_xy process_record_user() returns true, therefore all other key | ||
// handlers are invoked. | ||
FAST_AB = SAFE_RANGE, | ||
FAST_CD, | ||
SLOW_AB, | ||
SLOW_CD, | ||
}; | ||
|
||
enum tap_dance_ids { | ||
TD_L_MOVE, // ACTION_TAP_DANCE_LAYER_MOVE(KC_APP, 1) | ||
TD_L_TOGG, // ACTION_TAP_DANCE_LAYER_TOGGLE(KC_APP, 1) | ||
TD_LT_APP, // similar to LT(1, KC_APP) with KC_RCTL on tap+hold or double tap | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright 2022 Sergey Vlasov (@sigprof) | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
# -------------------------------------------------------------------------------- | ||
# Keep this file, even if it is empty, as a marker that this folder contains tests | ||
# -------------------------------------------------------------------------------- | ||
|
||
TAP_DANCE_ENABLE = yes | ||
|
||
SRC += tap_dance_defs.c |
Oops, something went wrong.