mooz / xkeysnail

Yet another keyboard remapping tool for X environment
890 stars 112 forks source link

Much faster input processing (avoid the whole stack) #162

Closed joshgoebel closed 2 years ago

joshgoebel commented 2 years ago

Input can be sped up quite a bit with a tiny hack:

JUST_KEYS = []
# adds all alpha keyboard keys to an exclusion list
JUST_KEYS.extend([Key[x] for x in "QWERTYUIOPASDFGHJKLZXCVBNM"])

def on_event(event, device_name, quiet):
    if event.type != ecodes.EV_KEY:
        _output.send_event(event)
        return

    if len(_pressed_modifier_keys) == 0 and event.code in JUST_KEYS:
        _output.send_event(event)
        return

This avoids the whole keymapping stack when there are no modifiers down and you're just typing regularly. In my testing the difference is pronounced:

I'm guessing a lot of the expense is asking X for the current window, but I haven't done any real testing yet.

joshgoebel commented 2 years ago

Sorry, in 0.4.0 here this if/else check is in input, not transform... and it may be slightly more complex than I first thought. Closing this for now. :)