refactor: CoreArgs Add display option

This commit is contained in:
sithlord48 2025-09-17 20:55:01 -04:00 committed by Chris Rizzitello
parent c2ee366e23
commit 295137dbd2
9 changed files with 35 additions and 46 deletions

View file

@ -49,6 +49,7 @@ public:
inline static const auto ScreenName = QStringLiteral("core/screenName"); inline static const auto ScreenName = QStringLiteral("core/screenName");
inline static const auto StartedBefore = QStringLiteral("core/startedBefore"); inline static const auto StartedBefore = QStringLiteral("core/startedBefore");
inline static const auto UpdateUrl = QStringLiteral("core/updateUrl"); inline static const auto UpdateUrl = QStringLiteral("core/updateUrl");
inline static const auto Display = QStringLiteral("core/display");
}; };
struct Daemon struct Daemon
{ {
@ -171,6 +172,7 @@ private:
, Settings::Core::ScreenName , Settings::Core::ScreenName
, Settings::Core::StartedBefore , Settings::Core::StartedBefore
, Settings::Core::UpdateUrl , Settings::Core::UpdateUrl
, Settings::Core::Display
, Settings::Daemon::Command , Settings::Daemon::Command
, Settings::Daemon::Elevate , Settings::Daemon::Elevate
, Settings::Daemon::LogFile , Settings::Daemon::LogFile

View file

@ -31,8 +31,8 @@ bool ArgParser::parseServerArgs(deskflow::ServerArgs &args, int argc, const char
updateCommonArgs(argv); updateCommonArgs(argv);
int i = 1; int i = 1;
while (i < argc) { while (i < argc) {
if (parsePlatformArgs(args, argc, argv, i) || parseGenericArgs(argc, argv, i) || if (parseGenericArgs(argc, argv, i) || parseDeprecatedArgs(argc, argv, i) ||
parseDeprecatedArgs(argc, argv, i) || isArg(i, argc, argv, nullptr, "server")) { isArg(i, argc, argv, nullptr, "server")) {
++i; ++i;
continue; continue;
} else if (isArg(i, argc, argv, "-c", "--config", 1)) { } else if (isArg(i, argc, argv, "-c", "--config", 1)) {
@ -61,8 +61,8 @@ bool ArgParser::parseClientArgs(deskflow::ClientArgs &args, int argc, const char
int i{1}; int i{1};
while (i < argc) { while (i < argc) {
if (parsePlatformArgs(args, argc, argv, i) || parseGenericArgs(argc, argv, i) || if (parseGenericArgs(argc, argv, i) || parseDeprecatedArgs(argc, argv, i) ||
parseDeprecatedArgs(argc, argv, i) || isArg(i, argc, argv, nullptr, "client")) { isArg(i, argc, argv, nullptr, "client")) {
++i; ++i;
continue; continue;
} else if (isArg(i, argc, argv, nullptr, "--camp") || isArg(i, argc, argv, nullptr, "--no-camp")) { } else if (isArg(i, argc, argv, nullptr, "--camp") || isArg(i, argc, argv, nullptr, "--no-camp")) {
@ -99,27 +99,6 @@ bool ArgParser::parseClientArgs(deskflow::ClientArgs &args, int argc, const char
return true; return true;
} }
bool ArgParser::parsePlatformArgs(deskflow::ArgsBase &argsBase, const int &argc, const char *const *argv, int &i) const
{
#if !WINAPI_XWINDOWS
// no options for carbon or windows
return false;
#else
if (isArg(i, argc, argv, "-display", "--display", 1)) {
// use alternative display
argsBase.m_display = argv[++i];
}
else {
// option not supported here
return false;
}
return true;
#endif
}
bool ArgParser::parseGenericArgs(int argc, const char *const *argv, int &i) const bool ArgParser::parseGenericArgs(int argc, const char *const *argv, int &i) const
{ {
if (isArg(i, argc, argv, "-1", "--no-restart")) { if (isArg(i, argc, argv, "-1", "--no-restart")) {

View file

@ -25,7 +25,6 @@ public:
bool parseServerArgs(deskflow::ServerArgs &args, int argc, const char *const *argv) const; bool parseServerArgs(deskflow::ServerArgs &args, int argc, const char *const *argv) const;
bool parseClientArgs(deskflow::ClientArgs &args, int argc, const char *const *argv) const; bool parseClientArgs(deskflow::ClientArgs &args, int argc, const char *const *argv) const;
bool parsePlatformArgs(deskflow::ArgsBase &argsBase, const int &argc, const char *const *argv, int &i) const;
bool parseGenericArgs(int argc, const char *const *argv, int &i) const; bool parseGenericArgs(int argc, const char *const *argv, int &i) const;
bool parseDeprecatedArgs(int argc, const char *const *argv, int &i) const; bool parseDeprecatedArgs(int argc, const char *const *argv, int &i) const;
void setArgsBase(deskflow::ArgsBase &argsBase) const void setArgsBase(deskflow::ArgsBase &argsBase) const

View file

@ -41,9 +41,6 @@ public:
/// @brief The filename of the running process /// @brief The filename of the running process
const char *m_pname = nullptr; const char *m_pname = nullptr;
/// @brief Contains the X-Server display to use
const char *m_display = nullptr;
/// @brief Will cause the application to exit with OK code when set to true /// @brief Will cause the application to exit with OK code when set to true
bool m_shouldExitOk = false; bool m_shouldExitOk = false;

View file

@ -118,10 +118,6 @@ void ClientApp::help()
<< " --sync-language enable language synchronization.\n" << " --sync-language enable language synchronization.\n"
<< " --invert-scroll invert scroll direction on this\n" << " --invert-scroll invert scroll direction on this\n"
<< " computer.\n" << " computer.\n"
#if WINAPI_XWINDOWS
<< " --display <display> when in X mode, connect to the X server\n"
<< " at <display>.\n"
#endif
<< s_helpVersionArgs << "\n" << s_helpVersionArgs << "\n"
<< "* marks defaults.\n" << "* marks defaults.\n"
@ -181,7 +177,10 @@ deskflow::Screen *ClientApp::createScreen()
#if WINAPI_XWINDOWS #if WINAPI_XWINDOWS
LOG_INFO("using legacy x windows screen"); LOG_INFO("using legacy x windows screen");
return new deskflow::Screen( return new deskflow::Screen(
new XWindowsScreen(args().m_display, false, args().m_yscroll, getEvents(), args().m_clientScrollDirection), new XWindowsScreen(
qPrintable(Settings::value(Settings::Core::Display).toString()), false, args().m_yscroll, getEvents(),
args().m_clientScrollDirection
),
getEvents() getEvents()
); );

View file

@ -90,6 +90,11 @@ void CoreArgParser::parse()
(m_parser.value(CoreArgs::preventSleepOption) == "1")); (m_parser.value(CoreArgs::preventSleepOption) == "1"));
Settings::setValue(Settings::Core::PreventSleep, value); Settings::setValue(Settings::Core::PreventSleep, value);
} }
if (m_parser.isSet(CoreArgs::displayOption)) {
auto value = m_parser.value(CoreArgs::displayOption);
Settings::setValue(Settings::Core::Display, value);
}
} }
[[noreturn]] void CoreArgParser::showHelpText() const [[noreturn]] void CoreArgParser::showHelpText() const
@ -136,3 +141,12 @@ bool CoreArgParser::clientMode() const
{ {
return m_clientMode; return m_clientMode;
} }
const char *CoreArgParser::display() const
{
#if WINAPI_XWINDOWS
return qPrintable(m_parser.value(CoreArgs::displayOption));
#else
return nullptr;
#endif
}

View file

@ -33,6 +33,7 @@ public:
bool version() const; bool version() const;
bool serverMode() const; bool serverMode() const;
bool clientMode() const; bool clientMode() const;
const char *display() const;
private: private:
[[noreturn]] void showHelpText() const; [[noreturn]] void showHelpText() const;

View file

@ -13,6 +13,9 @@
*/ */
struct CoreArgs struct CoreArgs
{ {
inline static const auto displayOption =
QCommandLineOption("display", "When in X mode, connect to the X server at <display>", "display");
inline static const auto helpOption = QCommandLineOption({"h", "help"}, "Display Help on the command line"); inline static const auto helpOption = QCommandLineOption({"h", "help"}, "Display Help on the command line");
inline static const auto versionOption = QCommandLineOption({"v", "version"}, "Display version information"); inline static const auto versionOption = QCommandLineOption({"v", "version"}, "Display version information");
inline static const auto configOption = QCommandLineOption( inline static const auto configOption = QCommandLineOption(
@ -48,7 +51,7 @@ struct CoreArgs
"prevent-sleep", "When true the machine will be prevented from sleeping while the program is running", "value" "prevent-sleep", "When true the machine will be prevented from sleeping while the program is running", "value"
); );
inline static const auto options = {helpOption, versionOption, configOption, interfaceOption, inline static const auto options = {helpOption, versionOption, configOption, interfaceOption,
portOption, nameOption, logLevelOption, logFileOption, portOption, nameOption, logLevelOption, logFileOption,
secureOption, tlsCertOption, preventSleepOption}; secureOption, tlsCertOption, preventSleepOption, displayOption};
}; };

View file

@ -117,14 +117,6 @@ void ServerApp::help()
<< " --disable-client-cert-check disable client SSL certificate \n" << " --disable-client-cert-check disable client SSL certificate \n"
" checking (deprecated)\n" " checking (deprecated)\n"
<< s_helpVersionArgs << "\n" << s_helpVersionArgs << "\n"
#if WINAPI_XWINDOWS
<< " --display <display> when in X mode, connect to the X server\n"
<< " at <display>.\n"
#endif
<< "* marks defaults.\n"
<< s_helpNoWayland; << s_helpNoWayland;
LOG_PRINT("%s", help.str().c_str()); LOG_PRINT("%s", help.str().c_str());
@ -482,7 +474,10 @@ deskflow::Screen *ServerApp::createScreen()
#if WINAPI_XWINDOWS #if WINAPI_XWINDOWS
LOG_INFO("using legacy x windows screen"); LOG_INFO("using legacy x windows screen");
return new deskflow::Screen(new XWindowsScreen(args().m_display, true, 0, getEvents()), getEvents()); return new deskflow::Screen(
new XWindowsScreen(qPrintable(Settings::value(Settings::Core::Display).toString()), true, 0, getEvents()),
getEvents()
);
#elif WINAPI_CARBON #elif WINAPI_CARBON
return new deskflow::Screen(new OSXScreen(getEvents(), true), getEvents()); return new deskflow::Screen(new OSXScreen(getEvents(), true), getEvents());
#endif #endif