Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/barry-ran/QtScrcpy into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	QtScrcpy/dialog.ui
#	README.md
  • Loading branch information
yxtj committed Jan 18, 2020
2 parents 0cb5826 + 3798975 commit bcfb3d6
Show file tree
Hide file tree
Showing 58 changed files with 1,799 additions and 749 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
/server/gradlew
/server/gradlew.bat
/server/local.properties
build
build-*
*.DS_Store
10 changes: 7 additions & 3 deletions QtScrcpy/QtScrcpy.pro
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ INCLUDEPATH += \

# 统一版本号入口,只修改这一个地方即可
VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_PATCH = 4
VERSION_MINOR = 1
VERSION_PATCH = 0

# qmake变量的方式定义版本号
VERSION = $${VERSION_MAJOR}.$${VERSION_MINOR}.$${VERSION_PATCH}
Expand Down Expand Up @@ -140,7 +140,7 @@ macos {
-L$$PWD/../third_party/ffmpeg/lib -lswscale.5

# mac bundle file
APP_SCRCPY_SERVER.files = $$files($$PWD/../third_party/scrcpy-server.jar)
APP_SCRCPY_SERVER.files = $$files($$PWD/../third_party/scrcpy-server)
APP_SCRCPY_SERVER.path = Contents/MacOS
QMAKE_BUNDLE_DATA += APP_SCRCPY_SERVER

Expand All @@ -152,6 +152,10 @@ macos {
APP_FFMPEG.path = Contents/MacOS
QMAKE_BUNDLE_DATA += APP_FFMPEG

APP_CONFIG.files = $$files($$PWD/../config/config.ini)
APP_CONFIG.path = Contents/MacOS
QMAKE_BUNDLE_DATA += APP_CONFIG

# mac application icon
ICON = $$PWD/res/QtScrcpy.icns
QMAKE_INFO_PLIST = $$PWD/res/Info_mac.plist
Expand Down
4 changes: 2 additions & 2 deletions QtScrcpy/device/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ void Controller::postControlMsg(ControlMsg *controlMsg)

void Controller::test(QRect rc)
{
ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_MOUSE);
controlMsg->setInjectMouseMsgData(AMOTION_EVENT_ACTION_DOWN, AMOTION_EVENT_BUTTON_PRIMARY, rc);
ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TOUCH);
controlMsg->setInjectTouchMsgData(POINTER_ID_MOUSE, AMOTION_EVENT_ACTION_DOWN, AMOTION_EVENT_BUTTON_PRIMARY, rc, 1.0f);
postControlMsg(controlMsg);
}

Expand Down
39 changes: 22 additions & 17 deletions QtScrcpy/device/controller/inputconvert/controlmsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,13 @@ void ControlMsg::setInjectTextMsgData(QString& text)
m_data.injectText.text[tmp.length()] = '\0';
}

void ControlMsg::setInjectMouseMsgData(AndroidMotioneventAction action, AndroidMotioneventButtons buttons, QRect position)
void ControlMsg::setInjectTouchMsgData(quint64 id, AndroidMotioneventAction action, AndroidMotioneventButtons buttons, QRect position, float pressure)
{
m_data.injectMouse.action = action;
m_data.injectMouse.buttons = buttons;
m_data.injectMouse.position = position;
}

void ControlMsg::setInjectTouchMsgData(quint32 id, AndroidMotioneventAction action, QRect position)
{
m_data.injectTouch.action = action;
m_data.injectTouch.id = id;
m_data.injectTouch.action = action;
m_data.injectTouch.buttons = buttons;
m_data.injectTouch.position = position;
m_data.injectTouch.pressure = pressure;
}

void ControlMsg::setInjectScrollMsgData(QRect position, qint32 hScroll, qint32 vScroll)
Expand Down Expand Up @@ -85,12 +80,22 @@ void ControlMsg::setSetScreenPowerModeData(ControlMsg::ScreenPowerMode mode)

void ControlMsg::writePosition(QBuffer &buffer, const QRect& value)
{
BufferUtil::write16(buffer, value.left());
BufferUtil::write16(buffer, value.top());
BufferUtil::write32(buffer, value.left());
BufferUtil::write32(buffer, value.top());
BufferUtil::write16(buffer, value.width());
BufferUtil::write16(buffer, value.height());
}

quint16 ControlMsg::toFixedPoint16(float f)
{
assert(f >= 0.0f && f <= 1.0f);
quint32 u = f * 0x1p16f; // 2^16
if (u >= 0xffff) {
u = 0xffff;
}
return (quint16) u;
}

QByteArray ControlMsg::serializeData()
{
QByteArray byteArray;
Expand All @@ -108,15 +113,15 @@ QByteArray ControlMsg::serializeData()
BufferUtil::write16(buffer, strlen(m_data.injectText.text));
buffer.write(m_data.injectText.text, strlen(m_data.injectText.text));
break;
case CMT_INJECT_MOUSE:
buffer.putChar(m_data.injectMouse.action);
BufferUtil::write32(buffer, m_data.injectMouse.buttons);
writePosition(buffer, m_data.injectMouse.position);
break;
case CMT_INJECT_TOUCH:
buffer.putChar(m_data.injectTouch.id);
{
buffer.putChar(m_data.injectTouch.action);
BufferUtil::write64(buffer, m_data.injectTouch.id);
writePosition(buffer, m_data.injectTouch.position);
quint16 pressure = toFixedPoint16(m_data.injectTouch.pressure);
BufferUtil::write16(buffer, pressure);
BufferUtil::write32(buffer, m_data.injectTouch.buttons);
}
break;
case CMT_INJECT_SCROLL:
writePosition(buffer, m_data.injectScroll.position);
Expand Down
18 changes: 7 additions & 11 deletions QtScrcpy/device/controller/inputconvert/controlmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#define CONTROL_MSG_TEXT_MAX_LENGTH 300
#define CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH 4093
#define POINTER_ID_MOUSE UINT64_C(-1)
// ControlMsg
class ControlMsg : public QScrcpyEvent
{
Expand All @@ -19,16 +20,14 @@ class ControlMsg : public QScrcpyEvent
CMT_NULL = -1,
CMT_INJECT_KEYCODE = 0,
CMT_INJECT_TEXT,
CMT_INJECT_MOUSE,
CMT_INJECT_TOUCH,
CMT_INJECT_SCROLL,
CMT_BACK_OR_SCREEN_ON,
CMT_EXPAND_NOTIFICATION_PANEL,
CMT_COLLAPSE_NOTIFICATION_PANEL,
CMT_GET_CLIPBOARD,
CMT_SET_CLIPBOARD,
CMT_SET_SCREEN_POWER_MODE,

CMT_INJECT_TOUCH,
CMT_SET_SCREEN_POWER_MODE
};

enum ScreenPowerMode {
Expand All @@ -42,11 +41,10 @@ class ControlMsg : public QScrcpyEvent

void setInjectKeycodeMsgData(AndroidKeyeventAction action, AndroidKeycode keycode, AndroidMetastate metastate);
void setInjectTextMsgData(QString& text);
void setInjectMouseMsgData(AndroidMotioneventAction action, AndroidMotioneventButtons buttons, QRect position);
// id 代表一个触摸点,最多支持10个触摸点[0,9]
// action 只能是AMOTION_EVENT_ACTION_DOWN,AMOTION_EVENT_ACTION_UP,AMOTION_EVENT_ACTION_MOVE
// position action动作对应的位置
void setInjectTouchMsgData(quint32 id, AndroidMotioneventAction action, QRect position);
void setInjectTouchMsgData(quint64 id, AndroidMotioneventAction action, AndroidMotioneventButtons buttons, QRect position, float pressure);
void setInjectScrollMsgData(QRect position, qint32 hScroll, qint32 vScroll);
void setSetClipboardMsgData(QString& text);
void setSetScreenPowerModeData(ControlMsg::ScreenPowerMode mode);
Expand All @@ -55,6 +53,7 @@ class ControlMsg : public QScrcpyEvent

private:
void writePosition(QBuffer& buffer, const QRect& value);
quint16 toFixedPoint16(float f);

private:
struct ControlMsgData {
Expand All @@ -69,14 +68,11 @@ class ControlMsg : public QScrcpyEvent
char* text = Q_NULLPTR;
} injectText;
struct {
quint64 id;
AndroidMotioneventAction action;
AndroidMotioneventButtons buttons;
QRect position;
} injectMouse;
struct {
quint32 id;
AndroidMotioneventAction action;
QRect position;
float pressure;
} injectTouch;
struct {
QRect position;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void InputConvertGame::sendTouchEvent(int id, QPointF pos, AndroidMotioneventAct
if (!controlMsg) {
return;
}
controlMsg->setInjectTouchMsgData(id, action, QRect(calcFrameAbsolutePos(pos).toPoint(), m_frameSize));
controlMsg->setInjectTouchMsgData(id, action, (AndroidMotioneventButtons)0, QRect(calcFrameAbsolutePos(pos).toPoint(), m_frameSize), 1.0f);
sendControlMsg(controlMsg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ void InputConvertNormal::mouseEvent(const QMouseEvent* from, const QSize& frameS
pos.setY(pos.y() * frameSize.height() / showSize.height());

// set data
ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_MOUSE);
ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TOUCH);
if (!controlMsg) {
return;
}
controlMsg->setInjectMouseMsgData(action, convertMouseButtons(from->buttons()), QRect(pos.toPoint(), frameSize));
controlMsg->setInjectTouchMsgData(POINTER_ID_MOUSE, action, convertMouseButtons(from->buttons()), QRect(pos.toPoint(), frameSize), 1.0f);
sendControlMsg(controlMsg);
}

Expand Down
7 changes: 3 additions & 4 deletions QtScrcpy/device/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "stream.h"
#include "videoform.h"
#include "controller.h"
#include "config.h"

Device::Device(DeviceParams params, QObject *parent)
: QObject(parent)
Expand All @@ -27,8 +28,7 @@ Device::Device(DeviceParams params, QObject *parent)
m_decoder = new Decoder(m_vb, this);
m_fileHandler = new FileHandler(this);
m_controller = new Controller(params.gameScript, this);
//m_videoForm = new VideoForm(false);
m_videoForm = new VideoForm();
m_videoForm = new VideoForm(Config::getInstance().getSkin());
m_videoForm->setSerial(m_params.serial);
if (m_controller) {
m_videoForm->setController(m_controller);
Expand Down Expand Up @@ -204,14 +204,13 @@ void Device::startServer()
//m_server->start("192.168.0.174:5555", 27183, m_maxSize, m_bitRate, "");
// only one devices, serial can be null
// mark: crop input format: "width:height:x:y" or - for no crop, for example: "100:200:0:0"
// sendFrameMeta for recorder mp4
Server::ServerParams params;
params.serial = m_params.serial;
params.localPort = m_params.localPort;
params.maxSize = m_params.maxSize;
params.bitRate = m_params.bitRate;
params.maxFps = m_params.maxFps;
params.crop = "-";
params.sendFrameMeta = m_recorder ? true : false;
params.control = true;
params.useReverse = m_params.useReverse;
m_server->start(params);
Expand Down
1 change: 1 addition & 0 deletions QtScrcpy/device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Device : public QObject
quint16 localPort = 27183; // reverse时本地监听端口
quint16 maxSize = 720; // 视频分辨率
quint32 bitRate = 8000000; // 视频比特率
quint32 maxFps = 60; // 视频最大帧率
bool closeScreen = false; // 启动时自动息屏
bool useReverse = true; // true:先使用adb reverse,失败后自动使用adb forward;false:直接使用adb forward
bool display = true; // 是否显示画面(或者仅仅后台录制)
Expand Down
Loading

0 comments on commit bcfb3d6

Please sign in to comment.