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: Allow layer behaviors to "lock" layers on #2717

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Nick-Munnich
Copy link
Contributor

@Nick-Munnich Nick-Munnich commented Dec 16, 2024

Adds a locking property to momentary, to, and toggle layer behaviors. Enabled by default for &to and &tog, a layer being "locked" prevents behaviors without the locking property from deactivating the layer.

Conditional layer activation and deactivation is always non-locking, which seems to interact nicely.

Common use case: with this PR you can place e.g. a &tog_on 1 or a &to 1 on layer 1, allowing you to "lock" it in place while it is active.

PR check-list

  • Branch has a clean commit history
  • Additional tests are included, if changing behaviors/core code that is testable.
  • Pre-commit used to check formatting of files, commit messages, etc.
  • Has any necessary documentation updates.

@Nick-Munnich Nick-Munnich requested a review from a team as a code owner December 16, 2024 16:15
@Nick-Munnich Nick-Munnich marked this pull request as draft December 16, 2024 18:06
@caksoylar
Copy link
Contributor

caksoylar commented Dec 16, 2024

Conditional layer activation and deactivation is always non-locking, which seems to interact nicely.

If you want to get the state of a conditionally activated then-layer, it seems useful to me to propagate the locked state from if-layers (i.e. it is locked if all of the if-layers are locked). This'd be necessary to replace the momentariness tracking I mentioned on Discord.

Can you lock on a then-layer using &tog? I would guess not, since it still needs all the if-layers to be active.

@Nick-Munnich
Copy link
Contributor Author

If you want to get the state of a conditionally activated then-layer, it seems useful to me to propagate the locked state from if-layers (i.e. it is locked if all of the if-layers are locked). This'd be necessary to replace the momentariness tracking I mentioned on Discord.

Can you lock on a then-layer using &tog? I would guess not, since it still needs all the if-layers to be active.

I realised that tracking that is unnecessary for this to work as expected. Rather, if both if-layers are locked then the then-layer is semi-locked: If it is deactivated, then on the event triggered by the deactivation the then-layer immediately becomes reactivated.

This also has the effect of allowing the then-layer to be locked using &tog, as if one of the if-layers becomes inactive then the conditional layer effect will try but fail to deactivate the then-layer.

@caksoylar
Copy link
Contributor

I will rewind a bit: I have this momentariness tracking feature which is being used to filter layer change events that aren't "permanent". I am hoping to replace the tracking of momentariness by checking the "locked" state of the highest active layer instead. For that to work:

  • There'd need to be a function like bool zmk_keymap_layer_locked(zmk_keymap_layer_id_t layer) that'd return the state of a layer
  • Conditional layers would need to set the default locked status (check if all the if-layers are locked), before it might be locked directly by e.g. a &tog

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

Successfully merging this pull request may close these issues.

2 participants