woodruffw / x_do.cr

Crystal bindings for libxdo (xdotool)
https://woodruffw.github.io/x_do.cr/
MIT License
18 stars 1 forks source link

Get window by #14

Closed phil294 closed 2 years ago

phil294 commented 2 years ago

closes #13

Just to clarify: is there a libxdo API for getting (and validating) a window by WID

It looks like there is none.

, or are you proposing that x_do.cr add a separate API for that that uses Xlib directly?

Yes - I tried doing that in this PR. However, you cannot simply do

win = Window.new(xdo_p, id)
begin
  win.name
rescue
  nil

because when id is invalid, xdotool does not catch the X11 error and that kills the entire process... so I think the only way is to temporarily override the default X11 error handler like I did. Unless I missed something?

I think this approach is horrible and suggest this experiment should not be merged and closed instead. I wanted to share it anyway.

Another downside is that binding to XSetErrorHandler can conflict with other libraries that do similar stuff. It most likely fails to build in conjunction with https://github.com/TamasSzekeres/x11-cr but I haven't tested.

phil294 commented 2 years ago

Also tests seem to randomly fail as soon as you have 83 or more tests (??). At least in my setup, on normal Display X11 (Xfwm), when I repeated some of the standard tests, I got weird X display closed errors

woodruffw commented 2 years ago

I think this approach is horrible and suggest this experiment should not be merged and closed instead. I wanted to share it anyway.

Thanks for sharing it! Yeah, I agree -- overriding the default error handler isn't guaranteed to be MT-safe, so we shouldn't attempt it in this library.

For the time being, I'd like to keep these bindings limited to just the API surface exposed by libxdo. If you can convince the upstream to merge an API for getting a window by its ID, I'd be more than happy to expose that API here 🙂

phil294 commented 2 years ago

ok makes sense