Last active
March 31, 2022 12:59
-
-
Save knoopx/f84d9b41fb03f17c0e23c428cf8d21b3 to your computer and use it in GitHub Desktop.
QMK RGB Matrix Effect Layer Mask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { | |
uint8_t layer = get_highest_layer(layer_state); | |
for (uint8_t row = 0; row < MATRIX_ROWS; ++row) { | |
for (uint8_t col = 0; col < MATRIX_COLS; ++col) { | |
uint8_t index = g_led_config.matrix_co[row][col]; | |
keypos_t keypos = {col, row}; | |
if (g_led_config.flags[index] == LED_FLAG_NONE) { | |
rgb_matrix_set_color(index, RGB_OFF); | |
continue; | |
} | |
// caps lock indicator | |
if (row == 3 && col == 0) { | |
if (host_keyboard_led_state().caps_lock) { | |
g_led_config.flags[index] = LED_FLAG_INDICATOR; | |
} else { | |
g_led_config.flags[index] = keymap_key_to_keycode(layer, keypos) == KC_TRNS ? LED_FLAG_NONE : LED_FLAG_KEYLIGHT; | |
} | |
} | |
if (g_led_config.flags[index] == LED_FLAG_INDICATOR) { | |
rgb_matrix_set_color(index, RGB_RED); | |
continue; | |
} | |
} | |
} | |
} | |
layer_state_t layer_state_set_user(layer_state_t state) { | |
uint8_t layer = get_highest_layer(state); | |
for (uint8_t row = 0; row < MATRIX_ROWS; ++row) { | |
for (uint8_t col = 0; col < MATRIX_COLS; ++col) { | |
uint8_t index = g_led_config.matrix_co[row][col]; | |
keypos_t keypos = {col, row}; | |
// transparent keys | |
if (keymap_key_to_keycode(layer, keypos) == KC_TRNS) { | |
g_led_config.flags[index] = LED_FLAG_NONE; | |
continue; | |
} | |
g_led_config.flags[index] = LED_FLAG_KEYLIGHT; | |
} | |
} | |
return state; | |
} | |
// make effects apply only to keys flagged as keylights | |
void keyboard_post_init_user(void) { rgb_matrix_set_flags(LED_FLAG_KEYLIGHT); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment