2021-02-18 19:38:14 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
2022-01-01 12:00:49 +00:00
|
|
|
# input-remapper - GUI for device specific keyboard mappings
|
2022-01-01 12:52:33 +00:00
|
|
|
# Copyright (C) 2022 sezanzeb <proxima@sezanzeb.de>
|
2021-02-18 19:38:14 +00:00
|
|
|
#
|
2022-01-01 12:00:49 +00:00
|
|
|
# This file is part of input-remapper.
|
2021-02-18 19:38:14 +00:00
|
|
|
#
|
2022-01-01 12:00:49 +00:00
|
|
|
# input-remapper is free software: you can redistribute it and/or modify
|
2021-02-18 19:38:14 +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-02-18 19:38:14 +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-11-23 21:55:28 +00:00
|
|
|
|
|
|
|
from tests.lib.cleanup import quick_cleanup
|
|
|
|
from tests.lib.fixtures import get_key_mapping
|
2022-04-17 10:19:23 +00:00
|
|
|
from evdev.ecodes import (
|
|
|
|
EV_REL,
|
|
|
|
EV_ABS,
|
|
|
|
ABS_X,
|
|
|
|
ABS_Y,
|
|
|
|
REL_WHEEL_HI_RES,
|
|
|
|
REL_HWHEEL_HI_RES,
|
|
|
|
)
|
2021-02-18 19:38:14 +00:00
|
|
|
import unittest
|
|
|
|
|
2022-01-01 12:00:49 +00:00
|
|
|
from inputremapper.injection.context import Context
|
2022-01-31 19:58:37 +00:00
|
|
|
from inputremapper.configs.preset import Preset
|
|
|
|
from inputremapper.event_combination import EventCombination
|
2022-04-17 10:19:23 +00:00
|
|
|
from inputremapper.configs.mapping import Mapping
|
2021-02-18 19:38:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestContext(unittest.TestCase):
|
2021-09-29 18:17:45 +00:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
quick_cleanup()
|
|
|
|
|
2022-04-17 10:19:23 +00:00
|
|
|
def test_callbacks(self):
|
|
|
|
preset = Preset()
|
|
|
|
cfg = {
|
|
|
|
"event_combination": ",".join((str(EV_ABS), str(ABS_X), "0")),
|
|
|
|
"target_uinput": "mouse",
|
|
|
|
"output_type": EV_REL,
|
|
|
|
"output_code": REL_HWHEEL_HI_RES,
|
|
|
|
}
|
|
|
|
preset.add(Mapping(**cfg)) # abs x -> wheel
|
|
|
|
cfg["event_combination"] = ",".join((str(EV_ABS), str(ABS_Y), "0"))
|
|
|
|
cfg["output_code"] = REL_WHEEL_HI_RES
|
|
|
|
preset.add(Mapping(**cfg)) # abs y -> wheel
|
|
|
|
|
|
|
|
preset.add(get_key_mapping(EventCombination((1, 31, 1)), "keyboard", "k(a)"))
|
|
|
|
preset.add(get_key_mapping(EventCombination((1, 32, 1)), "keyboard", "b"))
|
|
|
|
|
|
|
|
# overlapping combination for (1, 32, 1)
|
|
|
|
preset.add(
|
|
|
|
get_key_mapping(
|
2022-04-18 11:52:59 +00:00
|
|
|
EventCombination(((1, 32, 1), (1, 33, 1), (1, 34, 1))),
|
|
|
|
"keyboard",
|
|
|
|
"c",
|
2022-04-17 10:19:23 +00:00
|
|
|
)
|
2022-01-31 19:58:37 +00:00
|
|
|
)
|
2021-02-18 19:38:14 +00:00
|
|
|
|
2022-04-17 10:19:23 +00:00
|
|
|
# map abs x to key "b"
|
|
|
|
preset.add(
|
2022-04-18 11:52:59 +00:00
|
|
|
get_key_mapping(EventCombination([EV_ABS, ABS_X, 20]), "keyboard", "d"),
|
2021-09-26 10:44:56 +00:00
|
|
|
)
|
2022-04-17 10:19:23 +00:00
|
|
|
context = Context(preset)
|
|
|
|
|
|
|
|
# expected callbacks and their lengths:
|
|
|
|
callbacks = {
|
|
|
|
(
|
|
|
|
EV_ABS,
|
|
|
|
ABS_X,
|
|
|
|
): 2, # ABS_X -> "d" and ABS_X -> wheel have the same type and code
|
|
|
|
(EV_ABS, ABS_Y): 1,
|
|
|
|
(1, 31): 1,
|
|
|
|
# even though we have 2 mappings with this type and code, we only expect one callback
|
|
|
|
# because they both map to keys. We don't want to trigger two mappings with the same key press
|
|
|
|
(1, 32): 1,
|
|
|
|
(1, 33): 1,
|
|
|
|
(1, 34): 1,
|
|
|
|
}
|
2022-07-23 08:53:41 +00:00
|
|
|
self.assertEqual(set(callbacks.keys()), set(context.notify_callbacks.keys()))
|
2022-04-17 10:19:23 +00:00
|
|
|
for key, val in callbacks.items():
|
2022-07-23 08:53:41 +00:00
|
|
|
self.assertEqual(val, len(context.notify_callbacks[key]))
|
2021-02-18 19:38:14 +00:00
|
|
|
|
2022-11-12 16:45:32 +00:00
|
|
|
# 7 unique input events in the preset
|
|
|
|
self.assertEqual(7, len(context._handlers))
|
2021-02-18 19:38:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|