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;
@azamalvi
Copy link

azamalvi commented Jun 6, 2020

how to use this code?
Just copy all and paste into console?

@Zagrebelin
Copy link

how to use this code?
Just copy all and paste into console?

No, you have to apply this patch to source code and rebuild deepin.
Unfortunaly i have not idea how to do it.

@martin640
Copy link

  1. Make a dir for patch mkdir deepin-screenshot-patch
  2. cd mkdir deepin-screenshot-patch
  3. Download PKGBUILD with wget https://gist.githubusercontent.com/msenol86/c0c7daad3de32a7922486e5d669f24c6/raw/82abb9ad54f13c8e53d6272e0d0a999498ffa204/PKGBUILD
  4. Download xclip.patch with wget https://gist.githubusercontent.com/msenol86/c0c7daad3de32a7922486e5d669f24c6/raw/82abb9ad54f13c8e53d6272e0d0a999498ffa204/xclip.patch
  5. If you never used makepkg, ensure you have required tools with sudo pacman -Sy --needed base-devel
  6. Build package with makepkg -si

@msenol86
Copy link
Author

msenol86 commented Jul 13, 2020

@hoaivan
Copy link

hoaivan commented Aug 3, 2020

Hi, i got this when builing the patch. Any idea?

 ✘ voi@voi-pc  ~/Research/Screenshot  makepkg -si
==> Making package: deepin-screenshot 5.0.0-1 (Mon 03 Aug 2020 05:25:25 PM +07)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Found deepin-screenshot-5.0.0.tar.gz
  -> Found xclip.patch
==> Validating source files with sha512sums...
    deepin-screenshot-5.0.0.tar.gz ... Passed
    xclip.patch ... Passed
==> Extracting sources...
  -> Extracting deepin-screenshot-5.0.0.tar.gz with bsdtar
==> Removing existing $pkgdir/ directory...
==> Starting build()...
patching file src/mainwindow.cpp
patch unexpectedly ends in middle of line
Hunk #1 succeeded at 1401 with fuzz 1.

process translations/deepin-screenshot_af.ts
Updating 'translations/deepin-screenshot_af.qm'...
    Generated 6 translation(s) (6 finished and 0 unfinished)
    Ignored 46 untranslated source text(s)

process translations/deepin-screenshot_am_ET.ts
Updating 'translations/deepin-screenshot_am_ET.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_ar.ts
Updating 'translations/deepin-screenshot_ar.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_ast.ts
Updating 'translations/deepin-screenshot_ast.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_az.ts
Updating 'translations/deepin-screenshot_az.qm'...
    Generated 11 translation(s) (11 finished and 0 unfinished)
    Ignored 41 untranslated source text(s)

process translations/deepin-screenshot_bg.ts
Updating 'translations/deepin-screenshot_bg.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_bn.ts
Updating 'translations/deepin-screenshot_bn.qm'...
    Generated 9 translation(s) (9 finished and 0 unfinished)
    Ignored 43 untranslated source text(s)

process translations/deepin-screenshot_ca.ts
Updating 'translations/deepin-screenshot_ca.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_cs.ts
Updating 'translations/deepin-screenshot_cs.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_da.ts
Updating 'translations/deepin-screenshot_da.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_de.ts
Updating 'translations/deepin-screenshot_de.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_el.ts
Updating 'translations/deepin-screenshot_el.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_en_AU.ts
Updating 'translations/deepin-screenshot_en_AU.qm'...
    Generated 14 translation(s) (14 finished and 0 unfinished)
    Ignored 38 untranslated source text(s)

process translations/deepin-screenshot_eo.ts
Updating 'translations/deepin-screenshot_eo.qm'...
    Generated 9 translation(s) (9 finished and 0 unfinished)
    Ignored 43 untranslated source text(s)

process translations/deepin-screenshot_es_419.ts
Updating 'translations/deepin-screenshot_es_419.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_es.ts
Updating 'translations/deepin-screenshot_es.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_fa.ts
Updating 'translations/deepin-screenshot_fa.qm'...
    Generated 8 translation(s) (8 finished and 0 unfinished)
    Ignored 44 untranslated source text(s)

process translations/deepin-screenshot_fil.ts
Updating 'translations/deepin-screenshot_fil.qm'...
    Generated 0 translation(s) (0 finished and 0 unfinished)
    Ignored 51 untranslated source text(s)

process translations/deepin-screenshot_fi.ts
Updating 'translations/deepin-screenshot_fi.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_fr.ts
Updating 'translations/deepin-screenshot_fr.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_gl_ES.ts
Updating 'translations/deepin-screenshot_gl_ES.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_he.ts
Updating 'translations/deepin-screenshot_he.qm'...
    Generated 46 translation(s) (46 finished and 0 unfinished)
    Ignored 6 untranslated source text(s)

process translations/deepin-screenshot_hi_IN.ts
Updating 'translations/deepin-screenshot_hi_IN.qm'...
    Generated 43 translation(s) (43 finished and 0 unfinished)
    Ignored 9 untranslated source text(s)

process translations/deepin-screenshot_hr.ts
Updating 'translations/deepin-screenshot_hr.qm'...
    Generated 50 translation(s) (50 finished and 0 unfinished)
    Ignored 2 untranslated source text(s)

process translations/deepin-screenshot_hu.ts
Updating 'translations/deepin-screenshot_hu.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_hy.ts
Updating 'translations/deepin-screenshot_hy.qm'...
    Generated 5 translation(s) (5 finished and 0 unfinished)
    Ignored 47 untranslated source text(s)

process translations/deepin-screenshot_id.ts
Updating 'translations/deepin-screenshot_id.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_it.ts
Updating 'translations/deepin-screenshot_it.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_ja.ts
Updating 'translations/deepin-screenshot_ja.qm'...
    Generated 50 translation(s) (50 finished and 0 unfinished)
    Ignored 2 untranslated source text(s)

process translations/deepin-screenshot_ko.ts
Updating 'translations/deepin-screenshot_ko.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_ku_IQ.ts
Updating 'translations/deepin-screenshot_ku_IQ.qm'...
    Generated 3 translation(s) (3 finished and 0 unfinished)
    Ignored 49 untranslated source text(s)

process translations/deepin-screenshot_lt.ts
Updating 'translations/deepin-screenshot_lt.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_ml.ts
Updating 'translations/deepin-screenshot_ml.qm'...
    Generated 6 translation(s) (6 finished and 0 unfinished)
    Ignored 46 untranslated source text(s)

process translations/deepin-screenshot_mn.ts
Updating 'translations/deepin-screenshot_mn.qm'...
    Generated 6 translation(s) (6 finished and 0 unfinished)
    Ignored 46 untranslated source text(s)

process translations/deepin-screenshot_ms.ts
Updating 'translations/deepin-screenshot_ms.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_nb.ts
Updating 'translations/deepin-screenshot_nb.qm'...
    Generated 49 translation(s) (49 finished and 0 unfinished)
    Ignored 3 untranslated source text(s)

process translations/deepin-screenshot_ne.ts
Updating 'translations/deepin-screenshot_ne.qm'...
    Generated 4 translation(s) (4 finished and 0 unfinished)
    Ignored 48 untranslated source text(s)

process translations/deepin-screenshot_nl.ts
Updating 'translations/deepin-screenshot_nl.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_pam.ts
Updating 'translations/deepin-screenshot_pam.qm'...
    Generated 5 translation(s) (5 finished and 0 unfinished)
    Ignored 47 untranslated source text(s)

process translations/deepin-screenshot_pl.ts
Updating 'translations/deepin-screenshot_pl.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_pt_BR.ts
Updating 'translations/deepin-screenshot_pt_BR.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_pt.ts
Updating 'translations/deepin-screenshot_pt.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_ro.ts
Updating 'translations/deepin-screenshot_ro.qm'...
    Generated 45 translation(s) (45 finished and 0 unfinished)
    Ignored 7 untranslated source text(s)

process translations/deepin-screenshot_ru.ts
Updating 'translations/deepin-screenshot_ru.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_sk.ts
Updating 'translations/deepin-screenshot_sk.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_sl.ts
Updating 'translations/deepin-screenshot_sl.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_sq.ts
Updating 'translations/deepin-screenshot_sq.qm'...
    Generated 2 translation(s) (2 finished and 0 unfinished)
    Ignored 50 untranslated source text(s)

process translations/deepin-screenshot_sr.ts
Updating 'translations/deepin-screenshot_sr.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_sv.ts
Updating 'translations/deepin-screenshot_sv.qm'...
    Generated 49 translation(s) (49 finished and 0 unfinished)
    Ignored 3 untranslated source text(s)

process translations/deepin-screenshot_ta.ts
Updating 'translations/deepin-screenshot_ta.qm'...
    Generated 8 translation(s) (8 finished and 0 unfinished)
    Ignored 44 untranslated source text(s)

process translations/deepin-screenshot_tr.ts
Updating 'translations/deepin-screenshot_tr.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot.ts
Updating 'translations/deepin-screenshot.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_uk.ts
Updating 'translations/deepin-screenshot_uk.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_vi.ts
Updating 'translations/deepin-screenshot_vi.qm'...
    Generated 14 translation(s) (14 finished and 0 unfinished)
    Ignored 38 untranslated source text(s)

process translations/deepin-screenshot_zh_CN.ts
Updating 'translations/deepin-screenshot_zh_CN.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_zh_HK.ts
Updating 'translations/deepin-screenshot_zh_HK.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)

process translations/deepin-screenshot_zh_TW.ts
Updating 'translations/deepin-screenshot_zh_TW.qm'...
    Generated 52 translation(s) (52 finished and 0 unfinished)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0
[  2%] Automatic MOC for target deepin-screenshot
[  2%] Built target deepin-screenshot_autogen
Scanning dependencies of target deepin-screenshot
[  5%] Building CXX object CMakeFiles/deepin-screenshot.dir/src/mainwindow.cpp.o
[  7%] Building CXX object CMakeFiles/deepin-screenshot.dir/src/widgets/shapeswidget.cpp.o
/home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/widgets/shapeswidget.cpp: In member function ‘void ShapesWidget::paintRect(QPainter&, FourPoints, int, ShapesWidget::ShapeBlurStatus, bool, bool)’:
/home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/widgets/shapeswidget.cpp:1262:18: error: aggregate ‘QPainterPath rectPath’ has incomplete type and cannot be defined
 1262 |     QPainterPath rectPath;
      |                  ^~~~~~~~
/home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/widgets/shapeswidget.cpp: In member function ‘void ShapesWidget::paintEllipse(QPainter&, FourPoints, int, ShapesWidget::ShapeBlurStatus, bool, bool)’:
/home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/widgets/shapeswidget.cpp:1300:18: error: aggregate ‘QPainterPath ellipsePath’ has incomplete type and cannot be defined
 1300 |     QPainterPath ellipsePath;
      |                  ^~~~~~~~~~~
/home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/widgets/shapeswidget.cpp: In member function ‘void ShapesWidget::paintArrow(QPainter&, QList<QPointF>, int, bool)’:
/home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/widgets/shapeswidget.cpp:1328:26: error: aggregate ‘QPainterPath path’ has incomplete type and cannot be defined
 1328 |             QPainterPath path;
      |                          ^~~~
/home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/widgets/shapeswidget.cpp: In member function ‘void ShapesWidget::paintLine(QPainter&, QList<QPointF>)’:
/home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/widgets/shapeswidget.cpp:1346:18: error: aggregate ‘QPainterPath linePaths’ has incomplete type and cannot be defined
 1346 |     QPainterPath linePaths;
      |                  ^~~~~~~~~
/home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/mainwindow.cpp: In member function ‘bool MainWindow::saveAction(const QPixmap&)’:
/home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/mainwindow.cpp:1421:42: warning: ‘static int QProcess::execute(const QString&)’ is deprecated: Use QProcess::execute(const QString &program, const QStringList &arguments) instead [-Wdeprecated-declarations]
 1421 |                 QProcess::execute(command);
      |                                          ^
In file included from /usr/include/qt/QtCore/QtCore:170,
                 from /home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/utils/shapesutils.h:23,
                 from /home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/widgets/shapeswidget.h:26,
                 from /home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/mainwindow.h:38,
                 from /home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/mainwindow.cpp:20:
/usr/include/qt/QtCore/qprocess.h:263:16: note: declared here
  263 |     static int execute(const QString &command);
      |                ^~~~~~~
/home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/mainwindow.cpp: In member function ‘void MainWindow::onViewShortcut()’:
/home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/mainwindow.cpp:1533:69: warning: ‘static bool QProcess::startDetached(const QString&)’ is deprecated: Use QProcess::startDetached(const QString &program, const QStringList &arguments) instead [-Wdeprecated-declarations]
 1533 |     shortcutViewProc->startDetached("killall deepin-shortcut-viewer");
      |                                                                     ^
In file included from /usr/include/qt/QtCore/QtCore:170,
                 from /home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/utils/shapesutils.h:23,
                 from /home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/widgets/shapeswidget.h:26,
                 from /home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/mainwindow.h:38,
                 from /home/voi/Research/Screenshot/src/deepin-screenshot-5.0.0/src/mainwindow.cpp:20:
/usr/include/qt/QtCore/qprocess.h:278:17: note: declared here
  278 |     static bool startDetached(const QString &command);
      |                 ^~~~~~~~~~~~~
make[2]: *** [CMakeFiles/deepin-screenshot.dir/build.make:717: CMakeFiles/deepin-screenshot.dir/src/widgets/shapeswidget.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:97: CMakeFiles/deepin-screenshot.dir/all] Error 2
make: *** [Makefile:150: all] Error 2
==> ERROR: A failure occurred in build().
    Aborting...

@msenol86
Copy link
Author

@hoaivan I think it is related to deepin-screenshot_autogen, I will check it. I get a different error on my machine.

@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