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

Random crash at X11 #161

Open
fecet opened this issue Aug 11, 2023 · 8 comments
Open

Random crash at X11 #161

fecet opened this issue Aug 11, 2023 · 8 comments
Labels
bug Something isn't working help welcome Help/contrib is esp welcome

Comments

@fecet
Copy link

fecet commented Aug 11, 2023

I still face the problem mentioned at #137 (comment). So open a issue to track this

@fecet fecet added bug Something isn't working help welcome Help/contrib is esp welcome labels Aug 11, 2023
@fecet
Copy link
Author

fecet commented Aug 11, 2023

Here is the log

keyszer v0.6.92
(--) ROOT: Yes, I am.  --very-bad-idea acknowledged.
(--) Autodetecting all keyboards (--device not specified)
(+K) Grabbing 'Logitech USB Receiver' (/dev/input/event15)
(+K) Grabbing 'HTKB HTKB HHKB-BLE' (/dev/input/event19)
(+K) Grabbing 'HTKB HTKB HHKB-BLE Keyboard' (/dev/input/event22)
(--) Ready to process input.
ls
llsException in callback receive_input(InputDevice('...nput/event19')) at /root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...nput/event19')) at /root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/transform.py", line 347, in on_event
    if context.x_error:
       ^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/lib/key_context.py", line 27, in x_error
    self._query_window_context()
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/lib/key_context.py", line 13, in _query_window_context
    self._X_ctx = get_xorg_context()
                  ^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/xorg.py", line 36, in get_xorg_context
    wm_name = window.get_full_text_property(_display.get_atom("_NET_WM_NAME"))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/xobject/drawable.py", line 486, in get_full_text_property
    prop = self.get_full_property(property, property_type,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/xobject/drawable.py", line 476, in get_full_property
    prop = self.get_property(property, property_type, sizehint,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/xobject/drawable.py", line 455, in get_property
    r = request.GetProperty(display = self.display,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/protocol/rq.py", line 1368, in __init__
    self.reply()
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/protocol/rq.py", line 1380, in reply
    self._display.send_and_recv(request = self._serial)
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/protocol/display.py", line 612, in send_and_recv
    gotreq = self.parse_response(request)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/protocol/display.py", line 719, in parse_response
    gotreq = self.parse_error_response(request) or gotreq
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/protocol/display.py", line 745, in parse_error_response

@joshgoebel
Copy link
Owner

Is it the full log? I don't see it mention BadRRModeError at the bottom.

@fecet
Copy link
Author

fecet commented Aug 13, 2023

Oops, will upload full log next time crashed.

But I think this should be

keyszer v0.6.92
(--) ROOT: Yes, I am.  --very-bad-idea acknowledged.
(--) Autodetecting all keyboards (--device not specified)
(+K) Grabbing 'Logitech USB Receiver' (/dev/input/event15)
(+K) Grabbing 'HTKB HTKB HHKB-BLE' (/dev/input/event19)
(+K) Grabbing 'HTKB HTKB HHKB-BLE Keyboard' (/dev/input/event22)
(--) Ready to process input.
ls
llsException in callback receive_input(InputDevice('...nput/event19')) at /root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...nput/event19')) at /root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/transform.py", line 347, in on_event
    if context.x_error:
       ^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/lib/key_context.py", line 27, in x_error
    self._query_window_context()
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/lib/key_context.py", line 13, in _query_window_context
    self._X_ctx = get_xorg_context()
                  ^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/xorg.py", line 36, in get_xorg_context
    wm_name = window.get_full_text_property(_display.get_atom("_NET_WM_NAME"))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/xobject/drawable.py", line 486, in get_full_text_property
    prop = self.get_full_property(property, property_type,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/xobject/drawable.py", line 476, in get_full_property
    prop = self.get_property(property, property_type, sizehint,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/xobject/drawable.py", line 455, in get_property
    r = request.GetProperty(display = self.display,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/protocol/rq.py", line 1368, in __init__
    self.reply()
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/protocol/rq.py", line 1380, in reply
    self._display.send_and_recv(request = self._serial)
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/protocol/display.py", line 612, in send_and_recv
    gotreq = self.parse_response(request)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/protocol/display.py", line 719, in parse_response
    gotreq = self.parse_error_response(request) or gotreq
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/Xlib/protocol/display.py", line 745, in parse_error_response
    req = self.get_waiting_request(e.sequence_number)
AttributeError: 'BadRRModeError' object has no attribute 'sequence_number'

by merging #137 (comment)

@RedBearAK
Copy link
Contributor

RedBearAK commented Aug 29, 2023

This seems to be some kind of internal issue with Xlib version 0.32, so pinning the version to 0.31 should avoid it until the fix is in place. One fix apparently exists, but has not been merged, for some reason.

python-xlib/python-xlib#241
python-xlib/python-xlib#242
python-xlib/python-xlib#259

To install a specific version of the package with pip:

pip install python-xlib==0.31

It may not be quite that straightforward if you're using pipx to install keyszer and relying on the system python-xlib package, which is probably 0.32 or 0.33 by now. Using a full Python virtual environment is probably the best way to handle these things.

I haven't experienced anything like this with my own project that is using a modified fork of keyszer with Wayland support. I don't run keyszer as root, or do much connecting/disconnecting of devices, but I've been testing my project in dozens of Linux distros in Boxes virtual machines without seeing this issue. Though mostly in Wayland to make sure the Wayland support is working.

Looks like wrapping this line in xorg.py in a try/except could at least stop it from crashing keyszer, but I'm not sure what the side effects would be.

  File "/root/.local/pipx/venvs/keyszer/lib/python3.11/site-packages/keyszer/xorg.py", line 36, in get_xorg_context
    wm_name = window.get_full_text_property(_display.get_atom("_NET_WM_NAME"))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@fecet
Copy link
Author

fecet commented Sep 4, 2023

I haven't experienced anything like this with my own project that is using a modified fork of keyszer with Wayland support.

Did you mean https://github.com/RedBearAK/toshy? It looks promising, does it support https://github.com/hyprwm/Hyprland?

@RedBearAK
Copy link
Contributor

@fecet

That's the one. Toshy installs a development branch of keyszer with an adaptable window context module, capable of dealing with more environments than just X11/Xorg.

That branch of keyszer does not have Hyprland support yet. But the project that I've been drawing from has Wayland support for GNOME, KDE, sway, and Hyprland environments. So you may want to take a look at that.

https://github.com/k0kubun/xremap

In theory the sway and Hyprland support could also be added to the same branch of keyszer that I'm using, but I'd have to take a close look at how they're doing it in xremap, and whether those environments actually provide the window name info Toshy needs.

@fecet
Copy link
Author

fecet commented Sep 4, 2023

Thanks for your link, I tried xremap and it works both at x11 and hyprland (should build seperately though). However I still encouther rust-windowing/winit#2898 (comment), did you know what's the magic behind keyszer?

@RedBearAK
Copy link
Contributor

@fecet

I don't know keyszer deeply to know why you're not seeing a similar bug.

I'm trying to figure out if I can get what I need from Hyprland, but I don't have a way to run it right now. Would you mind starting a new issue in the Toshy repo and providing some sample output from commands like hyprctl clients -j and hyprctrl activewindow -j? You can title it something like (enh) Hyprland support.

https://github.com/RedBearAK/toshy/issues

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

3 participants