process_unicode_common.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Copyright 2017 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 "process_unicode_common.h"
  17. uint8_t mods;
  18. void set_unicode_input_mode(uint8_t os_target)
  19. {
  20. input_mode = os_target;
  21. }
  22. uint8_t get_unicode_input_mode(void) {
  23. return input_mode;
  24. }
  25. __attribute__((weak))
  26. void unicode_input_start (void) {
  27. // save current mods
  28. mods = keyboard_report->mods;
  29. // unregister all mods to start from clean state
  30. if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT);
  31. if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT);
  32. if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL);
  33. if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL);
  34. if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT);
  35. if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT);
  36. if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI);
  37. if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI);
  38. switch(input_mode) {
  39. case UC_OSX:
  40. register_code(KC_LALT);
  41. break;
  42. case UC_LNX:
  43. register_code(KC_LCTL);
  44. register_code(KC_LSFT);
  45. register_code(KC_U);
  46. unregister_code(KC_U);
  47. unregister_code(KC_LSFT);
  48. unregister_code(KC_LCTL);
  49. break;
  50. case UC_WIN:
  51. register_code(KC_LALT);
  52. register_code(KC_PPLS);
  53. unregister_code(KC_PPLS);
  54. break;
  55. case UC_WINC:
  56. register_code(KC_RALT);
  57. unregister_code(KC_RALT);
  58. register_code(KC_U);
  59. unregister_code(KC_U);
  60. }
  61. wait_ms(UNICODE_TYPE_DELAY);
  62. }
  63. __attribute__((weak))
  64. void unicode_input_finish (void) {
  65. switch(input_mode) {
  66. case UC_OSX:
  67. case UC_WIN:
  68. unregister_code(KC_LALT);
  69. break;
  70. case UC_LNX:
  71. register_code(KC_SPC);
  72. unregister_code(KC_SPC);
  73. break;
  74. }
  75. // reregister previously set mods
  76. if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT);
  77. if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT);
  78. if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL);
  79. if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL);
  80. if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT);
  81. if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT);
  82. if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI);
  83. if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI);
  84. }
  85. void register_hex(uint16_t hex) {
  86. for(int i = 3; i >= 0; i--) {
  87. uint8_t digit = ((hex >> (i*4)) & 0xF);
  88. register_code(hex_to_keycode(digit));
  89. unregister_code(hex_to_keycode(digit));
  90. }
  91. }