archrelease: copy trunk to community-any
[ArchLinux/community.git] / flameshot / repos / community-x86_64 / flameshot-wayland-clipboard.patch
blob3affff78d17bf3fc2bb19d10faf3c8fca22b7ee3
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
6 ---
7 .github/workflows/Linux-pack.yml | 1 +
8 CMakeLists.txt | 2 ++
9 packaging/flatpak/org.flameshot.Flameshot.yml | 5 ++--
10 snapcraft.yaml | 2 ++
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:
20 fcitx-frontend-qt5 \
21 openssl \
22 ca-certificates
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
29 --- a/CMakeLists.txt
30 +++ b/CMakeLists.txt
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)
44 if (APPLE)
45 add_subdirectory(external/QHotkey)
46 endif()
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:
52 - name: flameshot
53 buildsystem: cmake-ninja
54 config-opts:
55 - - -DCMAKE_BUILD_TYPE=Release
56 + - -DCMAKE_BUILD_TYPE=Release
57 + - -DUSE_WAYLAND_CLIPBOARD=1
58 sources:
59 - type: git
60 url: https://github.com/flameshot-org/flameshot.git
61 - branch: master
62 \ No newline at end of file
63 + branch: master
64 diff --git a/snapcraft.yaml b/snapcraft.yaml
65 index 6714d9f3d..8da86f9a9 100644
66 --- a/snapcraft.yaml
67 +++ b/snapcraft.yaml
68 @@ -46,6 +46,8 @@ parts:
69 - kde-frameworks-5-qt-5-15-core20
70 source: https://github.com/flameshot-org/flameshot.git
71 plugin: cmake
72 + cmake-parameters:
73 + - -DUSE_WAYLAND_CLIPBOARD=1
74 source-type: git
75 override-pull: |
76 snapcraftctl pull
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(
82 DBus
83 LinguistTools)
85 +if (USE_WAYLAND_CLIPBOARD)
86 + find_package(KF5GuiAddons)
87 +endif()
89 set(CMAKE_AUTOMOC ON)
90 set(CMAKE_AUTORCC ON)
91 set(CMAKE_AUTOUIC ON)
92 @@ -190,8 +194,14 @@ target_link_libraries(
93 Qt5::Widgets
94 ${QTSINGLEAPPLICATION_LIBRARY}
95 QtColorWidgets
99 +if (USE_WAYLAND_CLIPBOARD)
100 + target_compile_definitions(flameshot PRIVATE USE_WAYLAND_CLIPBOARD=1)
101 + target_link_libraries(flameshot KF5::GuiAddons)
102 +endif()
104 if (APPLE)
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
111 @@ -9,6 +9,11 @@
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>
118 +#endif
120 #include <QApplication>
121 #include <QBuffer>
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());
127 - QPixmap pngPixmap;
128 + QPixmap formattedPixmap;
129 bool isLoaded =
130 - pngPixmap.loadFromData(reinterpret_cast<uchar*>(array.data()),
131 - array.size(),
132 - imageType.toUpper().toUtf8());
133 + formattedPixmap.loadFromData(reinterpret_cast<uchar*>(array.data()),
134 + array.size(),
135 + imageType.toUpper().toUtf8());
136 if (isLoaded) {
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"),
144 + QByteArray());
145 + KSystemClipboard::instance()->setMimeData(mimeData,
146 + QClipboard::Clipboard);
147 +#else
148 mimeData->setData("image/" + imageType, array);
149 QApplication::clipboard()->setMimeData(mimeData);
150 +#endif
152 } else {
153 AbstractLogger::error()
154 << QObject::tr("Error while saving to clipboard");