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

AttributeError: 'int' object has no attribute 'xinput_select_events' #8

Open
jeason1997 opened this issue Dec 7, 2023 · 12 comments
Open

Comments

@jeason1997
Copy link

jeason1997 commented Dec 7, 2023

 gambaterm ~/pokemon.gbc
Traceback (most recent call last):
  File "/usr/local/bin/gambaterm", line 8, in <module>
    sys.exit(main())
  File "/home/jeason/.local/lib/python3.10/site-packages/gambaterm/main.py", line 142, in main
    with input_context as get_gb_input:
  File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/home/jeason/.local/lib/python3.10/site-packages/gambaterm/keyboard_input.py", line 247, in console_input_from_keyboard_context
    with key_pressed_context(display=display) as get_pressed:
  File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "/home/jeason/.local/lib/python3.10/site-packages/gambaterm/keyboard_input.py", line 119, in xlib_key_pressed_context
    term_window.xinput_select_events(
AttributeError: 'int' object has no attribute 'xinput_select_events'
@vxgmichel
Copy link
Owner

Thanks for the report @jeason1997 :)

I couldn't replicate this bug, could you provide the python-xlib you're using (I'm currently testing with version 0.33).

Also, could you run this code:

from Xlib.display import Display

xdisplay = Display()
extension_info = xdisplay.query_extension("XInputExtension")
input_focus = xdisplay.get_input_focus()
term_window = input_focus.focus
print(f"{extension_info=}\n{input_focus=}\n{term_window=}")

For the reference, I get the following trace:

extension_info=<QueryExtension serial = 18, data = {'sequence_number': 18, 'present': 1, 'major_opcode': 131, 'first_event': 66, 'first_error': 129}, error = None>
input_focus=<GetInputFocus serial = 19, data = {'revert_to': 2, 'sequence_number': 19, 'focus': <Window 0x052002e0>}, error = None>
term_window=<Window 0x052002e0>

@jeason1997
Copy link
Author

Thanks for the report @jeason1997 :)

I couldn't replicate this bug, could you provide the python-xlib you're using (I'm currently testing with version 0.33).

Also, could you run this code:

from Xlib.display import Display

xdisplay = Display()
extension_info = xdisplay.query_extension("XInputExtension")
input_focus = xdisplay.get_input_focus()
term_window = input_focus.focus
print(f"{extension_info=}\n{input_focus=}\n{term_window=}")

For the reference, I get the following trace:

extension_info=<QueryExtension serial = 18, data = {'sequence_number': 18, 'present': 1, 'major_opcode': 131, 'first_event': 66, 'first_error': 129}, error = None>
input_focus=<GetInputFocus serial = 19, data = {'revert_to': 2, 'sequence_number': 19, 'focus': <Window 0x052002e0>}, error = None>
term_window=<Window 0x052002e0>

Hi @vxgmichel , my python-xlib version is same to yours

~> pip3 show python-xlib
Name: python-xlib
Version: 0.33
Summary: Python X Library
Home-page: https://github.com/python-xlib/python-xlib
Author: Peter Liljenberg
Author-email: petli@ctrl-c.liu.se
License: LGPLv2+
Location: /usr/local/lib/python3.10/dist-packages
Requires: six
Required-by: gambaterm`

after run the code it output:

In [1]: from Xlib.display import Display
   ...:
   ...: xdisplay = Display()
   ...: extension_info = xdisplay.query_extension("XInputExtension")
   ...: input_focus = xdisplay.get_input_focus()
   ...: term_window = input_focus.focus
   ...: print(f"{extension_info=}\n{input_focus=}\n{term_window=}")
extension_info=<QueryExtension serial = 15, data = {'sequence_number': 15, 'present': 1, 'major_opcode': 131, 'first_event': 66, 'first_error': 129}, error = None>
input_focus=<GetInputFocus serial = 16, data = {'revert_to': 0, 'sequence_number': 16, 'focus': 1}, error = None>
term_window=1`

My computer environment is wsl:

 ~> uname -a
Linux DESKTOP-10NTA73 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

@diminou91
Copy link

diminou91 commented Jan 24, 2024

Hello,

Same issue here.

Traceback (most recent call last):
  File "/home/user/.local/bin/gambaterm", line 8, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.9/site-packages/gambaterm/main.py", line 142, in main
    with input_context as get_gb_input:
  File "/usr/local/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
  File "/home/user/.local/lib/python3.9/site-packages/gambaterm/keyboard_input.py", line 247, in console_input_from_keyboard_context
    with key_pressed_context(display=display) as get_pressed:
  File "/usr/local/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
  File "/home/user/.local/lib/python3.9/site-packages/gambaterm/keyboard_input.py", line 119, in xlib_key_pressed_context
    term_window.xinput_select_events(
AttributeError: 'int' object has no attribute 'xinput_select_events'
extension_info=<QueryExtension serial = 15, data = {'sequence_number': 15, 'present': 1, 'major_opcode': 131, 'first_event': 66, 'first_error': 129}, error = None>
input_focus=<GetInputFocus serial = 16, data = {'revert_to': 1, 'sequence_number': 16, 'focus': 0}, error = None>
term_window=0

Ubuntu 23.10, please let me know if you need something else tested :)

@vxgmichel
Copy link
Owner

Ubuntu 23.10, please let me know if you need something else tested :)

Oh interesting, I admit I wasn't too motivated to install WSL but if you can reproduce this on ubuntu that's good news. Do you use Wayland or X11? Could you provide the python-xlib version you're using?

@diminou91
Copy link

Ahah, I totally understand ! I'm on wayland, I did not try it out on X11. And i'm using the same python-xlib version than you : 0.33

Name: python-xlib
Version: 0.33
Summary: Python X Library
Home-page: https://github.com/python-xlib/python-xlib
Author: Peter Liljenberg
Author-email: petli@ctrl-c.liu.se
License: LGPLv2+
Location: /home/user/.local/lib/python3.9/site-packages
Requires: six
Required-by: gambaterm

I could try it out on X11 and report back if you want

@vxgmichel
Copy link
Owner

I could try it out on X11 and report back if you want

That'd be awesome :) I'll run some tests on wayland on my own as well

@diminou91
Copy link

That'd be awesome :) I'll run some tests on wayland on my own as well

Working as intended on X11! Un problème avec Wayland alors ? :)

@vxgmichel
Copy link
Owner

I ran some tests on wayland and it seems like some windows are not accessible through the xlib API.

I wrote this script to show the full window tree along with their respective geometry:

from Xlib.display import Display

def print_window(window, indent=0):
    wid = hex(window.id)
    name = window.get_wm_name()
    geometry = window.get_geometry()
    x, y, width, height = geometry.x, geometry.y, geometry.width, geometry.height
    print(f"{' '*indent}* [{wid}] {name} ({x}, {y}) {width}x{height}")
    for child in window.query_tree().children:
        print_window(child, indent+2)


xdisplay = Display()
screen = xdisplay.screen()
root = screen.root
print_window(root)

I ran it several times while changing the terminal window size but there was no difference in the output. It seems like the terminal window simply does not appear.

I noticed the same thing using this gist to get the current active window.

Funnily enough, VSCode does appear in the list. That means that if you use the VSCode terminal to run gambaterm it does work properly. I'd be curious to know if this trick also work in WSL, @jeason1997 please let me know if you happen to have VSCode installed in WSL.

I also tried to capture the keyboard input at root level (as a fallback workaround) but the key presses are not captured if the terminal window is focused. The key presses are properly captured if another "available" window is focused though, which is not helpful at all but does indicated that some windows are somehow "protected". This might be a security feature but I didn't look too long into it.

@diminou91 I'm currently running out of ideas here but I'd be curious to hear your opinion about it :)

@diminou91
Copy link

diminou91 commented Jan 25, 2024

Hmm I've tried forcing xwayland and X11 by un-setting WAYLAND_DISPLAY and by using GDK_BACKEND=x11 but same results.

Is there any other software that you know of using the same mechanism to draw a window on screen ? Just to be able to compare if it is working and if so what are the differences ?

EDIT : tried it in vscode terminal, different issue :

  File "/home/user/.local/bin/gambaterm", line 8, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.9/site-packages/gambaterm/main.py", line 144, in main
    with player(console, args.speed_factor) as audio_out:
  File "/usr/local/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
  File "/home/user/.local/lib/python3.9/site-packages/gambaterm/audio.py", line 83, in audio_player
    import sounddevice
  File "/home/user/.local/lib/python3.9/site-packages/sounddevice.py", line 71, in <module>
    raise OSError('PortAudio library not found')
OSError: PortAudio library not found

But I'm guessing this could be easily sorted out, just wanted to see if it was working as well

@vxgmichel
Copy link
Owner

tried it in vscode terminal, different issue :

It seems like sounddevice could not find the PortAudio library. Mine is located here /usr/lib/x86_64-linux-gnu/libportaudio.so.2 (from the package libportaudio2). In any case you can disable audio using --disable-audio and it should fix the import.

Is there any other software that you know of using the same mechanism to draw a window on screen ? Just to be able to compare if it is working and if so what are the differences ?

You mean a GUI program that appears in the window tree? Apart from desktop related stuff, I've tested with VSCode and glxgears that both appear in the list.

@diminou91
Copy link

diminou91 commented Jan 25, 2024

Yes using --disable-audio makes it work in vscode!

I mean any other piece of software using the same methods as yours to draw a window and use the keyboard, taht we could launch in X and Wayland to test if it is working or not, but that's a bit far fetched.

Maybe a rewrite to pywayland lib could work ? But that's a bit of work, I'd like to try but I'm no dev :D

@vxgmichel
Copy link
Owner

Maybe a rewrite to pywayland lib could work ? But that's a bit of work, I'd like to try but I'm no dev :D

That's a good idea, I didn't know about pywayland. That seems pretty tricky though, I could not find similar examples to start from. I don't have time to work on that at the moment, feel free to post your attempt if you end up giving it a try :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants