woodruffw / x_do.cr

Crystal bindings for libxdo (xdotool)

Home Page:https://woodruffw.github.io/x_do.cr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

active_window.type doesn't work in some windows

phil294 opened this issue · comments

In #10, I mentioned having issues with things like win.activate! and type. The former was actually my bad, I needed to use raise!() instead, as both activate! and focus! seem to be ignored by Xfwm when the window is minimized.

However, typing keys can sometimes fail, even when the window is focussed where it works in xdotool. For example, the editor Mousepad never receives anything when you do active_window.type "abc", even when the window is active. It's a bit more complicated unfortunately, with it being the difference between XSendEvent and XTestFakeKeyEvent; when the window is active, it should actually fall back to XTest but it doesn't, somehow: jordansissel/xdotool#85 (comment) <- This not working PR fix is was added on the last day before the previous release, so it's present in both the 2016 and 2021 version.

Normal xdotool without specifying a --window will always use XTest, but x_do.cr only ever goes the XSend route. This can be solved by specifying CURRENTWINDOW (which is 0) as window instead which xdotool understands as "use XTest to the active window".

So maybe we should add new functions inside the x_do.cr file such as

def type(text : String, delay = DEFAULT_DELAY)
    LibXDo.enter_text_window(xdo_p, 0, text, delay)
end

so you can

XDo.act { type("abc") }

which will work fine like xdotool does. This means that the send and key functions all have to be duplicated and such

That makes sense to me; feel free to submit a PR with those new APIs.

Just to clarify: is CURRENTWINDOW a constant/macro provided by libxdo? If so we should reuse it. I'm a little bit surprised that 0 means "current window" however, since normally that means "root window" in X11 contexts. But who knows!

Just to clarify: is CURRENTWINDOW a constant/macro provided by libxdo?

Yes, it's just a plain #define. From here by the author:

... I think it's worth noting that doing key --window 0 a will send 'a' to the current window -- I don't know if this is documented, though. There's a special window value xdo uses for knowing when to act on the "current window" and that is 0.

I'll create a PR some time later.