]> git.donarmstrong.com Git - qmk_firmware.git/blob - users/333fred/333fred.c
Keymap: Adds zen layout for 333fred (#3563)
[qmk_firmware.git] / users / 333fred / 333fred.c
1 #include "333fred.h"
2 #include "quantum.h"
3 #include "action.h"
4
5 typedef enum {
6     SINGLE_TAP, SINGLE_HOLD, DOUBLE
7 } tap_dance_state_enum;
8
9 static tap_dance_state_enum tap_dance_state;
10 static bool tap_dance_active = false;
11
12 void tap_dance_layer_finished(qk_tap_dance_state_t *state, void *user_data) {
13     // Determine the current state
14     if (state->count == 1) {
15         if (state->interrupted || state->pressed == 0) tap_dance_state = SINGLE_TAP;
16         else tap_dance_state = SINGLE_HOLD;
17     } else {
18         // Handle any number of other taps as a VIM movement hold
19         tap_dance_state = DOUBLE;
20     }
21
22     switch (tap_dance_state) {
23         case SINGLE_TAP:
24             if (tap_dance_active) {
25                 reset_oneshot_layer();
26                 tap_dance_active = false;
27             } else {
28                 set_oneshot_layer(SYMB, ONESHOT_START);
29                 tap_dance_active = true;
30             }
31             break;
32         case SINGLE_HOLD:
33             layer_on(SYMB);
34             break;
35         case DOUBLE:
36             layer_on(VIM);
37             break;
38     }
39 }
40
41
42 void tap_dance_layer_reset(qk_tap_dance_state_t *state, void *user_data) {
43     switch(tap_dance_state) {
44         case SINGLE_TAP:
45             clear_oneshot_layer_state(ONESHOT_PRESSED);
46             break;
47         case SINGLE_HOLD:
48             layer_off(SYMB);
49             break;
50         case DOUBLE:
51             layer_off(VIM);
52             break;
53     }
54 }
55
56 qk_tap_dance_action_t tap_dance_actions[] = {
57     [TD_SYM_VIM] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, tap_dance_layer_finished, tap_dance_layer_reset)
58 };
59
60 void tap_dance_process_record(uint16_t keycode) {
61     if (tap_dance_state == SINGLE_TAP && keycode != TD(TD_SYM_VIM)) {
62         tap_dance_active = false;
63     }
64 }
65
66 __attribute__ ((weak))
67 void matrix_init_rgb(void) {}
68
69 __attribute__ ((weak))
70 void layer_state_set_rgb(uint32_t state) {}
71
72 __attribute__ ((weak))
73 void matrix_scan_user_keyboard(void) {}
74
75 void matrix_scan_user() {
76   static bool first_run = true;
77   if (first_run) {
78     first_run = false;
79     matrix_init_rgb();
80   }
81   matrix_scan_user_keyboard();
82 }
83
84 uint32_t layer_state_set_user(uint32_t state) {
85   layer_state_set_rgb(state);
86   return state;
87 }