Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate from primary selection not work #407

Closed
FusionGold opened this issue Oct 22, 2024 · 15 comments · Fixed by #408
Closed

Translate from primary selection not work #407

FusionGold opened this issue Oct 22, 2024 · 15 comments · Fixed by #408
Labels
bug Something isn't working

Comments

@FusionGold
Copy link

I am encountering an issue with Dialect, both when installed via AUR (dialect-git) and Flatpak on my Archlinux Gnome Wayland desktop environment. When running dialect -n from terminal and attempting to translate from the primary selection, the following error occurs:

Traceback (most recent call last):
  File "/app/share/dialect/dialect/window.py", line 532, in on_paste
    text = clipboard.read_text_finish(result)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gi.repository.GLib.GError: g-io-error-quark: Cannot read from empty clipboard. (1)

Steps to Reproduce:

  1. Install Dialect via AUR (dialect-git) or Flatpak.
  2. In GNOME Text Editor, select a word and ensure wl-paste --primary can paste the content.
  3. With the flatpak version, run LANG=C flatpak run app.drey.Dialect -n
  4. Dialect window poped up with empty input and the above error message.
@FusionGold FusionGold changed the title Translate from primary selction not work Translate from primary selection not work Oct 22, 2024
@ivan-toriya
Copy link

Experiencing the same issue. Dialect 2.5.0, installed via flatpak.

@ivan-toriya
Copy link

Identified another issue: clipboard history is only available for running apps.
So, in order to translate the selection, I just run the flatpak run app.drey.Dialect --selection twice via custom shortcut.

@rafaelmardojai
Copy link
Member

If you use the paste button in Dialect, do you get the same error?

@FusionGold
Copy link
Author

Paste button works fine if I have contents in my clipboard.

@rafaelmardojai
Copy link
Member

Right, @mufeedali confirmed me that he could reproduce the problem, but I can't in my Fedora setup.

@ivan-toriya could you give me info about your system? I can get the selection activating Dialect once.

@ivan-toriya
Copy link

@rafaelmardojai
Debian 12.7, Gnome 43.9 (Wayland)

@mufeedali mufeedali added the bug Something isn't working label Oct 28, 2024
@ivan-toriya
Copy link

@rafaelmardojai
btw, is it possible to run Dialect in background or in minimized mode?

@rafaelmardojai
Copy link
Member

@ivan-toriya Nope.

@rafaelmardojai
Copy link
Member

If you have wl-clipboard, as a workaround to this issue you can use what's suggested in this comment: #219 (comment).

@FusionGold
Copy link
Author

@rafaelmardojai Thanks for the workaround hint.

@zefr0x
Copy link

zefr0x commented Oct 31, 2024

Identified another issue: clipboard history is only available for running apps. So, in order to translate the selection, I just run the flatpak run app.drey.Dialect --selection twice via custom shortcut.

You need to focus on Dialect window while the second run is done.

It looks like it is a Wayland thing that prevents a window from reading the clipboard unless you are currently focusing on it.

https://wayland.app/protocols/primary-selection-unstable-v1

The result will differ depending on the timing of execution and the desktop environment behaviour (e.g. auto focus on new opened windows). That's why some might not be able to reproduce.


@rafaelmardojai can we wait for the user to focus on the window before reading the clipboard? This should solve the issue.

@rafaelmardojai
Copy link
Member

@zefr0x Yes that's possible.

Implemented that in #408, could you test that PR?

@FusionGold
Copy link
Author

@rafaelmardojai It seems that the primary selection can be correctly filled in with #408 . However, now whenever the -n option is used, a 'Translation failed' warning pops up first, and then the translation appears.
Screenshot from 2024-11-02 01-46-24

@rafaelmardojai
Copy link
Member

@FusionGold should be fixed now, could you test?

@FusionGold
Copy link
Author

@rafaelmardojai Everything seems fine for me. Thanks for your hard work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants