mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-07-31 12:58:39 +00:00
feat: ready for group control
This commit is contained in:
parent
8f8edd4bae
commit
54df9468c9
5 changed files with 58 additions and 21 deletions
|
@ -130,7 +130,7 @@ void Device::initSignals()
|
||||||
{
|
{
|
||||||
connect(this, &Device::screenshot, this, &Device::onScreenshot);
|
connect(this, &Device::screenshot, this, &Device::onScreenshot);
|
||||||
connect(this, &Device::showTouch, this, &Device::onShowTouch);
|
connect(this, &Device::showTouch, this, &Device::onShowTouch);
|
||||||
connect(this, &Device::setMainControl, this, &Device::onSetMainControl);
|
connect(this, &Device::setControlState, this, &Device::onSetControlState);
|
||||||
connect(this, &Device::grabCursor, this, &Device::onGrabCursor);
|
connect(this, &Device::grabCursor, this, &Device::onGrabCursor);
|
||||||
|
|
||||||
if (m_controller) {
|
if (m_controller) {
|
||||||
|
@ -185,7 +185,7 @@ void Device::initSignals()
|
||||||
tips = tr("%1 failed").arg(tipsType);
|
tips = tr("%1 failed").arg(tipsType);
|
||||||
}
|
}
|
||||||
qInfo() << tips;
|
qInfo() << tips;
|
||||||
if (!m_mainControl) {
|
if (m_controlState == GCS_CLIENT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QMessageBox::information(m_videoForm, "QtScrcpy", tips, QMessageBox::Ok);
|
QMessageBox::information(m_videoForm, "QtScrcpy", tips, QMessageBox::Ok);
|
||||||
|
@ -280,13 +280,14 @@ void Device::startServer()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::onSetMainControl(Device* device, bool mainControl)
|
void Device::onSetControlState(Device* device, Device::GroupControlState state)
|
||||||
{
|
{
|
||||||
Q_UNUSED(device)
|
Q_UNUSED(device)
|
||||||
if (m_mainControl == mainControl) {
|
if (m_controlState == state) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_mainControl = mainControl;
|
m_controlState = state;
|
||||||
|
emit controlStateChange(this, m_controlState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::onGrabCursor(bool grab)
|
void Device::onGrabCursor(bool grab)
|
||||||
|
@ -294,13 +295,16 @@ void Device::onGrabCursor(bool grab)
|
||||||
if (!m_videoForm) {
|
if (!m_videoForm) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (m_controlState == GCS_CLIENT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
QRect rc = m_videoForm->getGrabCursorRect();
|
QRect rc = m_videoForm->getGrabCursorRect();
|
||||||
MouseTap::getInstance()->enableMouseEventTap(rc, grab);
|
MouseTap::getInstance()->enableMouseEventTap(rc, grab);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::mainControl()
|
Device::GroupControlState Device::controlState()
|
||||||
{
|
{
|
||||||
return m_mainControl;
|
return m_controlState;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::saveFrame(const AVFrame* frame)
|
bool Device::saveFrame(const AVFrame* frame)
|
||||||
|
|
|
@ -35,6 +35,11 @@ public:
|
||||||
QString gameScript = ""; // 游戏映射脚本
|
QString gameScript = ""; // 游戏映射脚本
|
||||||
bool renderExpiredFrames = false; // 是否渲染延迟视频帧
|
bool renderExpiredFrames = false; // 是否渲染延迟视频帧
|
||||||
};
|
};
|
||||||
|
enum GroupControlState {
|
||||||
|
GCS_FREE = 0,
|
||||||
|
GCS_HOST,
|
||||||
|
GCS_CLIENT,
|
||||||
|
};
|
||||||
explicit Device(DeviceParams params, QObject *parent = nullptr);
|
explicit Device(DeviceParams params, QObject *parent = nullptr);
|
||||||
virtual ~Device();
|
virtual ~Device();
|
||||||
|
|
||||||
|
@ -43,7 +48,7 @@ public:
|
||||||
const QString &getSerial();
|
const QString &getSerial();
|
||||||
|
|
||||||
void updateScript(QString script);
|
void updateScript(QString script);
|
||||||
bool mainControl();
|
Device::GroupControlState controlState();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deviceDisconnect(QString serial);
|
void deviceDisconnect(QString serial);
|
||||||
|
@ -75,13 +80,16 @@ signals:
|
||||||
// self connect signal and slots
|
// self connect signal and slots
|
||||||
void screenshot();
|
void screenshot();
|
||||||
void showTouch(bool show);
|
void showTouch(bool show);
|
||||||
void setMainControl(Device* device, bool mainControl);
|
void setControlState(Device* device, Device::GroupControlState state);
|
||||||
void grabCursor(bool grab);
|
void grabCursor(bool grab);
|
||||||
|
|
||||||
|
// for notify
|
||||||
|
void controlStateChange(Device* device, Device::GroupControlState state);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onScreenshot();
|
void onScreenshot();
|
||||||
void onShowTouch(bool show);
|
void onShowTouch(bool show);
|
||||||
void onSetMainControl(Device* device, bool mainControl);
|
void onSetControlState(Device* device, Device::GroupControlState state);
|
||||||
void onGrabCursor(bool grab);
|
void onGrabCursor(bool grab);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -105,7 +113,7 @@ private:
|
||||||
QTime m_startTimeCount;
|
QTime m_startTimeCount;
|
||||||
DeviceParams m_params;
|
DeviceParams m_params;
|
||||||
|
|
||||||
bool m_mainControl = false;
|
GroupControlState m_controlState = GCS_FREE;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICE_H
|
#endif // DEVICE_H
|
||||||
|
|
|
@ -26,7 +26,11 @@ ToolForm::~ToolForm()
|
||||||
|
|
||||||
void ToolForm::setDevice(Device *device)
|
void ToolForm::setDevice(Device *device)
|
||||||
{
|
{
|
||||||
|
if (!device) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
m_device = device;
|
m_device = device;
|
||||||
|
connect(m_device, &Device::controlStateChange, this, &ToolForm::onControlStateChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolForm::initStyle()
|
void ToolForm::initStyle()
|
||||||
|
@ -52,10 +56,16 @@ void ToolForm::updateGroupControl()
|
||||||
if (!m_device) {
|
if (!m_device) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_device->mainControl()) {
|
switch (m_device->controlState()) {
|
||||||
ui->groupControlBtn->setStyleSheet("color: red");
|
case Device::GroupControlState::GCS_FREE:
|
||||||
} else {
|
|
||||||
ui->groupControlBtn->setStyleSheet("color: #DCDCDC");
|
ui->groupControlBtn->setStyleSheet("color: #DCDCDC");
|
||||||
|
break;
|
||||||
|
case Device::GroupControlState::GCS_HOST:
|
||||||
|
ui->groupControlBtn->setStyleSheet("color: red");
|
||||||
|
break;
|
||||||
|
case Device::GroupControlState::GCS_CLIENT:
|
||||||
|
ui->groupControlBtn->setStyleSheet("color: green");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,6 +206,18 @@ void ToolForm::on_groupControlBtn_clicked()
|
||||||
if (!m_device) {
|
if (!m_device) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
emit m_device->setMainControl(m_device, !m_device->mainControl());
|
Device::GroupControlState state = m_device->controlState();
|
||||||
|
if (state == Device::GroupControlState::GCS_FREE) {
|
||||||
|
emit m_device->setControlState(m_device, Device::GroupControlState::GCS_HOST);
|
||||||
|
}
|
||||||
|
if (state == Device::GroupControlState::GCS_HOST) {
|
||||||
|
emit m_device->setControlState(m_device, Device::GroupControlState::GCS_FREE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolForm::onControlStateChange(Device *device, Device::GroupControlState state)
|
||||||
|
{
|
||||||
|
Q_UNUSED(device)
|
||||||
|
Q_UNUSED(state)
|
||||||
updateGroupControl();
|
updateGroupControl();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
#include "magneticwidget.h"
|
#include "magneticwidget.h"
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ToolForm;
|
class ToolForm;
|
||||||
|
@ -44,6 +45,8 @@ private slots:
|
||||||
void on_touchBtn_clicked();
|
void on_touchBtn_clicked();
|
||||||
void on_groupControlBtn_clicked();
|
void on_groupControlBtn_clicked();
|
||||||
|
|
||||||
|
void onControlStateChange(Device* device, Device::GroupControlState state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initStyle();
|
void initStyle();
|
||||||
void updateGroupControl();
|
void updateGroupControl();
|
||||||
|
|
|
@ -184,8 +184,8 @@ void VideoForm::updateShowSize(const QSize &newSize)
|
||||||
showSize.setHeight(showSize.width() / m_widthHeightRatio);
|
showSize.setHeight(showSize.width() / m_widthHeightRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFullScreen()) {
|
if (isFullScreen() && m_device) {
|
||||||
onSwitchFullScreen();
|
emit m_device->switchFullScreen();
|
||||||
}
|
}
|
||||||
if (m_skin) {
|
if (m_skin) {
|
||||||
QMargins m = getMargins(vertical);
|
QMargins m = getMargins(vertical);
|
||||||
|
@ -351,13 +351,13 @@ void VideoForm::wheelEvent(QWheelEvent *event)
|
||||||
|
|
||||||
void VideoForm::keyPressEvent(QKeyEvent *event)
|
void VideoForm::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
|
if (!m_device) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Qt::Key_Escape == event->key()
|
if (Qt::Key_Escape == event->key()
|
||||||
&& !event->isAutoRepeat()
|
&& !event->isAutoRepeat()
|
||||||
&& isFullScreen()) {
|
&& isFullScreen()) {
|
||||||
onSwitchFullScreen();
|
emit m_device->switchFullScreen();
|
||||||
}
|
|
||||||
if (!m_device) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier)) {
|
if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier)) {
|
||||||
emit m_device->requestDeviceClipboard();
|
emit m_device->requestDeviceClipboard();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue