diff --git a/action/action_type.py b/action/action_type.py index c04c4cc..419ae8c 100644 --- a/action/action_type.py +++ b/action/action_type.py @@ -7,3 +7,4 @@ class ActionType(Enum): LayerOnAction = 3 LayerModAction = 4 LayerToggleAction = 5 + LayerTapAction = 6 diff --git a/action/layer_tap_action.py b/action/layer_tap_action.py new file mode 100644 index 0000000..ef97d6e --- /dev/null +++ b/action/layer_tap_action.py @@ -0,0 +1,31 @@ +from evdev.events import KeyEvent + +import host +import mapper +from action.action_type import ActionType +from log import debug + + +class LayerTapAction: + type: ActionType + layer: int + key: int + + def __init__(self, layer, key): + self.type = ActionType.LayerTapAction + self.layer = layer + self.key = key + + def handle(self, ui, e, config, pos, *args): + debug('-- handling layer tap action --') + if e.value == KeyEvent.key_down: + debug(f'LT is pressed, enabling layer [{self.layer}]') + mapper.enable_layer(self.layer, self, config) + else: + debug(f'LT is released, disabling layer [{self.layer}]') + mapper.disable_layer(ui, self.layer, config) + since_last_press = (e.timestamp() - mapper.last_press_timestamps[pos]) * 1000 + debug(f'since last press: {since_last_press}') + if since_last_press <= config.tapping_term: + debug('writing key press') + host.write_tap(ui, self.key) diff --git a/key.py b/key.py index 7c2edeb..1d01ccb 100644 --- a/key.py +++ b/key.py @@ -2,6 +2,7 @@ from action.layer_mod_action import LayerModAction from action.layer_on_action import LayerOnAction +from action.layer_tap_action import LayerTapAction from action.layer_toggle_action import LayerToggleAction from action.mod_key_action import ModKeyAction from action.mod_tap_action import ModTapAction @@ -710,3 +711,7 @@ def LM(layer, *modifiers): def TG(layer): return LayerToggleAction(layer) + + +def LT(layer, key): + return LayerTapAction(layer, key)