Skip to content

Commit

Permalink
Wayland kde clipboard (#2305)
Browse files Browse the repository at this point in the history
* working on wayland clipboard

* disabled wayland kde clipboard fix on snap until Kf5 tools are updated

* enable wayland clibboard on fedora

* drop fedora 34 and disable wayland clipboard on suse until it gets a new enough kf5
  • Loading branch information
borgmanJeremy committed Jan 28, 2022
1 parent 5075cbd commit 19d9284
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/Linux-pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ jobs:
fail-fast: false
matrix:
dist:
- {
- {
name: fedora-35,
os: fedora,
symbol: 35,
Expand Down Expand Up @@ -478,6 +478,7 @@ jobs:
fcitx-frontend-qt5 \
openssl \
ca-certificates
- name: Get go-appimage tool
# Will not use linuxdeployqt anymore, because it suopprts currently still-supported mainstream distribution,
# which is glibc 2.23. For more information, please see https://github.com/probonopd/linuxdeployqt/issues/340.
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ option(USE_MONOCHROME_ICON "Build using monochrome icon as default" OFF)
option(GENERATE_TS "Regenerate translation source files" OFF)
option(USE_EXTERNAL_SINGLEAPPLICATION "Use external QtSingleApplication library" OFF)
option(USE_LAUNCHER_ABSOLUTE_PATH "Use absolute path for the desktop launcher" ON)
option(USE_WAYLAND_CLIPBOARD "USE KF Gui Wayland Clipboard" OFF)


if (USE_QT6)
Expand Down Expand Up @@ -92,6 +93,7 @@ option(BUILD_STATIC_LIBS ON)
option(BUILD_SHARED_LIBS OFF)
add_subdirectory(external/Qt-Color-Widgets EXCLUDE_FROM_ALL)


if (APPLE)
add_subdirectory(external/QHotkey)
endif()
Expand Down
5 changes: 3 additions & 2 deletions packaging/flatpak/org.flameshot.Flameshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ modules:
- name: flameshot
buildsystem: cmake-ninja
config-opts:
- -DCMAKE_BUILD_TYPE=Release
- -DCMAKE_BUILD_TYPE=Release
- -DUSE_WAYLAND_CLIPBOARD=1
sources:
- type: git
url: https://github.com/flameshot-org/flameshot.git
branch: master
branch: master
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ target_link_libraries(
Qt${QT_VERSION_MAJOR}::Widgets
${QTSINGLEAPPLICATION_LIBRARY}
QtColorWidgets

)

if (USE_WAYLAND_CLIPBOARD)
Expand Down
26 changes: 21 additions & 5 deletions src/utils/screenshotsaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include "src/utils/filenamehandler.h"
#include "src/utils/globalvalues.h"
#include "utils/desktopinfo.h"

#if USE_WAYLAND_CLIPBOARD
#include <KSystemClipboard>
#endif

#include <QApplication>
#include <QBuffer>
#include <QClipboard>
Expand All @@ -33,15 +38,26 @@ void ScreenshotSaver::saveToClipboardMime(const QPixmap& capture,
QImageWriter imageWriter{ &buffer, imageType.toUpper().toUtf8() };
imageWriter.write(capture.toImage());

QPixmap pngPixmap;
QPixmap formattedPixmap;
bool isLoaded =
pngPixmap.loadFromData(reinterpret_cast<uchar*>(array.data()),
array.size(),
imageType.toUpper().toUtf8());
formattedPixmap.loadFromData(reinterpret_cast<uchar*>(array.data()),
array.size(),
imageType.toUpper().toUtf8());
if (isLoaded) {
QMimeData* mimeData = new QMimeData;

auto mimeData = new QMimeData();

#ifdef USE_WAYLAND_CLIPBOARD
mimeData->setImageData(formattedPixmap.toImage());
mimeData->setData(QStringLiteral("x-kde-force-image-copy"),
QByteArray());
KSystemClipboard::instance()->setMimeData(mimeData,
QClipboard::Clipboard);
#else
mimeData->setData("image/" + imageType, array);
QApplication::clipboard()->setMimeData(mimeData);
#endif

} else {
AbstractLogger::error()
<< QObject::tr("Error while saving to clipboard");
Expand Down

0 comments on commit 19d9284

Please sign in to comment.