keymap.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include QMK_KEYBOARD_H
  2. #define _BASE 0 // Base layer
  3. #define _SYSTEM 1 // System actions
  4. #define _VOLUME 2 // Volume actions
  5. #define SUPER_ALT_F4_TIMER 300 // Timeout on the super alt-f4 key
  6. /*
  7. The idea of this is pretty simple: base layer has four action, two of which (the outermost)
  8. are regular keystrokes on tap, and a momentary layer switch on hold, sending you to layers 1 and 2.
  9. The other bit of customization here is the 'Super Alt F4' which does Alt-F4, and then Enter if tapped
  10. again SUPER_ALT_F4_TIMER miliseconds after. This lets you Alt-F4 applications, and finally quickly
  11. double-tap it to Alt-F4+Enter to shut down the PC.
  12. */
  13. bool is_alt_f4_active = false;
  14. uint16_t alt_f4_timer = 0;
  15. enum custom_keycodes { // Make sure have the awesome keycode ready
  16. SUPER_ALT_F4 = SAFE_RANGE,
  17. };
  18. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  19. // 0: Base Layer
  20. [_BASE] = LAYOUT_all(LT(_SYSTEM, KC_F5), C(G(KC_LEFT)), C(G(KC_RIGHT)), LT(_VOLUME, KC_F7)),
  21. // 1: System actions
  22. [_SYSTEM] = LAYOUT_all(_______, SUPER_ALT_F4, G(KC_D), G(KC_L)),
  23. // 2: Volume actions
  24. [_VOLUME] = LAYOUT_all(KC_MEDIA_NEXT_TRACK, KC_AUDIO_VOL_DOWN, KC_AUDIO_VOL_UP, _______),
  25. };
  26. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  27. switch (keycode) { // This will do most of the grunt work with the keycodes.
  28. case SUPER_ALT_F4:
  29. if (record->event.pressed) {
  30. if (!is_alt_f4_active) {
  31. is_alt_f4_active = true;
  32. tap_code16(LALT(KC_F4)); // Alt-F4
  33. } else {
  34. tap_code(KC_ENTER); // Tap enter
  35. }
  36. }
  37. alt_f4_timer = timer_read();
  38. break;
  39. }
  40. return true;
  41. }
  42. void matrix_scan_user(void) {
  43. if (is_alt_f4_active && timer_elapsed(alt_f4_timer) > SUPER_ALT_F4_TIMER) {
  44. is_alt_f4_active = false;
  45. }
  46. };