action_layer.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. Copyright 2013 Jun Wako <wakojun@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. #pragma once
  15. #include <stdint.h>
  16. #include "keyboard.h"
  17. #include "action.h"
  18. /*
  19. * Default Layer
  20. */
  21. extern uint32_t default_layer_state;
  22. void default_layer_debug(void);
  23. void default_layer_set(uint32_t state);
  24. __attribute__((weak))
  25. uint32_t default_layer_state_set_kb(uint32_t state);
  26. #ifndef NO_ACTION_LAYER
  27. /* bitwise operation */
  28. void default_layer_or(uint32_t state);
  29. void default_layer_and(uint32_t state);
  30. void default_layer_xor(uint32_t state);
  31. #else
  32. #define default_layer_or(state)
  33. #define default_layer_and(state)
  34. #define default_layer_xor(state)
  35. #endif
  36. /*
  37. * Keymap Layer
  38. */
  39. #ifndef NO_ACTION_LAYER
  40. extern uint32_t layer_state;
  41. void layer_state_set(uint32_t state);
  42. bool layer_state_is(uint8_t layer);
  43. bool layer_state_cmp(uint32_t layer1, uint8_t layer2);
  44. void layer_debug(void);
  45. void layer_clear(void);
  46. void layer_move(uint8_t layer);
  47. void layer_on(uint8_t layer);
  48. void layer_off(uint8_t layer);
  49. void layer_invert(uint8_t layer);
  50. /* bitwise operation */
  51. void layer_or(uint32_t state);
  52. void layer_and(uint32_t state);
  53. void layer_xor(uint32_t state);
  54. #else
  55. #define layer_state 0
  56. #define layer_state_set(layer)
  57. #define layer_state_is(layer) (layer == 0)
  58. #define layer_state_cmp(state, layer) (state == 0 ? layer == 0 : (state & 1UL << layer) != 0)
  59. #define layer_debug()
  60. #define layer_clear()
  61. #define layer_move(layer)
  62. #define layer_on(layer)
  63. #define layer_off(layer)
  64. #define layer_invert(layer)
  65. #define layer_or(state)
  66. #define layer_and(state)
  67. #define layer_xor(state)
  68. __attribute__((weak))
  69. uint32_t layer_state_set_user(uint32_t state);
  70. __attribute__((weak))
  71. uint32_t layer_state_set_kb(uint32_t state);
  72. #endif
  73. /* pressed actions cache */
  74. #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
  75. /* The number of bits needed to represent the layer number: log2(32). */
  76. #define MAX_LAYER_BITS 5
  77. void update_source_layers_cache(keypos_t key, uint8_t layer);
  78. uint8_t read_source_layers_cache(keypos_t key);
  79. #endif
  80. action_t store_or_get_action(bool pressed, keypos_t key);
  81. /* return the topmost non-transparent layer currently associated with key */
  82. int8_t layer_switch_get_layer(keypos_t key);
  83. /* return action depending on current layer status */
  84. action_t layer_switch_get_action(keypos_t key);