Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Exception when using LC and RC on input and Ctrl on output in remaps #168

Open
RedBearAK opened this issue Oct 3, 2024 · 0 comments
Labels
bug Something isn't working help welcome Help/contrib is esp welcome

Comments

@RedBearAK
Copy link
Contributor

@joshgoebel

Discovered an exception happening in a specific circumstance. This is just an example:

    C("LC-Alt-RC-c"):               C("C-c"),

The cause appears to be using both the left and right variants of a modifier on the input side of a remap, while having the same modifier involved in the output side, but undifferentiated. I think this will apply equally to attempting to use both left and right Super or Alt while having Super or Alt in the output combo. Or even the left/right Shift key.

This would normally be a very unusual thing to do, but with the Toshy or Kinto config if you need a general remap of something like Super+RC+key to work correctly in terminals, it has to become LC+RC+key since there is no Meta/Super/Win key available in terminals.

This particular type of shortcut remap causes something like the following to happen, and the shortcut will exhibit odd behavior or just not work:

Exception in callback receive_input(InputDevice('...input/event4')) at /home/kris/.config/toshy/.venv/lib64/python3.12/site-packages/xwaykeyz/input.py:105
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/kris/.config/toshy/.venv/lib64/python3.12/site-packages/xwaykeyz/input.py:105>
Traceback (most recent call last):
  File "/usr/lib64/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/home/kris/.config/toshy/.venv/lib64/python3.12/site-packages/xwaykeyz/input.py", line 120, in receive_input
    on_event(event, device)
  File "/home/kris/.config/toshy/.venv/lib64/python3.12/site-packages/xwaykeyz/transform.py", line 389, in on_event
    on_key(ks, context)
  File "/home/kris/.config/toshy/.venv/lib64/python3.12/site-packages/xwaykeyz/transform.py", line 469, in on_key
    transform_key(key, action, context)
  File "/home/kris/.config/toshy/.venv/lib64/python3.12/site-packages/xwaykeyz/transform.py", line 516, in transform_key
    reset_mode = handle_commands(keymap[combo], key, action, ctx, combo)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kris/.config/toshy/.venv/lib64/python3.12/site-packages/xwaykeyz/transform.py", line 614, in handle_commands
    _output.send_combo(command)
  File "/home/kris/.config/toshy/.venv/lib64/python3.12/site-packages/xwaykeyz/output.py", line 142, in send_combo
    mods_we_need_to_press.remove(modifier)
  File "<frozen _collections_abc>", line 729, in remove
KeyError: Ctrl<Key.LEFT_CTRL>

The exception can apparently be avoided by just differentiating between left and right modifiers in the output portion of the remap. Something that is not normally necessary or meaningful.

Either this:

    C("LC-Alt-RC-c"):               C("LC-c"),

Or this:

    C("LC-Alt-RC-c"):               C("RC-c"),

With the left/right differentiated modifier alias in the output side, suddenly the shortcuts all work correctly.

I think this has something to do with the resuming of suspended modifiers, but this is happening in a part of the code that I don't fully understand. I'm going to try to debug it at some point, but if you have any insights leave them here.

This came up in Toshy issue #408.

@RedBearAK RedBearAK added bug Something isn't working help welcome Help/contrib is esp welcome labels Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help welcome Help/contrib is esp welcome
Projects
None yet
Development

No branches or pull requests

1 participant