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.

65 lines
2.1 KiB

  1. /* Copyright 2021 @daliusd
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include QMK_KEYBOARD_H
  18. // Represents the four states a oneshot key can be in
  19. typedef enum {
  20. os_up_unqueued,
  21. os_up_queued,
  22. os_up_queued_used,
  23. os_down_unused,
  24. os_down_used,
  25. } oneshot_state;
  26. // Custom oneshot mod implementation that doesn't rely on timers. If a mod is
  27. // used while it is held it will be unregistered on keyup as normal, otherwise
  28. // it will be queued and only released after the next non-mod keyup.
  29. void update_oneshot(
  30. oneshot_state *state,
  31. uint16_t mod,
  32. uint16_t trigger,
  33. uint16_t keycode,
  34. keyrecord_t *record
  35. );
  36. // Oneshot implementation for layers
  37. bool update_oneshot_layer(
  38. oneshot_state *state,
  39. uint16_t layer,
  40. uint16_t trigger,
  41. uint16_t keycode,
  42. keyrecord_t *record
  43. );
  44. // To be implemented by the consumer. Layers one shot implementation needs to
  45. // know which keys are used as oneshot mods
  46. bool is_oneshot_mod_key(
  47. uint16_t keycode
  48. );
  49. // To be implemented by the consumer. Defines keys to cancel oneshot mods.
  50. bool is_oneshot_cancel_key(uint16_t keycode);
  51. // To be implemented by the consumer. Defines keys to cancel oneshot layers.
  52. bool is_oneshot_layer_cancel_key(uint16_t keycode);
  53. // To be implemented by the consumer. Defines keys to ignore when determining
  54. // whether a oneshot mod has been used. Setting this to modifiers and layer
  55. // change keys allows stacking multiple oneshot modifiers, and carrying them
  56. // between layers.
  57. bool is_oneshot_ignored_key(uint16_t keycode);