only listing unmodified symbols from xmodmap

This commit is contained in:
sezanzeb 2021-04-02 19:54:08 +02:00
parent 3e1c3a3dfb
commit cc6f4133c2
5 changed files with 12 additions and 29 deletions

View File

@ -103,7 +103,7 @@ class Mapping(ConfigBase):
new_key : Key
character : string
A single character known to xkb or linux.
Examples: KP_1, Shift_L, a, B, BTN_LEFT.
Examples: KEY_KP1, Shift_L, a, B, BTN_LEFT.
previous_key : Key or None
the previous key

View File

@ -146,14 +146,6 @@ class SystemMapping:
name = names.split()[0]
xmodmap_dict[name] = int(keycode) - XKB_KEYCODE_OFFSET
for keycode, names in self._xmodmap:
# but since KP may be mapped like KP_Home KP_7 KP_Home KP_7,
# make another pass and add all of them if they don't already
# exist. don't overwrite any keycodes.
for name in names.split():
if 'KP_' in name and xmodmap_dict.get(name) is None:
xmodmap_dict[name] = int(keycode) - XKB_KEYCODE_OFFSET
return xmodmap_dict
@ -162,6 +154,3 @@ custom_mapping = Mapping()
# this mapping represents the xmodmap output, which stays constant
system_mapping = SystemMapping()
# permissions for files created in /usr
_PERMISSIONS = stat.S_IREAD | stat.S_IWRITE | stat.S_IRGRP | stat.S_IROTH

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -47,9 +47,9 @@ your keycodes (which is easier said than done), and X11/Wayland has to decide
what to do with it. And it decides, that if shift is pressed down, it will
capitalize your stuff.
A better option for a key combination would be `KP1 + a` instead of
A better option for a key combination would be `KEY_KP1 + a` instead of
`LEFTSHIFT + a`, because there won't be any side effect. You can disable
`KP1` by mapping it to `disable`, so you won't trigger writing a "1" into
`KEY_KP1` by mapping it to `disable`, so you won't trigger writing a "1" into
your focused application.
<p align="center">

View File

@ -100,25 +100,19 @@ class TestSystemMapping(unittest.TestCase):
self.assertEqual(system_mapping.get('BTN_left'), 272)
self.assertIsNotNone(system_mapping.get('kp_1'))
self.assertIsNotNone(system_mapping.get('KP_1'))
self.assertEqual(
system_mapping.get('KP_Left'),
system_mapping.get('KP_4')
)
self.assertIsNotNone(system_mapping.get('KEY_KP4'))
self.assertEqual(
system_mapping.get('KP_Left'),
system_mapping.get('KEY_KP4')
)
# this only lists the correct casing, includes linux constants,
# xmodmap symbols and all KP_ codes
# this only lists the correct casing,
# includes linux constants and xmodmap symbols
names = system_mapping.list_names()
self.assertIn('2', names)
self.assertIn('c', names)
self.assertIn('KEY_3', names)
self.assertNotIn('key_3', names)
self.assertIn('KP_8', names)
self.assertIn('KP_Down', names)
self.assertNotIn('kp_down', names)
names = system_mapping._mapping.keys()
@ -126,7 +120,7 @@ class TestSystemMapping(unittest.TestCase):
self.assertNotIn('f4', names)
self.assertIn('BTN_RIGHT', names)
self.assertNotIn('btn_right', names)
self.assertIn('KP_7', names)
self.assertIn('KEY_KP7', names)
self.assertIn('KP_Home', names)
self.assertNotIn('kp_home', names)
@ -345,16 +339,16 @@ class TestMapping(unittest.TestCase):
self.assertEqual(len(self.mapping), 0)
self.assertTrue(self.mapping.changed)
self.mapping.change(ev_4, 'KP_1', None)
self.mapping.change(ev_4, 'KEY_KP1', None)
self.assertTrue(self.mapping.changed)
self.mapping.change(ev_3, 'KP_2', None)
self.mapping.change(ev_2, 'KP_3', None)
self.mapping.change(ev_3, 'KEY_KP2', None)
self.mapping.change(ev_2, 'KEY_KP3', None)
self.assertEqual(len(self.mapping), 3)
self.mapping.clear(ev_3)
self.assertEqual(len(self.mapping), 2)
self.assertEqual(self.mapping.get_character(ev_4), 'KP_1')
self.assertEqual(self.mapping.get_character(ev_4), 'KEY_KP1')
self.assertIsNone(self.mapping.get_character(ev_3))
self.assertEqual(self.mapping.get_character(ev_2), 'KP_3')
self.assertEqual(self.mapping.get_character(ev_2), 'KEY_KP3')
def test_empty(self):
self.mapping.change(Key(EV_KEY, 10, 1), '1')