accented_keys.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Copyright 2022 Eric Gebhart <e.a.gebhart@gmail.com>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include USERSPACE_H
  15. #include "accented_keys.h"
  16. #include <stdint.h>
  17. #include <stdbool.h>
  18. static inline void tap_accented_letter(uint16_t letter, uint16_t dead_key) {
  19. uint8_t mod_state = get_mods();
  20. uint8_t oneshot_mod_state = get_oneshot_mods();
  21. del_mods(MOD_MASK_SHIFT);
  22. del_oneshot_mods(MOD_MASK_SHIFT);
  23. tap_code16(dead_key);
  24. set_mods(mod_state);
  25. set_oneshot_mods(oneshot_mod_state);
  26. tap_code(letter);
  27. }
  28. #undef ACCENTED
  29. #define ACCENTED(KC, K1, DEAD_KEY) \
  30. case KC: \
  31. if (record->event.pressed) { \
  32. tap_accented_letter(K1, DEAD_KEY); \
  33. } \
  34. return false;
  35. bool process_accent_keys(uint16_t keycode, keyrecord_t* record) {
  36. switch(keycode){
  37. #ifdef ACCENTED_KEYS_ENABLE
  38. #include "accented_keys.def"
  39. #endif
  40. }
  41. return true;
  42. }