aboutsummaryrefslogtreecommitdiff
path: root/keyboards/converter/modelm_ssk/keymaps/default/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/converter/modelm_ssk/keymaps/default/keymap.c')
-rw-r--r--keyboards/converter/modelm_ssk/keymaps/default/keymap.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/keyboards/converter/modelm_ssk/keymaps/default/keymap.c b/keyboards/converter/modelm_ssk/keymaps/default/keymap.c
new file mode 100644
index 000000000..adf557b26
--- /dev/null
+++ b/keyboards/converter/modelm_ssk/keymaps/default/keymap.c
@@ -0,0 +1,114 @@
1/* Copyright 2019-2021 iw0rm3r, tiltowait
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#include QMK_KEYBOARD_H
17
18enum custom_layers {
19 _BASE,
20 _NUMPAD,
21};
22
23enum custom_keycodes {
24 NUM_SCRL = SAFE_RANGE
25};
26
27void toggle_numpad_layer(int set_state);
28
29const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
30 [_BASE] = LAYOUT( /* Base layer */
31 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, KC_PSCR, NUM_SCRL, KC_PAUS,
32 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,
33 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,
34 KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_NUHS, KC_ENT,
35 KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP,
36 KC_LCTL, KC_LALT, KC_SPC, KC_RALT, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
37 ),
38 [_NUMPAD] = LAYOUT( /* Numpad Layer */
39 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
40
41 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_KP_7, KC_KP_8, KC_KP_9, KC_TRNS, KC_KP_MINUS, KC_KP_PLUS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
42 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_KP_4, KC_KP_5, KC_KP_6, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
43 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_KP_1, KC_KP_2, KC_KP_3, KC_KP_ASTERISK, KC_TRNS, KC_TRNS, KC_TRNS,
44 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_KP_0, KC_TRNS, KC_KP_DOT, KC_KP_SLASH, KC_TRNS, KC_TRNS,
45 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
46 ),
47};
48
49bool process_record_user(uint16_t keycode, keyrecord_t *record) {
50 static uint16_t last_num_scroll = 0; /* For unregistering the proper key */
51
52 switch (keycode) {
53 case NUM_SCRL: /* Numlock / Scroll Lock */
54 if (record->event.pressed) {
55 if (get_mods() & MOD_MASK_SHIFT) {
56 /* Remove the shift modifiers */
57 uint8_t shift_mods = get_mods() & (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT));
58 del_mods(MOD_MASK_SHIFT);
59
60 last_num_scroll = KC_NUMLOCK;
61 register_code(last_num_scroll);
62 toggle_numpad_layer(-1);
63
64 /* Reset the shift modifiers */
65 set_mods(shift_mods);
66 } else {
67 last_num_scroll = KC_SCROLLLOCK;
68 register_code(last_num_scroll);
69 }
70 } else {
71 unregister_code(last_num_scroll);
72 }
73 break;
74 }
75 return true;
76}
77
78void toggle_numpad_layer(int set_state) {
79 static uint8_t numlock_enabled = 0;
80
81 /* set_state allows us to explicitly change the numlock state
82 rather than merely toggling it. */
83 if (set_state == -1) {
84 numlock_enabled = !numlock_enabled;
85 } else {
86 numlock_enabled = set_state;
87 }
88
89 if (numlock_enabled) {
90 layer_on(_NUMPAD);
91 }
92 else {
93 layer_off(_NUMPAD);
94 }
95}
96
97bool led_update_user(led_t led_state) {
98 /* In rare and unlikely conditions, it's possible for numlock
99 state to change externally from the keyboard. If this happens,
100 we want to match the new state.
101
102 On Windows and Linux, this means that the keyboard will technically
103 toggle the numpad layer twice.
104 */
105
106 static int8_t numlock_state = -1; /* Unknown state at default */
107
108 if (led_state.num_lock != numlock_state) {
109 numlock_state = led_state.num_lock;
110 toggle_numpad_layer(led_state.num_lock);
111 }
112 return true;
113}
114