From 827c529b3650e396d9c09acb99ae9cee6b657cfa Mon Sep 17 00:00:00 2001 From: rankun Date: Sun, 29 Mar 2020 02:13:01 +0800 Subject: [PATCH] chore: code format by clang-format --- .clang-format | 227 +++++++++ QtScrcpy/adb/adbprocess.cpp | 56 +-- QtScrcpy/adb/adbprocess.h | 33 +- QtScrcpy/clang-format-all.sh | 84 ++++ QtScrcpy/common/qscrcpyevent.h | 7 +- QtScrcpy/device/android/input.h | 44 +- QtScrcpy/device/android/keycodes.h | 469 +++++++++--------- QtScrcpy/device/controller/controller.cpp | 48 +- QtScrcpy/device/controller/controller.h | 18 +- .../controller/inputconvert/controlmsg.cpp | 23 +- .../controller/inputconvert/controlmsg.h | 50 +- .../inputconvert/inputconvertbase.cpp | 10 +- .../inputconvert/inputconvertbase.h | 14 +- .../inputconvert/inputconvertgame.cpp | 49 +- .../inputconvert/inputconvertgame.h | 34 +- .../inputconvert/inputconvertnormal.cpp | 25 +- .../inputconvert/inputconvertnormal.h | 8 +- .../controller/inputconvert/keymap/keymap.cpp | 166 +++---- .../controller/inputconvert/keymap/keymap.h | 120 ++--- .../device/controller/receiver/devicemsg.cpp | 16 +- .../device/controller/receiver/devicemsg.h | 22 +- .../device/controller/receiver/receiver.cpp | 16 +- QtScrcpy/device/decoder/avframeconvert.cpp | 29 +- QtScrcpy/device/decoder/avframeconvert.h | 8 +- QtScrcpy/device/decoder/decoder.cpp | 20 +- QtScrcpy/device/decoder/decoder.h | 8 +- QtScrcpy/device/decoder/fpscounter.cpp | 14 +- QtScrcpy/device/decoder/fpscounter.h | 4 +- QtScrcpy/device/decoder/videobuffer.cpp | 16 +- QtScrcpy/device/decoder/videobuffer.h | 14 +- QtScrcpy/device/device.cpp | 69 +-- QtScrcpy/device/device.h | 52 +- QtScrcpy/device/filehandler/filehandler.cpp | 12 +- QtScrcpy/device/filehandler/filehandler.h | 13 +- QtScrcpy/device/recorder/recorder.cpp | 83 ++-- QtScrcpy/device/recorder/recorder.h | 37 +- QtScrcpy/device/render/qyuvopenglwidget.cpp | 44 +- QtScrcpy/device/render/qyuvopenglwidget.h | 24 +- QtScrcpy/device/server/server.cpp | 63 ++- QtScrcpy/device/server/server.h | 35 +- QtScrcpy/device/server/tcpserver.cpp | 10 +- QtScrcpy/device/server/videosocket.cpp | 6 +- QtScrcpy/device/server/videosocket.h | 6 +- QtScrcpy/device/stream/stream.cpp | 60 ++- QtScrcpy/device/stream/stream.h | 20 +- QtScrcpy/device/ui/toolform.cpp | 16 +- QtScrcpy/device/ui/toolform.h | 13 +- QtScrcpy/device/ui/videoform.cpp | 302 ++++++----- QtScrcpy/device/ui/videoform.h | 13 +- QtScrcpy/devicemanage/devicemanage.cpp | 24 +- QtScrcpy/devicemanage/devicemanage.h | 10 +- QtScrcpy/dialog.cpp | 50 +- QtScrcpy/dialog.h | 11 +- QtScrcpy/fontawesome/iconhelper.cpp | 9 +- QtScrcpy/fontawesome/iconhelper.h | 15 +- QtScrcpy/main.cpp | 23 +- QtScrcpy/uibase/keepradiowidget.cpp | 11 +- QtScrcpy/uibase/keepradiowidget.h | 5 +- QtScrcpy/uibase/magneticwidget.cpp | 56 +-- QtScrcpy/uibase/magneticwidget.h | 27 +- QtScrcpy/util/bufferutil.cpp | 17 +- QtScrcpy/util/bufferutil.h | 12 +- QtScrcpy/util/compat.h | 13 +- QtScrcpy/util/config.cpp | 7 +- QtScrcpy/util/config.h | 6 +- QtScrcpy/util/mousetap/cocoamousetap.h | 6 +- QtScrcpy/util/mousetap/mousetap.h | 5 +- QtScrcpy/util/mousetap/winmousetap.cpp | 26 +- 68 files changed, 1517 insertions(+), 1346 deletions(-) create mode 100644 .clang-format create mode 100644 QtScrcpy/clang-format-all.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..55fcd7d --- /dev/null +++ b/.clang-format @@ -0,0 +1,227 @@ +--- +# 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto +Language: Cpp +# BasedOnStyle: WebKit +# 访问说明符(public、private等)的偏移 +AccessModifierOffset: -4 +# 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行) +AlignAfterOpenBracket: AlwaysBreak +# 连续赋值时,对齐所有等号 +AlignConsecutiveAssignments: false +# 连续声明时,对齐所有声明的变量名 +AlignConsecutiveDeclarations: false +# 左对齐逃脱换行(使用反斜杠换行)的反斜杠 +AlignEscapedNewlines: Right +# 水平对齐二元和三元表达式的操作数 +AlignOperands: true +# 对齐连续的尾随的注释 +AlignTrailingComments: true +# 允许函数声明的所有参数在放在下一行 +AllowAllParametersOfDeclarationOnNextLine: false +# 允许短的块放在同一行 +AllowShortBlocksOnASingleLine: false +# 允许短的case标签放在同一行 +AllowShortCaseLabelsOnASingleLine: false +# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All +AllowShortFunctionsOnASingleLine: Empty +# 允许短的if语句保持在同一行 +AllowShortIfStatementsOnASingleLine: false +# 允许短的循环保持在同一行 +AllowShortLoopsOnASingleLine: false +# 总是在定义返回类型后换行(deprecated) +AlwaysBreakAfterDefinitionReturnType: None +# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数), +# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义) +AlwaysBreakAfterReturnType: None +# 总是在多行string字面量前换行 +AlwaysBreakBeforeMultilineStrings: false +# 总是在template声明后换行 +AlwaysBreakTemplateDeclarations: true +# false表示函数实参要么都在同一行,要么都各自一行 +BinPackArguments: false +# false表示所有形参要么都在同一行,要么都各自一行 +BinPackParameters: false + +# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似), +# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似), +# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom +# 注:这里认为语句块也属于函数 +BreakBeforeBraces: Custom +# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效 +BraceWrapping: + # class定义后面 + AfterClass: true + # 控制语句后面 + AfterControlStatement: false + # enum定义后面 + AfterEnum: true + # 函数定义后面 + AfterFunction: true + # 命名空间定义后面 + AfterNamespace: true + # ObjC定义后面 + AfterObjCDeclaration: false + # struct定义后面 + AfterStruct: true + # union定义后面 + AfterUnion: true + # extern 定义后面 + AfterExternBlock: true + # catch之前 + BeforeCatch: false + # else 之前 + BeforeElse: false + # 缩进大括号 + IndentBraces: false + +# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行) +BreakBeforeBinaryOperators: All + +# 继承列表的逗号前换行 +BreakBeforeInheritanceComma: true +# 继承列表换行 +#BreakInheritanceList: BeforeColon +# 在三元运算符前换行 +BreakBeforeTernaryOperators: true +# 在构造函数的初始化列表的逗号前换行 +BreakConstructorInitializersBeforeComma: true +# 初始化列表前换行 +BreakConstructorInitializers: BeforeComma +# Java注解后换行 +BreakAfterJavaFieldAnnotations: false + +BreakStringLiterals: true +# 每行字符的限制,0表示没有限制 +ColumnLimit: 160 +# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变 +CommentPragmas: '^ IWYU pragma:' +# 紧凑 命名空间 +CompactNamespaces: false +# 构造函数的初始化列表要么都在同一行,要么都各自一行 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +# 构造函数的初始化列表的缩进宽度 +ConstructorInitializerIndentWidth: 4 +# 延续的行的缩进宽度 +ContinuationIndentWidth: 4 +# 去除C++11的列表初始化的大括号{后和}前的空格 +Cpp11BracedListStyle: false +# 继承最常用的指针和引用的对齐方式 +DerivePointerAlignment: false +# 关闭格式化 +DisableFormat: false +# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental) +ExperimentalAutoDetectBinPacking: false +# 固定命名空间注释 +FixNamespaceComments: true +# 需要被解读为foreach循环而不是函数调用的宏 +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH + +IncludeBlocks: Preserve +# 对#include进行排序,匹配了某正则表达式的#include拥有对应的优先级,匹配不到的则默认优先级为INT_MAX(优先级越小排序越靠前), +# 可以定义负数优先级从而保证某些#include永远在最前面 +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: 'stdafx\.' + Priority: 1 + - Regex: '.*' + Priority: 1 + +IncludeIsMainRegex: '(Test)?$' +# 缩进case标签 +IndentCaseLabels: false + +IndentPPDirectives: None +# 缩进宽度 +IndentWidth: 4 +# 函数返回类型换行时,缩进函数声明或函数定义的函数名 +IndentWrappedFunctionNames: true + +JavaScriptQuotes: Leave + +JavaScriptWrapImports: true +# 保留在块开始处的空行 +KeepEmptyLinesAtTheStartOfBlocks: true +# 开始一个块的宏的正则表达式 +MacroBlockBegin: '' +# 结束一个块的宏的正则表达式 +MacroBlockEnd: '' +# 连续空行的最大数量 +MaxEmptyLinesToKeep: 1 + +# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All +NamespaceIndentation: All +ObjCBinPackProtocolList: Auto +# 使用ObjC块时缩进宽度 +ObjCBlockIndentWidth: 4 +# 在ObjC的@property后添加一个空格 +ObjCSpaceAfterProperty: true +# 在ObjC的protocol列表前添加一个空格 +ObjCSpaceBeforeProtocolList: true + +PenaltyBreakAssignment: 2 + +PenaltyBreakBeforeFirstCallParameter: 19 +# 在一个注释中引入换行的penalty +PenaltyBreakComment: 300 +# 第一次在<<前换行的penalty +PenaltyBreakFirstLessLess: 120 +# 在一个字符串字面量中引入换行的penalty +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +# 对于每个在行字符数限制之外的字符的penalty +PenaltyExcessCharacter: 1000000 +# 将函数的返回类型放到它自己的行的penalty +PenaltyReturnTypeOnItsOwnLine: 60 +# 指针和引用的对齐: Left, Right, Middle +PointerAlignment: Right + +#RawStringFormats: +# - Delimiter: pb +# Language: TextProto +# BasedOnStyle: google +# 允许重新排版注释 +ReflowComments: false +# 允许排序#include +SortIncludes: true + +SortUsingDeclarations: true +# 在C风格类型转换后添加空格 +SpaceAfterCStyleCast: false +# 模板关键字后面添加空格 +SpaceAfterTemplateKeyword: true +# 在赋值运算符之前添加空格 +SpaceBeforeAssignmentOperators: true +# 开圆括号之前添加一个空格: Never, ControlStatements, Always +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +# 在空的圆括号中添加空格 +SpaceInEmptyParentheses: false +# 在尾随的评论前添加的空格数(只适用于//) +SpacesBeforeTrailingComments: 1 +# 在尖括号的<后和>前添加空格 +SpacesInAngles: false +# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格 +SpacesInContainerLiterals: true +# 在C风格类型转换的括号中添加空格 +SpacesInCStyleCastParentheses: false +# 在圆括号的(后和)前添加空格 +SpacesInParentheses: false +# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响 +SpacesInSquareBrackets: false +# 标准: Cpp03, Cpp11, Auto +Standard: Cpp11 +# tab宽度 +TabWidth: 4 +# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always +UseTab: Never +... + diff --git a/QtScrcpy/adb/adbprocess.cpp b/QtScrcpy/adb/adbprocess.cpp index 91035fa..c84645d 100644 --- a/QtScrcpy/adb/adbprocess.cpp +++ b/QtScrcpy/adb/adbprocess.cpp @@ -1,15 +1,14 @@ -#include #include #include -#include #include +#include +#include #include "adbprocess.h" QString AdbProcess::s_adbPath = ""; -AdbProcess::AdbProcess(QObject *parent) - : QProcess(parent) +AdbProcess::AdbProcess(QObject *parent) : QProcess(parent) { initSignals(); } @@ -21,7 +20,7 @@ AdbProcess::~AdbProcess() } } -const QString& AdbProcess::getAdbPath() +const QString &AdbProcess::getAdbPath() { if (s_adbPath.isEmpty()) { s_adbPath = QString::fromLocal8Bit(qgetenv("QTSCRCPY_ADB_PATH")); @@ -38,8 +37,7 @@ void AdbProcess::initSignals() // aboutToQuit not exit event loop, so deletelater is ok //connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &AdbProcess::deleteLater); - connect(this, static_cast(&QProcess::finished), this, - [this](int exitCode, QProcess::ExitStatus exitStatus){ + connect(this, static_cast(&QProcess::finished), this, [this](int exitCode, QProcess::ExitStatus exitStatus) { if (NormalExit == exitStatus && 0 == exitCode) { emit adbProcessResult(AER_SUCCESS_EXEC); } else { @@ -49,9 +47,8 @@ void AdbProcess::initSignals() qDebug() << "adb return " << exitCode << "exit status " << exitStatus; }); - connect(this, &QProcess::errorOccurred, this, - [this](QProcess::ProcessError error){ - if (QProcess::FailedToStart == error) { + connect(this, &QProcess::errorOccurred, this, [this](QProcess::ProcessError error) { + if (QProcess::FailedToStart == error) { emit adbProcessResult(AER_ERROR_MISSING_BINARY); } else { emit adbProcessResult(AER_ERROR_START); @@ -60,27 +57,22 @@ void AdbProcess::initSignals() } }); - connect(this, &QProcess::readyReadStandardError, this, - [this](){ + connect(this, &QProcess::readyReadStandardError, this, [this]() { QString tmp = QString::fromUtf8(readAllStandardError()).trimmed(); m_errorOutput += tmp; qWarning(QString("AdbProcess::error:%1").arg(tmp).toStdString().data()); }); - connect(this, &QProcess::readyReadStandardOutput, this, - [this](){ + connect(this, &QProcess::readyReadStandardOutput, this, [this]() { QString tmp = QString::fromUtf8(readAllStandardOutput()).trimmed(); m_standardOutput += tmp; qInfo(QString("AdbProcess::out:%1").arg(tmp).toStdString().data()); }); - connect(this, &QProcess::started, this, - [this](){ - emit adbProcessResult(AER_SUCCESS_START); - }); + connect(this, &QProcess::started, this, [this]() { emit adbProcessResult(AER_SUCCESS_START); }); } -void AdbProcess::execute(const QString& serial, const QStringList& args) +void AdbProcess::execute(const QString &serial, const QStringList &args) { m_standardOutput = ""; m_errorOutput = ""; @@ -105,7 +97,11 @@ bool AdbProcess::isRuning() void AdbProcess::setShowTouchesEnabled(const QString &serial, bool enabled) { QStringList adbArgs; - adbArgs << "shell" << "settings" << "put" << "system" << "show_touches"; + adbArgs << "shell" + << "settings" + << "put" + << "system" + << "show_touches"; adbArgs << (enabled ? "1" : "0"); execute(serial, adbArgs); } @@ -115,7 +111,7 @@ QStringList AdbProcess::getDevicesSerialFromStdOut() // get devices serial by adb devices QStringList serials; QStringList devicesInfoList = m_standardOutput.split(QRegExp("\r\n|\n"), QString::SkipEmptyParts); - for(QString deviceInfo : devicesInfoList) { + for (QString deviceInfo : devicesInfoList) { QStringList deviceInfos = deviceInfo.split(QRegExp("\t"), QString::SkipEmptyParts); if (2 == deviceInfos.count() && 0 == deviceInfos[1].compare("device")) { serials << deviceInfos[0]; @@ -136,7 +132,7 @@ QString AdbProcess::getDeviceIPFromStdOut() } #else QString strIPExp = "inet addr:[\\d.]*"; - QRegExp ipRegExp(strIPExp,Qt::CaseInsensitive); + QRegExp ipRegExp(strIPExp, Qt::CaseInsensitive); if (ipRegExp.indexIn(m_standardOutput) != -1) { ip = ipRegExp.cap(0); ip = ip.right(ip.size() - 10); @@ -151,7 +147,7 @@ QString AdbProcess::getDeviceIPByIpFromStdOut() QString ip = ""; QString strIPExp = "wlan0 inet [\\d.]*"; - QRegExp ipRegExp(strIPExp,Qt::CaseInsensitive); + QRegExp ipRegExp(strIPExp, Qt::CaseInsensitive); if (ipRegExp.indexIn(m_standardOutput) != -1) { ip = ipRegExp.cap(0); ip = ip.right(ip.size() - 14); @@ -170,7 +166,7 @@ QString AdbProcess::getErrorOut() return m_errorOutput; } -void AdbProcess::forward(const QString& serial, quint16 localPort, const QString& deviceSocketName) +void AdbProcess::forward(const QString &serial, quint16 localPort, const QString &deviceSocketName) { QStringList adbArgs; adbArgs << "forward"; @@ -179,7 +175,7 @@ void AdbProcess::forward(const QString& serial, quint16 localPort, const QString execute(serial, adbArgs); } -void AdbProcess::forwardRemove(const QString& serial, quint16 localPort) +void AdbProcess::forwardRemove(const QString &serial, quint16 localPort) { QStringList adbArgs; adbArgs << "forward"; @@ -188,7 +184,7 @@ void AdbProcess::forwardRemove(const QString& serial, quint16 localPort) execute(serial, adbArgs); } -void AdbProcess::reverse(const QString& serial, const QString& deviceSocketName, quint16 localPort) +void AdbProcess::reverse(const QString &serial, const QString &deviceSocketName, quint16 localPort) { QStringList adbArgs; adbArgs << "reverse"; @@ -197,7 +193,7 @@ void AdbProcess::reverse(const QString& serial, const QString& deviceSocketName, execute(serial, adbArgs); } -void AdbProcess::reverseRemove(const QString& serial, const QString& deviceSocketName) +void AdbProcess::reverseRemove(const QString &serial, const QString &deviceSocketName) { QStringList adbArgs; adbArgs << "reverse"; @@ -206,7 +202,7 @@ void AdbProcess::reverseRemove(const QString& serial, const QString& deviceSocke execute(serial, adbArgs); } -void AdbProcess::push(const QString& serial, const QString& local, const QString& remote) +void AdbProcess::push(const QString &serial, const QString &local, const QString &remote) { QStringList adbArgs; adbArgs << "push"; @@ -215,7 +211,7 @@ void AdbProcess::push(const QString& serial, const QString& local, const QString execute(serial, adbArgs); } -void AdbProcess::install(const QString& serial, const QString& local) +void AdbProcess::install(const QString &serial, const QString &local) { QStringList adbArgs; adbArgs << "install"; @@ -224,7 +220,7 @@ void AdbProcess::install(const QString& serial, const QString& local) execute(serial, adbArgs); } -void AdbProcess::removePath(const QString& serial, const QString& path) +void AdbProcess::removePath(const QString &serial, const QString &path) { QStringList adbArgs; adbArgs << "shell"; diff --git a/QtScrcpy/adb/adbprocess.h b/QtScrcpy/adb/adbprocess.h index 9fd15f1..2bd6b27 100644 --- a/QtScrcpy/adb/adbprocess.h +++ b/QtScrcpy/adb/adbprocess.h @@ -8,34 +8,35 @@ class AdbProcess : public QProcess Q_OBJECT public: - enum ADB_EXEC_RESULT { - AER_SUCCESS_START, // 启动成功 - AER_ERROR_START, // 启动失败 - AER_SUCCESS_EXEC, // 执行成功 - AER_ERROR_EXEC, // 执行失败 - AER_ERROR_MISSING_BINARY, // 找不到文件 + enum ADB_EXEC_RESULT + { + AER_SUCCESS_START, // 启动成功 + AER_ERROR_START, // 启动失败 + AER_SUCCESS_EXEC, // 执行成功 + AER_ERROR_EXEC, // 执行失败 + AER_ERROR_MISSING_BINARY, // 找不到文件 }; explicit AdbProcess(QObject *parent = nullptr); virtual ~AdbProcess(); - void execute(const QString& serial, const QStringList& args); - void forward(const QString& serial, quint16 localPort, const QString& deviceSocketName); - void forwardRemove(const QString& serial, quint16 localPort); - void reverse(const QString& serial, const QString& deviceSocketName, quint16 localPort); - void reverseRemove(const QString& serial, const QString& deviceSocketName); - void push(const QString& serial, const QString& local, const QString& remote); - void install(const QString& serial, const QString& local); - void removePath(const QString& serial, const QString& path); + void execute(const QString &serial, const QStringList &args); + void forward(const QString &serial, quint16 localPort, const QString &deviceSocketName); + void forwardRemove(const QString &serial, quint16 localPort); + void reverse(const QString &serial, const QString &deviceSocketName, quint16 localPort); + void reverseRemove(const QString &serial, const QString &deviceSocketName); + void push(const QString &serial, const QString &local, const QString &remote); + void install(const QString &serial, const QString &local); + void removePath(const QString &serial, const QString &path); bool isRuning(); - void setShowTouchesEnabled(const QString& serial, bool enabled); + void setShowTouchesEnabled(const QString &serial, bool enabled); QStringList getDevicesSerialFromStdOut(); QString getDeviceIPFromStdOut(); QString getDeviceIPByIpFromStdOut(); QString getStdOut(); QString getErrorOut(); - static const QString& getAdbPath(); + static const QString &getAdbPath(); signals: void adbProcessResult(ADB_EXEC_RESULT processResult); diff --git a/QtScrcpy/clang-format-all.sh b/QtScrcpy/clang-format-all.sh new file mode 100644 index 0000000..645c3ce --- /dev/null +++ b/QtScrcpy/clang-format-all.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# clang-format-all: a tool to run clang-format on an entire project +# Copyright (C) 2016 Evan Klitzke +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +function usage { + echo "Usage: $0 DIR..." + exit 1 +} + +if [ $# -eq 0 ]; then + usage +fi + +# Variable that will hold the name of the clang-format command +FMT="" + +# Some distros just call it clang-format. Others (e.g. Ubuntu) are insistent +# that the version number be part of the command. We prefer clang-format if +# that's present, otherwise we work backwards from highest version to lowest +# version. +for clangfmt in clang-format{,-{4,3}.{9,8,7,6,5,4,3,2,1,0}}; do + if which "$clangfmt" &>/dev/null; then + FMT="$clangfmt" + break + fi +done + +# Check if we found a working clang-format +if [ -z "$FMT" ]; then + echo "failed to find clang-format" + exit 1 +fi + +# Check all of the arguments first to make sure they're all directories +for dir in "$@"; do + if [ ! -d "${dir}" ]; then + echo "${dir} is not a directory" + usage + fi +done + +# Find a dominating file, starting from a given directory and going up. +find-dominating-file() { + if [ -r "$1"/"$2" ]; then + return 0 + fi + if [ "$1" = "/" ]; then + return 1 + fi + find-dominating-file "$(realpath "$1"/..)" "$2" + return $? +} + +# Run clang-format -i on all of the things +for dir in "$@"; do + pushd "${dir}" &>/dev/null + if ! find-dominating-file . .clang-format; then + echo "Failed to find dominating .clang-format starting at $PWD" + continue + fi + find . \ + \( -name '*.c' \ + -o -name '*.cc' \ + -o -name '*.cpp' \ + -o -name '*.h' \ + -o -name '*.hh' \ + -o -name '*.hpp' \) \ + -exec "${FMT}" -i '{}' \; + popd &>/dev/null +done diff --git a/QtScrcpy/common/qscrcpyevent.h b/QtScrcpy/common/qscrcpyevent.h index 7365fb6..e140a46 100644 --- a/QtScrcpy/common/qscrcpyevent.h +++ b/QtScrcpy/common/qscrcpyevent.h @@ -5,17 +5,18 @@ class QScrcpyEvent : public QEvent { public: - enum Type { + enum Type + { VideoSocket = QEvent::User + 1, Control, }; - QScrcpyEvent(Type type) : QEvent(QEvent::Type(type)){} + QScrcpyEvent(Type type) : QEvent(QEvent::Type(type)) {} }; // VideoSocketEvent class VideoSocketEvent : public QScrcpyEvent { public: - VideoSocketEvent() : QScrcpyEvent(VideoSocket){} + VideoSocketEvent() : QScrcpyEvent(VideoSocket) {} }; #endif // QSCRCPYEVENT_H diff --git a/QtScrcpy/device/android/input.h b/QtScrcpy/device/android/input.h index 5e3b523..34b3e5d 100644 --- a/QtScrcpy/device/android/input.h +++ b/QtScrcpy/device/android/input.h @@ -23,7 +23,8 @@ /** * Meta key / modifer state. */ -enum AndroidMetastate { +enum AndroidMetastate +{ /** No meta keys are pressed. */ AMETA_NONE = 0, @@ -82,7 +83,8 @@ enum AndroidMetastate { /** * Input event types. */ -enum AndroidInputEventType { +enum AndroidInputEventType +{ /** Indicates that the input event is a key event. */ AINPUT_EVENT_TYPE_KEY = 1, /** Indicates that the input event is a motion event. */ @@ -92,7 +94,8 @@ enum AndroidInputEventType { /** * Key event actions. */ -enum AndroidKeyeventAction { +enum AndroidKeyeventAction +{ /** The key has been pressed down. */ AKEY_EVENT_ACTION_DOWN = 0, @@ -111,7 +114,8 @@ enum AndroidKeyeventAction { /** * Key event flags. */ -enum AndroidKeyeventFlags { +enum AndroidKeyeventFlags +{ /** This mask is set if the device woke because of this key event. */ AKEY_EVENT_FLAG_WOKE_HERE = 0x1, @@ -195,7 +199,8 @@ enum AndroidKeyeventFlags { #define AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT 8 /** Motion event actions */ -enum AndroidMotioneventAction { +enum AndroidMotioneventAction +{ /** Bit mask of the parts of the action code that are the action itself. */ AMOTION_EVENT_ACTION_MASK = 0xff, @@ -205,7 +210,7 @@ enum AndroidMotioneventAction { * down by AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT provides the actual pointer * index where the data for the pointer going up or down can be found. */ - AMOTION_EVENT_ACTION_POINTER_INDEX_MASK = 0xff00, + AMOTION_EVENT_ACTION_POINTER_INDEX_MASK = 0xff00, /** A pressed gesture has started, the motion contains the initial starting location. */ AMOTION_EVENT_ACTION_DOWN = 0, @@ -281,7 +286,8 @@ enum AndroidMotioneventAction { /** * Motion event flags. */ -enum AndroidMotioneventFlags { +enum AndroidMotioneventFlags +{ /** * This flag indicates that the window that received this motion event is partly * or wholly obscured by another visible window above it. This flag is set to true @@ -298,7 +304,8 @@ enum AndroidMotioneventFlags { /** * Motion event edge touch flags. */ -enum AndroidMotioneventEdgeTouchTlags { +enum AndroidMotioneventEdgeTouchTlags +{ /** No edges intersected. */ AMOTION_EVENT_EDGE_FLAG_NONE = 0, @@ -319,7 +326,8 @@ enum AndroidMotioneventEdgeTouchTlags { * Constants that identify each individual axis of a motion event. * @anchor AMOTION_EVENT_AXIS */ -enum AndroidMotioneventAxis { +enum AndroidMotioneventAxis +{ /** * Axis constant: X axis of a motion event. * @@ -688,7 +696,8 @@ enum AndroidMotioneventAxis { * Constants that identify buttons that are associated with motion events. * Refer to the documentation on the MotionEvent class for descriptions of each button. */ -enum AndroidMotioneventButtons { +enum AndroidMotioneventButtons +{ /** primary */ AMOTION_EVENT_BUTTON_PRIMARY = 1 << 0, /** secondary */ @@ -707,7 +716,8 @@ enum AndroidMotioneventButtons { * Constants that identify tool types. * Refer to the documentation on the MotionEvent class for descriptions of each tool type. */ -enum AndroidMotioneventToolType { +enum AndroidMotioneventToolType +{ /** unknown */ AMOTION_EVENT_TOOL_TYPE_UNKNOWN = 0, /** finger */ @@ -726,7 +736,8 @@ enum AndroidMotioneventToolType { * Refer to the documentation on android.view.InputDevice for more details about input sources * and their correct interpretation. */ -enum AndroidInputSourceClass { +enum AndroidInputSourceClass +{ /** mask */ AINPUT_SOURCE_CLASS_MASK = 0x000000ff, @@ -747,7 +758,8 @@ enum AndroidInputSourceClass { /** * Input sources. */ -enum AndroidInputSource { +enum AndroidInputSource +{ /** unknown */ AINPUT_SOURCE_UNKNOWN = 0x00000000, @@ -784,7 +796,8 @@ enum AndroidInputSource { * * Refer to the documentation on android.view.InputDevice for more details. */ -enum AndroidKeyboardType { +enum AndroidKeyboardType +{ /** none */ AINPUT_KEYBOARD_TYPE_NONE = 0, /** non alphabetic */ @@ -802,7 +815,8 @@ enum AndroidKeyboardType { * * @deprecated These constants are deprecated. Use {@link AMOTION_EVENT_AXIS AMOTION_EVENT_AXIS_*} constants instead. */ -enum AndroidMotionRange { +enum AndroidMotionRange +{ /** x */ AINPUT_MOTION_RANGE_X = AMOTION_EVENT_AXIS_X, /** y */ diff --git a/QtScrcpy/device/android/keycodes.h b/QtScrcpy/device/android/keycodes.h index 114881f..fdbb741 100644 --- a/QtScrcpy/device/android/keycodes.h +++ b/QtScrcpy/device/android/keycodes.h @@ -23,395 +23,396 @@ /** * Key codes. */ -enum AndroidKeycode { +enum AndroidKeycode +{ /** Unknown key code. */ - AKEYCODE_UNKNOWN = 0, + AKEYCODE_UNKNOWN = 0, /** Soft Left key. * Usually situated below the display on phones and used as a multi-function * feature key for selecting a software defined function shown on the bottom left * of the display. */ - AKEYCODE_SOFT_LEFT = 1, + AKEYCODE_SOFT_LEFT = 1, /** Soft Right key. * Usually situated below the display on phones and used as a multi-function * feature key for selecting a software defined function shown on the bottom right * of the display. */ - AKEYCODE_SOFT_RIGHT = 2, + AKEYCODE_SOFT_RIGHT = 2, /** Home key. * This key is handled by the framework and is never delivered to applications. */ - AKEYCODE_HOME = 3, + AKEYCODE_HOME = 3, /** Back key. */ - AKEYCODE_BACK = 4, + AKEYCODE_BACK = 4, /** Call key. */ - AKEYCODE_CALL = 5, + AKEYCODE_CALL = 5, /** End Call key. */ - AKEYCODE_ENDCALL = 6, + AKEYCODE_ENDCALL = 6, /** '0' key. */ - AKEYCODE_0 = 7, + AKEYCODE_0 = 7, /** '1' key. */ - AKEYCODE_1 = 8, + AKEYCODE_1 = 8, /** '2' key. */ - AKEYCODE_2 = 9, + AKEYCODE_2 = 9, /** '3' key. */ - AKEYCODE_3 = 10, + AKEYCODE_3 = 10, /** '4' key. */ - AKEYCODE_4 = 11, + AKEYCODE_4 = 11, /** '5' key. */ - AKEYCODE_5 = 12, + AKEYCODE_5 = 12, /** '6' key. */ - AKEYCODE_6 = 13, + AKEYCODE_6 = 13, /** '7' key. */ - AKEYCODE_7 = 14, + AKEYCODE_7 = 14, /** '8' key. */ - AKEYCODE_8 = 15, + AKEYCODE_8 = 15, /** '9' key. */ - AKEYCODE_9 = 16, + AKEYCODE_9 = 16, /** '*' key. */ - AKEYCODE_STAR = 17, + AKEYCODE_STAR = 17, /** '#' key. */ - AKEYCODE_POUND = 18, + AKEYCODE_POUND = 18, /** Directional Pad Up key. * May also be synthesized from trackball motions. */ - AKEYCODE_DPAD_UP = 19, + AKEYCODE_DPAD_UP = 19, /** Directional Pad Down key. * May also be synthesized from trackball motions. */ - AKEYCODE_DPAD_DOWN = 20, + AKEYCODE_DPAD_DOWN = 20, /** Directional Pad Left key. * May also be synthesized from trackball motions. */ - AKEYCODE_DPAD_LEFT = 21, + AKEYCODE_DPAD_LEFT = 21, /** Directional Pad Right key. * May also be synthesized from trackball motions. */ - AKEYCODE_DPAD_RIGHT = 22, + AKEYCODE_DPAD_RIGHT = 22, /** Directional Pad Center key. * May also be synthesized from trackball motions. */ - AKEYCODE_DPAD_CENTER = 23, + AKEYCODE_DPAD_CENTER = 23, /** Volume Up key. * Adjusts the speaker volume up. */ - AKEYCODE_VOLUME_UP = 24, + AKEYCODE_VOLUME_UP = 24, /** Volume Down key. * Adjusts the speaker volume down. */ - AKEYCODE_VOLUME_DOWN = 25, + AKEYCODE_VOLUME_DOWN = 25, /** Power key. */ - AKEYCODE_POWER = 26, + AKEYCODE_POWER = 26, /** Camera key. * Used to launch a camera application or take pictures. */ - AKEYCODE_CAMERA = 27, + AKEYCODE_CAMERA = 27, /** Clear key. */ - AKEYCODE_CLEAR = 28, + AKEYCODE_CLEAR = 28, /** 'A' key. */ - AKEYCODE_A = 29, + AKEYCODE_A = 29, /** 'B' key. */ - AKEYCODE_B = 30, + AKEYCODE_B = 30, /** 'C' key. */ - AKEYCODE_C = 31, + AKEYCODE_C = 31, /** 'D' key. */ - AKEYCODE_D = 32, + AKEYCODE_D = 32, /** 'E' key. */ - AKEYCODE_E = 33, + AKEYCODE_E = 33, /** 'F' key. */ - AKEYCODE_F = 34, + AKEYCODE_F = 34, /** 'G' key. */ - AKEYCODE_G = 35, + AKEYCODE_G = 35, /** 'H' key. */ - AKEYCODE_H = 36, + AKEYCODE_H = 36, /** 'I' key. */ - AKEYCODE_I = 37, + AKEYCODE_I = 37, /** 'J' key. */ - AKEYCODE_J = 38, + AKEYCODE_J = 38, /** 'K' key. */ - AKEYCODE_K = 39, + AKEYCODE_K = 39, /** 'L' key. */ - AKEYCODE_L = 40, + AKEYCODE_L = 40, /** 'M' key. */ - AKEYCODE_M = 41, + AKEYCODE_M = 41, /** 'N' key. */ - AKEYCODE_N = 42, + AKEYCODE_N = 42, /** 'O' key. */ - AKEYCODE_O = 43, + AKEYCODE_O = 43, /** 'P' key. */ - AKEYCODE_P = 44, + AKEYCODE_P = 44, /** 'Q' key. */ - AKEYCODE_Q = 45, + AKEYCODE_Q = 45, /** 'R' key. */ - AKEYCODE_R = 46, + AKEYCODE_R = 46, /** 'S' key. */ - AKEYCODE_S = 47, + AKEYCODE_S = 47, /** 'T' key. */ - AKEYCODE_T = 48, + AKEYCODE_T = 48, /** 'U' key. */ - AKEYCODE_U = 49, + AKEYCODE_U = 49, /** 'V' key. */ - AKEYCODE_V = 50, + AKEYCODE_V = 50, /** 'W' key. */ - AKEYCODE_W = 51, + AKEYCODE_W = 51, /** 'X' key. */ - AKEYCODE_X = 52, + AKEYCODE_X = 52, /** 'Y' key. */ - AKEYCODE_Y = 53, + AKEYCODE_Y = 53, /** 'Z' key. */ - AKEYCODE_Z = 54, + AKEYCODE_Z = 54, /** ',' key. */ - AKEYCODE_COMMA = 55, + AKEYCODE_COMMA = 55, /** '.' key. */ - AKEYCODE_PERIOD = 56, + AKEYCODE_PERIOD = 56, /** Left Alt modifier key. */ - AKEYCODE_ALT_LEFT = 57, + AKEYCODE_ALT_LEFT = 57, /** Right Alt modifier key. */ - AKEYCODE_ALT_RIGHT = 58, + AKEYCODE_ALT_RIGHT = 58, /** Left Shift modifier key. */ - AKEYCODE_SHIFT_LEFT = 59, + AKEYCODE_SHIFT_LEFT = 59, /** Right Shift modifier key. */ - AKEYCODE_SHIFT_RIGHT = 60, + AKEYCODE_SHIFT_RIGHT = 60, /** Tab key. */ - AKEYCODE_TAB = 61, + AKEYCODE_TAB = 61, /** Space key. */ - AKEYCODE_SPACE = 62, + AKEYCODE_SPACE = 62, /** Symbol modifier key. * Used to enter alternate symbols. */ - AKEYCODE_SYM = 63, + AKEYCODE_SYM = 63, /** Explorer special function key. * Used to launch a browser application. */ - AKEYCODE_EXPLORER = 64, + AKEYCODE_EXPLORER = 64, /** Envelope special function key. * Used to launch a mail application. */ - AKEYCODE_ENVELOPE = 65, + AKEYCODE_ENVELOPE = 65, /** Enter key. */ - AKEYCODE_ENTER = 66, + AKEYCODE_ENTER = 66, /** Backspace key. * Deletes characters before the insertion point, unlike {@link AKEYCODE_FORWARD_DEL}. */ - AKEYCODE_DEL = 67, + AKEYCODE_DEL = 67, /** '`' (backtick) key. */ - AKEYCODE_GRAVE = 68, + AKEYCODE_GRAVE = 68, /** '-'. */ - AKEYCODE_MINUS = 69, + AKEYCODE_MINUS = 69, /** '=' key. */ - AKEYCODE_EQUALS = 70, + AKEYCODE_EQUALS = 70, /** '[' key. */ - AKEYCODE_LEFT_BRACKET = 71, + AKEYCODE_LEFT_BRACKET = 71, /** ']' key. */ - AKEYCODE_RIGHT_BRACKET = 72, + AKEYCODE_RIGHT_BRACKET = 72, /** '\' key. */ - AKEYCODE_BACKSLASH = 73, + AKEYCODE_BACKSLASH = 73, /** ';' key. */ - AKEYCODE_SEMICOLON = 74, + AKEYCODE_SEMICOLON = 74, /** ''' (apostrophe) key. */ - AKEYCODE_APOSTROPHE = 75, + AKEYCODE_APOSTROPHE = 75, /** '/' key. */ - AKEYCODE_SLASH = 76, + AKEYCODE_SLASH = 76, /** '@' key. */ - AKEYCODE_AT = 77, + AKEYCODE_AT = 77, /** Number modifier key. * Used to enter numeric symbols. * This key is not {@link AKEYCODE_NUM_LOCK}; it is more like {@link AKEYCODE_ALT_LEFT}. */ - AKEYCODE_NUM = 78, + AKEYCODE_NUM = 78, /** Headset Hook key. * Used to hang up calls and stop media. */ - AKEYCODE_HEADSETHOOK = 79, + AKEYCODE_HEADSETHOOK = 79, /** Camera Focus key. * Used to focus the camera. */ - AKEYCODE_FOCUS = 80, + AKEYCODE_FOCUS = 80, /** '+' key. */ - AKEYCODE_PLUS = 81, + AKEYCODE_PLUS = 81, /** Menu key. */ - AKEYCODE_MENU = 82, + AKEYCODE_MENU = 82, /** Notification key. */ - AKEYCODE_NOTIFICATION = 83, + AKEYCODE_NOTIFICATION = 83, /** Search key. */ - AKEYCODE_SEARCH = 84, + AKEYCODE_SEARCH = 84, /** Play/Pause media key. */ - AKEYCODE_MEDIA_PLAY_PAUSE= 85, + AKEYCODE_MEDIA_PLAY_PAUSE = 85, /** Stop media key. */ - AKEYCODE_MEDIA_STOP = 86, + AKEYCODE_MEDIA_STOP = 86, /** Play Next media key. */ - AKEYCODE_MEDIA_NEXT = 87, + AKEYCODE_MEDIA_NEXT = 87, /** Play Previous media key. */ - AKEYCODE_MEDIA_PREVIOUS = 88, + AKEYCODE_MEDIA_PREVIOUS = 88, /** Rewind media key. */ - AKEYCODE_MEDIA_REWIND = 89, + AKEYCODE_MEDIA_REWIND = 89, /** Fast Forward media key. */ AKEYCODE_MEDIA_FAST_FORWARD = 90, /** Mute key. * Mutes the microphone, unlike {@link AKEYCODE_VOLUME_MUTE}. */ - AKEYCODE_MUTE = 91, + AKEYCODE_MUTE = 91, /** Page Up key. */ - AKEYCODE_PAGE_UP = 92, + AKEYCODE_PAGE_UP = 92, /** Page Down key. */ - AKEYCODE_PAGE_DOWN = 93, + AKEYCODE_PAGE_DOWN = 93, /** Picture Symbols modifier key. * Used to switch symbol sets (Emoji, Kao-moji). */ - AKEYCODE_PICTSYMBOLS = 94, + AKEYCODE_PICTSYMBOLS = 94, /** Switch Charset modifier key. * Used to switch character sets (Kanji, Katakana). */ - AKEYCODE_SWITCH_CHARSET = 95, + AKEYCODE_SWITCH_CHARSET = 95, /** A Button key. * On a game controller, the A button should be either the button labeled A * or the first button on the bottom row of controller buttons. */ - AKEYCODE_BUTTON_A = 96, + AKEYCODE_BUTTON_A = 96, /** B Button key. * On a game controller, the B button should be either the button labeled B * or the second button on the bottom row of controller buttons. */ - AKEYCODE_BUTTON_B = 97, + AKEYCODE_BUTTON_B = 97, /** C Button key. * On a game controller, the C button should be either the button labeled C * or the third button on the bottom row of controller buttons. */ - AKEYCODE_BUTTON_C = 98, + AKEYCODE_BUTTON_C = 98, /** X Button key. * On a game controller, the X button should be either the button labeled X * or the first button on the upper row of controller buttons. */ - AKEYCODE_BUTTON_X = 99, + AKEYCODE_BUTTON_X = 99, /** Y Button key. * On a game controller, the Y button should be either the button labeled Y * or the second button on the upper row of controller buttons. */ - AKEYCODE_BUTTON_Y = 100, + AKEYCODE_BUTTON_Y = 100, /** Z Button key. * On a game controller, the Z button should be either the button labeled Z * or the third button on the upper row of controller buttons. */ - AKEYCODE_BUTTON_Z = 101, + AKEYCODE_BUTTON_Z = 101, /** L1 Button key. * On a game controller, the L1 button should be either the button labeled L1 (or L) * or the top left trigger button. */ - AKEYCODE_BUTTON_L1 = 102, + AKEYCODE_BUTTON_L1 = 102, /** R1 Button key. * On a game controller, the R1 button should be either the button labeled R1 (or R) * or the top right trigger button. */ - AKEYCODE_BUTTON_R1 = 103, + AKEYCODE_BUTTON_R1 = 103, /** L2 Button key. * On a game controller, the L2 button should be either the button labeled L2 * or the bottom left trigger button. */ - AKEYCODE_BUTTON_L2 = 104, + AKEYCODE_BUTTON_L2 = 104, /** R2 Button key. * On a game controller, the R2 button should be either the button labeled R2 * or the bottom right trigger button. */ - AKEYCODE_BUTTON_R2 = 105, + AKEYCODE_BUTTON_R2 = 105, /** Left Thumb Button key. * On a game controller, the left thumb button indicates that the left (or only) * joystick is pressed. */ - AKEYCODE_BUTTON_THUMBL = 106, + AKEYCODE_BUTTON_THUMBL = 106, /** Right Thumb Button key. * On a game controller, the right thumb button indicates that the right * joystick is pressed. */ - AKEYCODE_BUTTON_THUMBR = 107, + AKEYCODE_BUTTON_THUMBR = 107, /** Start Button key. * On a game controller, the button labeled Start. */ - AKEYCODE_BUTTON_START = 108, + AKEYCODE_BUTTON_START = 108, /** Select Button key. * On a game controller, the button labeled Select. */ - AKEYCODE_BUTTON_SELECT = 109, + AKEYCODE_BUTTON_SELECT = 109, /** Mode Button key. * On a game controller, the button labeled Mode. */ - AKEYCODE_BUTTON_MODE = 110, + AKEYCODE_BUTTON_MODE = 110, /** Escape key. */ - AKEYCODE_ESCAPE = 111, + AKEYCODE_ESCAPE = 111, /** Forward Delete key. * Deletes characters ahead of the insertion point, unlike {@link AKEYCODE_DEL}. */ - AKEYCODE_FORWARD_DEL = 112, + AKEYCODE_FORWARD_DEL = 112, /** Left Control modifier key. */ - AKEYCODE_CTRL_LEFT = 113, + AKEYCODE_CTRL_LEFT = 113, /** Right Control modifier key. */ - AKEYCODE_CTRL_RIGHT = 114, + AKEYCODE_CTRL_RIGHT = 114, /** Caps Lock key. */ - AKEYCODE_CAPS_LOCK = 115, + AKEYCODE_CAPS_LOCK = 115, /** Scroll Lock key. */ - AKEYCODE_SCROLL_LOCK = 116, + AKEYCODE_SCROLL_LOCK = 116, /** Left Meta modifier key. */ - AKEYCODE_META_LEFT = 117, + AKEYCODE_META_LEFT = 117, /** Right Meta modifier key. */ - AKEYCODE_META_RIGHT = 118, + AKEYCODE_META_RIGHT = 118, /** Function modifier key. */ - AKEYCODE_FUNCTION = 119, + AKEYCODE_FUNCTION = 119, /** System Request / Print Screen key. */ - AKEYCODE_SYSRQ = 120, + AKEYCODE_SYSRQ = 120, /** Break / Pause key. */ - AKEYCODE_BREAK = 121, + AKEYCODE_BREAK = 121, /** Home Movement key. * Used for scrolling or moving the cursor around to the start of a line * or to the top of a list. */ - AKEYCODE_MOVE_HOME = 122, + AKEYCODE_MOVE_HOME = 122, /** End Movement key. * Used for scrolling or moving the cursor around to the end of a line * or to the bottom of a list. */ - AKEYCODE_MOVE_END = 123, + AKEYCODE_MOVE_END = 123, /** Insert key. * Toggles insert / overwrite edit mode. */ - AKEYCODE_INSERT = 124, + AKEYCODE_INSERT = 124, /** Forward key. * Navigates forward in the history stack. Complement of {@link AKEYCODE_BACK}. */ - AKEYCODE_FORWARD = 125, + AKEYCODE_FORWARD = 125, /** Play media key. */ - AKEYCODE_MEDIA_PLAY = 126, + AKEYCODE_MEDIA_PLAY = 126, /** Pause media key. */ - AKEYCODE_MEDIA_PAUSE = 127, + AKEYCODE_MEDIA_PAUSE = 127, /** Close media key. * May be used to close a CD tray, for example. */ - AKEYCODE_MEDIA_CLOSE = 128, + AKEYCODE_MEDIA_CLOSE = 128, /** Eject media key. * May be used to eject a CD tray, for example. */ - AKEYCODE_MEDIA_EJECT = 129, + AKEYCODE_MEDIA_EJECT = 129, /** Record media key. */ - AKEYCODE_MEDIA_RECORD = 130, + AKEYCODE_MEDIA_RECORD = 130, /** F1 key. */ - AKEYCODE_F1 = 131, + AKEYCODE_F1 = 131, /** F2 key. */ - AKEYCODE_F2 = 132, + AKEYCODE_F2 = 132, /** F3 key. */ - AKEYCODE_F3 = 133, + AKEYCODE_F3 = 133, /** F4 key. */ - AKEYCODE_F4 = 134, + AKEYCODE_F4 = 134, /** F5 key. */ - AKEYCODE_F5 = 135, + AKEYCODE_F5 = 135, /** F6 key. */ - AKEYCODE_F6 = 136, + AKEYCODE_F6 = 136, /** F7 key. */ - AKEYCODE_F7 = 137, + AKEYCODE_F7 = 137, /** F8 key. */ - AKEYCODE_F8 = 138, + AKEYCODE_F8 = 138, /** F9 key. */ - AKEYCODE_F9 = 139, + AKEYCODE_F9 = 139, /** F10 key. */ - AKEYCODE_F10 = 140, + AKEYCODE_F10 = 140, /** F11 key. */ - AKEYCODE_F11 = 141, + AKEYCODE_F11 = 141, /** F12 key. */ - AKEYCODE_F12 = 142, + AKEYCODE_F12 = 142, /** Num Lock key. * This is the Num Lock key; it is different from {@link AKEYCODE_NUM}. * This key alters the behavior of other keys on the numeric keypad. */ - AKEYCODE_NUM_LOCK = 143, + AKEYCODE_NUM_LOCK = 143, /** Numeric keypad '0' key. */ - AKEYCODE_NUMPAD_0 = 144, + AKEYCODE_NUMPAD_0 = 144, /** Numeric keypad '1' key. */ - AKEYCODE_NUMPAD_1 = 145, + AKEYCODE_NUMPAD_1 = 145, /** Numeric keypad '2' key. */ - AKEYCODE_NUMPAD_2 = 146, + AKEYCODE_NUMPAD_2 = 146, /** Numeric keypad '3' key. */ - AKEYCODE_NUMPAD_3 = 147, + AKEYCODE_NUMPAD_3 = 147, /** Numeric keypad '4' key. */ - AKEYCODE_NUMPAD_4 = 148, + AKEYCODE_NUMPAD_4 = 148, /** Numeric keypad '5' key. */ - AKEYCODE_NUMPAD_5 = 149, + AKEYCODE_NUMPAD_5 = 149, /** Numeric keypad '6' key. */ - AKEYCODE_NUMPAD_6 = 150, + AKEYCODE_NUMPAD_6 = 150, /** Numeric keypad '7' key. */ - AKEYCODE_NUMPAD_7 = 151, + AKEYCODE_NUMPAD_7 = 151, /** Numeric keypad '8' key. */ - AKEYCODE_NUMPAD_8 = 152, + AKEYCODE_NUMPAD_8 = 152, /** Numeric keypad '9' key. */ - AKEYCODE_NUMPAD_9 = 153, + AKEYCODE_NUMPAD_9 = 153, /** Numeric keypad '/' key (for division). */ - AKEYCODE_NUMPAD_DIVIDE = 154, + AKEYCODE_NUMPAD_DIVIDE = 154, /** Numeric keypad '*' key (for multiplication). */ AKEYCODE_NUMPAD_MULTIPLY = 155, /** Numeric keypad '-' key (for subtraction). */ AKEYCODE_NUMPAD_SUBTRACT = 156, /** Numeric keypad '+' key (for addition). */ - AKEYCODE_NUMPAD_ADD = 157, + AKEYCODE_NUMPAD_ADD = 157, /** Numeric keypad '.' key (for decimals or digit grouping). */ - AKEYCODE_NUMPAD_DOT = 158, + AKEYCODE_NUMPAD_DOT = 158, /** Numeric keypad ',' key (for decimals or digit grouping). */ - AKEYCODE_NUMPAD_COMMA = 159, + AKEYCODE_NUMPAD_COMMA = 159, /** Numeric keypad Enter key. */ - AKEYCODE_NUMPAD_ENTER = 160, + AKEYCODE_NUMPAD_ENTER = 160, /** Numeric keypad '=' key. */ - AKEYCODE_NUMPAD_EQUALS = 161, + AKEYCODE_NUMPAD_EQUALS = 161, /** Numeric keypad '(' key. */ AKEYCODE_NUMPAD_LEFT_PAREN = 162, /** Numeric keypad ')' key. */ @@ -420,107 +421,107 @@ enum AndroidKeycode { * Mutes the speaker, unlike {@link AKEYCODE_MUTE}. * This key should normally be implemented as a toggle such that the first press * mutes the speaker and the second press restores the original volume. */ - AKEYCODE_VOLUME_MUTE = 164, + AKEYCODE_VOLUME_MUTE = 164, /** Info key. * Common on TV remotes to show additional information related to what is * currently being viewed. */ - AKEYCODE_INFO = 165, + AKEYCODE_INFO = 165, /** Channel up key. * On TV remotes, increments the television channel. */ - AKEYCODE_CHANNEL_UP = 166, + AKEYCODE_CHANNEL_UP = 166, /** Channel down key. * On TV remotes, decrements the television channel. */ - AKEYCODE_CHANNEL_DOWN = 167, + AKEYCODE_CHANNEL_DOWN = 167, /** Zoom in key. */ - AKEYCODE_ZOOM_IN = 168, + AKEYCODE_ZOOM_IN = 168, /** Zoom out key. */ - AKEYCODE_ZOOM_OUT = 169, + AKEYCODE_ZOOM_OUT = 169, /** TV key. * On TV remotes, switches to viewing live TV. */ - AKEYCODE_TV = 170, + AKEYCODE_TV = 170, /** Window key. * On TV remotes, toggles picture-in-picture mode or other windowing functions. */ - AKEYCODE_WINDOW = 171, + AKEYCODE_WINDOW = 171, /** Guide key. * On TV remotes, shows a programming guide. */ - AKEYCODE_GUIDE = 172, + AKEYCODE_GUIDE = 172, /** DVR key. * On some TV remotes, switches to a DVR mode for recorded shows. */ - AKEYCODE_DVR = 173, + AKEYCODE_DVR = 173, /** Bookmark key. * On some TV remotes, bookmarks content or web pages. */ - AKEYCODE_BOOKMARK = 174, + AKEYCODE_BOOKMARK = 174, /** Toggle captions key. * Switches the mode for closed-captioning text, for example during television shows. */ - AKEYCODE_CAPTIONS = 175, + AKEYCODE_CAPTIONS = 175, /** Settings key. * Starts the system settings activity. */ - AKEYCODE_SETTINGS = 176, + AKEYCODE_SETTINGS = 176, /** TV power key. * On TV remotes, toggles the power on a television screen. */ - AKEYCODE_TV_POWER = 177, + AKEYCODE_TV_POWER = 177, /** TV input key. * On TV remotes, switches the input on a television screen. */ - AKEYCODE_TV_INPUT = 178, + AKEYCODE_TV_INPUT = 178, /** Set-top-box power key. * On TV remotes, toggles the power on an external Set-top-box. */ - AKEYCODE_STB_POWER = 179, + AKEYCODE_STB_POWER = 179, /** Set-top-box input key. * On TV remotes, switches the input mode on an external Set-top-box. */ - AKEYCODE_STB_INPUT = 180, + AKEYCODE_STB_INPUT = 180, /** A/V Receiver power key. * On TV remotes, toggles the power on an external A/V Receiver. */ - AKEYCODE_AVR_POWER = 181, + AKEYCODE_AVR_POWER = 181, /** A/V Receiver input key. * On TV remotes, switches the input mode on an external A/V Receiver. */ - AKEYCODE_AVR_INPUT = 182, + AKEYCODE_AVR_INPUT = 182, /** Red "programmable" key. * On TV remotes, acts as a contextual/programmable key. */ - AKEYCODE_PROG_RED = 183, + AKEYCODE_PROG_RED = 183, /** Green "programmable" key. * On TV remotes, actsas a contextual/programmable key. */ - AKEYCODE_PROG_GREEN = 184, + AKEYCODE_PROG_GREEN = 184, /** Yellow "programmable" key. * On TV remotes, acts as a contextual/programmable key. */ - AKEYCODE_PROG_YELLOW = 185, + AKEYCODE_PROG_YELLOW = 185, /** Blue "programmable" key. * On TV remotes, acts as a contextual/programmable key. */ - AKEYCODE_PROG_BLUE = 186, + AKEYCODE_PROG_BLUE = 186, /** App switch key. * Should bring up the application switcher dialog. */ - AKEYCODE_APP_SWITCH = 187, + AKEYCODE_APP_SWITCH = 187, /** Generic Game Pad Button #1.*/ - AKEYCODE_BUTTON_1 = 188, + AKEYCODE_BUTTON_1 = 188, /** Generic Game Pad Button #2.*/ - AKEYCODE_BUTTON_2 = 189, + AKEYCODE_BUTTON_2 = 189, /** Generic Game Pad Button #3.*/ - AKEYCODE_BUTTON_3 = 190, + AKEYCODE_BUTTON_3 = 190, /** Generic Game Pad Button #4.*/ - AKEYCODE_BUTTON_4 = 191, + AKEYCODE_BUTTON_4 = 191, /** Generic Game Pad Button #5.*/ - AKEYCODE_BUTTON_5 = 192, + AKEYCODE_BUTTON_5 = 192, /** Generic Game Pad Button #6.*/ - AKEYCODE_BUTTON_6 = 193, + AKEYCODE_BUTTON_6 = 193, /** Generic Game Pad Button #7.*/ - AKEYCODE_BUTTON_7 = 194, + AKEYCODE_BUTTON_7 = 194, /** Generic Game Pad Button #8.*/ - AKEYCODE_BUTTON_8 = 195, + AKEYCODE_BUTTON_8 = 195, /** Generic Game Pad Button #9.*/ - AKEYCODE_BUTTON_9 = 196, + AKEYCODE_BUTTON_9 = 196, /** Generic Game Pad Button #10.*/ - AKEYCODE_BUTTON_10 = 197, + AKEYCODE_BUTTON_10 = 197, /** Generic Game Pad Button #11.*/ - AKEYCODE_BUTTON_11 = 198, + AKEYCODE_BUTTON_11 = 198, /** Generic Game Pad Button #12.*/ - AKEYCODE_BUTTON_12 = 199, + AKEYCODE_BUTTON_12 = 199, /** Generic Game Pad Button #13.*/ - AKEYCODE_BUTTON_13 = 200, + AKEYCODE_BUTTON_13 = 200, /** Generic Game Pad Button #14.*/ - AKEYCODE_BUTTON_14 = 201, + AKEYCODE_BUTTON_14 = 201, /** Generic Game Pad Button #15.*/ - AKEYCODE_BUTTON_15 = 202, + AKEYCODE_BUTTON_15 = 202, /** Generic Game Pad Button #16.*/ - AKEYCODE_BUTTON_16 = 203, + AKEYCODE_BUTTON_16 = 203, /** Language Switch key. * Toggles the current input language such as switching between English and Japanese on * a QWERTY keyboard. On some devices, the same function may be performed by @@ -530,85 +531,85 @@ enum AndroidKeycode { * Toggles silent or vibrate mode on and off to make the device behave more politely * in certain settings such as on a crowded train. On some devices, the key may only * operate when long-pressed. */ - AKEYCODE_MANNER_MODE = 205, + AKEYCODE_MANNER_MODE = 205, /** 3D Mode key. * Toggles the display between 2D and 3D mode. */ - AKEYCODE_3D_MODE = 206, + AKEYCODE_3D_MODE = 206, /** Contacts special function key. * Used to launch an address book application. */ - AKEYCODE_CONTACTS = 207, + AKEYCODE_CONTACTS = 207, /** Calendar special function key. * Used to launch a calendar application. */ - AKEYCODE_CALENDAR = 208, + AKEYCODE_CALENDAR = 208, /** Music special function key. * Used to launch a music player application. */ - AKEYCODE_MUSIC = 209, + AKEYCODE_MUSIC = 209, /** Calculator special function key. * Used to launch a calculator application. */ - AKEYCODE_CALCULATOR = 210, + AKEYCODE_CALCULATOR = 210, /** Japanese full-width / half-width key. */ AKEYCODE_ZENKAKU_HANKAKU = 211, /** Japanese alphanumeric key. */ - AKEYCODE_EISU = 212, + AKEYCODE_EISU = 212, /** Japanese non-conversion key. */ - AKEYCODE_MUHENKAN = 213, + AKEYCODE_MUHENKAN = 213, /** Japanese conversion key. */ - AKEYCODE_HENKAN = 214, + AKEYCODE_HENKAN = 214, /** Japanese katakana / hiragana key. */ AKEYCODE_KATAKANA_HIRAGANA = 215, /** Japanese Yen key. */ - AKEYCODE_YEN = 216, + AKEYCODE_YEN = 216, /** Japanese Ro key. */ - AKEYCODE_RO = 217, + AKEYCODE_RO = 217, /** Japanese kana key. */ - AKEYCODE_KANA = 218, + AKEYCODE_KANA = 218, /** Assist key. * Launches the global assist activity. Not delivered to applications. */ - AKEYCODE_ASSIST = 219, + AKEYCODE_ASSIST = 219, /** Brightness Down key. * Adjusts the screen brightness down. */ AKEYCODE_BRIGHTNESS_DOWN = 220, /** Brightness Up key. * Adjusts the screen brightness up. */ - AKEYCODE_BRIGHTNESS_UP = 221, + AKEYCODE_BRIGHTNESS_UP = 221, /** Audio Track key. * Switches the audio tracks. */ AKEYCODE_MEDIA_AUDIO_TRACK = 222, /** Sleep key. * Puts the device to sleep. Behaves somewhat like {@link AKEYCODE_POWER} but it * has no effect if the device is already asleep. */ - AKEYCODE_SLEEP = 223, + AKEYCODE_SLEEP = 223, /** Wakeup key. * Wakes up the device. Behaves somewhat like {@link AKEYCODE_POWER} but it * has no effect if the device is already awake. */ - AKEYCODE_WAKEUP = 224, + AKEYCODE_WAKEUP = 224, /** Pairing key. * Initiates peripheral pairing mode. Useful for pairing remote control * devices or game controllers, especially if no other input mode is * available. */ - AKEYCODE_PAIRING = 225, + AKEYCODE_PAIRING = 225, /** Media Top Menu key. * Goes to the top of media menu. */ - AKEYCODE_MEDIA_TOP_MENU = 226, + AKEYCODE_MEDIA_TOP_MENU = 226, /** '11' key. */ - AKEYCODE_11 = 227, + AKEYCODE_11 = 227, /** '12' key. */ - AKEYCODE_12 = 228, + AKEYCODE_12 = 228, /** Last Channel key. * Goes to the last viewed channel. */ - AKEYCODE_LAST_CHANNEL = 229, + AKEYCODE_LAST_CHANNEL = 229, /** TV data service key. * Displays data services like weather, sports. */ AKEYCODE_TV_DATA_SERVICE = 230, /** Voice Assist key. * Launches the global voice assist activity. Not delivered to applications. */ - AKEYCODE_VOICE_ASSIST = 231, + AKEYCODE_VOICE_ASSIST = 231, /** Radio key. * Toggles TV service / Radio service. */ AKEYCODE_TV_RADIO_SERVICE = 232, /** Teletext key. * Displays Teletext service. */ - AKEYCODE_TV_TELETEXT = 233, + AKEYCODE_TV_TELETEXT = 233, /** Number entry key. * Initiates to enter multi-digit channel nubmber when each digit key is assigned * for selecting separate channel. Corresponds to Number Entry Mode (0x1D) of CEC @@ -622,7 +623,7 @@ enum AndroidKeycode { AKEYCODE_TV_TERRESTRIAL_DIGITAL = 236, /** Satellite key. * Switches to digital satellite broadcast service. */ - AKEYCODE_TV_SATELLITE = 237, + AKEYCODE_TV_SATELLITE = 237, /** BS key. * Switches to BS digital satellite broadcasting service available in Japan. */ AKEYCODE_TV_SATELLITE_BS = 238, @@ -634,7 +635,7 @@ enum AndroidKeycode { AKEYCODE_TV_SATELLITE_SERVICE = 240, /** Toggle Network key. * Toggles selecting broacast services. */ - AKEYCODE_TV_NETWORK = 241, + AKEYCODE_TV_NETWORK = 241, /** Antenna/Cable key. * Toggles broadcast input source between antenna and cable. */ AKEYCODE_TV_ANTENNA_CABLE = 242, @@ -664,7 +665,7 @@ enum AndroidKeycode { AKEYCODE_TV_INPUT_COMPONENT_2 = 250, /** VGA #1 key. * Switches to VGA (analog RGB) input #1. */ - AKEYCODE_TV_INPUT_VGA_1 = 251, + AKEYCODE_TV_INPUT_VGA_1 = 251, /** Audio description key. * Toggles audio description off / on. */ AKEYCODE_TV_AUDIO_DESCRIPTION = 252, @@ -676,7 +677,7 @@ enum AndroidKeycode { AKEYCODE_TV_AUDIO_DESCRIPTION_MIX_DOWN = 254, /** Zoom mode key. * Changes Zoom mode (Normal, Full, Zoom, Wide-zoom, etc.) */ - AKEYCODE_TV_ZOOM_MODE = 255, + AKEYCODE_TV_ZOOM_MODE = 255, /** Contents menu key. * Goes to the title list. Corresponds to Contents Menu (0x0B) of CEC User Control * Code */ @@ -690,11 +691,11 @@ enum AndroidKeycode { * CEC User Control Code. */ AKEYCODE_TV_TIMER_PROGRAMMING = 258, /** Help key. */ - AKEYCODE_HELP = 259, + AKEYCODE_HELP = 259, AKEYCODE_NAVIGATE_PREVIOUS = 260, - AKEYCODE_NAVIGATE_NEXT = 261, - AKEYCODE_NAVIGATE_IN = 262, - AKEYCODE_NAVIGATE_OUT = 263, + AKEYCODE_NAVIGATE_NEXT = 261, + AKEYCODE_NAVIGATE_IN = 262, + AKEYCODE_NAVIGATE_OUT = 263, /** Primary stem key for Wear * Main power/reset button on watch. */ AKEYCODE_STEM_PRIMARY = 264, @@ -705,11 +706,11 @@ enum AndroidKeycode { /** Generic stem key 3 for Wear */ AKEYCODE_STEM_3 = 267, /** Directional Pad Up-Left */ - AKEYCODE_DPAD_UP_LEFT = 268, + AKEYCODE_DPAD_UP_LEFT = 268, /** Directional Pad Down-Left */ - AKEYCODE_DPAD_DOWN_LEFT = 269, + AKEYCODE_DPAD_DOWN_LEFT = 269, /** Directional Pad Up-Right */ - AKEYCODE_DPAD_UP_RIGHT = 270, + AKEYCODE_DPAD_UP_RIGHT = 270, /** Directional Pad Down-Right */ AKEYCODE_DPAD_DOWN_RIGHT = 271, /** Skip forward media key */ diff --git a/QtScrcpy/device/controller/controller.cpp b/QtScrcpy/device/controller/controller.cpp index 8418109..c47efc6 100644 --- a/QtScrcpy/device/controller/controller.cpp +++ b/QtScrcpy/device/controller/controller.cpp @@ -2,12 +2,12 @@ #include #include "controller.h" -#include "videosocket.h" #include "controlmsg.h" -#include "receiver.h" #include "inputconvertgame.h" +#include "receiver.h" +#include "videosocket.h" -Controller::Controller(QString gameScript, QObject* parent) : QObject(parent) +Controller::Controller(QString gameScript, QObject *parent) : QObject(parent) { m_receiver = new Receiver(this); Q_ASSERT(m_receiver); @@ -15,12 +15,9 @@ Controller::Controller(QString gameScript, QObject* parent) : QObject(parent) updateScript(gameScript); } -Controller::~Controller() -{ +Controller::~Controller() {} -} - -void Controller::setControlSocket(QTcpSocket* controlSocket) +void Controller::setControlSocket(QTcpSocket *controlSocket) { if (m_controlSocket || !controlSocket) { return; @@ -38,11 +35,8 @@ void Controller::postControlMsg(ControlMsg *controlMsg) void Controller::test(QRect 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); + 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); } @@ -52,11 +46,11 @@ void Controller::updateScript(QString gameScript) delete m_inputConvert; } if (!gameScript.isEmpty()) { - InputConvertGame* convertgame = new InputConvertGame(this); + InputConvertGame *convertgame = new InputConvertGame(this); convertgame->loadKeyMap(gameScript); - m_inputConvert = convertgame; + m_inputConvert = convertgame; } else { - m_inputConvert = new InputConvertNormal(this); + m_inputConvert = new InputConvertNormal(this); } Q_ASSERT(m_inputConvert); connect(m_inputConvert, &InputConvertBase::grabCursor, this, &Controller::grabCursor); @@ -64,7 +58,7 @@ void Controller::updateScript(QString gameScript) void Controller::onPostBackOrScreenOn() { - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_BACK_OR_SCREEN_ON); + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_BACK_OR_SCREEN_ON); if (!controlMsg) { return; } @@ -108,7 +102,7 @@ void Controller::onPostVolumeDown() void Controller::onExpandNotificationPanel() { - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_EXPAND_NOTIFICATION_PANEL); + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_EXPAND_NOTIFICATION_PANEL); if (!controlMsg) { return; } @@ -117,7 +111,7 @@ void Controller::onExpandNotificationPanel() void Controller::onCollapseNotificationPanel() { - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_COLLAPSE_NOTIFICATION_PANEL); + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_COLLAPSE_NOTIFICATION_PANEL); if (!controlMsg) { return; } @@ -126,7 +120,7 @@ void Controller::onCollapseNotificationPanel() void Controller::onRequestDeviceClipboard() { - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_GET_CLIPBOARD); + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_GET_CLIPBOARD); if (!controlMsg) { return; } @@ -137,7 +131,7 @@ void Controller::onSetDeviceClipboard() { QClipboard *board = QApplication::clipboard(); QString text = board->text(); - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_SET_CLIPBOARD); + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_SET_CLIPBOARD); if (!controlMsg) { return; } @@ -152,9 +146,9 @@ void Controller::onClipboardPaste() onPostTextInput(text); } -void Controller::onPostTextInput(QString& text) +void Controller::onPostTextInput(QString &text) { - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TEXT); + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TEXT); if (!controlMsg) { return; } @@ -164,7 +158,7 @@ void Controller::onPostTextInput(QString& text) void Controller::onSetScreenPowerMode(ControlMsg::ScreenPowerMode mode) { - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_SET_SCREEN_POWER_MODE); + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_SET_SCREEN_POWER_MODE); if (!controlMsg) { return; } @@ -196,7 +190,7 @@ void Controller::onKeyEvent(const QKeyEvent *from, const QSize &frameSize, const bool Controller::event(QEvent *event) { if (event && static_cast(event->type()) == ControlMsg::Control) { - ControlMsg* controlMsg = dynamic_cast(event); + ControlMsg *controlMsg = dynamic_cast(event); if (controlMsg) { sendControl(controlMsg->serializeData()); } @@ -219,14 +213,14 @@ bool Controller::sendControl(const QByteArray &buffer) void Controller::postKeyCodeClick(AndroidKeycode keycode) { - ControlMsg* controlEventDown = new ControlMsg(ControlMsg::CMT_INJECT_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); + ControlMsg *controlEventUp = new ControlMsg(ControlMsg::CMT_INJECT_KEYCODE); if (!controlEventUp) { return; } diff --git a/QtScrcpy/device/controller/controller.h b/QtScrcpy/device/controller/controller.h index cf11610..ca19b77 100644 --- a/QtScrcpy/device/controller/controller.h +++ b/QtScrcpy/device/controller/controller.h @@ -13,11 +13,11 @@ class Controller : public QObject { Q_OBJECT public: - Controller(QString gameScript = "", QObject* parent = Q_NULLPTR); + Controller(QString gameScript = "", QObject *parent = Q_NULLPTR); virtual ~Controller(); - void setControlSocket(QTcpSocket* controlSocket); - void postControlMsg(ControlMsg* controlMsg); + void setControlSocket(QTcpSocket *controlSocket); + void postControlMsg(ControlMsg *controlMsg); void test(QRect rc); void updateScript(QString gameScript = ""); @@ -35,16 +35,16 @@ public slots: void onSetScreenPowerMode(ControlMsg::ScreenPowerMode mode); // for input convert - void onMouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); - void onWheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); - void onKeyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize); + void onMouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize); + void onWheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize); + void onKeyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize); // turn the screen on if it was off, press BACK otherwise void onPostBackOrScreenOn(); void onRequestDeviceClipboard(); void onSetDeviceClipboard(); void onClipboardPaste(); - void onPostTextInput(QString& text); + void onPostTextInput(QString &text); signals: void grabCursor(bool grab); @@ -53,8 +53,8 @@ protected: bool event(QEvent *event); private: - bool sendControl(const QByteArray& buffer); - void postKeyCodeClick(AndroidKeycode keycode); + bool sendControl(const QByteArray &buffer); + void postKeyCodeClick(AndroidKeycode keycode); private: QPointer m_controlSocket; diff --git a/QtScrcpy/device/controller/inputconvert/controlmsg.cpp b/QtScrcpy/device/controller/inputconvert/controlmsg.cpp index 48973b9..fa6444d 100644 --- a/QtScrcpy/device/controller/inputconvert/controlmsg.cpp +++ b/QtScrcpy/device/controller/inputconvert/controlmsg.cpp @@ -1,22 +1,19 @@ #include -#include "controlmsg.h" #include "bufferutil.h" +#include "controlmsg.h" -ControlMsg::ControlMsg(ControlMsgType controlMsgType) - : QScrcpyEvent(Control) +ControlMsg::ControlMsg(ControlMsgType controlMsgType) : QScrcpyEvent(Control) { m_data.type = controlMsgType; } ControlMsg::~ControlMsg() { - if (CMT_SET_CLIPBOARD == m_data.type - && Q_NULLPTR != m_data.setClipboard.text) { + if (CMT_SET_CLIPBOARD == m_data.type && Q_NULLPTR != m_data.setClipboard.text) { delete m_data.setClipboard.text; m_data.setClipboard.text = Q_NULLPTR; - } else if (CMT_INJECT_TEXT == m_data.type - && Q_NULLPTR != m_data.injectText.text){ + } else if (CMT_INJECT_TEXT == m_data.type && Q_NULLPTR != m_data.injectText.text) { delete m_data.injectText.text; m_data.injectText.text = Q_NULLPTR; } @@ -29,7 +26,7 @@ void ControlMsg::setInjectKeycodeMsgData(AndroidKeyeventAction action, AndroidKe m_data.injectKeycode.metastate = metastate; } -void ControlMsg::setInjectTextMsgData(QString& text) +void ControlMsg::setInjectTextMsgData(QString &text) { // write length (2 byte) + string (non nul-terminated) if (CONTROL_MSG_TEXT_MAX_LENGTH < text.length()) { @@ -78,7 +75,7 @@ void ControlMsg::setSetScreenPowerModeData(ControlMsg::ScreenPowerMode mode) m_data.setScreenPowerMode.mode = mode; } -void ControlMsg::writePosition(QBuffer &buffer, const QRect& value) +void ControlMsg::writePosition(QBuffer &buffer, const QRect &value) { BufferUtil::write32(buffer, value.left()); BufferUtil::write32(buffer, value.top()); @@ -93,7 +90,7 @@ quint16 ControlMsg::toFixedPoint16(float f) if (u >= 0xffff) { u = 0xffff; } - return (quint16) u; + return (quint16)u; } QByteArray ControlMsg::serializeData() @@ -113,16 +110,14 @@ 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_TOUCH: - { + case CMT_INJECT_TOUCH: { 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; + } break; case CMT_INJECT_SCROLL: writePosition(buffer, m_data.injectScroll.position); BufferUtil::write32(buffer, m_data.injectScroll.hScroll); diff --git a/QtScrcpy/device/controller/inputconvert/controlmsg.h b/QtScrcpy/device/controller/inputconvert/controlmsg.h index 5a2a547..2dc4267 100644 --- a/QtScrcpy/device/controller/inputconvert/controlmsg.h +++ b/QtScrcpy/device/controller/inputconvert/controlmsg.h @@ -1,13 +1,13 @@ #ifndef CONTROLMSG_H #define CONTROLMSG_H +#include #include #include -#include -#include "qscrcpyevent.h" #include "input.h" #include "keycodes.h" +#include "qscrcpyevent.h" #define CONTROL_MSG_TEXT_MAX_LENGTH 300 #define CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH 4093 @@ -15,8 +15,9 @@ // ControlMsg class ControlMsg : public QScrcpyEvent { -public: - enum ControlMsgType { +public: + enum ControlMsgType + { CMT_NULL = -1, CMT_INJECT_KEYCODE = 0, CMT_INJECT_TEXT, @@ -30,7 +31,8 @@ public: CMT_SET_SCREEN_POWER_MODE }; - enum ScreenPowerMode { + enum ScreenPowerMode + { // see SPM_OFF = 0, SPM_NORMAL = 2, @@ -40,55 +42,63 @@ public: virtual ~ControlMsg(); void setInjectKeycodeMsgData(AndroidKeyeventAction action, AndroidKeycode keycode, AndroidMetastate metastate); - void setInjectTextMsgData(QString& text); + void setInjectTextMsgData(QString &text); // id 代表一个触摸点,最多支持10个触摸点[0,9] // action 只能是AMOTION_EVENT_ACTION_DOWN,AMOTION_EVENT_ACTION_UP,AMOTION_EVENT_ACTION_MOVE // position action动作对应的位置 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 setSetClipboardMsgData(QString &text); void setSetScreenPowerModeData(ControlMsg::ScreenPowerMode mode); QByteArray serializeData(); -private: - void writePosition(QBuffer& buffer, const QRect& value); +private: + void writePosition(QBuffer &buffer, const QRect &value); quint16 toFixedPoint16(float f); private: - struct ControlMsgData { + struct ControlMsgData + { ControlMsgType type = CMT_NULL; - union { - struct { + union + { + struct + { AndroidKeyeventAction action; AndroidKeycode keycode; AndroidMetastate metastate; } injectKeycode; - struct { - char* text = Q_NULLPTR; + struct + { + char *text = Q_NULLPTR; } injectText; - struct { + struct + { quint64 id; AndroidMotioneventAction action; AndroidMotioneventButtons buttons; QRect position; float pressure; } injectTouch; - struct { + struct + { QRect position; qint32 hScroll; qint32 vScroll; } injectScroll; - struct { + struct + { char *text = Q_NULLPTR; } setClipboard; - struct { + struct + { ScreenPowerMode mode; } setScreenPowerMode; }; - ControlMsgData(){} - ~ControlMsgData(){} + ControlMsgData() {} + ~ControlMsgData() {} }; ControlMsgData m_data; diff --git a/QtScrcpy/device/controller/inputconvert/inputconvertbase.cpp b/QtScrcpy/device/controller/inputconvert/inputconvertbase.cpp index c95456d..25203be 100644 --- a/QtScrcpy/device/controller/inputconvert/inputconvertbase.cpp +++ b/QtScrcpy/device/controller/inputconvert/inputconvertbase.cpp @@ -1,17 +1,12 @@ #include "inputconvertbase.h" #include "controller.h" -InputConvertBase::InputConvertBase(Controller* controller) - : QObject(controller) - , m_controller(controller) +InputConvertBase::InputConvertBase(Controller *controller) : QObject(controller), m_controller(controller) { Q_ASSERT(controller); } -InputConvertBase::~InputConvertBase() -{ - -} +InputConvertBase::~InputConvertBase() {} void InputConvertBase::sendControlMsg(ControlMsg *msg) { @@ -19,4 +14,3 @@ void InputConvertBase::sendControlMsg(ControlMsg *msg) m_controller->postControlMsg(msg); } } - diff --git a/QtScrcpy/device/controller/inputconvert/inputconvertbase.h b/QtScrcpy/device/controller/inputconvert/inputconvertbase.h index 53f8d1a..6cc28cf 100644 --- a/QtScrcpy/device/controller/inputconvert/inputconvertbase.h +++ b/QtScrcpy/device/controller/inputconvert/inputconvertbase.h @@ -1,10 +1,10 @@ #ifndef INPUTCONVERTBASE_H #define INPUTCONVERTBASE_H -#include -#include #include +#include #include +#include #include "controlmsg.h" @@ -13,20 +13,20 @@ class InputConvertBase : public QObject { Q_OBJECT public: - InputConvertBase(Controller* controller); + InputConvertBase(Controller *controller); virtual ~InputConvertBase(); // the frame size may be different from the real device size, so we need the size // to which the absolute position apply, to scale it accordingly - virtual void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize) = 0; - virtual void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize) = 0; - virtual void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize) = 0; + virtual void mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize) = 0; + virtual void wheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize) = 0; + virtual void keyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize) = 0; signals: void grabCursor(bool grab); protected: - void sendControlMsg(ControlMsg* msg); + void sendControlMsg(ControlMsg *msg); private: QPointer m_controller; diff --git a/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp b/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp index 4bc3831..739d0e2 100644 --- a/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp +++ b/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp @@ -6,16 +6,9 @@ #define CURSOR_POS_CHECK 50 -InputConvertGame::InputConvertGame(Controller* controller) - : InputConvertNormal(controller) -{ +InputConvertGame::InputConvertGame(Controller *controller) : InputConvertNormal(controller) {} -} - -InputConvertGame::~InputConvertGame() -{ - -} +InputConvertGame::~InputConvertGame() {} void InputConvertGame::mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize) { @@ -55,7 +48,7 @@ void InputConvertGame::wheelEvent(const QWheelEvent *from, const QSize &frameSiz } } -void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, const QSize& showSize) +void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize) { // 处理开关按键 if (m_keyMap.isSwitchOnKeyboard() && m_keyMap.getSwitchKey() == from->key()) { @@ -68,11 +61,9 @@ void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, c return; } - const KeyMap::KeyMapNode& node = m_keyMap.getKeyMapNodeKey(from->key()); + const KeyMap::KeyMapNode &node = m_keyMap.getKeyMapNodeKey(from->key()); // 处理特殊按键:可以在按键映射和普通映射间切换的按键 - if (m_needSwitchGameAgain - && KeyMap::KMT_CLICK == node.type - && node.data.click.switchMap) { + if (m_needSwitchGameAgain && KeyMap::KMT_CLICK == node.type && node.data.click.switchMap) { updateSize(frameSize, showSize); // Qt::Key_Tab Qt::Key_M for PUBG mobile processKeyClick(node.data.click.keyNode.pos, false, node.data.click.switchMap, from); @@ -142,20 +133,17 @@ void InputConvertGame::sendTouchUpEvent(int id, QPointF pos) void InputConvertGame::sendTouchEvent(int id, QPointF pos, AndroidMotioneventAction action) { - if (0 > id || MULTI_TOUCH_MAX_NUM-1 < id) { + if (0 > id || MULTI_TOUCH_MAX_NUM - 1 < id) { Q_ASSERT(0); return; } //qDebug() << "id:" << id << " pos:" << pos << " action" << action; - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TOUCH); + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TOUCH); if (!controlMsg) { return; } - controlMsg->setInjectTouchMsgData(static_cast(id), - action, - static_cast(0), - QRect(calcFrameAbsolutePos(pos).toPoint(),m_frameSize), - 1.0f); + controlMsg->setInjectTouchMsgData( + static_cast(id), action, static_cast(0), QRect(calcFrameAbsolutePos(pos).toPoint(), m_frameSize), 1.0f); sendControlMsg(controlMsg); } @@ -244,7 +232,7 @@ void InputConvertGame::processSteerWheel(const KeyMap::KeyMapNode &node, const Q } // action - if(pressedNum == 0){ + if (pressedNum == 0) { // touch up release all int id = getTouchID(m_ctrlSteerWheel.touchKey); sendTouchUpEvent(id, node.data.steerWheel.centerPos + m_ctrlSteerWheel.lastOffset); @@ -268,8 +256,7 @@ void InputConvertGame::processSteerWheel(const KeyMap::KeyMapNode &node, const Q // -------- key event -------- -void InputConvertGame::processKeyClick( - const QPointF& clickPos, bool clickTwice, bool switchMap, const QKeyEvent *from) +void InputConvertGame::processKeyClick(const QPointF &clickPos, bool clickTwice, bool switchMap, const QKeyEvent *from) { if (switchMap && QEvent::KeyRelease == from->type()) { m_needSwitchGameAgain = !m_needSwitchGameAgain; @@ -293,9 +280,9 @@ void InputConvertGame::processKeyClick( } } -void InputConvertGame::processKeyDrag(const QPointF& startPos, QPointF endPos, const QKeyEvent* from) +void InputConvertGame::processKeyDrag(const QPointF &startPos, QPointF endPos, const QKeyEvent *from) { - if (QEvent::KeyPress == from->type()){ + if (QEvent::KeyPress == from->type()) { int id = attachTouchID(from->key()); sendTouchDownEvent(id, startPos); sendTouchMoveEvent(id, endPos); @@ -312,7 +299,7 @@ void InputConvertGame::processKeyDrag(const QPointF& startPos, QPointF endPos, c bool InputConvertGame::processMouseClick(const QMouseEvent *from) { - const KeyMap::KeyMapNode& node = m_keyMap.getKeyMapNodeMouse(from->button()); + const KeyMap::KeyMapNode &node = m_keyMap.getKeyMapNodeMouse(from->button()); if (KeyMap::KMT_INVALID == node.type) { return false; } @@ -353,10 +340,8 @@ bool InputConvertGame::processMouseMove(const QMouseEvent *from) m_ctrlMouseMove.lastConverPos.setX(m_ctrlMouseMove.lastConverPos.x() + distance.x() / m_showSize.width()); m_ctrlMouseMove.lastConverPos.setY(m_ctrlMouseMove.lastConverPos.y() + distance.y() / m_showSize.height()); - if (m_ctrlMouseMove.lastConverPos.x() < 0.1 - || m_ctrlMouseMove.lastConverPos.x() > 0.8 - || m_ctrlMouseMove.lastConverPos.y() < 0.1 - || m_ctrlMouseMove.lastConverPos.y() > 0.8) { + if (m_ctrlMouseMove.lastConverPos.x() < 0.1 || m_ctrlMouseMove.lastConverPos.x() > 0.8 || m_ctrlMouseMove.lastConverPos.y() < 0.1 + || m_ctrlMouseMove.lastConverPos.y() > 0.8) { mouseMoveStopTouch(); mouseMoveStartTouch(from); } @@ -401,7 +386,7 @@ void InputConvertGame::moveCursorTo(const QMouseEvent *from, const QPoint &local QCursor::setPos(globalPos); } -void InputConvertGame::mouseMoveStartTouch(const QMouseEvent* from) +void InputConvertGame::mouseMoveStartTouch(const QMouseEvent *from) { Q_UNUSED(from) if (!m_ctrlMouseMove.touching) { diff --git a/QtScrcpy/device/controller/inputconvert/inputconvertgame.h b/QtScrcpy/device/controller/inputconvert/inputconvertgame.h index 1e32813..c684717 100644 --- a/QtScrcpy/device/controller/inputconvert/inputconvertgame.h +++ b/QtScrcpy/device/controller/inputconvert/inputconvertgame.h @@ -11,17 +11,17 @@ class InputConvertGame : public InputConvertNormal { Q_OBJECT public: - InputConvertGame(Controller* controller); + InputConvertGame(Controller *controller); virtual ~InputConvertGame(); - virtual void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); - virtual void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); - virtual void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize); + virtual void mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize); + virtual void wheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize); + virtual void keyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize); - void loadKeyMap(const QString& json); + void loadKeyMap(const QString &json); protected: - void updateSize(const QSize& frameSize, const QSize& showSize); + void updateSize(const QSize &frameSize, const QSize &showSize); void sendTouchDownEvent(int id, QPointF pos); void sendTouchMoveEvent(int id, QPointF pos); void sendTouchUpEvent(int id, QPointF pos); @@ -35,19 +35,19 @@ protected: int getTouchID(int key); // steer wheel - void processSteerWheel(const KeyMap::KeyMapNode &node, const QKeyEvent* from); + void processSteerWheel(const KeyMap::KeyMapNode &node, const QKeyEvent *from); // click - void processKeyClick(const QPointF& clickPos, bool clickTwice, bool switchMap, const QKeyEvent* from); + void processKeyClick(const QPointF &clickPos, bool clickTwice, bool switchMap, const QKeyEvent *from); // drag - void processKeyDrag(const QPointF& startPos, QPointF endPos, const QKeyEvent* from); + void processKeyDrag(const QPointF &startPos, QPointF endPos, const QKeyEvent *from); // mouse - bool processMouseClick(const QMouseEvent* from); - bool processMouseMove(const QMouseEvent* from); - void moveCursorTo(const QMouseEvent* from, const QPoint& localPosPixel); - void mouseMoveStartTouch(const QMouseEvent* from); + bool processMouseClick(const QMouseEvent *from); + bool processMouseMove(const QMouseEvent *from); + void moveCursorTo(const QMouseEvent *from, const QPoint &localPosPixel); + void mouseMoveStartTouch(const QMouseEvent *from); void mouseMoveStopTouch(); void startMouseMoveTimer(); void stopMouseMoveTimer(); @@ -67,7 +67,8 @@ private: KeyMap m_keyMap; // steer wheel - struct { + struct + { // the first key pressed int touchKey = Qt::Key_unknown; bool pressedUp = false; @@ -79,9 +80,10 @@ private: } m_ctrlSteerWheel; // mouse move - struct { + struct + { QPointF lastConverPos; - QPointF lastPos = {0.0, 0.0}; + QPointF lastPos = { 0.0, 0.0 }; bool touching = false; int timer = 0; } m_ctrlMouseMove; diff --git a/QtScrcpy/device/controller/inputconvert/inputconvertnormal.cpp b/QtScrcpy/device/controller/inputconvert/inputconvertnormal.cpp index 73c4633..b82db8b 100644 --- a/QtScrcpy/device/controller/inputconvert/inputconvertnormal.cpp +++ b/QtScrcpy/device/controller/inputconvert/inputconvertnormal.cpp @@ -2,18 +2,11 @@ #include "inputconvertnormal.h" -InputConvertNormal::InputConvertNormal(Controller* controller) - : InputConvertBase(controller) -{ +InputConvertNormal::InputConvertNormal(Controller *controller) : InputConvertBase(controller) {} -} +InputConvertNormal::~InputConvertNormal() {} -InputConvertNormal::~InputConvertNormal() -{ - -} - -void InputConvertNormal::mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize) +void InputConvertNormal::mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize) { if (!from) { return; @@ -43,10 +36,10 @@ void InputConvertNormal::mouseEvent(const QMouseEvent* from, const QSize& frameS QPointF pos = from->localPos(); // convert pos pos.setX(pos.x() * frameSize.width() / showSize.width()); - pos.setY(pos.y() * frameSize.height() / showSize.height()); + pos.setY(pos.y() * frameSize.height() / showSize.height()); // set data - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TOUCH); + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_TOUCH); if (!controlMsg) { return; } @@ -54,7 +47,7 @@ void InputConvertNormal::mouseEvent(const QMouseEvent* from, const QSize& frameS sendControlMsg(controlMsg); } -void InputConvertNormal::wheelEvent(const QWheelEvent *from, const QSize& frameSize, const QSize& showSize) +void InputConvertNormal::wheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize) { if (!from) { return; @@ -79,7 +72,7 @@ void InputConvertNormal::wheelEvent(const QWheelEvent *from, const QSize& frameS pos.setY(pos.y() * frameSize.height() / showSize.height()); // set data - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_SCROLL); + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_SCROLL); if (!controlMsg) { return; } @@ -87,7 +80,7 @@ void InputConvertNormal::wheelEvent(const QWheelEvent *from, const QSize& frameS sendControlMsg(controlMsg); } -void InputConvertNormal::keyEvent(const QKeyEvent *from, const QSize& frameSize, const QSize& showSize) +void InputConvertNormal::keyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize) { Q_UNUSED(frameSize) Q_UNUSED(showSize) @@ -115,7 +108,7 @@ void InputConvertNormal::keyEvent(const QKeyEvent *from, const QSize& frameSize, } // set data - ControlMsg* controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_KEYCODE); + ControlMsg *controlMsg = new ControlMsg(ControlMsg::CMT_INJECT_KEYCODE); if (!controlMsg) { return; } diff --git a/QtScrcpy/device/controller/inputconvert/inputconvertnormal.h b/QtScrcpy/device/controller/inputconvert/inputconvertnormal.h index e8ebe2d..3b13db0 100644 --- a/QtScrcpy/device/controller/inputconvert/inputconvertnormal.h +++ b/QtScrcpy/device/controller/inputconvert/inputconvertnormal.h @@ -7,12 +7,12 @@ class InputConvertNormal : public InputConvertBase { Q_OBJECT public: - InputConvertNormal(Controller* controller); + InputConvertNormal(Controller *controller); virtual ~InputConvertNormal(); - virtual void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); - virtual void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); - virtual void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize); + virtual void mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize); + virtual void wheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize); + virtual void keyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize); private: AndroidMotioneventButtons convertMouseButtons(Qt::MouseButtons buttonState); diff --git a/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp b/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp index 184c4d1..6cfb3c3 100644 --- a/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp +++ b/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp @@ -1,27 +1,20 @@ -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include #include "keymap.h" QString KeyMap::s_keyMapPath = ""; -KeyMap::KeyMap(QObject *parent) - : QObject(parent) -{ +KeyMap::KeyMap(QObject *parent) : QObject(parent) {} -} +KeyMap::~KeyMap() {} -KeyMap::~KeyMap() -{ - -} - -const QString& KeyMap::getKeyMapPath() +const QString &KeyMap::getKeyMapPath() { if (s_keyMapPath.isEmpty()) { s_keyMapPath = QString::fromLocal8Bit(qgetenv("QTSCRCPY_KEYMAP_PATH")); @@ -43,7 +36,7 @@ void KeyMap::loadKeyMap(const QString &json) jsonDoc = QJsonDocument::fromJson(json.toUtf8(), &jsonError); - if(jsonError.error != QJsonParseError::NoError) { + if (jsonError.error != QJsonParseError::NoError) { errorString = QString("json error: %1").arg(jsonError.errorString()); goto parseError; } @@ -57,13 +50,13 @@ void KeyMap::loadKeyMap(const QString &json) } switchKey = getItemKey(rootObj, "switchKey"); - if(switchKey.first == AT_INVALID) { + if (switchKey.first == AT_INVALID) { errorString = QString("json error: switchKey invalid"); goto parseError; } m_switchKey.type = switchKey.first; - m_switchKey.key= switchKey.second; + m_switchKey.key = switchKey.second; // mouseMoveMap if (checkItemObject(rootObj, "mouseMoveMap")) { @@ -110,8 +103,7 @@ void KeyMap::loadKeyMap(const QString &json) KeyMap::KeyMapType type = getItemKeyMapType(node, "type"); switch (type) { - case KeyMap::KMT_CLICK: - { + case KeyMap::KMT_CLICK: { // safe check if (!checkForClick(node)) { qWarning() << "json error: keyMapNodes node format error"; @@ -129,10 +121,8 @@ void KeyMap::loadKeyMap(const QString &json) keyMapNode.data.click.keyNode.pos = getItemPos(node, "pos"); keyMapNode.data.click.switchMap = getItemBool(node, "switchMap"); m_keyMapNodes.push_back(keyMapNode); - } - break; - case KeyMap::KMT_CLICK_TWICE: - { + } break; + case KeyMap::KMT_CLICK_TWICE: { // safe check if (!checkForClickTwice(node)) { qWarning() << "json error: keyMapNodes node format error"; @@ -151,10 +141,8 @@ void KeyMap::loadKeyMap(const QString &json) keyMapNode.data.click.keyNode.pos = getItemPos(node, "pos"); keyMapNode.data.click.switchMap = getItemBool(node, "switchMap"); m_keyMapNodes.push_back(keyMapNode); - } - break; - case KeyMap::KMT_STEER_WHEEL: - { + } break; + case KeyMap::KMT_STEER_WHEEL: { // safe check if (!checkForSteerWhell(node)) { qWarning() << "json error: keyMapNodes node format error"; @@ -164,8 +152,7 @@ void KeyMap::loadKeyMap(const QString &json) QPair rightKey = getItemKey(node, "rightKey"); QPair upKey = getItemKey(node, "upKey"); QPair downKey = getItemKey(node, "downKey"); - if (leftKey.first == AT_INVALID || rightKey.first == AT_INVALID - || upKey.first == AT_INVALID || downKey.first == AT_INVALID) { + if (leftKey.first == AT_INVALID || rightKey.first == AT_INVALID || upKey.first == AT_INVALID || downKey.first == AT_INVALID) { if (leftKey.first == AT_INVALID) { qWarning() << "json error: keyMapNodes node invalid key: " << node.value("leftKey").toString(); } @@ -184,26 +171,16 @@ void KeyMap::loadKeyMap(const QString &json) KeyMapNode keyMapNode; keyMapNode.type = type; - keyMapNode.data.steerWheel.left = { leftKey.first, leftKey.second, - QPointF(0, 0), QPointF(0, 0), - getItemDouble(node, "leftOffset") }; - keyMapNode.data.steerWheel.right = { rightKey.first, rightKey.second, - QPointF(0, 0), QPointF(0, 0), - getItemDouble(node, "rightOffset") }; - keyMapNode.data.steerWheel.up = { upKey.first, upKey.second, - QPointF(0, 0), QPointF(0, 0), - getItemDouble(node, "upOffset") }; - keyMapNode.data.steerWheel.down = { downKey.first, downKey.second, - QPointF(0, 0), QPointF(0, 0), - getItemDouble(node, "downOffset") }; + keyMapNode.data.steerWheel.left = { leftKey.first, leftKey.second, QPointF(0, 0), QPointF(0, 0), getItemDouble(node, "leftOffset") }; + keyMapNode.data.steerWheel.right = { rightKey.first, rightKey.second, QPointF(0, 0), QPointF(0, 0), getItemDouble(node, "rightOffset") }; + keyMapNode.data.steerWheel.up = { upKey.first, upKey.second, QPointF(0, 0), QPointF(0, 0), getItemDouble(node, "upOffset") }; + keyMapNode.data.steerWheel.down = { downKey.first, downKey.second, QPointF(0, 0), QPointF(0, 0), getItemDouble(node, "downOffset") }; keyMapNode.data.steerWheel.centerPos = getItemPos(node, "centerPos"); m_idxSteerWheel = m_keyMapNodes.size(); m_keyMapNodes.push_back(keyMapNode); - } - break; - case KeyMap::KMT_DRAG: - { + } break; + case KeyMap::KMT_DRAG: { // safe check if (!checkForDrag(node)) { qWarning() << "json error: keyMapNodes node format error"; @@ -241,7 +218,7 @@ parseError: return; } -const KeyMap::KeyMapNode& KeyMap::getKeyMapNode(int key) +const KeyMap::KeyMapNode &KeyMap::getKeyMapNode(int key) { auto p = m_rmapKey.value(key, &m_invalidNode); if (p == &m_invalidNode) { @@ -250,12 +227,12 @@ const KeyMap::KeyMapNode& KeyMap::getKeyMapNode(int key) return *p; } -const KeyMap::KeyMapNode& KeyMap::getKeyMapNodeKey(int key) +const KeyMap::KeyMapNode &KeyMap::getKeyMapNodeKey(int key) { return *m_rmapKey.value(key, &m_invalidNode); } -const KeyMap::KeyMapNode& KeyMap::getKeyMapNodeMouse(int key) +const KeyMap::KeyMapNode &KeyMap::getKeyMapNodeMouse(int key) { return *m_rmapMouse.value(key, &m_invalidNode); } @@ -270,7 +247,7 @@ int KeyMap::getSwitchKey() return m_switchKey.key; } -const KeyMap::KeyMapNode& KeyMap::getMouseMoveMap() +const KeyMap::KeyMapNode &KeyMap::getMouseMoveMap() { return m_keyMapNodes[m_idxMouseMove]; } @@ -289,39 +266,31 @@ void KeyMap::makeReverseMap() { m_rmapKey.clear(); m_rmapMouse.clear(); - for (int i = 0 ; i < m_keyMapNodes.size(); ++i) { - auto& node = m_keyMapNodes[i]; + for (int i = 0; i < m_keyMapNodes.size(); ++i) { + auto &node = m_keyMapNodes[i]; switch (node.type) { - case KMT_CLICK: - { - QMultiHash& m = node.data.click.keyNode.type == AT_KEY ? m_rmapKey : m_rmapMouse; + case KMT_CLICK: { + QMultiHash &m = node.data.click.keyNode.type == AT_KEY ? m_rmapKey : m_rmapMouse; m.insert(node.data.click.keyNode.key, &node); - } - break; - case KMT_CLICK_TWICE: - { - QMultiHash& m = node.data.clickTwice.keyNode.type == AT_KEY ? m_rmapKey : m_rmapMouse; + } break; + case KMT_CLICK_TWICE: { + QMultiHash &m = node.data.clickTwice.keyNode.type == AT_KEY ? m_rmapKey : m_rmapMouse; m.insert(node.data.clickTwice.keyNode.key, &node); - } - break; - case KMT_STEER_WHEEL: - { - QMultiHash& ml = node.data.steerWheel.left.type == AT_KEY ? m_rmapKey : m_rmapMouse; + } break; + case KMT_STEER_WHEEL: { + QMultiHash &ml = node.data.steerWheel.left.type == AT_KEY ? m_rmapKey : m_rmapMouse; ml.insert(node.data.steerWheel.left.key, &node); - QMultiHash& mr = node.data.steerWheel.right.type == AT_KEY ? m_rmapKey : m_rmapMouse; + QMultiHash &mr = node.data.steerWheel.right.type == AT_KEY ? m_rmapKey : m_rmapMouse; mr.insert(node.data.steerWheel.right.key, &node); - QMultiHash& mu = node.data.steerWheel.up.type == AT_KEY ? m_rmapKey : m_rmapMouse; + QMultiHash &mu = node.data.steerWheel.up.type == AT_KEY ? m_rmapKey : m_rmapMouse; mu.insert(node.data.steerWheel.up.key, &node); - QMultiHash& md = node.data.steerWheel.down.type == AT_KEY ? m_rmapKey : m_rmapMouse; + QMultiHash &md = node.data.steerWheel.down.type == AT_KEY ? m_rmapKey : m_rmapMouse; md.insert(node.data.steerWheel.down.key, &node); - } - break; - case KMT_DRAG: - { - QMultiHash& m = node.data.drag.keyNode.type == AT_KEY ? m_rmapKey : m_rmapMouse; + } break; + case KMT_DRAG: { + QMultiHash &m = node.data.drag.keyNode.type == AT_KEY ? m_rmapKey : m_rmapMouse; m.insert(node.data.drag.keyNode.key, &node); - } - break; + } break; default: break; } @@ -333,12 +302,12 @@ QString KeyMap::getItemString(const QJsonObject &node, const QString &name) return node.value(name).toString(); } -double KeyMap::getItemDouble(const QJsonObject& node, const QString& name) +double KeyMap::getItemDouble(const QJsonObject &node, const QString &name) { return node.value(name).toDouble(); } -bool KeyMap::getItemBool(const QJsonObject& node, const QString& name) +bool KeyMap::getItemBool(const QJsonObject &node, const QString &name) { return node.value(name).toBool(false); } @@ -348,43 +317,43 @@ QJsonObject KeyMap::getItemObject(const QJsonObject &node, const QString &name) return node.value(name).toObject(); } -QPointF KeyMap::getItemPos(const QJsonObject& node, const QString& name) +QPointF KeyMap::getItemPos(const QJsonObject &node, const QString &name) { QJsonObject pos = node.value(name).toObject(); return QPointF(pos.value("x").toDouble(), pos.value("y").toDouble()); } -QPair KeyMap::getItemKey(const QJsonObject& node, const QString& name) +QPair KeyMap::getItemKey(const QJsonObject &node, const QString &name) { QString value = getItemString(node, name); int key = m_metaEnumKey.keyToValue(value.toStdString().c_str()); int btn = m_metaEnumMouseButtons.keyToValue(value.toStdString().c_str()); if (key == -1 && btn == -1) { - return {AT_INVALID, -1}; + return { AT_INVALID, -1 }; } else if (key != -1) { - return {AT_KEY, key}; + return { AT_KEY, key }; } else { - return {AT_MOUSE, btn}; + return { AT_MOUSE, btn }; } } -KeyMap::KeyMapType KeyMap::getItemKeyMapType(const QJsonObject& node, const QString& name) +KeyMap::KeyMapType KeyMap::getItemKeyMapType(const QJsonObject &node, const QString &name) { QString value = getItemString(node, name); return static_cast(m_metaEnumKeyMapType.keyToValue(value.toStdString().c_str())); } -bool KeyMap::checkItemString(const QJsonObject& node, const QString& name) +bool KeyMap::checkItemString(const QJsonObject &node, const QString &name) { return node.contains(name) && node.value(name).isString(); } -bool KeyMap::checkItemDouble(const QJsonObject& node, const QString& name) +bool KeyMap::checkItemDouble(const QJsonObject &node, const QString &name) { return node.contains(name) && node.value(name).isDouble(); } -bool KeyMap::checkItemBool(const QJsonObject& node, const QString& name) +bool KeyMap::checkItemBool(const QJsonObject &node, const QString &name) { return node.contains(name) && node.value(name).isBool(); } @@ -394,38 +363,33 @@ bool KeyMap::checkItemObject(const QJsonObject &node, const QString &name) return node.contains(name) && node.value(name).isObject(); } -bool KeyMap::checkItemPos(const QJsonObject& node, const QString& name) +bool KeyMap::checkItemPos(const QJsonObject &node, const QString &name) { if (node.contains(name) && node.value(name).isObject()) { QJsonObject pos = node.value(name).toObject(); - return pos.contains("x") && pos.value("x").isDouble() - && pos.contains("y") && pos.value("y").isDouble(); + return pos.contains("x") && pos.value("x").isDouble() && pos.contains("y") && pos.value("y").isDouble(); } return false; } -bool KeyMap::checkForClick(const QJsonObject& node) +bool KeyMap::checkForClick(const QJsonObject &node) { return checkForClickTwice(node) && checkItemBool(node, "switchMap"); } -bool KeyMap::checkForClickTwice(const QJsonObject& node) +bool KeyMap::checkForClickTwice(const QJsonObject &node) { return checkItemString(node, "key") && checkItemPos(node, "pos"); } -bool KeyMap::checkForSteerWhell(const QJsonObject& node) +bool KeyMap::checkForSteerWhell(const QJsonObject &node) { - return checkItemString(node, "leftKey") && checkItemString(node, "rightKey") - && checkItemString(node, "upKey") && checkItemString(node, "downKey") - && checkItemDouble(node, "leftOffset") && checkItemDouble(node, "rightOffset") - && checkItemDouble(node, "upOffset") && checkItemDouble(node, "downOffset") - && checkItemPos(node, "centerPos"); + return checkItemString(node, "leftKey") && checkItemString(node, "rightKey") && checkItemString(node, "upKey") && checkItemString(node, "downKey") + && checkItemDouble(node, "leftOffset") && checkItemDouble(node, "rightOffset") && checkItemDouble(node, "upOffset") + && checkItemDouble(node, "downOffset") && checkItemPos(node, "centerPos"); } -bool KeyMap::checkForDrag(const QJsonObject& node) +bool KeyMap::checkForDrag(const QJsonObject &node) { - return checkItemString(node, "key") - && checkItemPos(node, "startPos") && checkItemPos(node, "endPos"); + return checkItemString(node, "key") && checkItemPos(node, "startPos") && checkItemPos(node, "endPos"); } - diff --git a/QtScrcpy/device/controller/inputconvert/keymap/keymap.h b/QtScrcpy/device/controller/inputconvert/keymap/keymap.h index ffc1d28..b1fd321 100644 --- a/QtScrcpy/device/controller/inputconvert/keymap/keymap.h +++ b/QtScrcpy/device/controller/inputconvert/keymap/keymap.h @@ -1,76 +1,82 @@ #ifndef KEYMAP_H #define KEYMAP_H -#include -#include -#include -#include -#include +#include #include #include -#include +#include +#include +#include +#include +#include class KeyMap : public QObject -{ +{ Q_OBJECT public: - enum KeyMapType { + enum KeyMapType + { KMT_INVALID = -1, KMT_CLICK = 0, KMT_CLICK_TWICE, KMT_STEER_WHEEL, KMT_DRAG, KMT_MOUSE_MOVE - }; + }; Q_ENUM(KeyMapType) - enum ActionType { + enum ActionType + { AT_INVALID = -1, AT_KEY = 0, AT_MOUSE = 1, }; Q_ENUM(ActionType) - struct KeyNode { + struct KeyNode + { ActionType type = AT_INVALID; int key = Qt::Key_unknown; - QPointF pos = QPointF(0, 0); // normal key + QPointF pos = QPointF(0, 0); // normal key QPointF extendPos = QPointF(0, 0); // for drag - double extendOffset = 0.0; // for steerWheel + double extendOffset = 0.0; // for steerWheel - KeyNode(ActionType type = AT_INVALID, - int key = Qt::Key_unknown, - QPointF pos = QPointF(0, 0), - QPointF extendPos = QPointF(0, 0), - double extendOffset = 0.0) - : type(type) - , key(key) - , pos(pos) - , extendPos(extendPos) - , extendOffset(extendOffset) + KeyNode( + ActionType type = AT_INVALID, + int key = Qt::Key_unknown, + QPointF pos = QPointF(0, 0), + QPointF extendPos = QPointF(0, 0), + double extendOffset = 0.0) + : type(type), key(key), pos(pos), extendPos(extendPos), extendOffset(extendOffset) { - } }; - struct KeyMapNode { + struct KeyMapNode + { KeyMapType type = KMT_INVALID; - union DATA { - struct { + union DATA + { + struct + { KeyNode keyNode; bool switchMap = false; } click; - struct { + struct + { KeyNode keyNode; } clickTwice; - struct { - QPointF centerPos = {0.0, 0.0}; + struct + { + QPointF centerPos = { 0.0, 0.0 }; KeyNode left, right, up, down; } steerWheel; - struct { + struct + { KeyNode keyNode; } drag; - struct { - QPointF startPos = {0.0, 0.0}; + struct + { + QPointF startPos = { 0.0, 0.0 }; int speedRatio = 1; } mouseMove; DATA() {} @@ -84,49 +90,49 @@ public: virtual ~KeyMap(); void loadKeyMap(const QString &json); - const KeyMap::KeyMapNode& getKeyMapNode(int key); - const KeyMap::KeyMapNode& getKeyMapNodeKey(int key); - const KeyMap::KeyMapNode& getKeyMapNodeMouse(int key); + const KeyMap::KeyMapNode &getKeyMapNode(int key); + const KeyMap::KeyMapNode &getKeyMapNodeKey(int key); + const KeyMap::KeyMapNode &getKeyMapNodeMouse(int key); bool isSwitchOnKeyboard(); int getSwitchKey(); bool isValidMouseMoveMap(); bool isValidSteerWheelMap(); - const KeyMap::KeyMapNode& getMouseMoveMap(); + const KeyMap::KeyMapNode &getMouseMoveMap(); - static const QString& getKeyMapPath(); + static const QString &getKeyMapPath(); private: // set up the reverse map from key/event event to keyMapNode void makeReverseMap(); // safe check for base - bool checkItemString(const QJsonObject& node, const QString& name); - bool checkItemDouble(const QJsonObject& node, const QString& name); - bool checkItemBool(const QJsonObject& node, const QString& name); - bool checkItemObject(const QJsonObject& node, const QString& name); - bool checkItemPos(const QJsonObject& node, const QString& name); + bool checkItemString(const QJsonObject &node, const QString &name); + bool checkItemDouble(const QJsonObject &node, const QString &name); + bool checkItemBool(const QJsonObject &node, const QString &name); + bool checkItemObject(const QJsonObject &node, const QString &name); + bool checkItemPos(const QJsonObject &node, const QString &name); // safe check for KeyMapNode - bool checkForClick(const QJsonObject& node); - bool checkForClickTwice(const QJsonObject& node); - bool checkForSteerWhell(const QJsonObject& node); - bool checkForDrag(const QJsonObject& node); + bool checkForClick(const QJsonObject &node); + bool checkForClickTwice(const QJsonObject &node); + bool checkForSteerWhell(const QJsonObject &node); + bool checkForDrag(const QJsonObject &node); // get keymap from json object - QString getItemString(const QJsonObject& node, const QString& name); - double getItemDouble(const QJsonObject& node, const QString& name); - bool getItemBool(const QJsonObject& node, const QString& name); - QJsonObject getItemObject(const QJsonObject& node, const QString& name); - QPointF getItemPos(const QJsonObject& node, const QString& name); - QPair getItemKey(const QJsonObject& node, const QString& name); - KeyMapType getItemKeyMapType(const QJsonObject& node, const QString& name); + QString getItemString(const QJsonObject &node, const QString &name); + double getItemDouble(const QJsonObject &node, const QString &name); + bool getItemBool(const QJsonObject &node, const QString &name); + QJsonObject getItemObject(const QJsonObject &node, const QString &name); + QPointF getItemPos(const QJsonObject &node, const QString &name); + QPair getItemKey(const QJsonObject &node, const QString &name); + KeyMapType getItemKeyMapType(const QJsonObject &node, const QString &name); private: static QString s_keyMapPath; QVector m_keyMapNodes; - KeyNode m_switchKey = {AT_KEY, Qt::Key_QuoteLeft}; + KeyNode m_switchKey = { AT_KEY, Qt::Key_QuoteLeft }; // just for return KeyMapNode m_invalidNode; @@ -142,8 +148,8 @@ private: QMetaEnum m_metaEnumMouseButtons = QMetaEnum::fromType(); QMetaEnum m_metaEnumKeyMapType = QMetaEnum::fromType(); // reverse map of key/mouse event - QMultiHash m_rmapKey; - QMultiHash m_rmapMouse; + QMultiHash m_rmapKey; + QMultiHash m_rmapMouse; }; #endif // KEYMAP_H diff --git a/QtScrcpy/device/controller/receiver/devicemsg.cpp b/QtScrcpy/device/controller/receiver/devicemsg.cpp index 26fcc8c..e2bb28d 100644 --- a/QtScrcpy/device/controller/receiver/devicemsg.cpp +++ b/QtScrcpy/device/controller/receiver/devicemsg.cpp @@ -1,17 +1,13 @@ #include -#include "devicemsg.h" #include "bufferutil.h" +#include "devicemsg.h" -DeviceMsg::DeviceMsg(QObject *parent) : QObject(parent) -{ - -} +DeviceMsg::DeviceMsg(QObject *parent) : QObject(parent) {} DeviceMsg::~DeviceMsg() { - if (DMT_GET_CLIPBOARD == m_data.type - && Q_NULLPTR != m_data.clipboardMsg.text) { + if (DMT_GET_CLIPBOARD == m_data.type && Q_NULLPTR != m_data.clipboardMsg.text) { delete m_data.clipboardMsg.text; m_data.clipboardMsg.text = Q_NULLPTR; } @@ -22,12 +18,12 @@ DeviceMsg::DeviceMsgType DeviceMsg::type() return m_data.type; } -void DeviceMsg::getClipboardMsgData(QString& text) +void DeviceMsg::getClipboardMsgData(QString &text) { text = QString::fromUtf8(m_data.clipboardMsg.text); } -qint32 DeviceMsg::deserialize(QByteArray& byteArray) +qint32 DeviceMsg::deserialize(QByteArray &byteArray) { QBuffer buf(&byteArray); buf.open(QBuffer::ReadOnly); @@ -61,7 +57,7 @@ qint32 DeviceMsg::deserialize(QByteArray& byteArray) break; } default: - qWarning("Unsupported device msg type: %d", (int) m_data.type); + qWarning("Unsupported device msg type: %d", (int)m_data.type); ret = -1; // error, we cannot recover } diff --git a/QtScrcpy/device/controller/receiver/devicemsg.h b/QtScrcpy/device/controller/receiver/devicemsg.h index e7fb68a..1ed0f22 100644 --- a/QtScrcpy/device/controller/receiver/devicemsg.h +++ b/QtScrcpy/device/controller/receiver/devicemsg.h @@ -11,7 +11,8 @@ class DeviceMsg : public QObject { Q_OBJECT public: - enum DeviceMsgType { + enum DeviceMsgType + { DMT_NULL = -1, // 和服务端对应 DMT_GET_CLIPBOARD = 0, @@ -20,20 +21,23 @@ public: virtual ~DeviceMsg(); DeviceMsg::DeviceMsgType type(); - void getClipboardMsgData(QString& text); + void getClipboardMsgData(QString &text); - qint32 deserialize(QByteArray& byteArray); + qint32 deserialize(QByteArray &byteArray); private: - struct DeviceMsgData { + struct DeviceMsgData + { DeviceMsgType type = DMT_NULL; - union { - struct { - char* text = Q_NULLPTR; + union + { + struct + { + char *text = Q_NULLPTR; } clipboardMsg; }; - DeviceMsgData(){} - ~DeviceMsgData(){} + DeviceMsgData() {} + ~DeviceMsgData() {} }; DeviceMsgData m_data; diff --git a/QtScrcpy/device/controller/receiver/receiver.cpp b/QtScrcpy/device/controller/receiver/receiver.cpp index 6b496e9..5e282ef 100644 --- a/QtScrcpy/device/controller/receiver/receiver.cpp +++ b/QtScrcpy/device/controller/receiver/receiver.cpp @@ -1,18 +1,13 @@ -#include #include #include #include -#include "receiver.h" #include "devicemsg.h" +#include "receiver.h" -Receiver::Receiver(QObject *parent) : QObject(parent) -{ -} +Receiver::Receiver(QObject *parent) : QObject(parent) {} -Receiver::~Receiver() -{ -} +Receiver::~Receiver() {} void Receiver::setControlSocket(QTcpSocket *controlSocket) { @@ -24,7 +19,7 @@ void Receiver::setControlSocket(QTcpSocket *controlSocket) } void Receiver::onReadyRead() -{ +{ if (!m_controlSocket) { return; } @@ -44,8 +39,7 @@ void Receiver::onReadyRead() void Receiver::processMsg(DeviceMsg *deviceMsg) { switch (deviceMsg->type()) { - case DeviceMsg::DMT_GET_CLIPBOARD: - { + case DeviceMsg::DMT_GET_CLIPBOARD: { qInfo("Device clipboard copied"); QClipboard *board = QApplication::clipboard(); QString text; diff --git a/QtScrcpy/device/decoder/avframeconvert.cpp b/QtScrcpy/device/decoder/avframeconvert.cpp index 31930d1..e82aaff 100644 --- a/QtScrcpy/device/decoder/avframeconvert.cpp +++ b/QtScrcpy/device/decoder/avframeconvert.cpp @@ -2,15 +2,9 @@ #include "avframeconvert.h" -AVFrameConvert::AVFrameConvert() -{ +AVFrameConvert::AVFrameConvert() {} -} - -AVFrameConvert::~AVFrameConvert() -{ - -} +AVFrameConvert::~AVFrameConvert() {} void AVFrameConvert::setSrcFrameInfo(int srcWidth, int srcHeight, AVPixelFormat srcFormat) { @@ -20,11 +14,11 @@ void AVFrameConvert::setSrcFrameInfo(int srcWidth, int srcHeight, AVPixelFormat qDebug() << "Convert::src frame info " << srcWidth << "x" << srcHeight; } -void AVFrameConvert::getSrcFrameInfo(int& srcWidth, int& srcHeight, AVPixelFormat& srcFormat) +void AVFrameConvert::getSrcFrameInfo(int &srcWidth, int &srcHeight, AVPixelFormat &srcFormat) { srcWidth = m_srcWidth; srcHeight = m_srcHeight; - srcFormat = m_srcFormat; + srcFormat = m_srcFormat; } void AVFrameConvert::setDstFrameInfo(int dstWidth, int dstHeight, AVPixelFormat dstFormat) @@ -34,7 +28,7 @@ void AVFrameConvert::setDstFrameInfo(int dstWidth, int dstHeight, AVPixelFormat m_dstFormat = dstFormat; } -void AVFrameConvert::getDstFrameInfo(int& dstWidth, int& dstHeight, AVPixelFormat& dstFormat) +void AVFrameConvert::getDstFrameInfo(int &dstWidth, int &dstHeight, AVPixelFormat &dstFormat) { dstWidth = m_dstWidth; dstHeight = m_dstHeight; @@ -46,8 +40,7 @@ bool AVFrameConvert::init() if (m_convertCtx) { return true; } - m_convertCtx = sws_getContext(m_srcWidth, m_srcHeight, m_srcFormat, m_dstWidth, m_dstHeight, m_dstFormat, - SWS_BICUBIC, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR); + m_convertCtx = sws_getContext(m_srcWidth, m_srcHeight, m_srcFormat, m_dstWidth, m_dstHeight, m_dstFormat, SWS_BICUBIC, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR); if (!m_convertCtx) { return false; } @@ -67,15 +60,13 @@ void AVFrameConvert::deInit() } } -bool AVFrameConvert::convert(const AVFrame* srcFrame, AVFrame* dstFrame) +bool AVFrameConvert::convert(const AVFrame *srcFrame, AVFrame *dstFrame) { - if(!m_convertCtx || !srcFrame || !dstFrame) { + if (!m_convertCtx || !srcFrame || !dstFrame) { return false; } - qint32 ret = sws_scale(m_convertCtx, - static_cast(srcFrame->data), - srcFrame->linesize, 0, m_srcHeight, dstFrame->data, - dstFrame->linesize); + qint32 ret + = sws_scale(m_convertCtx, static_cast(srcFrame->data), srcFrame->linesize, 0, m_srcHeight, dstFrame->data, dstFrame->linesize); if (0 == ret) { return false; } diff --git a/QtScrcpy/device/decoder/avframeconvert.h b/QtScrcpy/device/decoder/avframeconvert.h index d32338e..9d32853 100644 --- a/QtScrcpy/device/decoder/avframeconvert.h +++ b/QtScrcpy/device/decoder/avframeconvert.h @@ -5,8 +5,8 @@ extern "C" { #include "libavcodec/avcodec.h" -#include "libswscale/swscale.h" #include "libavutil/frame.h" +#include "libswscale/swscale.h" } class AVFrameConvert @@ -17,14 +17,14 @@ public: public: void setSrcFrameInfo(int srcWidth, int srcHeight, AVPixelFormat srcFormat); - void getSrcFrameInfo(int& srcWidth, int& srcHeight, AVPixelFormat& srcFormat); + void getSrcFrameInfo(int &srcWidth, int &srcHeight, AVPixelFormat &srcFormat); void setDstFrameInfo(int dstWidth, int dstHeight, AVPixelFormat dstFormat); - void getDstFrameInfo(int& dstWidth, int& dstHeight, AVPixelFormat& dstFormat); + void getDstFrameInfo(int &dstWidth, int &dstHeight, AVPixelFormat &dstFormat); bool init(); bool isInit(); void deInit(); - bool convert(const AVFrame* srcFrame, AVFrame* dstFrame); + bool convert(const AVFrame *srcFrame, AVFrame *dstFrame); private: int m_srcWidth = 0; diff --git a/QtScrcpy/device/decoder/decoder.cpp b/QtScrcpy/device/decoder/decoder.cpp index 2ce622a..c6d727e 100644 --- a/QtScrcpy/device/decoder/decoder.cpp +++ b/QtScrcpy/device/decoder/decoder.cpp @@ -1,20 +1,12 @@ #include #include "compat.h" -#include "videobuffer.h" #include "decoder.h" +#include "videobuffer.h" -Decoder::Decoder(VideoBuffer* vb, QObject *parent) - : QObject(parent) - , m_vb(vb) -{ +Decoder::Decoder(VideoBuffer *vb, QObject *parent) : QObject(parent), m_vb(vb) {} -} - -Decoder::~Decoder() -{ - -} +Decoder::~Decoder() {} bool Decoder::open(const AVCodec *codec) { @@ -43,12 +35,12 @@ void Decoder::close() avcodec_free_context(&m_codecCtx); } -bool Decoder::push(const AVPacket* packet) +bool Decoder::push(const AVPacket *packet) { if (!m_codecCtx || !m_vb) { return false; } - AVFrame* decodingFrame = m_vb->decodingFrame(); + AVFrame *decodingFrame = m_vb->decodingFrame(); #ifdef QTSCRCPY_LAVF_HAS_NEW_ENCODING_DECODING_API int ret = -1; if ((ret = avcodec_send_packet(m_codecCtx, packet)) < 0) { @@ -123,6 +115,6 @@ void Decoder::pushFrame() if (previousFrameSkipped) { // the previous newFrame will consume this frame return; - } + } emit onNewFrame(); } diff --git a/QtScrcpy/device/decoder/decoder.h b/QtScrcpy/device/decoder/decoder.h index a0ba971..5497a09 100644 --- a/QtScrcpy/device/decoder/decoder.h +++ b/QtScrcpy/device/decoder/decoder.h @@ -12,7 +12,7 @@ class Decoder : public QObject { Q_OBJECT public: - Decoder(VideoBuffer* vb, QObject *parent = Q_NULLPTR); + Decoder(VideoBuffer *vb, QObject *parent = Q_NULLPTR); virtual ~Decoder(); bool open(const AVCodec *codec); @@ -26,9 +26,9 @@ signals: protected: void pushFrame(); -private: - VideoBuffer* m_vb = Q_NULLPTR; - AVCodecContext* m_codecCtx = Q_NULLPTR; +private: + VideoBuffer *m_vb = Q_NULLPTR; + AVCodecContext *m_codecCtx = Q_NULLPTR; bool m_isCodecCtxOpen = false; }; diff --git a/QtScrcpy/device/decoder/fpscounter.cpp b/QtScrcpy/device/decoder/fpscounter.cpp index 492e51e..0bb099f 100644 --- a/QtScrcpy/device/decoder/fpscounter.cpp +++ b/QtScrcpy/device/decoder/fpscounter.cpp @@ -1,17 +1,11 @@ -#include #include +#include #include "fpscounter.h" -FpsCounter::FpsCounter(QObject* parent) : QObject(parent) -{ +FpsCounter::FpsCounter(QObject *parent) : QObject(parent) {} -} - -FpsCounter::~FpsCounter() -{ - -} +FpsCounter::~FpsCounter() {} void FpsCounter::start() { @@ -20,7 +14,7 @@ void FpsCounter::start() } void FpsCounter::stop() -{ +{ stopCounterTimer(); resetCounter(); } diff --git a/QtScrcpy/device/decoder/fpscounter.h b/QtScrcpy/device/decoder/fpscounter.h index 82daa79..d39df67 100644 --- a/QtScrcpy/device/decoder/fpscounter.h +++ b/QtScrcpy/device/decoder/fpscounter.h @@ -6,7 +6,7 @@ class FpsCounter : public QObject { Q_OBJECT public: - FpsCounter(QObject* parent = Q_NULLPTR); + FpsCounter(QObject *parent = Q_NULLPTR); virtual ~FpsCounter(); void start(); @@ -23,7 +23,7 @@ private: void stopCounterTimer(); void resetCounter(); -private: +private: quint32 m_counterTimer = 0; quint32 m_curRendered = 0; quint32 m_curSkipped = 0; diff --git a/QtScrcpy/device/decoder/videobuffer.cpp b/QtScrcpy/device/decoder/videobuffer.cpp index c0cb22a..6ddecbd 100644 --- a/QtScrcpy/device/decoder/videobuffer.cpp +++ b/QtScrcpy/device/decoder/videobuffer.cpp @@ -1,19 +1,13 @@ #include "videobuffer.h" extern "C" { -#include "libavutil/avutil.h" #include "libavformat/avformat.h" +#include "libavutil/avutil.h" } -VideoBuffer::VideoBuffer() -{ +VideoBuffer::VideoBuffer() {} -} - -VideoBuffer::~VideoBuffer() -{ - -} +VideoBuffer::~VideoBuffer() {} bool VideoBuffer::init(bool renderExpiredFrames) { @@ -68,7 +62,7 @@ AVFrame *VideoBuffer::decodingFrame() return m_decodingFrame; } -void VideoBuffer::offerDecodedFrame(bool& previousFrameSkipped) +void VideoBuffer::offerDecodedFrame(bool &previousFrameSkipped) { m_mutex.lock(); @@ -87,7 +81,7 @@ void VideoBuffer::offerDecodedFrame(bool& previousFrameSkipped) swap(); previousFrameSkipped = !m_renderingFrameConsumed; m_renderingFrameConsumed = false; - m_mutex.unlock(); + m_mutex.unlock(); } const AVFrame *VideoBuffer::consumeRenderedFrame() diff --git a/QtScrcpy/device/decoder/videobuffer.h b/QtScrcpy/device/decoder/videobuffer.h index 41b5b1c..fad772a 100644 --- a/QtScrcpy/device/decoder/videobuffer.h +++ b/QtScrcpy/device/decoder/videobuffer.h @@ -10,7 +10,7 @@ typedef struct AVFrame AVFrame; class VideoBuffer -{ +{ public: VideoBuffer(); virtual ~VideoBuffer(); @@ -20,19 +20,19 @@ public: void lock(); void unLock(); - AVFrame* decodingFrame(); + AVFrame *decodingFrame(); // set the decoder frame as ready for rendering // this function locks m_mutex during its execution // returns true if the previous frame had been consumed - void offerDecodedFrame(bool& previousFrameSkipped); + void offerDecodedFrame(bool &previousFrameSkipped); // mark the rendering frame as consumed and return it // MUST be called with m_mutex locked!!! // the caller is expected to render the returned frame to some texture before // unlocking m_mutex - const AVFrame* consumeRenderedFrame(); + const AVFrame *consumeRenderedFrame(); - const AVFrame* peekRenderedFrame(); + const AVFrame *peekRenderedFrame(); // wake up and avoid any blocking call void interrupt(); @@ -41,8 +41,8 @@ private: void swap(); private: - AVFrame* m_decodingFrame = Q_NULLPTR; - AVFrame* m_renderingframe = Q_NULLPTR; + AVFrame *m_decodingFrame = Q_NULLPTR; + AVFrame *m_renderingframe = Q_NULLPTR; QMutex m_mutex; bool m_renderingFrameConsumed = true; FpsCounter m_fpsCounter; diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index a0bda6b..c0e6a26 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -1,27 +1,25 @@ -#include -#include #include +#include +#include +#include "avframeconvert.h" +#include "config.h" +#include "controller.h" +#include "decoder.h" #include "device.h" +#include "filehandler.h" +#include "mousetap/mousetap.h" #include "recorder.h" #include "server.h" -#include "videobuffer.h" -#include "decoder.h" -#include "filehandler.h" #include "stream.h" +#include "videobuffer.h" #include "videoform.h" -#include "controller.h" -#include "config.h" -#include "avframeconvert.h" -#include "mousetap/mousetap.h" extern "C" { #include "libavutil/imgutils.h" } -Device::Device(DeviceParams params, QObject *parent) - : QObject(parent) - , m_params(params) +Device::Device(DeviceParams params, QObject *parent) : QObject(parent), m_params(params) { if (!params.display && m_params.recordFileName.trimmed().isEmpty()) { qCritical("not display must be recorded"); @@ -102,7 +100,7 @@ const QSize Device::frameSize() void Device::updateScript(QString script) { - if(m_controller){ + if (m_controller) { m_controller->updateScript(script); } } @@ -121,11 +119,11 @@ void Device::onScreenshot() void Device::onShowTouch(bool show) { - AdbProcess* adb = new AdbProcess(); + AdbProcess *adb = new AdbProcess(); if (!adb) { return; } - connect(adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){ + connect(adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult) { if (AdbProcess::AER_SUCCESS_START != processResult) { sender()->deleteLater(); } @@ -167,7 +165,7 @@ void Device::initSignals() connect(this, &Device::postTextInput, m_controller, &Controller::onPostTextInput); } if (m_videoForm) { - connect(m_videoForm, &VideoForm::destroyed, this, [this](QObject *obj){ + connect(m_videoForm, &VideoForm::destroyed, this, [this](QObject *obj) { Q_UNUSED(obj) deleteLater(); }); @@ -177,7 +175,7 @@ void Device::initSignals() if (m_fileHandler) { connect(this, &Device::pushFileRequest, m_fileHandler, &FileHandler::onPushFileRequest); connect(this, &Device::installApkRequest, m_fileHandler, &FileHandler::onInstallApkRequest); - connect(m_fileHandler, &FileHandler::fileHandlerResult, this, [this](FileHandler::FILE_HANDLER_RESULT processResult, bool isApk){ + connect(m_fileHandler, &FileHandler::fileHandlerResult, this, [this](FileHandler::FILE_HANDLER_RESULT processResult, bool isApk) { QString tipsType = ""; if (isApk) { tipsType = tr("install apk"); @@ -203,14 +201,14 @@ void Device::initSignals() } if (m_server) { - connect(m_server, &Server::serverStartResult, this, [this](bool success){ + connect(m_server, &Server::serverStartResult, this, [this](bool success) { if (success) { m_server->connectTo(); } else { deleteLater(); } }); - connect(m_server, &Server::connectToResult, this, [this](bool success, const QString &deviceName, const QSize &size){ + connect(m_server, &Server::connectToResult, this, [this](bool success, const QString &deviceName, const QSize &size) { if (success) { double diff = m_startTimeCount.elapsed() / 1000.0; qInfo(QString("server start finish in %1s").arg(diff).toStdString().c_str()); @@ -251,14 +249,14 @@ void Device::initSignals() } } }); - connect(m_server, &Server::onServerStop, this, [this](){ + connect(m_server, &Server::onServerStop, this, [this]() { deleteLater(); qDebug() << "server process stop"; }); } if (m_stream) { - connect(m_stream, &Stream::onStreamStop, this, [this](){ + connect(m_stream, &Stream::onStreamStop, this, [this]() { deleteLater(); qDebug() << "stream thread stop"; }); @@ -266,21 +264,26 @@ void Device::initSignals() if (m_decoder && m_vb) { // must be Qt::QueuedConnection, ui update must be main thread - connect(m_decoder, &Decoder::onNewFrame, this, [this](){ - m_vb->lock(); - const AVFrame *frame = m_vb->consumeRenderedFrame(); - if (m_videoForm) { - m_videoForm->updateRender(frame); - } - m_vb->unLock(); - },Qt::QueuedConnection); + connect( + m_decoder, + &Decoder::onNewFrame, + this, + [this]() { + m_vb->lock(); + const AVFrame *frame = m_vb->consumeRenderedFrame(); + if (m_videoForm) { + m_videoForm->updateRender(frame); + } + m_vb->unLock(); + }, + Qt::QueuedConnection); } } void Device::startServer() { // fix: macos cant recv finished signel, timer is ok - QTimer::singleShot(0, this, [this](){ + QTimer::singleShot(0, this, [this]() { m_startTimeCount.start(); // max size support 480p 720p 1080p 设备原生分辨率 // support wireless connect, example: @@ -300,7 +303,7 @@ void Device::startServer() }); } -void Device::onSetControlState(Device* device, Device::GroupControlState state) +void Device::onSetControlState(Device *device, Device::GroupControlState state) { Q_UNUSED(device) if (m_controlState == state) { @@ -328,7 +331,7 @@ Device::GroupControlState Device::controlState() return m_controlState; } -bool Device::saveFrame(const AVFrame* frame) +bool Device::saveFrame(const AVFrame *frame) { if (!frame) { return false; @@ -336,7 +339,7 @@ bool Device::saveFrame(const AVFrame* frame) // create buffer QImage rgbImage(frame->width, frame->height, QImage::Format_RGB32); - AVFrame* rgbFrame = av_frame_alloc(); + AVFrame *rgbFrame = av_frame_alloc(); if (!rgbFrame) { return false; } diff --git a/QtScrcpy/device/device.h b/QtScrcpy/device/device.h index 041ad8e..de8b109 100644 --- a/QtScrcpy/device/device.h +++ b/QtScrcpy/device/device.h @@ -22,20 +22,22 @@ class Device : public QObject { Q_OBJECT public: - struct DeviceParams { - QString recordFileName = ""; // 视频录制文件名 - QString serial = ""; // 设备序列号 - 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; // 是否显示画面(或者仅仅后台录制) - QString gameScript = ""; // 游戏映射脚本 - bool renderExpiredFrames = false; // 是否渲染延迟视频帧 + struct DeviceParams + { + QString recordFileName = ""; // 视频录制文件名 + QString serial = ""; // 设备序列号 + 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; // 是否显示画面(或者仅仅后台录制) + QString gameScript = ""; // 游戏映射脚本 + bool renderExpiredFrames = false; // 是否渲染延迟视频帧 }; - enum GroupControlState { + enum GroupControlState + { GCS_FREE = 0, GCS_HOST, GCS_CLIENT, @@ -67,37 +69,37 @@ signals: void expandNotificationPanel(); void collapseNotificationPanel(); void postBackOrScreenOn(); - void postTextInput(QString& text); + void postTextInput(QString &text); void requestDeviceClipboard(); void setDeviceClipboard(); void clipboardPaste(); - void pushFileRequest(const QString& serial, const QString& file, const QString& devicePath = ""); - void installApkRequest(const QString& serial, const QString& apkFile); + void pushFileRequest(const QString &serial, const QString &file, const QString &devicePath = ""); + void installApkRequest(const QString &serial, const QString &apkFile); // key map - void mouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); - void wheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); - void keyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize); + void mouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize); + void wheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize); + void keyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize); // self connect signal and slots void screenshot(); void showTouch(bool show); - void setControlState(Device* device, Device::GroupControlState state); + void setControlState(Device *device, Device::GroupControlState state); void grabCursor(bool grab); // for notify - void controlStateChange(Device* device, Device::GroupControlState oldState, Device::GroupControlState newState); + void controlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState); public slots: void onScreenshot(); void onShowTouch(bool show); - void onSetControlState(Device* device, Device::GroupControlState state); + void onSetControlState(Device *device, Device::GroupControlState state); void onGrabCursor(bool grab); private: void initSignals(); void startServer(); - bool saveFrame(const AVFrame* frame); + bool saveFrame(const AVFrame *frame); private: // server relevant @@ -106,8 +108,8 @@ private: QPointer m_controller; QPointer m_fileHandler; QPointer m_stream; - VideoBuffer* m_vb = Q_NULLPTR; - Recorder* m_recorder = Q_NULLPTR; + VideoBuffer *m_vb = Q_NULLPTR; + Recorder *m_recorder = Q_NULLPTR; // ui QPointer m_videoForm; diff --git a/QtScrcpy/device/filehandler/filehandler.cpp b/QtScrcpy/device/filehandler/filehandler.cpp index 4730f6c..a687ee8 100644 --- a/QtScrcpy/device/filehandler/filehandler.cpp +++ b/QtScrcpy/device/filehandler/filehandler.cpp @@ -1,9 +1,8 @@ #include "filehandler.h" -FileHandler::FileHandler(QObject *parent) - : QObject (parent) +FileHandler::FileHandler(QObject *parent) : QObject(parent) { - connect(&m_adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){ + connect(&m_adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult) { switch (processResult) { case AdbProcess::AER_ERROR_START: case AdbProcess::AER_ERROR_EXEC: @@ -19,12 +18,9 @@ FileHandler::FileHandler(QObject *parent) }); } -FileHandler::~FileHandler() -{ +FileHandler::~FileHandler() {} -} - -void FileHandler::onPushFileRequest(const QString &serial, const QString &file, const QString& devicePath) +void FileHandler::onPushFileRequest(const QString &serial, const QString &file, const QString &devicePath) { if (m_adb.isRuning()) { emit fileHandlerResult(FAR_IS_RUNNING, false); diff --git a/QtScrcpy/device/filehandler/filehandler.h b/QtScrcpy/device/filehandler/filehandler.h index 8c48db1..6dbc9ca 100644 --- a/QtScrcpy/device/filehandler/filehandler.h +++ b/QtScrcpy/device/filehandler/filehandler.h @@ -8,10 +8,11 @@ class FileHandler : public QObject { Q_OBJECT public: - enum FILE_HANDLER_RESULT { - FAR_IS_RUNNING, // 正在执行 - FAR_SUCCESS_EXEC, // 执行成功 - FAR_ERROR_EXEC, // 执行失败 + enum FILE_HANDLER_RESULT + { + FAR_IS_RUNNING, // 正在执行 + FAR_SUCCESS_EXEC, // 执行成功 + FAR_ERROR_EXEC, // 执行失败 }; FileHandler(QObject *parent = nullptr); @@ -20,8 +21,8 @@ public: const QString &getDevicePath(); public slots: - void onPushFileRequest(const QString& serial, const QString& file, const QString& devicePath = ""); - void onInstallApkRequest(const QString& serial, const QString& apkFile); + void onPushFileRequest(const QString &serial, const QString &file, const QString &devicePath = ""); + void onInstallApkRequest(const QString &serial, const QString &apkFile); signals: void fileHandlerResult(FILE_HANDLER_RESULT processResult, bool isApk = false); diff --git a/QtScrcpy/device/recorder/recorder.cpp b/QtScrcpy/device/recorder/recorder.cpp index b01d1cb..2bd29eb 100644 --- a/QtScrcpy/device/recorder/recorder.cpp +++ b/QtScrcpy/device/recorder/recorder.cpp @@ -1,25 +1,19 @@ +#include #include #include -#include #include "compat.h" #include "recorder.h" -static const AVRational SCRCPY_TIME_BASE = {1, 1000000}; // timestamps in us +static const AVRational SCRCPY_TIME_BASE = { 1, 1000000 }; // timestamps in us -Recorder::Recorder(const QString& fileName, QObject* parent) - : QThread(parent) - , m_fileName(fileName) - , m_format(guessRecordFormat(fileName)) +Recorder::Recorder(const QString &fileName, QObject *parent) : QThread(parent), m_fileName(fileName), m_format(guessRecordFormat(fileName)) {} + +Recorder::~Recorder() {} + +AVPacket *Recorder::packetNew(const AVPacket *packet) { -} - -Recorder::~Recorder() -{ -} - -AVPacket* Recorder::packetNew(const AVPacket *packet) { - AVPacket* rec = new AVPacket; + AVPacket *rec = new AVPacket; if (!rec) { return Q_NULLPTR; } @@ -34,7 +28,8 @@ AVPacket* Recorder::packetNew(const AVPacket *packet) { return rec; } -void Recorder::packetDelete(AVPacket* packet) { +void Recorder::packetDelete(AVPacket *packet) +{ av_packet_unref(packet); delete packet; } @@ -56,11 +51,11 @@ void Recorder::setFormat(Recorder::RecorderFormat format) m_format = format; } -bool Recorder::open(const AVCodec* inputCodec) +bool Recorder::open(const AVCodec *inputCodec) { QString formatName = recorderGetFormatName(m_format); Q_ASSERT(!formatName.isEmpty()); - const AVOutputFormat* format = findMuxer(formatName.toUtf8()); + const AVOutputFormat *format = findMuxer(formatName.toUtf8()); if (!format) { qCritical("Could not find muxer"); return false; @@ -77,13 +72,12 @@ bool Recorder::open(const AVCodec* inputCodec) // still expects a pointer-to-non-const (it has not be updated accordingly) // - m_formatCtx->oformat = (AVOutputFormat*)format; + m_formatCtx->oformat = (AVOutputFormat *)format; QString comment = "Recorded by QtScrcpy " + QCoreApplication::applicationVersion(); - av_dict_set(&m_formatCtx->metadata, "comment", - comment.toUtf8(), 0); + av_dict_set(&m_formatCtx->metadata, "comment", comment.toUtf8(), 0); - AVStream* outStream = avformat_new_stream(m_formatCtx, inputCodec); + AVStream *outStream = avformat_new_stream(m_formatCtx, inputCodec); if (!outStream) { avformat_free_context(m_formatCtx); m_formatCtx = Q_NULLPTR; @@ -102,10 +96,9 @@ bool Recorder::open(const AVCodec* inputCodec) outStream->codec->pix_fmt = AV_PIX_FMT_YUV420P; outStream->codec->width = m_declaredFrameSize.width(); outStream->codec->height = m_declaredFrameSize.height(); -#endif +#endif - int ret = avio_open(&m_formatCtx->pb, m_fileName.toUtf8().toStdString().c_str(), - AVIO_FLAG_WRITE); + int ret = avio_open(&m_formatCtx->pb, m_fileName.toUtf8().toStdString().c_str(), AVIO_FLAG_WRITE); if (ret < 0) { char errorbuf[255] = { 0 }; av_strerror(ret, errorbuf, 254); @@ -164,12 +157,12 @@ bool Recorder::write(AVPacket *packet) return av_write_frame(m_formatCtx, packet) >= 0; } -const AVOutputFormat *Recorder::findMuxer(const char* name) +const AVOutputFormat *Recorder::findMuxer(const char *name) { #ifdef QTSCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API - void* opaque = Q_NULLPTR; + void *opaque = Q_NULLPTR; #endif - const AVOutputFormat* outFormat = Q_NULLPTR; + const AVOutputFormat *outFormat = Q_NULLPTR; do { #ifdef QTSCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API outFormat = av_muxer_iterate(&opaque); @@ -181,10 +174,10 @@ const AVOutputFormat *Recorder::findMuxer(const char* name) return outFormat; } -bool Recorder::recorderWriteHeader(const AVPacket* packet) +bool Recorder::recorderWriteHeader(const AVPacket *packet) { AVStream *ostream = m_formatCtx->streams[0]; - quint8* extradata = (quint8*)av_malloc(packet->size * sizeof(quint8)); + quint8 *extradata = (quint8 *)av_malloc(packet->size * sizeof(quint8)); if (!extradata) { qCritical("Cannot allocate extradata"); return false; @@ -208,7 +201,7 @@ bool Recorder::recorderWriteHeader(const AVPacket* packet) return true; } -void Recorder::recorderRescalePacket(AVPacket* packet) +void Recorder::recorderRescalePacket(AVPacket *packet) { AVStream *ostream = m_formatCtx->streams[0]; av_packet_rescale_ts(packet, SCRCPY_TIME_BASE, ostream->time_base); @@ -217,9 +210,12 @@ void Recorder::recorderRescalePacket(AVPacket* packet) QString Recorder::recorderGetFormatName(Recorder::RecorderFormat format) { switch (format) { - case RECORDER_FORMAT_MP4: return "mp4"; - case RECORDER_FORMAT_MKV: return "matroska"; - default: return ""; + case RECORDER_FORMAT_MP4: + return "mp4"; + case RECORDER_FORMAT_MKV: + return "matroska"; + default: + return ""; } } @@ -240,7 +236,8 @@ Recorder::RecorderFormat Recorder::guessRecordFormat(const QString &fileName) return Recorder::RECORDER_FORMAT_NULL; } -void Recorder::run() { +void Recorder::run() +{ for (;;) { AVPacket *rec = Q_NULLPTR; { @@ -252,7 +249,7 @@ void Recorder::run() { // if stopped is set, continue to process the remaining events (to // finish the recording) before actually stopping if (m_stopped && m_queue.isEmpty()) { - AVPacket* last = m_previous; + AVPacket *last = m_previous; if (last) { // assign an arbitrary duration to the last packet last->duration = 100000; @@ -272,7 +269,7 @@ void Recorder::run() { } // recorder->previous is only written from this thread, no need to lock - AVPacket* previous = m_previous; + AVPacket *previous = m_previous; m_previous = rec; if (!previous) { @@ -281,8 +278,7 @@ void Recorder::run() { } // config packets have no PTS, we must ignore them - if (rec->pts != AV_NOPTS_VALUE - && previous->pts != AV_NOPTS_VALUE) { + if (rec->pts != AV_NOPTS_VALUE && previous->pts != AV_NOPTS_VALUE) { // we now know the duration of the previous packet previous->duration = rec->pts - previous->pts; } @@ -302,18 +298,21 @@ void Recorder::run() { qDebug("Recorder thread ended"); } -bool Recorder::startRecorder() { +bool Recorder::startRecorder() +{ start(); return true; } -void Recorder::stopRecorder() { +void Recorder::stopRecorder() +{ QMutexLocker locker(&m_mutex); m_stopped = true; m_recvDataCond.wakeOne(); } -bool Recorder::push(const AVPacket *packet) { +bool Recorder::push(const AVPacket *packet) +{ QMutexLocker locker(&m_mutex); Q_ASSERT(!m_stopped); @@ -322,7 +321,7 @@ bool Recorder::push(const AVPacket *packet) { return false; } - AVPacket* rec = packetNew(packet); + AVPacket *rec = packetNew(packet); if (rec) { m_queue.enqueue(rec); m_recvDataCond.wakeOne(); diff --git a/QtScrcpy/device/recorder/recorder.h b/QtScrcpy/device/recorder/recorder.h index cdbe72a..1691f38 100644 --- a/QtScrcpy/device/recorder/recorder.h +++ b/QtScrcpy/device/recorder/recorder.h @@ -1,11 +1,11 @@ #ifndef RECORDER_H #define RECORDER_H -#include -#include -#include #include -#include #include +#include +#include +#include +#include extern "C" { @@ -16,34 +16,35 @@ class Recorder : public QThread { Q_OBJECT public: - enum RecorderFormat { + enum RecorderFormat + { RECORDER_FORMAT_NULL = 0, RECORDER_FORMAT_MP4, RECORDER_FORMAT_MKV, }; - Recorder(const QString& fileName, QObject *parent = Q_NULLPTR); + Recorder(const QString &fileName, QObject *parent = Q_NULLPTR); virtual ~Recorder(); - void setFrameSize(const QSize& declaredFrameSize); + void setFrameSize(const QSize &declaredFrameSize); void setFormat(Recorder::RecorderFormat format); - bool open(const AVCodec* inputCodec); + bool open(const AVCodec *inputCodec); void close(); - bool write(AVPacket* packet); + bool write(AVPacket *packet); bool startRecorder(); void stopRecorder(); bool push(const AVPacket *packet); private: - const AVOutputFormat* findMuxer(const char* name); - bool recorderWriteHeader(const AVPacket* packet); + const AVOutputFormat *findMuxer(const char *name); + bool recorderWriteHeader(const AVPacket *packet); void recorderRescalePacket(AVPacket *packet); QString recorderGetFormatName(Recorder::RecorderFormat format); - RecorderFormat guessRecordFormat(const QString& fileName); + RecorderFormat guessRecordFormat(const QString &fileName); private: - AVPacket* packetNew(const AVPacket *packet); - void packetDelete(AVPacket* packet); + AVPacket *packetNew(const AVPacket *packet); + void packetDelete(AVPacket *packet); void queueClear(); protected: @@ -51,20 +52,20 @@ protected: private: QString m_fileName = ""; - AVFormatContext* m_formatCtx = Q_NULLPTR; + AVFormatContext *m_formatCtx = Q_NULLPTR; QSize m_declaredFrameSize; bool m_headerWritten = false; RecorderFormat m_format = RECORDER_FORMAT_NULL; QMutex m_mutex; QWaitCondition m_recvDataCond; bool m_stopped = false; // set on recorder_stop() by the stream reader - bool m_failed = false; // set on packet write failure - QQueue m_queue; + bool m_failed = false; // set on packet write failure + QQueue m_queue; // we can write a packet only once we received the next one so that we can // set its duration (next_pts - current_pts) // "previous" is only accessed from the recorder thread, so it does not // need to be protected by the mutex - AVPacket* m_previous = Q_NULLPTR; + AVPacket *m_previous = Q_NULLPTR; }; #endif // RECORDER_H diff --git a/QtScrcpy/device/render/qyuvopenglwidget.cpp b/QtScrcpy/device/render/qyuvopenglwidget.cpp index 232c523..44572b7 100644 --- a/QtScrcpy/device/render/qyuvopenglwidget.cpp +++ b/QtScrcpy/device/render/qyuvopenglwidget.cpp @@ -14,18 +14,30 @@ static const GLfloat coordinate[] = { // GL_TRIANGLE_STRIP的绘制方式: // 使用前3个坐标绘制一个三角形,使用后三个坐标绘制一个三角形,正好为一个矩形 // x y z - -1.0f, -1.0f, 0.0f, - 1.0f, -1.0f, 0.0f, - -1.0f, 1.0f, 0.0f, - 1.0f, 1.0f, 0.0f, + -1.0f, + -1.0f, + 0.0f, + 1.0f, + -1.0f, + 0.0f, + -1.0f, + 1.0f, + 0.0f, + 1.0f, + 1.0f, + 0.0f, // 纹理坐标,存储4个xy坐标 // 坐标范围为[0,1],左下角为 0,0 // TODO 为什么这个顺序指定四个顶点?顶点坐标和纹理坐标如何映射的? - 0.0f, 1.0f, - 1.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 0.0f + 0.0f, + 1.0f, + 1.0f, + 1.0f, + 0.0f, + 0.0f, + 1.0f, + 0.0f }; // 顶点着色器 @@ -107,7 +119,7 @@ void QYUVOpenGLWidget::setFrameSize(const QSize &frameSize) } } -const QSize& QYUVOpenGLWidget::frameSize() +const QSize &QYUVOpenGLWidget::frameSize() { return m_frameSize; } @@ -133,13 +145,13 @@ void QYUVOpenGLWidget::initializeGL() m_vbo.allocate(coordinate, sizeof(coordinate)); initShader(); // 设置背景清理色为黑色 - glClearColor(0.0,0.0,0.0,0.0); + glClearColor(0.0, 0.0, 0.0, 0.0); // 清理颜色背景 - glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT); } void QYUVOpenGLWidget::paintGL() -{ +{ if (m_needUpdate) { deInitTextures(); initTextures(); @@ -198,7 +210,7 @@ void QYUVOpenGLWidget::initShader() } void QYUVOpenGLWidget::initTextures() -{ +{ // 创建纹理 glGenTextures(1, &m_texture[0]); glBindTexture(GL_TEXTURE_2D, m_texture[0]); @@ -216,7 +228,7 @@ void QYUVOpenGLWidget::initTextures() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, m_frameSize.width()/2, m_frameSize.height()/2, 0, GL_RED, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, m_frameSize.width() / 2, m_frameSize.height() / 2, 0, GL_RED, GL_UNSIGNED_BYTE, NULL); glGenTextures(1, &m_texture[2]); glBindTexture(GL_TEXTURE_2D, m_texture[2]); @@ -226,7 +238,7 @@ void QYUVOpenGLWidget::initTextures() // 设置st方向上纹理超出坐标时的显示策略 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, m_frameSize.width()/2, m_frameSize.height()/2, 0, GL_RED, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, m_frameSize.width() / 2, m_frameSize.height() / 2, 0, GL_RED, GL_UNSIGNED_BYTE, NULL); m_textureInited = true; } @@ -246,7 +258,7 @@ void QYUVOpenGLWidget::updateTexture(GLuint texture, quint32 textureType, quint8 if (!pixels) return; - QSize size = 0 == textureType ? m_frameSize : m_frameSize/2; + QSize size = 0 == textureType ? m_frameSize : m_frameSize / 2; makeCurrent(); glBindTexture(GL_TEXTURE_2D, texture); diff --git a/QtScrcpy/device/render/qyuvopenglwidget.h b/QtScrcpy/device/render/qyuvopenglwidget.h index d9d4f1b..949b4ac 100644 --- a/QtScrcpy/device/render/qyuvopenglwidget.h +++ b/QtScrcpy/device/render/qyuvopenglwidget.h @@ -1,11 +1,13 @@ #ifndef QYUVOPENGLWIDGET_H #define QYUVOPENGLWIDGET_H -#include +#include #include #include -#include +#include -class QYUVOpenGLWidget : public QOpenGLWidget, protected QOpenGLFunctions +class QYUVOpenGLWidget + : public QOpenGLWidget + , protected QOpenGLFunctions { Q_OBJECT public: @@ -15,24 +17,24 @@ public: QSize minimumSizeHint() const override; QSize sizeHint() const override; - void setFrameSize(const QSize& frameSize); - const QSize& frameSize(); - void updateTextures(quint8* dataY, quint8* dataU, quint8* dataV, quint32 linesizeY, quint32 linesizeU, quint32 linesizeV); + void setFrameSize(const QSize &frameSize); + const QSize &frameSize(); + void updateTextures(quint8 *dataY, quint8 *dataU, quint8 *dataV, quint32 linesizeY, quint32 linesizeU, quint32 linesizeV); protected: void initializeGL(); void paintGL(); void resizeGL(int width, int height); -private: +private: void initShader(); void initTextures(); void deInitTextures(); - void updateTexture(GLuint texture, quint32 textureType, quint8* pixels, quint32 stride); + void updateTexture(GLuint texture, quint32 textureType, quint8 *pixels, quint32 stride); private: // 视频帧尺寸 - QSize m_frameSize = {-1, -1}; + QSize m_frameSize = { -1, -1 }; bool m_needUpdate = false; bool m_textureInited = false; @@ -40,10 +42,10 @@ private: QOpenGLBuffer m_vbo; // 着色器程序:编译链接着色器 - QOpenGLShaderProgram m_shaderProgram; + QOpenGLShaderProgram m_shaderProgram; // YUV纹理,用于生成纹理贴图 - GLuint m_texture[3] = {0}; + GLuint m_texture[3] = { 0 }; }; #endif // QYUVOPENGLWIDGET_H diff --git a/QtScrcpy/device/server/server.cpp b/QtScrcpy/device/server/server.cpp index c79ad83..2226980 100644 --- a/QtScrcpy/device/server/server.cpp +++ b/QtScrcpy/device/server/server.cpp @@ -1,12 +1,12 @@ -#include -#include -#include -#include #include +#include #include +#include +#include +#include -#include "server.h" #include "config.h" +#include "server.h" #define DEVICE_NAME_FIELD_LENGTH 64 #define SOCKET_NAME "scrcpy" @@ -18,10 +18,10 @@ Server::Server(QObject *parent) : QObject(parent) connect(&m_workProcess, &AdbProcess::adbProcessResult, this, &Server::onWorkProcessResult); connect(&m_serverProcess, &AdbProcess::adbProcessResult, this, &Server::onWorkProcessResult); - connect(&m_serverSocket, &QTcpServer::newConnection, this, [this](){ - QTcpSocket* tmp = m_serverSocket.nextPendingConnection(); - if (dynamic_cast(tmp)) { - m_videoSocket = dynamic_cast(tmp); + connect(&m_serverSocket, &QTcpServer::newConnection, this, [this]() { + QTcpSocket *tmp = m_serverSocket.nextPendingConnection(); + if (dynamic_cast(tmp)) { + m_videoSocket = dynamic_cast(tmp); if (!m_videoSocket->isValid() || !readInfo(m_videoSocket, m_deviceName, m_deviceSize)) { stop(); emit connectToResult(false); @@ -45,12 +45,9 @@ Server::Server(QObject *parent) : QObject(parent) }); } -Server:: ~Server() -{ +Server::~Server() {} -} - -const QString& Server::getServerPath() +const QString &Server::getServerPath() { if (m_serverPath.isEmpty()) { m_serverPath = QString::fromLocal8Bit(qgetenv("QTSCRCPY_SERVER_PATH")); @@ -63,7 +60,7 @@ const QString& Server::getServerPath() } bool Server::pushServer() -{ +{ if (m_workProcess.isRuning()) { m_workProcess.kill(); } @@ -82,11 +79,11 @@ bool Server::enableTunnelReverse() bool Server::disableTunnelReverse() { - AdbProcess* adb = new AdbProcess(); + AdbProcess *adb = new AdbProcess(); if (!adb) { return false; } - connect(adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){ + connect(adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult) { if (AdbProcess::AER_SUCCESS_START != processResult) { sender()->deleteLater(); } @@ -105,11 +102,11 @@ bool Server::enableTunnelForward() } bool Server::disableTunnelForward() { - AdbProcess* adb = new AdbProcess(); + AdbProcess *adb = new AdbProcess(); if (!adb) { return false; } - connect(adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){ + connect(adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult) { if (AdbProcess::AER_SUCCESS_START != processResult) { sender()->deleteLater(); } @@ -150,7 +147,7 @@ bool Server::execute() } bool Server::start(Server::ServerParams params) -{ +{ m_params = params; m_serverStartStep = SSS_PUSH; return startServerByStep(); @@ -161,7 +158,7 @@ bool Server::connectTo() if (SSS_RUNNING != m_serverStartStep) { qWarning("server not run"); return false; - } + } if (!m_tunnelForward && !m_videoSocket) { startAcceptTimeoutTimer(); @@ -192,8 +189,8 @@ void Server::timerEvent(QTimerEvent *event) } } -VideoSocket* Server::getVideoSocket() -{ +VideoSocket *Server::getVideoSocket() +{ return m_videoSocket; } @@ -228,8 +225,8 @@ void Server::stop() } m_tunnelForward = false; m_tunnelEnabled = false; - } - m_serverSocket.close(); + } + m_serverSocket.close(); } bool Server::startServerByStep() @@ -283,14 +280,14 @@ bool Server::startServerByStep() return stepSuccess; } -bool Server::readInfo(VideoSocket* videoSocket, QString &deviceName, QSize &size) +bool Server::readInfo(VideoSocket *videoSocket, QString &deviceName, QSize &size) { unsigned char buf[DEVICE_NAME_FIELD_LENGTH + 4]; if (videoSocket->bytesAvailable() <= (DEVICE_NAME_FIELD_LENGTH + 4)) { videoSocket->waitForReadyRead(300); } - qint64 len = videoSocket->read((char*)buf, sizeof(buf)); + qint64 len = videoSocket->read((char *)buf, sizeof(buf)); if (len < DEVICE_NAME_FIELD_LENGTH + 4) { qInfo("Could not retrieve device information"); return false; @@ -298,7 +295,7 @@ bool Server::readInfo(VideoSocket* videoSocket, QString &deviceName, QSize &size buf[DEVICE_NAME_FIELD_LENGTH - 1] = '\0'; // in case the client sends garbage // strcpy is safe here, since name contains at least DEVICE_NAME_FIELD_LENGTH bytes // and strlen(buf) < DEVICE_NAME_FIELD_LENGTH - deviceName = (char*)buf; + deviceName = (char *)buf; size.setWidth((buf[DEVICE_NAME_FIELD_LENGTH] << 8) | buf[DEVICE_NAME_FIELD_LENGTH + 1]); size.setHeight((buf[DEVICE_NAME_FIELD_LENGTH + 2] << 8) | buf[DEVICE_NAME_FIELD_LENGTH + 3]); return true; @@ -342,7 +339,7 @@ void Server::onConnectTimer() QSize deviceSize; bool success = false; - VideoSocket* videoSocket = new VideoSocket(); + VideoSocket *videoSocket = new VideoSocket(); QTcpSocket *controlSocket = new QTcpSocket(); videoSocket->connectToHost(QHostAddress::LocalHost, m_params.localPort); @@ -427,7 +424,7 @@ void Server::onWorkProcessResult(AdbProcess::ADB_EXEC_RESULT processResult) m_serverStartStep = SSS_ENABLE_TUNNEL_FORWARD; } startServerByStep(); - } else if (AdbProcess::AER_SUCCESS_START != processResult){ + } else if (AdbProcess::AER_SUCCESS_START != processResult) { qCritical("adb push failed"); m_serverStartStep = SSS_NULL; emit serverStartResult(false); @@ -437,7 +434,7 @@ void Server::onWorkProcessResult(AdbProcess::ADB_EXEC_RESULT processResult) if (AdbProcess::AER_SUCCESS_EXEC == processResult) { m_serverStartStep = SSS_EXECUTE_SERVER; startServerByStep(); - } else if (AdbProcess::AER_SUCCESS_START != processResult){ + } else if (AdbProcess::AER_SUCCESS_START != processResult) { // 有一些设备reverse会报错more than o'ne device,adb的bug // https://github.com/Genymobile/scrcpy/issues/5 qCritical("adb reverse failed"); @@ -450,7 +447,7 @@ void Server::onWorkProcessResult(AdbProcess::ADB_EXEC_RESULT processResult) if (AdbProcess::AER_SUCCESS_EXEC == processResult) { m_serverStartStep = SSS_EXECUTE_SERVER; startServerByStep(); - } else if (AdbProcess::AER_SUCCESS_START != processResult){ + } else if (AdbProcess::AER_SUCCESS_START != processResult) { qCritical("adb forward failed"); m_serverStartStep = SSS_NULL; emit serverStartResult(false); @@ -467,7 +464,7 @@ void Server::onWorkProcessResult(AdbProcess::ADB_EXEC_RESULT processResult) m_serverStartStep = SSS_RUNNING; m_tunnelEnabled = true; emit serverStartResult(true); - } else if (AdbProcess::AER_ERROR_START == processResult){ + } else if (AdbProcess::AER_ERROR_START == processResult) { if (!m_tunnelForward) { m_serverSocket.close(); disableTunnelReverse(); diff --git a/QtScrcpy/device/server/server.h b/QtScrcpy/device/server/server.h index 8c21172..d45a573 100644 --- a/QtScrcpy/device/server/server.h +++ b/QtScrcpy/device/server/server.h @@ -5,15 +5,16 @@ #include #include +#include "adbprocess.h" #include "tcpserver.h" #include "videosocket.h" -#include "adbprocess.h" class Server : public QObject { Q_OBJECT - enum SERVER_START_STEP { + enum SERVER_START_STEP + { SSS_NULL, SSS_PUSH, SSS_ENABLE_TUNNEL_REVERSE, @@ -21,16 +22,18 @@ class Server : public QObject SSS_EXECUTE_SERVER, SSS_RUNNING, }; + public: - struct ServerParams { - QString serial = ""; // 设备序列号 - quint16 localPort = 27183; // reverse时本地监听端口 - quint16 maxSize = 720; // 视频分辨率 - quint32 bitRate = 8000000; // 视频比特率 - quint32 maxFps = 60; // 视频最大帧率 - QString crop = "-"; // 视频裁剪 - bool control = true; // 安卓端是否接收键鼠控制 - bool useReverse = true; // true:先使用adb reverse,失败后自动使用adb forward;false:直接使用adb forward + struct ServerParams + { + QString serial = ""; // 设备序列号 + quint16 localPort = 27183; // reverse时本地监听端口 + quint16 maxSize = 720; // 视频分辨率 + quint32 bitRate = 8000000; // 视频比特率 + quint32 maxFps = 60; // 视频最大帧率 + QString crop = "-"; // 视频裁剪 + bool control = true; // 安卓端是否接收键鼠控制 + bool useReverse = true; // true:先使用adb reverse,失败后自动使用adb forward;false:直接使用adb forward }; explicit Server(QObject *parent = nullptr); @@ -41,8 +44,8 @@ public: bool isReverse(); Server::ServerParams getParams(); - VideoSocket* getVideoSocket(); - QTcpSocket* getControlSocket(); + VideoSocket *getVideoSocket(); + QTcpSocket *getControlSocket(); void stop(); @@ -58,15 +61,15 @@ protected: void timerEvent(QTimerEvent *event); private: - const QString& getServerPath(); - bool pushServer(); + const QString &getServerPath(); + bool pushServer(); bool enableTunnelReverse(); bool disableTunnelReverse(); bool enableTunnelForward(); bool disableTunnelForward(); bool execute(); bool startServerByStep(); - bool readInfo(VideoSocket* videoSocket, QString& deviceName, QSize& size); + bool readInfo(VideoSocket *videoSocket, QString &deviceName, QSize &size); void startAcceptTimeoutTimer(); void stopAcceptTimeoutTimer(); void startConnectTimeoutTimer(); diff --git a/QtScrcpy/device/server/tcpserver.cpp b/QtScrcpy/device/server/tcpserver.cpp index c341a6b..9042d28 100644 --- a/QtScrcpy/device/server/tcpserver.cpp +++ b/QtScrcpy/device/server/tcpserver.cpp @@ -1,15 +1,9 @@ #include "tcpserver.h" #include "videosocket.h" -TcpServer::TcpServer(QObject *parent) : QTcpServer(parent) -{ +TcpServer::TcpServer(QObject *parent) : QTcpServer(parent) {} -} - -TcpServer::~TcpServer() -{ - -} +TcpServer::~TcpServer() {} void TcpServer::incomingConnection(qintptr handle) { diff --git a/QtScrcpy/device/server/videosocket.cpp b/QtScrcpy/device/server/videosocket.cpp index ed1fa7b..fae8ff5 100644 --- a/QtScrcpy/device/server/videosocket.cpp +++ b/QtScrcpy/device/server/videosocket.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include #include "qscrcpyevent.h" #include "videosocket.h" @@ -31,7 +31,7 @@ qint32 VideoSocket::subThreadRecvData(quint8 *buf, qint32 bufSize) m_dataSize = 0; // post event - VideoSocketEvent* getDataEvent = new VideoSocketEvent(); + VideoSocketEvent *getDataEvent = new VideoSocketEvent(); QCoreApplication::postEvent(this, getDataEvent); // wait @@ -58,7 +58,7 @@ void VideoSocket::onReadyRead() if (m_buffer && m_bufferSize <= bytesAvailable()) { // recv data qint64 readSize = qMin(bytesAvailable(), (qint64)m_bufferSize); - m_dataSize = read((char*)m_buffer, readSize); + m_dataSize = read((char *)m_buffer, readSize); m_buffer = Q_NULLPTR; m_bufferSize = 0; diff --git a/QtScrcpy/device/server/videosocket.h b/QtScrcpy/device/server/videosocket.h index ef6e6d2..844dc94 100644 --- a/QtScrcpy/device/server/videosocket.h +++ b/QtScrcpy/device/server/videosocket.h @@ -2,8 +2,8 @@ #define VIDEOSOCKET_H #include -#include #include +#include #include class VideoSocket : public QTcpSocket @@ -13,7 +13,7 @@ public: explicit VideoSocket(QObject *parent = nullptr); virtual ~VideoSocket(); - qint32 subThreadRecvData(quint8* buf, qint32 bufSize); + qint32 subThreadRecvData(quint8 *buf, qint32 bufSize); protected: bool event(QEvent *event); @@ -26,7 +26,7 @@ private: QMutex m_mutex; QWaitCondition m_recvDataCond; bool m_recvData = false; - quint8* m_buffer = Q_NULLPTR; + quint8 *m_buffer = Q_NULLPTR; qint32 m_bufferSize = 0; qint32 m_dataSize = 0; bool m_quit = false; diff --git a/QtScrcpy/device/stream/stream.cpp b/QtScrcpy/device/stream/stream.cpp index 9d77f88..17c96de 100644 --- a/QtScrcpy/device/stream/stream.cpp +++ b/QtScrcpy/device/stream/stream.cpp @@ -2,27 +2,23 @@ #include #include "compat.h" -#include "stream.h" #include "decoder.h" -#include "videosocket.h" #include "recorder.h" +#include "stream.h" +#include "videosocket.h" #define BUFSIZE 0x10000 #define HEADER_SIZE 12 #define NO_PTS UINT64_C(-1) -typedef qint32 (*ReadPacketFunc)(void*, quint8*, qint32); +typedef qint32 (*ReadPacketFunc)(void *, quint8 *, qint32); -Stream::Stream(QObject *parent) - : QThread(parent) +Stream::Stream(QObject *parent) : QThread(parent) {} + +Stream::~Stream() {} + +static void avLogCallback(void *avcl, int level, const char *fmt, va_list vl) { -} - -Stream::~Stream() -{ -} - -static void avLogCallback(void *avcl, int level, const char *fmt, va_list vl) { Q_UNUSED(avcl) Q_UNUSED(vl) @@ -68,22 +64,24 @@ void Stream::deInit() avformat_network_deinit(); // ignore failure } -void Stream::setDecoder(Decoder* decoder) +void Stream::setDecoder(Decoder *decoder) { m_decoder = decoder; } -static quint32 bufferRead32be(quint8* buf) { +static quint32 bufferRead32be(quint8 *buf) +{ return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; } -static quint64 bufferRead64be(quint8* buf) { +static quint64 bufferRead64be(quint8 *buf) +{ quint32 msb = bufferRead32be(buf); quint32 lsb = bufferRead32be(&buf[4]); - return ((quint64) msb << 32) | lsb; + return ((quint64)msb << 32) | lsb; } -void Stream::setVideoSocket(VideoSocket* videoSocket) +void Stream::setVideoSocket(VideoSocket *videoSocket) { m_videoSocket = videoSocket; } @@ -93,7 +91,7 @@ void Stream::setRecoder(Recorder *recorder) m_recorder = recorder; } -qint32 Stream::recvData(quint8* buf, qint32 bufSize) +qint32 Stream::recvData(quint8 *buf, qint32 bufSize) { if (!buf) { return 0; @@ -149,16 +147,16 @@ void Stream::run() if (m_recorder) { if (!m_recorder->open(codec)) { - qCritical("Could not open recorder"); - goto runQuit; - } - - if (!m_recorder->startRecorder()) { - qCritical("Could not start recorder"); - goto runQuit; - } + qCritical("Could not open recorder"); + goto runQuit; } + if (!m_recorder->startRecorder()) { + qCritical("Could not start recorder"); + goto runQuit; + } + } + m_parser = av_parser_init(AV_CODEC_ID_H264); if (!m_parser) { qCritical("Could not initialize parser"); @@ -242,12 +240,12 @@ bool Stream::recvPacket(AVPacket *packet) } r = recvData(packet->data, len); - if (r < 0 || ((uint32_t) r) < len) { + if (r < 0 || ((uint32_t)r) < len) { av_packet_unref(packet); return false; } - packet->pts = pts != NO_PTS ? (int64_t) pts : AV_NOPTS_VALUE; + packet->pts = pts != NO_PTS ? (int64_t)pts : AV_NOPTS_VALUE; return true; } @@ -324,13 +322,11 @@ bool Stream::parse(AVPacket *packet) int inLen = packet->size; quint8 *outData = Q_NULLPTR; int outLen = 0; - int r = av_parser_parse2(m_parser, m_codecCtx, - &outData, &outLen, inData, inLen, - AV_NOPTS_VALUE, AV_NOPTS_VALUE, -1); + int r = av_parser_parse2(m_parser, m_codecCtx, &outData, &outLen, inData, inLen, AV_NOPTS_VALUE, AV_NOPTS_VALUE, -1); // PARSER_FLAG_COMPLETE_FRAMES is set Q_ASSERT(r == inLen); - (void) r; + (void)r; Q_ASSERT(outLen == inLen); if (m_parser->key_frame == 1) { diff --git a/QtScrcpy/device/stream/stream.h b/QtScrcpy/device/stream/stream.h index 5031fc1..dc46c87 100644 --- a/QtScrcpy/device/stream/stream.h +++ b/QtScrcpy/device/stream/stream.h @@ -1,8 +1,8 @@ #ifndef STREAM_H #define STREAM_H -#include #include +#include extern "C" { @@ -24,10 +24,10 @@ public: static bool init(); static void deInit(); - void setDecoder(Decoder* decoder); - void setRecoder(Recorder* recorder); - void setVideoSocket(VideoSocket* deviceSocket); - qint32 recvData(quint8* buf, qint32 bufSize); + void setDecoder(Decoder *decoder); + void setRecoder(Recorder *recorder); + void setVideoSocket(VideoSocket *deviceSocket); + qint32 recvData(quint8 *buf, qint32 bufSize); bool startDecode(); void stopDecode(); @@ -36,8 +36,8 @@ signals: protected: void run(); - bool recvPacket(AVPacket* packet); - bool pushPacket(AVPacket* packet); + bool recvPacket(AVPacket *packet); + bool pushPacket(AVPacket *packet); bool processConfigPacket(AVPacket *packet); bool parse(AVPacket *packet); bool processFrame(AVPacket *packet); @@ -45,10 +45,10 @@ protected: private: QPointer m_videoSocket; // for recorder - Recorder* m_recorder = Q_NULLPTR; - Decoder* m_decoder = Q_NULLPTR; + Recorder *m_recorder = Q_NULLPTR; + Decoder *m_decoder = Q_NULLPTR; - AVCodecContext* m_codecCtx = Q_NULLPTR; + AVCodecContext *m_codecCtx = Q_NULLPTR; AVCodecParserContext *m_parser = Q_NULLPTR; // successive packets may need to be concatenated, until a non-config // packet is available diff --git a/QtScrcpy/device/ui/toolform.cpp b/QtScrcpy/device/ui/toolform.cpp index e640bd4..52c898c 100644 --- a/QtScrcpy/device/ui/toolform.cpp +++ b/QtScrcpy/device/ui/toolform.cpp @@ -1,16 +1,14 @@ -#include #include -#include #include +#include +#include +#include "device.h" +#include "iconhelper.h" #include "toolform.h" #include "ui_toolform.h" -#include "iconhelper.h" -#include "device.h" -ToolForm::ToolForm(QWidget* adsorbWidget, AdsorbPositions adsorbPos) - : MagneticWidget(adsorbWidget, adsorbPos) - , ui(new Ui::ToolForm) +ToolForm::ToolForm(QWidget *adsorbWidget, AdsorbPositions adsorbPos) : MagneticWidget(adsorbWidget, adsorbPos), ui(new Ui::ToolForm) { ui->setupUi(this); setWindowFlags(windowFlags() | Qt::FramelessWindowHint); @@ -40,7 +38,7 @@ void ToolForm::initStyle() IconHelper::Instance()->SetIcon(ui->homeBtn, QChar(0xf1db), 15); //IconHelper::Instance()->SetIcon(ui->returnBtn, QChar(0xf104), 15); IconHelper::Instance()->SetIcon(ui->returnBtn, QChar(0xf053), 15); - IconHelper::Instance()->SetIcon(ui->appSwitchBtn, QChar(0xf24d), 15); + IconHelper::Instance()->SetIcon(ui->appSwitchBtn, QChar(0xf24d), 15); IconHelper::Instance()->SetIcon(ui->volumeUpBtn, QChar(0xf028), 15); IconHelper::Instance()->SetIcon(ui->volumeDownBtn, QChar(0xf027), 15); IconHelper::Instance()->SetIcon(ui->closeScreenBtn, QChar(0xf070), 15); @@ -132,7 +130,7 @@ void ToolForm::on_menuBtn_clicked() if (!m_device) { return; } - emit m_device->postGoMenu(); + emit m_device->postGoMenu(); } void ToolForm::on_appSwitchBtn_clicked() diff --git a/QtScrcpy/device/ui/toolform.h b/QtScrcpy/device/ui/toolform.h index 037e55c..19164fe 100644 --- a/QtScrcpy/device/ui/toolform.h +++ b/QtScrcpy/device/ui/toolform.h @@ -1,14 +1,15 @@ #ifndef TOOLFORM_H #define TOOLFORM_H -#include #include +#include -#include "magneticwidget.h" #include "device.h" +#include "magneticwidget.h" -namespace Ui { -class ToolForm; +namespace Ui +{ + class ToolForm; } class Device; @@ -17,7 +18,7 @@ class ToolForm : public MagneticWidget Q_OBJECT public: - explicit ToolForm(QWidget* adsorbWidget, AdsorbPositions adsorbPos); + explicit ToolForm(QWidget *adsorbWidget, AdsorbPositions adsorbPos); ~ToolForm(); void setDevice(Device *device); @@ -45,7 +46,7 @@ private slots: void on_touchBtn_clicked(); void on_groupControlBtn_clicked(); - void onControlStateChange(Device* device, Device::GroupControlState oldState, Device::GroupControlState newState); + void onControlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState); private: void initStyle(); diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index 8fea7db..c6b9428 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -1,34 +1,31 @@ #include -#include -#include -#include -#include -#include -#include -#include #include #include -#include -#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include -#include "videoform.h" -#include "qyuvopenglwidget.h" -#include "ui_videoform.h" -#include "iconhelper.h" -#include "toolform.h" -#include "device.h" -#include "controller.h" #include "config.h" +#include "controller.h" +#include "device.h" +#include "iconhelper.h" +#include "qyuvopenglwidget.h" +#include "toolform.h" +#include "ui_videoform.h" +#include "videoform.h" extern "C" { #include "libavutil/frame.h" } -VideoForm::VideoForm(bool framelessWindow, bool skin, QWidget *parent) - : QWidget(parent) - , ui(new Ui::videoForm) - , m_skin(skin) +VideoForm::VideoForm(bool framelessWindow, bool skin, QWidget *parent) : QWidget(parent), ui(new Ui::videoForm), m_skin(skin) { ui->setupUi(this); initUI(); @@ -80,8 +77,7 @@ QRect VideoForm::getGrabCursorRect() { QRect rc; #if defined(Q_OS_WIN32) - rc = QRect(m_videoWidget->mapToGlobal(m_videoWidget->pos()) - , m_videoWidget->size()); + rc = QRect(m_videoWidget->mapToGlobal(m_videoWidget->pos()), m_videoWidget->size()); // high dpi support rc.setTopLeft(rc.topLeft() * m_videoWidget->devicePixelRatio()); rc.setBottomRight(rc.bottomRight() * m_videoWidget->devicePixelRatio()); @@ -130,8 +126,7 @@ void VideoForm::updateRender(const AVFrame *frame) updateShowSize(QSize(frame->width, frame->height)); m_videoWidget->setFrameSize(QSize(frame->width, frame->height)); - m_videoWidget->updateTextures(frame->data[0], frame->data[1], frame->data[2], - frame->linesize[0], frame->linesize[1], frame->linesize[2]); + m_videoWidget->updateTextures(frame->data[0], frame->data[1], frame->data[2], frame->linesize[0], frame->linesize[1], frame->linesize[2]); } void VideoForm::showToolForm(bool show) @@ -157,146 +152,141 @@ void VideoForm::moveCenter() void VideoForm::installShortcut() { - QShortcut *shortcut = nullptr; + QShortcut *shortcut = nullptr; - // switchFullScreen - shortcut = new QShortcut(QKeySequence("Ctrl+f"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->switchFullScreen(); - }); + // switchFullScreen + shortcut = new QShortcut(QKeySequence("Ctrl+f"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->switchFullScreen(); + }); - // resizeSquare - shortcut = new QShortcut(QKeySequence("Ctrl+g"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - resizeSquare(); - }); + // resizeSquare + shortcut = new QShortcut(QKeySequence("Ctrl+g"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { resizeSquare(); }); - // removeBlackRect - shortcut = new QShortcut(QKeySequence("Ctrl+x"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - removeBlackRect(); - }); + // removeBlackRect + shortcut = new QShortcut(QKeySequence("Ctrl+x"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { removeBlackRect(); }); + // postGoHome + shortcut = new QShortcut(QKeySequence("Ctrl+h"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->postGoHome(); + }); - // postGoHome - shortcut = new QShortcut(QKeySequence("Ctrl+h"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->postGoHome(); - }); + // postGoBack + shortcut = new QShortcut(QKeySequence("Ctrl+b"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->postGoBack(); + }); - // postGoBack - shortcut = new QShortcut(QKeySequence("Ctrl+b"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->postGoBack(); - }); + // postAppSwitch + shortcut = new QShortcut(QKeySequence("Ctrl+s"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->postAppSwitch(); + }); - // postAppSwitch - shortcut = new QShortcut(QKeySequence("Ctrl+s"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->postAppSwitch(); - }); + // postGoMenu + shortcut = new QShortcut(QKeySequence("Ctrl+m"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->postGoMenu(); + }); - // postGoMenu - shortcut = new QShortcut(QKeySequence("Ctrl+m"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->postGoMenu(); - }); + // postVolumeUp + shortcut = new QShortcut(QKeySequence("Ctrl+up"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->postVolumeUp(); + }); - // postVolumeUp - shortcut = new QShortcut(QKeySequence("Ctrl+up"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->postVolumeUp(); - }); + // postVolumeDown + shortcut = new QShortcut(QKeySequence("Ctrl+down"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->postVolumeDown(); + }); - // postVolumeDown - shortcut = new QShortcut(QKeySequence("Ctrl+down"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->postVolumeDown(); - }); + // postPower + shortcut = new QShortcut(QKeySequence("Ctrl+p"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->postPower(); + }); - // postPower - shortcut = new QShortcut(QKeySequence("Ctrl+p"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->postPower(); - }); + // setScreenPowerMode(ControlMsg::SPM_OFF) + shortcut = new QShortcut(QKeySequence("Ctrl+o"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->setScreenPowerMode(ControlMsg::SPM_OFF); + }); - // setScreenPowerMode(ControlMsg::SPM_OFF) - shortcut = new QShortcut(QKeySequence("Ctrl+o"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->setScreenPowerMode(ControlMsg::SPM_OFF); - }); + // expandNotificationPanel + shortcut = new QShortcut(QKeySequence("Ctrl+n"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->expandNotificationPanel(); + }); - // expandNotificationPanel - shortcut = new QShortcut(QKeySequence("Ctrl+n"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->expandNotificationPanel(); - }); + // collapseNotificationPanel + shortcut = new QShortcut(QKeySequence("Ctrl+Shift+n"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->collapseNotificationPanel(); + }); - // collapseNotificationPanel - shortcut = new QShortcut(QKeySequence("Ctrl+Shift+n"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->collapseNotificationPanel(); - }); + // requestDeviceClipboard + shortcut = new QShortcut(QKeySequence("Ctrl+c"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->requestDeviceClipboard(); + }); - // requestDeviceClipboard - shortcut = new QShortcut(QKeySequence("Ctrl+c"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->requestDeviceClipboard(); - }); + // clipboardPaste + shortcut = new QShortcut(QKeySequence("Ctrl+v"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->clipboardPaste(); + }); - // clipboardPaste - shortcut = new QShortcut(QKeySequence("Ctrl+v"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->clipboardPaste(); - }); - - // setDeviceClipboard - shortcut = new QShortcut(QKeySequence("Ctrl+Shift+v"), this); - connect(shortcut, &QShortcut::activated, this, [this](){ - if (!m_device) { - return; - } - emit m_device->setDeviceClipboard(); - }); + // setDeviceClipboard + shortcut = new QShortcut(QKeySequence("Ctrl+Shift+v"), this); + connect(shortcut, &QShortcut::activated, this, [this]() { + if (!m_device) { + return; + } + emit m_device->setDeviceClipboard(); + }); } QRect VideoForm::getScreenRect() @@ -368,7 +358,7 @@ void VideoForm::updateShowSize(const QSize &newSize) showSize.setHeight(qMin(newSize.height(), screenRect.height() - 200)); showSize.setWidth(showSize.height() * m_widthHeightRatio); } else { - showSize.setWidth(qMin(newSize.width(), screenRect.width()/2)); + showSize.setWidth(qMin(newSize.width(), screenRect.width() / 2)); showSize.setHeight(showSize.width() / m_widthHeightRatio); } @@ -517,7 +507,7 @@ void VideoForm::mouseMoveEvent(QMouseEvent *event) } event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint())); emit m_device->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); - } else if (!m_dragPosition.isNull()){ + } else if (!m_dragPosition.isNull()) { if (event->buttons() & Qt::LeftButton) { move(event->globalPos() - m_dragPosition); event->accept(); @@ -527,8 +517,7 @@ void VideoForm::mouseMoveEvent(QMouseEvent *event) void VideoForm::mouseDoubleClickEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton - && !m_videoWidget->geometry().contains(event->pos())) { + if (event->button() == Qt::LeftButton && !m_videoWidget->geometry().contains(event->pos())) { removeBlackRect(); } @@ -549,8 +538,7 @@ void VideoForm::wheelEvent(QWheelEvent *event) Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient = Qt::Vertical); */ - QWheelEvent wheelEvent(pos, event->globalPosF(), event->delta(), - event->buttons(), event->modifiers(), event->orientation()); + QWheelEvent wheelEvent(pos, event->globalPosF(), event->delta(), event->buttons(), event->modifiers(), event->orientation()); emit m_device->wheelEvent(&wheelEvent, m_videoWidget->frameSize(), m_videoWidget->size()); } } @@ -560,9 +548,7 @@ void VideoForm::keyPressEvent(QKeyEvent *event) if (!m_device) { return; } - if (Qt::Key_Escape == event->key() - && !event->isAutoRepeat() - && isFullScreen()) { + if (Qt::Key_Escape == event->key() && !event->isAutoRepeat() && isFullScreen()) { emit m_device->switchFullScreen(); } @@ -649,7 +635,7 @@ void VideoForm::dropEvent(QDropEvent *event) if (!m_device) { return; } - const QMimeData* qm = event->mimeData(); + const QMimeData *qm = event->mimeData(); QString file = qm->urls()[0].toLocalFile(); QFileInfo fileInfo(file); diff --git a/QtScrcpy/device/ui/videoform.h b/QtScrcpy/device/ui/videoform.h index c3b4fc6..e000f5a 100644 --- a/QtScrcpy/device/ui/videoform.h +++ b/QtScrcpy/device/ui/videoform.h @@ -1,11 +1,12 @@ #ifndef VIDEOFORM_H #define VIDEOFORM_H -#include #include +#include -namespace Ui { -class videoForm; +namespace Ui +{ + class videoForm; } struct AVFrame; @@ -32,11 +33,11 @@ public: public slots: void onSwitchFullScreen(); -private: +private: void updateStyleSheet(bool vertical); QMargins getMargins(bool vertical); void initUI(); - + void showToolForm(bool show = true); void moveCenter(); void installShortcut(); @@ -63,7 +64,7 @@ protected: private: // ui - Ui::videoForm *ui; + Ui::videoForm *ui; QPointer m_toolForm; QPointer m_loadingWidget; QPointer m_videoWidget; diff --git a/QtScrcpy/devicemanage/devicemanage.cpp b/QtScrcpy/devicemanage/devicemanage.cpp index 75f5465..f6ad67e 100644 --- a/QtScrcpy/devicemanage/devicemanage.cpp +++ b/QtScrcpy/devicemanage/devicemanage.cpp @@ -1,7 +1,7 @@ #include +#include #include #include -#include #include "devicemanage.h" #include "server.h" @@ -9,15 +9,9 @@ #define DM_MAX_DEVICES_NUM 16 -DeviceManage::DeviceManage(QObject *parent) : QObject(parent) -{ +DeviceManage::DeviceManage(QObject *parent) : QObject(parent) {} -} - -DeviceManage::~DeviceManage() -{ - -} +DeviceManage::~DeviceManage() {} bool DeviceManage::connectDevice(Device::DeviceParams params) { @@ -195,8 +189,7 @@ void DeviceManage::onControlStateChange(Device *device, Device::GroupControlStat return; } // free to host - if (oldState == Device::GroupControlState::GCS_FREE - && newState == Device::GroupControlState::GCS_HOST) { + if (oldState == Device::GroupControlState::GCS_FREE && newState == Device::GroupControlState::GCS_HOST) { // install direct control signals setGroupControlHost(device, true); // install convert control signals(frameSize need convert) @@ -206,8 +199,7 @@ void DeviceManage::onControlStateChange(Device *device, Device::GroupControlStat return; } // host to free - if (oldState == Device::GroupControlState::GCS_HOST - && newState == Device::GroupControlState::GCS_FREE) { + if (oldState == Device::GroupControlState::GCS_HOST && newState == Device::GroupControlState::GCS_FREE) { // uninstall direct control signals setGroupControlHost(device, false); // uninstall convert control signals(frameSize need convert) @@ -268,16 +260,14 @@ void DeviceManage::onKeyEvent(const QKeyEvent *from, const QSize &frameSize, con quint16 DeviceManage::getFreePort() { - quint16 port = m_localPortStart; + quint16 port = m_localPortStart; while (port < m_localPortStart + DM_MAX_DEVICES_NUM) { bool used = false; QMapIterator> i(m_devices); while (i.hasNext()) { i.next(); auto device = i.value(); - if (device && device->getServer() - && device->getServer()->isReverse() - && port == device->getServer()->getParams().localPort) { + if (device && device->getServer() && device->getServer()->isReverse() && port == device->getServer()->getParams().localPort) { used = true; break; } diff --git a/QtScrcpy/devicemanage/devicemanage.h b/QtScrcpy/devicemanage/devicemanage.h index fb86089..1d0250a 100644 --- a/QtScrcpy/devicemanage/devicemanage.h +++ b/QtScrcpy/devicemanage/devicemanage.h @@ -1,8 +1,8 @@ #ifndef DEVICEMANAGE_H #define DEVICEMANAGE_H -#include #include +#include #include "device.h" @@ -26,12 +26,12 @@ protected: protected slots: void onDeviceDisconnect(QString serial); - void onControlStateChange(Device* device, Device::GroupControlState oldState, Device::GroupControlState newState); + void onControlStateChange(Device *device, Device::GroupControlState oldState, Device::GroupControlState newState); // neend convert frameSize to its frameSize - void onMouseEvent(const QMouseEvent* from, const QSize& frameSize, const QSize& showSize); - void onWheelEvent(const QWheelEvent* from, const QSize& frameSize, const QSize& showSize); - void onKeyEvent(const QKeyEvent* from, const QSize& frameSize, const QSize& showSize); + void onMouseEvent(const QMouseEvent *from, const QSize &frameSize, const QSize &showSize); + void onWheelEvent(const QWheelEvent *from, const QSize &frameSize, const QSize &showSize); + void onKeyEvent(const QKeyEvent *from, const QSize &frameSize, const QSize &showSize); private: quint16 getFreePort(); diff --git a/QtScrcpy/dialog.cpp b/QtScrcpy/dialog.cpp index d142ac6..722da32 100644 --- a/QtScrcpy/dialog.cpp +++ b/QtScrcpy/dialog.cpp @@ -1,25 +1,23 @@ -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include -#include "dialog.h" -#include "ui_dialog.h" -#include "device.h" -#include "videoform.h" -#include "keymap.h" #include "config.h" +#include "device.h" +#include "dialog.h" +#include "keymap.h" +#include "ui_dialog.h" +#include "videoform.h" -Dialog::Dialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::Dialog) -{ +Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) +{ ui->setupUi(this); initUI(); - connect(&m_adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){ + connect(&m_adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult) { QString log = ""; bool newLine = true; QStringList args = m_adb.arguments(); @@ -33,7 +31,7 @@ Dialog::Dialog(QWidget *parent) : break; case AdbProcess::AER_ERROR_EXEC: //log = m_adb.getErrorOut(); - if (args.contains("ifconfig") && args.contains("wlan0")){ + if (args.contains("ifconfig") && args.contains("wlan0")) { getIPbyIp(); } break; @@ -45,7 +43,7 @@ Dialog::Dialog(QWidget *parent) : if (args.contains("devices")) { QStringList devices = m_adb.getDevicesSerialFromStdOut(); ui->serialBox->clear(); - for (auto& item : devices) { + for (auto &item : devices) { ui->serialBox->addItem(item); } } else if (args.contains("show") && args.contains("wlan0")) { @@ -119,7 +117,7 @@ void Dialog::initUI() // linux need more width setFixedWidth(480); #endif - } +} void Dialog::execAdbCmd() { @@ -131,11 +129,10 @@ void Dialog::execAdbCmd() m_adb.execute(ui->serialBox->currentText().trimmed(), cmd.split(" ", QString::SkipEmptyParts)); } -QString Dialog::getGameScript(const QString& fileName) +QString Dialog::getGameScript(const QString &fileName) { QFile loadFile(KeyMap::getKeyMapPath() + "/" + fileName); - if(!loadFile.open(QIODevice::ReadOnly)) - { + if (!loadFile.open(QIODevice::ReadOnly)) { outLog("open file failed:" + fileName, true); return ""; } @@ -194,7 +191,7 @@ void Dialog::on_startServerBtn_clicked() } void Dialog::on_stopServerBtn_clicked() -{ +{ if (m_deviceManage.disconnectDevice(ui->serialBox->currentText().trimmed())) { outLog("stop server"); } @@ -241,7 +238,7 @@ void Dialog::outLog(const QString &log, bool newLine) { // avoid sub thread update ui QString backLog = log; - QTimer::singleShot(0, this, [this, backLog, newLine](){ + QTimer::singleShot(0, this, [this, backLog, newLine]() { ui->outEdit->append(backLog); if (newLine) { ui->outEdit->append("
"); @@ -324,10 +321,7 @@ void Dialog::on_wirelessDisConnectBtn_clicked() void Dialog::on_selectRecordPathBtn_clicked() { QFileDialog::Options options = QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly; - QString directory = QFileDialog::getExistingDirectory(this, - tr("select path"), - "", - options); + QString directory = QFileDialog::getExistingDirectory(this, tr("select path"), "", options); ui->recordPathEdt->setText(directory); } @@ -349,7 +343,7 @@ void Dialog::on_stopAdbBtn_clicked() } void Dialog::on_clearOut_clicked() -{ +{ ui->outEdit->clear(); } diff --git a/QtScrcpy/dialog.h b/QtScrcpy/dialog.h index 8101752..20eae6f 100644 --- a/QtScrcpy/dialog.h +++ b/QtScrcpy/dialog.h @@ -7,8 +7,9 @@ #include "adbprocess.h" #include "devicemanage.h" -namespace Ui { -class Dialog; +namespace Ui +{ + class Dialog; } class QYUVOpenGLWidget; @@ -20,8 +21,8 @@ public: explicit Dialog(QWidget *parent = 0); ~Dialog(); - void outLog(const QString& log, bool newLine = true); - bool filterLog(const QString & log); + void outLog(const QString &log, bool newLine = true); + bool filterLog(const QString &log); void getIPbyIp(); private slots: @@ -69,7 +70,7 @@ private: bool checkAdbRun(); void initUI(); void execAdbCmd(); - QString getGameScript(const QString& fileName); + QString getGameScript(const QString &fileName); private: Ui::Dialog *ui; diff --git a/QtScrcpy/fontawesome/iconhelper.cpp b/QtScrcpy/fontawesome/iconhelper.cpp index 6698f32..c2dbd7c 100644 --- a/QtScrcpy/fontawesome/iconhelper.cpp +++ b/QtScrcpy/fontawesome/iconhelper.cpp @@ -1,22 +1,21 @@ #include "iconhelper.h" -IconHelper* IconHelper::_instance = 0; -IconHelper::IconHelper(QObject*): - QObject(qApp) +IconHelper *IconHelper::_instance = 0; +IconHelper::IconHelper(QObject *) : QObject(qApp) { int fontId = QFontDatabase::addApplicationFont(":/font/fontawesome-webfont.ttf"); QString fontName = QFontDatabase::applicationFontFamilies(fontId).at(0); iconFont = QFont(fontName); } -void IconHelper::SetIcon(QLabel* lab, QChar c, int size) +void IconHelper::SetIcon(QLabel *lab, QChar c, int size) { iconFont.setPointSize(size); lab->setFont(iconFont); lab->setText(c); } -void IconHelper::SetIcon(QPushButton* btn, QChar c, int size) +void IconHelper::SetIcon(QPushButton *btn, QChar c, int size) { iconFont.setPointSize(size); btn->setFont(iconFont); diff --git a/QtScrcpy/fontawesome/iconhelper.h b/QtScrcpy/fontawesome/iconhelper.h index 32cc543..167c72c 100644 --- a/QtScrcpy/fontawesome/iconhelper.h +++ b/QtScrcpy/fontawesome/iconhelper.h @@ -1,23 +1,23 @@ #ifndef ICONHELPER_H #define ICONHELPER_H -#include +#include #include #include -#include #include +#include +#include #include -#include class IconHelper : public QObject { private: explicit IconHelper(QObject *parent = 0); QFont iconFont; - static IconHelper* _instance; + static IconHelper *_instance; public: - static IconHelper* Instance() + static IconHelper *Instance() { static QMutex mutex; if (!_instance) { @@ -29,9 +29,8 @@ public: return _instance; } - void SetIcon(QLabel* lab, QChar c, int size = 10); - void SetIcon(QPushButton* btn, QChar c, int size = 10); - + void SetIcon(QLabel *lab, QChar c, int size = 10); + void SetIcon(QPushButton *btn, QChar c, int size = 10); }; #endif // ICONHELPER_H diff --git a/QtScrcpy/main.cpp b/QtScrcpy/main.cpp index cc6223f..27665dd 100644 --- a/QtScrcpy/main.cpp +++ b/QtScrcpy/main.cpp @@ -1,17 +1,17 @@ #include #include -#include -#include -#include #include #include +#include +#include +#include -#include "dialog.h" -#include "stream.h" -#include "mousetap/mousetap.h" #include "config.h" +#include "dialog.h" +#include "mousetap/mousetap.h" +#include "stream.h" -static Dialog* g_mainDlg = Q_NULLPTR; +static Dialog *g_mainDlg = Q_NULLPTR; static QtMessageHandler g_oldMessageHandler = Q_NULLPTR; void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg); @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) int opengl = Config::getInstance().getDesktopOpenGL(); if (0 == opengl) { QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL); - } else if (1 == opengl){ + } else if (1 == opengl) { QApplication::setAttribute(Qt::AA_UseOpenGLES); } else if (2 == opengl) { QApplication::setAttribute(Qt::AA_UseDesktopOpenGL); @@ -98,7 +98,9 @@ int main(int argc, char *argv[]) g_mainDlg->setWindowTitle(Config::getInstance().getTitle()); g_mainDlg->show(); - qInfo(QObject::tr("This software is completely open source and free. Strictly used for illegal purposes, or at your own risk. You can download it at the following address:").toUtf8()); + qInfo(QObject::tr("This software is completely open source and free. Strictly used for illegal purposes, or at your own risk. You can download it at the " + "following address:") + .toUtf8()); qInfo(QString("QtScrcpy %1 ").arg(QCoreApplication::applicationVersion()).toUtf8()); int ret = a.exec(); @@ -111,7 +113,8 @@ int main(int argc, char *argv[]) return ret; } -void installTranslator() { +void installTranslator() +{ static QTranslator translator; QLocale locale; QLocale::Language language = locale.language(); diff --git a/QtScrcpy/uibase/keepradiowidget.cpp b/QtScrcpy/uibase/keepradiowidget.cpp index 09a5077..4e88ab0 100644 --- a/QtScrcpy/uibase/keepradiowidget.cpp +++ b/QtScrcpy/uibase/keepradiowidget.cpp @@ -3,16 +3,9 @@ #include "keepradiowidget.h" -KeepRadioWidget::KeepRadioWidget(QWidget *parent) : - QWidget(parent) -{ +KeepRadioWidget::KeepRadioWidget(QWidget *parent) : QWidget(parent) {} -} - -KeepRadioWidget::~KeepRadioWidget() -{ - -} +KeepRadioWidget::~KeepRadioWidget() {} void KeepRadioWidget::setWidget(QWidget *w) { diff --git a/QtScrcpy/uibase/keepradiowidget.h b/QtScrcpy/uibase/keepradiowidget.h index 8baa992..ef0877a 100644 --- a/QtScrcpy/uibase/keepradiowidget.h +++ b/QtScrcpy/uibase/keepradiowidget.h @@ -1,8 +1,8 @@ #ifndef KEEPRADIOWIDGET_H #define KEEPRADIOWIDGET_H -#include #include +#include class KeepRadioWidget : public QWidget { @@ -11,7 +11,7 @@ public: explicit KeepRadioWidget(QWidget *parent = nullptr); ~KeepRadioWidget(); - void setWidget(QWidget* w); + void setWidget(QWidget *w); void setWidthHeightRadio(float widthHeightRadio); const QSize goodSize(); @@ -23,7 +23,6 @@ private: float m_widthHeightRadio = -1.0f; QPointer m_subWidget; QSize m_goodSize; - }; #endif // KEEPRADIOWIDGET_H diff --git a/QtScrcpy/uibase/magneticwidget.cpp b/QtScrcpy/uibase/magneticwidget.cpp index 6fd29be..3c7a9c2 100644 --- a/QtScrcpy/uibase/magneticwidget.cpp +++ b/QtScrcpy/uibase/magneticwidget.cpp @@ -4,17 +4,13 @@ #include "magneticwidget.h" -MagneticWidget::MagneticWidget(QWidget* adsorbWidget, AdsorbPositions adsorbPos) - : QWidget(Q_NULLPTR) - , m_adsorbPos(adsorbPos) - , m_adsorbWidget(adsorbWidget) +MagneticWidget::MagneticWidget(QWidget *adsorbWidget, AdsorbPositions adsorbPos) : QWidget(Q_NULLPTR), m_adsorbPos(adsorbPos), m_adsorbWidget(adsorbWidget) { Q_ASSERT(m_adsorbWidget); setParent(m_adsorbWidget); setWindowFlags(windowFlags() | Qt::Tool); m_adsorbWidget->installEventFilter(this); - } MagneticWidget::~MagneticWidget() @@ -110,68 +106,53 @@ void MagneticWidget::moveEvent(QMoveEvent *event) m_adsorbed = false; - if (m_adsorbPos & AP_INSIDE_LEFT - && parentRect.intersects(targetRect) - && qAbs(parentLeft - targetLeft) < adsorbDistance) { + if (m_adsorbPos & AP_INSIDE_LEFT && parentRect.intersects(targetRect) && qAbs(parentLeft - targetLeft) < adsorbDistance) { finalPosition.setX(parentLeft); m_adsorbed |= true; - m_curAdsorbPosition = AP_INSIDE_LEFT; + m_curAdsorbPosition = AP_INSIDE_LEFT; } - if (m_adsorbPos & AP_OUTSIDE_RIGHT - && parentRect.intersects(targetRect.translated(-adsorbDistance, 0)) - && qAbs(parentRight - targetLeft) < adsorbDistance) { + if (m_adsorbPos & AP_OUTSIDE_RIGHT && parentRect.intersects(targetRect.translated(-adsorbDistance, 0)) && qAbs(parentRight - targetLeft) < adsorbDistance) { finalPosition.setX(parentRight); m_adsorbed |= true; - m_curAdsorbPosition = AP_OUTSIDE_RIGHT; + m_curAdsorbPosition = AP_OUTSIDE_RIGHT; } - if (m_adsorbPos & AP_OUTSIDE_LEFT - && parentRect.intersects(targetRect.translated(adsorbDistance, 0)) - && qAbs(parentLeft - targetRight) < adsorbDistance) { + if (m_adsorbPos & AP_OUTSIDE_LEFT && parentRect.intersects(targetRect.translated(adsorbDistance, 0)) && qAbs(parentLeft - targetRight) < adsorbDistance) { finalPosition.setX(parentLeft - targetRect.width()); m_adsorbed |= true; - m_curAdsorbPosition = AP_OUTSIDE_LEFT; + m_curAdsorbPosition = AP_OUTSIDE_LEFT; } - if (m_adsorbPos & AP_INSIDE_RIGHT - && parentRect.intersects(targetRect) - && qAbs(parentRight - targetRight) < adsorbDistance) { + if (m_adsorbPos & AP_INSIDE_RIGHT && parentRect.intersects(targetRect) && qAbs(parentRight - targetRight) < adsorbDistance) { finalPosition.setX(parentRight - targetRect.width()); m_adsorbed |= true; - m_curAdsorbPosition = AP_INSIDE_RIGHT; + m_curAdsorbPosition = AP_INSIDE_RIGHT; } - if (m_adsorbPos & AP_INSIDE_TOP - && parentRect.intersects(targetRect) - && qAbs(parentTop - targetTop) < adsorbDistance) { + if (m_adsorbPos & AP_INSIDE_TOP && parentRect.intersects(targetRect) && qAbs(parentTop - targetTop) < adsorbDistance) { finalPosition.setY(parentTop); m_adsorbed |= true; - m_curAdsorbPosition = AP_INSIDE_TOP; + m_curAdsorbPosition = AP_INSIDE_TOP; } - if (m_adsorbPos & AP_OUTSIDE_TOP - && parentRect.intersects(targetRect.translated(0, adsorbDistance)) - && qAbs(parentTop - targetBottom) < adsorbDistance) { + if (m_adsorbPos & AP_OUTSIDE_TOP && parentRect.intersects(targetRect.translated(0, adsorbDistance)) && qAbs(parentTop - targetBottom) < adsorbDistance) { finalPosition.setY(parentTop - targetRect.height()); m_adsorbed |= true; - m_curAdsorbPosition = AP_OUTSIDE_TOP; + m_curAdsorbPosition = AP_OUTSIDE_TOP; } - if (m_adsorbPos & AP_OUTSIDE_BOTTOM - && parentRect.intersects(targetRect.translated(0, -adsorbDistance)) - && qAbs(parentBottom - targetTop) < adsorbDistance) { + if (m_adsorbPos & AP_OUTSIDE_BOTTOM && parentRect.intersects(targetRect.translated(0, -adsorbDistance)) + && qAbs(parentBottom - targetTop) < adsorbDistance) { finalPosition.setY(parentBottom); m_adsorbed |= true; - m_curAdsorbPosition = AP_OUTSIDE_BOTTOM; + m_curAdsorbPosition = AP_OUTSIDE_BOTTOM; } - if (m_adsorbPos & AP_INSIDE_BOTTOM - && parentRect.intersects(targetRect) - && qAbs(parentBottom - targetBottom) < adsorbDistance) { + if (m_adsorbPos & AP_INSIDE_BOTTOM && parentRect.intersects(targetRect) && qAbs(parentBottom - targetBottom) < adsorbDistance) { finalPosition.setY(parentBottom - targetRect.height()); m_adsorbed |= true; - m_curAdsorbPosition = AP_INSIDE_BOTTOM; + m_curAdsorbPosition = AP_INSIDE_BOTTOM; } if (m_adsorbed) { @@ -191,4 +172,3 @@ void MagneticWidget::getGeometry(QRect &relativeWidgetRect, QRect &targetWidgetR targetWidgetRect.setWidth(width()); targetWidgetRect.setHeight(height()); } - diff --git a/QtScrcpy/uibase/magneticwidget.h b/QtScrcpy/uibase/magneticwidget.h index 8ed730a..23b6cff 100644 --- a/QtScrcpy/uibase/magneticwidget.h +++ b/QtScrcpy/uibase/magneticwidget.h @@ -1,8 +1,8 @@ #ifndef MAGNETICWIDGET_H #define MAGNETICWIDGET_H -#include #include +#include /* * a magnetic widget @@ -14,21 +14,22 @@ class MagneticWidget : public QWidget Q_OBJECT public: - enum AdsorbPosition { - AP_OUTSIDE_LEFT = 0x01, // 吸附外部左边框 - AP_OUTSIDE_TOP = 0x02, // 吸附外部上边框 - AP_OUTSIDE_RIGHT = 0x04, // 吸附外部右边框 - AP_OUTSIDE_BOTTOM = 0x08, // 吸附外部下边框 - AP_INSIDE_LEFT = 0x10, // 吸附内部左边框 - AP_INSIDE_TOP = 0x20, // 吸附内部上边框 - AP_INSIDE_RIGHT = 0x40, // 吸附内部右边框 - AP_INSIDE_BOTTOM = 0x80, // 吸附内部下边框 - AP_ALL = 0xFF, // 全吸附 + enum AdsorbPosition + { + AP_OUTSIDE_LEFT = 0x01, // 吸附外部左边框 + AP_OUTSIDE_TOP = 0x02, // 吸附外部上边框 + AP_OUTSIDE_RIGHT = 0x04, // 吸附外部右边框 + AP_OUTSIDE_BOTTOM = 0x08, // 吸附外部下边框 + AP_INSIDE_LEFT = 0x10, // 吸附内部左边框 + AP_INSIDE_TOP = 0x20, // 吸附内部上边框 + AP_INSIDE_RIGHT = 0x40, // 吸附内部右边框 + AP_INSIDE_BOTTOM = 0x80, // 吸附内部下边框 + AP_ALL = 0xFF, // 全吸附 }; Q_DECLARE_FLAGS(AdsorbPositions, AdsorbPosition) public: - explicit MagneticWidget(QWidget* adsorbWidget, AdsorbPositions adsorbPos = AP_ALL); + explicit MagneticWidget(QWidget *adsorbWidget, AdsorbPositions adsorbPos = AP_ALL); ~MagneticWidget(); bool isAdsorbed(); @@ -38,7 +39,7 @@ protected: void moveEvent(QMoveEvent *event) override; private: - void getGeometry(QRect& relativeWidgetRect, QRect& targetWidgetRect); + void getGeometry(QRect &relativeWidgetRect, QRect &targetWidgetRect); private: AdsorbPositions m_adsorbPos = AP_ALL; diff --git a/QtScrcpy/util/bufferutil.cpp b/QtScrcpy/util/bufferutil.cpp index 0627b75..9103ccf 100644 --- a/QtScrcpy/util/bufferutil.cpp +++ b/QtScrcpy/util/bufferutil.cpp @@ -11,7 +11,7 @@ void BufferUtil::write32(QBuffer &buffer, quint32 value) void BufferUtil::write64(QBuffer &buffer, quint64 value) { write32(buffer, value >> 32); - write32(buffer, (quint32) value); + write32(buffer, (quint32)value); } void BufferUtil::write16(QBuffer &buffer, quint32 value) @@ -24,9 +24,9 @@ quint16 BufferUtil::read16(QBuffer &buffer) { uchar c; quint16 ret = 0; - buffer.getChar(reinterpret_cast(&c)); + buffer.getChar(reinterpret_cast(&c)); ret |= (c << 8); - buffer.getChar(reinterpret_cast(&c)); + buffer.getChar(reinterpret_cast(&c)); ret |= c; return ret; @@ -36,13 +36,13 @@ quint32 BufferUtil::read32(QBuffer &buffer) { uchar c; quint32 ret = 0; - buffer.getChar(reinterpret_cast(&c)); + buffer.getChar(reinterpret_cast(&c)); ret |= (c << 24); - buffer.getChar(reinterpret_cast(&c)); + buffer.getChar(reinterpret_cast(&c)); ret |= (c << 16); - buffer.getChar(reinterpret_cast(&c)); + buffer.getChar(reinterpret_cast(&c)); ret |= (c << 8); - buffer.getChar(reinterpret_cast(&c)); + buffer.getChar(reinterpret_cast(&c)); ret |= c; return ret; @@ -53,5 +53,6 @@ quint64 BufferUtil::read64(QBuffer &buffer) quint32 msb = read32(buffer); quint32 lsb = read32(buffer); - return ((quint64) msb << 32) | lsb;; + return ((quint64)msb << 32) | lsb; + ; } diff --git a/QtScrcpy/util/bufferutil.h b/QtScrcpy/util/bufferutil.h index fb307c4..a3c17f1 100644 --- a/QtScrcpy/util/bufferutil.h +++ b/QtScrcpy/util/bufferutil.h @@ -5,12 +5,12 @@ class BufferUtil { public: - static void write16(QBuffer& buffer, quint32 value); - static void write32(QBuffer& buffer, quint32 value); - static void write64(QBuffer& buffer, quint64 value); - static quint16 read16(QBuffer& buffer); - static quint32 read32(QBuffer& buffer); - static quint64 read64(QBuffer& buffer); + static void write16(QBuffer &buffer, quint32 value); + static void write32(QBuffer &buffer, quint32 value); + static void write64(QBuffer &buffer, quint64 value); + static quint16 read16(QBuffer &buffer); + static quint32 read32(QBuffer &buffer); + static quint64 read64(QBuffer &buffer); }; #endif // BUFFERUTIL_H diff --git a/QtScrcpy/util/compat.h b/QtScrcpy/util/compat.h index a2ae3f1..8277728 100644 --- a/QtScrcpy/util/compat.h +++ b/QtScrcpy/util/compat.h @@ -6,11 +6,10 @@ // In ffmpeg/doc/APIchanges: // 2016-04-11 - 6f69f7a / 9200514 - lavf 57.33.100 / 57.5.0 - avformat.h // Add AVStream.codecpar, deprecate AVStream.codec. -#if (LIBAVFORMAT_VERSION_MICRO >= 100 /* FFmpeg */ && \ - LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 33, 100)) \ - || (LIBAVFORMAT_VERSION_MICRO < 100 && /* Libav */ \ +#if (LIBAVFORMAT_VERSION_MICRO >= 100 /* FFmpeg */ && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 33, 100)) \ + || (LIBAVFORMAT_VERSION_MICRO < 100 && /* Libav */ \ LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 5, 0)) -# define QTSCRCPY_LAVF_HAS_NEW_CODEC_PARAMS_API +#define QTSCRCPY_LAVF_HAS_NEW_CODEC_PARAMS_API #endif // In ffmpeg/doc/APIchanges: @@ -19,9 +18,9 @@ // av_register_all(), av_iformat_next(), av_oformat_next(). // Add av_demuxer_iterate(), and av_muxer_iterate(). #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100) -# define QTSCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API +#define QTSCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API #else -# define QTSCRCPY_LAVF_REQUIRES_REGISTER_ALL +#define QTSCRCPY_LAVF_REQUIRES_REGISTER_ALL #endif // In ffmpeg/doc/APIchanges: @@ -30,7 +29,7 @@ // and output -- avcodec_send_packet(), avcodec_receive_frame(), // avcodec_send_frame() and avcodec_receive_packet(). #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 100) -# define QTSCRCPY_LAVF_HAS_NEW_ENCODING_DECODING_API +#define QTSCRCPY_LAVF_HAS_NEW_ENCODING_DECODING_API #endif #endif // COMPAT_H diff --git a/QtScrcpy/util/config.cpp b/QtScrcpy/util/config.cpp index ea39ea7..222a3c3 100644 --- a/QtScrcpy/util/config.cpp +++ b/QtScrcpy/util/config.cpp @@ -1,6 +1,6 @@ -#include #include #include +#include #include "config.h" @@ -72,7 +72,7 @@ Config &Config::getInstance() return config; } -const QString& Config::getConfigPath() +const QString &Config::getConfigPath() { if (s_configPath.isEmpty()) { s_configPath = QString::fromLocal8Bit(qgetenv("QTSCRCPY_CONFIG_PATH")); @@ -261,6 +261,3 @@ QString Config::getTitle() m_settings->endGroup(); return title; } - - - diff --git a/QtScrcpy/util/config.h b/QtScrcpy/util/config.h index 28cfec2..ed472fe 100644 --- a/QtScrcpy/util/config.h +++ b/QtScrcpy/util/config.h @@ -10,7 +10,7 @@ class Config : public QObject { Q_OBJECT public: - static Config& getInstance(); + static Config &getInstance(); // config QString getTitle(); QString getServerVersion(); @@ -23,7 +23,7 @@ public: // user data QString getRecordPath(); - void setRecordPath(const QString& path); + void setRecordPath(const QString &path); int getBitRateIndex(); void setBitRateIndex(int bitRateIndex); int getMaxSizeIndex(); @@ -37,7 +37,7 @@ public: private: explicit Config(QObject *parent = nullptr); - const QString& getConfigPath(); + const QString &getConfigPath(); private: static QString s_configPath; diff --git a/QtScrcpy/util/mousetap/cocoamousetap.h b/QtScrcpy/util/mousetap/cocoamousetap.h index e1757f8..a8d1ee8 100644 --- a/QtScrcpy/util/mousetap/cocoamousetap.h +++ b/QtScrcpy/util/mousetap/cocoamousetap.h @@ -1,13 +1,15 @@ #ifndef COCOAMOUSETAP_H #define COCOAMOUSETAP_H -#include #include +#include #include "mousetap.h" struct MouseEventTapData; class QWidget; -class CocoaMouseTap : public MouseTap, public QThread +class CocoaMouseTap + : public MouseTap + , public QThread { public: CocoaMouseTap(QObject *parent = Q_NULLPTR); diff --git a/QtScrcpy/util/mousetap/mousetap.h b/QtScrcpy/util/mousetap/mousetap.h index 8cad8f9..a2c6820 100644 --- a/QtScrcpy/util/mousetap/mousetap.h +++ b/QtScrcpy/util/mousetap/mousetap.h @@ -3,9 +3,10 @@ #include class QWidget; -class MouseTap { +class MouseTap +{ public: - static MouseTap* getInstance(); + static MouseTap *getInstance(); virtual void initMouseEventTap() = 0; virtual void quitMouseEventTap() = 0; // rc base global screenspace coordinate system, which has a flipped Y. diff --git a/QtScrcpy/util/mousetap/winmousetap.cpp b/QtScrcpy/util/mousetap/winmousetap.cpp index ecbf369..50a13d8 100644 --- a/QtScrcpy/util/mousetap/winmousetap.cpp +++ b/QtScrcpy/util/mousetap/winmousetap.cpp @@ -1,35 +1,23 @@ -#include -#include #include +#include +#include #include "winmousetap.h" -WinMouseTap::WinMouseTap() -{ +WinMouseTap::WinMouseTap() {} -} +WinMouseTap::~WinMouseTap() {} -WinMouseTap::~WinMouseTap() -{ +void WinMouseTap::initMouseEventTap() {} -} - -void WinMouseTap::initMouseEventTap() -{ - -} - -void WinMouseTap::quitMouseEventTap() -{ - -} +void WinMouseTap::quitMouseEventTap() {} void WinMouseTap::enableMouseEventTap(QRect rc, bool enabled) { if (enabled && rc.isEmpty()) { return; } - if(enabled) { + if (enabled) { RECT mainRect; mainRect.left = (LONG)rc.left(); mainRect.right = (LONG)rc.right();