refactor: move invert-scroll to coreArgs

This commit is contained in:
sithlord48 2025-09-25 21:07:06 -04:00 committed by Chris Rizzitello
parent 5fc00f7af4
commit a78959e66f
9 changed files with 60 additions and 35 deletions

View file

@ -36,8 +36,6 @@ bool ArgParser::parseClientArgs(deskflow::ClientArgs &args, int argc, const char
continue;
} else if (isArg(i, argc, argv, nullptr, "--camp") || isArg(i, argc, argv, nullptr, "--no-camp")) {
// ignore -- included for backwards compatibility
} else if (isArg(i, argc, argv, nullptr, "--invert-scroll")) {
args.m_clientScrollDirection = deskflow::ClientScrollDirection::Inverted;
} else {
if (i + 1 == argc) {
args.m_serverAddress = argv[i];

View file

@ -9,12 +9,6 @@
#include "ArgsBase.h"
namespace deskflow {
enum class ClientScrollDirection
{
Normal = 1, //!< Same direction as the server
Inverted = -1 //!< Inverted scroll direction from the server
};
class ClientArgs : public ArgsBase
{
@ -25,12 +19,6 @@ public:
~ClientArgs() override = default;
public:
/**
* @brief m_clientScrollDirection
* This option is responcible for scroll direction on client side.
*/
ClientScrollDirection m_clientScrollDirection = ClientScrollDirection::Normal;
/**
* @brief m_serverAddress stores deskflow server address
*/

View file

@ -131,6 +131,13 @@ void CoreArgParser::parse()
(m_parser.value(CoreArgs::languageSyncOption) == "1"));
Settings::setValue(Settings::Client::LanguageSync, value);
}
if (m_parser.isSet(CoreArgs::invertScrollOption)) {
bool value =
((m_parser.value(CoreArgs::invertScrollOption).toLower() == "true") ||
(m_parser.value(CoreArgs::invertScrollOption) == "1"));
Settings::setValue(Settings::Client::InvertScrollDirection, value);
}
}
[[noreturn]] void CoreArgParser::showHelpText() const

View file

@ -73,9 +73,13 @@ struct CoreArgs
inline static const auto languageSyncOption =
QCommandLineOption("languageSync", "Client Mode: Sync language with client (default: false)", "value");
inline static const auto options = {helpOption, versionOption, configOption, interfaceOption,
portOption, nameOption, logLevelOption, logFileOption,
secureOption, tlsCertOption, preventSleepOption, restartOption,
displayOption, useHooksOption, peerCheckOption, serverConfigOption,
yscrollOption, languageSyncOption};
inline static const auto invertScrollOption = QCommandLineOption(
"invertScrollDirection", "Client Mode: Set scroll direciton to be inverted (default: false)", "value"
);
inline static const auto options = {helpOption, versionOption, configOption, interfaceOption,
portOption, nameOption, logLevelOption, logFileOption,
secureOption, tlsCertOption, preventSleepOption, restartOption,
displayOption, useHooksOption, peerCheckOption, serverConfigOption,
yscrollOption, languageSyncOption, invertScrollOption};
};

View file

@ -479,10 +479,6 @@ bool CoreProcess::addClientArgs(QStringList &args)
args << "--log" << Settings::value(Settings::Log::File).toString();
}
if (Settings::value(Settings::Client::InvertScrollDirection).toBool()) {
args << "--invert-scroll";
}
if (correctedAddress().isEmpty()) {
Q_EMIT error(Error::AddressMissing);
qDebug("address is missing for client args");

View file

@ -170,17 +170,6 @@ void ArgParserTests::clientArgs()
QVERIFY(args.m_shouldExitOk);
}
void ArgParserTests::client_setInvertScroll()
{
deskflow::ClientArgs clientArgs;
const int argc = 2;
std::array<const char *, argc> kLangCmd = {"stub", "--invert-scroll"};
m_parser.parseClientArgs(clientArgs, argc, kLangCmd.data());
QCOMPARE(clientArgs.m_clientScrollDirection, deskflow::ClientScrollDirection::Inverted);
}
void ArgParserTests::client_setAddress()
{
deskflow::ClientArgs clientArgs;

View file

@ -22,7 +22,6 @@ private Q_SLOTS:
void getArgv();
void assembleCommand();
void clientArgs();
void client_setInvertScroll();
void client_setAddress();
void client_badArgs();
void deprecatedArg_crypoPass_true();

View file

@ -370,6 +370,46 @@ void CoreArgParserTests::client_languageSync_0()
QVERIFY(!Settings::value(Settings::Client::LanguageSync).toBool());
}
void CoreArgParserTests::client_invertScrolling_true()
{
QStringList args = {"stub", "client", "--invertScrollDirection", "true"};
CoreArgParser parser(args);
parser.parse();
QVERIFY(Settings::value(Settings::Client::InvertScrollDirection).toBool());
}
void CoreArgParserTests::client_invertScrolling_false()
{
QStringList args = {"stub", "client", "--invertScrollDirection", "false"};
CoreArgParser parser(args);
parser.parse();
QVERIFY(!Settings::value(Settings::Client::InvertScrollDirection).toBool());
}
void CoreArgParserTests::client_invertScrolling_1()
{
QStringList args = {"stub", "client", "--invertScrollDirection", "1"};
CoreArgParser parser(args);
parser.parse();
QVERIFY(Settings::value(Settings::Client::InvertScrollDirection).toBool());
}
void CoreArgParserTests::client_invertScrolling_0()
{
QStringList args = {"stub", "client", "--invertScrollDirection", "0"};
CoreArgParser parser(args);
parser.parse();
QVERIFY(!Settings::value(Settings::Client::InvertScrollDirection).toBool());
}
void CoreArgParserTests::preventSleep_true()
{
QStringList args = {"stub", "client", "--prevent-sleep", "true"};

View file

@ -50,6 +50,10 @@ private Q_SLOTS:
void client_languageSync_false();
void client_languageSync_1();
void client_languageSync_0();
void client_invertScrolling_true();
void client_invertScrolling_false();
void client_invertScrolling_1();
void client_invertScrolling_0();
private:
inline static const QString m_settingsPath = QStringLiteral("tmp/test");