Skip to content
This repository has been archived by the owner on Dec 30, 2021. It is now read-only.

Commit

Permalink
#14 layer tap action
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Aug 29, 2020
1 parent bab3d01 commit 976e7ae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions action/action_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ class ActionType(Enum):
LayerOnAction = 3
LayerModAction = 4
LayerToggleAction = 5
LayerTapAction = 6
31 changes: 31 additions & 0 deletions action/layer_tap_action.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -710,3 +711,7 @@ def LM(layer, *modifiers):

def TG(layer):
return LayerToggleAction(layer)


def LT(layer, key):
return LayerTapAction(layer, key)

0 comments on commit 976e7ae

Please sign in to comment.