aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Hærvig <10219471+jakobhaervig@users.noreply.github.com>2021-07-01 19:12:19 +0200
committerGitHub <noreply@github.com>2021-07-01 10:12:19 -0700
commitbef73f44aacf49d0969e3cdd6718b9a594d49066 (patch)
treea1a01e738dd1d7e9ad33224aa1d075e79c962ada
parentc275828ac20f55a42ca1d1546c330501c00839ab (diff)
downloadqmk_firmware-bef73f44aacf49d0969e3cdd6718b9a594d49066.tar.gz
qmk_firmware-bef73f44aacf49d0969e3cdd6718b9a594d49066.zip
[Keymap] Add haervig userspace and keymaps (#13362)
-rw-r--r--keyboards/dztech/dz65rgb/keymaps/haervig/keymap.c36
-rw-r--r--keyboards/dztech/dz65rgb/keymaps/haervig/rules.mk3
-rw-r--r--users/haervig/config.h19
-rw-r--r--users/haervig/haervig.c234
-rw-r--r--users/haervig/haervig.h297
-rw-r--r--users/haervig/readme.md11
-rw-r--r--users/haervig/rules.mk5
7 files changed, 605 insertions, 0 deletions
diff --git a/keyboards/dztech/dz65rgb/keymaps/haervig/keymap.c b/keyboards/dztech/dz65rgb/keymaps/haervig/keymap.c
new file mode 100644
index 000000000..6784c14f0
--- /dev/null
+++ b/keyboards/dztech/dz65rgb/keymaps/haervig/keymap.c
@@ -0,0 +1,36 @@
1/*
2Copyright 2021 Jakob Hærvig <jakob.haervig@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include QMK_KEYBOARD_H
19#include "haervig.h"
20
21const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
22 [0] = LAYOUT_65_ansi(
23 KC_GESC, DK_1, CU_2, DK_3, CU_4, DK_5, CU_6, CU_7, CU_8, CU_9, CU_0, CU_MINS, CU_EQL, CU_BSPC, KC_HOME,
24 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, CU_LBRC, CU_RBRC, CU_BSLS, KC_PGUP,
25 CTL_T(KC_CAPS), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, CU_SCLN, CU_QUOT, KC_ENT, KC_PGDN,
26 CU_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, CU_COMM, CU_DOT, CU_SLSH, CU_RSFT, KC_UP, KC_END,
27 KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, MO(1), KC_RALT, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
28 ),
29 [1] = LAYOUT_65_ansi(
30 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______,
31 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
32 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
33 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
34 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
35 )
36};
diff --git a/keyboards/dztech/dz65rgb/keymaps/haervig/rules.mk b/keyboards/dztech/dz65rgb/keymaps/haervig/rules.mk
new file mode 100644
index 000000000..676050bfc
--- /dev/null
+++ b/keyboards/dztech/dz65rgb/keymaps/haervig/rules.mk
@@ -0,0 +1,3 @@
1# Userspace defines
2DANISH_ENABLE = yes # Enable Custom US Ansi Keycodes for PC with Danish set as input language
3RGB_MATRIX_ENABLE = no # Disable the ugly RGB light \ No newline at end of file
diff --git a/users/haervig/config.h b/users/haervig/config.h
new file mode 100644
index 000000000..6a7d67737
--- /dev/null
+++ b/users/haervig/config.h
@@ -0,0 +1,19 @@
1/*
2Copyright 2021 Jakob Hærvig <jakob.haervig@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#pragma once
19#define TAPPING_TERM 200
diff --git a/users/haervig/haervig.c b/users/haervig/haervig.c
new file mode 100644
index 000000000..d03b43edc
--- /dev/null
+++ b/users/haervig/haervig.c
@@ -0,0 +1,234 @@
1/*
2Copyright 2021 Jakob Hærvig <jakob.haervig@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "haervig.h"
19
20#ifdef DANISH_ENABLE
21// These indicate if left and right shift are physically pressed
22bool lshift = false;
23bool rshift = false;
24
25// Interrupt and times for space cadet shift
26bool lshiftp = false;
27bool rshiftp = false;
28uint16_t lshift_timer = 0;
29uint16_t rshift_timer = 0;
30
31// Number of items that are saved in prev_kcs
32uint8_t prev_indx = 0;
33// Used to save the last 6 actual keycodes activated by frankenkeycodes
34uint16_t prev_kcs[6] = {0, 0, 0, 0, 0, 0};
35
36// If true the deadkey characters grave and circonflexe are not automatically escaped
37bool esct = false;
38
39/*
40Used to add a keycode to a prev_kcs to remember it.
41When full the last code gets discarded and replaced by
42the new one.
43*/
44void add_to_prev(uint16_t kc){
45 for (int i=0; i<prev_indx; i++){
46 if (kc == prev_kcs[i])
47 return;
48 }
49 if (prev_indx == 6){
50 for (int i=5; i>0; i--){
51 prev_kcs[i] = prev_kcs[i-1];
52 }
53 prev_kcs[0] = kc;
54 } else {
55 prev_kcs[prev_indx] = kc;
56 prev_indx++;
57 }
58}
59
60/*
61Unregisters all codes saved in prev_kcs and resets prev_indx.
62gets called on multiple occasions mainly when shift is released
63and when frankenkeycodes are pressed. Prevents output of
64wrong characters when really specific key combinations
65that would never occur during normal usage are pressed.
66*/
67void unreg_prev(void){
68 if (prev_indx == 0)
69 return;
70 for (int i=0; i<prev_indx; i++){
71 unregister_code(prev_kcs[i]);
72 }
73 prev_indx = 0;
74}
75#endif
76
77// Interrupt and times for Nav/Esc
78bool navesc = false;
79uint16_t navesc_timer = 0;
80
81// Interrupts all timers
82void timer_timeout(void){
83 #ifdef DANISH_ENABLE
84 lshiftp = false;
85 rshiftp = false;
86 #endif
87 navesc = false;
88 timer_timeout_keymap();
89}
90
91__attribute__((weak))
92void timer_timeout_keymap(void){
93}
94
95bool process_record_user(uint16_t keycode, keyrecord_t *record) {
96 switch (keycode) {
97 case KC_LGUI:
98 case KC_RGUI:
99 if (record->event.pressed)
100 timer_timeout();
101 return true;
102 case CU_NAV:
103 if(record->event.pressed) {
104 navesc = true;
105 navesc_timer = timer_read();
106 layer_on(_NAV);
107 } else {
108 if (timer_elapsed(navesc_timer) < TAPPING_TERM && navesc) {
109 tap_code(KC_ESC);
110 }
111 layer_off(_NAV);
112 }
113 return false;
114
115 #ifdef DANISH_ENABLE
116 case CU_LSFT:
117 if(record->event.pressed) {
118 lshiftp = true;
119 lshift_timer = timer_read();
120 unregister_code(KC_LSFT);
121 register_code(KC_LSFT);
122 lshift = true;
123 } else {
124 if (timer_elapsed(lshift_timer) < TAPPING_TERM && lshiftp) {
125 register_code(KC_LSFT);
126 tap_code(KC_8);
127 unregister_code(KC_LSFT);
128 }
129 unreg_prev();
130 if (!rshift)
131 unregister_code(KC_LSFT);
132 lshift = false;
133 }
134 return false;
135 case CU_RSFT:
136 if(record->event.pressed) {
137 rshiftp = true;
138 rshift_timer = timer_read();
139 unregister_code(KC_LSFT);
140 register_code(KC_LSFT);
141 rshift = true;
142 } else {
143 if (timer_elapsed(rshift_timer) < TAPPING_TERM && rshiftp) {
144 register_code(KC_LSFT);
145 tap_code(KC_9);
146 unregister_code(KC_LSFT);
147 }
148 unreg_prev();
149 if (!lshift)
150 unregister_code(KC_LSFT);
151 rshift = false;
152 }
153 return false;
154 case CU_COMM:
155 SHIFT_NO(DK_COMM, KC_GRV)
156 case CU_DOT:
157 SHIFT_NORM(DK_DOT, KC_GRV)
158 case CU_SLSH:
159 SHIFT_ALL(DK_7, KC_MINS)
160 case CU_SCLN:
161 SHIFT_ALL(DK_COMM, DK_DOT)
162 case CU_QUOT:
163 SHIFT_NORM(DK_QUOT, DK_2)
164 case CU_2:
165 NORM_ALGR(DK_2, KC_NUHS)
166 case CU_4:
167 if (record->event.pressed) { \
168 timer_timeout(); \
169 if (lshift || rshift) { \
170 register_code(KC_LSFT); \
171 register_code(KC_ALGR); \
172 unregister_code(KC_3); \
173 tap_code(KC_3); \
174 unregister_code(KC_3); \
175 } else { \
176 unregister_code(KC_4); \
177 tap_code(KC_4); \
178 } \
179 unregister_code(KC_ALGR); \
180 unregister_code(KC_LSFT); \
181 } \
182 return false;
183 case CU_6:
184 SHIFT_NORM(DK_6, KC_RBRC)
185 case CU_7:
186 SHIFT_NORM(DK_7, DK_6)
187 case CU_8:
188 SHIFT_NORM(DK_8, KC_NUHS)
189 case CU_9:
190 SHIFT_NORM(DK_9, DK_8)
191 case CU_0:
192 SHIFT_NORM(DK_0, DK_9)
193 case CU_MINS:
194 SHIFT_NORM(KC_SLSH, KC_SLSH)
195 case CU_EQL:
196 SHIFT_SWITCH(DK_0, DK_PLUS)
197 case CU_BSPC:
198 SHIFT_NO(KC_BSPC, KC_DEL)
199 case CU_LBRC:
200 NORM_ALGRSHIFT(DK_8, DK_8)
201 case CU_RBRC:
202 NORM_ALGRSHIFT(DK_9, DK_9)
203 case CU_BSLS:
204 ALGR_SWITCH(DK_7, DK_I)
205 case KC_LCTL:
206 case KC_RCTL:
207 if(!record->event.pressed) {
208 timer_timeout();
209 unregister_code(KC_Z);
210 unregister_code(KC_Y);
211 }
212 return true;
213 #endif
214
215 default:
216 if(record->event.pressed) {
217 timer_timeout();
218
219 #ifdef DANISH_ENABLE
220 if (lshift || rshift)
221 register_code(KC_LSFT);
222 else
223 unregister_code(KC_LSFT);
224 #endif
225
226 }
227 return process_record_keymap(keycode, record);
228 }
229}
230
231__attribute__((weak))
232bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
233 return true;
234}
diff --git a/users/haervig/haervig.h b/users/haervig/haervig.h
new file mode 100644
index 000000000..e0d47e4cc
--- /dev/null
+++ b/users/haervig/haervig.h
@@ -0,0 +1,297 @@
1/*
2Copyright 2021 Jakob Hærvig <jakob.haervig@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "quantum.h"
19#include "keymap_danish.h"
20
21enum userspace_layers {
22 _DEADKEY = 14, // Change if more than 16 layers are required
23 _NAV
24};
25
26enum userspace_custom_keycodes {
27 //CU_GAME = SAFE_RANGE, // Toggle game mode on/off
28 CU_NAV = SAFE_RANGE, // NAV | ESC
29
30 #ifdef DANISH_ENABLE
31 CU_LSFT, // LSFT | (
32 CU_RSFT, // LSFT | )
33 CU_COMM, // , | <
34 CU_DOT, // . | >
35 CU_SLSH, // / | ?
36 CU_SCLN, // ; | :
37 CU_QUOT, // ' | "
38 CU_2, // 2 | @
39 CU_4, // 4 | $
40 CU_6, // 6 | ^
41 CU_7, // 7 | &
42 CU_8, // 8 | *
43 CU_9, // 9 | (
44 CU_0, // 0 | )
45 CU_MINS, // - | _
46 CU_EQL, // = | +
47 CU_BSPC, // backspace | delete
48 CU_LBRC, // [ | {
49 CU_RBRC, // ] | }
50 CU_BSLS, // \ | |
51 #endif
52
53 NEW_SAFE_RANGE // Use for keymap specific keycodes
54};
55
56#ifdef DANISH_ENABLE
57extern bool lshift;
58extern bool rshift;
59extern bool lshiftp;
60extern bool rshiftp;
61extern uint16_t lshift_timer;
62extern uint16_t rshift_timer;
63
64extern uint8_t prev_indx;
65extern uint16_t prev_kcs[6];
66void add_to_prev(uint16_t kc);
67void unreg_prev(void);
68
69extern bool esct;
70#endif
71
72extern bool navesc;
73extern uint16_t navesc_timer;
74
75void timer_timeout(void);
76
77void timer_timeout_keymap(void);
78
79bool process_record_keymap(uint16_t keycode, keyrecord_t *record);
80
81#define CTRLX LCTL(KC_X)
82#define CTRLC LCTL(KC_C)
83#define CTRLV LCTL(KC_V)
84
85#define ALTF4 LALT(KC_F4)
86
87#define GUIU LGUI(KC_UP)
88#define GUID LGUI(KC_DOWN)
89#define GUIL LGUI(KC_LEFT)
90#define GUIR RGUI(KC_RIGHT)
91
92#define CTLENT CTL_T(KC_ENT)
93
94#define EMOJI LWIN(KC_DOT)
95
96/*
97Templates for Keys, with custom shifted and non shifted Characters
98*/
99
100// Normal shift status
101#define SHIFT_NORM(kc1, kc2) \
102if (record->event.pressed) { \
103 timer_timeout(); \
104 if (lshift || rshift) { \
105 register_code(KC_LSFT); \
106 unregister_code(kc2); \
107 register_code(kc2); \
108 add_to_prev(kc2); \
109 } else { \
110 unregister_code(KC_LSFT); \
111 unregister_code(kc1); \
112 register_code(kc1); \
113 } \
114} else { \
115 unregister_code(kc1); \
116 unregister_code(kc2); \
117} \
118return false;
119
120// Inverted shift status
121#define SHIFT_SWITCH(kc1, kc2) \
122if (record->event.pressed) { \
123 timer_timeout(); \
124 if (lshift || rshift) { \
125 unregister_code(KC_LSFT); \
126 unregister_code(kc2); \
127 register_code(kc2); \
128 add_to_prev(kc2); \
129 } else { \
130 register_code(KC_LSFT); \
131 unregister_code(kc1); \
132 register_code(kc1); \
133 add_to_prev(kc1); \
134 } \
135} else { \
136 unregister_code(kc1); \
137 unregister_code(kc2); \
138 unreg_prev(); \
139 if (lshift || rshift) \
140 register_code(KC_LSFT); \
141 else \
142 unregister_code(KC_LSFT); \
143} \
144return false;
145
146// Always shifted
147#define SHIFT_ALL(kc1, kc2) \
148if (record->event.pressed) { \
149 timer_timeout(); \
150 register_code(KC_LSFT); \
151 if (lshift || rshift) { \
152 tap_code(kc2); \
153 add_to_prev(kc2); \
154 } else { \
155 tap_code(kc1); \
156 add_to_prev(kc1); \
157 } \
158} else { \
159 unregister_code(kc1); \
160 unregister_code(kc2); \
161 unreg_prev(); \
162 if (lshift || rshift) \
163 register_code(KC_LSFT); \
164 else \
165 unregister_code(KC_LSFT); \
166} \
167return false;
168
169// Never shifted
170#define SHIFT_NO(kc1, kc2) \
171if (record->event.pressed) { \
172 timer_timeout(); \
173 unregister_code(KC_LSFT); \
174 if (lshift || rshift) { \
175 tap_code(kc2); \
176 add_to_prev(kc2); \
177 } else { \
178 tap_code(kc1); \
179 } \
180} else { \
181 unregister_code(kc1); \
182 unregister_code(kc2); \
183 unreg_prev(); \
184 if (lshift || rshift) \
185 register_code(KC_LSFT); \
186 else \
187 unregister_code(KC_LSFT); \
188} \
189return false;
190
191// Norm AltGr
192#define NORM_ALGR(kc1, kc2) \
193if (record->event.pressed) { \
194 timer_timeout(); \
195 if (lshift || rshift) { \
196 register_code(KC_ALGR); \
197 unregister_code(KC_LSFT); \
198 tap_code(kc2); \
199 unregister_code(KC_ALGR); \
200 } else { \
201 unregister_code(KC_ALGR); \
202 unregister_code(KC_LSFT); \
203 tap_code(kc1); \
204 } \
205} else { \
206 unregister_code(kc1); \
207 unregister_code(kc2); \
208} \
209return false;
210
211// Norm AltGr shift
212#define NORM_ALGRSHIFT(kc1, kc2) \
213if (record->event.pressed) { \
214 timer_timeout(); \
215 register_code(KC_LSFT); \
216 register_code(KC_ALGR); \
217 if (lshift || rshift) { \
218 unregister_code(kc2); \
219 tap_code(kc2); \
220 unregister_code(KC_LSFT); \
221 } else { \
222 unregister_code(KC_LSFT); \
223 unregister_code(kc1); \
224 register_code(kc1); \
225 } \
226 unregister_code(KC_ALGR); \
227} else { \
228 unregister_code(kc1); \
229 unregister_code(kc2); \
230} \
231return false;
232
233// Inverted altgr status
234#define ALGR_SWITCH(kc1, kc2) \
235if (record->event.pressed) { \
236 timer_timeout(); \
237 register_code(KC_ALGR); \
238 if (lshift || rshift) { \
239 unregister_code(KC_LSFT); \
240 unregister_code(kc2); \
241 register_code(kc2); \
242 unregister_code(KC_ALGR); \
243 add_to_prev(kc2); \
244 } else { \
245 register_code(KC_LSFT); \
246 unregister_code(kc1); \
247 register_code(kc1); \
248 unregister_code(KC_ALGR); \
249 add_to_prev(kc1); \
250 } \
251} else { \
252 unregister_code(kc1); \
253 unregister_code(kc2); \
254 unreg_prev(); \
255 if (lshift || rshift) \
256 register_code(KC_LSFT); \
257 else \
258 unregister_code(KC_LSFT); \
259} \
260return false;
261
262// Always AltGr
263#define SHIFT_ALGR(kc1, kc2) \
264if (record->event.pressed) { \
265 timer_timeout(); \
266 unregister_code(KC_LSFT); \
267 register_code(KC_ALGR); \
268 if (lshift || rshift) { \
269 unregister_code(kc2); \
270 tap_code(kc2); \
271 register_code(KC_LSFT); \
272 } else { \
273 unregister_code(kc1); \
274 tap_code(kc1); \
275 } \
276 unregister_code(KC_ALGR); \
277} \
278return false;
279
280// Different keycode when Ctrl is pressed
281#define CTRL(kc1, kc2) \
282if(record->event.pressed) { \
283 timer_timeout(); \
284 if (lshift || rshift) \
285 register_code(KC_LSFT); \
286 else \
287 unregister_code(KC_LSFT); \
288 if (keyboard_report->mods & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))){ \
289 register_code(kc2); \
290 } else { \
291 register_code(kc1); \
292 } \
293} else { \
294 unregister_code(kc1); \
295 unregister_code(kc2); \
296} \
297return false;
diff --git a/users/haervig/readme.md b/users/haervig/readme.md
new file mode 100644
index 000000000..dc2ebbd13
--- /dev/null
+++ b/users/haervig/readme.md
@@ -0,0 +1,11 @@
1# haervig Userspace
2
3This userspace keeps my userdefined codes. I work on a ANSI keyboard on a Danish macOS system. I believe this code might be relevant for similar users. A big shout out to user spacebarracecar for the ideas on how to map keys, which served as the basis of this code.
4
5## US Layout Keys for Danish PCs
6
7By daily work involves a lot of coding. I find an ANSI layout superior and decided to buy a QMK keyboard. However, all PC's here in Denmark are set to input language Danish. Even though I could simply set input language language to US international, I find this inconvenient. I instead decided to map my keys so the ANSI keyboard would will function as expected when the OS inputn language is Danish.
8
9## More details
10
11Tracking the current state of the shift code is nessesary for it to work. User spacebarracecar has documented the idea thoroughly and should serve you as a starting point if you wish to implement this code. I modified the code to suit Danish input language. Additionally, a couple of functions were added to accomodate the altgr key. \ No newline at end of file
diff --git a/users/haervig/rules.mk b/users/haervig/rules.mk
new file mode 100644
index 000000000..e06647ff2
--- /dev/null
+++ b/users/haervig/rules.mk
@@ -0,0 +1,5 @@
1SRC += haervig.c
2
3ifeq ($(strip $(DANISH_ENABLE)), yes)
4 OPT_DEFS += -DDANISH_ENABLE
5endif