1 From 27961143dd8d73cb9a5cfda8f79f7890e20bf4f5 Mon Sep 17 00:00:00 2001
2 From: Jeremy Borgman <borgman.jeremy@pm.me>
3 Date: Wed, 19 Jan 2022 05:16:36 -0600
4 Subject: [PATCH] working on wayland clipboard
7 .github/workflows/Linux-pack.yml | 1 +
9 packaging/flatpak/org.flameshot.Flameshot.yml | 5 ++--
11 src/CMakeLists.txt | 10 +++++++
12 src/utils/screenshotsaver.cpp | 26 +++++++++++++++----
13 6 files changed, 39 insertions(+), 7 deletions(-)
15 diff --git a/.github/workflows/Linux-pack.yml b/.github/workflows/Linux-pack.yml
16 index da5ab0d00..9e714965d 100644
17 --- a/.github/workflows/Linux-pack.yml
18 +++ b/.github/workflows/Linux-pack.yml
19 @@ -484,6 +484,7 @@ jobs:
24 - name: Get go-appimage tool
25 # Will not use linuxdeployqt anymore, because it suopprts currently still-supported mainstream distribution,
26 # which is glibc 2.23. For more information, please see https://github.com/probonopd/linuxdeployqt/issues/340.
27 diff --git a/CMakeLists.txt b/CMakeLists.txt
28 index 66fd0581e..ec6479a7e 100644
31 @@ -67,6 +67,7 @@ option(USE_MONOCHROME_ICON "Build using monochrome icon as default" OFF)
32 option(GENERATE_TS "Regenerate translation source files" OFF)
33 option(USE_EXTERNAL_SINGLEAPPLICATION "Use external QtSingleApplication library" OFF)
34 option(USE_LAUNCHER_ABSOLUTE_PATH "Use absolute path for the desktop launcher" ON)
35 +option(USE_WAYLAND_CLIPBOARD "USE KF Gui Wayland Clipboard" OFF)
37 include(cmake/StandardProjectSettings.cmake)
39 @@ -108,6 +109,7 @@ option(BUILD_STATIC_LIBS ON)
40 option(BUILD_SHARED_LIBS OFF)
41 add_subdirectory(external/Qt-Color-Widgets EXCLUDE_FROM_ALL)
45 add_subdirectory(external/QHotkey)
47 diff --git a/packaging/flatpak/org.flameshot.Flameshot.yml b/packaging/flatpak/org.flameshot.Flameshot.yml
48 index 183a241b5..31a3d8af5 100644
49 --- a/packaging/flatpak/org.flameshot.Flameshot.yml
50 +++ b/packaging/flatpak/org.flameshot.Flameshot.yml
51 @@ -26,8 +26,9 @@ modules:
53 buildsystem: cmake-ninja
55 - - -DCMAKE_BUILD_TYPE=Release
56 + - -DCMAKE_BUILD_TYPE=Release
57 + - -DUSE_WAYLAND_CLIPBOARD=1
60 url: https://github.com/flameshot-org/flameshot.git
62 \ No newline at end of file
64 diff --git a/snapcraft.yaml b/snapcraft.yaml
65 index 6714d9f3d..8da86f9a9 100644
68 @@ -46,6 +46,8 @@ parts:
69 - kde-frameworks-5-qt-5-15-core20
70 source: https://github.com/flameshot-org/flameshot.git
73 + - -DUSE_WAYLAND_CLIPBOARD=1
77 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
78 index 4ae982cb7..4adc66a90 100644
79 --- a/src/CMakeLists.txt
80 +++ b/src/CMakeLists.txt
81 @@ -10,6 +10,10 @@ find_package(
85 +if (USE_WAYLAND_CLIPBOARD)
86 + find_package(KF5GuiAddons)
92 @@ -190,8 +194,14 @@ target_link_libraries(
94 ${QTSINGLEAPPLICATION_LIBRARY}
99 +if (USE_WAYLAND_CLIPBOARD)
100 + target_compile_definitions(flameshot PRIVATE USE_WAYLAND_CLIPBOARD=1)
101 + target_link_libraries(flameshot KF5::GuiAddons)
105 set(MACOSX_BUNDLE_IDENTIFIER "org.flameshot")
106 set_target_properties(
107 diff --git a/src/utils/screenshotsaver.cpp b/src/utils/screenshotsaver.cpp
108 index 317a0d65e..8f0d4d9d9 100644
109 --- a/src/utils/screenshotsaver.cpp
110 +++ b/src/utils/screenshotsaver.cpp
112 #include "src/utils/filenamehandler.h"
113 #include "src/utils/globalvalues.h"
114 #include "utils/desktopinfo.h"
116 +#if USE_WAYLAND_CLIPBOARD
117 +#include <KSystemClipboard>
120 #include <QApplication>
122 #include <QClipboard>
123 @@ -33,15 +38,26 @@ void ScreenshotSaver::saveToClipboardMime(const QPixmap& capture,
124 QImageWriter imageWriter{ &buffer, imageType.toUpper().toUtf8() };
125 imageWriter.write(capture.toImage());
128 + QPixmap formattedPixmap;
130 - pngPixmap.loadFromData(reinterpret_cast<uchar*>(array.data()),
132 - imageType.toUpper().toUtf8());
133 + formattedPixmap.loadFromData(reinterpret_cast<uchar*>(array.data()),
135 + imageType.toUpper().toUtf8());
137 - QMimeData* mimeData = new QMimeData;
139 + auto mimeData = new QMimeData();
141 +#ifdef USE_WAYLAND_CLIPBOARD
142 + mimeData->setImageData(formattedPixmap.toImage());
143 + mimeData->setData(QStringLiteral("x-kde-force-image-copy"),
145 + KSystemClipboard::instance()->setMimeData(mimeData,
146 + QClipboard::Clipboard);
148 mimeData->setData("image/" + imageType, array);
149 QApplication::clipboard()->setMimeData(mimeData);
153 AbstractLogger::error()
154 << QObject::tr("Error while saving to clipboard");