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

Input event with origin #550

Merged
merged 37 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fdbe5d4
Update InputEvent to include origin and analog threshold
jonasBoss Nov 20, 2022
4738843
preset save file migration
jonasBoss Nov 20, 2022
df386bd
Merge branch 'beta' into input-event-with-origin
jonasBoss Nov 21, 2022
5b321f0
Use the InputEvent.analog_threshold field instead of value
jonasBoss Nov 22, 2022
fb1d407
Merge branch 'beta' into input-event-with-origin
jonasBoss Nov 24, 2022
56501b8
Make tests start in pycharm again
jonasBoss Nov 24, 2022
2fadc1f
Seperate InputEvent and InputConfiguration
jonasBoss Nov 24, 2022
db652a5
integration tests
jonasBoss Nov 26, 2022
3f6e81d
simplyfied InputEvent
jonasBoss Nov 26, 2022
af96ce1
move find_analog_input_event to InputCombination
jonasBoss Nov 26, 2022
53f2a49
rename InputConfiguration to InputConfig
jonasBoss Nov 26, 2022
b41bcce
move input_configuration.py to configs/input_config.py
jonasBoss Nov 26, 2022
0b88d79
simplified imports
jonasBoss Nov 26, 2022
e76c30b
rename event_combination to input_combination
jonasBoss Nov 26, 2022
705d97b
mypy
jonasBoss Dec 1, 2022
e518a05
use event origin information
jonasBoss Dec 2, 2022
0f724e4
fix reader-service and use md5 hashing
jonasBoss Dec 2, 2022
fc95635
Updated Mapping handlers
jonasBoss Dec 2, 2022
9da39c6
Updated Tests
jonasBoss Dec 2, 2022
2f168a1
Merge branch 'beta' into input-event-with-origin
jonasBoss Dec 6, 2022
11dce4c
fix test_injector
jonasBoss Dec 6, 2022
b7ca337
mypy
jonasBoss Dec 6, 2022
d67dd32
integration tests
jonasBoss Dec 7, 2022
c3b30cf
added unit tests
jonasBoss Dec 9, 2022
e5f0159
usage.md
jonasBoss Dec 10, 2022
9af4a59
refactor injector grab deviece logic
jonasBoss Dec 11, 2022
6c1d8f9
InputConfig docstring
jonasBoss Dec 11, 2022
6067285
refactor migrations._input_combination_from_string
jonasBoss Dec 11, 2022
f94e5e7
amend
jonasBoss Dec 11, 2022
61fe702
refactor temprary preset migration
jonasBoss Dec 11, 2022
5943fd0
made notify_callbacks private
jonasBoss Dec 12, 2022
925ffad
constrain origin to lowercase
jonasBoss Dec 12, 2022
7639422
tabs 'n spaces
jonasBoss Dec 12, 2022
7010955
mypy
jonasBoss Dec 12, 2022
aa3d868
mypy
jonasBoss Dec 13, 2022
699a6f8
Signal no longer inherits Message protocol
jonasBoss Dec 13, 2022
a1d1641
rename origin to origin_hash
jonasBoss Dec 14, 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
Prev Previous commit
Next Next commit
move find_analog_input_event to InputCombination
  • Loading branch information
jonasBoss committed Nov 26, 2022
commit af96ce1f77a72b9f12d5744742aaaf8b038ada5b
12 changes: 0 additions & 12 deletions inputremapper/configs/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
from inputremapper.gui.gettext import _
from inputremapper.gui.messages.message_types import MessageType
from inputremapper.injection.macros.parse import is_this_a_macro, parse
from inputremapper.input_event import InputEvent, EventActions

# TODO: remove pydantic VERSION check as soon as we no longer support
# Ubuntu 20.04 and with it the ancient pydantic 1.2
Expand Down Expand Up @@ -230,17 +229,6 @@ def is_axis_mapping(self) -> bool:
"""Whether this mapping specifies an output axis."""
return self.output_type in [EV_ABS, EV_REL]

def find_analog_input_event(
self, type_: Optional[int] = None
) -> Optional[InputConfiguration]:
"""Return the first event that defines an analog input"""
for input_config in self.event_combination:
if input_config.defines_analog_input and (
type_ is None or input_config.type == type_
):
return input_config
return None

def is_wheel_output(self) -> bool:
"""Check if this maps to wheel output."""
return self.output_code in (
Expand Down
20 changes: 10 additions & 10 deletions inputremapper/gui/components/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def __init__(
self,
message_broker: MessageBroker,
widget: Gtk.ToggleButton,
require_recorded_input: False,
require_recorded_input: bool,
):
self._widget = widget
self._default_tooltip = self._widget.get_tooltip_text()
Expand Down Expand Up @@ -778,15 +778,15 @@ def __init__(
self._message_broker = message_broker
self._controller = controller
self._gui = gui
self._event: Optional[InputEvent] = None
self._input_config: Optional[InputConfiguration] = None

self._gui.connect("state-set", self._on_gtk_toggle)
self._message_broker.subscribe(MessageType.selected_event, self._on_event)

def _on_event(self, input_cfg: InputConfiguration):
with HandlerDisabled(self._gui, self._on_gtk_toggle):
self._gui.set_active(input_cfg.defines_analog_input)
self._event = input_cfg
self._input_config = input_cfg

if input_cfg.type == EV_KEY:
self._gui.set_sensitive(False)
Expand All @@ -812,17 +812,17 @@ def __init__(
self._message_broker = message_broker
self._controller = controller
self._gui = gui
self._event: Optional[InputEvent] = None
self._input_config: Optional[InputConfiguration] = None

self._gui.set_increments(1, 1)
self._gui.connect("value-changed", self._on_gtk_changed)
self._message_broker.subscribe(MessageType.selected_event, self._on_event)

def _on_event(self, event: InputEvent):
if event.type == EV_KEY:
def _on_event(self, input_config: InputConfiguration):
if input_config.type == EV_KEY:
self._gui.set_sensitive(False)
self._gui.set_opacity(0.5)
elif event.type == EV_ABS:
elif input_config.type == EV_ABS:
self._gui.set_sensitive(True)
self._gui.set_opacity(1)
self._gui.set_range(-99, 99)
Expand All @@ -832,12 +832,12 @@ def _on_event(self, event: InputEvent):
self._gui.set_range(-999, 999)

with HandlerDisabled(self._gui, self._on_gtk_changed):
self._gui.set_value(event.analog_threshold or 0)
self._event = event
self._gui.set_value(input_config.analog_threshold or 0)
self._input_config = input_config

def _on_gtk_changed(self, *_):
self._controller.update_input_config(
self._event.modify(analog_threshold=int(self._gui.get_value()))
self._input_config.modify(analog_threshold=int(self._gui.get_value()))
)


Expand Down
4 changes: 3 additions & 1 deletion inputremapper/gui/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ def _get_ui_error_string(mapping: UIMapping) -> str:
)
if mapping.output_symbol is not None:
event = [
event for event in mapping.event_combination if event.value == 0
event
for event in mapping.event_combination
if event.defines_analog_input
][0]
message += _(
"\nIf you mean to create a key or macro mapping "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(

# find the input event we are supposed to map. If the input combination is
# BTN_A + ABS_X + BTN_B, then use the value of ABS_X for the transformation
assert (map_axis := mapping.find_analog_input_event(type_=EV_ABS))
assert (map_axis := combination.find_analog_input_config(type_=EV_ABS))
self._map_axis = map_axis.type_and_code

assert mapping.output_code is not None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __init__(
super().__init__(combination, mapping)

# find the input event we are supposed to map
assert (map_axis := mapping.find_analog_input_event(type_=EV_ABS))
assert (map_axis := combination.find_analog_input_config(type_=EV_ABS))
self._map_axis = map_axis.type_and_code

self._value = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(
if not event.defines_analog_input
]
assert len(trigger_keys) >= 1
assert (map_axis := mapping.find_analog_input_event())
assert (map_axis := combination.find_analog_input_config())
self._map_axis = map_axis.type_and_code
self._trigger_keys = tuple(trigger_keys)
self._active = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(

# find the input event we are supposed to map. If the input combination is
# BTN_A + REL_X + BTN_B, then use the value of REL_X for the transformation
assert (map_axis := mapping.find_analog_input_event(type_=EV_REL))
assert (map_axis := combination.find_analog_input_config(type_=EV_REL))
self._map_axis = map_axis.type_and_code

assert mapping.output_code is not None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(

# find the input event we are supposed to map. If the input combination is
# BTN_A + REL_X + BTN_B, then use the value of REL_X for the transformation
input_event = mapping.find_analog_input_event(type_=EV_REL)
input_event = combination.find_analog_input_config(type_=EV_REL)
assert input_event is not None
self._input_config = input_event

Expand Down
11 changes: 11 additions & 0 deletions inputremapper/input_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ def defines_analog_input(self) -> bool:
"""Check if there is any analog input in self."""
return True in filter(lambda i: i.defines_analog_input, self)

def find_analog_input_config(
self, type_: Optional[int] = None
) -> Optional[InputConfiguration]:
"""Return the first event that defines an analog input"""
for input_config in self:
if input_config.defines_analog_input and (
type_ is None or input_config.type == type_
):
return input_config
return None

def get_permutations(self) -> List[InputCombination]:
"""Get a list of EventCombinations representing all possible permutations.

Expand Down
31 changes: 29 additions & 2 deletions tests/unit/test_input_combination.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
BTN_C,
BTN_B,
BTN_A,
BTN_MIDDLE,
REL_X,
REL_Y,
REL_WHEEL,
REL_HWHEEL,
ABS_RY,
Expand All @@ -41,8 +44,6 @@
)

from inputremapper.input_configuration import InputCombination, InputConfiguration
from inputremapper.input_event import InputEvent

from tests.lib.fixtures import get_combination_config


Expand Down Expand Up @@ -205,6 +206,32 @@ def test_beautify(self):
"Button A + Button B + Button C",
)

def test_find_analog_input_config(self):
analog_input = InputConfiguration(type=EV_REL, code=REL_X)

combination = InputCombination(
(
InputConfiguration(type=EV_KEY, code=BTN_MIDDLE),
InputConfiguration(type=EV_REL, code=REL_Y, analog_threshold=1),
analog_input,
)
)
self.assertIsNone(combination.find_analog_input_config(type_=EV_ABS))
self.assertEqual(
combination.find_analog_input_config(type_=EV_REL), analog_input
)
self.assertEqual(combination.find_analog_input_config(), analog_input)

combination = InputCombination(
(
InputConfiguration(type=EV_REL, code=REL_X, analog_threshold=1),
InputConfiguration(type=EV_KEY, code=BTN_MIDDLE),
)
)
self.assertIsNone(combination.find_analog_input_config(type_=EV_ABS))
self.assertIsNone(combination.find_analog_input_config(type_=EV_REL))
self.assertIsNone(combination.find_analog_input_config())


if __name__ == "__main__":
unittest.main()
35 changes: 0 additions & 35 deletions tests/unit/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from inputremapper.configs.system_mapping import system_mapping, DISABLE_NAME
from inputremapper.input_configuration import InputCombination, InputConfiguration
from inputremapper.gui.messages.message_broker import MessageType
from inputremapper.input_event import EventActions, InputEvent


class TestMapping(unittest.IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -102,40 +101,6 @@ def test_is_wheel_output(self):
self.assertFalse(mapping.is_wheel_output())
self.assertTrue(mapping.is_high_res_wheel_output())

def test_find_analog_input_event(self):
analog_input = InputConfiguration(type=EV_REL, code=REL_X)

mapping = Mapping(
event_combination=InputCombination(
(
InputConfiguration(type=EV_KEY, code=BTN_MIDDLE),
InputConfiguration(type=EV_REL, code=REL_Y, analog_threshold=1),
analog_input,
)
),
target_uinput="keyboard",
output_type=EV_ABS,
output_code=ABS_X,
)
self.assertIsNone(mapping.find_analog_input_event(type_=EV_ABS))
self.assertEqual(mapping.find_analog_input_event(type_=EV_REL), analog_input)
self.assertEqual(mapping.find_analog_input_event(), analog_input)

mapping = Mapping(
event_combination=InputCombination(
(
InputConfiguration(type=EV_REL, code=REL_X, analog_threshold=1),
InputConfiguration(type=EV_KEY, code=BTN_MIDDLE),
)
),
target_uinput="keyboard",
output_type=EV_KEY,
output_code=KEY_A,
)
self.assertIsNone(mapping.find_analog_input_event(type_=EV_ABS))
self.assertIsNone(mapping.find_analog_input_event(type_=EV_REL))
self.assertIsNone(mapping.find_analog_input_event())

def test_get_output_type_code(self):
cfg = {
"event_combination": [{"type": 1, "code": 2}],
Expand Down