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.

117 lines
3.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. extern keymap_config_t keymap_config;
  18. uint16_t keycode_config(uint16_t keycode) {
  19. switch (keycode) {
  20. case KC_CAPSLOCK:
  21. case KC_LOCKING_CAPS:
  22. if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
  23. return KC_LCTL;
  24. }
  25. return keycode;
  26. case KC_LCTL:
  27. if (keymap_config.swap_control_capslock) {
  28. return KC_CAPSLOCK;
  29. }
  30. return KC_LCTL;
  31. case KC_LALT:
  32. if (keymap_config.swap_lalt_lgui) {
  33. if (keymap_config.no_gui) {
  34. return KC_NO;
  35. }
  36. return KC_LGUI;
  37. }
  38. return KC_LALT;
  39. case KC_LGUI:
  40. if (keymap_config.swap_lalt_lgui) {
  41. return KC_LALT;
  42. }
  43. if (keymap_config.no_gui) {
  44. return KC_NO;
  45. }
  46. return KC_LGUI;
  47. case KC_RALT:
  48. if (keymap_config.swap_ralt_rgui) {
  49. if (keymap_config.no_gui) {
  50. return KC_NO;
  51. }
  52. return KC_RGUI;
  53. }
  54. return KC_RALT;
  55. case KC_RGUI:
  56. if (keymap_config.swap_ralt_rgui) {
  57. return KC_RALT;
  58. }
  59. if (keymap_config.no_gui) {
  60. return KC_NO;
  61. }
  62. return KC_RGUI;
  63. case KC_GRAVE:
  64. if (keymap_config.swap_grave_esc) {
  65. return KC_ESC;
  66. }
  67. return KC_GRAVE;
  68. case KC_ESC:
  69. if (keymap_config.swap_grave_esc) {
  70. return KC_GRAVE;
  71. }
  72. return KC_ESC;
  73. case KC_BSLASH:
  74. if (keymap_config.swap_backslash_backspace) {
  75. return KC_BSPACE;
  76. }
  77. return KC_BSLASH;
  78. case KC_BSPACE:
  79. if (keymap_config.swap_backslash_backspace) {
  80. return KC_BSLASH;
  81. }
  82. return KC_BSPACE;
  83. default:
  84. return keycode;
  85. }
  86. }
  87. uint8_t mod_config(uint8_t mod) {
  88. if (keymap_config.swap_lalt_lgui) {
  89. if ((mod & MOD_RGUI) == MOD_LGUI) {
  90. mod &= ~MOD_LGUI;
  91. mod |= MOD_LALT;
  92. } else if ((mod & MOD_RALT) == MOD_LALT) {
  93. mod &= ~MOD_LALT;
  94. mod |= MOD_LGUI;
  95. }
  96. }
  97. if (keymap_config.swap_ralt_rgui) {
  98. if ((mod & MOD_RGUI) == MOD_RGUI) {
  99. mod &= ~MOD_RGUI;
  100. mod |= MOD_RALT;
  101. } else if ((mod & MOD_RALT) == MOD_RALT) {
  102. mod &= ~MOD_RALT;
  103. mod |= MOD_RGUI;
  104. }
  105. }
  106. if (keymap_config.no_gui) {
  107. mod &= ~MOD_LGUI;
  108. mod &= ~MOD_RGUI;
  109. }
  110. return mod;
  111. }