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.

165 lines
4.9 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. extern keymap_config_t keymap_config;
  18. /** \brief keycode_config
  19. *
  20. * This function is used to check a specific keycode against the bootmagic config,
  21. * and will return the corrected keycode, when appropriate.
  22. */
  23. uint16_t keycode_config(uint16_t keycode) {
  24. switch (keycode) {
  25. case KC_CAPSLOCK:
  26. case KC_LOCKING_CAPS:
  27. if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
  28. return KC_LCTL;
  29. }
  30. return keycode;
  31. case KC_LCTL:
  32. if (keymap_config.swap_control_capslock) {
  33. return KC_CAPSLOCK;
  34. }
  35. if (keymap_config.swap_lctl_lgui) {
  36. if (keymap_config.no_gui) {
  37. return KC_NO;
  38. }
  39. return KC_LGUI;
  40. }
  41. return KC_LCTL;
  42. case KC_LALT:
  43. if (keymap_config.swap_lalt_lgui) {
  44. if (keymap_config.no_gui) {
  45. return KC_NO;
  46. }
  47. return KC_LGUI;
  48. }
  49. return KC_LALT;
  50. case KC_LGUI:
  51. if (keymap_config.swap_lalt_lgui) {
  52. return KC_LALT;
  53. }
  54. if (keymap_config.swap_lctl_lgui) {
  55. return KC_LCTRL;
  56. }
  57. if (keymap_config.no_gui) {
  58. return KC_NO;
  59. }
  60. return KC_LGUI;
  61. case KC_RCTL:
  62. if (keymap_config.swap_rctl_rgui) {
  63. if (keymap_config.no_gui) {
  64. return KC_NO;
  65. }
  66. return KC_RGUI;
  67. }
  68. return KC_RCTL;
  69. case KC_RALT:
  70. if (keymap_config.swap_ralt_rgui) {
  71. if (keymap_config.no_gui) {
  72. return KC_NO;
  73. }
  74. return KC_RGUI;
  75. }
  76. return KC_RALT;
  77. case KC_RGUI:
  78. if (keymap_config.swap_ralt_rgui) {
  79. return KC_RALT;
  80. }
  81. if (keymap_config.swap_rctl_rgui) {
  82. return KC_RCTL;
  83. }
  84. if (keymap_config.no_gui) {
  85. return KC_NO;
  86. }
  87. return KC_RGUI;
  88. case KC_GRAVE:
  89. if (keymap_config.swap_grave_esc) {
  90. return KC_ESC;
  91. }
  92. return KC_GRAVE;
  93. case KC_ESC:
  94. if (keymap_config.swap_grave_esc) {
  95. return KC_GRAVE;
  96. }
  97. return KC_ESC;
  98. case KC_BSLASH:
  99. if (keymap_config.swap_backslash_backspace) {
  100. return KC_BSPACE;
  101. }
  102. return KC_BSLASH;
  103. case KC_BSPACE:
  104. if (keymap_config.swap_backslash_backspace) {
  105. return KC_BSLASH;
  106. }
  107. return KC_BSPACE;
  108. default:
  109. return keycode;
  110. }
  111. }
  112. /** \brief mod_config
  113. *
  114. * This function checks the mods passed to it against the bootmagic config,
  115. * and will remove or replace mods, based on that.
  116. */
  117. uint8_t mod_config(uint8_t mod) {
  118. if (keymap_config.swap_lalt_lgui) {
  119. if ((mod & MOD_RGUI) == MOD_LGUI) {
  120. mod &= ~MOD_LGUI;
  121. mod |= MOD_LALT;
  122. } else if ((mod & MOD_RALT) == MOD_LALT) {
  123. mod &= ~MOD_LALT;
  124. mod |= MOD_LGUI;
  125. }
  126. }
  127. if (keymap_config.swap_ralt_rgui) {
  128. if ((mod & MOD_RGUI) == MOD_RGUI) {
  129. mod &= ~MOD_RGUI;
  130. mod |= MOD_RALT;
  131. } else if ((mod & MOD_RALT) == MOD_RALT) {
  132. mod &= ~MOD_RALT;
  133. mod |= MOD_RGUI;
  134. }
  135. }
  136. if (keymap_config.swap_lctl_lgui) {
  137. if ((mod & MOD_RGUI) == MOD_LGUI) {
  138. mod &= ~MOD_LGUI;
  139. mod |= MOD_LCTL;
  140. } else if ((mod & MOD_RCTL) == MOD_LCTL) {
  141. mod &= ~MOD_LCTL;
  142. mod |= MOD_LGUI;
  143. }
  144. }
  145. if (keymap_config.swap_rctl_rgui) {
  146. if ((mod & MOD_RGUI) == MOD_RGUI) {
  147. mod &= ~MOD_RGUI;
  148. mod |= MOD_RCTL;
  149. } else if ((mod & MOD_RCTL) == MOD_RCTL) {
  150. mod &= ~MOD_RCTL;
  151. mod |= MOD_RGUI;
  152. }
  153. }
  154. if (keymap_config.no_gui) {
  155. mod &= ~MOD_LGUI;
  156. mod &= ~MOD_RGUI;
  157. }
  158. return mod;
  159. }