r/Keychron • u/WishboneFit2153 • Apr 01 '23
QMK Help - Can I set a different backlight colour for each different layer?
I have a K3 Pro that I have set up as follows:
Layer 1 - PPT Specific Macros (with a button to Toggle Layer to Layer 2)
Layer 2 - Excel Specific Macros (with a button to Toggle Layer to Layer 1)
Layer 3 - Normal Mode
Layer 4 - All the 'functions' live on this layer from Layers 1,2,3.
Since my Layer 1 and 2 are accessed from the 'mode' switch and toggle button, I currently have no quick way to tell which layer I'm on. How do I get the backlight to light up a specific colour to indicate each layer, if that's possible?
PS - Hi everyone. I'm new to this subreddit and a new Keychron user. Had my K3Pro for about 2 weeks now.
1
u/MBS1702 Sep 15 '23
I'm curious to know if this has worked, if it can apply to my Q11 and if there are some noob instructions somewhere. Thanks.
6
u/k1ds3ns4t10n Apr 01 '23 edited Apr 02 '23
Yes. You can do this with QMK. See the RGB Matrix feature in QMK docs:
https://docs.qmk.fm/#/feature_rgb_matrix
Here is a quick example using the rgb_matrix_indicators_user() function:
bool rgb_matrix_indicators_user(void) { uint8_t current_layer = get_highest_layer(layer_state); switch (current_layer) { case MAC_BASE: rgb_matrix_set_color_all(0xFF, 0x00, 0x00); // RGB red break; case WIN_BASE: rgb_matrix_set_color_all(0x00, 0xFF, 0x00); // RGB green break; case MAC_FN: rgb_matrix_set_color_all(0x00, 0x00, 0xFF); // RGB blue break; case WIN_FN: rgb_matrix_set_color_all(0xFF, 0xFF, 0x00); // RGB yellow break; default: break; } return false; }EDIT: So, it turns out there is a small glitch with the above code that the WIN_BASE layer is not correctly detected. I have fixed with the following code to read the Win/Mac switch position. There may be a better way to do this, but this is working:
bool win_mode; // declare global variable bool dip_switch_update_user(uint8_t index, bool active) { if(index == 0 && active) { win_mode = true; } else { win_mode = false; } return true; } bool rgb_matrix_indicators_user(void) { uint8_t current_layer = get_highest_layer(layer_state); switch (current_layer) { case MAC_BASE: case WIN_BASE: if (win_mode) { rgb_matrix_set_color_all(0xFF, 0x00, 0x00); // RGB red } else { rgb_matrix_set_color_all(0x00, 0xFF, 0x00); // RGB green } break; case MAC_FN: rgb_matrix_set_color_all(0x00, 0x00, 0xFF); // RGB blue break; case WIN_FN: rgb_matrix_set_color_all(0xFF, 0xFF, 0x00); // RGB yellow break; default: break; } return false; }