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

Clipboard v0.82 (flathub on Ubuntu) steals focus every two seconds on Wayland #171

Open
2 of 6 tasks
DavidKoot opened this issue Oct 12, 2023 · 11 comments
Open
2 of 6 tasks
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@DavidKoot
Copy link

Describe the bug
Once I have used Clipboard it will keep stealing for a split-second every two seconds or so. Very annoying when using context menus or other, that will just disappear if anything else gets focus.

To Reproduce
I might have a bit specific setup. I'm on Ubuntu (Gnome) 22.04, and I use ddterm as my terminal app, which is a Gnome specific extension that displays a dropdown, screen-wide terminal. I noticed that using this with Clipboard, results in the Clipboard application opening in the background whenever I issue a cb command. I then would have to alt+tab to the Clipboard application which then disappears and with that completes the command. I therefore installed the Gnome extension 'NoAnnoyance' which focuses directly any new spawn application, so I don't have to alt+tab to the Clipboard application. Not sure if that all contributes to the bug, I'll try to turn that off the next time before I use cb. Once this Clipboard behaviour started, it doesn't help to turn off 'NoAnnoyance'.

Expected behavior
Clearly, I don't want something to interfere with my input through mouse and/or keyboard typing, every two seconds.

Screenshots
Can't make any screenshots

Version
Clipboard 0.82, from Flathub, on Ubuntu 22.04, possibly influenced by the extension 'NoAnnoyance' thatThe version of CB you're using, how you got it, and what system you're using. Didn't have this problem with 0.81, but I have it quite consistently on other computers as well where I use Ubuntu/gnome extenstions as well.

Questionnaire
Check these boxes to see if your issue is valid or not.

  • If I compiled CB, then any errors that may be present don't mention "LTO error" (this is sadly a bug with the compiler, not Clipboard)
  • If I compiled CB, then any errors that may be present don't mention "XYZ has not been defined in namespace std" (this sadly means you need a compiler with C++20 support, so upgrade first)
  • I check all these boxes without reading them
  • I think bachata is the best music
  • I'm using the latest commit/release (we only support the latest)
  • If I downloaded CB from GitHub Actions or with the install script, any errors that may be present don't mention "GLIBC XYZ not found" (your system is sadly too outdated for CB, so upgrade it)

Additional context
Add any other context about the problem here.

Before you post
Please make sure you check previous bug reports before filing a new one.
This will help keep the Issues section less cluttered. :)
Feel free to delete this section once you've completed this form.

@DavidKoot DavidKoot added the bug Something isn't working label Oct 12, 2023
@Slackadays
Copy link
Owner

This is because 0.8.2 added asynchronous clipboard syncing, where CB will refresh every 2 seconds in the background to grab any changed desktop clipboard contents. Unfortunately, because you're using Ubuntu 22.04 on GNOME, this means you have Wayland. And because Wayland has this horrible new security feature where a window needs focus to get the clipboard, CB and other clipboard managers have to add a horrible hack by opening a temporary 1x1 window just to get focus. There is a special feature that some desktop systems support that gets rid of this issue, but it would require special handling code in CB to use.

Therefore, you can try the following to work around this issue:

  • switch to X11
  • disable desktop clipboard syncing with export CLIPBOARD_NOGUI=1
  • wait for someone to add the special handling code to CB

@DavidKoot
Copy link
Author

That sounds pretty horrible indeed. Thanks for explaining, it also explains some of the other things I've seen. Need to think about what to do now. I have played around with CLIPBOARD_NOGUI, but I just like to use cb together with ctrl-v pasting. Don't like it much to go back to X11 either. I guess this closes the issue then.

@Slackadays
Copy link
Owner

Slackadays commented Oct 12, 2023

I can see if anyone would like to make a PR to add the special Wayland code before closing this, because this is a recurring issue on Wayland

@Slackadays Slackadays added the help wanted Extra attention is needed label Oct 12, 2023
@Slackadays Slackadays pinned this issue Oct 12, 2023
@Slackadays Slackadays changed the title Clipboard v0.82 (flathub on Ubuntu) steals focus every two seconds Clipboard v0.82 (flathub on Ubuntu) steals focus every two seconds on Wayland Oct 12, 2023
@Slackadays Slackadays unpinned this issue Oct 12, 2023
@Slackadays Slackadays pinned this issue Oct 12, 2023
@PlexSheep
Copy link

can cb maybe use wl-copy and wl-paste to sync the clipboards? I don't know how it's done in NeoVim, but I can copy from NeoVim to my system without opening a window. This is reduces the functionality of the app a lot for me.

@Slackadays
Copy link
Owner

can cb maybe use wl-copy and wl-paste to sync the clipboards?

Actually, this may be easily possible in a future version by adding a custom script hook to each clipboard. However, I haven't done anything to add this feature yet, so stay tuned.

@MaddyGuthridge
Copy link
Contributor

Unfortunately, despite much experimentation, I haven't found a workaround to this on Gnome, and so have had to keep the GUI integration disabled, lest my typing be significantly disrupted by the constant focus stealing. Is there a way to monitor the clipboard in the background without stealing focus from other applications, eg putting it in the system tray instead?

@Slackadays
Copy link
Owner

Slackadays commented Jul 31, 2024

@MaddyGuthridge There is unfortunately no concrete fix, but the following will at least get rid of the symptom:

  • turn off Wayland with NO_WAYLAND=1
  • switch to a different window manager

There is a way to keep Wayland support without interfering with the focus, but it involves supporting a new non-standard protocol and I refuse to do that because Wayland feels like a huge waste of effort to me. However, I'd be all ears for a PR if anybody wants to take on the challenge!

@MaddyGuthridge
Copy link
Contributor

The NO_WAYLAND=1 thing doesn't seem to have worked for me (installed via Flatpak, configured using Flatseal).

image

Could it be a better user experience to disable GUI integration on Gnome Wayland (and other affected desktops/WMs) by default, given the degree to which it breaks the user experience?

Out of curiosity, which desktops/window managers aren't affected by the issue?

Either way, maybe I'll look into improving the Wayland support if I have time, since this tool is so excellent on every other system I use. No promises though, since C++ and I have a pretty questionable relationship :p

@Slackadays
Copy link
Owner

I think NO_WAYLAND=1 is actually what you'd use when building Clipboard to disable the Wayland library requirement, so it doesn't apply during runtime. Now that I look at it, CLIPBOARD_NO_GUI=1 seems to be the only way to disable it at runtime, but I can see if maybe a "one shot" option would work so there isn't any daemon constantly checking for new data. When I was testing this feature I was in fact using Gnome Wayland but maybe they changed something recently?

@MaddyGuthridge
Copy link
Contributor

Perhaps having it only check for new data when performing a paste operation could improve things? Still less than ideal, but unless people have scripts running in the background, it at least wouldn't interrupt typing.

Additionally, having a command to kill the daemon once it is started could be helpful (currently I need to kill it via my system monitor).

@bharathanr
Copy link

I'm really interested in this project, and I do hope to see this issue get fixed eventually. I'm also pretty excited of the option to sync through wl-clipboard.

If I find some time to learn more about Wayland, I'll gladly try my hand at raising a PR and providing a fix.

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

No branches or pull requests

5 participants