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.

76 lines
2.5 KiB

  1. /* Copyright 2021 @ Grayson Carr
  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 "rgb_matrix_user.h"
  18. #include "keymap_user.h"
  19. keypos_t led_index_key_position[RGB_MATRIX_LED_COUNT];
  20. void rgb_matrix_init_user(void) {
  21. for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
  22. for (uint8_t col = 0; col < MATRIX_COLS; col++) {
  23. uint8_t led_index = g_led_config.matrix_co[row][col];
  24. if (led_index != NO_LED) {
  25. led_index_key_position[led_index] = (keypos_t){.row = row, .col = col};
  26. }
  27. }
  28. }
  29. }
  30. bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
  31. uint8_t current_layer = get_highest_layer(layer_state);
  32. switch (current_layer) {
  33. case MAC_BASE:
  34. case WIN_BASE:
  35. #ifdef CAPS_LOCK_INDICATOR_COLOR
  36. if (host_keyboard_led_state().caps_lock) {
  37. rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_caps_lock_indicator, CAPS_LOCK_INDICATOR_COLOR);
  38. }
  39. #endif
  40. break;
  41. case MAC_FN:
  42. case WIN_FN:
  43. #ifdef FN_LAYER_TRANSPARENT_KEYS_OFF
  44. rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_transparent, RGB_OFF);
  45. #endif
  46. break;
  47. }
  48. return false;
  49. }
  50. void rgb_matrix_set_color_by_keycode(uint8_t led_min, uint8_t led_max, uint8_t layer, bool (*is_keycode)(uint16_t), uint8_t red, uint8_t green, uint8_t blue) {
  51. for (uint8_t i = led_min; i < led_max; i++) {
  52. uint16_t keycode = keymap_key_to_keycode(layer, led_index_key_position[i]);
  53. if ((*is_keycode)(keycode)) {
  54. rgb_matrix_set_color(i, red, green, blue);
  55. }
  56. }
  57. }
  58. bool is_caps_lock_indicator(uint16_t keycode) {
  59. switch (keycode) {
  60. #ifdef CAPS_LOCK_INDICATOR_LIGHT_ALPHAS
  61. case KC_A ... KC_Z:
  62. #endif
  63. case KC_CAPS:
  64. return true;
  65. default:
  66. return false;
  67. }
  68. }
  69. bool is_transparent(uint16_t keycode) { return keycode == KC_TRNS; }