keymap.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* Copyright 2017 Wunder
  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. #include "keycodes.h"
  18. #include "leds.h"
  19. // Implement Super-alt↯tab
  20. // See https://docs.qmk.fm/#/feature_macros?id=super-alt↯tab
  21. bool is_alt_tab_active = false;
  22. uint16_t alt_tab_timer = 0;
  23. bool is_screen_lock_triggered = false;
  24. uint16_t screen_lock_timer = 0;
  25. // Defining all the custom keycodes.
  26. enum custom_keycodes {
  27. ALT_TAB = SAFE_RANGE,
  28. KC_00 ,
  29. SLC_ROW,
  30. SLC_ALL,
  31. SLC_WRD
  32. };
  33. enum combo_events {
  34. SCR_LCK
  35. };
  36. const uint16_t PROGMEM lock_combo[] = {KC_J, KC_K, KC_L, KC_SCLN, COMBO_END};
  37. combo_t key_combos[COMBO_COUNT] = {COMBO(lock_combo, SCR_LCK)};
  38. // Layer shorthand
  39. #define _QW 0
  40. #define _FN 1
  41. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  42. /* QWERTY
  43. * ┌──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┐
  44. * │` Esc │ 1 │ 2 │ 3 │ 4 │ 5 │ Del │ 6 │ 7 │ 8 │ 9 │ 0 │ - │ = │PrtScn│
  45. * ├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
  46. * │ Tab │ Q │ W │ E │ R │ T │ Bksp │ Y │ U │ I │ O │ P │ [ │ ] │ Home │
  47. * ├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
  48. * │ FN │ A │ S │ D │ F │ G │Enter │ H │ J │ K │ L │ ; │ ' │ # │ End │
  49. * ├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
  50. * │ Shft │ Z │ X │ C │ V │ B │ALTTAB│ N │ M │ , │ . │ / │ Shft │ FN │ PgUp │
  51. * ├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
  52. * │ Ctrl │ Gui │ Alt │ Back │ Frwd │Space │ App │Space │ Left │ Up │ Down │ Right│ Alt │ Ctrl │ PgDn │
  53. * └──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┘
  54. */
  55. [_QW] = LAYOUT_ortho_5x15( /* QWERTY */
  56. KC_GESC, KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_DEL , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_MINUS, KC_EQUAL, KC_PSCR,
  57. KC_TAB , KC_Q , KC_W , KC_E , KC_R , KC_T , KC_BSPC, KC_Y , KC_U , KC_I , KC_O , KC_P , KC_LBRC , KC_RBRC , KC_HOME,
  58. MO(_FN), KC_A , KC_S , KC_D , KC_F , KC_G , KC_ENT , KC_H , KC_J , KC_K , KC_L , KC_SCLN , KC_QUOT , KC_NUHS , KC_END ,
  59. KC_LSFT, KC_Z , KC_X , KC_C , KC_V , KC_B , ALT_TAB, KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH , KC_RSFT , MO(_FN) , KC_PGUP,
  60. KC_LCTL, KC_LGUI, KC_LALT, KC_WBAK, KC_WFWD, KC_SPC, KC_APP , KC_SPC, KC_LEFT, KC_UP , KC_DOWN, KC_RIGHT, KC_RALT , KC_RCTL , KC_PGDN
  61. ),
  62. /* FUNCTION
  63. * NB :  My OS  layout (Bépo) don't have direct access to numbers, so that's why I use « LSFT » mod for the keypad.
  64. * You need to remove LSFT(KC) for using this layout with Qwerty. Also the use of KC_8, 7, and V are some specific Bépo
  65. * things.
  66. * ┌──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┐
  67. * │Alt F4│ F1 │ F2 │ F3 │ F4 │ F5 │BL Tog│ F6 │ F7 │ F8 │ F9 │ F10 │ F11 │ F12 │ # Lk │
  68. * ├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
  69. * │ │ │SltAll│SltRow│SltRow│ Brt+ │BL Stp│ │ │ KP 7 │ KP 8 │ KP 9 │ 8 │ │ │
  70. * ├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
  71. * │ │ │ Cut │ Copy │Paste │ Brt- │BL Brt│ │ │ KP 4 │ KP 5 │ KP 6 │ 7 │ │Reset │
  72. * ├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
  73. * │ │ │ Mute │ Vol- │ Vol+ │ Play │Ld Tog│ │ │ KP 1 │ KP 2 │ KP 3 │Enter │ │ │
  74. * ├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
  75. * │ │ │ │ │ │ │Ld M+ │ │ │ KP 0 │KC 00 │ V │ │ │ │
  76. * └──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┘
  77. */
  78. [_FN] = LAYOUT_ortho_5x15( /* FUNCTION */
  79. LALT(KC_F4), KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , BL_TOGG, KC_F6 , KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 , KC_F12 , KC_NLCK,
  80. _______ , _______, SLC_ALL , SLC_ROW , SLC_WRD , KC_BRIU, BL_STEP, _______, _______, LSFT(KC_7) , LSFT(KC_8) , LSFT(KC_9), KC_8 , _______, _______,
  81. _______ , _______, LSFT(KC_DEL), LCTL(KC_INS), LSFT(KC_INS), KC_BRID, BL_BRTG, _______, _______, LSFT(KC_4) , LSFT(KC_5) , LSFT(KC_6), KC_7 , _______, RESET ,
  82. _______ , _______, KC_MUTE , KC_VOLD , KC_VOLU , KC_MPLY, RGB_TOG, _______, _______, LSFT(KC_1) , LSFT(KC_2) , LSFT(KC_3), KC_ENT , _______, _______,
  83. _______ , _______, _______ , _______ , _______ , _______, RGB_MOD, _______, _______, LSFT(KC_0) , KC_00 , KC_V , _______ , _______, _______
  84. )
  85. };
  86. // Processing all the key pressed.
  87. // Alt+tab.
  88. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  89. // Depending keycodes…
  90. switch (keycode) { // This will do most of the grunt work with the keycodes.
  91. case ALT_TAB:
  92. if (record->event.pressed) {
  93. if (!is_alt_tab_active) {
  94. is_alt_tab_active = true;
  95. gp100_led_on();
  96. register_code(KC_LALT);
  97. }
  98. alt_tab_timer = timer_read();
  99. register_code(KC_TAB);
  100. } else {
  101. unregister_code(KC_TAB);
  102. }
  103. break;
  104. case KC_00:
  105. insert_00(record);
  106. break;
  107. case SLC_ALL:
  108. select_all(record);
  109. break;
  110. case SLC_ROW:
  111. select_row(record);
  112. break;
  113. case SLC_WRD:
  114. select_word(record);
  115. break;
  116. }
  117. return true;
  118. }
  119. void process_combo_event(uint16_t combo_index, bool pressed) {
  120. switch(combo_index) {
  121. case SCR_LCK:
  122. if (pressed) {
  123. /*if (!is_screen_lock_triggered) {*/
  124. is_screen_lock_triggered = true;
  125. gp103_led_on();
  126. windows_lock();
  127. /*}*/
  128. screen_lock_timer = timer_read();
  129. }
  130. break;
  131. }
  132. }
  133. void matrix_scan_user(void) { // The very important timer.
  134. if (is_alt_tab_active) {
  135. if (timer_elapsed(alt_tab_timer) > 750) {
  136. unregister_code(KC_LALT);
  137. gp100_led_off();
  138. is_alt_tab_active = false;
  139. }
  140. }
  141. if (is_screen_lock_triggered) {
  142. if (timer_elapsed(screen_lock_timer) > 750) {
  143. gp103_led_off();
  144. is_screen_lock_triggered = false;
  145. }
  146. }
  147. }
  148. void led_set_user(uint8_t usb_led) {
  149. if (IS_LAYER_ON(_FN)) {
  150. capslock_led_on();
  151. } else {
  152. capslock_led_off();
  153. }
  154. }
  155. void keyboard_post_init_user (void) {
  156. setDefaultDisplay();
  157. }
  158. layer_state_t layer_state_set_user(layer_state_t state) {
  159. switch (get_highest_layer(state)) {
  160. case _FN:
  161. setFNDisplay();
  162. break;
  163. default: // for any other layers, or the default layer
  164. setDefaultDisplay();
  165. break;
  166. }
  167. return state;
  168. }