~ruther/qmk_firmware

ref: 85fa65bc0303b5ddc28877ccb6b95cedf957bc6d qmk_firmware/users/rutherther/features/cz_accent.c -rw-r--r-- 2.9 KiB
85fa65bc — Rutherther feat: remove need for plain layer for cz_accent by disabling tap-hold keys 8 months ago
                                                                                
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "cz_accent.h"
#include "keymap_czech.h"

const uint16_t cz_acute_keycodes[] = {
  KC_A, KC_E, KC_I, KC_O, KC_U, KC_Y
};
const uint8_t NUM_ACUTE_KEYCODES = sizeof(cz_acute_keycodes) / sizeof(uint16_t);

const uint16_t cz_caret_keycodes[] = {
  KC_Z, KC_S, KC_C, KC_R, KC_E, KC_D, KC_T, KC_N, KC_U
};
const uint8_t NUM_CARET_KEYCODES = sizeof(cz_caret_keycodes) / sizeof(uint16_t);

const uint16_t cz_scln_char = KC_U;

bool process_prefixed_accent(uint16_t keycode, keyrecord_t* record, const uint16_t accent_prefix, const uint16_t *filters, const uint8_t filters_size) {
  if (!record->event.pressed) {
    return true;
  }

  uint16_t bkeycode = QK_MODS_GET_BASIC_KEYCODE(keycode);

  bool found = false;
  for (int i = 0; i < filters_size; i++) {
    if (bkeycode == filters[i]) {
      found = true;
      break;
    }
  }

  if (!found) {
    return true;
  }

  const uint8_t mods = get_mods() | get_weak_mods() | get_oneshot_mods();

  clear_mods();
  clear_weak_mods();
  clear_oneshot_mods();

  tap_code16(accent_prefix);
  set_mods(mods);

  tap_code16(bkeycode);

  return false;
}

bool process_czech_acute(uint16_t keycode, keyrecord_t* record,
                         uint16_t acute_keycode, int8_t plain_layer) {
  static bool cz_send_acuted = false;

  if (keycode == acute_keycode) {
    cz_send_acuted = record->event.pressed;

    // TODO: make sure that this works also for stuff like tap-hold
    // without this plain layer hack.
    // The problem is that here we don't know if it's tap or hold, at
    // least I think. Maybe different function will have to be overriden
    // somehow.
    if (record->event.pressed) {
      /* layer_move(plain_layer); */
    } else {
      /* layer_move(0); */
    }

    return false;
  }

  if (cz_send_acuted) {
    return process_prefixed_accent(keycode, record, QK_CZ_ACUTE, cz_acute_keycodes, NUM_ACUTE_KEYCODES);
  }

  return true;
}

bool process_czech_caret(uint16_t keycode, keyrecord_t* record,
                         uint16_t caret_keycode, int8_t plain_layer) {
  static bool cz_send_careted = false;

  if (keycode == caret_keycode) {
    cz_send_careted = record->event.pressed;

    if (record->event.pressed) {
      /* layer_move(plain_layer); */
    } else {
      /* layer_move(0); */
    }
    return false;
  }

  if (cz_send_careted) {
    if (QK_MODS_GET_BASIC_KEYCODE(keycode) == cz_scln_char)
      return process_prefixed_accent(
                                     keycode,
                                     record,
                                     QK_CZ_SCLN,
                                     cz_caret_keycodes,
                                     NUM_CARET_KEYCODES);
    else
      return process_prefixed_accent(
                                     keycode,
                                     record,
                                     QK_CZ_CARET,
                                     cz_caret_keycodes,
                                     NUM_CARET_KEYCODES);
  }

  return true;
}
Do not follow this link