Wayland kde clipboard (#2305)

* 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
This commit is contained in:
borgmanJeremy
2022-01-22 09:57:10 -06:00
committed by GitHub
parent 00b1088997
commit 00685369a0
7 changed files with 49 additions and 16 deletions

View File

@@ -303,13 +303,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
dist: dist:
- { - {
name: fedora-34,
os: fedora,
symbol: 34,
arch: x86_64
}
- {
name: fedora-35, name: fedora-35,
os: fedora, os: fedora,
symbol: 35, symbol: 35,
@@ -484,6 +478,7 @@ jobs:
fcitx-frontend-qt5 \ fcitx-frontend-qt5 \
openssl \ openssl \
ca-certificates ca-certificates
- name: Get go-appimage tool - name: Get go-appimage tool
# Will not use linuxdeployqt anymore, because it suopprts currently still-supported mainstream distribution, # 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. # which is glibc 2.23. For more information, please see https://github.com/probonopd/linuxdeployqt/issues/340.

View File

@@ -67,6 +67,7 @@ option(USE_MONOCHROME_ICON "Build using monochrome icon as default" OFF)
option(GENERATE_TS "Regenerate translation source files" OFF) option(GENERATE_TS "Regenerate translation source files" OFF)
option(USE_EXTERNAL_SINGLEAPPLICATION "Use external QtSingleApplication library" 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_LAUNCHER_ABSOLUTE_PATH "Use absolute path for the desktop launcher" ON)
option(USE_WAYLAND_CLIPBOARD "USE KF Gui Wayland Clipboard" OFF)
include(cmake/StandardProjectSettings.cmake) include(cmake/StandardProjectSettings.cmake)
@@ -108,6 +109,7 @@ option(BUILD_STATIC_LIBS ON)
option(BUILD_SHARED_LIBS OFF) option(BUILD_SHARED_LIBS OFF)
add_subdirectory(external/Qt-Color-Widgets EXCLUDE_FROM_ALL) add_subdirectory(external/Qt-Color-Widgets EXCLUDE_FROM_ALL)
if (APPLE) if (APPLE)
add_subdirectory(external/QHotkey) add_subdirectory(external/QHotkey)
endif() endif()

View File

@@ -1,6 +1,6 @@
app-id: org.flameshot.Flameshot app-id: org.flameshot.Flameshot
runtime: org.kde.Platform runtime: org.kde.Platform
runtime-version: '5.15' runtime-version: '5.15-21.08'
sdk: org.kde.Sdk sdk: org.kde.Sdk
command: flameshot command: flameshot
finish-args: finish-args:
@@ -26,8 +26,9 @@ modules:
- name: flameshot - name: flameshot
buildsystem: cmake-ninja buildsystem: cmake-ninja
config-opts: config-opts:
- -DCMAKE_BUILD_TYPE=Release - -DCMAKE_BUILD_TYPE=Release
- -DUSE_WAYLAND_CLIPBOARD=1
sources: sources:
- type: git - type: git
url: https://github.com/flameshot-org/flameshot.git url: https://github.com/flameshot-org/flameshot.git
branch: master branch: master

View File

@@ -34,6 +34,9 @@ BuildRequires: ninja-build
BuildRequires: desktop-file-utils BuildRequires: desktop-file-utils
BuildRequires: cmake(Qt5Core) >= 5.9.0 BuildRequires: cmake(Qt5Core) >= 5.9.0
%if %{is_rhel_or_fedora}
BuildRequires: cmake(KF5GuiAddons) >= 5.89.0
%endif
BuildRequires: cmake(Qt5DBus) >= 5.9.0 BuildRequires: cmake(Qt5DBus) >= 5.9.0
BuildRequires: cmake(Qt5Gui) >= 5.9.0 BuildRequires: cmake(Qt5Gui) >= 5.9.0
BuildRequires: cmake(Qt5LinguistTools) >= 5.9.0 BuildRequires: cmake(Qt5LinguistTools) >= 5.9.0
@@ -78,7 +81,10 @@ Features:
%cmake -DCMAKE_BUILD_TYPE=Release %cmake -DCMAKE_BUILD_TYPE=Release
%endif %endif
%if %{is_rhel_or_fedora} %if %{is_rhel_or_fedora}
%cmake -G Ninja -DCMAKE_BUILD_TYPE=Release
%cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DUSE_WAYLAND_CLIPBOARD:BOOL=ON \
%endif %endif
%cmake_build %cmake_build

View File

@@ -46,6 +46,9 @@ parts:
- kde-frameworks-5-qt-5-15-core20 - kde-frameworks-5-qt-5-15-core20
source: https://github.com/flameshot-org/flameshot.git source: https://github.com/flameshot-org/flameshot.git
plugin: cmake plugin: cmake
# This cannot be enabled until the KF5 toolkit in the snap is updated
#cmake-parameters:
# - -DUSE_WAYLAND_CLIPBOARD=1
source-type: git source-type: git
override-pull: | override-pull: |
snapcraftctl pull snapcraftctl pull

View File

@@ -10,6 +10,10 @@ find_package(
DBus DBus
LinguistTools) LinguistTools)
if (USE_WAYLAND_CLIPBOARD)
find_package(KF5GuiAddons)
endif()
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC ON)
@@ -190,8 +194,14 @@ target_link_libraries(
Qt5::Widgets Qt5::Widgets
${QTSINGLEAPPLICATION_LIBRARY} ${QTSINGLEAPPLICATION_LIBRARY}
QtColorWidgets QtColorWidgets
) )
if (USE_WAYLAND_CLIPBOARD)
target_compile_definitions(flameshot PRIVATE USE_WAYLAND_CLIPBOARD=1)
target_link_libraries(flameshot KF5::GuiAddons)
endif()
if (APPLE) if (APPLE)
set(MACOSX_BUNDLE_IDENTIFIER "org.flameshot") set(MACOSX_BUNDLE_IDENTIFIER "org.flameshot")
set_target_properties( set_target_properties(

View File

@@ -9,6 +9,11 @@
#include "src/utils/filenamehandler.h" #include "src/utils/filenamehandler.h"
#include "src/utils/globalvalues.h" #include "src/utils/globalvalues.h"
#include "utils/desktopinfo.h" #include "utils/desktopinfo.h"
#if USE_WAYLAND_CLIPBOARD
#include <KSystemClipboard>
#endif
#include <QApplication> #include <QApplication>
#include <QBuffer> #include <QBuffer>
#include <QClipboard> #include <QClipboard>
@@ -33,15 +38,26 @@ void ScreenshotSaver::saveToClipboardMime(const QPixmap& capture,
QImageWriter imageWriter{ &buffer, imageType.toUpper().toUtf8() }; QImageWriter imageWriter{ &buffer, imageType.toUpper().toUtf8() };
imageWriter.write(capture.toImage()); imageWriter.write(capture.toImage());
QPixmap pngPixmap; QPixmap formattedPixmap;
bool isLoaded = bool isLoaded =
pngPixmap.loadFromData(reinterpret_cast<uchar*>(array.data()), formattedPixmap.loadFromData(reinterpret_cast<uchar*>(array.data()),
array.size(), array.size(),
imageType.toUpper().toUtf8()); imageType.toUpper().toUtf8());
if (isLoaded) { 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); mimeData->setData("image/" + imageType, array);
QApplication::clipboard()->setMimeData(mimeData); QApplication::clipboard()->setMimeData(mimeData);
#endif
} else { } else {
AbstractLogger::error() AbstractLogger::error()
<< QObject::tr("Error while saving to clipboard"); << QObject::tr("Error while saving to clipboard");