Skip to content

Commit

Permalink
Dev (#367)
Browse files Browse the repository at this point in the history
* feat: update speed ratio script

* feat: update install qt script

* feat: update dmgbuild to 1.4.2

* fix: run error on win

* feat: update comment

* feat: sync scrcpy

* feat: shoutcut no repeat

* feat: volume allow repeat

* fix: set clipboard 16 len bug

* feat: add repeat

* feat: update platform-tools to 31.0.0

* feat: update speed ratio
  • Loading branch information
barry-ran authored Mar 7, 2021
1 parent 93dc6b4 commit ae7f47c
Show file tree
Hide file tree
Showing 23 changed files with 140 additions and 44 deletions.
18 changes: 14 additions & 4 deletions QtScrcpy/device/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ void Controller::onPostVolumeDown()
postKeyCodeClick(AKEYCODE_VOLUME_DOWN);
}

void Controller::onCopy()
{
postKeyCodeClick(AKEYCODE_COPY);
}

void Controller::onCut()
{
postKeyCodeClick(AKEYCODE_CUT);
}

void Controller::onExpandNotificationPanel()
{
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_EXPAND_NOTIFICATION_PANEL);
Expand Down Expand Up @@ -136,15 +146,15 @@ void Controller::onRequestDeviceClipboard()
postControlMsg(controlMsg);
}

void Controller::onSetDeviceClipboard()
void Controller::onSetDeviceClipboard(bool pause)
{
QClipboard *board = QApplication::clipboard();
QString text = board->text();
ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_SET_CLIPBOARD);
if (!controlMsg) {
return;
}
controlMsg->setSetClipboardMsgData(text, true);
controlMsg->setSetClipboardMsgData(text, pause);
postControlMsg(controlMsg);
}

Expand Down Expand Up @@ -226,13 +236,13 @@ void Controller::postKeyCodeClick(AndroidKeycode keycode)
if (!controlEventDown) {
return;
}
controlEventDown->setInjectKeycodeMsgData(AKEY_EVENT_ACTION_DOWN, keycode, AMETA_NONE);
controlEventDown->setInjectKeycodeMsgData(AKEY_EVENT_ACTION_DOWN, keycode, 0, AMETA_NONE);
postControlMsg(controlEventDown);

ControlMsg *controlEventUp = new ControlMsg(ControlMsg::CMT_INJECT_KEYCODE);
if (!controlEventUp) {
return;
}
controlEventUp->setInjectKeycodeMsgData(AKEY_EVENT_ACTION_UP, keycode, AMETA_NONE);
controlEventUp->setInjectKeycodeMsgData(AKEY_EVENT_ACTION_UP, keycode, 0, AMETA_NONE);
postControlMsg(controlEventUp);
}
4 changes: 3 additions & 1 deletion QtScrcpy/device/controller/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public slots:
void onPostPower();
void onPostVolumeUp();
void onPostVolumeDown();
void onCopy();
void onCut();
void onExpandNotificationPanel();
void onCollapseNotificationPanel();
void onSetScreenPowerMode(ControlMsg::ScreenPowerMode mode);
Expand All @@ -43,7 +45,7 @@ public slots:
// turn the screen on if it was off, press BACK otherwise
void onPostBackOrScreenOn();
void onRequestDeviceClipboard();
void onSetDeviceClipboard();
void onSetDeviceClipboard(bool pause = true);
void onClipboardPaste();
void onPostTextInput(QString &text);

Expand Down
8 changes: 5 additions & 3 deletions QtScrcpy/device/controller/inputconvert/controlmsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ ControlMsg::~ControlMsg()
}
}

void ControlMsg::setInjectKeycodeMsgData(AndroidKeyeventAction action, AndroidKeycode keycode, AndroidMetastate metastate)
void ControlMsg::setInjectKeycodeMsgData(AndroidKeyeventAction action, AndroidKeycode keycode, quint32 repeat, AndroidMetastate metastate)
{
m_data.injectKeycode.action = action;
m_data.injectKeycode.keycode = keycode;
m_data.injectKeycode.repeat = repeat;
m_data.injectKeycode.metastate = metastate;
}

Expand Down Expand Up @@ -105,10 +106,11 @@ QByteArray ControlMsg::serializeData()
case CMT_INJECT_KEYCODE:
buffer.putChar(m_data.injectKeycode.action);
BufferUtil::write32(buffer, m_data.injectKeycode.keycode);
BufferUtil::write32(buffer, m_data.injectKeycode.repeat);
BufferUtil::write32(buffer, m_data.injectKeycode.metastate);
break;
case CMT_INJECT_TEXT:
BufferUtil::write16(buffer, static_cast<quint32>(strlen(m_data.injectText.text)));
BufferUtil::write32(buffer, static_cast<quint32>(strlen(m_data.injectText.text)));
buffer.write(m_data.injectText.text, strlen(m_data.injectText.text));
break;
case CMT_INJECT_TOUCH: {
Expand All @@ -126,7 +128,7 @@ QByteArray ControlMsg::serializeData()
break;
case CMT_SET_CLIPBOARD:
buffer.putChar(!!m_data.setClipboard.paste);
BufferUtil::write16(buffer, static_cast<quint32>(strlen(m_data.setClipboard.text)));
BufferUtil::write32(buffer, static_cast<quint32>(strlen(m_data.setClipboard.text)));
buffer.write(m_data.setClipboard.text, strlen(m_data.setClipboard.text));
break;
case CMT_SET_SCREEN_POWER_MODE:
Expand Down
11 changes: 9 additions & 2 deletions QtScrcpy/device/controller/inputconvert/controlmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
#include "keycodes.h"
#include "qscrcpyevent.h"

#define CONTROL_MSG_MAX_SIZE (1 << 18) // 256k

#define CONTROL_MSG_INJECT_TEXT_MAX_LENGTH 300
#define CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH 4092
// type: 1 byte; paste flag: 1 byte; length: 4 bytes
#define CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH \
(CONTROL_MSG_MAX_SIZE - 6)

#define POINTER_ID_MOUSE static_cast<quint64>(-1)

// ControlMsg
class ControlMsg : public QScrcpyEvent
{
Expand Down Expand Up @@ -41,7 +47,7 @@ class ControlMsg : public QScrcpyEvent
ControlMsg(ControlMsgType controlMsgType);
virtual ~ControlMsg();

void setInjectKeycodeMsgData(AndroidKeyeventAction action, AndroidKeycode keycode, AndroidMetastate metastate);
void setInjectKeycodeMsgData(AndroidKeyeventAction action, AndroidKeycode keycode, quint32 repeat, AndroidMetastate metastate);
void setInjectTextMsgData(QString &text);
// id 代表一个触摸点,最多支持10个触摸点[0,9]
// action 只能是AMOTION_EVENT_ACTION_DOWN,AMOTION_EVENT_ACTION_UP,AMOTION_EVENT_ACTION_MOVE
Expand All @@ -67,6 +73,7 @@ class ControlMsg : public QScrcpyEvent
{
AndroidKeyeventAction action;
AndroidKeycode keycode;
quint32 repeat;
AndroidMetastate metastate;
} injectKeycode;
struct
Expand Down
4 changes: 3 additions & 1 deletion QtScrcpy/device/controller/inputconvert/inputconvertbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ class InputConvertBase : public QObject
protected:
void sendControlMsg(ControlMsg *msg);

private:
QPointer<Controller> m_controller;
// Qt reports repeated events as a boolean, but Android expects the actual
// number of repetitions. This variable keeps track of the count.
unsigned m_repeat = 0;
};

#endif // INPUTCONVERTBASE_H
6 changes: 5 additions & 1 deletion QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,15 @@ void InputConvertGame::sendTouchEvent(int id, QPointF pos, AndroidMotioneventAct
QPoint absolutePos = calcFrameAbsolutePos(pos).toPoint();
static QPoint lastAbsolutePos = absolutePos;
if (AMOTION_EVENT_ACTION_MOVE == action && lastAbsolutePos == absolutePos) {
delete controlMsg;
return;
}
lastAbsolutePos = absolutePos;

controlMsg->setInjectTouchMsgData(static_cast<quint64>(id), action, static_cast<AndroidMotioneventButtons>(0), QRect(absolutePos, m_frameSize), 1.0f);
controlMsg->setInjectTouchMsgData(static_cast<quint64>(id), action,
static_cast<AndroidMotioneventButtons>(0),
QRect(absolutePos, m_frameSize),
AMOTION_EVENT_ACTION_DOWN == action? 1.0f : 0.0f);
sendControlMsg(controlMsg);
}

Expand Down
18 changes: 16 additions & 2 deletions QtScrcpy/device/controller/inputconvert/inputconvertnormal.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <cmath>
#include <QDebug>

#include "inputconvertnormal.h"
#include "controller.h"

InputConvertNormal::InputConvertNormal(Controller *controller) : InputConvertBase(controller) {}

Expand Down Expand Up @@ -44,7 +46,10 @@ void InputConvertNormal::mouseEvent(const QMouseEvent *from, const QSize &frameS
return;
}
controlMsg->setInjectTouchMsgData(
static_cast<quint64>(POINTER_ID_MOUSE), action, convertMouseButtons(from->buttons()), QRect(pos.toPoint(), frameSize), 1.0f);
static_cast<quint64>(POINTER_ID_MOUSE), action,
convertMouseButtons(from->buttons()),
QRect(pos.toPoint(), frameSize),
AMOTION_EVENT_ACTION_DOWN == action? 1.0f : 0.0f);
sendControlMsg(controlMsg);
}

Expand Down Expand Up @@ -81,6 +86,8 @@ void InputConvertNormal::keyEvent(const QKeyEvent *from, const QSize &frameSize,
return;
}

bool repeat = from->isAutoRepeat();

// action
AndroidKeyeventAction action;
switch (from->type()) {
Expand All @@ -105,7 +112,14 @@ void InputConvertNormal::keyEvent(const QKeyEvent *from, const QSize &frameSize,
if (!controlMsg) {
return;
}
controlMsg->setInjectKeycodeMsgData(action, keyCode, convertMetastate(from->modifiers()));

if (repeat) {
m_repeat++;
} else {
m_repeat = 0;
}

controlMsg->setInjectKeycodeMsgData(action, keyCode, m_repeat, convertMetastate(from->modifiers()));
sendControlMsg(controlMsg);
}

Expand Down
8 changes: 4 additions & 4 deletions QtScrcpy/device/controller/receiver/devicemsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ qint32 DeviceMsg::deserialize(QByteArray &byteArray)
char c = 0;
qint32 ret = 0;

if (len < 3) {
if (len < 5) {
// at least type + empty string length
return 0; // not available
}
Expand All @@ -42,8 +42,8 @@ qint32 DeviceMsg::deserialize(QByteArray &byteArray)
switch (m_data.type) {
case DMT_GET_CLIPBOARD: {
m_data.clipboardMsg.text = Q_NULLPTR;
quint16 clipboardLen = BufferUtil::read16(buf);
if (clipboardLen > len - 3) {
quint16 clipboardLen = BufferUtil::read32(buf);
if (clipboardLen > len - 5) {
ret = 0; // not available
break;
}
Expand All @@ -53,7 +53,7 @@ qint32 DeviceMsg::deserialize(QByteArray &byteArray)
memcpy(m_data.clipboardMsg.text, text.data(), text.length());
m_data.clipboardMsg.text[text.length()] = '\0';

ret = 3 + clipboardLen;
ret = 5 + clipboardLen;
break;
}
default:
Expand Down
6 changes: 3 additions & 3 deletions QtScrcpy/device/controller/receiver/devicemsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#include <QBuffer>

#define DEVICE_MSG_QUEUE_SIZE 64
#define DEVICE_MSG_TEXT_MAX_LENGTH 4093
#define DEVICE_MSG_SERIALIZED_MAX_SIZE (3 + DEVICE_MSG_TEXT_MAX_LENGTH)
#define DEVICE_MSG_MAX_SIZE (1 << 18) // 256k
// type: 1 byte; length: 4 bytes
#define DEVICE_MSG_TEXT_MAX_LENGTH (DEVICE_MSG_MAX_SIZE - 5)

class DeviceMsg : public QObject
{
Expand Down
5 changes: 5 additions & 0 deletions QtScrcpy/device/controller/receiver/receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void Receiver::processMsg(DeviceMsg *deviceMsg)
QClipboard *board = QApplication::clipboard();
QString text;
deviceMsg->getClipboardMsgData(text);

if (board->text() == text) {
qDebug("Computer clipboard unchanged");
break;
}
board->setText(text);
break;
}
Expand Down
3 changes: 2 additions & 1 deletion QtScrcpy/device/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ void Device::initSignals()
connect(this, &Device::postPower, m_controller, &Controller::onPostPower);
connect(this, &Device::postVolumeUp, m_controller, &Controller::onPostVolumeUp);
connect(this, &Device::postVolumeDown, m_controller, &Controller::onPostVolumeDown);
connect(this, &Device::postCopy, m_controller, &Controller::onCopy);
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);
Expand All @@ -159,7 +161,6 @@ void Device::initSignals()
connect(this, &Device::keyEvent, m_controller, &Controller::onKeyEvent);

connect(this, &Device::postBackOrScreenOn, m_controller, &Controller::onPostBackOrScreenOn);
connect(this, &Device::requestDeviceClipboard, m_controller, &Controller::onRequestDeviceClipboard);
connect(this, &Device::setDeviceClipboard, m_controller, &Controller::onSetDeviceClipboard);
connect(this, &Device::clipboardPaste, m_controller, &Controller::onClipboardPaste);
connect(this, &Device::postTextInput, m_controller, &Controller::onPostTextInput);
Expand Down
4 changes: 3 additions & 1 deletion QtScrcpy/device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ class Device : public QObject
void postPower();
void postVolumeUp();
void postVolumeDown();
void postCopy();
void postCut();
void setScreenPowerMode(ControlMsg::ScreenPowerMode mode);
void expandNotificationPanel();
void collapseNotificationPanel();
void postBackOrScreenOn();
void postTextInput(QString &text);
void requestDeviceClipboard();
void setDeviceClipboard();
void setDeviceClipboard(bool pause = true);
void clipboardPaste();
void pushFileRequest(const QString &file, const QString &devicePath = "");
void installApkRequest(const QString &apkFile);
Expand Down
1 change: 1 addition & 0 deletions QtScrcpy/device/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ bool Server::execute()
// https://github.com/Genymobile/scrcpy/commit/080a4ee3654a9b7e96c8ffe37474b5c21c02852a
// <https://d.android.com/reference/android/media/MediaFormat>
args << Config::getInstance().getCodecOptions();
args << Config::getInstance().getCodecName();

#ifdef SERVER_DEBUGGER
qInfo("Server debugger waiting for a client on device port " SERVER_DEBUGGER_PORT "...");
Expand Down
Loading

0 comments on commit ae7f47c

Please sign in to comment.