johnfactotum / foliate

Read e-books in style
https://johnfactotum.github.io/foliate/
GNU General Public License v3.0
5.93k stars 273 forks source link

Doesn't work with Goldendict #1139

Closed aero31aero closed 8 months ago

aero31aero commented 9 months ago

Describe the bug

Foliate's text selection seems to work differently than rest of the system. In Goldendict, there's a feature where when the text selection is updated, it'll show a button to perform a dictionary lookup. That works everywhere on the entire system (Qt apps, GTK apps, electron apps, Discord etc) but not on Foliate. I'm assuming this has something to do with how Foliate deals with text, maybe it doesn't use the regular APIs for that and Goldendict cannot detect it?

To Reproduce

Steps to reproduce the behavior:

  1. Install Goldendict-ng and enable scanning and "Track Selection Change" options.
  2. Open Foliate
  3. Select some text using the mouse.
  4. Observe the lack of Goldendict popup.

Expected behavior

Foliate uses whatever standard APIs there are to let the system know that there has been a text selection change. This is fundamentally different from #791, even though the end goal is same.

Screenshots

  1. Discord with working popup:

image

  1. Foliate without the goldendict popup:

image

Version:

Additional context

I know that Foliate itself has dictionary lookup but its pretty useless for languages where words often have multiple forms and you need the word stems, something that goldendict and hunspell are designed to do well. Thus, just using Foliate's dictionary features isn't a good workaround for the core problem.

johnfactotum commented 9 months ago

I'm assuming this has something to do with how Foliate deals with text, maybe it doesn't use the regular APIs for that and Goldendict cannot detect it?

Assuming it's just using the primary clipboard, which it probably is because AFAIK that's the only API there is for getting the selection, I don't think there's actually a way to prevent the system from getting the selected text from WebKitGTK even if you really wanted to. But just to be sure, you can check this by selecting text in Foliate and pasting the selection, which on most systems you can do by middle-clicking, in another program.

If I have to guess, since popovers are separate windows in GTK 4, and the popover is modal, it might be that the popover is preventing other windows from showing, or something of the sort.

johnfactotum commented 9 months ago

Ah, okay. I see now that you're using the GTK 3 version. Well, in that case perhaps you can try disabling the selection popover in Preferences.

aero31aero commented 9 months ago

Hey, thanks for the quick reply.

I tried disabling it (When a word is selected > "Do Nothing"), but that didn't help.

But just to be sure, you can check this by selecting text in Foliate and pasting the selection

The text isn't copied to the clipboard automatically. Selecting (When a word is selected > "Copy") does copy it to the clipboard.

You mention I'm running the GTK3 version. Is there a GTK4 version I should try?

Edit: I installed the version from git (GTK4) and still no luck.

johnfactotum commented 9 months ago

No, I don't mean the clipboard. Well, it's a bit confusing because the "clipboard" can refer to many different things.

There are usually two clipboards, or selections used. The first is called "primary", and the other one is called "clipboard". See https://unix.stackexchange.com/questions/139191/whats-the-difference-between-primary-selection-and-clipboard-buffer

Whenever you select any text, it will be available in the primary selection clipboard. To paste this text, you will need to middle click with the mouse or trackpad, rather than clicking "Paste" or pressing Ctrl+V. This is something that's handled automatically by the toolkit and the system.

I guess there a couple things that can be considered here:

aero31aero commented 9 months ago

Ah, gotcha. I'm on Wayland, Kwin to be specific. Wayland doesn't have the same 3 step primary-secondary-clipboard split. I guess I'm on my own for now.

In that case, I have just the request to be able to run some command like: "myscript.sh ${selection}", but that's more like #791.

I tried all other text that I could select (search input, about the book, add a highlight note), but none show the popup. While typing these, I also realized that FCITX IME doesn't work either (ugh, hate when issues reveal themselves one by one!) so I'd see if there's a pattern too.

Can you leave this issue open in case something changes or someone who knows how Goldendict works internally can chime in?

johnfactotum commented 9 months ago

I'm on Wayland, Kwin to be specific.

Well, that explains it. I had assumed that you were using X11 since Goldendict-ng doesn't seem to support Wayland.

Wayland doesn't have the same 3 step primary-secondary-clipboard split.

I don't know how it works exactly, but there is a primary selection protocol for Wayland now, and on GNOME at least, there is a primary selection. If it doesn't work, it could be a KDE bug or an issue specific to your system.

In that case, I have just the request to be able to run some command like: "myscript.sh ${selection}", but that's more like https://github.com/johnfactotum/foliate/issues/791.

You can achieve that by binding a global shortcut on your desktop to launch dictionary apps with the selected text, e.g.

gnome-dictionary --look-up "$(wl-paste --primary)"

You can also use wl-paste --watch to look up words whenever the selection changes.