Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(underglow): per-key/layer RGB underglow #2752

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

darknao
Copy link

@darknao darknao commented Jan 5, 2025

Introduce a per-key / per-layer RGB underglow that can be configured in the keymap as follows:

/ {
    underglow-layer {
        compatible  = "zmk,underglow-layer";

        lower {
            bindings = <
    &ug ___    &ug ___  &ug ___    &ug ___    &ug ___                                                                                 &ug ___             &ug ___           &ug ___           &ug ___     &ug ___
    &ug PURPLE &ug PINK &ug PINK   &ug   PINK &ug   PINK &ug PINK                                                             &ug ___ &ug_nl WHITE ORANGE &ug ORANGE        &ug ORANGE        &ug ORANGE  &ug RED
    &ug PURPLE &ug ___  &ug ___    &ug ORANGE &ug ___    &ug ___                                                              &ug ___ &ug_nl RED YELLOW   &ug_nl RED YELLOW &ug_nl RED YELLOW &ug ORANGE  &ug ___
    &ug PURPLE &ug ___  &ug ORANGE &ug    RED &ug ORANGE &ug ___                                                              &ug ___ &ug_nl RED YELLOW   &ug_nl RED YELLOW &ug_nl RED YELLOW &ug ORANGE  &ug ___
    &ug   BLUE &ug ___  &ug RED    &ug    RED &ug    RED &ug ___  &ug_cl BLUE TEAL &ug ___   &ug ___  &ug ___ &ug ___ &ug ___ &ug ___ &ug_nl RED YELLOW   &ug_nl RED YELLOW &ug_nl RED YELLOW &ug    RED  &ug BLUE
    &ug ___    &ug ___  &ug ORANGE &ug ORANGE &ug ORANGE          &ug ___          &ug GREEN &ug ___  &ug ___ &ug ___ &ug ___         &ug_nl RED YELLOW   &ug_nl RED YELLOW &ug ORANGE        &ug    RED  &ug ___
                >;
            layer-id = <LAYER_Lower>;
        };

        another-layer {
            bindings = < [...] >;
            layer-id = <LAYER_Name>;
        };
    };
};

bindings: Visual representation of the RGB underglow layer, just like keymap, but for RGB.
&ug is the simplest behavior that set the specified color. the ___ color constant means the RGB is off. You can use predefined color names (defined in app/include/dt-bindings/zmk/rgb_colors.h) or RGB hex code like 0xFF0000 for red.
&ug_cl COLOR_OFF COLOR_ON is another behavior that sets the underglow color according to the CAPSLOCK state.
&ug_nl and &ug_sl do the same for NumLock & ScrollLock respectively.

layer-id: This must match the associated keymap layer identifier. You can use the #define name such as BASE, LOWER, RAISE...

The RGB underglow layer effect can be enabled with the RGB_TOG key. Use the RGB_EFF key to cycle through all effects until the layer effect is enabled. The layer effect is located after the swirl effect, and before the static color effect (the swirl effect will freeze when the layer effect is enabled).

The layer effect is available if the CONFIG_EXPERIMENTAL_RGB_LAYER Kconfig is set.
On split keyboards, the CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS Kconfig is required for peripherals to display the HID indicators.

This was initially made for the Glove80 last year, but maybe others might find that feature useful.
The code is far from perfect, but I'm willing to improve it if you have any suggestions or recommendations.

Related: #554

PR check-list

  • Branch has a clean commit history
  • Additional tests are included, if changing behaviors/core code that is testable.
  • Proper Copyright + License headers added to applicable files (Generally, we stick to "The ZMK Contributors" for copyrights to help avoid churn when files get edited)
  • Pre-commit used to check formatting of files, commit messages, etc.
  • Includes any necessary documentation changes.

@darknao darknao force-pushed the zmk-perkey_ug branch 2 times, most recently from a7faa94 to 8b90e1e Compare January 6, 2025 13:20
@darknao darknao marked this pull request as ready for review January 6, 2025 13:30
@darknao darknao requested a review from a team as a code owner January 6, 2025 13:30
@Nick-Munnich
Copy link
Contributor

Hi, thanks for the PR. I just wanted to give a heads up that this is unlikely to be merged as-is. What ZMK really needs is a more general lighting system than either the RGB UG code or the backlight code, that is also designed with ZMK Studio in mind. Such a lighting system would most likely need some discussion on Discord on the implementation details.

I hence see it as unlikely that PRs extending the current functionality will be reviewed fully (and thus merged), as the ZMK team is quite small and limited on time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants