zmk icon indicating copy to clipboard operation
zmk copied to clipboard

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

Open darknao opened this issue 1 year ago • 1 comments

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

  • [x] Branch has a clean commit history
  • [ ] Additional tests are included, if changing behaviors/core code that is testable.
  • [x] 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)
  • [x] Pre-commit used to check formatting of files, commit messages, etc.
  • [ ] Includes any necessary documentation changes.

darknao avatar Jan 05 '25 22:01 darknao

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.

nmunnich avatar Jan 11 '25 08:01 nmunnich