diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index 9dc12eb..d898920 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -91,6 +91,15 @@ const QString &Device::getSerial() return m_params.serial; } +const QSize Device::frameSize() +{ + QSize size; + if (!m_videoForm) { + return size; + } + return m_videoForm->frameSize(); +} + void Device::updateScript(QString script) { if(m_controller){ diff --git a/QtScrcpy/device/device.h b/QtScrcpy/device/device.h index cc7dd6d..5c519fc 100644 --- a/QtScrcpy/device/device.h +++ b/QtScrcpy/device/device.h @@ -46,6 +46,7 @@ public: VideoForm *getVideoForm(); Server *getServer(); const QString &getSerial(); + const QSize frameSize(); void updateScript(QString script); Device::GroupControlState controlState(); diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index ea4a2c9..5f54fcf 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -92,6 +92,11 @@ QRect VideoForm::getGrabCursorRect() return rc; } +const QSize &VideoForm::frameSize() +{ + return m_frameSize; +} + void VideoForm::updateRender(const AVFrame *frame) { if (m_videoWidget->isHidden()) { diff --git a/QtScrcpy/device/ui/videoform.h b/QtScrcpy/device/ui/videoform.h index 6f573a0..f2a3d09 100644 --- a/QtScrcpy/device/ui/videoform.h +++ b/QtScrcpy/device/ui/videoform.h @@ -25,6 +25,7 @@ public: void updateRender(const AVFrame *frame); void setDevice(Device *device); QRect getGrabCursorRect(); + const QSize &frameSize(); public slots: void onSwitchFullScreen(); diff --git a/QtScrcpy/devicemanage/devicemanage.cpp b/QtScrcpy/devicemanage/devicemanage.cpp index f0d0e44..e456517 100644 --- a/QtScrcpy/devicemanage/devicemanage.cpp +++ b/QtScrcpy/devicemanage/devicemanage.cpp @@ -127,9 +127,6 @@ void DeviceManage::setGroupControlSignals(Device *host, Device *client, bool ins connect(host, &Device::clipboardPaste, client, &Device::clipboardPaste); connect(host, &Device::pushFileRequest, client, &Device::pushFileRequest); connect(host, &Device::installApkRequest, client, &Device::installApkRequest); - connect(host, &Device::mouseEvent, client, &Device::mouseEvent); - connect(host, &Device::wheelEvent, client, &Device::wheelEvent); - connect(host, &Device::keyEvent, client, &Device::keyEvent); connect(host, &Device::screenshot, client, &Device::screenshot); connect(host, &Device::showTouch, client, &Device::showTouch); // dont connect requestDeviceClipboard @@ -150,9 +147,6 @@ void DeviceManage::setGroupControlSignals(Device *host, Device *client, bool ins disconnect(host, &Device::clipboardPaste, client, &Device::clipboardPaste); disconnect(host, &Device::pushFileRequest, client, &Device::pushFileRequest); disconnect(host, &Device::installApkRequest, client, &Device::installApkRequest); - disconnect(host, &Device::mouseEvent, client, &Device::mouseEvent); - disconnect(host, &Device::wheelEvent, client, &Device::wheelEvent); - disconnect(host, &Device::keyEvent, client, &Device::keyEvent); disconnect(host, &Device::screenshot, client, &Device::screenshot); disconnect(host, &Device::showTouch, client, &Device::showTouch); } @@ -201,19 +195,75 @@ void DeviceManage::onControlStateChange(Device *device, Device::GroupControlStat // free to host if (oldState == Device::GroupControlState::GCS_FREE && newState == Device::GroupControlState::GCS_HOST) { - // install control signals + // install direct control signals setGroupControlHost(device, true); + // install convert control signals(frameSize need convert) + connect(device, &Device::mouseEvent, this, &DeviceManage::onMouseEvent, Qt::UniqueConnection); + connect(device, &Device::wheelEvent, this, &DeviceManage::onWheelEvent, Qt::UniqueConnection); + connect(device, &Device::keyEvent, this, &DeviceManage::onKeyEvent, Qt::UniqueConnection); return; } // host to free if (oldState == Device::GroupControlState::GCS_HOST && newState == Device::GroupControlState::GCS_FREE) { - // uninstall control signals + // uninstall direct control signals setGroupControlHost(device, false); + // uninstall convert control signals(frameSize need convert) + disconnect(device, &Device::mouseEvent, this, &DeviceManage::onMouseEvent); + disconnect(device, &Device::wheelEvent, this, &DeviceManage::onWheelEvent); + disconnect(device, &Device::keyEvent, this, &DeviceManage::onKeyEvent); return; } } +void DeviceManage::onMouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize) +{ + QMapIterator> i(m_devices); + while (i.hasNext()) { + i.next(); + if (!i.value()) { + continue; + } + if (i.value() == sender()) { + continue; + } + // neend convert frameSize to its frameSize + emit i.value()->mouseEvent(from, i.value()->frameSize(), showSize); + } +} + +void DeviceManage::onWheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize) +{ + QMapIterator> i(m_devices); + while (i.hasNext()) { + i.next(); + if (!i.value()) { + continue; + } + if (i.value() == sender()) { + continue; + } + // neend convert frameSize to its frameSize + emit i.value()->wheelEvent(from, i.value()->frameSize(), showSize); + } +} + +void DeviceManage::onKeyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize) +{ + QMapIterator> i(m_devices); + while (i.hasNext()) { + i.next(); + if (!i.value()) { + continue; + } + if (i.value() == sender()) { + continue; + } + // neend convert frameSize to its frameSize + emit i.value()->keyEvent(from, i.value()->frameSize(), showSize); + } +} + quint16 DeviceManage::getFreePort() { quint16 port = m_localPortStart; diff --git a/QtScrcpy/devicemanage/devicemanage.h b/QtScrcpy/devicemanage/devicemanage.h index cbef25c..fb86089 100644 --- a/QtScrcpy/devicemanage/devicemanage.h +++ b/QtScrcpy/devicemanage/devicemanage.h @@ -28,6 +28,11 @@ protected slots: void onDeviceDisconnect(QString serial); void onControlStateChange(Device* device, Device::GroupControlState oldState, Device::GroupControlState newState); + // neend convert frameSize to its frameSize + void onMouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); + void onWheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); + void onKeyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize); + private: quint16 getFreePort();