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.

163 lines
5.4 KiB

  1. /* Copyright 2016 Jack Humbert
  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. #include "keycode_config.h"
  17. /** \brief keycode_config
  18. *
  19. * This function is used to check a specific keycode against the bootmagic config,
  20. * and will return the corrected keycode, when appropriate.
  21. */
  22. __attribute__((weak)) uint16_t keycode_config(uint16_t keycode) {
  23. switch (keycode) {
  24. case KC_CAPS_LOCK:
  25. case KC_LOCKING_CAPS_LOCK:
  26. if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
  27. return KC_LEFT_CTRL;
  28. } else if (keymap_config.swap_escape_capslock) {
  29. return KC_ESCAPE;
  30. }
  31. return keycode;
  32. case KC_LEFT_CTRL:
  33. if (keymap_config.swap_control_capslock) {
  34. return KC_CAPS_LOCK;
  35. }
  36. if (keymap_config.swap_lctl_lgui) {
  37. if (keymap_config.no_gui) {
  38. return KC_NO;
  39. }
  40. return KC_LEFT_GUI;
  41. }
  42. return KC_LEFT_CTRL;
  43. case KC_LEFT_ALT:
  44. if (keymap_config.swap_lalt_lgui) {
  45. if (keymap_config.no_gui) {
  46. return KC_NO;
  47. }
  48. return KC_LEFT_GUI;
  49. }
  50. return KC_LEFT_ALT;
  51. case KC_LEFT_GUI:
  52. if (keymap_config.swap_lalt_lgui) {
  53. return KC_LEFT_ALT;
  54. }
  55. if (keymap_config.swap_lctl_lgui) {
  56. return KC_LEFT_CTRL;
  57. }
  58. if (keymap_config.no_gui) {
  59. return KC_NO;
  60. }
  61. return KC_LEFT_GUI;
  62. case KC_RIGHT_CTRL:
  63. if (keymap_config.swap_rctl_rgui) {
  64. if (keymap_config.no_gui) {
  65. return KC_NO;
  66. }
  67. return KC_RIGHT_GUI;
  68. }
  69. return KC_RIGHT_CTRL;
  70. case KC_RIGHT_ALT:
  71. if (keymap_config.swap_ralt_rgui) {
  72. if (keymap_config.no_gui) {
  73. return KC_NO;
  74. }
  75. return KC_RIGHT_GUI;
  76. }
  77. return KC_RIGHT_ALT;
  78. case KC_RIGHT_GUI:
  79. if (keymap_config.swap_ralt_rgui) {
  80. return KC_RIGHT_ALT;
  81. }
  82. if (keymap_config.swap_rctl_rgui) {
  83. return KC_RIGHT_CTRL;
  84. }
  85. if (keymap_config.no_gui) {
  86. return KC_NO;
  87. }
  88. return KC_RIGHT_GUI;
  89. case KC_GRAVE:
  90. if (keymap_config.swap_grave_esc) {
  91. return KC_ESCAPE;
  92. }
  93. return KC_GRAVE;
  94. case KC_ESCAPE:
  95. if (keymap_config.swap_grave_esc) {
  96. return KC_GRAVE;
  97. } else if (keymap_config.swap_escape_capslock) {
  98. return KC_CAPS_LOCK;
  99. }
  100. return KC_ESCAPE;
  101. case KC_BACKSLASH:
  102. if (keymap_config.swap_backslash_backspace) {
  103. return KC_BACKSPACE;
  104. }
  105. return KC_BACKSLASH;
  106. case KC_BACKSPACE:
  107. if (keymap_config.swap_backslash_backspace) {
  108. return KC_BACKSLASH;
  109. }
  110. return KC_BACKSPACE;
  111. default:
  112. return keycode;
  113. }
  114. }
  115. /** \brief mod_config
  116. *
  117. * This function checks the mods passed to it against the bootmagic config,
  118. * and will remove or replace mods, based on that.
  119. */
  120. __attribute__((weak)) uint8_t mod_config(uint8_t mod) {
  121. /**
  122. * Note: This function is for the 5-bit packed mods, NOT the full 8-bit mods.
  123. * More info about the mods can be seen in modifiers.h.
  124. */
  125. if (keymap_config.swap_lalt_lgui) {
  126. /** If both modifiers pressed or neither pressed, do nothing
  127. * Otherwise swap the values
  128. * Note: The left mods are ANDed with the right-hand values to check
  129. * if they were pressed with the right hand bit set
  130. */
  131. if (((mod & MOD_RALT) == MOD_LALT) ^ ((mod & MOD_RGUI) == MOD_LGUI)) {
  132. mod ^= (MOD_LALT | MOD_LGUI);
  133. }
  134. }
  135. if (keymap_config.swap_ralt_rgui) {
  136. if (((mod & MOD_RALT) == MOD_RALT) ^ ((mod & MOD_RGUI) == MOD_RGUI)) {
  137. /* lefthand values to preserve the right hand bit */
  138. mod ^= (MOD_LALT | MOD_LGUI);
  139. }
  140. }
  141. if (keymap_config.swap_lctl_lgui) {
  142. /* left mods ANDed with right-hand values to check for right hand bit */
  143. if (((mod & MOD_RCTL) == MOD_LCTL) ^ ((mod & MOD_RGUI) == MOD_LGUI)) {
  144. mod ^= (MOD_LCTL | MOD_LGUI);
  145. }
  146. }
  147. if (keymap_config.swap_rctl_rgui) {
  148. if (((mod & MOD_RCTL) == MOD_RCTL) ^ ((mod & MOD_RGUI) == MOD_RGUI)) {
  149. /* lefthand values to preserve the right hand bit */
  150. mod ^= (MOD_LCTL | MOD_LGUI);
  151. }
  152. }
  153. if (keymap_config.no_gui) {
  154. mod &= ~MOD_LGUI;
  155. mod &= ~MOD_RGUI;
  156. }
  157. return mod;
  158. }