1

It's more of a question in "where to start?" category.

I need to make an app that can read currently selected text in Linux. It will only be used in KDE with KWin and X11 (Kubuntu, if that matters).

For example this is expected UX: I'm selecting text in Kate (or any other app) -> press some global shortcut -> either app starts or already running in background and reads that selected text from Kate and does something with it (saves to file, for example). And it should be able to read selection from any application (browsers, GTK apps, Qt apps, etc).

Is it even possible? Where should I start? What subsystem should have this info of "currently focused window" and "selected text in that window"? How can this be achieved? I would very much appreciate any guidance or insight, because I'm completely new to linux/KDE app development. Maybe there's an open-source app that does this so I can try and learn from sources? No requirements on lang and framework but Qt/C++ is preferable.

Thank you

  • 1
    I'm not quite sure I follow ... it's X11 default behaviour to put "selected text" into the clipboard; an app (or WM/DE) would have to go out of it's way to NOT do that. And any other X11 app can read the clipboard. – tink Dec 14 '20 at 00:27
  • @tink, wow, you're right, it does put it in clipboard, I actually didn't notice it before. Wow, thank you! Do you know whether it's X11 specific? Does selected text put on Wayland? – Oleksii Vynnychenko Dec 14 '20 at 00:36
  • heh. Glad to be of assistance ;) Btw, for "normal" clipboard interaction a "middle click" will paste ;) – tink Dec 14 '20 at 00:38
  • 1
    As for wayland - I can't say for sure, I *think* that it is compatible in that respect. – tink Dec 14 '20 at 00:40
  • 1
    @tink, thank you again, already reading about those 2 buffers (`CLIPBOARD` and `PRIMARY`). That's exactly the guidance I was looking for. You helped a lot! In case someone will see this question, interesting answer regarding clipboards in: https://stackoverflow.com/questions/27378318/c-get-string-from-clipboard-on-linux – Oleksii Vynnychenko Dec 14 '20 at 00:46

0 Answers0