locales.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Copyright 2018-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 "ericgebhart.h"
  15. #include "locales.h"
  16. bool process_locales(uint16_t keycode, keyrecord_t *record) {
  17. switch (keycode) {
  18. case KC_SET_BASE:
  19. // set the current default base to eeprom.
  20. if (record->event.pressed) {
  21. set_single_persistent_default_layer(get_highest_layer(default_layer_state));
  22. }
  23. break;
  24. // choose a different set of default layers based on locales.
  25. case KC_NEXT_LOCALE:
  26. // choose another locale and set the default base to the first layer.
  27. if (!record->event.pressed) {
  28. if (current_locale + 1 < LOCALES_END){
  29. current_locale++;
  30. }else{
  31. current_locale = 0;
  32. }
  33. default_layer_set(1UL << LOCALE_LAYER_RANGE[0]);
  34. }
  35. return false;
  36. break;
  37. // choose a different base layer based on locales.
  38. // simply iterates over the list and sets the default layer.
  39. case KC_NEXT_BASE_LAYER:
  40. if (!record->event.pressed) {
  41. uint8_t current = get_highest_layer(default_layer_state);
  42. if (current < LOCALE_LAYER_RANGE[1]){
  43. current++;
  44. }else{
  45. current = LOCALE_LAYER_RANGE[0];
  46. }
  47. default_layer_set(1UL << current);
  48. }
  49. return false;
  50. break;
  51. }
  52. return true;
  53. }