I'd like to display a popover right above where the user is typing, in any Linux app (GTK, Qt, Electron, etc.), running on X.
I figured out creating the popover, now I'm trying to figure out how to get the coordinates of the input text cursor (what blinks while you type, not sure if it's called "caret"?) relative to the screen.
I know I can get info on where the mouse with xdotool
:
xdotool getmouselocation
I would need the same thing but for the text cursor, in the currently focused window.
I have no idea how to achieve this. I would love if someone could point me in the right direction.
So, after doing some research I was able to figure out one way to implement this:
- use
xdotool
to paste some random string - use OCR to find coordinates of the random string
- use
xdotool
to remove random string
The problem is that this approach is pretty slow (up to 10 seconds depending on how much text there is on the screen).
I'v also tried comparing screenshots (before/after inserting text) and it's much faster, but a lot less precise.
来源:https://stackoverflow.com/questions/53346707/get-x-y-position-of-caret-input-text-cursor-under-xorg