summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2024-03-10 00:47:43 +0100
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2024-03-10 00:47:43 +0100
commit40183b3cfa7fa2f487e1bfb828ddeecfc76c25e7 (patch)
treeec6b6e5cb3bf04a46dda00222252448e2dd9d707
parent7e9f4b4aedd9e26d2aa3a51fb762a1293c69af1c (diff)
Add sfrp to fix right parenthesis bug
-rw-r--r--aktersnurra/charybdis/keymap.c4
-rw-r--r--aktersnurra/ferris/keymap.c3
-rw-r--r--aktersnurra/sftrp.c69
3 files changed, 73 insertions, 3 deletions
diff --git a/aktersnurra/charybdis/keymap.c b/aktersnurra/charybdis/keymap.c
index 3bec92f..15316d9 100644
--- a/aktersnurra/charybdis/keymap.c
+++ b/aktersnurra/charybdis/keymap.c
@@ -2,6 +2,7 @@
// This is the canonical layout file for the Quantum project. If you want to add another keyboard,
#include QMK_KEYBOARD_H
+#include "../sftrp.c"
// Each layer gets a name for readability, which is then used in the keymap matrix below.
// The underscores don't mean anything - you can have a layer called STUFF or any other name.
@@ -19,7 +20,6 @@
#define KC_HN SFT_T(KC_N)
#define KC_SLBRC SFT_T(KC_LBRC)
-#define KC_SRPRN SFT_T(KC_RPRN)
#define KC_ALT_CTL LALT(KC_LCTL)
@@ -40,7 +40,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_SYM] = LAYOUT( /* [> Symbol layer <] */
KC_TRNS, KC_EXLM, KC_PERC, KC_DLR, KC_AT, KC_GRV, KC_ASTR, KC_CIRC, KC_TRNS, KC_TRNS,
- KC_AMPR, KC_HASH, KC_LPRN, KC_SRPRN, KC_MINS, KC_EQL, KC_SLBRC, KC_RBRC, KC_QUOT, KC_PIPE,
+ KC_AMPR, KC_HASH, KC_LPRN, TD(SFT_RP), KC_MINS, KC_EQL, KC_SLBRC, KC_RBRC, KC_QUOT, KC_PIPE,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BSLS,
KC_TRNS, KC_SPC, KC_TRNS, KC_TRNS, KC_TRNS
),
diff --git a/aktersnurra/ferris/keymap.c b/aktersnurra/ferris/keymap.c
index c7838e9..021b232 100644
--- a/aktersnurra/ferris/keymap.c
+++ b/aktersnurra/ferris/keymap.c
@@ -1,4 +1,5 @@
#include QMK_KEYBOARD_H
+#include "../sftrp.c"
#define KC_HA GUI_T(KC_A)
#define KC_HR ALT_T(KC_R)
@@ -37,7 +38,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_SYM] = LAYOUT( /* [> Symbol layer <] */
KC_TRNS, KC_EXLM, KC_PERC, KC_DLR, KC_AT, KC_GRV, KC_ASTR, KC_CIRC, KC_TRNS, KC_TRNS,
- KC_AMPR, KC_HASH, KC_LPRN, KC_SRPRN, KC_MINS, KC_EQL, KC_SLBRC, KC_RBRC, KC_QUOT, KC_PIPE,
+ KC_AMPR, KC_HASH, KC_LPRN, TD(SFT_RP), KC_MINS, KC_EQL, KC_SLBRC, KC_RBRC, KC_QUOT, KC_PIPE,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BSLS,
KC_TRNS, KC_SPC, KC_TRNS, KC_TRNS
),
diff --git a/aktersnurra/sftrp.c b/aktersnurra/sftrp.c
new file mode 100644
index 0000000..b80f6c7
--- /dev/null
+++ b/aktersnurra/sftrp.c
@@ -0,0 +1,69 @@
+enum td_keycodes {
+ SFT_RP // `LSFT` when held, `(` when tapped.
+};
+
+typedef enum {
+ TD_NONE,
+ TD_UNKNOWN,
+ TD_SINGLE_TAP,
+ TD_SINGLE_HOLD,
+ TD_DOUBLE_SINGLE_TAP
+} td_state_t;
+
+static td_state_t td_state;
+
+td_state_t cur_dance(tap_dance_state_t *state) {
+ if (state->count == 1) {
+ if (state->interrupted || !state->pressed)
+ return TD_SINGLE_TAP;
+ else
+ return TD_SINGLE_HOLD;
+ }
+
+ if (state->count == 2)
+ return TD_DOUBLE_SINGLE_TAP;
+ else
+ return TD_UNKNOWN; // Any number higher than the maximum state value you
+ // return above
+}
+
+void sftrp_finished(tap_dance_state_t *state, void *user_data) {
+ td_state = cur_dance(state);
+ switch (td_state) {
+ case TD_SINGLE_TAP:
+ register_code16(KC_RPRN);
+ break;
+ case TD_SINGLE_HOLD:
+ register_mods(MOD_BIT(
+ KC_LSFT)); // For a layer-tap key, use `layer_on(_MY_LAYER)` here
+ break;
+ case TD_DOUBLE_SINGLE_TAP: // Allow nesting of 2 parens `))` within tapping
+ // term
+ tap_code16(KC_RPRN);
+ register_code16(KC_RPRN);
+ break;
+ default:
+ break;
+ }
+}
+
+void sftrp_reset(tap_dance_state_t *state, void *user_data) {
+ switch (td_state) {
+ case TD_SINGLE_TAP:
+ unregister_code16(KC_RPRN);
+ break;
+ case TD_SINGLE_HOLD:
+ unregister_mods(MOD_BIT(
+ KC_LSFT)); // For a layer-tap key, use `layer_off(_MY_LAYER)` here
+ break;
+ case TD_DOUBLE_SINGLE_TAP:
+ unregister_code16(KC_RPRN);
+ break;
+ default:
+ break;
+ }
+}
+
+tap_dance_action_t tap_dance_actions[] = {
+ [SFT_RP] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, sftrp_finished, sftrp_reset)};
+