Merge pull request #125 from elvis-epx/master
Fix bug in TO layer key handling and add new API
This commit is contained in:
commit
f073b7568b
@ -77,7 +77,7 @@ def tg_pressed(key, state, *args, **kwargs):
|
|||||||
|
|
||||||
def to_pressed(key, state, *args, **kwargs):
|
def to_pressed(key, state, *args, **kwargs):
|
||||||
"""Activates layer and deactivates all other layers"""
|
"""Activates layer and deactivates all other layers"""
|
||||||
state.active_layers = [key.meta.kc]
|
state.active_layers = [key.meta.layer]
|
||||||
state.reversed_active_layers = list(reversed(state.active_layers))
|
state.reversed_active_layers = list(reversed(state.active_layers))
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
@ -67,8 +67,15 @@ class InternalState:
|
|||||||
else:
|
else:
|
||||||
timeout_key = ticks_ms() + after_ticks
|
timeout_key = ticks_ms() + after_ticks
|
||||||
|
|
||||||
|
while timeout_key in self.timeouts:
|
||||||
|
timeout_key += 1
|
||||||
|
|
||||||
self.timeouts[timeout_key] = callback
|
self.timeouts[timeout_key] = callback
|
||||||
return self
|
return timeout_key
|
||||||
|
|
||||||
|
def cancel_timeout(self, timeout_key):
|
||||||
|
if timeout_key in self.timeouts:
|
||||||
|
del self.timeouts[timeout_key]
|
||||||
|
|
||||||
def process_timeouts(self):
|
def process_timeouts(self):
|
||||||
if not self.timeouts:
|
if not self.timeouts:
|
||||||
|
16
kmk/keys.py
16
kmk/keys.py
@ -60,7 +60,8 @@ class Key:
|
|||||||
|
|
||||||
def _on_press(self, state, coord_int, coord_raw):
|
def _on_press(self, state, coord_int, coord_raw):
|
||||||
for fn in self._pre_press_handlers:
|
for fn in self._pre_press_handlers:
|
||||||
fn(self, state, KC, coord_int, coord_raw)
|
if not fn(self, state, KC, coord_int, coord_raw):
|
||||||
|
return None
|
||||||
|
|
||||||
ret = self._handle_press(self, state, KC, coord_int, coord_raw)
|
ret = self._handle_press(self, state, KC, coord_int, coord_raw)
|
||||||
|
|
||||||
@ -71,7 +72,8 @@ class Key:
|
|||||||
|
|
||||||
def _on_release(self, state, coord_int, coord_raw):
|
def _on_release(self, state, coord_int, coord_raw):
|
||||||
for fn in self._pre_release_handlers:
|
for fn in self._pre_release_handlers:
|
||||||
fn(self, state, KC, coord_int, coord_raw)
|
if not fn(self, state, KC, coord_int, coord_raw):
|
||||||
|
return None
|
||||||
|
|
||||||
ret = self._handle_release(self, state, KC, coord_int, coord_raw)
|
ret = self._handle_release(self, state, KC, coord_int, coord_raw)
|
||||||
|
|
||||||
@ -110,8 +112,9 @@ class Key:
|
|||||||
provided for consistency with the internal handlers)
|
provided for consistency with the internal handlers)
|
||||||
- coord_raw (an X,Y tuple of the matrix coordinate - also likely not useful)
|
- coord_raw (an X,Y tuple of the matrix coordinate - also likely not useful)
|
||||||
|
|
||||||
The return value of the provided callback is discarded. Exceptions are _not_
|
If return value of the provided callback is evaluated to False, press
|
||||||
caught, and will likely crash KMK if not handled within your function.
|
processing is cancelled. Exceptions are _not_ caught, and will likely
|
||||||
|
crash KMK if not handled within your function.
|
||||||
|
|
||||||
These handlers are run in attachment order: handlers provided by earlier
|
These handlers are run in attachment order: handlers provided by earlier
|
||||||
calls of this method will be executed before those provided by later calls.
|
calls of this method will be executed before those provided by later calls.
|
||||||
@ -156,8 +159,9 @@ class Key:
|
|||||||
provided for consistency with the internal handlers)
|
provided for consistency with the internal handlers)
|
||||||
- coord_raw (an X,Y tuple of the matrix coordinate - also likely not useful)
|
- coord_raw (an X,Y tuple of the matrix coordinate - also likely not useful)
|
||||||
|
|
||||||
The return value of the provided callback is discarded. Exceptions are _not_
|
If return value of the provided callback evaluates to False, the release
|
||||||
caught, and will likely crash KMK if not handled within your function.
|
processing is cancelled. Exceptions are _not_ caught, and will likely crash
|
||||||
|
KMK if not handled within your function.
|
||||||
|
|
||||||
These handlers are run in attachment order: handlers provided by earlier
|
These handlers are run in attachment order: handlers provided by earlier
|
||||||
calls of this method will be executed before those provided by later calls.
|
calls of this method will be executed before those provided by later calls.
|
||||||
|
Loading…
Reference in New Issue
Block a user