Slackadays / Clipboard

😎🏖️🐬 Your new, 𝙧𝙞𝙙𝙤𝙣𝙠𝙪𝙡𝙞𝙘𝙞𝙤𝙪𝙨𝙡𝙮 smart clipboard manager
https://getclipboard.app/
GNU General Public License v3.0
4.64k stars 133 forks source link

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

Open DavidKoot opened 11 months ago

DavidKoot commented 11 months ago

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.

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.

Slackadays commented 11 months ago

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:

DavidKoot commented 11 months ago

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 commented 11 months ago

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

PlexSheep commented 10 months ago

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 commented 8 months ago

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 commented 1 month ago

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 commented 1 month ago

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

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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).