2021-12-15 14:06:23 +00:00
|
|
|
#
|
2022-01-01 12:00:49 +00:00
|
|
|
# input-remapper is free software: you can redistribute it and/or modify
|
2021-12-15 14:06:23 +00:00
|
|
|
# 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.
|
|
|
|
#
|
2022-01-01 12:00:49 +00:00
|
|
|
# input-remapper is distributed in the hope that it will be useful,
|
2021-12-15 14:06:23 +00:00
|
|
|
# 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
|
2022-01-01 12:00:49 +00:00
|
|
|
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
|
2022-04-17 10:19:23 +00:00
|
|
|
from inputremapper.configs.mapping import UIMapping, Mapping
|
2022-03-03 22:42:37 +00:00
|
|
|
from tests.test import quick_cleanup, tmp
|
|
|
|
|
2021-12-15 14:06:23 +00:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
import shutil
|
|
|
|
import json
|
|
|
|
|
2022-04-17 10:19:23 +00:00
|
|
|
from evdev.ecodes import (
|
|
|
|
EV_KEY,
|
|
|
|
EV_ABS,
|
|
|
|
ABS_HAT0X,
|
|
|
|
ABS_X,
|
|
|
|
ABS_Y,
|
|
|
|
ABS_RX,
|
|
|
|
ABS_RY,
|
|
|
|
EV_REL,
|
|
|
|
REL_X,
|
|
|
|
REL_Y,
|
|
|
|
REL_WHEEL_HI_RES,
|
|
|
|
REL_HWHEEL_HI_RES,
|
|
|
|
)
|
2021-12-15 14:06:23 +00:00
|
|
|
|
2022-01-31 19:58:37 +00:00
|
|
|
from inputremapper.configs.migrations import migrate, config_version
|
|
|
|
from inputremapper.configs.preset import Preset
|
|
|
|
from inputremapper.configs.global_config import global_config
|
|
|
|
from inputremapper.configs.paths import touch, CONFIG_PATH, mkdir, get_preset_path
|
2022-04-17 10:19:23 +00:00
|
|
|
from inputremapper.logger import IS_BETA
|
2022-01-31 19:58:37 +00:00
|
|
|
from inputremapper.event_combination import EventCombination
|
2022-01-01 12:00:49 +00:00
|
|
|
from inputremapper.user import HOME
|
2021-12-15 14:06:23 +00:00
|
|
|
|
2022-01-01 12:00:49 +00:00
|
|
|
from inputremapper.logger import VERSION
|
2021-12-15 14:06:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestMigrations(unittest.TestCase):
|
|
|
|
def tearDown(self):
|
|
|
|
quick_cleanup()
|
2022-01-31 19:58:37 +00:00
|
|
|
self.assertEqual(len(global_config.iterate_autoload_presets()), 0)
|
2021-12-15 14:06:23 +00:00
|
|
|
|
|
|
|
def test_migrate_suffix(self):
|
|
|
|
old = os.path.join(CONFIG_PATH, "config")
|
|
|
|
new = os.path.join(CONFIG_PATH, "config.json")
|
2022-01-01 12:00:49 +00:00
|
|
|
|
2021-12-15 14:06:23 +00:00
|
|
|
try:
|
|
|
|
os.remove(new)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
2022-01-01 12:00:49 +00:00
|
|
|
|
2021-12-15 14:06:23 +00:00
|
|
|
touch(old)
|
|
|
|
with open(old, "w") as f:
|
|
|
|
f.write("{}")
|
2022-01-01 12:00:49 +00:00
|
|
|
|
|
|
|
migrate()
|
|
|
|
self.assertTrue(os.path.exists(new))
|
|
|
|
self.assertFalse(os.path.exists(old))
|
|
|
|
|
|
|
|
def test_rename_config(self):
|
|
|
|
old = os.path.join(HOME, ".config", "key-mapper")
|
2022-04-17 10:19:23 +00:00
|
|
|
if IS_BETA:
|
|
|
|
new = os.path.join(*os.path.split(CONFIG_PATH)[:-1])
|
|
|
|
else:
|
|
|
|
new = CONFIG_PATH
|
2022-01-01 12:00:49 +00:00
|
|
|
|
|
|
|
# we are not destroying our actual config files with this test
|
2022-01-17 23:32:13 +00:00
|
|
|
self.assertTrue(new.startswith(tmp))
|
2022-01-01 12:00:49 +00:00
|
|
|
|
|
|
|
try:
|
2022-01-10 19:37:22 +00:00
|
|
|
shutil.rmtree(new)
|
2022-01-01 12:00:49 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
old_config_json = os.path.join(old, "config.json")
|
|
|
|
touch(old_config_json)
|
|
|
|
with open(old_config_json, "w") as f:
|
|
|
|
f.write('{"foo":"bar"}')
|
|
|
|
|
2021-12-15 14:06:23 +00:00
|
|
|
migrate()
|
2022-01-01 12:00:49 +00:00
|
|
|
|
2021-12-15 14:06:23 +00:00
|
|
|
self.assertTrue(os.path.exists(new))
|
|
|
|
self.assertFalse(os.path.exists(old))
|
|
|
|
|
2022-01-01 12:00:49 +00:00
|
|
|
new_config_json = os.path.join(new, "config.json")
|
|
|
|
with open(new_config_json, "r") as f:
|
|
|
|
moved_config = json.loads(f.read())
|
|
|
|
self.assertEqual(moved_config["foo"], "bar")
|
|
|
|
|
2021-12-15 14:06:23 +00:00
|
|
|
def test_wont_migrate_suffix(self):
|
|
|
|
old = os.path.join(CONFIG_PATH, "config")
|
|
|
|
new = os.path.join(CONFIG_PATH, "config.json")
|
|
|
|
|
|
|
|
touch(new)
|
|
|
|
with open(new, "w") as f:
|
|
|
|
f.write("{}")
|
|
|
|
|
|
|
|
touch(old)
|
|
|
|
with open(old, "w") as f:
|
|
|
|
f.write("{}")
|
|
|
|
|
|
|
|
migrate()
|
|
|
|
self.assertTrue(os.path.exists(new))
|
|
|
|
self.assertTrue(os.path.exists(old))
|
|
|
|
|
|
|
|
def test_migrate_preset(self):
|
2022-04-17 10:19:23 +00:00
|
|
|
if os.path.exists(CONFIG_PATH):
|
|
|
|
shutil.rmtree(CONFIG_PATH)
|
2021-12-15 14:06:23 +00:00
|
|
|
|
2022-04-17 10:19:23 +00:00
|
|
|
p1 = os.path.join(CONFIG_PATH, "foo1", "bar1.json")
|
|
|
|
p2 = os.path.join(CONFIG_PATH, "foo2", "bar2.json")
|
2021-12-15 14:06:23 +00:00
|
|
|
touch(p1)
|
|
|
|
touch(p2)
|
|
|
|
|
|
|
|
with open(p1, "w") as f:
|
|
|
|
f.write("{}")
|
|
|
|
|
|
|
|
with open(p2, "w") as f:
|
|
|
|
f.write("{}")
|
|
|
|
|
|
|
|
migrate()
|
|
|
|
|
2022-04-17 10:19:23 +00:00
|
|
|
self.assertFalse(os.path.exists(os.path.join(CONFIG_PATH, "foo1", "bar1.json")))
|
|
|
|
self.assertFalse(os.path.exists(os.path.join(CONFIG_PATH, "foo2", "bar2.json")))
|
2021-12-15 14:06:23 +00:00
|
|
|
|
|
|
|
self.assertTrue(
|
2022-04-18 11:52:59 +00:00
|
|
|
os.path.exists(os.path.join(CONFIG_PATH, "presets", "foo1", "bar1.json")),
|
2021-12-15 14:06:23 +00:00
|
|
|
)
|
|
|
|
self.assertTrue(
|
2022-04-18 11:52:59 +00:00
|
|
|
os.path.exists(os.path.join(CONFIG_PATH, "presets", "foo2", "bar2.json")),
|
2021-12-15 14:06:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_wont_migrate_preset(self):
|
2022-04-17 10:19:23 +00:00
|
|
|
if os.path.exists(CONFIG_PATH):
|
|
|
|
shutil.rmtree(CONFIG_PATH)
|
2021-12-15 14:06:23 +00:00
|
|
|
|
2022-04-17 10:19:23 +00:00
|
|
|
p1 = os.path.join(CONFIG_PATH, "foo1", "bar1.json")
|
|
|
|
p2 = os.path.join(CONFIG_PATH, "foo2", "bar2.json")
|
2021-12-15 14:06:23 +00:00
|
|
|
touch(p1)
|
|
|
|
touch(p2)
|
|
|
|
|
|
|
|
with open(p1, "w") as f:
|
|
|
|
f.write("{}")
|
|
|
|
|
|
|
|
with open(p2, "w") as f:
|
|
|
|
f.write("{}")
|
|
|
|
|
|
|
|
# already migrated
|
2022-04-17 10:19:23 +00:00
|
|
|
mkdir(os.path.join(CONFIG_PATH, "presets"))
|
2021-12-15 14:06:23 +00:00
|
|
|
|
|
|
|
migrate()
|
|
|
|
|
2022-04-17 10:19:23 +00:00
|
|
|
self.assertTrue(os.path.exists(os.path.join(CONFIG_PATH, "foo1", "bar1.json")))
|
|
|
|
self.assertTrue(os.path.exists(os.path.join(CONFIG_PATH, "foo2", "bar2.json")))
|
2021-12-15 14:06:23 +00:00
|
|
|
|
|
|
|
self.assertFalse(
|
2022-04-18 11:52:59 +00:00
|
|
|
os.path.exists(os.path.join(CONFIG_PATH, "presets", "foo1", "bar1.json")),
|
2021-12-15 14:06:23 +00:00
|
|
|
)
|
|
|
|
self.assertFalse(
|
2022-04-18 11:52:59 +00:00
|
|
|
os.path.exists(os.path.join(CONFIG_PATH, "presets", "foo2", "bar2.json")),
|
2021-12-15 14:06:23 +00:00
|
|
|
)
|
|
|
|
|
2022-01-14 17:50:57 +00:00
|
|
|
def test_migrate_mappings(self):
|
2022-04-18 11:52:59 +00:00
|
|
|
"""Test if mappings are migrated correctly
|
2022-01-14 17:50:57 +00:00
|
|
|
|
|
|
|
mappings like
|
2022-04-17 10:19:23 +00:00
|
|
|
{(type, code): symbol} or {(type, code, value): symbol} should migrate
|
|
|
|
to {EventCombination: {target: target, symbol: symbol, ...}}
|
2022-01-14 17:50:57 +00:00
|
|
|
"""
|
2022-04-17 10:19:23 +00:00
|
|
|
path = os.path.join(CONFIG_PATH, "presets", "Foo Device", "test.json")
|
2021-12-15 14:06:23 +00:00
|
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
|
|
with open(path, "w") as file:
|
|
|
|
json.dump(
|
|
|
|
{
|
|
|
|
"mapping": {
|
2022-01-14 17:50:57 +00:00
|
|
|
f"{EV_KEY},1": "a",
|
|
|
|
f"{EV_KEY}, 2, 1": "BTN_B", # can be mapped to "gamepad"
|
|
|
|
f"{EV_KEY}, 3, 1": "BTN_1", # can not be mapped
|
2021-12-15 14:06:23 +00:00
|
|
|
f"{EV_ABS},{ABS_HAT0X},-1": "b",
|
|
|
|
f"{EV_ABS},1,1+{EV_ABS},2,-1+{EV_ABS},3,1": "c",
|
2022-04-17 10:19:23 +00:00
|
|
|
f"{EV_KEY}, 4, 1": ("d", "keyboard"),
|
|
|
|
f"{EV_KEY}, 5, 1": ("e", "foo"), # unknown target
|
|
|
|
f"{EV_KEY}, 6, 1": ("key(a, b)", "keyboard"), # broken macro
|
2021-12-15 14:06:23 +00:00
|
|
|
# ignored because broken
|
|
|
|
f"3,1,1,2": "e",
|
|
|
|
f"3": "e",
|
|
|
|
f",,+3,1,2": "g",
|
|
|
|
f"": "h",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
file,
|
|
|
|
)
|
|
|
|
migrate()
|
2022-04-17 10:19:23 +00:00
|
|
|
# use UIMapping to also load invalid mappings
|
|
|
|
preset = Preset(get_preset_path("Foo Device", "test"), UIMapping)
|
|
|
|
preset.load()
|
2022-01-14 17:50:57 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
2022-04-17 10:19:23 +00:00
|
|
|
preset.get_mapping(EventCombination([EV_KEY, 1, 1])),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination([EV_KEY, 1, 1]),
|
|
|
|
target_uinput="keyboard",
|
|
|
|
output_symbol="a",
|
|
|
|
),
|
2022-01-31 19:58:37 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-04-17 10:19:23 +00:00
|
|
|
preset.get_mapping(EventCombination([EV_KEY, 2, 1])),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination([EV_KEY, 2, 1]),
|
|
|
|
target_uinput="gamepad",
|
|
|
|
output_symbol="BTN_B",
|
|
|
|
),
|
2022-01-31 19:58:37 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-04-17 10:19:23 +00:00
|
|
|
preset.get_mapping(EventCombination([EV_KEY, 3, 1])),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination([EV_KEY, 3, 1]),
|
|
|
|
target_uinput="keyboard",
|
|
|
|
output_symbol="BTN_1\n# Broken mapping:\n# No target can handle all specified keycodes",
|
2022-01-14 17:50:57 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-04-17 10:19:23 +00:00
|
|
|
preset.get_mapping(EventCombination([EV_KEY, 4, 1])),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination([EV_KEY, 4, 1]),
|
|
|
|
target_uinput="keyboard",
|
|
|
|
output_symbol="d",
|
|
|
|
),
|
2022-01-14 17:50:57 +00:00
|
|
|
)
|
2021-12-15 14:06:23 +00:00
|
|
|
self.assertEqual(
|
2022-04-17 10:19:23 +00:00
|
|
|
preset.get_mapping(EventCombination([EV_ABS, ABS_HAT0X, -1])),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination([EV_ABS, ABS_HAT0X, -1]),
|
|
|
|
target_uinput="keyboard",
|
|
|
|
output_symbol="b",
|
|
|
|
),
|
2022-01-31 19:58:37 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-04-17 10:19:23 +00:00
|
|
|
preset.get_mapping(
|
2022-04-18 11:52:59 +00:00
|
|
|
EventCombination(((EV_ABS, 1, 1), (EV_ABS, 2, -1), (EV_ABS, 3, 1))),
|
2022-04-17 10:19:23 +00:00
|
|
|
),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination(
|
2022-04-18 11:52:59 +00:00
|
|
|
((EV_ABS, 1, 1), (EV_ABS, 2, -1), (EV_ABS, 3, 1)),
|
2022-04-17 10:19:23 +00:00
|
|
|
),
|
|
|
|
target_uinput="keyboard",
|
|
|
|
output_symbol="c",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
preset.get_mapping(EventCombination([EV_KEY, 5, 1])),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination([EV_KEY, 5, 1]),
|
|
|
|
target_uinput="foo",
|
|
|
|
output_symbol="e",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
preset.get_mapping(EventCombination([EV_KEY, 6, 1])),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination([EV_KEY, 6, 1]),
|
|
|
|
target_uinput="keyboard",
|
|
|
|
output_symbol="key(a, b)",
|
2022-01-31 19:58:37 +00:00
|
|
|
),
|
2021-12-15 14:06:23 +00:00
|
|
|
)
|
|
|
|
|
2022-04-17 10:19:23 +00:00
|
|
|
self.assertEqual(8, len(preset))
|
2022-03-03 22:42:37 +00:00
|
|
|
|
2022-02-08 14:53:59 +00:00
|
|
|
def test_migrate_otherwise(self):
|
2022-04-17 10:19:23 +00:00
|
|
|
path = os.path.join(CONFIG_PATH, "presets", "Foo Device", "test.json")
|
2022-02-08 14:53:59 +00:00
|
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
|
|
with open(path, "w") as file:
|
|
|
|
json.dump(
|
|
|
|
{
|
|
|
|
"mapping": {
|
|
|
|
f"{EV_KEY},1,1": ("otherwise + otherwise", "keyboard"),
|
|
|
|
f"{EV_KEY},2,1": ("bar($otherwise)", "keyboard"),
|
|
|
|
f"{EV_KEY},3,1": ("foo(otherwise=qux)", "keyboard"),
|
|
|
|
f"{EV_KEY},4,1": ("qux(otherwise).bar(otherwise = 1)", "foo"),
|
|
|
|
f"{EV_KEY},5,1": ("foo(otherwise1=2qux)", "keyboard"),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
file,
|
|
|
|
)
|
|
|
|
|
|
|
|
migrate()
|
|
|
|
|
2022-04-17 10:19:23 +00:00
|
|
|
preset = Preset(get_preset_path("Foo Device", "test"), UIMapping)
|
|
|
|
preset.load()
|
2022-02-08 14:53:59 +00:00
|
|
|
|
|
|
|
self.assertEqual(
|
2022-04-17 10:19:23 +00:00
|
|
|
preset.get_mapping(EventCombination([EV_KEY, 1, 1])),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination([EV_KEY, 1, 1]),
|
|
|
|
target_uinput="keyboard",
|
|
|
|
output_symbol="otherwise + otherwise",
|
|
|
|
),
|
2022-02-08 14:53:59 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-04-17 10:19:23 +00:00
|
|
|
preset.get_mapping(EventCombination([EV_KEY, 2, 1])),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination([EV_KEY, 2, 1]),
|
|
|
|
target_uinput="keyboard",
|
|
|
|
output_symbol="bar($otherwise)",
|
|
|
|
),
|
2022-02-08 14:53:59 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-04-17 10:19:23 +00:00
|
|
|
preset.get_mapping(EventCombination([EV_KEY, 3, 1])),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination([EV_KEY, 3, 1]),
|
|
|
|
target_uinput="keyboard",
|
|
|
|
output_symbol="foo(else=qux)",
|
|
|
|
),
|
2022-02-08 14:53:59 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-04-17 10:19:23 +00:00
|
|
|
preset.get_mapping(EventCombination([EV_KEY, 4, 1])),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination([EV_KEY, 4, 1]),
|
|
|
|
target_uinput="foo",
|
|
|
|
output_symbol="qux(otherwise).bar(else=1)",
|
|
|
|
),
|
2022-02-08 14:53:59 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2022-04-17 10:19:23 +00:00
|
|
|
preset.get_mapping(EventCombination([EV_KEY, 5, 1])),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination([EV_KEY, 5, 1]),
|
|
|
|
target_uinput="keyboard",
|
|
|
|
output_symbol="foo(otherwise1=2qux)",
|
|
|
|
),
|
2022-02-08 14:53:59 +00:00
|
|
|
)
|
|
|
|
|
2021-12-15 14:06:23 +00:00
|
|
|
def test_add_version(self):
|
|
|
|
path = os.path.join(CONFIG_PATH, "config.json")
|
|
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
|
|
with open(path, "w") as file:
|
|
|
|
file.write("{}")
|
|
|
|
|
|
|
|
migrate()
|
|
|
|
self.assertEqual(VERSION, config_version().public)
|
|
|
|
|
|
|
|
def test_update_version(self):
|
|
|
|
path = os.path.join(CONFIG_PATH, "config.json")
|
|
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
|
|
with open(path, "w") as file:
|
|
|
|
json.dump({"version": "0.1.0"}, file)
|
|
|
|
|
|
|
|
migrate()
|
|
|
|
self.assertEqual(VERSION, config_version().public)
|
|
|
|
|
|
|
|
def test_config_version(self):
|
|
|
|
path = os.path.join(CONFIG_PATH, "config.json")
|
|
|
|
with open(path, "w") as file:
|
|
|
|
file.write("{}")
|
2022-02-08 14:53:59 +00:00
|
|
|
|
2021-12-15 14:06:23 +00:00
|
|
|
self.assertEqual("0.0.0", config_version().public)
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.remove(path)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
2022-02-08 14:53:59 +00:00
|
|
|
|
2021-12-15 14:06:23 +00:00
|
|
|
self.assertEqual("0.0.0", config_version().public)
|
|
|
|
|
2022-04-17 10:19:23 +00:00
|
|
|
def test_migrate_left_and_right_purpose(self):
|
|
|
|
path = os.path.join(CONFIG_PATH, "presets", "Foo Device", "test.json")
|
|
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
|
|
with open(path, "w") as file:
|
|
|
|
json.dump(
|
|
|
|
{
|
|
|
|
"gamepad": {
|
|
|
|
"joystick": {
|
|
|
|
"left_purpose": "mouse",
|
|
|
|
"right_purpose": "wheel",
|
|
|
|
"pointer_speed": 50,
|
|
|
|
"x_scroll_speed": 10,
|
|
|
|
"y_scroll_speed": 20,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
file,
|
|
|
|
)
|
|
|
|
migrate()
|
|
|
|
|
|
|
|
preset = Preset(get_preset_path("Foo Device", "test"), UIMapping)
|
|
|
|
preset.load()
|
|
|
|
# 2 mappings for mouse
|
|
|
|
# 2 mappings for wheel
|
|
|
|
self.assertEqual(len(preset), 4)
|
|
|
|
self.assertEqual(
|
|
|
|
preset.get_mapping(EventCombination((EV_ABS, ABS_X, 0))),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination((EV_ABS, ABS_X, 0)),
|
|
|
|
target_uinput="mouse",
|
|
|
|
output_type=EV_REL,
|
|
|
|
output_code=REL_X,
|
|
|
|
gain=50 / 100,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
preset.get_mapping(EventCombination((EV_ABS, ABS_Y, 0))),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination((EV_ABS, ABS_Y, 0)),
|
|
|
|
target_uinput="mouse",
|
|
|
|
output_type=EV_REL,
|
|
|
|
output_code=REL_Y,
|
|
|
|
gain=50 / 100,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
preset.get_mapping(EventCombination((EV_ABS, ABS_RX, 0))),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination((EV_ABS, ABS_RX, 0)),
|
|
|
|
target_uinput="mouse",
|
|
|
|
output_type=EV_REL,
|
|
|
|
output_code=REL_HWHEEL_HI_RES,
|
|
|
|
gain=10,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
preset.get_mapping(EventCombination((EV_ABS, ABS_RY, 0))),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination((EV_ABS, ABS_RY, 0)),
|
|
|
|
target_uinput="mouse",
|
|
|
|
output_type=EV_REL,
|
|
|
|
output_code=REL_WHEEL_HI_RES,
|
|
|
|
gain=20,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_migrate_left_and_right_purpose2(self):
|
|
|
|
# same as above, but left and right is swapped
|
|
|
|
|
|
|
|
path = os.path.join(CONFIG_PATH, "presets", "Foo Device", "test.json")
|
|
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
|
|
with open(path, "w") as file:
|
|
|
|
json.dump(
|
|
|
|
{
|
|
|
|
"gamepad": {
|
|
|
|
"joystick": {
|
|
|
|
"right_purpose": "mouse",
|
|
|
|
"left_purpose": "wheel",
|
|
|
|
"pointer_speed": 50,
|
|
|
|
"x_scroll_speed": 10,
|
|
|
|
"y_scroll_speed": 20,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
file,
|
|
|
|
)
|
|
|
|
migrate()
|
|
|
|
|
|
|
|
preset = Preset(get_preset_path("Foo Device", "test"), UIMapping)
|
|
|
|
preset.load()
|
|
|
|
# 2 mappings for mouse
|
|
|
|
# 2 mappings for wheel
|
|
|
|
self.assertEqual(len(preset), 4)
|
|
|
|
self.assertEqual(
|
|
|
|
preset.get_mapping(EventCombination((EV_ABS, ABS_RX, 0))),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination((EV_ABS, ABS_RX, 0)),
|
|
|
|
target_uinput="mouse",
|
|
|
|
output_type=EV_REL,
|
|
|
|
output_code=REL_X,
|
|
|
|
gain=50 / 100,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
preset.get_mapping(EventCombination((EV_ABS, ABS_RY, 0))),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination((EV_ABS, ABS_RY, 0)),
|
|
|
|
target_uinput="mouse",
|
|
|
|
output_type=EV_REL,
|
|
|
|
output_code=REL_Y,
|
|
|
|
gain=50 / 100,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
preset.get_mapping(EventCombination((EV_ABS, ABS_X, 0))),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination((EV_ABS, ABS_X, 0)),
|
|
|
|
target_uinput="mouse",
|
|
|
|
output_type=EV_REL,
|
|
|
|
output_code=REL_HWHEEL_HI_RES,
|
|
|
|
gain=10,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
preset.get_mapping(EventCombination((EV_ABS, ABS_Y, 0))),
|
|
|
|
UIMapping(
|
|
|
|
event_combination=EventCombination((EV_ABS, ABS_Y, 0)),
|
|
|
|
target_uinput="mouse",
|
|
|
|
output_type=EV_REL,
|
|
|
|
output_code=REL_WHEEL_HI_RES,
|
|
|
|
gain=20,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2021-12-15 14:06:23 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|