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

Commit

Permalink
#14 layer toggle action; KC_NO
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Aug 29, 2020
1 parent 3c6c208 commit bab3d01
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions action/action_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ class ActionType(Enum):
ModTapAction = 2
LayerOnAction = 3
LayerModAction = 4
LayerToggleAction = 5
24 changes: 24 additions & 0 deletions action/layer_toggle_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from evdev.events import KeyEvent

import mapper
from action.action_type import ActionType
from log import debug


class LayerToggleAction:
type: ActionType
layer: int

def __init__(self, layer, ):
self.type = ActionType.LayerToggleAction
self.layer = layer

def handle(self, ui, e, config, *args):
debug('-- handling layer toggle action --')
if e.value == KeyEvent.key_down:
if mapper.active_layers[self.layer]:
debug(f'disabling layer [{self.layer}]')
mapper.disable_layer(ui, self.layer, config)
else:
debug(f'enabling layer [{self.layer}]')
mapper.enable_layer(self.layer, self, config)
4 changes: 2 additions & 2 deletions example/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
KC_TAB , KC_Q , KC_W , KC_E , KC_R , KC_T , KC_Y , KC_U , KC_I , KC_O , KC_P , KC_LBRC, KC_RBRC, KC_BSLS,
KC_CAPS, KC_A , KC_S , KC_D , KC_F , KC_G , KC_H , KC_J , KC_K , KC_L , KC_SCLN, KC_QUOT, KC_ENT ,
KC_LSFT, KC_Z , KC_X , KC_C , KC_V , KC_B , KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH, KC_RSFT, KC_UP ,
KC_LCTL, KC_LGUI, KC_LALT, LSFT_T(KC_SPC) , KC_RALT, KC_APP , KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT,
TG(1) , KC_LGUI, KC_LALT, LSFT_T(KC_SPC) , KC_RALT, KC_APP , KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT,
],
[
T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______,
T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______,
T______, T______, KC_A , T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______,
T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______,
T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______,
T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______, T______,
Expand Down
7 changes: 6 additions & 1 deletion key.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from action.layer_mod_action import LayerModAction
from action.layer_on_action import LayerOnAction
from action.layer_toggle_action import LayerToggleAction
from action.mod_key_action import ModKeyAction
from action.mod_tap_action import ModTapAction

# special keys

KC_NO = None
KC_NO = 999

KC_TRANSPARENT = None
KC_TRNS = KC_TRANSPARENT
Expand Down Expand Up @@ -705,3 +706,7 @@ def MO(layer):

def LM(layer, *modifiers):
return LayerModAction(layer, *modifiers)


def TG(layer):
return LayerToggleAction(layer)
10 changes: 8 additions & 2 deletions mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ def handle_event(e, kb, ui, config):
debug(f'key is mapped to action of type {key.type} at {pos}')
key.handle(ui, e, config, pos)
else:
debug(f'key is mapped to key: {ecodes.KEY[key]} ({key}) at {pos}')
debug(f'key is mapped to key: {get_key_name(key)} ({key}) at {pos}')
write_key(ui, key, e, layer_index, config)

update_timestamps(pos, e)


def get_key_name(key):
if key == 999:
return 'KC_NO'
return ecodes.KEY.get(key, "UNKNOWN")


def map_key_to_pos(code, config):
debug(f'looking for key {ecodes.KEY[code]} with code {code}')
try:
Expand Down Expand Up @@ -120,7 +126,7 @@ def find_key(pos, config):
def write_key(ui, key, e, layer, config):
global active_layers
active_layer = active_layers[layer]
if active_layer and active_layer.activator:
if active_layer and active_layer.activator and hasattr(active_layer.activator, 'handle_layer_key'):
active_layer.activator.handle_layer_key(ui, key, e, config)
else:
host.write_code(ui, key, e.value)
Expand Down

0 comments on commit bab3d01

Please sign in to comment.