From 7f6697e0208e60489154511f3561c015c2d106f7 Mon Sep 17 00:00:00 2001
From: "Peter J. Keleher" <keleher@cs.umd.edu>
Date: Mon, 13 Apr 2020 00:52:54 -0400
Subject: [PATCH] auto

---
 config.h |   4 +-
 keymap.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 rules.mk |   1 +
 3 files changed, 148 insertions(+), 8 deletions(-)

diff --git a/config.h b/config.h
index 8e8bd2f..9eb9a76 100644
--- a/config.h
+++ b/config.h
@@ -12,8 +12,8 @@
 // #define PERMISSIVE_HOLD             // Makes tap and hold keys trigger the hold if another key is pressed before releasing, even if it hasn't hit the TAPPING_TERM. See Permissive Hold for details
 // #define IGNORE_MOD_TAP_INTERRUPT    // Makes it possible to do rolling combos (zx) with keys that convert to other keys on hold, by enforcing the TAPPING_TERM for both keys. See Mod tap interrupt for details
 // #define TAPPING_FORCE_HOLD          // Makes it possible to use a dual role key as modifier shortly after having been tapped. See Hold after tap. Breaks any Tap Toggle functionality (TT or the One Shot Tap Toggle)
-// #define LEADER_TIMEOUT 300          // How long before the leader key times out. If you're having issues finishing the sequence before it times out, you may need to increase the timeout setting. Or you may want to enable the LEADER_PER_KEY_TIMING option, which resets the timeout after each key is tapped.
-// #define LEADER_PER_KEY_TIMING       // Sets the timer for leader key chords to run on each key press rather than overall
+#define LEADER_TIMEOUT 250          // How long before the leader key times out. If you're having issues finishing the sequence before it times out, you may need to increase the timeout setting. Or you may want to enable the LEADER_PER_KEY_TIMING option, which resets the timeout after each key is tapped.
+#define LEADER_PER_KEY_TIMING       // Sets the timer for leader key chords to run on each key press rather than overall
 // #define LEADER_KEY_STRICT_KEY_PROCESSING    // Disables keycode filtering for Mod-Tap and Layer-Tap keycodes. Eg, if you enable this, you would need to specify MT(MOD_CTL, KC_A) if you want to use KC_A.
 // #define ONESHOT_TIMEOUT 300         // How long before oneshot times out
 // #define ONESHOT_TAP_TOGGLE 2        // How many taps before oneshot toggle is triggered
diff --git a/keymap.c b/keymap.c
index 0c120e1..4e2e954 100644
--- a/keymap.c
+++ b/keymap.c
@@ -6,6 +6,12 @@ enum ctrl_layers {
 	_FNC,
 	_KEN,
 	_KEN2,
+	_PROG
+};
+
+enum tapdance_keycodes {
+    TD_ESC_LGUI_0 = 0,
+    TD_F1_LGUI_1,
 };
 
 enum ctrl_keycodes {
@@ -37,16 +43,22 @@ enum ctrl_keycodes {
 bool autoshift_enabled;
 
 
+//Associate our tap dance key with its functionality
+qk_tap_dance_action_t tap_dance_actions[] = {
+					     [TD_ESC_LGUI_0] = ACTION_TAP_DANCE_DOUBLE(KC_ESC, RGUI(KC_0)),
+					     [TD_F1_LGUI_1] = ACTION_TAP_DANCE_DOUBLE(KC_F1, RGUI(KC_1)),
+};
+
 keymap_config_t keymap_config;
 
 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
 	[_QWERTY] = LAYOUT(
-			   KC_ESC,  KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,             RGB_TOG, KC_SLCK, TG(_KEN), \
+			   TD(TD_ESC_LGUI_0),  TD(TD_F1_LGUI_1),   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,             RGB_TOG, KC_SLCK, TG(_KEN), \
 		KC_GRV,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_MINS, KC_EQL,  KC_BSPC,   KC_INS,  KC_HOME, KC_PGUP, \
 		KC_TAB,  KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    KC_LBRC, KC_RBRC, KC_BSLS,   KC_DEL,  KC_END,  KC_PGDN, \
 		KC_LCTL, KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    KC_SCLN, KC_QUOT, KC_ENT, \
 		KC_LSPO, KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, KC_RSPC,                              KC_UP, \
-		KC_LCTL, KC_LALT, KC_LGUI,                   KC_SPC,                             KC_RALT, MO(_FNC), KC_APP,  KC_LEAD,            KC_LEFT, KC_DOWN, KC_RGHT \
+			   KC_LCTL, KC_LALT, KC_LGUI,                   KC_SPC,                             MO(_PROG), MO(_FNC), KC_APP,  KC_LEAD,            KC_LEFT, KC_DOWN, KC_RGHT \
 	),
 	[_NAV] = LAYOUT(
 		_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,            _______, _______, _______, \
@@ -80,6 +92,14 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
 	    _______, _______, _______, _______, _______, _______, KC_A,         KC_1,    KC_2,    KC_3, _______, _______,                              _______, \
 	    _______, _______, _______,                   _______,                            _______, _______, _______, _______,            _______, _______, TG(_QWERTY) \
 	),
+	[_PROG] = LAYOUT(
+	    LGUI(KC_R), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,            _______, _______, _______, \
+	    LGUI(KC_0), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,   _______, _______, _______, , \
+	    LGUI(KC_EQL), _______, KENKEN_NUM2, KC_UP, KC_C, KC_U, _______,    KC_7,    KC_8,    KC_9, _______, _______, _______, _______,   _______, _______, _______, \
+	    LGUI(KC_MINS), _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______,   KC_4,    KC_5,    KC_6, _______, _______, _______, \
+	    _______, _______, _______, _______, _______, _______, KC_A,         KC_1,    KC_2,    KC_3, _______, _______,                              _______, \
+	    _______, _______, _______,                   _______,                            _______, _______, _______, _______,            _______, _______, TG(_QWERTY) \
+	),
 	/*
 	[X] = LAYOUT(
 	    _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,            _______, _______, _______, \
@@ -116,7 +136,7 @@ void rgb_matrix_indicators_user(void)
 	switch (biton32(layer_state)) {
 	case _KEN:
 	    for (int i = 0; i < sizeof(positions); i++) {
-		rgb_matrix_set_color(i, 0, 0, 0);
+		rgb_matrix_set_color(i, 0xff, 0, 0);
 	    }
 	    // layer indicator
 	    rgb_matrix_set_color(15, 0xFF, 0, 0);
@@ -324,12 +344,132 @@ void matrix_init_user(void)
 LEADER_EXTERNS();
 
 void matrix_scan_user(void) {
-#ifdef NOTDEF
   LEADER_DICTIONARY() {
     leading = false;
     leader_end();
 
-    SEQ_ONE_KEY(KC_F) {
+    SEQ_ONE_KEY(KC_PGUP) {
+      // Anything you can do in a macro.
+	register_code(KC_LGUI);
+	register_code(KC_LCTL);
+	register_code(KC_LEFT);
+	unregister_code(KC_LEFT);
+	unregister_code(KC_LCTL);
+	unregister_code(KC_LGUI);
+    }
+    SEQ_ONE_KEY(KC_PGDN) {
+      // Anything you can do in a macro.
+	register_code(KC_LGUI);
+	register_code(KC_LCTL);
+	register_code(KC_RGHT);
+	unregister_code(KC_RGHT);
+	unregister_code(KC_LCTL);
+	unregister_code(KC_LGUI);
+    }
+    SEQ_ONE_KEY(KC_HOME) {
+      // Anything you can do in a macro.
+	register_code(KC_LGUI);
+	register_code(KC_LCTL);
+	register_code(KC_UP);
+	unregister_code(KC_UP);
+	unregister_code(KC_LCTL);
+	unregister_code(KC_LGUI);
+    }
+    SEQ_ONE_KEY(KC_END) {
+      // Anything you can do in a macro.
+	register_code(KC_LGUI);
+	register_code(KC_LCTL);
+	register_code(KC_END);
+	unregister_code(KC_END);
+	unregister_code(KC_LCTL);
+	unregister_code(KC_LGUI);
+    }
+    SEQ_ONE_KEY(KC_INS) {
+      // Anything you can do in a macro.
+	register_code(KC_LGUI);
+	register_code(KC_LCTL);
+	register_code(KC_F);
+	unregister_code(KC_F);
+	unregister_code(KC_LCTL);
+	unregister_code(KC_LGUI);
+    }
+    SEQ_ONE_KEY(KC_DEL) {
+      // Anything you can do in a macro.
+	register_code(KC_LGUI);
+	register_code(KC_LCTL);
+	register_code(KC_LALT);
+	register_code(KC_F);
+	unregister_code(KC_F);
+	unregister_code(KC_LALT);
+	unregister_code(KC_LCTL);
+	unregister_code(KC_LGUI);
+    }
+    SEQ_ONE_KEY(KC_ESC) {
+	SEND_STRING(SS_LGUI("0"));
+    }
+    SEQ_ONE_KEY(KC_F1) {
+	SEND_STRING(SS_LGUI("1"));
+    }
+    SEQ_ONE_KEY(KC_F2) {
+	SEND_STRING(SS_LGUI("2"));
+    }
+    SEQ_ONE_KEY(KC_F3) {
+	SEND_STRING(SS_LGUI("3"));
+    }
+    SEQ_ONE_KEY(KC_F4) {
+	SEND_STRING(SS_LGUI("4"));
+    }
+    SEQ_ONE_KEY(KC_F9) {
+	register_code(KC_LGUI);
+	register_code(KC_LALT);
+	register_code(KC_0);
+	unregister_code(KC_0);
+	unregister_code(KC_LALT);
+	unregister_code(KC_LGUI);
+    }
+    SEQ_ONE_KEY(KC_F5) {
+	register_code(KC_LGUI);
+	register_code(KC_LALT);
+	register_code(KC_1);
+	unregister_code(KC_1);
+	unregister_code(KC_LALT);
+	unregister_code(KC_LGUI);
+    }
+    SEQ_ONE_KEY(KC_F6) {
+	register_code(KC_LGUI);
+	register_code(KC_LALT);
+	register_code(KC_2);
+	unregister_code(KC_2);
+	unregister_code(KC_LALT);
+	unregister_code(KC_LGUI);
+    }
+    SEQ_ONE_KEY(KC_F7) {
+	register_code(KC_LGUI);
+	register_code(KC_LALT);
+	register_code(KC_3);
+	unregister_code(KC_3);
+	unregister_code(KC_LALT);
+	unregister_code(KC_LGUI);
+    }
+    SEQ_ONE_KEY(KC_F8) {
+	register_code(KC_LGUI);
+	register_code(KC_LALT);
+	register_code(KC_4);
+	unregister_code(KC_4);
+	unregister_code(KC_LALT);
+	unregister_code(KC_LGUI);
+    }
+    SEQ_ONE_KEY(KC_F10) {
+	register_code(KC_LGUI);
+	register_code(KC_LSFT);
+	register_code(KC_Y);
+	unregister_code(KC_Y);
+	unregister_code(KC_LSFT);
+	unregister_code(KC_LGUI);
+    }
+
+
+    SEQ_ONE_KEY(KC_A) {
       // Anything you can do in a macro.
       SEND_STRING("QMK is awesome.");
     }
@@ -346,7 +486,6 @@ void matrix_scan_user(void) {
       unregister_code(KC_LGUI);
     }
   }
-#endif
 }
 
 
diff --git a/rules.mk b/rules.mk
index a447cad..ea061ae 100644
--- a/rules.mk
+++ b/rules.mk
@@ -1,3 +1,4 @@
+TAP_DANCE_ENABLE = yes			# Enable tap dance keys
 LEADER_ENABLE = yes
 NKRO_ENABLE = yes           # USB Nkey Rollover
 AUTO_SHIFT_ENABLE = yes      # Auto Shift
-- 
GitLab