flameshot icon indicating copy to clipboard operation
flameshot copied to clipboard

Copy to clipboard doesn't work on Wayland

Open pintassilgo opened this issue 2 years ago • 44 comments

Flameshot Version

Flameshot v12.1.0 (001726a5)

Installation Type

Compiled from source

Operating System type and version

Linux

Description

Almost no copy function work on Wayland, both text or image:

  • Ctrl+C or button after creating a screenshot
  • "Copy URL" or "Image to Clipboard" on "Upload image" dialog (after uploading image to Imgur)

This one works, might be used as a tip to understand what is wrong in source:

  • "Copy URL" in "Upload History" dialog.

Interestingly, this one that works is the only one that doesn't produce any visual response like desktop notification saying "copied to clipboard". Others display a response saying it was copied, but it wasn't.

This is restricted to Wayland, I tried logging with X11 and it works. But it isn't a limitation of Wayland because other apps obviously works fine to copy things to clipboard, be it image or text.

Tried with official openSUSE Tumbleweed package (12.0.0) and compiling latest source by myself, both are affected.

Steps to reproduce

As in description.

Screenshots or screen recordings

No response

System Information

Operating System: openSUSE Tumbleweed 20220725 KDE Plasma Version: 5.25.3 KDE Frameworks Version: 5.96.0 Qt Version: 5.15.5 Kernel Version: 5.18.11-1-default (64-bit) Graphics Platform: Wayland Processors: 12 × AMD Ryzen 5 1600 Six-Core Processor Memory: 31,3 GiB of RAM Graphics Processor: AMD Radeon RX 570 Series

pintassilgo avatar Jul 29 '22 08:07 pintassilgo

Have you followed https://flameshot.org/docs/guide/wayland-help/#can-t-screen-anything-on-wayland-kde ? Basically have you installed xdg-desktop-portal-kde and xdg-desktop-portal?

mmahmoudian avatar Jul 29 '22 08:07 mmahmoudian

Yes, both were already installed.

Flameshot is working perfectly here, it's just that it can't copy things to clipboard.

I mentioned above in "Descrption" the only situation in which copying to clipboard is working, I guess it might help to investigate the root of the issue, looking into differences in source between that one and other "copy to clipboard" functions.

pintassilgo avatar Jul 29 '22 08:07 pintassilgo

Same happens on NixOS with KDE 5.23.3 and flameshot-12.1.0. I've been using NixOS with KDE for several months and copying to keyboard using CTRL-C shortcut never worked.

haizaar avatar Jul 29 '22 10:07 haizaar

I've been using NixOS with KDE for several months and copying to keyboard using CTRL-C shortcut never worked.

Just to make sure, you have checked that you are on Wayland, and in the Flameshot config Ctrl-c is bound to copy?

mmahmoudian avatar Jul 29 '22 10:07 mmahmoudian

Yes, 100% on wayland:

$ echo $XDG_SESSION_TYPE
wayland

Here is the snipped from Flameshot config screen:

Screenshot_20220729_210050

haizaar avatar Jul 29 '22 11:07 haizaar

Other shortcuts like Ctrl+S work just fine.

When I press Ctrl-C it does say "Capture saved to clipboard" but it's not actually.

haizaar avatar Jul 29 '22 11:07 haizaar

Just to make sure, you have checked that you are on Wayland, and in the Flameshot config Ctrl-c is bound to copy?

Just to be clear, the issue is not related to key pressing, because (1) every other shortcut is working and (2) it's still a issue when you try to copy to clipboard by clicking screen buttons instead of using shortcuts (with one single working exception as described in first comment).

pintassilgo avatar Jul 29 '22 13:07 pintassilgo

It's working from the notification pop menu (as in below), I guess it's coming from Plasma at this stage, not flameshot.

I'd like to see if this helps once I manage to build it on Nix

20220729_235056

haizaar avatar Jul 29 '22 13:07 haizaar

I'd like to see if this helps once I manage to build it on Nix

Thank you, that fixed part of the issue.

After building with cmake ../ -DUSE_WAYLAND_CLIPBOARD=true, copying image now works on Wayland, both by Ctrl+C and by clicking button.

But it still not perfect because copying URL string on upload still doesn't work. A desktop notification displays it was copied, but it wasn't. And if I click Copy URL button from "Upload image" dialog it also doesn't work: image

But from "Upload History" dialog, as I said in initial comment clicking in Copy URL does work. image

So now for this last remaining issue I believe it's something fixable in Flameshot code because there's already a place in which copy URL command works.

pintassilgo avatar Jul 29 '22 14:07 pintassilgo

Is there any reason for not using -DUSE_WAYLAND_CLIPBOARD=true in official binaries? As I said in previous comment, it fixes part of this Wayland issue. Now I just tested on X11 and it works on there too, so for me at least there's no negative side effect on compiling with that flag.

pintassilgo avatar Jul 29 '22 14:07 pintassilgo

So I managed to recompile flameshot with -DUSE_WAYLAND_CLIPBOARD=true on NixOS and now both Ctrl-C and clicking button work! Hooray!

If anyone is on NixOS, you can put the following snippet into a separate file and include in your configuration.nix (make sure to remove flameshot from your package list in other places of course):

{ config, pkgs, ... }:

let 

  flameshotPin = import (pkgs.fetchFromGitHub {
    owner = "haizaar";
    repo = "nixpkgs";
    rev = "ca6081cbce02589ad9594350ce6e5bca39b09ad1";
    sha256 = "6lOu2O4KAYfGccHdZQUEr2A3mdwEtcr3S7pyLxxlZII=";
  }) {};

in {
  environment.systemPackages = [ flameshotPin.flameshot ];
}

The only downside is that using it introduces dependency on kguiaddons which is probably not necessary for GNOME users.

But definitely it's a great progress!

haizaar avatar Jul 29 '22 16:07 haizaar

So I managed to recompile flameshot with -DUSE_WAYLAND_CLIPBOARD=true on NixOS and now both Ctrl-C and clicking button work! Hooray!

But just image copying, right? What about auto path copying on save and auto URL copying on upload? These are still not working for me.

pintassilgo avatar Jul 29 '22 16:07 pintassilgo

Yes, just the image copying. Getting file path after save into clipboard still doesn't work :/

haizaar avatar Jul 29 '22 16:07 haizaar

Well, I was curious enough to fix it by myself.

As said above, recompiling with -DUSE_WAYLAND_CLIPBOARD=true fixes copying image. Here is the code: https://github.com/flameshot-org/flameshot/blob/54690d5be8d8b23ff4736bda553e99de1a8bc9a7/src/utils/screenshotsaver.cpp#L109-L114

So I simply done the exact same thing for copying text, which still doesn't work with current source even with that compile flag:

flameshotdaemon.cpp

+
+#if USE_WAYLAND_CLIPBOARD
+#include <KSystemClipboard>
+#include <QMimeData>
+#endif
+
void FlameshotDaemon::attachTextToClipboard(QString text, QString notification)
{
    // Must send notification before clipboard modification on linux
    if (!notification.isEmpty()) {
        AbstractLogger::info() << notification;
    }

    m_hostingClipboard = true;
+
+#ifdef USE_WAYLAND_CLIPBOARD
+    auto* mimeData = new QMimeData();
+    mimeData->setText(text);
+    KSystemClipboard::instance()->setMimeData(mimeData,
+                                            QClipboard::Clipboard);
+#else
    QClipboard* clipboard = QApplication::clipboard();

    clipboard->blockSignals(true);
    // This variable is necessary because the signal doesn't get blocked on
    // windows for some reason
    m_clipboardSignalBlocked = true;
    clipboard->setText(text);
    clipboard->blockSignals(false);
+#endif
}

Recompiled and copying path and URL is now working!

It seems to be working perfectly, but I'm not sure if that's the optimal way to fix so I didn't submit a PR.

pintassilgo avatar Jul 29 '22 17:07 pintassilgo

@borgmanJeremy what do you think about https://github.com/flameshot-org/flameshot/issues/2848#issuecomment-1199796142

mmahmoudian avatar Jul 30 '22 08:07 mmahmoudian

Yes I think that is a good change to make. Im also fine with changing the packages to include the wayland clipboard dependencies as long as someone else does it. Not all distro's support it and I hate spending time on packaging.

borgmanJeremy avatar Jul 31 '22 14:07 borgmanJeremy

Just out of curiosity: is this change bound to happen then?

morrolinux avatar Aug 26 '22 13:08 morrolinux

@morrolinux the situation is that we are open to this change but we need someone to step up, do it, and keep maintaining it. Are you interested to contribute regarding this matter?

mmahmoudian avatar Aug 27 '22 18:08 mmahmoudian

On arch the official package already builds with said flag, yet it still does not work with everything else being fine except for actually copying the screenshot. I am using DWL as my compositor, and desktop portals are functioning correctly.

Edit: It seems like saving to a file does not work either.

Kirottu avatar Aug 29 '22 07:08 Kirottu

Same on Ubuntu 22.04 on Gnome/Wayland. Clicking copy here or hitting Ctrl+C seems to think it's being done successfully, but the clipboard is empty.

image

Also possibly related, Ctrl+S does nothing at all, but the save to file icon works. The shortcuts are configured correctly.

BrianLeishman avatar Sep 01 '22 14:09 BrianLeishman

I can confirm it for Zorin OS 16.1, which is basically Ubuntu 20.04 LTS with Gnome But I think it's not the OS Problem, as it worked very well with Ubuntu 20.04 LTS itself. Therefore I tried different installations: the snaps didn't work, the installation from flathub (all Versions 12) copies to clipboard see also https://github.com/flameshot-org/flameshot/issues/2857#issuecomment-1242999573

@https://github.com/flameshot-org/flameshot/issues/2813

gerhardbeck avatar Sep 13 '22 17:09 gerhardbeck

I sketched a little script to easy build and install flameshot with USE_WAYLAND_CLIPBOARD flag enabled on debian based distros. It also respects new version if it will be released.

#!/bin/bash

set -e

rm -rf build
mkdir -p build
cd build

sudo apt install devscripts equivs libkf5guiaddons-dev -y
sudo mk-build-deps -t'apt-get -y' -ir flameshot

apt source flameshot
SRC_DIR=`ls | cut -f1 | head -n1`

pushd ${SRC_DIR}
sed -i 's/-DFLAMESHOT_ABOUT_DEB_VERSION/-DUSE_WAYLAND_CLIPBOARD=1 -DFLAMESHOT_ABOUT_DEB_VERSION/' debian/rules
[email protected] dch -n ''
debuild -i -j -us -uc
popd

sudo apt purge flameshot-build-deps devscripts equivs libkf5guiaddons-dev --auto-remove -y

sudo dpkg -i flameshot_*.deb
rm -rf ../build

zorn-v avatar Oct 06 '22 19:10 zorn-v

But it still not perfect because copying URL string on upload still doesn't work.

The workaround to fix this remaining issue is launching flameshot with GDK_BACKEND=x11.

pintassilgo avatar Dec 07 '22 22:12 pintassilgo

The workaround to fix this remaining issue is launching flameshot with GDK_BACKEND=x11.

Didn't work for me on Kubuntu 22.10

ahangarha avatar Dec 18 '22 07:12 ahangarha

So, since i had already invested hours in trying to even make flameshot open in hyprland, I decided to get this working no matter what. I just found out that the image is actually copied in wl-copy, but pasting it doesn't work unless i do this: wl-paste | wl-copy which works. I have no idea why, but i hope it'll help someone in the meantime...

I also found out that up to a certain size of the screenshot, let's say 150x150, copying straight from flameshot works, but if make a bigger one, it doesn't work anymore, until i run the aforementioned command. Might even be an issue with wl-copy, I don't know.

As of right now I made this command for copyq that makes it work flawlessly

[Command]
Automatic=true
Command="
    bash:
    wl-paste | wl-copy"
Icon=\xf021
Input=image/png
Name=refresh wlcopy

DominickVale avatar Dec 23 '22 09:12 DominickVale

Copying to clipboard works if we run: flameshot gui --raw | wl-copy

ExistingExpert avatar Jan 02 '23 04:01 ExistingExpert

Same problem on Arch Linux and Flameshot v12.1.0 (-) compiled with Qt 5.15.5.

The Arch Linux package is compiled with -DUSE_WAYLAND_CLIPBOARD=1

simonbcn avatar Feb 22 '23 18:02 simonbcn

Copying to clipboard works if we run: flameshot gui --raw | wl-copy

Only this solution worked for me @ Hyprland even though i compiled with the -DUSE_WAYLAND_CLIPBOARD=1 flag

y0nei avatar Jul 05 '23 11:07 y0nei

It's still an issue with

Operating System: Kubuntu 23.04 KDE Plasma Version: 5.27.4 KDE Frameworks Version: 5.104.0 Qt Version: 5.15.8 Kernel Version: 6.2.0-25-generic (64-bit) Graphics Platform: Wayland Processors: 4 × Intel® Core™ i5-4460 CPU @ 3.20GHz Memory: 7.6 GiB of RAM Graphics Processor: Mesa Intel® HD Graphics 4600 Manufacturer: MSI Product Name: MS-7817 System Version: 1.0

This workaround works, albeit cumbersome. Need to install wl-copy. You will lose the ability to save to file directly.

neoscopio avatar Jul 14 '23 08:07 neoscopio

Can confirm that this patch works for me and fixes the issue of the uploaded image URL not being copied to clipboard (arch/wayland/plasma).

greg2010 avatar Aug 09 '23 22:08 greg2010