Skip to content

Commit

Permalink
fix: 修复浏览器中选中文本后长按Ctrl+C出现桌面崩溃的问题。
Browse files Browse the repository at this point in the history
此修改为配合窗管一起修改,解决wayland下多实例接收数据导致的问题。已将wayland下剪切板给UI提供数据和管理数据实例合并,去掉插件。

Log: 修复浏览器中选中文本后长按Ctrl+C出现桌面崩溃的问题。
Bug: https://pms.uniontech.com/bug-view-151723.html
Influence: 剪切板全量功能。
  • Loading branch information
yixinshark authored and deepin-bot[bot] committed Sep 7, 2022
1 parent f5ac129 commit d54b654
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 1,084 deletions.
83 changes: 7 additions & 76 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all")
set(CMAKE_EXE_LINKER_FLAGS "-z relro -z now -z noexecstack -pie")

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=address -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -O2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=address -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -O0")
endif()

if (DEFINED ENABLE_MIEEE)
Expand Down Expand Up @@ -139,9 +139,8 @@ install(TARGETS ${BIN_NAME} DESTINATION bin)
set(BIN_NAME dde-clipboard-daemon)

file(GLOB_RECURSE dde-clipboard-daemon_SCRS
"dde-clipboard-daemon/main.cpp"
"dde-clipboard-daemon/dbus_manager.cpp"
"dde-clipboard-daemon/dbus_manager.h"
"dde-clipboard-daemon/*.h"
"dde-clipboard-daemon/*.cpp"
)

add_executable(${BIN_NAME}
Expand All @@ -152,13 +151,15 @@ target_include_directories(${BIN_NAME} PUBLIC
${Qt5Widget_INCLUDE_DIRS}
${Qt5Core_INCLUDE_DIRS}
${DtkCore_INCLUDE_DIRS}
)
KF5::WaylandClient
)

target_link_libraries(${BIN_NAME} PRIVATE
${Qt5DBus_LIBRARIES}
${Qt5Core_LIBRARIES}
${Qt5Widgets_LIBRARIES}
${DtkCore_LIBRARIES}
KF5::WaylandClient
)

install(TARGETS ${BIN_NAME} DESTINATION bin)
Expand All @@ -172,76 +173,6 @@ install(FILES misc/dde-clipboard-daemon.desktop
DESTINATION /etc/xdg/autostart/
)

#----------------------------dde-clipboard-loader------------------------------
set(PLUGIN_NAME "dde-clipboard-loader")

file(GLOB_RECURSE dde-clipboard-loader_SCRS
"dde-clipboard-daemon/plugin/dde-clipboard-loader/*.h"
"dde-clipboard-daemon/plugin/dde-clipboard-loader/*.cpp"
"dde-clipboard-daemon/plugin/dde-clipboard-loader/src/*.h"
"dde-clipboard-daemon/plugin/dde-clipboard-loader/src/*.cpp"
)

add_definitions("${QT_DEFINITIONS} -DCLIPBOARD_LIBRARY")

add_library(${PLUGIN_NAME} SHARED
${dde-clipboard-loader_SCRS}
)

set_target_properties(${PLUGIN_NAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY
plugins/
)

target_include_directories(${PLUGIN_NAME} PUBLIC
${Qt5Widget_INCLUDE_DIRS}
${Qt5DBus_INCLUDE_DIRS}
KF5::WaylandClient
"dde-clipboard-daemon/plugin/dde-clipboard-loader/src"
)

target_link_libraries(${PLUGIN_NAME} PRIVATE
${Qt5Widgets_LIBRARIES}
${Qt5DBus_LIBRARIES}
KF5::WaylandClient
)

install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-clipboard/)

#----------------------------dde-clipboard-manager------------------------------
set(PLUGIN_NAME "dde-clipboard-manager")

file(GLOB_RECURSE dde-clipboard-manager_SRCS
"dde-clipboard-daemon/plugin/dde-clipboard-manager/*.h"
"dde-clipboard-daemon/plugin/dde-clipboard-manager/*.cpp"
"dde-clipboard-daemon/plugin/dde-clipboard-manager/src/*.h"
"dde-clipboard-daemon/plugin/dde-clipboard-manager/src/*.cpp"
)

add_definitions("${QT_DEFINITIONS} -DCLIPBOARD_LIBRARY")

add_library(${PLUGIN_NAME} SHARED ${dde-clipboard-manager_SRCS})

set_target_properties(${PLUGIN_NAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY
plugins/
)

target_include_directories(${PLUGIN_NAME} PUBLIC
${Qt5Widget_INCLUDE_DIRS}
${Qt5DBus_INCLUDE_DIRS}
KF5::WaylandServer
"dde-clipboard-daemon/plugin/dde-clipboard-manager/src"
)

target_link_libraries(${PLUGIN_NAME} PRIVATE
${Qt5Widgets_LIBRARIES}
${Qt5DBus_LIBRARIES}
KF5::WaylandClient
)

install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-clipboard/)

#----------------------------ut-dde-clipboard------------------------------
set(UT_BIN_NAME ut-dde-clipboard)

Expand Down
31 changes: 31 additions & 0 deletions dde-clipboard-daemon/clipboarddaemon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "clipboarddaemon.h"
#include "clipboardloader.h"

#include <QDBusError>
#include <QDBusConnection>

ClipboardDaemon::ClipboardDaemon(QObject *parent)
: QObject(parent)
{
QDBusConnection connection = QDBusConnection::sessionBus();
if (!connection.registerService("com.deepin.dde.ClipboardLoader")) {
qInfo() << "error:" << connection.lastError().message();
}

ClipboardLoader *clipboardLoader = new ClipboardLoader(this);
connection.registerObject("/com/deepin/dde/ClipboardLoader", clipboardLoader,
QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals);

// 剪切板管理和提供UI数据的功能合并,WaylandCopyClient只实例化一次
#if 0
// 实例化wayland 剪切板管理器
if (qEnvironmentVariable("XDG_SESSION_TYPE").contains("wayland")) {
WaylandCopyClient *waylandClipboardManager = new WaylandCopyClient(this);
waylandClipboardManager->init(true);
}
#endif
}
17 changes: 17 additions & 0 deletions dde-clipboard-daemon/clipboarddaemon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef CLIPBOARD_DAEMON_H
#define CLIPBOARD_DAEMON_H

#include <QObject>

class ClipboardDaemon : public QObject
{
Q_OBJECT
public:
explicit ClipboardDaemon(QObject *parent = nullptr);
};

#endif //CLIPBOARD_DAEMON_H
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "clipboard_loader.h"
#include "clipboardloader.h"

#include <QApplication>
#include <QDBusMetaType>
#include <QDebug>
#include <QClipboard>
#include <QMimeData>
#include <QDir>
Expand Down Expand Up @@ -82,15 +80,16 @@ ItemInfo Buf2Info(const QByteArray &buf)

QString ClipboardLoader::m_pixPath;

ClipboardLoader::ClipboardLoader()
: m_board(qApp->clipboard())
ClipboardLoader::ClipboardLoader(QObject *parent)
: QObject(parent)
, m_board(nullptr)
#ifdef USE_DEEPIN_KF5_WAYLAND
, m_waylandCopyClient(nullptr)
#endif
{
if (qEnvironmentVariable("XDG_SESSION_TYPE").contains("wayland")) {
#ifdef USE_DEEPIN_KF5_WAYLAND
m_waylandCopyClient = &WaylandCopyClient::ref();
m_waylandCopyClient = new WaylandCopyClient(this);
m_waylandCopyClient->init();

connect(m_waylandCopyClient, &WaylandCopyClient::dataChanged, this, [this] {
Expand All @@ -99,15 +98,16 @@ ClipboardLoader::ClipboardLoader()
#else
qWarning() << "we will not work with wayland";
#endif
} else {
m_board = qApp->clipboard();
connect(m_board, &QClipboard::dataChanged, this, [this] {
this->doWork(X11_PROTOCOL);
});
}

connect(m_board, &QClipboard::dataChanged, this, [this] {
this->doWork(X11_PROTOCOL);
});

QDir dir(QDir::homePath() + PixCacheDir);
if (dir.exists() && dir.removeRecursively()) {
qDebug() << "ClipboardLoder startup, remove old cache, path:" << dir.path();
qDebug() << "ClipboardLoader startup, remove old cache, path:" << dir.path();
}
}

Expand All @@ -132,7 +132,9 @@ void ClipboardLoader::dataReborned(const QByteArray &buf)
break;
}

m_board->setMimeData(mimeData);
if (m_board)
m_board->setMimeData(mimeData);

#ifdef USE_DEEPIN_KF5_WAYLAND
if (m_waylandCopyClient)
m_waylandCopyClient->setMimeData(mimeData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

#include "constants.h"
#ifdef USE_DEEPIN_KF5_WAYLAND
#include "wayland_copy_client.h"
#include "waylandcopyclient.h"
#endif

#include "iteminfo.h"

#include <QObject>
Expand All @@ -28,7 +29,7 @@ class ClipboardLoader : public QObject
Q_CLASSINFO("D-Bus Interface", "com.deepin.dde.ClipboardLoader")

public:
ClipboardLoader();
explicit ClipboardLoader(QObject *parent = nullptr);

bool cachePixmap(const QPixmap &srcPix, ItemInfo &info);
void setImageData(const ItemInfo &info, QMimeData *&mimeData);
Expand Down
File renamed without changes.
Loading

0 comments on commit d54b654

Please sign in to comment.