14

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.

nkkollaw
  • 1,947
  • 1
  • 19
  • 29
  • X has no idea where the text input caret is. I don't think your idea is implementable (without co-operation from the application or toolkit). – Jussi Kukkonen Nov 17 '18 at 13:36
  • I agree with @jku, X doesn't know anything particular about that, just that you clicked somewhere (if even a click is needed) and that it has been handled by an application. It doesn't know at all whether you're typing text or not! Also, I think it's called a cursor – Jaffa Nov 26 '18 at 08:47
  • Right. I was told one way would be witha GTK module. – nkkollaw Nov 27 '18 at 10:24
  • Sounds interesting. What is the program for? Just out of curiosity, is it like an open-source grammarly or something? – kettle Mar 22 '21 at 04:35
  • I don't know what Grammarly is @linux_kettle, but I was trying to implement a tooltip with accented letters like macOS or mobile OSes, that would activate by keeping a key pressed and insert the accented letter on click. – nkkollaw Mar 28 '21 at 21:37
  • That's something Linux needs so much! I'm sick of going into GNOME Characters every time I want to type something that isn't on my keyboard. – kettle Mar 30 '21 at 04:17
  • @linux_kettle Just in case you, and anyone else out there, wanted to know: GNOME Tweaks enables a special key so that you can type special characters without having to copy them from GNOME Characters. For example, on my system that special key is `Caps Lock`, so if I type `Caps Lock`, `a`, and `-`, the output is `ā` . If you don't want to use `Caps Lock`, you can alternately set it to another key, like `Right Alt`. – Sylvester Kruin Oct 25 '21 at 23:03
  • I have exactly that on now, found it in June :~) Thanks anyway though. And it does mean putting good use to the key I hate so much... – kettle Oct 27 '21 at 07:57

1 Answers1

0

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.

nkkollaw
  • 1,947
  • 1
  • 19
  • 29