You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.4 KiB

  1. #include QMK_KEYBOARD_H
  2. /*
  3. Define a keycode KF_LAYO to rotate between available default layers.
  4. Shift+KF_LAYO makes the current one persistent.
  5. To use:
  6. in your keymap.c, define KF_LAYO so it does not conflict with anything else.
  7. then include this header and set highest_base_layer.
  8. #define KF_LAYO SAFE_RANGE
  9. #include "feature_default_layers_selector.h"
  10. const uint8_t highest_base_layer = 4; // the index
  11. and in your rules.mk,
  12. SRC += feature_default_layers_selector.c
  13. */
  14. /*
  15. See https://docs.qmk.fm/#/keymap for docs about layers including the concept
  16. of "base" or "default" layers.
  17. This is broken into two functions so that:
  18. - If you don't want to store the default layer state in eeprom, don't call
  19. process_record_save_default_layer.
  20. - If you have your own mechanism for setting the default layer state (to one
  21. or multiple layers), do that instead of process_record_select_default_layer.
  22. If you call both functions, call process_record_save_default_layer first.
  23. The QMK docs seem to assume that you will have only one layer as your
  24. default layer at any time, but the source code actually supports an arbitrary
  25. default_layer_state (composition of layers)
  26. quantum has "set_single_persistent_default_layer" but that writes to eeprom
  27. every time you change your default layer preference. i wanted a behavior
  28. instead which lets you switch default layers all you want, then store the
  29. current configuration once you're happy with it. that way if you get into an
  30. unusable state you can just unplug and replug your keyboard to escape from it.
  31. this code assumes:
  32. 1. each default layer state that you would select among consists of a single
  33. layer, which we will call a "base" layer.
  34. 2. all your "base" layers are stored contiguously at the bottom of your
  35. keymaps[] stack, and there are no non-"base" layers mixed in.
  36. 3. you have a maximum of 8 "base" layers. that is, the highest base layer is
  37. index 7.
  38. while 16 and 32 bit platforms might allow default_layer_state to include more
  39. and higher-numbered layers, eeconfig_update_default_layer saves only the first
  40. 8 bits of default_layer_state to eeprom.
  41. */
  42. #ifndef KF_LAYO
  43. #define KF_LAYO SAFE_RANGE
  44. #endif
  45. const uint8_t highest_base_layer;
  46. bool process_record_save_default_layer(uint16_t keycode, keyrecord_t *record);
  47. bool process_record_select_default_layer(uint16_t keycode, keyrecord_t *record);