aboutsummaryrefslogtreecommitdiff
path: root/qmk/keyboards/sofle_choc/keymaps/custom/keycodes.c
blob: 76b6b9146a2c32c6ad767b28aae8118c075ab8ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include QMK_KEYBOARD_H
#include "keycodes.h"

bool keycodes_process_record(uint16_t keycode, keyrecord_t *record) {

  static bool kc_lgui = false;
  static bool kc_ralt = false;

  switch (keycode) {
    case KC_ESC:
      /* By default, send the ESC code to the host.
       * This code will be muted if there is a specific state to remove firts.

       * The keys L_GUI and R_ALT activate a layer automatically, but can be
       * used in a combo with the ESC key, I do not want to ignore the key press
       * in this case.
       */
      bool handle_key = true;
      if (get_oneshot_mods()) {
        clear_oneshot_mods();
        handle_key = false;
      }
      if (   (! kc_ralt) \
          && (! kc_lgui) \
          && (layer_state_is(LAYER_KEYPAD) || layer_state_is(LAYER_ARROW) )) {
          // Remove the layer the key is released.
          layer_clear();
          handle_key = false;
      }
      if (host_keyboard_led_state().caps_lock) {
          tap_code16(KC_CAPS_LOCK);
          handle_key = false;
      }
      return handle_key;
    case AL_ENT:
      if (!record->event.pressed \
          && (! kc_lgui) \
          && (layer_state_is(LAYER_KEYPAD) || layer_state_is(LAYER_ARROW) )) {
          // Remove the layer the key is released.
          layer_clear();
      }
      return true;

    // Override the key APP when hold into AltGR + Layer 1 when hold
    case KEY_APP:
      if (!record->tap.count && record->event.pressed) {
          kc_ralt = record->event.pressed;
          register_code(KC_RIGHT_ALT);
          layer_on(LAYER_ARROW);
          return false;
      } else if (!record->tap.count && !record->event.pressed) {
          kc_ralt = record->event.pressed;
          unregister_code(KC_RIGHT_ALT);
          layer_off(LAYER_ARROW);
          return false;
      }
      return true;

    case KC_LGUI:
        kc_lgui = record->event.pressed;
        if (record->event.pressed) {
          layer_on(LAYER_ARROW);
        }
        else {
          layer_off(LAYER_ARROW);
        }
        return true;

    default:
      return true; // Process all other keycodes normally
  }
}