aboutsummaryrefslogtreecommitdiff
path: root/users/mnil/mnil.c
diff options
context:
space:
mode:
Diffstat (limited to 'users/mnil/mnil.c')
-rw-r--r--users/mnil/mnil.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/users/mnil/mnil.c b/users/mnil/mnil.c
new file mode 100644
index 000000000..11d5ee28d
--- /dev/null
+++ b/users/mnil/mnil.c
@@ -0,0 +1,146 @@
1/* Copyright 2021 Mats Nilsson
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "mnil.h"
18
19bool process_record_user(uint16_t keycode, keyrecord_t *record) {
20 switch (keycode) {
21 case M_TILD: // ~
22 if (record->event.pressed) {
23 tap_code16(RALT(KC_RBRC));
24 tap_code(KC_SPC);
25 } else {
26 }
27 break;
28 case M_CIRC: // ^
29 if (record->event.pressed) {
30 tap_code16(S(KC_RBRC));
31 tap_code(KC_SPC);
32 } else {
33 }
34 break;
35 case M_BTCK: // `
36 if (record->event.pressed) {
37 tap_code16(S(KC_EQL));
38 tap_code(KC_SPC);
39 } else {
40 }
41 break;
42 case QWE_COL: // Swap default keymap layer
43 if (record->event.pressed) {
44 if (get_highest_layer(default_layer_state) == _COLEMAK) {
45 default_layer_set(1UL << _QWERTY);
46 } else {
47 default_layer_set(1UL << _COLEMAK);
48 }
49 }
50 break;
51 }
52 return true;
53};
54
55// Tap Dance
56// Determine the current tap dance state
57int cur_dance(qk_tap_dance_state_t *state) {
58 if (state->count == 1) {
59 if (state->interrupted || !state->pressed)
60 return SINGLE_TAP;
61 else
62 return SINGLE_HOLD;
63 } else if (state->count == 2) {
64 if (state->interrupted)
65 return DOUBLE_SINGLE_TAP;
66 else if (state->pressed)
67 return DOUBLE_HOLD;
68 else
69 return DOUBLE_SINGLE_TAP;
70 }
71 if (state->count == 3) {
72 if (state->interrupted || !state->pressed)
73 return TRIPLE_TAP;
74 else
75 return TRIPLE_HOLD;
76 } else
77 return 8;
78}
79
80static tap ae_tap_state = {.is_press_action = true, .state = 0};
81
82void ae_finished(qk_tap_dance_state_t *state, void *user_data) {
83 ae_tap_state.state = cur_dance(state);
84 switch (ae_tap_state.state) {
85 case SINGLE_TAP:
86 register_code(KC_A);
87 break;
88 case SINGLE_HOLD:
89 tap_code(SE_AE);
90 break;
91 case DOUBLE_SINGLE_TAP:
92 tap_code(KC_A);
93 register_code(KC_A);
94 break;
95 }
96}
97
98void ae_reset(qk_tap_dance_state_t *state, void *user_data) {
99 switch (ae_tap_state.state) {
100 case SINGLE_TAP:
101 unregister_code(KC_A);
102 break;
103 case DOUBLE_SINGLE_TAP:
104 unregister_code(KC_A);
105 break;
106 }
107 ae_tap_state.state = 0;
108}
109
110static tap aa_tap_state = {.is_press_action = true, .state = 0};
111
112void aa_finished(qk_tap_dance_state_t *state, void *user_data) {
113 aa_tap_state.state = cur_dance(state);
114 switch (aa_tap_state.state) {
115 case SINGLE_TAP:
116 register_code(SE_OSLH);
117 break;
118 case SINGLE_HOLD:
119 register_code(SE_AA);
120 unregister_code(SE_AA);
121 break;
122 case DOUBLE_SINGLE_TAP:
123 tap_code(SE_OSLH);
124 register_code(SE_OSLH);
125 break;
126 }
127}
128
129void aa_reset(qk_tap_dance_state_t *state, void *user_data) {
130 switch (aa_tap_state.state) {
131 case SINGLE_TAP:
132 unregister_code(SE_OSLH);
133 break;
134 case DOUBLE_SINGLE_TAP:
135 unregister_code(SE_OSLH);
136 break;
137 }
138 aa_tap_state.state = 0;
139}
140
141// clang-format off
142qk_tap_dance_action_t tap_dance_actions[] = {
143 [AAE] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, ae_finished, ae_reset, 250),
144 [OAA] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, aa_finished, aa_reset, 250)
145};
146// clang-format on