mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-20 03:25:02 +00:00
feat: group control
This commit is contained in:
parent
54df9468c9
commit
3487fb7d2b
6 changed files with 117 additions and 5 deletions
|
@ -286,8 +286,9 @@ void Device::onSetControlState(Device* device, Device::GroupControlState state)
|
|||
if (m_controlState == state) {
|
||||
return;
|
||||
}
|
||||
GroupControlState oldState = m_controlState;
|
||||
m_controlState = state;
|
||||
emit controlStateChange(this, m_controlState);
|
||||
emit controlStateChange(this, oldState, m_controlState);
|
||||
}
|
||||
|
||||
void Device::onGrabCursor(bool grab)
|
||||
|
|
|
@ -84,7 +84,7 @@ signals:
|
|||
void grabCursor(bool grab);
|
||||
|
||||
// for notify
|
||||
void controlStateChange(Device* device, Device::GroupControlState state);
|
||||
void controlStateChange(Device* device, Device::GroupControlState oldState, Device::GroupControlState newState);
|
||||
|
||||
public slots:
|
||||
void onScreenshot();
|
||||
|
|
|
@ -215,9 +215,10 @@ void ToolForm::on_groupControlBtn_clicked()
|
|||
}
|
||||
}
|
||||
|
||||
void ToolForm::onControlStateChange(Device *device, Device::GroupControlState state)
|
||||
void ToolForm::onControlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState)
|
||||
{
|
||||
Q_UNUSED(device)
|
||||
Q_UNUSED(state)
|
||||
Q_UNUSED(oldState)
|
||||
Q_UNUSED(newState)
|
||||
updateGroupControl();
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ private slots:
|
|||
void on_touchBtn_clicked();
|
||||
void on_groupControlBtn_clicked();
|
||||
|
||||
void onControlStateChange(Device* device, Device::GroupControlState state);
|
||||
void onControlStateChange(Device* device, Device::GroupControlState oldState, Device::GroupControlState newState);
|
||||
|
||||
private:
|
||||
void initStyle();
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
#include <QWheelEvent>
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include "devicemanage.h"
|
||||
#include "server.h"
|
||||
|
@ -44,6 +47,7 @@ bool DeviceManage::connectDevice(Device::DeviceParams params)
|
|||
*/
|
||||
Device *device = new Device(params);
|
||||
connect(device, &Device::deviceDisconnect, this, &DeviceManage::onDeviceDisconnect);
|
||||
connect(device, &Device::controlStateChange, this, &DeviceManage::onControlStateChange);
|
||||
m_devices[params.serial] = device;
|
||||
return true;
|
||||
}
|
||||
|
@ -102,13 +106,114 @@ void DeviceManage::disconnectAllDevice()
|
|||
}
|
||||
}
|
||||
|
||||
void DeviceManage::setGroupControlSignals(Device *host, Device *client, bool install)
|
||||
{
|
||||
if (!host || !client) {
|
||||
return;
|
||||
}
|
||||
if (install) {
|
||||
connect(host, &Device::postGoBack, client, &Device::postGoBack);
|
||||
connect(host, &Device::postGoHome, client, &Device::postGoHome);
|
||||
connect(host, &Device::postGoMenu, client, &Device::postGoMenu);
|
||||
connect(host, &Device::postAppSwitch, client, &Device::postAppSwitch);
|
||||
connect(host, &Device::postPower, client, &Device::postPower);
|
||||
connect(host, &Device::postVolumeUp, client, &Device::postVolumeUp);
|
||||
connect(host, &Device::postVolumeDown, client, &Device::postVolumeDown);
|
||||
connect(host, &Device::setScreenPowerMode, client, &Device::setScreenPowerMode);
|
||||
connect(host, &Device::expandNotificationPanel, client, &Device::expandNotificationPanel);
|
||||
connect(host, &Device::postTurnOn, client, &Device::postTurnOn);
|
||||
connect(host, &Device::postTextInput, client, &Device::postTextInput);
|
||||
connect(host, &Device::setDeviceClipboard, client, &Device::setDeviceClipboard);
|
||||
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
|
||||
//connect(host, &Device::requestDeviceClipboard, client, &Device::requestDeviceClipboard);
|
||||
} else {
|
||||
disconnect(host, &Device::postGoBack, client, &Device::postGoBack);
|
||||
disconnect(host, &Device::postGoHome, client, &Device::postGoHome);
|
||||
disconnect(host, &Device::postGoMenu, client, &Device::postGoMenu);
|
||||
disconnect(host, &Device::postAppSwitch, client, &Device::postAppSwitch);
|
||||
disconnect(host, &Device::postPower, client, &Device::postPower);
|
||||
disconnect(host, &Device::postVolumeUp, client, &Device::postVolumeUp);
|
||||
disconnect(host, &Device::postVolumeDown, client, &Device::postVolumeDown);
|
||||
disconnect(host, &Device::setScreenPowerMode, client, &Device::setScreenPowerMode);
|
||||
disconnect(host, &Device::expandNotificationPanel, client, &Device::expandNotificationPanel);
|
||||
disconnect(host, &Device::postTurnOn, client, &Device::postTurnOn);
|
||||
disconnect(host, &Device::postTextInput, client, &Device::postTextInput);
|
||||
disconnect(host, &Device::setDeviceClipboard, client, &Device::setDeviceClipboard);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManage::setGroupControlHost(Device *host, bool install)
|
||||
{
|
||||
QMapIterator<QString, QPointer<Device>> i(m_devices);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (!i.value()) {
|
||||
continue;
|
||||
}
|
||||
if (i.value() == host) {
|
||||
continue;
|
||||
}
|
||||
if (install) {
|
||||
if (host) {
|
||||
setGroupControlSignals(host, i.value(), true);
|
||||
}
|
||||
emit i.value()->setControlState(i.value(), Device::GroupControlState::GCS_CLIENT);
|
||||
} else {
|
||||
if (host) {
|
||||
setGroupControlSignals(host, i.value(), false);
|
||||
}
|
||||
emit i.value()->setControlState(i.value(), Device::GroupControlState::GCS_FREE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManage::onDeviceDisconnect(QString serial)
|
||||
{
|
||||
if (!serial.isEmpty() && m_devices.contains(serial)) {
|
||||
if (m_devices[serial]->controlState() == Device::GroupControlState::GCS_HOST) {
|
||||
setGroupControlHost(nullptr, false);
|
||||
}
|
||||
m_devices.remove(serial);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManage::onControlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState)
|
||||
{
|
||||
if (!device) {
|
||||
return;
|
||||
}
|
||||
// free to host
|
||||
if (oldState == Device::GroupControlState::GCS_FREE
|
||||
&& newState == Device::GroupControlState::GCS_HOST) {
|
||||
// install control signals
|
||||
setGroupControlHost(device, true);
|
||||
return;
|
||||
}
|
||||
// host to free
|
||||
if (oldState == Device::GroupControlState::GCS_HOST
|
||||
&& newState == Device::GroupControlState::GCS_FREE) {
|
||||
// uninstall control signals
|
||||
setGroupControlHost(device, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
quint16 DeviceManage::getFreePort()
|
||||
{
|
||||
quint16 port = m_localPortStart;
|
||||
|
|
|
@ -20,8 +20,13 @@ public:
|
|||
bool disconnectDevice(const QString &serial);
|
||||
void disconnectAllDevice();
|
||||
|
||||
protected:
|
||||
void setGroupControlSignals(Device *host, Device *client, bool install);
|
||||
void setGroupControlHost(Device *host, bool install);
|
||||
|
||||
protected slots:
|
||||
void onDeviceDisconnect(QString serial);
|
||||
void onControlStateChange(Device* device, Device::GroupControlState oldState, Device::GroupControlState newState);
|
||||
|
||||
private:
|
||||
quint16 getFreePort();
|
||||
|
|
Loading…
Add table
Reference in a new issue