mirror of
https://github.com/sezanzeb/input-remapper
synced 2024-11-13 19:10:50 +00:00
Renamed EventProducer to JoystickToMouse
This commit is contained in:
parent
e13780a208
commit
d3c955fe04
@ -116,7 +116,7 @@ class Reader:
|
|||||||
the combination to get trimmed.
|
the combination to get trimmed.
|
||||||
"""
|
"""
|
||||||
# this is in some ways similar to the keycode_mapper and
|
# this is in some ways similar to the keycode_mapper and
|
||||||
# event_producer, but its much simpler because it doesn't
|
# joystick_to_mouse, but its much simpler because it doesn't
|
||||||
# have to trigger anything, manage any macros and only
|
# have to trigger anything, manage any macros and only
|
||||||
# reports key-down events. This function is called periodically
|
# reports key-down events. This function is called periodically
|
||||||
# by the window.
|
# by the window.
|
||||||
|
@ -26,14 +26,14 @@ import asyncio
|
|||||||
|
|
||||||
import evdev
|
import evdev
|
||||||
|
|
||||||
from keymapper.injection.consumers.event_producer import EventProducer
|
from keymapper.injection.consumers.joystick_to_mouse import JoystickToMouse
|
||||||
from keymapper.injection.consumers.keycode_mapper import KeycodeMapper
|
from keymapper.injection.consumers.keycode_mapper import KeycodeMapper
|
||||||
from keymapper.logger import logger
|
from keymapper.logger import logger
|
||||||
|
|
||||||
|
|
||||||
consumer_classes = [
|
consumer_classes = [
|
||||||
KeycodeMapper,
|
KeycodeMapper,
|
||||||
EventProducer,
|
JoystickToMouse,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ def abs_max(value_1, value_2):
|
|||||||
return value_2
|
return value_2
|
||||||
|
|
||||||
|
|
||||||
class EventProducer(Consumer):
|
class JoystickToMouse(Consumer):
|
||||||
"""Keeps producing events at 60hz if needed.
|
"""Keeps producing events at 60hz if needed.
|
||||||
|
|
||||||
Maps joysticks to mouse movements.
|
Maps joysticks to mouse movements.
|
@ -336,7 +336,7 @@ class Injector(multiprocessing.Process):
|
|||||||
# - SharedDict becomes obsolete
|
# - SharedDict becomes obsolete
|
||||||
# - quick_cleanup needs to be able to reliably stop the injection
|
# - quick_cleanup needs to be able to reliably stop the injection
|
||||||
# - I think I want an event listener architecture so that macros,
|
# - I think I want an event listener architecture so that macros,
|
||||||
# event_producer, keycode_mapper and possibly other modules can get
|
# joystick_to_mouse, keycode_mapper and possibly other modules can get
|
||||||
# what they filter for whenever they want, without having to wire
|
# what they filter for whenever they want, without having to wire
|
||||||
# things through multiple other objects all the time
|
# things through multiple other objects all the time
|
||||||
# - _new_event_arrived moves to the place where events are emitted. injector?
|
# - _new_event_arrived moves to the place where events are emitted. injector?
|
||||||
@ -352,7 +352,7 @@ class Injector(multiprocessing.Process):
|
|||||||
logger.info('Starting injecting the mapping for "%s"', self.group.key)
|
logger.info('Starting injecting the mapping for "%s"', self.group.key)
|
||||||
|
|
||||||
# create a new event loop, because somehow running an infinite loop
|
# create a new event loop, because somehow running an infinite loop
|
||||||
# that sleeps on iterations (event_producer) in one process causes
|
# that sleeps on iterations (joystick_to_mouse) in one process causes
|
||||||
# another injection process to screw up reading from the grabbed
|
# another injection process to screw up reading from the grabbed
|
||||||
# device.
|
# device.
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
|
@ -38,7 +38,11 @@ from evdev.ecodes import (
|
|||||||
from keymapper.config import config
|
from keymapper.config import config
|
||||||
from keymapper.mapping import Mapping
|
from keymapper.mapping import Mapping
|
||||||
from keymapper.injection.context import Context
|
from keymapper.injection.context import Context
|
||||||
from keymapper.injection.consumers.event_producer import EventProducer, MOUSE, WHEEL
|
from keymapper.injection.consumers.joystick_to_mouse import (
|
||||||
|
JoystickToMouse,
|
||||||
|
MOUSE,
|
||||||
|
WHEEL,
|
||||||
|
)
|
||||||
|
|
||||||
from tests.test import (
|
from tests.test import (
|
||||||
InputDevice,
|
InputDevice,
|
||||||
@ -55,7 +59,7 @@ from tests.test import (
|
|||||||
abs_state = [0, 0, 0, 0]
|
abs_state = [0, 0, 0, 0]
|
||||||
|
|
||||||
|
|
||||||
class TestEventProducer(unittest.IsolatedAsyncioTestCase):
|
class TestJoystickToMouse(unittest.IsolatedAsyncioTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
@ -67,7 +71,7 @@ class TestEventProducer(unittest.IsolatedAsyncioTestCase):
|
|||||||
self.context.uinput = uinput
|
self.context.uinput = uinput
|
||||||
|
|
||||||
source = InputDevice("/dev/input/event30")
|
source = InputDevice("/dev/input/event30")
|
||||||
self.event_producer = EventProducer(self.context, source)
|
self.joystick_to_mouse = JoystickToMouse(self.context, source)
|
||||||
|
|
||||||
config.set("gamepad.joystick.x_scroll_speed", 1)
|
config.set("gamepad.joystick.x_scroll_speed", 1)
|
||||||
config.set("gamepad.joystick.y_scroll_speed", 1)
|
config.set("gamepad.joystick.y_scroll_speed", 1)
|
||||||
@ -101,11 +105,11 @@ class TestEventProducer(unittest.IsolatedAsyncioTestCase):
|
|||||||
Depending on the configuration, the cursor or wheel should move.
|
Depending on the configuration, the cursor or wheel should move.
|
||||||
"""
|
"""
|
||||||
clear_write_history()
|
clear_write_history()
|
||||||
self.event_producer.context.update_purposes()
|
self.joystick_to_mouse.context.update_purposes()
|
||||||
await self.event_producer.notify(new_event(EV_ABS, ABS_X, a))
|
await self.joystick_to_mouse.notify(new_event(EV_ABS, ABS_X, a))
|
||||||
await self.event_producer.notify(new_event(EV_ABS, ABS_Y, b))
|
await self.joystick_to_mouse.notify(new_event(EV_ABS, ABS_Y, b))
|
||||||
await self.event_producer.notify(new_event(EV_ABS, ABS_RX, c))
|
await self.joystick_to_mouse.notify(new_event(EV_ABS, ABS_RX, c))
|
||||||
await self.event_producer.notify(new_event(EV_ABS, ABS_RY, d))
|
await self.joystick_to_mouse.notify(new_event(EV_ABS, ABS_RY, d))
|
||||||
|
|
||||||
# sleep long enough to test if multiple events are written
|
# sleep long enough to test if multiple events are written
|
||||||
await asyncio.sleep(5 / 60)
|
await asyncio.sleep(5 / 60)
|
||||||
@ -120,7 +124,7 @@ class TestEventProducer(unittest.IsolatedAsyncioTestCase):
|
|||||||
self.assertClose(history_entry[2], expectation[2], 0.1)
|
self.assertClose(history_entry[2], expectation[2], 0.1)
|
||||||
|
|
||||||
async def test_joystick_purpose_1(self):
|
async def test_joystick_purpose_1(self):
|
||||||
asyncio.ensure_future(self.event_producer.run())
|
asyncio.ensure_future(self.joystick_to_mouse.run())
|
||||||
|
|
||||||
speed = 20
|
speed = 20
|
||||||
self.mapping.set("gamepad.joystick.non_linearity", 1)
|
self.mapping.set("gamepad.joystick.non_linearity", 1)
|
||||||
@ -134,7 +138,7 @@ class TestEventProducer(unittest.IsolatedAsyncioTestCase):
|
|||||||
# which might be difficult to test.
|
# which might be difficult to test.
|
||||||
max_abs = 256
|
max_abs = 256
|
||||||
rest = 128 # resting position of the cursor
|
rest = 128 # resting position of the cursor
|
||||||
self.event_producer.set_abs_range(min_abs, max_abs)
|
self.joystick_to_mouse.set_abs_range(min_abs, max_abs)
|
||||||
|
|
||||||
await self.do(max_abs, rest, rest, rest, (EV_REL, REL_X, speed))
|
await self.do(max_abs, rest, rest, rest, (EV_REL, REL_X, speed))
|
||||||
await self.do(min_abs, rest, rest, rest, (EV_REL, REL_X, -speed))
|
await self.do(min_abs, rest, rest, rest, (EV_REL, REL_X, -speed))
|
||||||
@ -148,7 +152,7 @@ class TestEventProducer(unittest.IsolatedAsyncioTestCase):
|
|||||||
await self.do(rest, rest, rest, min_abs, (EV_REL, REL_WHEEL, 1))
|
await self.do(rest, rest, rest, min_abs, (EV_REL, REL_WHEEL, 1))
|
||||||
|
|
||||||
async def test_joystick_purpose_2(self):
|
async def test_joystick_purpose_2(self):
|
||||||
asyncio.ensure_future(self.event_producer.run())
|
asyncio.ensure_future(self.joystick_to_mouse.run())
|
||||||
|
|
||||||
speed = 30
|
speed = 30
|
||||||
config.set("gamepad.joystick.non_linearity", 1)
|
config.set("gamepad.joystick.non_linearity", 1)
|
||||||
@ -170,7 +174,7 @@ class TestEventProducer(unittest.IsolatedAsyncioTestCase):
|
|||||||
await self.do(0, 0, 0, MIN_ABS, (EV_REL, REL_Y, -speed))
|
await self.do(0, 0, 0, MIN_ABS, (EV_REL, REL_Y, -speed))
|
||||||
|
|
||||||
async def test_joystick_purpose_3(self):
|
async def test_joystick_purpose_3(self):
|
||||||
asyncio.ensure_future(self.event_producer.run())
|
asyncio.ensure_future(self.joystick_to_mouse.run())
|
||||||
|
|
||||||
speed = 40
|
speed = 40
|
||||||
self.mapping.set("gamepad.joystick.non_linearity", 1)
|
self.mapping.set("gamepad.joystick.non_linearity", 1)
|
||||||
@ -189,7 +193,7 @@ class TestEventProducer(unittest.IsolatedAsyncioTestCase):
|
|||||||
await self.do(0, 0, 0, MIN_ABS, (EV_REL, REL_Y, -speed))
|
await self.do(0, 0, 0, MIN_ABS, (EV_REL, REL_Y, -speed))
|
||||||
|
|
||||||
async def test_joystick_purpose_4(self):
|
async def test_joystick_purpose_4(self):
|
||||||
asyncio.ensure_future(self.event_producer.run())
|
asyncio.ensure_future(self.joystick_to_mouse.run())
|
||||||
|
|
||||||
config.set("gamepad.joystick.left_purpose", WHEEL)
|
config.set("gamepad.joystick.left_purpose", WHEEL)
|
||||||
config.set("gamepad.joystick.right_purpose", WHEEL)
|
config.set("gamepad.joystick.right_purpose", WHEEL)
|
||||||
|
@ -46,7 +46,7 @@ from evdev.ecodes import (
|
|||||||
KEY_C,
|
KEY_C,
|
||||||
)
|
)
|
||||||
|
|
||||||
from keymapper.injection.consumers.event_producer import EventProducer
|
from keymapper.injection.consumers.joystick_to_mouse import JoystickToMouse
|
||||||
from keymapper.injection.injector import (
|
from keymapper.injection.injector import (
|
||||||
Injector,
|
Injector,
|
||||||
is_in_capabilities,
|
is_in_capabilities,
|
||||||
@ -119,12 +119,12 @@ class TestInjector(unittest.IsolatedAsyncioTestCase):
|
|||||||
|
|
||||||
quick_cleanup()
|
quick_cleanup()
|
||||||
|
|
||||||
def find_event_producer(self):
|
def find_joystick_to_mouse(self):
|
||||||
# this object became somewhat a pain to retreive
|
# this object became somewhat a pain to retreive
|
||||||
return [
|
return [
|
||||||
consumer
|
consumer
|
||||||
for consumer in self.injector._consumer_controls[0]._consumers
|
for consumer in self.injector._consumer_controls[0]._consumers
|
||||||
if isinstance(consumer, EventProducer)
|
if isinstance(consumer, JoystickToMouse)
|
||||||
][0]
|
][0]
|
||||||
|
|
||||||
def test_grab(self):
|
def test_grab(self):
|
||||||
@ -471,7 +471,7 @@ class TestInjector(unittest.IsolatedAsyncioTestCase):
|
|||||||
self.assertEqual(history.count((EV_ABS, ABS_RZ, value)), 1)
|
self.assertEqual(history.count((EV_ABS, ABS_RZ, value)), 1)
|
||||||
|
|
||||||
@mock.patch("evdev.InputDevice.ungrab")
|
@mock.patch("evdev.InputDevice.ungrab")
|
||||||
def test_gamepad_to_mouse_event_producer(self, ungrab_patch):
|
def test_gamepad_to_mouse_joystick_to_mouse(self, ungrab_patch):
|
||||||
custom_mapping.set("gamepad.joystick.left_purpose", MOUSE)
|
custom_mapping.set("gamepad.joystick.left_purpose", MOUSE)
|
||||||
custom_mapping.set("gamepad.joystick.right_purpose", NONE)
|
custom_mapping.set("gamepad.joystick.right_purpose", NONE)
|
||||||
self.injector = Injector(groups.find(name="gamepad"), custom_mapping)
|
self.injector = Injector(groups.find(name="gamepad"), custom_mapping)
|
||||||
@ -485,13 +485,13 @@ class TestInjector(unittest.IsolatedAsyncioTestCase):
|
|||||||
self.assertIsNone(self.injector.context)
|
self.assertIsNone(self.injector.context)
|
||||||
|
|
||||||
# not in a process because this doesn't call start, so the
|
# not in a process because this doesn't call start, so the
|
||||||
# event_producer state can be checked
|
# joystick_to_mouse state can be checked
|
||||||
self.injector.run()
|
self.injector.run()
|
||||||
|
|
||||||
event_producer = self.find_event_producer()
|
joystick_to_mouse = self.find_joystick_to_mouse()
|
||||||
|
|
||||||
self.assertEqual(event_producer._abs_range[0], MIN_ABS)
|
self.assertEqual(joystick_to_mouse._abs_range[0], MIN_ABS)
|
||||||
self.assertEqual(event_producer._abs_range[1], MAX_ABS)
|
self.assertEqual(joystick_to_mouse._abs_range[1], MAX_ABS)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.injector.context.mapping.get("gamepad.joystick.left_purpose"), MOUSE
|
self.injector.context.mapping.get("gamepad.joystick.left_purpose"), MOUSE
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user