diff --git a/QtScrcpy/controller/controller.cpp b/QtScrcpy/controller/controller.cpp index 4314170..593d2cc 100644 --- a/QtScrcpy/controller/controller.cpp +++ b/QtScrcpy/controller/controller.cpp @@ -1,4 +1,5 @@ -#include +#include +#include #include "controller.h" #include "videosocket.h" @@ -43,6 +44,116 @@ void Controller::test(QRect rc) postControlMsg(controlMsg); } +void Controller::postTurnOn() +{ + ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_BACK_OR_SCREEN_ON); + if (!controlMsg) { + return; + } + postControlMsg(controlMsg); +} + +void Controller::postGoHome() +{ + postKeyCodeClick(AKEYCODE_HOME); +} + +void Controller::postGoMenu() +{ + postKeyCodeClick(AKEYCODE_MENU); +} + +void Controller::postGoBack() +{ + postKeyCodeClick(AKEYCODE_BACK); +} + +void Controller::postAppSwitch() +{ + postKeyCodeClick(AKEYCODE_APP_SWITCH); +} + +void Controller::postPower() +{ + postKeyCodeClick(AKEYCODE_POWER); +} + +void Controller::postVolumeUp() +{ + postKeyCodeClick(AKEYCODE_VOLUME_UP); +} + +void Controller::postVolumeDown() +{ + postKeyCodeClick(AKEYCODE_VOLUME_DOWN); +} + +void Controller::expandNotificationPanel() +{ + ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_EXPAND_NOTIFICATION_PANEL); + if (!controlMsg) { + return; + } + postControlMsg(controlMsg); +} + +void Controller::collapseNotificationPanel() +{ + ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_COLLAPSE_NOTIFICATION_PANEL); + if (!controlMsg) { + return; + } + postControlMsg(controlMsg); +} + +void Controller::requestDeviceClipboard() +{ + ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_GET_CLIPBOARD); + if (!controlMsg) { + return; + } + postControlMsg(controlMsg); +} + +void Controller::setDeviceClipboard() +{ + QClipboard *board = QApplication::clipboard(); + QString text = board->text(); + ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_SET_CLIPBOARD); + if (!controlMsg) { + return; + } + controlMsg->setSetClipboardMsgData(text); + postControlMsg(controlMsg); +} + +void Controller::clipboardPaste() +{ + QClipboard *board = QApplication::clipboard(); + QString text = board->text(); + postTextInput(text); +} + +void Controller::postTextInput(QString& text) +{ + ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TEXT); + if (!controlMsg) { + return; + } + controlMsg->setInjectTextMsgData(text); + postControlMsg(controlMsg); +} + +void Controller::setScreenPowerMode(ControlMsg::ScreenPowerMode mode) +{ + ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_SET_SCREEN_POWER_MODE); + if (!controlMsg) { + return; + } + controlMsg->setSetScreenPowerModeData(mode); + postControlMsg(controlMsg); +} + void Controller::mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize) { if (m_inputConvert) { @@ -87,3 +198,20 @@ bool Controller::sendControl(const QByteArray &buffer) } return len == buffer.length() ? true : false; } + +void Controller::postKeyCodeClick(AndroidKeycode keycode) +{ + ControlMsg* controlEventDown = new ControlMsg(ControlMsg::CMT_INJECT_KEYCODE); + if (!controlEventDown) { + return; + } + controlEventDown->setInjectKeycodeMsgData(AKEY_EVENT_ACTION_DOWN, keycode, AMETA_NONE); + postControlMsg(controlEventDown); + + ControlMsg* controlEventUp = new ControlMsg(ControlMsg::CMT_INJECT_KEYCODE); + if (!controlEventUp) { + return; + } + controlEventUp->setInjectKeycodeMsgData(AKEY_EVENT_ACTION_UP, keycode, AMETA_NONE); + postControlMsg(controlEventUp); +} diff --git a/QtScrcpy/controller/controller.h b/QtScrcpy/controller/controller.h index da537b6..220b966 100644 --- a/QtScrcpy/controller/controller.h +++ b/QtScrcpy/controller/controller.h @@ -15,10 +15,27 @@ public: Controller(QObject* parent = Q_NULLPTR); virtual ~Controller(); - void setControlSocket(QTcpSocket* controlSocket); + void setControlSocket(QTcpSocket* controlSocket); void postControlMsg(ControlMsg* controlMsg); void test(QRect rc); + // turn the screen on if it was off, press BACK otherwise + void postTurnOn(); + void postGoHome(); + void postGoMenu(); + void postGoBack(); + void postAppSwitch(); + void postPower(); + void postVolumeUp(); + void postVolumeDown(); + void expandNotificationPanel(); + void collapseNotificationPanel(); + void requestDeviceClipboard(); + void setDeviceClipboard(); + void clipboardPaste(); + void postTextInput(QString& text); + void setScreenPowerMode(ControlMsg::ScreenPowerMode mode); + // for input convert void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); @@ -32,6 +49,7 @@ protected: private: bool sendControl(const QByteArray& buffer); + void postKeyCodeClick(AndroidKeycode keycode); private: QPointer m_controlSocket; diff --git a/QtScrcpy/dialog.cpp b/QtScrcpy/dialog.cpp index c7603df..e4113a2 100644 --- a/QtScrcpy/dialog.cpp +++ b/QtScrcpy/dialog.cpp @@ -242,12 +242,13 @@ void Dialog::on_alwaysTopCheck_stateChanged(int arg1) void Dialog::on_closeScreenCheck_stateChanged(int arg1) { + Q_UNUSED(arg1); if (!m_videoForm) { return; } if (ui->closeScreenCheck->isChecked()) { - m_videoForm->setScreenPowerMode(ControlMsg::SPM_OFF); + m_videoForm->getController()->setScreenPowerMode(ControlMsg::SPM_OFF); } else { - m_videoForm->setScreenPowerMode(ControlMsg::SPM_NORMAL); + m_videoForm->getController()->setScreenPowerMode(ControlMsg::SPM_NORMAL); } } diff --git a/QtScrcpy/toolform.cpp b/QtScrcpy/toolform.cpp index d23c913..9f2d556 100644 --- a/QtScrcpy/toolform.cpp +++ b/QtScrcpy/toolform.cpp @@ -82,62 +82,62 @@ void ToolForm::on_fullScreenBtn_clicked() void ToolForm::on_returnBtn_clicked() { if (m_videoForm) { - m_videoForm->postGoBack(); + m_videoForm->getController()->postGoBack(); } } void ToolForm::on_homeBtn_clicked() { if (m_videoForm) { - m_videoForm->postGoHome(); + m_videoForm->getController()->postGoHome(); } } void ToolForm::on_menuBtn_clicked() { if (m_videoForm) { - m_videoForm->postGoMenu(); + m_videoForm->getController()->postGoMenu(); } } void ToolForm::on_appSwitchBtn_clicked() { if (m_videoForm) { - m_videoForm->postAppSwitch(); + m_videoForm->getController()->postAppSwitch(); } } void ToolForm::on_powerBtn_clicked() { if (m_videoForm) { - m_videoForm->postPower(); + m_videoForm->getController()->postPower(); } } void ToolForm::on_volumeUpBtn_clicked() { if (m_videoForm) { - m_videoForm->postVolumeUp(); + m_videoForm->getController()->postVolumeUp(); } } void ToolForm::on_volumeDownBtn_clicked() { if (m_videoForm) { - m_videoForm->postVolumeDown(); + m_videoForm->getController()->postVolumeDown(); } } void ToolForm::on_closeScreenBtn_clicked() { if (m_videoForm) { - m_videoForm->setScreenPowerMode(ControlMsg::SPM_OFF); + m_videoForm->getController()->setScreenPowerMode(ControlMsg::SPM_OFF); } } void ToolForm::on_expandNotifyBtn_clicked() { if (m_videoForm) { - m_videoForm->expandNotificationPanel(); + m_videoForm->getController()->expandNotificationPanel(); } } diff --git a/QtScrcpy/videoform.cpp b/QtScrcpy/videoform.cpp index 6df50df..7199a8c 100644 --- a/QtScrcpy/videoform.cpp +++ b/QtScrcpy/videoform.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include "videoform.h" #include "recorder.h" @@ -191,7 +190,7 @@ void VideoForm::initSignals() m_controller->setControlSocket(m_server->getControlSocket()); if (m_closeScreen) { - setScreenPowerMode(ControlMsg::SPM_OFF); + m_controller->setScreenPowerMode(ControlMsg::SPM_OFF); } } }); @@ -221,10 +220,10 @@ void VideoForm::initSignals() ui->videoWidget->setFrameSize(QSize(frame->width, frame->height)); ui->videoWidget->updateTextures(frame->data[0], frame->data[1], frame->data[2], frame->linesize[0], frame->linesize[1], frame->linesize[2]); m_vb->unLock(); - },Qt::QueuedConnection); + },Qt::QueuedConnection); } -void VideoForm::showToolFrom(bool show) +void VideoForm::showToolForm(bool show) { if (!m_toolForm) { m_toolForm = new ToolForm(this, ToolForm::AP_OUTSIDE_RIGHT); @@ -304,7 +303,7 @@ void VideoForm::switchFullScreen() //show(); #endif updateStyleSheet(height() > width()); - showToolFrom(true); + showToolForm(true); #ifdef Q_OS_WIN32 ::SetThreadExecutionState(ES_CONTINUOUS); #endif @@ -314,7 +313,7 @@ void VideoForm::switchFullScreen() #ifdef Q_OS_OSX //setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint); #endif - showToolFrom(false); + showToolForm(false); layout()->setContentsMargins(0, 0, 0, 0); showFullScreen(); @@ -325,110 +324,7 @@ void VideoForm::switchFullScreen() } } -void VideoForm::postGoMenu() -{ - postKeyCodeClick(AKEYCODE_MENU); -} -void VideoForm::postGoBack() -{ - postKeyCodeClick(AKEYCODE_BACK); -} - -void VideoForm::postAppSwitch() -{ - postKeyCodeClick(AKEYCODE_APP_SWITCH); -} - -void VideoForm::postPower() -{ - postKeyCodeClick(AKEYCODE_POWER); -} - -void VideoForm::postVolumeUp() -{ - postKeyCodeClick(AKEYCODE_VOLUME_UP); -} - -void VideoForm::postVolumeDown() -{ - postKeyCodeClick(AKEYCODE_VOLUME_DOWN); -} - -void VideoForm::postTurnOn() -{ - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_BACK_OR_SCREEN_ON); - if (!controlMsg) { - return; - } - m_controller->postControlMsg(controlMsg); -} - -void VideoForm::expandNotificationPanel() -{ - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_EXPAND_NOTIFICATION_PANEL); - if (!controlMsg) { - return; - } - m_controller->postControlMsg(controlMsg); -} - -void VideoForm::collapseNotificationPanel() -{ - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_COLLAPSE_NOTIFICATION_PANEL); - if (!controlMsg) { - return; - } - m_controller->postControlMsg(controlMsg); -} - -void VideoForm::requestDeviceClipboard() -{ - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_GET_CLIPBOARD); - if (!controlMsg) { - return; - } - m_controller->postControlMsg(controlMsg); -} - -void VideoForm::setDeviceClipboard() -{ - QClipboard *board = QApplication::clipboard(); - QString text = board->text(); - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_SET_CLIPBOARD); - if (!controlMsg) { - return; - } - controlMsg->setSetClipboardMsgData(text); - m_controller->postControlMsg(controlMsg); -} - -void VideoForm::clipboardPaste() -{ - QClipboard *board = QApplication::clipboard(); - QString text = board->text(); - postTextInput(text); -} - -void VideoForm::postTextInput(QString& text) -{ - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TEXT); - if (!controlMsg) { - return; - } - controlMsg->setInjectTextMsgData(text); - m_controller->postControlMsg(controlMsg); -} - -void VideoForm::setScreenPowerMode(ControlMsg::ScreenPowerMode mode) -{ - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_SET_SCREEN_POWER_MODE); - if (!controlMsg) { - return; - } - controlMsg->setSetScreenPowerModeData(mode); - m_controller->postControlMsg(controlMsg); -} void VideoForm::staysOnTop(bool top) { @@ -445,26 +341,9 @@ void VideoForm::staysOnTop(bool top) } } -void VideoForm::postGoHome() +Controller *VideoForm::getController() { - postKeyCodeClick(AKEYCODE_HOME); -} - -void VideoForm::postKeyCodeClick(AndroidKeycode keycode) -{ - ControlMsg* controlEventDown = new ControlMsg(ControlMsg::CMT_INJECT_KEYCODE); - if (!controlEventDown) { - return; - } - controlEventDown->setInjectKeycodeMsgData(AKEY_EVENT_ACTION_DOWN, keycode, AMETA_NONE); - m_controller->postControlMsg(controlEventDown); - - ControlMsg* controlEventUp = new ControlMsg(ControlMsg::CMT_INJECT_KEYCODE); - if (!controlEventUp) { - return; - } - controlEventUp->setInjectKeycodeMsgData(AKEY_EVENT_ACTION_UP, keycode, AMETA_NONE); - m_controller->postControlMsg(controlEventUp); + return m_controller; } void VideoForm::mousePressEvent(QMouseEvent *event) @@ -524,13 +403,13 @@ void VideoForm::keyPressEvent(QKeyEvent *event) switchFullScreen(); } if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier)) { - requestDeviceClipboard(); + m_controller->requestDeviceClipboard(); } if (event->key() == Qt::Key_V && (event->modifiers() & Qt::ControlModifier)) { if (event->modifiers() & Qt::ShiftModifier) { - setDeviceClipboard(); + m_controller->setDeviceClipboard(); } else { - clipboardPaste(); + m_controller->clipboardPaste(); } return; } @@ -558,7 +437,7 @@ void VideoForm::showEvent(QShowEvent *event) { Q_UNUSED(event); if (!isFullScreen()) { - showToolFrom(); + showToolForm(); } } diff --git a/QtScrcpy/videoform.h b/QtScrcpy/videoform.h index 9f4f992..c4089a2 100644 --- a/QtScrcpy/videoform.h +++ b/QtScrcpy/videoform.h @@ -25,33 +25,16 @@ public: explicit VideoForm(const QString& serial, quint16 maxSize = 720, quint32 bitRate = 8000000, const QString& fileName = "", bool closeScreen = false, QWidget *parent = 0); ~VideoForm(); - void switchFullScreen(); - void postGoMenu(); - void postGoHome(); - void postGoBack(); - void postAppSwitch(); - void postPower(); - void postVolumeUp(); - void postVolumeDown(); - // turn the screen on if it was off, press BACK otherwise - void postTurnOn(); - void expandNotificationPanel(); - void collapseNotificationPanel(); - void requestDeviceClipboard(); - void setDeviceClipboard(); - void clipboardPaste(); - void postTextInput(QString& text); - void setScreenPowerMode(ControlMsg::ScreenPowerMode mode); - + void switchFullScreen(); void staysOnTop(bool top = true); + Controller* getController(); private: void updateShowSize(const QSize &newSize); void updateStyleSheet(bool vertical); void initUI(); - void initSignals(); - void showToolFrom(bool show = true); - void postKeyCodeClick(AndroidKeycode keycode); + void initSignals(); + void showToolForm(bool show = true); protected: void mousePressEvent(QMouseEvent *event);