Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
Это архивный репозиторий. Вы можете его клонировать или просматривать файлы, но не вносить изменения или открывать задачи/запросы на слияние.

11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include <stdint.h>
  2. #include "keyboard.h"
  3. #include "action.h"
  4. #include "debug.h"
  5. #include "util.h"
  6. #include "action_layer.h"
  7. /*
  8. * Default Layer State
  9. */
  10. uint32_t default_layer_state = 0;
  11. static void default_layer_state_set(uint32_t state)
  12. {
  13. debug("default_layer_state: ");
  14. default_layer_debug(); debug(" to ");
  15. default_layer_state = state;
  16. default_layer_debug(); debug("\n");
  17. clear_keyboard_but_mods(); // To avoid stuck keys
  18. }
  19. void default_layer_debug(void)
  20. {
  21. debug_hex32(default_layer_state);
  22. debug("("); debug_dec(biton32(default_layer_state)); debug(")");
  23. }
  24. void default_layer_set(uint8_t layer)
  25. {
  26. default_layer_state_set(1UL<<layer);
  27. }
  28. #ifndef NO_ACTION_LAYER
  29. void default_layer_or(uint32_t state)
  30. {
  31. default_layer_state_set(default_layer_state | state);
  32. }
  33. void default_layer_and(uint32_t state)
  34. {
  35. default_layer_state_set(default_layer_state & state);
  36. }
  37. void default_layer_xor(uint32_t state)
  38. {
  39. default_layer_state_set(default_layer_state ^ state);
  40. }
  41. #endif
  42. #ifndef NO_ACTION_LAYER
  43. /*
  44. * Keymap Layer State
  45. */
  46. uint32_t layer_state = 0;
  47. static void layer_state_set(uint32_t state)
  48. {
  49. debug("layer_state: ");
  50. layer_debug(); debug(" to ");
  51. layer_state = state;
  52. layer_debug(); debug("\n");
  53. clear_keyboard_but_mods(); // To avoid stuck keys
  54. }
  55. void layer_clear(void)
  56. {
  57. layer_state_set(0);
  58. }
  59. void layer_move(uint8_t layer)
  60. {
  61. layer_state_set(1UL<<layer);
  62. }
  63. void layer_on(uint8_t layer)
  64. {
  65. layer_state_set(layer_state | (1UL<<layer));
  66. }
  67. void layer_off(uint8_t layer)
  68. {
  69. layer_state_set(layer_state & ~(1UL<<layer));
  70. }
  71. void layer_invert(uint8_t layer)
  72. {
  73. layer_state_set(layer_state ^ (1UL<<layer));
  74. }
  75. void layer_or(uint32_t state)
  76. {
  77. layer_state_set(layer_state | state);
  78. }
  79. void layer_and(uint32_t state)
  80. {
  81. layer_state_set(layer_state & state);
  82. }
  83. void layer_xor(uint32_t state)
  84. {
  85. layer_state_set(layer_state ^ state);
  86. }
  87. void layer_debug(void)
  88. {
  89. debug_hex32(layer_state);
  90. debug("("); debug_dec(biton32(layer_state)); debug(")");
  91. }
  92. #endif
  93. action_t layer_switch_get_action(key_t key)
  94. {
  95. action_t action;
  96. action.code = ACTION_TRANSPARENT;
  97. #ifndef NO_ACTION_LAYER
  98. uint32_t layers = layer_state | default_layer_state;
  99. /* check top layer first */
  100. for (int8_t i = 31; i >= 0; i--) {
  101. if (layers & (1UL<<i)) {
  102. action = action_for_key(i, key);
  103. if (action.code != ACTION_TRANSPARENT) {
  104. return action;
  105. }
  106. }
  107. }
  108. /* fall back to layer 0 */
  109. action = action_for_key(0, key);
  110. return action;
  111. #else
  112. action = action_for_key(biton32(default_layer_state), key);
  113. return action;
  114. #endif
  115. }