using the offset constant everywhere

This commit is contained in:
sezanzeb 2020-12-02 21:24:35 +01:00
parent 194b8dfa1c
commit d355806c5a
3 changed files with 16 additions and 16 deletions

View File

@ -31,7 +31,7 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from keymapper.state import custom_mapping, system_mapping, \
clear_system_mapping
clear_system_mapping, KEYCODE_OFFSET
from keymapper.config import config
from keymapper.daemon import Daemon, get_dbus_interface, BUS_NAME
@ -97,7 +97,7 @@ class TestDaemon(unittest.TestCase):
config.set_autoload_preset('device 2', preset)
pending_events['device 2'] = [
Event(evdev.events.EV_KEY, keycode_from_1 - 8, 0),
Event(evdev.events.EV_KEY, keycode_from_1 - KEYCODE_OFFSET, 0),
]
self.daemon = Daemon()
@ -108,15 +108,15 @@ class TestDaemon(unittest.TestCase):
event = uinput_write_history_pipe[0].recv()
self.assertEqual(event.type, evdev.events.EV_KEY)
self.assertEqual(event.code, keycode_to_1 - 8)
self.assertEqual(event.code, keycode_to_1 - KEYCODE_OFFSET)
self.assertEqual(event.value, 0)
self.daemon.stop_injecting('device 2')
self.assertFalse(self.daemon.is_injecting('device 2'))
pending_events['device 2'] = [
Event(evdev.events.EV_KEY, keycode_from_2 - 8, 1),
Event(evdev.events.EV_KEY, keycode_from_2 - 8, 0),
Event(evdev.events.EV_KEY, keycode_from_2 - KEYCODE_OFFSET, 1),
Event(evdev.events.EV_KEY, keycode_from_2 - KEYCODE_OFFSET, 0),
]
time.sleep(0.2)
@ -126,12 +126,12 @@ class TestDaemon(unittest.TestCase):
event = uinput_write_history_pipe[0].recv()
self.assertEqual(event.type, evdev.events.EV_KEY)
self.assertEqual(event.code, keycode_to_2 - 8)
self.assertEqual(event.code, keycode_to_2 - KEYCODE_OFFSET)
self.assertEqual(event.value, 1)
event = uinput_write_history_pipe[0].recv()
self.assertEqual(event.type, evdev.events.EV_KEY)
self.assertEqual(event.code, keycode_to_2 - 8)
self.assertEqual(event.code, keycode_to_2 - KEYCODE_OFFSET)
self.assertEqual(event.value, 0)

View File

@ -36,7 +36,7 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from keymapper.state import custom_mapping, system_mapping, \
clear_system_mapping
clear_system_mapping, KEYCODE_OFFSET
from keymapper.paths import CONFIG, get_config_path
from keymapper.config import config
from keymapper.dev.reader import keycode_reader
@ -408,8 +408,8 @@ class TestIntegration(unittest.TestCase):
system_mapping['a'] = keycode_to
pending_events['device 2'] = [
Event(evdev.events.EV_KEY, keycode_from - 8, 1),
Event(evdev.events.EV_KEY, keycode_from - 8, 0)
Event(evdev.events.EV_KEY, keycode_from - KEYCODE_OFFSET, 1),
Event(evdev.events.EV_KEY, keycode_from - KEYCODE_OFFSET, 0)
]
custom_mapping.save('device 2', 'foo preset')
@ -428,12 +428,12 @@ class TestIntegration(unittest.TestCase):
event = uinput_write_history_pipe[0].recv()
self.assertEqual(event.type, evdev.events.EV_KEY)
self.assertEqual(event.code, keycode_to - 8)
self.assertEqual(event.code, keycode_to - KEYCODE_OFFSET)
self.assertEqual(event.value, 1)
event = uinput_write_history_pipe[0].recv()
self.assertEqual(event.type, evdev.events.EV_KEY)
self.assertEqual(event.code, keycode_to - 8)
self.assertEqual(event.code, keycode_to - KEYCODE_OFFSET)
self.assertEqual(event.value, 0)
def test_stop_injecting(self):
@ -446,7 +446,7 @@ class TestIntegration(unittest.TestCase):
# not all of those events should be processed, since that takes some
# time due to time.sleep in the fakes and the injection is stopped.
pending_events['device 2'] = [Event(1, keycode_from - 8, 1)] * 100
pending_events['device 2'] = [Event(1, keycode_from - KEYCODE_OFFSET, 1)] * 100
custom_mapping.save('device 2', 'foo preset')

View File

@ -21,11 +21,11 @@
import unittest
import evdev
from evdev.events import EV_KEY
import time
from keymapper.dev.reader import keycode_reader
from keymapper.state import KEYCODE_OFFSET
from tests.test import Event, pending_events, EVENT_READ_TIMEOUT
@ -58,7 +58,7 @@ class TestReader(unittest.TestCase):
keycode_reader._pipe[0].send((EV_KEY, 1234))
time.sleep(EVENT_READ_TIMEOUT * 5)
self.assertEqual(keycode_reader.read(), (EV_KEY, CODE_3 + 8))
self.assertEqual(keycode_reader.read(), (EV_KEY, CODE_3 + KEYCODE_OFFSET))
self.assertEqual(keycode_reader.read(), (None, None))
def test_wrong_device(self):
@ -106,7 +106,7 @@ class TestReader(unittest.TestCase):
keycode_reader.start_reading('device 1')
time.sleep(EVENT_READ_TIMEOUT * 5)
self.assertEqual(keycode_reader.read(), (EV_KEY, CODE_3 + 8))
self.assertEqual(keycode_reader.read(), (EV_KEY, CODE_3 + KEYCODE_OFFSET))
self.assertEqual(keycode_reader.read(), (None, None))