Skip to content

Instantly share code, notes, and snippets.

@springzfx
Last active March 28, 2022 16:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save springzfx/f881dff2d1c89efbfe59cfc288e09462 to your computer and use it in GitHub Desktop.
Save springzfx/f881dff2d1c89efbfe59cfc288e09462 to your computer and use it in GitHub Desktop.
Fix copytoclipboard in kde for deepin-screenshot

Fix deepin-screenshot clipboard bug in KDE

On X11 clipboard content is owned by the application, Data copied to clipboard remains in the clipboard only as long as the parent application is running and is discarded when the application quits.

Added "x-kde-force-image-copy" mime type to screenshots being copied to clipboard, which forces klipper clipboard manager to remember this clipboard entry even if user has set "ignore images" option to true in klipper.

Another thing you need to notice, deepin-screenshot should not exit too fast, otherwise the clipboard content will destroy before clipper manager finish syncing. This is important, if you just unchecked "ignore images" option in kde clipper manager, it will only work randomly, and mostly won't work.

1403a1404,1409
> // On X11 clipboard content is owned by the application,
> // Data copied to clipboard remains in the clipboard only
> // as long as the parent application is running and is discarded when the application quits.
> // Added "x-kde-force-image-copy" mime type to screenshots being copied to clipboard,
> // which forces klipper clipboard manager to remember this clipboard entry
> // even if user has set "ignore images" option to true in klipper.
1405c1411,1414
< cb->setPixmap(screenShotPix, QClipboard::Clipboard);
---
> QMimeData *data = new QMimeData();
> data->setImageData(screenShotPix.toImage());
> data->setData(QStringLiteral("x-kde-force-image-copy"), QByteArray());
> cb->setMimeData(data, QClipboard::Clipboard);
1464c1473,1474
< QTimer::singleShot(2, [=]{
---
> // set time longer, so klipper manager have enough time to sync
> QTimer::singleShot(500, [=]{
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>
# Contributor: Xu Fasheng <fasheng.xu[AT]gmail.com>
pkgname=deepin-screenshot
pkgver=5.0.0
pkgrel=1
pkgdesc="Easy-to-use screenshot tool for linuxdeepin desktop environment"
arch=('x86_64')
url="https://github.com/linuxdeepin/deepin-screenshot"
license=('GPL3')
depends=('deepin-qt5integration' 'dtkwm' 'deepin-turbo')
makedepends=('cmake' 'qt5-tools')
groups=('deepin-extra')
source=("$pkgname-$pkgver.tar.gz::https://github.com/linuxdeepin/deepin-screenshot/archive/$pkgver.tar.gz"
"fix_copytoclipboard_in_kde_for_deepin-screenshot.patch")
sha512sums=('ad073961deaa78a47739af6cf8b0d0fa77a92ee6668c57f9a5bbf51ad2be1d2028681cffabdc26548be1bdbe24c7ccc7e7ff3d49b86907f794495bfbea62aa30'
'9e453b5b78cf7cbaa1fe4342b5f7cef916b2476b42bc664a51441b925817cf4f9b040139d407236526e7d746dc2eec934379b311a8863da68494b206b0879f9d')
build() {
cd deepin-screenshot-$pkgver
patch src/mainwindow.cpp < $srcdir/fix_copytoclipboard_in_kde_for_deepin-screenshot.patch
cmake . -DCMAKE_INSTALL_PREFIX=/usr
make
}
package() {
cd deepin-screenshot-$pkgver
make DESTDIR="$pkgdir" install
}
@felixonmars
Copy link

I have adopted the patch into [community]/deepin-screenshot 5.0.0-6. Thanks!
archlinux/svntogit-community@8f16773#diff-3e341d2d9c67be01819b25b25d5e53ea3cdf3a38d28846cda85a195eb9b7203a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment