From 8bcd98491aae344b8f12d921a267618acdc55c8c Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Sun, 16 Jan 2022 21:57:44 +0800 Subject: [PATCH] fix: clipboard bug --- QtScrcpy/device/controller/controller.cpp | 18 ++++++++++--- QtScrcpy/device/controller/controller.h | 6 +++-- .../controller/inputconvert/controlmsg.cpp | 23 ++++++++++++++--- .../controller/inputconvert/controlmsg.h | 25 +++++++++++++++++-- QtScrcpy/device/device.cpp | 2 +- QtScrcpy/device/device.h | 4 +-- QtScrcpy/device/ui/videoform.cpp | 6 ++--- QtScrcpy/devicemanage/devicemanage.cpp | 4 +-- 8 files changed, 70 insertions(+), 18 deletions(-) diff --git a/QtScrcpy/device/controller/controller.cpp b/QtScrcpy/device/controller/controller.cpp index 7b171a0..b0faa82 100644 --- a/QtScrcpy/device/controller/controller.cpp +++ b/QtScrcpy/device/controller/controller.cpp @@ -65,9 +65,10 @@ bool Controller::isCurrentCustomKeymap() return m_inputConvert->isCurrentCustomKeymap(); } -void Controller::onPostBackOrScreenOn() +void Controller::onPostBackOrScreenOn(bool down) { ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_BACK_OR_SCREEN_ON); + controlMsg->setBackOrScreenOnData(down); if (!controlMsg) { return; } @@ -128,9 +129,9 @@ void Controller::onExpandNotificationPanel() postControlMsg(controlMsg); } -void Controller::onCollapseNotificationPanel() +void Controller::onCollapsePanel() { - ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_COLLAPSE_NOTIFICATION_PANEL); + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_COLLAPSE_PANELS); if (!controlMsg) { return; } @@ -146,6 +147,17 @@ void Controller::onRequestDeviceClipboard() postControlMsg(controlMsg); } +void Controller::onGetDeviceClipboard(bool cut) +{ + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_GET_CLIPBOARD); + if (!controlMsg) { + return; + } + ControlMsg::GetClipboardCopyKey copyKey = cut ? ControlMsg::GCCK_CUT : ControlMsg::GCCK_COPY; + controlMsg->setGetClipboardMsgData(copyKey); + postControlMsg(controlMsg); +} + void Controller::onSetDeviceClipboard(bool pause) { QClipboard *board = QApplication::clipboard(); diff --git a/QtScrcpy/device/controller/controller.h b/QtScrcpy/device/controller/controller.h index 29f77f1..0b2d886 100644 --- a/QtScrcpy/device/controller/controller.h +++ b/QtScrcpy/device/controller/controller.h @@ -34,7 +34,7 @@ public slots: void onCopy(); void onCut(); void onExpandNotificationPanel(); - void onCollapseNotificationPanel(); + void onCollapsePanel(); void onSetScreenPowerMode(ControlMsg::ScreenPowerMode mode); // for input convert @@ -43,8 +43,10 @@ public slots: void onKeyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize); // turn the screen on if it was off, press BACK otherwise - void onPostBackOrScreenOn(); + // If the screen is off, it is turned on only on down + void onPostBackOrScreenOn(bool down); void onRequestDeviceClipboard(); + void onGetDeviceClipboard(bool cut = false); void onSetDeviceClipboard(bool pause = true); void onClipboardPaste(); void onPostTextInput(QString &text); diff --git a/QtScrcpy/device/controller/inputconvert/controlmsg.cpp b/QtScrcpy/device/controller/inputconvert/controlmsg.cpp index 6a21634..2a06dac 100644 --- a/QtScrcpy/device/controller/inputconvert/controlmsg.cpp +++ b/QtScrcpy/device/controller/inputconvert/controlmsg.cpp @@ -56,6 +56,11 @@ void ControlMsg::setInjectScrollMsgData(QRect position, qint32 hScroll, qint32 v m_data.injectScroll.vScroll = vScroll; } +void ControlMsg::setGetClipboardMsgData(ControlMsg::GetClipboardCopyKey copyKey) +{ + m_data.getClipboard.copyKey = copyKey; +} + void ControlMsg::setSetClipboardMsgData(QString &text, bool paste) { if (text.isEmpty()) { @@ -70,6 +75,7 @@ void ControlMsg::setSetClipboardMsgData(QString &text, bool paste) memcpy(m_data.setClipboard.text, tmp.data(), tmp.length()); m_data.setClipboard.text[tmp.length()] = '\0'; m_data.setClipboard.paste = paste; + m_data.setClipboard.sequence = 0; } void ControlMsg::setSetScreenPowerModeData(ControlMsg::ScreenPowerMode mode) @@ -77,6 +83,11 @@ void ControlMsg::setSetScreenPowerModeData(ControlMsg::ScreenPowerMode mode) m_data.setScreenPowerMode.mode = mode; } +void ControlMsg::setBackOrScreenOnData(bool down) +{ + m_data.backOrScreenOn.action = down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP; +} + void ControlMsg::writePosition(QBuffer &buffer, const QRect &value) { BufferUtil::write32(buffer, value.left()); @@ -126,7 +137,13 @@ QByteArray ControlMsg::serializeData() BufferUtil::write32(buffer, m_data.injectScroll.hScroll); BufferUtil::write32(buffer, m_data.injectScroll.vScroll); break; + case CMT_BACK_OR_SCREEN_ON: + buffer.putChar(m_data.backOrScreenOn.action); + break; + case CMT_GET_CLIPBOARD: + buffer.putChar(m_data.getClipboard.copyKey); case CMT_SET_CLIPBOARD: + BufferUtil::write64(buffer, m_data.setClipboard.sequence); buffer.putChar(!!m_data.setClipboard.paste); BufferUtil::write32(buffer, static_cast(strlen(m_data.setClipboard.text))); buffer.write(m_data.setClipboard.text, strlen(m_data.setClipboard.text)); @@ -134,10 +151,10 @@ QByteArray ControlMsg::serializeData() case CMT_SET_SCREEN_POWER_MODE: buffer.putChar(m_data.setScreenPowerMode.mode); break; - case CMT_BACK_OR_SCREEN_ON: case CMT_EXPAND_NOTIFICATION_PANEL: - case CMT_COLLAPSE_NOTIFICATION_PANEL: - case CMT_GET_CLIPBOARD: + case CMT_EXPAND_SETTINGS_PANEL: + case CMT_COLLAPSE_PANELS: + case CMT_ROTATE_DEVICE: break; default: qDebug() << "Unknown event type:" << m_data.type; diff --git a/QtScrcpy/device/controller/inputconvert/controlmsg.h b/QtScrcpy/device/controller/inputconvert/controlmsg.h index e455060..93a7e2f 100644 --- a/QtScrcpy/device/controller/inputconvert/controlmsg.h +++ b/QtScrcpy/device/controller/inputconvert/controlmsg.h @@ -17,6 +17,7 @@ (CONTROL_MSG_MAX_SIZE - 6) #define POINTER_ID_MOUSE static_cast(-1) +#define POINTER_ID_VIRTUAL_FINGER UINT64_C(-2) // ControlMsg class ControlMsg : public QScrcpyEvent @@ -31,10 +32,12 @@ public: CMT_INJECT_SCROLL, CMT_BACK_OR_SCREEN_ON, CMT_EXPAND_NOTIFICATION_PANEL, - CMT_COLLAPSE_NOTIFICATION_PANEL, + CMT_EXPAND_SETTINGS_PANEL, + CMT_COLLAPSE_PANELS, CMT_GET_CLIPBOARD, CMT_SET_CLIPBOARD, - CMT_SET_SCREEN_POWER_MODE + CMT_SET_SCREEN_POWER_MODE, + CMT_ROTATE_DEVICE }; enum ScreenPowerMode @@ -44,6 +47,12 @@ public: SPM_NORMAL = 2, }; + enum GetClipboardCopyKey { + GCCK_NONE, + GCCK_COPY, + GCCK_CUT, + }; + ControlMsg(ControlMsgType controlMsgType); virtual ~ControlMsg(); @@ -54,8 +63,10 @@ public: // position action动作对应的位置 void setInjectTouchMsgData(quint64 id, AndroidMotioneventAction action, AndroidMotioneventButtons buttons, QRect position, float pressure); void setInjectScrollMsgData(QRect position, qint32 hScroll, qint32 vScroll); + void setGetClipboardMsgData(ControlMsg::GetClipboardCopyKey copyKey); void setSetClipboardMsgData(QString &text, bool paste); void setSetScreenPowerModeData(ControlMsg::ScreenPowerMode mode); + void setBackOrScreenOnData(bool down); QByteArray serializeData(); @@ -96,6 +107,16 @@ private: } injectScroll; struct { + AndroidKeyeventAction action; // action for the BACK key + // screen may only be turned on on ACTION_DOWN + } backOrScreenOn; + struct + { + enum GetClipboardCopyKey copyKey; + } getClipboard; + struct + { + uint64_t sequence = 0; char *text = Q_NULLPTR; bool paste = true; } setClipboard; diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index 98901d6..5ee2cdd 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -155,7 +155,7 @@ void Device::initSignals() connect(this, &Device::postCut, m_controller, &Controller::onCut); connect(this, &Device::setScreenPowerMode, m_controller, &Controller::onSetScreenPowerMode); connect(this, &Device::expandNotificationPanel, m_controller, &Controller::onExpandNotificationPanel); - connect(this, &Device::collapseNotificationPanel, m_controller, &Controller::onCollapseNotificationPanel); + connect(this, &Device::collapsePanel, m_controller, &Controller::onCollapsePanel); connect(this, &Device::mouseEvent, m_controller, &Controller::onMouseEvent); connect(this, &Device::wheelEvent, m_controller, &Controller::onWheelEvent); connect(this, &Device::keyEvent, m_controller, &Controller::onKeyEvent); diff --git a/QtScrcpy/device/device.h b/QtScrcpy/device/device.h index 33e602c..2691348 100644 --- a/QtScrcpy/device/device.h +++ b/QtScrcpy/device/device.h @@ -76,8 +76,8 @@ signals: void postCut(); void setScreenPowerMode(ControlMsg::ScreenPowerMode mode); void expandNotificationPanel(); - void collapseNotificationPanel(); - void postBackOrScreenOn(); + void collapsePanel(); + void postBackOrScreenOn(bool down); void postTextInput(QString &text); void requestDeviceClipboard(); void setDeviceClipboard(bool pause = true); diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index 07281a0..9dc14dd 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -295,14 +295,14 @@ void VideoForm::installShortcut() emit m_device->expandNotificationPanel(); }); - // collapseNotificationPanel + // collapsePanel shortcut = new QShortcut(QKeySequence("Ctrl+Shift+n"), this); shortcut->setAutoRepeat(false); connect(shortcut, &QShortcut::activated, this, [this]() { if (!m_device) { return; } - emit m_device->collapseNotificationPanel(); + emit m_device->collapsePanel(); }); // copy @@ -613,7 +613,7 @@ void VideoForm::mouseDoubleClickEvent(QMouseEvent *event) } if (event->button() == Qt::RightButton && m_device && !m_device->isCurrentCustomKeymap()) { - emit m_device->postBackOrScreenOn(); + emit m_device->postBackOrScreenOn(event->type() == QEvent::MouseButtonPress); } if (m_videoWidget->geometry().contains(event->pos())) { diff --git a/QtScrcpy/devicemanage/devicemanage.cpp b/QtScrcpy/devicemanage/devicemanage.cpp index fd2421d..975bae9 100644 --- a/QtScrcpy/devicemanage/devicemanage.cpp +++ b/QtScrcpy/devicemanage/devicemanage.cpp @@ -130,7 +130,7 @@ void DeviceManage::setGroupControlSignals(Device *host, Device *client, bool ins connect(host, &Device::postVolumeDown, client, &Device::postVolumeDown); connect(host, &Device::setScreenPowerMode, client, &Device::setScreenPowerMode); connect(host, &Device::expandNotificationPanel, client, &Device::expandNotificationPanel); - connect(host, &Device::collapseNotificationPanel, client, &Device::collapseNotificationPanel); + connect(host, &Device::collapsePanel, client, &Device::collapsePanel); connect(host, &Device::postBackOrScreenOn, client, &Device::postBackOrScreenOn); connect(host, &Device::postTextInput, client, &Device::postTextInput); connect(host, &Device::setDeviceClipboard, client, &Device::setDeviceClipboard); @@ -149,7 +149,7 @@ void DeviceManage::setGroupControlSignals(Device *host, Device *client, bool ins disconnect(host, &Device::postVolumeDown, client, &Device::postVolumeDown); disconnect(host, &Device::setScreenPowerMode, client, &Device::setScreenPowerMode); disconnect(host, &Device::expandNotificationPanel, client, &Device::expandNotificationPanel); - disconnect(host, &Device::collapseNotificationPanel, client, &Device::collapseNotificationPanel); + disconnect(host, &Device::collapsePanel, client, &Device::collapsePanel); disconnect(host, &Device::postBackOrScreenOn, client, &Device::postBackOrScreenOn); disconnect(host, &Device::postTextInput, client, &Device::postTextInput); disconnect(host, &Device::setDeviceClipboard, client, &Device::setDeviceClipboard);