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.

83 lines
2.8 KiB

  1. /* Copyright 2022 @ Keychron (https://www.keychron.com)
  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 QMK_KEYBOARD_H
  17. #include "keychron_common.h"
  18. bool is_siri_active = false;
  19. uint32_t siri_timer = 0;
  20. key_combination_t key_comb_list[4] = {
  21. {2, {KC_LWIN, KC_TAB}},
  22. {2, {KC_LWIN, KC_E}},
  23. {3, {KC_LSFT, KC_LCMD, KC_4}},
  24. {2, {KC_LWIN, KC_C}}
  25. };
  26. static uint8_t mac_keycode[4] = { KC_LOPT, KC_ROPT, KC_LCMD, KC_RCMD };
  27. void housekeeping_task_keychron(void) {
  28. if (is_siri_active) {
  29. if (sync_timer_elapsed32(siri_timer) >= 500) {
  30. unregister_code(KC_LCMD);
  31. unregister_code(KC_SPACE);
  32. is_siri_active = false;
  33. }
  34. }
  35. }
  36. bool process_record_keychron(uint16_t keycode, keyrecord_t *record) {
  37. switch (keycode) {
  38. case KC_LOPTN:
  39. case KC_ROPTN:
  40. case KC_LCMMD:
  41. case KC_RCMMD:
  42. if (record->event.pressed) {
  43. register_code(mac_keycode[keycode - KC_LOPTN]);
  44. } else {
  45. unregister_code(mac_keycode[keycode - KC_LOPTN]);
  46. }
  47. return false; // Skip all further processing of this key
  48. case KC_SIRI:
  49. if (record->event.pressed) {
  50. if (!is_siri_active) {
  51. is_siri_active = true;
  52. register_code(KC_LCMD);
  53. register_code(KC_SPACE);
  54. }
  55. siri_timer = sync_timer_read32();
  56. } else {
  57. // Do something else when release
  58. }
  59. return false; // Skip all further processing of this key
  60. case KC_TASK:
  61. case KC_FLXP:
  62. case KC_SNAP:
  63. case KC_CRTA:
  64. if (record->event.pressed) {
  65. for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
  66. register_code(key_comb_list[keycode - KC_TASK].keycode[i]);
  67. }
  68. } else {
  69. for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
  70. unregister_code(key_comb_list[keycode - KC_TASK].keycode[i]);
  71. }
  72. }
  73. return false; // Skip all further processing of this key
  74. default:
  75. return true; // Process all other keycodes normally
  76. }
  77. }