Skip to content
Merged

62 #64

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DeskControler/DeskControler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QJsonObject>
#include <QFile>
#include "VideoWidget.h"
#include "RemoteClipboard.h"
#include "LogWidget.h"

DeskControler::DeskControler(QWidget* parent)
Expand Down Expand Up @@ -201,6 +202,11 @@ void DeskControler::setupVideoSession(const QString& relayServer, quint16 relayP
m_videoReceiver = new VideoReceiver(this);


RemoteClipboard* remoteClipboard = new RemoteClipboard(this);

connect(remoteClipboard, &RemoteClipboard::clipboardDataReady,
m_videoReceiver, &VideoReceiver::clipboardDataCaptured);

connect(videoWidget, &VideoWidget::mouseEventCaptured,
m_videoReceiver, &VideoReceiver::mouseEventCaptured);

Expand Down
4 changes: 4 additions & 0 deletions DeskControler/DeskControler.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<ClCompile Include="MessageHandler.cpp" />
<ClCompile Include="NetworkManager.cpp" />
<ClCompile Include="NetworkWorker.cpp" />
<ClCompile Include="RemoteClipboard.cpp" />
<ClCompile Include="VideoDecoderWorker.cpp" />
<ClCompile Include="VideoReceiver.cpp" />
<ClCompile Include="VideoWidget.cpp" />
Expand Down Expand Up @@ -104,6 +105,9 @@
<ItemGroup>
<QtMoc Include="NetworkWorker.h" />
</ItemGroup>
<ItemGroup>
<QtMoc Include="RemoteClipboard.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
<Import Project="$(QtMsBuild)\qt.targets" />
Expand Down
34 changes: 34 additions & 0 deletions DeskControler/NetworkWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,40 @@ void NetworkWorker::sendKeyEventToServer(int key, bool pressed)
}
}

void NetworkWorker::sendClipboardEventToServer(const ClipboardEvent& clipboardEvent)
{
if (m_socket->state() != QAbstractSocket::ConnectedState) {
return; // 如果没有连接上 RelayServer,就不发送
}

// 组装 ClipboardEvent 消息到 RendezvousMessage 中
RendezvousMessage msg;
*msg.mutable_clipboardevent() = clipboardEvent;

std::string serialized;
if (!msg.SerializeToString(&serialized)) {
LogWidget::instance()->addLog("Failed to serialize ClipboardEvent message", LogWidget::Error);
return;
}

QByteArray protobufData(serialized.data(), serialized.size());

// 计算长度头(大端序)
quint32 len = static_cast<quint32>(protobufData.size());
quint32 len_be = qToBigEndian(len); // 大端序转换

// 构造完整数据
QByteArray sendData;
sendData.append(reinterpret_cast<const char*>(&len_be), sizeof(len_be));
sendData.append(protobufData);

if (m_socket && m_socket->state() == QAbstractSocket::ConnectedState) {
m_socket->write(sendData);
m_socket->flush();
}
}



void NetworkWorker::onSocketError(QAbstractSocket::SocketError socketError)
{
Expand Down
1 change: 1 addition & 0 deletions DeskControler/NetworkWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public slots:
void cleanup();
void sendMouseEventToServer(int x, int y, int mask);
void sendKeyEventToServer(int key, bool pressed);
void sendClipboardEventToServer(const ClipboardEvent& clipboardEvent);


signals:
Expand Down
67 changes: 67 additions & 0 deletions DeskControler/RemoteClipboard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "RemoteClipboard.h"
#include <QApplication>
#include <QClipboard>
#include <QKeyEvent>
#include <QFile>
#include <QFileInfo>
#include "LogWidget.h"

RemoteClipboard::RemoteClipboard(QObject* parent)
: QObject(parent)
{
qApp->installEventFilter(this);
}


bool RemoteClipboard::eventFilter(QObject* /*obj*/, QEvent* event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if ((keyEvent->modifiers() & Qt::ControlModifier) && keyEvent->key() == Qt::Key_C) {
QClipboard* clipboard = QApplication::clipboard();
const QMimeData* mimeData = clipboard->mimeData();
if (mimeData) {
LogWidget::instance()->addLog("Control side: Detected Ctrl+C, sending clipboard data", LogWidget::Info);
sendClipboardData(mimeData);
}
else {
LogWidget::instance()->addLog("Control side: Clipboard is empty", LogWidget::Warning);
}
return true;
}
}
return QObject::eventFilter(nullptr, event);
}

void RemoteClipboard::sendClipboardData(const QMimeData* mimeData)
{
ClipboardEvent eventMsg;
// 如果剪贴板中包含文件 URL,优先处理文件数据
if (mimeData->hasUrls() && !mimeData->urls().isEmpty()) {
QString filePath = mimeData->urls().first().toLocalFile();
QFile file(filePath);
if (file.open(QIODevice::ReadOnly)) {
QByteArray data = file.readAll();
file.close();
FileContent* fileContent = eventMsg.mutable_file();
fileContent->set_file_data(data.toStdString());
QFileInfo fileInfo(filePath);
fileContent->set_file_name(fileInfo.fileName().toStdString());
LogWidget::instance()->addLog(QString("Control side: Copied file: %1").arg(filePath), LogWidget::Info);
}
else {
LogWidget::instance()->addLog(QString("Control side: Failed to open file: %1").arg(filePath), LogWidget::Error);
return;
}
}
else if (mimeData->hasText()) {
TextContent* textContent = eventMsg.mutable_text();
textContent->set_text_data(mimeData->text().toStdString());
LogWidget::instance()->addLog("Control side: Copied text data", LogWidget::Info);
}
else {
LogWidget::instance()->addLog("Control side: Unsupported clipboard data", LogWidget::Warning);
return;
}
emit clipboardDataReady(eventMsg);
}
25 changes: 25 additions & 0 deletions DeskControler/RemoteClipboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef REMOTECLIPBOARD_H
#define REMOTECLIPBOARD_H

#include <QObject>
#include <QEvent>
#include <QMimeData>
#include "rendezvous.pb.h"

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

protected:
bool eventFilter(QObject* obj, QEvent* event) override;

private:
void sendClipboardData(const QMimeData* mimeData);


signals:
void clipboardDataReady(const ClipboardEvent& clipboardEvent);
};

#endif // REMOTECLIPBOARD_H
10 changes: 9 additions & 1 deletion DeskControler/VideoReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,12 @@ void VideoReceiver::keyEventCaptured(int key, bool pressed)
Qt::QueuedConnection,
Q_ARG(int, key),
Q_ARG(bool, pressed));
}
}

void VideoReceiver::clipboardDataCaptured(const ClipboardEvent& clipboardEvent)
{
QMetaObject::invokeMethod(m_netWorker,
"sendClipboardEventToServer",
Qt::QueuedConnection,
Q_ARG(ClipboardEvent, clipboardEvent));
}
2 changes: 2 additions & 0 deletions DeskControler/VideoReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QObject>
#include <QThread>
#include <QImage>
#include "rendezvous.pb.h"

class NetworkWorker;
class VideoDecoderWorker;
Expand All @@ -28,6 +29,7 @@ class VideoReceiver : public QObject
public slots:
void mouseEventCaptured(int x, int y, int mask);
void keyEventCaptured(int key, bool pressed);
void clipboardDataCaptured(const ClipboardEvent& clipboardEvent);

private slots:
// 褰撹В鐮佺嚎绋嬪彂鍑� frameDecoded 鏃惰皟鐢�
Expand Down
1 change: 1 addition & 0 deletions DeskControler/VideoWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void VideoWidget::setFrame(const QImage& image)
setMinimumSize(currentFrame.size());
resize(currentFrame.size());
m_firstFrame = false;

}

update();
Expand Down
1 change: 1 addition & 0 deletions DeskControler/VideoWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QMouseEvent>
#include <QKeyEvent>


enum MouseMask {
MouseMove = 0x01, // 鼠标移动
MouseLeftDown = 0x02, // 鼠标左键按下
Expand Down
8 changes: 4 additions & 4 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ SimpleRustDesk 鏄竴涓繙绋嬫闈㈡帶鍒剁郴缁熺ず渚嬮」鐩紝鍙傝�� RustDesk

![榧犳爣閿洏鎺у埗 UML](diagrams/output/MouseKeyInput.svg)

## 鏂囦欢浼犺緭-浠庢帶鍒剁澶嶅埗绀烘剰鍥� (ctrlcFromControl.puml)
## 鏂囦欢浼犺緭-浠庢帶鍒剁澶嶅埗 UML 鍥�

![ctrlcFromControl](./diagrams/ctrlcFromControl.png)
![ctrlcFromControl](./diagrams/output/ctrlcFromControl.png)

## 鏂囦欢浼犺緭-浠庤鎺у埗绔鍒剁ず鎰忓浘 (ctrlcFromServer.puml)
## 鏂囦欢浼犺緭-浠庤鎺у埗绔鍒� UML 鍥�

![ctrlcFromServer](./diagrams/ctrlcFromServer.png)
![ctrlcFromServer](./diagrams/output/ctrlcFromServer.png)


## 娉ㄦ剰浜嬮」
Expand Down
Loading