woodruffw / x_do.cr

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

How do you access a window by its Window ID? #13

Closed phil294 closed 2 years ago

phil294 commented 2 years ago

I don't think it's possible (?). I guess an XDo::Window.get_by_id would be quite helpful? It would also need some kind of exists check. It doesn't look like libxdo supports that, so we need begin/rescue on an arbitrary command to check?

If you agree with me, I can of course open another PR.

Sorry for spamming your repo, but that should be about it now :-)

Edit six months later: If I am not mistaken, you can just query window.name. It will show a warning in the console, but not crash the program, if the window doesn't exist. If it returns nil, the window ID does not exist.

woodruffw commented 2 years ago

Sorry for spamming your repo, but that should be about it now :-)

Not a problem at all! These have been great issues.

I don't think it's possible (?). I guess an XDo::Window.get_by_id would be quite helpful? It would also need some kind of exists check. It doesn't look like libxdo supports that, so we need begin/rescue on an arbitrary command to check?

Just to clarify: is there a libxdo API for getting (and validating) a window by WID, or are you proposing that x_do.cr add a separate API for that that uses Xlib directly?

phil294 commented 2 years ago

I answered your question in the linked PR.

I now think the best solution is to do this in user space:

all_wins = XDo.act do
  search { window_name "" }
end
my_win = all_wins.find { |win| win.window == [ID] }

this is probably also not super performant but the best solution (?)

so in my opinion this issue can also be closed.

woodruffw commented 2 years ago

Thanks for posting your solution. Closing.