keymap.c (6672B)
1 /* 2 Copyright 2012 Jun Wako <wakojun@gmail.com> 3 Copyright 2015 Jack Humbert 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #include QMK_KEYBOARD_H 20 21 #include "keymap_colemak.h" 22 #include "sendstring_colemak.h" 23 24 // Automatic Layer ID: 25 enum layer_names { 26 _QWERTY, // OS-side Colemak. Default. 27 _COLEMAK, // Keyboard-side Colemak. Portability, emergency. 28 _NUMERIC, 29 }; 30 31 // Shorthand: 32 #define LAYER_N MO(_NUMERIC) 33 #define LAYER_C TG(_COLEMAK) 34 #define PASTE LSFT(KC_INS) // Terminal-compatible paste. 35 #define SLQ RALT(KC_9) // Single left-side quotation mark (in Colemak). 36 #define SRQ RALT(KC_0) 37 #define EMDASH RALT(LSFT(KC_MINUS)) // Em dash character (in Colemak). 38 #define BK_LCTL CTL_T(KC_LEFT_BRACKET) 39 #define BK_RCTL RCTL_T(KC_RIGHT_BRACKET) 40 // TODO: Mod-tap ALT with a curvilinear brace. 41 // https://github.com/qmk/qmk_firmware/pull/2055 42 43 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 44 [_QWERTY] = LAYOUT( 45 KC_VOLD, KC_VOLU, CM_W, CM_F, CM_P, CM_G, CM_J, CM_L, CM_U, CM_Y, KC_MPLY, KC_MUTE, 46 KC_TAB, CM_Q, CM_R, CM_S, CM_T, CM_D, CM_H, CM_N, CM_E, CM_I, CM_SCLN, KC_BSLS, 47 KC_BSPC, CM_A, CM_X, CM_C, CM_V, CM_B, CM_K, CM_M, KC_COMM, KC_DOT, CM_O, KC_QUOT, 48 SLQ, CM_Z, KC_HOME, KC_PGUP, KC_END, KC_LEFT, KC_UP, KC_RGHT, KC_SLSH, SRQ, 49 KC_PGDN, KC_ENT, KC_SPC, KC_DEL, KC_ESC, KC_DOWN, 50 SC_LSPO, KC_LGUI, KC_MINS, KC_EQL, LAYER_N, SC_RSPC, 51 BK_LCTL, KC_LALT, KC_RALT, BK_RCTL 52 ), 53 54 [_COLEMAK] = LAYOUT( 55 _______, _______, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, _______, _______, 56 _______, KC_Q, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_SCLN, _______, 57 _______, KC_A, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, _______, _______, KC_O, _______, 58 _______, KC_Z, _______, _______, _______, _______, _______, _______, _______, _______, 59 _______, _______, _______, _______, _______, _______, 60 _______, _______, _______, _______, _______, _______, 61 _______, _______, _______, _______ 62 ), 63 64 [_NUMERIC] = LAYOUT( 65 LAYER_C, KC_INS, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, QK_BOOT, KC_WAKE, // * 66 KC_F12, KC_F1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_F10, KC_F11, 67 _______, KC_1, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_APP, KC_0, PASTE, 68 KC_GRV, KC_EXLM, MS_BTN1, MS_WHLU, MS_BTN2, MS_LEFT, MS_UP, MS_RGHT, KC_PSCR, UG_TOGG, 69 MS_WHLD, UG_NEXT, _______, MS_ACL1, MS_ACL2, MS_DOWN, 70 _______, _______, EMDASH, MS_ACL0, _______, _______, 71 _______, _______, _______, _______ 72 ) 73 }; 74 75 // *KC_WAKE: Used in place of KC_SLEP because X11 with i3 on prerelease 76 // Debian 10 was seeing duplicate keypress and release events for sleep 77 // (regardless of i3 binding), which ruined the function. 78 79 /* 80 The rest is all about lighting control. 81 The logic here represents a pretty poor compromise solution between the 82 following concerns: 83 84 - Feedback on active modifiers. 85 - Flexibility: Both sides of the keyboard are interchangeable. 86 - Regular QMK RBG lighting modes. Specifically, Knight and Xmas. 87 88 Currently, the last item suffers, because the first two seem to require 89 calling a function that implements the RGBLIGHT_SPLIT_SET_CHANGE_HSVS macro, 90 which most of the rgblight.c functions do not. In particular, functions that 91 target an individual LED do not do so correctly across the wire, so instead 92 we let HSV vary without ever targeting LEDs. 93 */ 94 95 // How long to wait between animation steps for "Knight" animation: 96 const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {255, 200, 100}; 97 98 bool _initialized = false; 99 bool _leds_dirty = false; 100 101 void modal_leds(void) { 102 uint8_t mods = get_mods(); 103 uint16_t hue = 355; // Rough match to printed case. 104 uint8_t saturation = 255; 105 uint8_t value = 0; 106 if (layer_state_is(_COLEMAK)) { hue -= 50; saturation -= 20; value += 20; } 107 if (layer_state_is(_NUMERIC)) { value += 30; } 108 if (mods & MOD_MASK_SHIFT) { saturation -= 20; value += 30; } 109 if (mods & MOD_MASK_ALT) { hue -= 100; saturation -= 20; value += 30; } 110 if (mods & MOD_MASK_CTRL) { hue -= 200; saturation -= 20; value += 30; } 111 // rgblight_sethsv_eeprom_helper is not a great API function but it does 112 // affect both halves of a split keyboard. 113 rgblight_sethsv_eeprom_helper(hue, saturation, value, false); 114 _leds_dirty = false; 115 } 116 117 void matrix_scan_user(void) { 118 if (_leds_dirty) { modal_leds(); } 119 } 120 121 bool process_record_user(uint16_t keycode, keyrecord_t *record) { 122 if (!_initialized) { 123 // Static lighting is amenable to customization. 124 rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); 125 _initialized = true; 126 } 127 if (keycode == KC_WAKE) { 128 // Turn the lights off before going to sleep. 129 rgblight_sethsv_eeprom_helper(0, 0, 0, false); 130 } else { 131 _leds_dirty = true; 132 } 133 return true; 134 }