Only update the keymap cache if the layer state changed for real. If we turn a
layer that was already on, on again, we do not need to update. Same for turning
them off.
This results in a tiny speedup if we have code that calls `Layer.on()` or
`Layer.off()` often.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
When we change layers, we want to update the key cache for the whole keyboard,
so that LED modes and other things that depend on all keys being up-to-date will
work as expected.
Do the same at `Kaleidoscope.setup` time, so we start with a good state too.
This fixeskeyboardio/Kaleidoscope-Numlock#7.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
To find layer keys and layer keys only, we need to make sure that `key.flags`
has only these two bits set, and none of the others. Otherwise it may light up
keys as if they were layer keys, while they aren't, because they happen to have
`SYNTHETIC` and `SWITCH_TO_KEYMAP` set, `RESERVED` unset, but have other flags
that make the event handler loop treat them properly. Mouse keys are one such
thing.
Thanks to @ToyKeeper for reporting the issue!
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
We want to phase out `event_handler_hook_use` and `loop_hook_use`, so use the
new methods instead.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Use `Kaleiodscope.use` instead of `USE_PLUGINS` in both README and the example.
Also create a separate "Plugin properties" section in the former.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
If the `RESERVED` bit is set, that means the key is outside of the control of
the core firmware, and as such, can't be a normal layer key. As it happens,
`OSM(LeftControl)` (and other OSM keys) triggered this branch of code, and
resulted in one-shot modifiers getting highlighted too.
Thanks to @ToyKeeper for reporting the problem, and providing reproduction
steps.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
If we do not turn `should_cancel_` off, the next time one taps a one-shot key,
the flag will still be on (because nothing else turned it off, and it was set
before `hold_time_out_` happened, because the normal one-shot timeout is shorter
than that). If the flag is on, the loop hook will turn any and all one-shot
effects off.
In practice, this resulted in one-shot keys not working properly if they were
held for a longer period before.
Fixes#12, with many thanks to @ToyKeeper for finding and reporting the issue
with reproduction steps.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
We are trying to migrate to the former, so while I'm here, do so in this plugin,
so we can deprecate and remove `loop_hook_use` sooner.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Make it clear that layer keys are considered modifiers by the plugin.
While in that area, use `Kaleidoscope.use` instead of the now deprecated
`USE_PLUGINS` macro.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
The goal is to have a single `if` for checking if we should highlight a key, so
that we can later have an `else if` branch to highlight non-traditional
modifiers.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
To make it easier to extend the plugin, to teach it to highlight keys other than
the traditional modifiers, lift the code that checks for a modifier into its own
function.
No functional change, just refactoring.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
It may happen that we get passed an UNKNOWN_KEYSWITCH_LOCATION, which will
always be out of bounds. Lets not corrupt random memory when in this situation,
but instead, return quickly.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Uses mickeys (1/16th subpixel units) now instead of pixels. Much smoother!
Added "speedLimit" config var to set maximum cursor speed.
Ensured default values are sane.
For some odd reason, initializing it there crashes the firmware early on. Until
I figure out how to fix this, lets default to an implicit false.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Switch from the masking behaviour to repeating the symbol the key had when first
pressed.
This - along with the previous changes - fixes#158.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Instead of storing the layer for each key, store the keycode, so that lookups
are considerably faster (one array lookup instead of two). This saves us almost
a full millisecond per scan cycle. Furthermore, inline `Layer_.lookup`, saving
us even more time.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
This changes how key caching & lookup works: instead of updating the whole key
cache whenever we change the layer state, we update each key before they are
pressed or released. This allows us to have two different ways in which layers
can work:
- Keys still held when releasing the layer key will be masked out until they are
released. (This is the current behaviour)
- Keys held will repeat the keycode they had when they toggled on, even if the
layer key gets released prior to this other key, while other keys will not be
affected.
One can toggle between the two modes by setting
`Kaleidoscope.repeat_first_press` to `true` (second behaviour) or `false` (first
behaviour).
For now, the default behaviour is left unchanged.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
When we hold the OSL key, we do not need to mask out interruptors, because they
are not going to interrupt. As such, flip the `should_mask_on_interrupt_` bit on
OSL key release.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
As the enum is already namespaced, there is no need to include the
`KALEIDOSCOPE_` prefix in the first & safe start values. Do keep the prefixed
variant too, for the sake of backward compatibility.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
To make it easier to type a set of strings, apply some template magic to the
`Macros.type()` method. The same trick that is used in `Kaleidoscope.use()`.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Instead of computing the one-shot index when it is needed, compute it once at
the beginning. Even if we don't use it, we still save a few bytes by not
computing it in two branches.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>