TeXitoi / keyberon

A rust crate to create a pure rust keyboard firmware.
MIT License
1.07k stars 78 forks source link

Feature: tri-state layers #124

Open dariogoetz opened 1 year ago

dariogoetz commented 1 year ago

This PR adds "tri-state layers" that become active if two configured layer modifiers are held at the same time (QMK has something similar).

I previously achieved such a functionality by placing a layer modifier for the third layer on the modifier layers corresponding to the other layer modifiers. In that case, however, the third layer remains active, even when the first hit layer modifier is released.

Example for layer modifiers m1 and m2 leading to layers l1 and l2 if pressed by themselves and a third "tri-state layer" l3:

Intended effect: press m1 -> l1 press m2 -> l3 release m1 -> l2 release m2 -> default layer

My previous hack-solution gave: press m1 -> l1 press m2 -> l3 release m1 -> remain on l3 release m2 -> default layer

TeXitoi commented 11 months ago

The current behavior is wanted. At the first version of keyberon, the pressed layers was added to give the current active layer (so plessing l(1) and l(2) will activate l(3)). This behavior was less flexible than the current one, and would not allow "path" to layer.

TeXitoi commented 11 months ago

Can you give the "equivalent" QMK feature? QMK has lots of strange and interleaved features, and keyberon aims for a condensed list of coherent features.

dariogoetz commented 11 months ago

Note: I renamed this functionality to add_tri_layer instead of add_tri_state_layer (to be consistent with QMK).

The suggested solution is "opt-in" so that the "current behavior" still remains as the default. One can configure such a new tri-layer by calling the Layout's new add_tri_layer method.

        let mut layout = Layout::new(&some_layers);
        layout.add_tri_layer((1, 2), 3);

In QMK, this functionality is described here: https://docs.qmk.fm/#/ref_functions?id=update_tri_layer_statestate-x-y-z The relevant QMK code is found here: https://github.com/qmk/qmk_firmware/blob/master/quantum/action_layer.c#L354