Skip to content

Commit

Permalink
test for transition 6
Browse files Browse the repository at this point in the history
  • Loading branch information
sezanzeb committed Oct 16, 2024
1 parent fd0e005 commit 9a69df4
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def notify(
sub_handler_result = self._sub_handler.notify(event, source, suppress)

if is_pressed:
# If the sub-handler return True, it handled the event, so the user never
# sees this key-down event. In that case, we don't require a release event.
# Only if the sub-handler return False, we need a release-event later.
# If it handled the event, the user never sees this key-down event.
self.require_release_later(not sub_handler_result, event)
return sub_handler_result
else:
Expand Down
94 changes: 93 additions & 1 deletion tests/unit/test_event_pipeline/test_event_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
ABS_HAT0Y,
KEY_B,
KEY_C,
KEY_D,
BTN_TL,
KEY_1,
)
Expand Down Expand Up @@ -75,7 +76,7 @@ class EventPipelineTestBase(unittest.IsolatedAsyncioTestCase):
def setUp(self):
global_uinputs.is_service = True
global_uinputs.prepare_all()
self.forward_uinput = evdev.UInput()
self.forward_uinput = evdev.UInput(name="test-forward-uinput")
self.stop_event = asyncio.Event()

def tearDown(self) -> None:
Expand Down Expand Up @@ -597,6 +598,7 @@ async def test_suppressed_doesnt_forward_releases(self):
preset.add(mapping_2)

event_reader = self.create_event_reader(preset, origin)
# Trigger mapping_1, mapping_2 should be suppressed
await self.send_events(
[
InputEvent.key(KEY_A, 1, origin_hash),
Expand Down Expand Up @@ -624,6 +626,96 @@ async def test_suppressed_doesnt_forward_releases(self):
],
)

async def test_no_stuck_key(self):
origin = fixtures.foo_device_2_keyboard
origin_hash = origin.get_device_hash()

input_combination_1 = InputCombination(
[
InputConfig(
type=EV_KEY,
code=KEY_A,
origin_hash=origin_hash,
),
InputConfig(
type=EV_KEY,
code=KEY_B,
origin_hash=origin_hash,
),
InputConfig(
type=EV_KEY,
code=KEY_D,
origin_hash=origin_hash,
),
]
)

mapping_1 = Mapping(
input_combination=input_combination_1.to_config(),
target_uinput="keyboard",
output_symbol="1",
release_combination_keys=False,
)

input_combination_2 = InputCombination(
[
InputConfig(
type=EV_KEY,
code=KEY_C,
origin_hash=origin_hash,
),
InputConfig(
type=EV_KEY,
code=KEY_D,
origin_hash=origin_hash,
),
]
)

mapping_2 = Mapping(
input_combination=input_combination_2.to_config(),
target_uinput="keyboard",
output_symbol="2",
release_combination_keys=True,
)

preset = Preset()
preset.add(mapping_1)
preset.add(mapping_2)

event_reader = self.create_event_reader(preset, origin)
# Trigger mapping_1, mapping_2 should be suppressed
await self.send_events(
[
InputEvent.key(KEY_A, 1, origin_hash),
InputEvent.key(KEY_B, 1, origin_hash),
InputEvent.key(KEY_C, 1, origin_hash),
InputEvent.key(KEY_D, 1, origin_hash),
# Release c -> mapping_2 transitions from suppressed to passive.
# The release of c should be forwarded.
InputEvent.key(KEY_C, 0, origin_hash),
],
event_reader,
)

keyboard_history = global_uinputs.get_uinput("keyboard").write_history
forwarded_history = self.forward_uinput.write_history
self.assertListEqual(
forwarded_history,
[
(EV_KEY, KEY_A, 1),
(EV_KEY, KEY_B, 1),
(EV_KEY, KEY_C, 1),
(EV_KEY, KEY_C, 0),
],
)
self.assertListEqual(
keyboard_history,
[
(EV_KEY, KEY_1, 1),
],
)

async def test_ignore_hold(self):
# hold as in event-value 2, not in macro-hold.
# linux will generate events with value 2 after input-remapper injected
Expand Down

0 comments on commit 9a69df4

Please sign in to comment.