From 20dfe406c1d8fb4ddde3dcfc7e38414b7a039135 Mon Sep 17 00:00:00 2001 From: ivanjermakov Date: Fri, 28 Aug 2020 23:43:53 +0300 Subject: [PATCH] #14 refactoring --- action/layer_on_action.py | 8 ++++---- mapper.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/action/layer_on_action.py b/action/layer_on_action.py index e82ca89..c117926 100644 --- a/action/layer_on_action.py +++ b/action/layer_on_action.py @@ -1,6 +1,5 @@ from evdev.events import KeyEvent -import host import mapper from action.action_type import ActionType from log import debug @@ -14,8 +13,9 @@ def __init__(self, layer): self.type = ActionType.LayerOnAction self.layer = layer - def handle(self, ui, e, config, *args): + def handle(self, _, e, *args): debug('-- handling layer on action --') - mapper.active_layers[self.layer] = e.value == KeyEvent.key_down if e.value == KeyEvent.key_up: - host.release_layer_keys(ui, self.layer, config) + mapper.enable_layer(self.layer) + else: + mapper.disable_layer(self.layer) diff --git a/mapper.py b/mapper.py index 0f0f04b..1c30fcb 100644 --- a/mapper.py +++ b/mapper.py @@ -113,3 +113,14 @@ def find_key(pos, config): layer_key = layer[pos] if active_layers[layer_index] and layer_key != key.KC_TRANSPARENT: return layer_key, layer_index + + +def enable_layer(layer): + global active_layers + active_layers[layer] = True + + +def disable_layer(layer): + global active_layers + active_layers[layer] = False + host.release_layer_keys(ui, self.layer, config)