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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

пре 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 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. Copyright 2013 Jun Wako <[email protected]>
  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 <avr/pgmspace.h>
  15. #include "keymap.h"
  16. #include "report.h"
  17. #include "keycode.h"
  18. #include "action_layer.h"
  19. #include "action.h"
  20. #include "action_macro.h"
  21. #include "debug.h"
  22. static action_t keycode_to_action(uint8_t keycode);
  23. /* converts key to action */
  24. action_t action_for_key(uint8_t layer, key_t key)
  25. {
  26. uint8_t keycode = keymap_key_to_keycode(layer, key);
  27. switch (keycode) {
  28. case KC_FN0 ... KC_FN31:
  29. return keymap_fn_to_action(keycode);
  30. default:
  31. return keycode_to_action(keycode);
  32. }
  33. }
  34. /* Macro */
  35. __attribute__ ((weak))
  36. const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  37. {
  38. return MACRO_NONE;
  39. }
  40. /* Function */
  41. __attribute__ ((weak))
  42. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
  43. {
  44. }
  45. /* translates keycode to action */
  46. static action_t keycode_to_action(uint8_t keycode)
  47. {
  48. action_t action;
  49. switch (keycode) {
  50. case KC_A ... KC_EXSEL:
  51. case KC_LCTRL ... KC_RGUI:
  52. action.code = ACTION_KEY(keycode);
  53. break;
  54. case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
  55. action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
  56. break;
  57. case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
  58. action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
  59. break;
  60. case KC_MS_UP ... KC_MS_ACCEL2:
  61. action.code = ACTION_MOUSEKEY(keycode);
  62. break;
  63. case KC_TRNS:
  64. action.code = ACTION_TRANSPARENT;
  65. break;
  66. default:
  67. action.code = ACTION_NO;
  68. break;
  69. }
  70. return action;
  71. }
  72. #ifdef USE_LEGACY_KEYMAP
  73. /*
  74. * Legacy keymap support
  75. * Consider using new keymap API instead.
  76. */
  77. __attribute__ ((weak))
  78. uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
  79. {
  80. return keymap_get_keycode(layer, key.row, key.col);
  81. }
  82. /* Legacy keymap support */
  83. __attribute__ ((weak))
  84. action_t keymap_fn_to_action(uint8_t keycode)
  85. {
  86. action_t action = { .code = ACTION_NO };
  87. switch (keycode) {
  88. case KC_FN0 ... KC_FN31:
  89. {
  90. uint8_t layer = keymap_fn_layer(FN_INDEX(keycode));
  91. uint8_t key = keymap_fn_keycode(FN_INDEX(keycode));
  92. if (key) {
  93. action.code = ACTION_KEYMAP_TAP_KEY(layer, key);
  94. } else {
  95. action.code = ACTION_KEYMAP_MOMENTARY(layer);
  96. }
  97. }
  98. return action;
  99. default:
  100. return action;
  101. }
  102. }
  103. #endif