Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored injection #263

Merged
merged 211 commits into from
Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
211 commits
Select commit Hold shift + click to select a range
19923e8
the ui no longer records keycodes if the preset is active
jonasBoss Jan 14, 2022
3740dfd
updated docstring
jonasBoss Jan 14, 2022
9e4f306
typing for injector.py
jonasBoss Jan 15, 2022
6f4857e
removed unused method from mapping
jonasBoss Jan 15, 2022
f938838
first implementation of refactored injector
jonasBoss Jan 16, 2022
2469473
created HirachyKeyHandler
jonasBoss Jan 16, 2022
8ecfb59
TODO
jonasBoss Jan 16, 2022
7ec8bc0
implemented _create_sorted_handlers
jonasBoss Jan 17, 2022
5d6374a
Merge branch 'main' into refactored-injection
jonasBoss Jan 17, 2022
c4f3cc5
added supress parameter to MappingHandler.notify
jonasBoss Jan 17, 2022
6754cc2
improved combination handling
jonasBoss Jan 17, 2022
8924dd5
forwarding release events before combinations trigger
jonasBoss Jan 17, 2022
cb93523
NO MORE STUCK KEYS
jonasBoss Jan 17, 2022
8068c96
disabled keycode_mapper
jonasBoss Jan 18, 2022
d0f80bd
updated order_keys method to take the common key in account
jonasBoss Jan 18, 2022
197ed15
Merge branch 'main' into refactored-injection
jonasBoss Jan 18, 2022
2c6df45
separeted responsibilities in mapping_handlers
jonasBoss Jan 18, 2022
76562c2
Support macros in new injection
jonasBoss Jan 19, 2022
bb8fbcd
created mapping_parser
jonasBoss Jan 20, 2022
cc1e6c3
improved readability, black
jonasBoss Jan 20, 2022
0306d50
Merge branch 'main' into refactored-injection
jonasBoss Jan 20, 2022
e36fa78
fixed logger
jonasBoss Jan 20, 2022
579c383
implemented a AbsToBtn handler
jonasBoss Jan 20, 2022
3df2c11
AbsToBtnHandler includen in mapping_parser
jonasBoss Jan 20, 2022
20c2f64
created custom logger for mapping_handlers
jonasBoss Jan 20, 2022
75d2530
cleand up some logging
jonasBoss Jan 20, 2022
adbba96
reworked the macro if_single function
jonasBoss Jan 21, 2022
59c30e5
added asyncio.sleep(0) after creation of listeners tasks
jonasBoss Jan 21, 2022
8a96a8c
added RelToBtnHandler
jonasBoss Jan 21, 2022
481670d
created AbsToRelHandler
jonasBoss Jan 22, 2022
a782017
implemented mouse handling with new handlers
jonasBoss Jan 22, 2022
e6c9a0e
Update inputremapper/injection/consumer_control.py
jonasBoss Jan 22, 2022
6ab12e1
Update inputremapper/injection/consumer_control.py
jonasBoss Jan 22, 2022
feaa6dd
indented asyncio.sleep in consumer_control
jonasBoss Jan 22, 2022
fcb0c52
Added geogebra link
jonasBoss Jan 22, 2022
27ccfdb
removed except in injector
jonasBoss Jan 22, 2022
46d32bd
fixed a random error with macro if_single
jonasBoss Jan 22, 2022
89edbc6
added comments
jonasBoss Jan 22, 2022
266d7e0
Merge branch 'main' into refactored-injection
jonasBoss Jan 22, 2022
9d1321e
WIP rename Mapping to Preset
jonasBoss Jan 23, 2022
2e334b7
Renamed Mapping to Preset
jonasBoss Jan 23, 2022
6d7acbf
some thoughts
sezanzeb Jan 23, 2022
2c05ed3
Merge remote-tracking branch 'jonasboss/refactored-injection' into re…
sezanzeb Jan 23, 2022
f533052
unused time
sezanzeb Jan 23, 2022
695a9a3
removed leftover debug logs
sezanzeb Jan 23, 2022
88f4e94
added comment
sezanzeb Jan 23, 2022
1f4201c
No longer chatch errors in macros.parse
jonasBoss Jan 23, 2022
c42f31e
merged presets.py into preset.py
jonasBoss Jan 23, 2022
fd69989
renamed the golobal config object to global_config
jonasBoss Jan 23, 2022
6aea79e
renamed the file containing global_config to global_config.py
jonasBoss Jan 23, 2022
43cf37e
moved global_config.py to configs/global_config.py
jonasBoss Jan 23, 2022
12a997a
moved files to configs directory
jonasBoss Jan 23, 2022
b7a7b47
created Mapping class
jonasBoss Jan 25, 2022
03d2ca2
ensuring order of syn events
sezanzeb Jan 26, 2022
4c34b40
Merge remote-tracking branch 'sezanzeb/refactored-injection-lkerjtlka…
jonasBoss Jan 26, 2022
22e5531
simplified if_single macro
jonasBoss Jan 26, 2022
be0d41c
Renamed ConsumerControl to EventReader
jonasBoss Jan 26, 2022
29ef908
split mapping_handlers into seperate files
jonasBoss Jan 26, 2022
0631d41
created InputEvent
jonasBoss Jan 26, 2022
34405c6
Better docstring in mapping_handler
jonasBoss Jan 27, 2022
27cd5c9
quick fix
jonasBoss Jan 27, 2022
31160e5
renamed Key to EventCombination
jonasBoss Jan 27, 2022
51553a2
Created new EventCombination as replacement for Key
jonasBoss Jan 28, 2022
e22c2a2
black
jonasBoss Jan 28, 2022
bc0a175
WIP rename Mapping to Preset
jonasBoss Jan 29, 2022
4d9400f
WIP
jonasBoss Jan 29, 2022
87378a0
rename Mapping to Preset
jonasBoss Jan 29, 2022
8524773
merged presets.py into preset.py
jonasBoss Jan 29, 2022
d7de413
renamed the golobal config object to global_config
jonasBoss Jan 29, 2022
539ce7a
renamed the file containing global_config to global_config.py
jonasBoss Jan 29, 2022
d6e40a1
moved global_config.py to configs/global_config.py
jonasBoss Jan 29, 2022
857ab0b
moved files to configs directory
jonasBoss Jan 29, 2022
7347cd9
created InputEvent
jonasBoss Jan 29, 2022
2ce1a9e
renamed Key to EventCombination
jonasBoss Jan 29, 2022
2a56208
Created new EventCombination as replacement for Key
jonasBoss Jan 29, 2022
b15bfd1
renamed some more stuff
jonasBoss Jan 29, 2022
4b7b66c
black
jonasBoss Jan 29, 2022
c3bc4ec
updated missed docstring
jonasBoss Jan 29, 2022
fa4e03d
Merge branch 'renaming-and-minor-stuff' into refactored-injection
jonasBoss Jan 29, 2022
3986317
WIP new preset
jonasBoss Jan 31, 2022
542699c
WIP new preset
jonasBoss Jan 31, 2022
8f35b2a
Merge branch 'main' into refactored-injection
jonasBoss Jan 31, 2022
a6f1051
created migration _convert_to_inidivual_mapping()
jonasBoss Jan 31, 2022
65dbb6c
WIP new mapping_parser
jonasBoss Feb 1, 2022
ff9bd49
updated CombinationHandler to work with the new mapping parser
jonasBoss Feb 1, 2022
aed3bc3
WIP rewoking handlers to use the mapping and work with the new mappin…
jonasBoss Feb 2, 2022
b83e3a7
WIP rework MappingHandlers
jonasBoss Feb 2, 2022
665f7ff
bug fixing
jonasBoss Feb 2, 2022
5167e3f
Added a action field to the InputEvent
jonasBoss Feb 2, 2022
fbae4f1
Merge branch 'main' into refactored-injection
jonasBoss Feb 2, 2022
74f084e
added macro_key_sleep_ms to mapping
jonasBoss Feb 3, 2022
7d0ccbc
run event pipeline synchronus
jonasBoss Feb 3, 2022
26e7eb7
WIP update UI
jonasBoss Feb 7, 2022
eef01db
Merge branch 'main' into refactored-injection
jonasBoss Feb 7, 2022
ee0da85
WIP UI
jonasBoss Feb 7, 2022
a3271b6
Merge branch 'main' into refactored-injection
jonasBoss Feb 7, 2022
15201da
more spacing
jonasBoss Feb 8, 2022
fa7b76c
Merge branch 'main' into refactored-injection
jonasBoss Feb 8, 2022
7b9ebca
some more GUI fixes
jonasBoss Feb 9, 2022
d9eec80
implemented a bad and hacky solution to add new mappings from the UI
jonasBoss Feb 12, 2022
17cff76
Merge branch 'main' into refactored-injection
jonasBoss Feb 12, 2022
4401ef4
some gui test fixes
jonasBoss Feb 16, 2022
4427740
UIMapping() now inherits from Mapping
jonasBoss Feb 18, 2022
9ea1d5a
GUI now directly manipulates a mapping object
jonasBoss Feb 20, 2022
755a992
small test changes
jonasBoss Mar 18, 2022
80a0a52
Merge branch 'main' into refactored-injection
jonasBoss Mar 18, 2022
13b76de
fix migration bug
jonasBoss Mar 18, 2022
7b5748e
Merge branch 'main' into refactored-injection
jonasBoss Mar 18, 2022
d1ccc0f
No longer use evdev.device.absinfo
jonasBoss Mar 18, 2022
916593f
fixed test_event_reader
jonasBoss Mar 18, 2022
9d09bc7
better context docstring
jonasBoss Mar 18, 2022
54a6188
fix missing return in HierarchyHandler.wrap_with()
jonasBoss Mar 18, 2022
83d67e9
fixed test_context
jonasBoss Mar 18, 2022
832ce94
fixed test_control
jonasBoss Mar 19, 2022
f85fd6f
Merge branch 'main' into refactored-injection
jonasBoss Mar 19, 2022
37fda83
fixed test_deamon
jonasBoss Mar 19, 2022
ff681e3
fixed test_dev_utils
jonasBoss Mar 19, 2022
c508ef6
deleted test_event_producer
jonasBoss Mar 20, 2022
3a5f726
fixed a modulo calculation error in abs_to_rel_handler
jonasBoss Mar 20, 2022
bc15d7b
updated test-fixture for InputDevice.capabilities
jonasBoss Mar 20, 2022
f4af8d5
fixed trigger condition in rel_to_btn handler
jonasBoss Mar 20, 2022
27a31e8
fixed test_injector
jonasBoss Mar 20, 2022
83b829a
removed triggering_event from Macro.press_trigger
jonasBoss Mar 20, 2022
5b330aa
fix a bug in macro._type_check
jonasBoss Mar 20, 2022
639f7f2
added a missing MacroParsingError
jonasBoss Mar 20, 2022
b895754
raise an exception if _parse_recurse() did not return a Macro instance
jonasBoss Mar 20, 2022
da36908
fixed test_macros
jonasBoss Mar 20, 2022
17e0ca0
reformated test_macros.TestMacros.test_raises_error
jonasBoss Mar 21, 2022
352483e
fix an error handling error in event_combination
jonasBoss Mar 21, 2022
488d3ab
allow invalid mappings to be saved and loaded by UIMapping
jonasBoss Mar 21, 2022
117e5b2
allow migratin of invalid mappings as long as the combination is valid
jonasBoss Mar 21, 2022
dae3107
fixed test_migrations
jonasBoss Mar 21, 2022
abbd316
removed macro and gampepad config from INITIAL_CONFIG
jonasBoss Mar 21, 2022
0871286
reworked saving and loading behaviour of preset
jonasBoss Mar 21, 2022
0a74905
fixed preset.dangerously_mapped_btn_left
jonasBoss Mar 22, 2022
3c16832
preset.removes fails now silently if mapping not found
jonasBoss Mar 22, 2022
2e19c20
fixed test_pereset
jonasBoss Mar 22, 2022
8bbac0b
fixed test_reader ???
jonasBoss Mar 22, 2022
32953ff
fixed test_config
jonasBoss Mar 22, 2022
aadf8c2
fixed test_presets
jonasBoss Mar 22, 2022
15b11e9
added pycharm configutation to run only unit tests
jonasBoss Mar 22, 2022
c0f85a7
moved and fixed test_if_single_joystick
jonasBoss Mar 22, 2022
c121915
added convinient function to convert test event history
jonasBoss Mar 22, 2022
50e484e
updated CombinationHandler
jonasBoss Mar 23, 2022
9046039
update RelToBtnHandler
jonasBoss Mar 23, 2022
6e2a337
reworked AbsToBtnHandler trigger logic
jonasBoss Mar 23, 2022
14e1e1a
fix threshold check in AbsToButtonHandler to include zero
jonasBoss Mar 23, 2022
02d27b1
added ABS_HAT0Y to gamepad fixture
jonasBoss Mar 23, 2022
3180a78
added NullHandler for disabled mappings
jonasBoss Mar 23, 2022
6be8fec
fixed CombinationHandler releaseing when not needed
jonasBoss Mar 23, 2022
2c6164a
fixed abs_to_button_handler not releasing when triggered by hat swithch
jonasBoss Mar 24, 2022
a578767
CombinationHandler no longer consumes events when not triggered
jonasBoss Mar 24, 2022
79b3513
fixed a bug in mapping parser
jonasBoss Mar 24, 2022
bbfbb5e
reworked rel_to_btn_handler logic
jonasBoss Mar 24, 2022
d45b7f4
New test_event_pipeline as replacement for test_keycode_mapper
jonasBoss Mar 24, 2022
cff9700
black
jonasBoss Mar 24, 2022
79b5709
Github actions
jonasBoss Mar 24, 2022
d54ba4b
Added a stupid hack to be compadible with ubuntus outdated pydantic v…
jonasBoss Mar 24, 2022
087c83b
black
jonasBoss Mar 24, 2022
c866809
Added more workarounds for old ubuntu versions
jonasBoss Mar 24, 2022
82c8e64
Updated wheel macro
jonasBoss Mar 26, 2022
6220f70
Updated Null Handler
jonasBoss Mar 26, 2022
7d15b9b
Updated Wheel macro
jonasBoss Mar 26, 2022
45da93a
less debug spam in rel_to_btn_handler
jonasBoss Mar 26, 2022
855650e
Use pkg_resources to parse the pydantic version
jonasBoss Mar 26, 2022
0a14495
exclude the ATTRIBUTES filed in the UIMapping.__eq__() method
jonasBoss Mar 26, 2022
eee7758
Fixed some UI bugs
jonasBoss Mar 26, 2022
31bd6a8
fixed some gui tests
jonasBoss Mar 26, 2022
c647cf9
added pycharm run configuration for integration tests
jonasBoss Mar 26, 2022
919eae4
fixed test_mouse macro test
jonasBoss Mar 26, 2022
5b7119f
black
jonasBoss Mar 26, 2022
03cbdf7
fixed incompatibility with old pydantic version
jonasBoss Mar 27, 2022
1a76d40
fixed a bug where asymetric abs axis would not trigger buttons correctly
jonasBoss Mar 27, 2022
9546c4d
rearranged mapping settings and adjusted abs_to_rel handler
jonasBoss Mar 27, 2022
7d4c702
adapted test_abs_to_rel to the new behaviour
jonasBoss Mar 27, 2022
5734b72
added test for REL_WHEEL event quirk
jonasBoss Mar 27, 2022
4ebdb62
implemented REL_WHEEL event quirk to the abs to rel handler
jonasBoss Mar 27, 2022
3f9554e
black
jonasBoss Mar 27, 2022
0f09d3f
created a dedicated handler for activating and deactivating of axis
jonasBoss Mar 28, 2022
fb723ee
unit tests for mapping
jonasBoss Mar 29, 2022
e64771a
fixed mapping to pass tests
jonasBoss Mar 29, 2022
e997281
more unit tests for preset
jonasBoss Mar 29, 2022
f72391b
fixed python unit test run config
jonasBoss Mar 30, 2022
621826f
fixed tests with older python and pydantic version
jonasBoss Mar 30, 2022
b2c5cd1
test Mappings obtained by mapping.copy()
jonasBoss Mar 30, 2022
1175ace
more pydantic backwards compatibility
jonasBoss Mar 30, 2022
17c20a7
fixed some mypy errors
jonasBoss Mar 31, 2022
3be7190
reformatting of mapping.py to make mypy happy
jonasBoss Apr 1, 2022
8f5595c
Updated type signature for EventCombination.__new__
jonasBoss Apr 1, 2022
93bfff1
custom Logger class for better type hints
jonasBoss Apr 1, 2022
943df86
added types-pkg_resources to reviewdog workflow
jonasBoss Apr 1, 2022
0768903
make mypy happy
jonasBoss Apr 2, 2022
2e8aa55
simplified order_combinations method
jonasBoss Apr 2, 2022
00d58cf
mypy happieness
jonasBoss Apr 2, 2022
cf58d58
Merge branch 'main' into refactored-injection
jonasBoss Apr 8, 2022
0338427
fix #296
jonasBoss Apr 10, 2022
341d5b7
Updated mapping_handler init method
jonasBoss Apr 11, 2022
47f7d5c
more migration tests
jonasBoss Apr 11, 2022
fff3906
removed unused method
jonasBoss Apr 11, 2022
f853bbd
move axis calculations to seperate class
jonasBoss Apr 11, 2022
dd9cf9d
Tests for axis transformation
jonasBoss Apr 13, 2022
368c025
more tests
jonasBoss Apr 13, 2022
1c7a6aa
Hiding irrelevant permission denied error log (#370)
sezanzeb Apr 16, 2022
43f1755
minor changes form code rewiew
jonasBoss Apr 16, 2022
1399f12
Merge branch 'main' into refactored-injection
jonasBoss Apr 16, 2022
09ae430
New test for the axis_switch_handler
jonasBoss Apr 16, 2022
eb4274a
Enable beta save folder
jonasBoss Apr 16, 2022
99440b9
update to a beta version
jonasBoss Apr 16, 2022
581e785
Updtated readme and usage
jonasBoss Apr 16, 2022
834bb9a
Implemented setting for #229
jonasBoss Apr 17, 2022
311a7ad
Updated usage with new mapping parameter
jonasBoss Apr 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ coverage.xml
.hypothesis/
.pytest_cache/

# pyreverse graphs
*.dot

# Translations
*.mo

Expand Down
7 changes: 6 additions & 1 deletion inputremapper/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,12 @@ def loads(self, dump):
"""Load a serialized representation created via dumps."""
self._groups = [_Group.loads(group) for group in json.loads(dump)]

def find(self, name=None, key=None, path=None, include_inputremapper=False):
def find(self,
name: str = None,
key: str = None,
path: str = None,
include_inputremapper: bool = False
) -> _Group:
"""Find a group that matches the provided parameters.

Parameters
Expand Down
37 changes: 27 additions & 10 deletions inputremapper/injection/consumer_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,27 @@


import asyncio

import evdev

from inputremapper.injection.consumers.joystick_to_mouse import JoystickToMouse
from inputremapper.injection.consumers.keycode_mapper import KeycodeMapper
from inputremapper.logger import logger

from inputremapper.injection.context import Context

consumer_classes = [
KeycodeMapper,
JoystickToMouse,
]

def copy_event(event: evdev.InputEvent) -> evdev.InputEvent:
return evdev.InputEvent(
sec=event.sec,
usec=event.usec,
type=event.type,
code=event.code,
value=event.value,
)


class ConsumerControl:
"""Reads input events from a single device and distributes them.
Expand All @@ -48,7 +56,11 @@ class ConsumerControl:
needs to be created multiple times.
"""

def __init__(self, context, source, forward_to):
def __init__(self,
context: Context,
source: evdev.InputDevice,
forward_to: evdev.UInput,
) -> None:
"""Initialize all consumers

Parameters
Expand All @@ -62,6 +74,7 @@ def __init__(self, context, source, forward_to):
"""
self._source = source
self._forward_to = forward_to
self.context = context

# add all consumers that are enabled for this particular configuration
self._consumers = []
Expand Down Expand Up @@ -93,17 +106,21 @@ async def run(self):
# won't appear, no need to forward or map them.
continue

tasks = []
for callback in self.context.callbacks:
tasks.append(callback(copy_event(event)))
results = await asyncio.gather(*tasks)

if True in results:
continue

# try legacy injection if the new injection did not do anything
# TODO: Remove. only keep the call to forward
sezanzeb marked this conversation as resolved.
Show resolved Hide resolved
handled = False
for consumer in self._consumers:
# copy so that the consumer doesn't screw this up for
# all other future consumers
event_copy = evdev.InputEvent(
sec=event.sec,
usec=event.usec,
type=event.type,
code=event.code,
value=event.value,
)
event_copy = copy_event(event)
if consumer.is_handled(event_copy):
await consumer.notify(event_copy)
handled = True
Expand Down
178 changes: 178 additions & 0 deletions inputremapper/injection/consumers/mapping_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# input-remapper - GUI for device specific keyboard mappings
# Copyright (C) 2022 sezanzeb <proxima@sezanzeb.de>
#
# This file is part of input-remapper.
#
# input-remapper is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# input-remapper is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.


"""Consumer base class.

Can be notified of new events so that inheriting classes can map them and
inject new events based on them.
"""
import copy
from typing import Dict, Tuple, Type, List

import evdev

from inputremapper import utils
from inputremapper.logger import logger
from inputremapper.system_mapping import system_mapping
from inputremapper.key import Key
from inputremapper.injection.global_uinputs import global_uinputs


class MappingHandler:
"""Can be notified of new events to inject them. Base class."""
_config: Dict[str, any]
_key: Key
_target: str

# hierarich mapping handlers e.g. KeysToKeyHandler will get sorted to make sure
# only one handler will receive the event. This allows mapping of combinations
# to override other combinations.
# Non hierarich handlers will always receive all events they care about
hierarich = False

def __init__(self, config_dict: Dict[str, any]) -> None:
"""Initialize event consuming functionality."""
self._config = copy.deepcopy(config_dict)
self._key = Key(self._config['key'])
self._target = self._config["target"]

def might_handle(self, event_type: int, event_code: int) -> bool:
"""Check if the handler cares about this at all"""
return self._key.contains_event(event_type, event_code)

async def notify(self, event: evdev.InputEvent) -> bool:
"""A new event is ready.

return if the event was actually taken care of

Overwrite this function if the consumer should do something each time
a new event arrives. E.g. mapping a single button once clicked.
"""
raise NotImplementedError

async def run(self) -> None:
"""Start doing things.

Overwrite this function if the consumer should do something
continuously even if no new event arrives. e.g. continuously injecting
mouse movement events.
"""
raise NotImplementedError

def inject(self, event_tuple: Tuple) -> None:
logger.debug("injecting form new mapping handler: %s", event_tuple)
global_uinputs.write(event_tuple, self._target)


class KeysToKeyHandler(MappingHandler):

_key_map: Dict[Tuple[int, int], bool]
_active: bool # keep track if the target key is pressed down
maps_to: Tuple[int, int]
hierarich = True

def __init__(self, config: Dict[str, any]) -> None:
super().__init__(config)

self._active = False
self._key_map = {}
for sub_key in self._key: # prepare key_map
self._key_map[sub_key[:2]] = False

self.maps_to = (evdev.ecodes.EV_KEY, system_mapping.get(self._config["symbol"]))

async def notify(self, event: evdev.InputEvent) -> bool:
map_key = (event.type, event.code)
if map_key not in self._key_map.keys():
return False # we are not responsible for the event

self._key_map[map_key] = event.value == 1
if self.get_active() == self._active:
return False # nothing changed ignore this event

self._active = self.get_active() and not utils.is_key_up(event.value)
if self._active:
value = 1
else:
value = 0

print("warum kommt der folgende key_spam nicht immer an?")
logger.key_spam(self._key, "maps to (%s)", self.maps_to)
self.inject((*self.maps_to, value))
return True

async def run(self) -> None: # no debouncer or anything (yet)
pass

def get_active(self) -> bool:
return False not in self._key_map.values()


class HierarchyHandler(MappingHandler):
"""handler consisting of an ordered list of KeysToKeyHandler

only the first handler which successfully handles a key_down event will execute the key_down.
All handlers receive key up events, but in reversed order.
"""
hierarich = False

def __init__(self, handlers: List[MappingHandler]) -> None:
cfg = {
"key": None,
"target": None,
}
super().__init__(cfg)
self.handlers = handlers

async def run(self) -> None:
pass

async def notify(self, event: evdev.InputEvent) -> bool:
if event.value == 1:
return self.handle_key_down(event)
else:
return self.handle_key_up(event)

def handle_key_up(self, event: evdev.InputEvent) -> bool:
success = False
for handler in self.handlers[::-1]:
success = await handler.notify(event)
return success

def handle_key_down(self, event: evdev.InputEvent) -> bool:
success = False
for handler in self.handlers:
success = await handler.notify(event)
if success:
break

return success


mapping_handler_classes: Dict[str, Type[MappingHandler]] = {
# all available mapping_handlers
"keys_to_key": KeysToKeyHandler,
}


def create_handler(config: Dict[str, any]) -> MappingHandler:
"""return the MappingHandler"""
return mapping_handler_classes[config['type']](config)
Loading