This repository has been archived by the owner on Dec 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from ivanjermakov/dev
Dev
- Loading branch information
Showing
20 changed files
with
555 additions
and
596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
|
||
|
||
class ActionType(Enum): | ||
""" | ||
Action type | ||
""" | ||
ModKeyAction = 1 | ||
ModTapAction = 2 | ||
LayerOnAction = 3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
from evdev.events import KeyEvent | ||
from evdev.events import InputEvent, KeyEvent | ||
|
||
from kbmap import mapper | ||
from kbmap.action.action_type import ActionType | ||
from kbmap.log import debug | ||
|
||
|
||
class KbmapToggleAction: | ||
""" | ||
Action used to toggle kbmap on and off. | ||
When kbmap is off, all mapped physical keys directly written to UInput, bypassing any mapping. | ||
""" | ||
|
||
type: ActionType | ||
|
||
def __init__(self): | ||
def __init__(self) -> None: | ||
self.type = ActionType.KbmapToggleAction | ||
|
||
def handle(self, _, e, *args): | ||
def handle(self, _, e: InputEvent, *args) -> None: | ||
debug('-- handling kbmap toggle action --') | ||
if e.value == KeyEvent.key_down: | ||
debug(f'now kbmap is {"enabled" if mapper.kbmap_enabled else "disabled"}') | ||
mapper.kbmap_enabled = not mapper.kbmap_enabled | ||
debug(f'toggle kbmap {"enabled" if mapper.kbmap_enabled else "disabled"}') | ||
else: | ||
debug('key release, skipping') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
from evdev import UInput | ||
from evdev.events import InputEvent | ||
from evdev.events import KeyEvent | ||
|
||
from kbmap import mapper | ||
from kbmap.action.action_type import ActionType | ||
from kbmap.config import Config | ||
from kbmap.log import debug | ||
|
||
|
||
class LayerOnAction: | ||
""" | ||
Layer on action. | ||
""" | ||
|
||
type: ActionType | ||
layer: int | ||
layer_index: int | ||
|
||
def __init__(self, layer): | ||
def __init__(self, layer_index: int) -> None: | ||
self.type = ActionType.LayerOnAction | ||
self.layer = layer | ||
self.layer_index = layer_index | ||
|
||
def handle(self, ui, e, config, *args): | ||
def handle(self, ui: UInput, e: InputEvent, config: Config, *args): | ||
debug('-- handling layer on action --') | ||
if e.value == KeyEvent.key_down: | ||
mapper.enable_layer(self.layer, self, config) | ||
mapper.enable_layer(self.layer_index, self, config) | ||
else: | ||
mapper.disable_layer(ui, self.layer, config) | ||
mapper.disable_layer(ui, self.layer_index, config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,51 @@ | ||
from evdev.events import KeyEvent | ||
from evdev import UInput | ||
from evdev.events import InputEvent, KeyEvent | ||
|
||
from kbmap import mapper, host | ||
from kbmap import host | ||
from kbmap import mapper | ||
from kbmap.action.action_type import ActionType | ||
from kbmap.config import Config | ||
from kbmap.log import debug | ||
|
||
|
||
class LayerTapAction: | ||
""" | ||
Layer tap action. | ||
""" | ||
|
||
type: ActionType | ||
layer: int | ||
key: int | ||
layer_index: int | ||
code: int | ||
used: bool | ||
|
||
def __init__(self, layer, key): | ||
def __init__(self, layer_index: int, code: int) -> None: | ||
self.type = ActionType.LayerTapAction | ||
self.layer = layer | ||
self.key = key | ||
self.layer_index = layer_index | ||
self.code = code | ||
self.used = False | ||
|
||
def __repr__(self): | ||
return f'LT({self.layer}, {self.key})' | ||
def __repr__(self) -> str: | ||
return f'LT({self.layer_index}, {self.code})' | ||
|
||
def handle(self, ui, e, config, pos, *args): | ||
def handle(self, ui: UInput, e: InputEvent, config: Config, pos: int, *args) -> None: | ||
debug('-- handling layer tap action --') | ||
if e.value == KeyEvent.key_down: | ||
mapper.active_tap_actions[pos] = self | ||
|
||
debug(f'LT is pressed, enabling layer [{self.layer}]') | ||
mapper.enable_layer(self.layer, self, config) | ||
debug(f'LT is pressed, enabling layer [{self.layer_index}]') | ||
mapper.enable_layer(self.layer_index, self, config) | ||
else: | ||
mapper.active_tap_actions.pop(pos) | ||
|
||
host.release_weak_keys(ui, config) | ||
debug(f'LT is released, disabling layer [{self.layer}]') | ||
debug(f'LT is released, disabling layer [{self.layer_index}]') | ||
|
||
mapper.disable_layer(ui, self.layer, config) | ||
mapper.disable_layer(ui, self.layer_index, config) | ||
|
||
since_last_press = (e.timestamp() - mapper.last_press_timestamps[pos]) * 1000 | ||
debug(f'since last press: {since_last_press}') | ||
debug(f'action is used: {self.used}') | ||
if not self.used and since_last_press <= config.tapping_term: | ||
debug('writing key press') | ||
host.write_tap(ui, self.key) | ||
host.write_tap(ui, self.code) | ||
self.used = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
from evdev.events import KeyEvent | ||
from evdev import UInput | ||
from evdev.events import InputEvent, KeyEvent | ||
|
||
from kbmap import mapper | ||
from kbmap.action.action_type import ActionType | ||
from kbmap.config import Config | ||
from kbmap.log import debug | ||
|
||
|
||
class LayerToggleAction: | ||
""" | ||
Layer toggle action. | ||
""" | ||
|
||
type: ActionType | ||
layer: int | ||
layer_index: int | ||
|
||
def __init__(self, layer, ): | ||
def __init__(self, layer_index: int) -> None: | ||
self.type = ActionType.LayerToggleAction | ||
self.layer = layer | ||
self.layer_index = layer_index | ||
|
||
def handle(self, ui, e, config, *args): | ||
def handle(self, ui: UInput, e: InputEvent, config: Config, *args) -> None: | ||
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) | ||
if mapper.active_layers[self.layer_index]: | ||
debug(f'disabling layer [{self.layer_index}]') | ||
mapper.disable_layer(ui, self.layer_index, config) | ||
else: | ||
debug(f'enabling layer [{self.layer}]') | ||
mapper.enable_layer(self.layer, self, config) | ||
debug(f'enabling layer [{self.layer_index}]') | ||
mapper.enable_layer(self.layer_index, self, config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,36 @@ | ||
from typing import Tuple | ||
from typing import * | ||
|
||
from evdev.events import KeyEvent | ||
from evdev import UInput | ||
from evdev.events import InputEvent, KeyEvent | ||
|
||
from kbmap import host | ||
from kbmap.action.action_type import ActionType | ||
from kbmap.log import debug | ||
|
||
|
||
class ModKeyAction: | ||
""" | ||
Mod key action. | ||
""" | ||
|
||
type: ActionType | ||
key: int | ||
code: Union[int, None] | ||
modifiers: Tuple[int, ...] | ||
|
||
def __init__(self, key, *modifiers): | ||
def __init__(self, code: Union[int, None], *modifiers) -> None: | ||
self.type = ActionType.ModKeyAction | ||
self.modifiers = modifiers | ||
self.key = key | ||
self.code = code | ||
|
||
def handle(self, ui, e, *args): | ||
def handle(self, ui: UInput, e: InputEvent, *args) -> None: | ||
debug('-- handling mod key action --') | ||
if e.value == KeyEvent.key_down: | ||
for m in self.modifiers: | ||
host.write_code(ui, m, e.value) | ||
if self.key: | ||
host.write_code(ui, self.key, e.value) | ||
if self.code: | ||
host.write_code(ui, self.code, e.value) | ||
else: | ||
if self.key: | ||
host.write_code(ui, self.key, e.value) | ||
if self.code: | ||
host.write_code(ui, self.code, e.value) | ||
for m in self.modifiers: | ||
host.write_code(ui, m, e.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.