enigo-rs / enigo

Cross platform input simulation in Rust
MIT License
1.03k stars 102 forks source link

`Window` can be the wrong integer size? #116

Closed elidupree closed 1 year ago

elidupree commented 2 years ago

I actually ran into this issue while using Prunkton's fork, where it caused a segfault, but it seems like it would affect mainline Enigo as well.

This source code from X11 appears to make XID's size (and hence Window's size) conditional on some sort of built flags. I haven't fully grokked the flags, but what I do know is that my version of libxdo assumes that the Window type is 64 bits, while Enigo defines type Window = c_int, which is 32 bits.

I don't know why this isn't causing obvious bugs when calling xdo_mouse_down, etc., which pass a Window as an argument, but it seems like it would technically be a memory error (that might just coincidentally not cause the incorrect behavior during simple usage).

pentamassiv commented 1 year ago

Hmm, so sometimes it is 32 bits and sometime 64? Or did they switch to 64 bits in a newer version? I'll have to look into this

FabioGNR commented 1 year ago

I'm also running into this issue (with a crash as result).

From linked source code:

/*
 * _XSERVER64 must ONLY be defined when compiling X server sources on
 * systems where unsigned long is not 32 bits, must NOT be used in
 * client or library code.
 */

Through another issue I found that the X11 bindings always use c_ulong:
https://docs.rs/x11-dl/latest/i686-unknown-linux-gnu/x11_dl/xlib/type.XID.html

Looking at Xserver source code it should be based on size of ulong:
https://github.com/freedesktop/xorg-xserver/blob/master/include/meson.build#L48

So perhaps it should just be configured based on 32 vs 64 bits? Hope this info helps.

pentamassiv commented 1 year ago

The last link from FabisGNR is dead. I guess it now is: https://gitlab.freedesktop.org/xorg/xserver/-/blob/master/include/meson.build#L48

That was very helpful. If I understand correctly, using c_ulong should be fine. Depending on the architecture it then is either 32 or 64 bits long. Here is an example where it is 32 bits and here it is 64 bits

pentamassiv commented 1 year ago

This should now be fixed. I should have looked into it earlier :/