Skip to content

Instantly share code, notes, and snippets.

@msenol86
Forked from springzfx/PKGBUILD
Last active May 10, 2021 23:12
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msenol86/c0c7daad3de32a7922486e5d669f24c6 to your computer and use it in GitHub Desktop.
Save msenol86/c0c7daad3de32a7922486e5d669f24c6 to your computer and use it in GitHub Desktop.
Fix copytoclipboard in deepin-screenshot by using xclip

Fix deepin-screenshot clipboard bug by using xclip

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.

I have added xclip as a dependecy to solve this issue. Deepin Screenshot creates a temporary file and then sends it to the xclip.

- martyr-deepin/deepin-screenshot#8

Please see for updated version: https://aur.archlinux.org/packages/deepin-screenshot-copy-patch

# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>
# Contributor: Xu Fasheng <fasheng.xu[AT]gmail.com>
# Contributor: Mucahit Senol <mucahitsenol86 at gmail dot 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' 'xclip')
makedepends=('cmake' 'qt5-tools')
groups=('deepin-extra')
source=("$pkgname-$pkgver.tar.gz::https://github.com/linuxdeepin/deepin-screenshot/archive/$pkgver.tar.gz"
"xclip.patch")
sha512sums=('ad073961deaa78a47739af6cf8b0d0fa77a92ee6668c57f9a5bbf51ad2be1d2028681cffabdc26548be1bdbe24c7ccc7e7ff3d49b86907f794495bfbea62aa30'
'74eadb86232153f0b652c71411aaa258f800b97066d3d9c6d9b971c4f6d55d3bb0c129b08b0c4e1448ec4db89cd1970be5733323a671b4852591ca20a2baeea8')
build() {
cd deepin-screenshot-$pkgver
patch src/mainwindow.cpp < $srcdir/xclip.patch
cmake . -DCMAKE_INSTALL_PREFIX=/usr
make
}
package() {
cd deepin-screenshot-$pkgver
make DESTDIR="$pkgdir" install
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index def901e..2f81456 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1401,8 +1401,30 @@ bool MainWindow::saveAction(const QPixmap &pix)
if (copyToClipboard) {
Q_ASSERT(!screenShotPix.isNull());
- QClipboard* cb = qApp->clipboard();
- cb->setPixmap(screenShotPix, QClipboard::Clipboard);
+ bool tmpFileCreated = false;
+
+ if (!QFile("/usr/bin/xclip").exists()) {
+ qCritical() << "Copying to clipboard failed. Please install xclip!";
+ return false;
+ } else {
+
+ QTemporaryFile file;
+ if (file.open()) {
+ tmpFileCreated = true;
+ screenShotPix.save(file.fileName(), "PNG");
+ qDebug() << "tmp filename: " << file.fileName();
+ QString command = QString("/usr/bin/xclip -selection clipboard -t image/png -i %1").arg(file.fileName());
+ if(m_saveFileName != "") {
+ command = QString("/usr/bin/xclip -selection clipboard -t image/png -i %1").arg(m_saveFileName); // if auto save + copy to clipboard selected, use saved file
+ }
+ qDebug() << "command: " << command;
+ QProcess::execute(command);
+ } // do not add else part to not distrubt tmp file destruction process
+ }
+ if(!tmpFileCreated) {
+ qCritical() << "Saving image into temporary file failed!";
+ return false;
+ }
}
return true;
@msenol86
Copy link
Author

@CodigoCristo
Copy link

Nice !

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