aboutsummaryrefslogtreecommitdiff
path: root/users/konstantin
diff options
context:
space:
mode:
authorKonstantin Đorđević <vomindoraan@gmail.com>2019-01-14 18:09:47 +0100
committerMechMerlin <30334081+mechmerlin@users.noreply.github.com>2019-01-14 09:09:47 -0800
commit9105bf2434c54c40362173e1734a24485cfbe702 (patch)
tree5a31a50767ad464b5d3d75341f6f0d9686a116f4 /users/konstantin
parentee96b7a89dd2de78b9372d3b8ce899757e3190c4 (diff)
downloadqmk_firmware-9105bf2434c54c40362173e1734a24485cfbe702.tar.gz
qmk_firmware-9105bf2434c54c40362173e1734a24485cfbe702.zip
Add personal userspace, update keymaps (#4845)
* Add kbd6x:konstantin keymap * Prevent tap dance from sending LShift as a weak mod in KBD6X * Move config.h and rules.mk definitions into userspace * Add UC_WIN to UNICODE_SELECTED_MODES * Temporarily use Bootmagic until Command is fixed * Move common behavior from keyboards into userspace * Update kbd6x:konstantin keymap and userspace * Make a RCTRL layer in kbd6x:konstantin * Make KC_ESC turn off layers * KC_ESC turns L_FN off only if it was locked on * Add missing record->event.pressed checks * Move numpad toggling logic into function * Disable Bootmagic, enable KEYBOARD_SHARED_EP with Command
Diffstat (limited to 'users/konstantin')
-rw-r--r--users/konstantin/config.h24
-rw-r--r--users/konstantin/konstantin.c77
-rw-r--r--users/konstantin/konstantin.h50
-rw-r--r--users/konstantin/rules.mk16
-rw-r--r--users/konstantin/tap_dance.c93
-rw-r--r--users/konstantin/tap_dance.h25
-rw-r--r--users/konstantin/unicode.h11
7 files changed, 296 insertions, 0 deletions
diff --git a/users/konstantin/config.h b/users/konstantin/config.h
new file mode 100644
index 000000000..d03333f05
--- /dev/null
+++ b/users/konstantin/config.h
@@ -0,0 +1,24 @@
1#pragma once
2
3#define FORCE_NKRO
4
5#define MAGIC_KEY_LAYER0_ALT1 BSLS
6#define MAGIC_KEY_BOOTLOADER ESC
7
8#define MOUSEKEY_DELAY 50
9#define MOUSEKEY_INTERVAL 15
10#define MOUSEKEY_MAX_SPEED 4
11#define MOUSEKEY_TIME_TO_MAX 50
12#define MOUSEKEY_WHEEL_MAX_SPEED 1
13#define MOUSEKEY_WHEEL_TIME_TO_MAX 50
14
15#define NO_ACTION_FUNCTION
16#define NO_ACTION_MACRO
17
18#define PERMISSIVE_HOLD
19#define TAPPING_TERM 200
20#define TAPPING_TOGGLE 2
21
22#define UNICODE_CYCLE_PERSIST false
23#define UNICODE_SELECTED_MODES UC_WINC, UC_WIN, UC_LNX
24#define UNICODE_WINC_KEY KC_RGUI
diff --git a/users/konstantin/konstantin.c b/users/konstantin/konstantin.c
new file mode 100644
index 000000000..977111c1f
--- /dev/null
+++ b/users/konstantin/konstantin.c
@@ -0,0 +1,77 @@
1#include "konstantin.h"
2
3#ifdef LAYER_NUMPAD
4static void toggle_numpad(void) {
5 layer_invert(L_NUMPAD);
6 bool num_lock = host_keyboard_leds() & 1<<USB_LED_NUM_LOCK;
7 if (num_lock != (bool)IS_LAYER_ON(L_NUMPAD)) {
8 tap_code(KC_NLCK); // Toggle Num Lock to match layer state
9 }
10}
11#endif
12
13__attribute__((weak))
14bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
15 return true;
16}
17
18bool process_record_user(uint16_t keycode, keyrecord_t *record) {
19 if (!process_record_keymap(keycode, record)) {
20 return false;
21 }
22
23 switch (keycode) {
24 case CLEAR:
25 if (record->event.pressed) {
26 SEND_STRING(SS_LCTRL("a") SS_TAP(X_DELETE));
27 }
28 return false;
29
30#ifdef LAYER_FN
31 static bool fn_lock;
32
33 case FN_FNLK:
34 if (record->event.pressed && record->tap.count == TAPPING_TOGGLE) {
35 fn_lock = !IS_LAYER_ON(L_FN); // Fn layer will be toggled after this
36 }
37 return true;
38#endif
39
40#ifdef LAYER_NUMPAD
41 case NUMPAD:
42 if (record->event.pressed) {
43 toggle_numpad();
44 }
45 return false;
46#endif
47
48 case KC_ESC:
49 if (record->event.pressed) {
50#ifdef LAYER_NUMPAD
51 if (IS_LAYER_ON(L_NUMPAD)) {
52 toggle_numpad();
53 return false;
54 }
55#endif
56#ifdef LAYER_FN
57 if (IS_LAYER_ON(L_FN) && fn_lock) {
58 layer_off(L_FN);
59 return fn_lock = false;
60 }
61#endif
62 }
63 return true;
64
65 default:
66 return true;
67 }
68}
69
70__attribute__((weak))
71uint32_t layer_state_set_keymap(uint32_t state) {
72 return state;
73}
74
75uint32_t layer_state_set_user(uint32_t state) {
76 return layer_state_set_keymap(state);
77}
diff --git a/users/konstantin/konstantin.h b/users/konstantin/konstantin.h
new file mode 100644
index 000000000..06081496b
--- /dev/null
+++ b/users/konstantin/konstantin.h
@@ -0,0 +1,50 @@
1#pragma once
2
3#include "quantum.h"
4#ifdef TAP_DANCE_ENABLE
5 #include "tap_dance.h"
6#endif
7#ifdef UNICODE_ENABLE
8 #include "unicode.h"
9#endif
10
11#ifdef LAYER_FN
12 #define FN MO(L_FN)
13 #define FN_CAPS LT(L_FN, KC_CAPS)
14 #define FN_FNLK TT(L_FN)
15#endif
16
17#define MV_UP LCTL(KC_UP)
18#define MV_DOWN LCTL(KC_DOWN)
19#define MV_LEFT LCTL(KC_LEFT)
20#define MV_RGHT LCTL(KC_RGHT)
21#define TOP LCTL(KC_HOME)
22#define BOTTOM LCTL(KC_END)
23#define PRV_TAB LCTL(KC_PGUP)
24#define NXT_TAB LCTL(KC_PGDN)
25
26#define LCT_CPS LCTL_T(KC_CAPS)
27
28enum keycodes_user {
29 CLEAR = SAFE_RANGE,
30#ifdef LAYER_NUMPAD
31 NUMPAD,
32#endif
33
34 RANGE_KEYMAP,
35};
36
37enum layers_user {
38 L_BASE,
39#ifdef LAYER_FN
40 L_FN,
41#endif
42#ifdef LAYER_NUMPAD
43 L_NUMPAD,
44#endif
45
46 L_RANGE_KEYMAP,
47};
48
49bool process_record_keymap(uint16_t keycode, keyrecord_t *record);
50uint32_t layer_state_set_keymap(uint32_t state);
diff --git a/users/konstantin/rules.mk b/users/konstantin/rules.mk
new file mode 100644
index 000000000..7f25a8107
--- /dev/null
+++ b/users/konstantin/rules.mk
@@ -0,0 +1,16 @@
1BOOTMAGIC_ENABLE = no
2COMMAND_ENABLE = yes
3CONSOLE_ENABLE = yes
4EXTRAKEY_ENABLE = yes
5KEYBOARD_SHARED_EP = yes # TODO: Disable once Command is fixed
6MOUSEKEY_ENABLE = yes
7NKRO_ENABLE = yes
8TAP_DANCE_ENABLE = yes
9UNICODE_ENABLE = yes
10
11SRC += konstantin.c
12ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
13 SRC += tap_dance.c
14endif
15
16EXTRAFLAGS += -flto
diff --git a/users/konstantin/tap_dance.c b/users/konstantin/tap_dance.c
new file mode 100644
index 000000000..b13f33c02
--- /dev/null
+++ b/users/konstantin/tap_dance.c
@@ -0,0 +1,93 @@
1#include "tap_dance.h"
2#include "konstantin.h"
3
4#define ACTION_TAP_DANCE_DOUBLE_MODS(mod1, mod2) { \
5 .fn = { td_double_mods_each, NULL, td_double_mods_reset }, \
6 .user_data = &(qk_tap_dance_pair_t){ mod1, mod2 }, \
7 }
8
9void td_double_mods_each(qk_tap_dance_state_t *state, void *user_data) {
10 qk_tap_dance_pair_t *mods = (qk_tap_dance_pair_t *)user_data;
11 // Single tap → mod1, double tap → mod2, triple tap etc. → mod1+mod2
12 if (state->count == 1 || state->count == 3) {
13 register_code(mods->kc1);
14 } else if (state->count == 2) {
15 unregister_code(mods->kc1);
16 register_code(mods->kc2);
17 }
18 // Prevent tap dance from sending kc1 and kc2 as weak mods
19 state->weak_mods &= ~(MOD_BIT(mods->kc1) | MOD_BIT(mods->kc2));
20}
21
22void td_double_mods_reset(qk_tap_dance_state_t *state, void *user_data) {
23 qk_tap_dance_pair_t *mods = (qk_tap_dance_pair_t *)user_data;
24 if (state->count == 1 || state->count >= 3) {
25 unregister_code(mods->kc1);
26 }
27 if (state->count >= 2) {
28 unregister_code(mods->kc2);
29 }
30}
31
32struct {
33 bool fn_on; // Layer state when tap dance started
34 bool started;
35} td_fn_rctrl_data;
36
37void td_fn_rctrl_each(qk_tap_dance_state_t *state, void *user_data) {
38 if (!td_fn_rctrl_data.started) {
39 td_fn_rctrl_data.fn_on = IS_LAYER_ON(L_FN);
40 td_fn_rctrl_data.started = true;
41 }
42 // Single tap → Fn, double tap → RCtrl, triple tap etc. → Fn+RCtrl
43 if (state->count == 1 || state->count == 3) {
44 layer_on(L_FN);
45 } else if (state->count == 2) {
46 if (!td_fn_rctrl_data.fn_on) {
47 layer_off(L_FN);
48 }
49 register_code(KC_RCTL);
50 }
51}
52
53void td_fn_rctrl_reset(qk_tap_dance_state_t *state, void *user_data) {
54 if ((state->count == 1 || state->count >= 3) && !td_fn_rctrl_data.fn_on) {
55 layer_off(L_FN);
56 }
57 if (state->count >= 2) {
58 unregister_code(KC_RCTL);
59 }
60 td_fn_rctrl_data.started = false;
61}
62
63void td_lsft_fn_each(qk_tap_dance_state_t *state, void *user_data) {
64 // Single tap → LShift, double tap → Fn, triple tap etc. → Fn+LShift
65 if (state->count == 1 || state->count == 3) {
66 register_code(KC_LSFT);
67 } else if (state->count == 2) {
68 unregister_code(KC_LSFT);
69 // Prevent tap dance from sending LShift as a weak mod
70 state->weak_mods &= ~MOD_BIT(KC_LSFT);
71 layer_on(L_FN);
72 }
73}
74
75void td_lsft_fn_reset(qk_tap_dance_state_t *state, void *user_data) {
76 if (state->count == 1 || state->count >= 3) {
77 unregister_code(KC_LSFT);
78 }
79 if (state->count >= 2) {
80 layer_off(L_FN);
81 }
82}
83
84qk_tap_dance_action_t tap_dance_actions[] = {
85 [TD_DESKTOP] = ACTION_TAP_DANCE_DOUBLE(LCTL(LGUI(KC_D)), LCTL(LGUI(KC_F4))), // Add/close virtual desktop
86
87 [TD_RAL_LAL] = ACTION_TAP_DANCE_DOUBLE_MODS(KC_RALT, KC_LALT),
88 [TD_RAL_RGU] = ACTION_TAP_DANCE_DOUBLE_MODS(KC_RALT, KC_RGUI),
89 [TD_RCT_RSF] = ACTION_TAP_DANCE_DOUBLE_MODS(KC_RCTL, KC_RSFT),
90
91 [TD_FN_RCTL] = ACTION_TAP_DANCE_FN_ADVANCED(td_fn_rctrl_each, NULL, td_fn_rctrl_reset),
92 [TD_LSFT_FN] = ACTION_TAP_DANCE_FN_ADVANCED(td_lsft_fn_each, NULL, td_lsft_fn_reset),
93};
diff --git a/users/konstantin/tap_dance.h b/users/konstantin/tap_dance.h
new file mode 100644
index 000000000..922a63514
--- /dev/null
+++ b/users/konstantin/tap_dance.h
@@ -0,0 +1,25 @@
1#pragma once
2
3#include "quantum.h"
4
5#define DESKTOP TD(TD_DESKTOP)
6#define DSKTP_L LCTL(LGUI(KC_LEFT))
7#define DSKTP_R LCTL(LGUI(KC_RGHT))
8
9#define RAL_LAL TD(TD_RAL_LAL)
10#define RAL_RGU TD(TD_RAL_RGU)
11#define RCT_RSF TD(TD_RCT_RSF)
12
13#define FN_RCTL TD(TD_FN_RCTL)
14#define LSFT_FN TD(TD_LSFT_FN)
15
16enum tap_dance {
17 TD_DESKTOP,
18
19 TD_RAL_LAL,
20 TD_RAL_RGU,
21 TD_RCT_RSF,
22
23 TD_FN_RCTL,
24 TD_LSFT_FN,
25};
diff --git a/users/konstantin/unicode.h b/users/konstantin/unicode.h
new file mode 100644
index 000000000..09af7e1c7
--- /dev/null
+++ b/users/konstantin/unicode.h
@@ -0,0 +1,11 @@
1#pragma once
2
3#include "quantum.h"
4
5#define COMMA UC(0x002C)
6#define L_PAREN UC(0x0028)
7#define R_PAREN UC(0x0029)
8#define EQUALS UC(0x003D)
9#define TIMES UC(0x00D7)
10#define DIVIDE UC(0x00F7)
11#define MINUS UC(0x2212)