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

[Enhancement] Layer timeouts #946

Open
bradezard131 opened this issue Mar 16, 2024 · 1 comment
Open

[Enhancement] Layer timeouts #946

bradezard131 opened this issue Mar 16, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@bradezard131
Copy link

Is your feature request related to a problem? Please describe.
I have a habit of walking away from my keyboard while in a layer, usually my function/nav layer, and then coming back 5-10 minutes later without remembering that I'm in a layer. This causes rather chaotic results when I start pressing F-keys in rapid succession.

Describe the solution you'd like
A layer timeout similar to CapsWord, where after a configurable time of inactivity the layer will deactivate. A well configured timeout would completely remove this issue, and a default of no timeout would prevent this from affecting existing users who may be happy with existing behaviour.

Describe alternatives you've considered
I have a KC.TO set up to reset everything manually, but it's rather clunky and I regularly forget to do it. I could also use momentary layer activation but holding down my layer key while I navigate around with arrows hasn't been a great experience either.

Additional context
I can probably figure this implementation out myself if need be, so I'd be interested in knowing if the project would be willing to receive a PR for it even if nobody else wants to work on it.

@bradezard131 bradezard131 added the enhancement New feature or request label Mar 16, 2024
@xs5871
Copy link
Collaborator

xs5871 commented Mar 27, 2024

Here's an untested blueprint how this could look like:

new module inactivity.py

from kmk.modules import Module
from kmk.scheduler import cancel_task, create_task


class Inactivity(Module):
    def __init__(self, timeout, action):
        self.timeout = timeout
        self.action = action

    def during_bootup(self, keyboard):
        self._task = create_task(action(keyboard), after_ms=timeout)

    def before_matrix_scan(self, keyboard):
        return

    def process_key(self, keyboard, key, is_pressed, int_coord):
        cancel_task(self._task)
        self._task = create_task(action, after_ms=self.timeout)
        return key

    def before_hid_send(self, keyboard):
        return

    def after_hid_send(self, keyboard):
        return

    def on_powersave_enable(self, keyboard):
        return

    def on_powersave_disable(self, keyboard):
        return

    def after_matrix_scan(self, keyboard):
        return

in main.py

# ...
from inactivity import Inactivity

def reset_layers(keyboard):
    def _():
        keyboard.active_layers.clear()
        layers.activate_layer(keyboard, 0)

    return _

keyboard.modules.append( 
    Inactivity(timeout=60 * 1000, action=reset_layers)
)

The name "Inactivity" isn't great. Was too lazy to come up with something more descriptive.

If you test that and write some documentation we'll accept a PR.

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

No branches or pull requests

2 participants