diff --git a/docs/user/configuration.md b/docs/user/configuration.md index 6fe3e491a..d0b369eb9 100644 --- a/docs/user/configuration.md +++ b/docs/user/configuration.md @@ -144,6 +144,7 @@ This section contains options used when in server mode it will begin with `[serv |:-------------------|:-----------------:|:-----------| | externalConfig | `true` or `false` | When true use the external config path | | externalConfigFile | Filepath | Path the server config file if it does not exist the GUI will it generated based on the `internalConfig` section.| +| protocol | `barrier` or `synergy` | The protocol to use when saying hello to clients. Can be set to barrier or synergy. If not set barrier is used as the default | ### InternalConfig @@ -176,7 +177,6 @@ hotkeys\1\keys\size=1 hotkeys\size=1 numColumns=5 numRows=3 -protocol=1 relativeMouseMoves=false screens\1\name= screens\10\aliasArray\size=0 @@ -389,7 +389,6 @@ Note that links do not have to be symmetrical; for instance, here the edge betwe ``` section: options - protocol = barrier heartbeat = 5000 switchDelay = 500 end @@ -399,7 +398,6 @@ end | Options | Value Values| Description| |:--------|:-----------:|:-----------| -|protocol | barrier or synergy| The protocol to use when saying hello to clients. Can be set to barrier or synergy. If not set barrier is used as the default | |heartbeat| integer (N) | The server will expect each client to send a message no less than every `N` milliseconds. If no message arrives from a client within `3N` seconds the server forces that client to disconnect. If deskflow fails to detect clients disconnecting while the server is sleeping or vice versa, try using this option. | |switchCorners | none top-left top-right bottom-left bottom-right left right top bottom all | Deskflow won't switch computers when the mouse reaches the edge of the computer if it's in a listed corner. The size of all corners is given by the `switchCornerSize` option. The first name in the list is one of the above names and defines the initial set of corners. Subsequent names are prefixed with + or - to add the corner to or remove the corner from the set, respectively. For example: `all -left +top-left` starts will all corners, removes the left corners (top and bottom) then adds the top-left back in, resulting in the top-left, bottom-left and bottom-right corners.| |switchCornerSize | integer (N) | Sets the size of all corners in pixels. The cursor must be within `N` pixels of the corner to be considered to be in the corner.| diff --git a/src/lib/common/NetworkProtocol.h b/src/lib/common/NetworkProtocol.h index 7c4fce0cc..be54cfe60 100644 --- a/src/lib/common/NetworkProtocol.h +++ b/src/lib/common/NetworkProtocol.h @@ -5,6 +5,7 @@ */ #pragma once +#include #include inline static const auto kSynergyProtocolOption = "synergy"; @@ -16,6 +17,7 @@ enum class NetworkProtocol Synergy, Barrier }; +Q_DECLARE_METATYPE(NetworkProtocol); static int networkProtocolToInt(const NetworkProtocol proto) { diff --git a/src/lib/common/Settings.cpp b/src/lib/common/Settings.cpp index 6e162de03..e83b21cb4 100644 --- a/src/lib/common/Settings.cpp +++ b/src/lib/common/Settings.cpp @@ -6,6 +6,7 @@ #include "Settings.h" +#include "NetworkProtocol.h" #include "UrlConstants.h" #include @@ -105,6 +106,8 @@ void Settings::cleanSettings() { const QStringList keys = m_settings->allKeys(); for (const QString &key : keys) { + if (key.startsWith(QStringLiteral("internalConfig/protocol"))) + m_settings->remove(key); if (key.startsWith(QStringLiteral("internalConfig"))) continue; if (!m_validKeys.contains(key)) @@ -206,6 +209,9 @@ QVariant Settings::defaultValue(const QString &key) if (key == Client::YScrollScale || key == Client::XScrollScale) return 1.0; + if (key == Server::Protocol) + return QVariant::fromValue(NetworkProtocol::Barrier); + return QVariant(); } diff --git a/src/lib/common/Settings.h b/src/lib/common/Settings.h index 59295066a..af1ceb6a8 100644 --- a/src/lib/common/Settings.h +++ b/src/lib/common/Settings.h @@ -105,6 +105,7 @@ public: { inline static const auto ExternalConfig = QStringLiteral("server/externalConfig"); inline static const auto ExternalConfigFile = QStringLiteral("server/externalConfigFile"); + inline static const auto Protocol = QStringLiteral("server/protocol"); }; // Enums types used in settings @@ -251,6 +252,7 @@ private: , Settings::Security::TlsEnabled , Settings::Server::ExternalConfig , Settings::Server::ExternalConfigFile + , Settings::Server::Protocol }; // When checking the default values this list contains the ones that default to false. diff --git a/src/lib/deskflow/OptionTypes.h b/src/lib/deskflow/OptionTypes.h index ed0c249dc..86da2ef1f 100644 --- a/src/lib/deskflow/OptionTypes.h +++ b/src/lib/deskflow/OptionTypes.h @@ -44,7 +44,6 @@ static const OptionID kOptionModifierMapForAltGr = OPTION_CODE("MMFG"); static const OptionID kOptionModifierMapForMeta = OPTION_CODE("MMFM"); static const OptionID kOptionModifierMapForSuper = OPTION_CODE("MMFR"); static const OptionID kOptionHeartbeat = OPTION_CODE("HART"); -static const OptionID kOptionProtocol = OPTION_CODE("PROT"); static const OptionID kOptionScreenSwitchCorners = OPTION_CODE("SSCM"); static const OptionID kOptionScreenSwitchCornerSize = OPTION_CODE("SSCS"); static const OptionID kOptionScreenSwitchDelay = OPTION_CODE("SSWT"); diff --git a/src/lib/gui/config/ServerConfig.cpp b/src/lib/gui/config/ServerConfig.cpp index aff460f48..75f38e0a6 100644 --- a/src/lib/gui/config/ServerConfig.cpp +++ b/src/lib/gui/config/ServerConfig.cpp @@ -107,7 +107,6 @@ void ServerConfig::commit() settings().setValue("hasHeartbeat", hasHeartbeat()); settings().setValue("heartbeat", heartbeat()); - settings().setValue("protocol", static_cast(protocol())); settings().setValue("relativeMouseMoves", relativeMouseMoves()); settings().setValue("win32KeepForeground", win32KeepForeground()); settings().setValue("hasSwitchDelay", hasSwitchDelay()); @@ -159,7 +158,7 @@ void ServerConfig::recall() haveHeartbeat(settings().value("hasHeartbeat", false).toBool()); setHeartbeat(settings().value("heartbeat", 5000).toInt()); - setProtocol(networkProtocolFromInt(settings().value("protocol", networkProtocolToInt(protocol())).toInt())); + setProtocol(Settings::value(Settings::Server::Protocol).value()); setRelativeMouseMoves(settings().value("relativeMouseMoves", false).toBool()); setWin32KeepForeground(settings().value("win32KeepForeground", false).toBool()); haveSwitchDelay(settings().value("hasSwitchDelay", false).toBool()); diff --git a/src/lib/gui/dialogs/ServerConfigDialog.cpp b/src/lib/gui/dialogs/ServerConfigDialog.cpp index 83062f1e0..7ac8c3737 100644 --- a/src/lib/gui/dialogs/ServerConfigDialog.cpp +++ b/src/lib/gui/dialogs/ServerConfigDialog.cpp @@ -7,11 +7,12 @@ */ #include "ServerConfigDialog.h" -#include "common/PlatformInfo.h" #include "ui_ServerConfigDialog.h" #include "common/Constants.h" #include "common/NetworkProtocol.h" +#include "common/PlatformInfo.h" +#include "common/Settings.h" #include "dialogs/ActionDialog.h" #include "dialogs/HotkeyDialog.h" #include "dialogs/ScreenSettingsDialog.h" @@ -32,6 +33,7 @@ ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config) { ui->setupUi(this); + m_originalProtocol = Settings::value(Settings::Server::Protocol).value(); connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ServerConfigDialog::accept); connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ServerConfigDialog::reject); @@ -365,6 +367,7 @@ void ServerConfigDialog::toggleProtocol() { auto proto = ui->rbProtocolBarrier->isChecked() ? NetworkProtocol::Barrier : NetworkProtocol::Synergy; serverConfig().setProtocol(proto); + Settings::setValue(Settings::Server::Protocol, networkProtocolToOption(proto)); onChange(); } @@ -506,8 +509,10 @@ bool ServerConfigDialog::addComputer(const QString &clientName, bool doSilent) void ServerConfigDialog::onChange() { - bool isAppConfigDataEqual = m_originalServerConfigIsExternal == serverConfig().useExternalConfig() && - m_originalServerConfigUsesExternalFile == serverConfig().configFile(); + bool isAppConfigDataEqual = + m_originalServerConfigIsExternal == serverConfig().useExternalConfig() && + m_originalServerConfigUsesExternalFile == serverConfig().configFile() && + m_originalProtocol == Settings::value(Settings::Server::Protocol).value(); ui->buttonBox->button(QDialogButtonBox::Ok) ->setEnabled(!isAppConfigDataEqual || !(m_originalServerConfig == m_serverConfig)); } diff --git a/src/lib/gui/dialogs/ServerConfigDialog.h b/src/lib/gui/dialogs/ServerConfigDialog.h index d9faa7a14..5c5fa2582 100644 --- a/src/lib/gui/dialogs/ServerConfigDialog.h +++ b/src/lib/gui/dialogs/ServerConfigDialog.h @@ -98,6 +98,7 @@ private: std::unique_ptr ui; QString m_message = ""; ServerConfig &m_originalServerConfig; + NetworkProtocol m_originalProtocol; bool m_originalServerConfigIsExternal; QString m_originalServerConfigUsesExternalFile; ServerConfig m_serverConfig; diff --git a/src/lib/server/Config.cpp b/src/lib/server/Config.cpp index 2a4053640..0c2cd649e 100644 --- a/src/lib/server/Config.cpp +++ b/src/lib/server/Config.cpp @@ -635,7 +635,12 @@ void Config::readSectionOptions(ConfigReadContext &s) ++i; s.parseNameWithArgs("value", line, ",;\n", i, value, valueArgs); + // Skip old protocol name + if (name == "protocol") + continue; + bool handled = true; + if (name == "address") { try { m_deskflowAddress = NetworkAddress(value, kDefaultPort); @@ -645,8 +650,6 @@ void Config::readSectionOptions(ConfigReadContext &s) } } else if (name == "heartbeat") { addOption("", kOptionHeartbeat, s.parseInt(value)); - } else if (name == "protocol") { - addOption("", kOptionProtocol, s.parseProtocol(value)); } else if (name == "switchCorners") { addOption("", kOptionScreenSwitchCorners, s.parseCorners(value)); } else if (name == "switchCornerSize") { @@ -1314,13 +1317,6 @@ std::string Config::getOptionValue(OptionID id, OptionValue value) } return result; } - if (id == kOptionProtocol) { - const auto enumValue = networkProtocolFromInt(value); - if (enumValue == NetworkProtocol::Unknown) - throw InvalidProtocolException(); - return networkProtocolToOption(enumValue).toStdString(); - } - return ""; } @@ -1795,14 +1791,6 @@ OptionValue ConfigReadContext::parseCorner(const std::string &arg) const throw ServerConfigReadException(*this, "invalid argument \"%{1}\"", arg); } -OptionValue ConfigReadContext::parseProtocol(const std::string &args) const -{ - const auto protoValue = networkProtocolFromString(QString::fromStdString(args)); - if (protoValue == NetworkProtocol::Unknown) - throw ServerConfigReadException(*this, "invalid protocol argument \"%{1}\"", args); - return static_cast(protoValue); -} - OptionValue ConfigReadContext::parseCorners(const std::string &args) const { // find first token diff --git a/src/lib/server/Server.cpp b/src/lib/server/Server.cpp index 8e55e6b58..b61afa6bd 100644 --- a/src/lib/server/Server.cpp +++ b/src/lib/server/Server.cpp @@ -1085,12 +1085,7 @@ void Server::processOptions() for (auto [optionId, optionValue] : *options) { const OptionID id = optionId; const OptionValue value = optionValue; - if (id == kOptionProtocol) { - const auto enumValue = networkProtocolFromInt(value); - if (enumValue == NetworkProtocol::Unknown) - throw InvalidProtocolException(); - m_protocol = enumValue; - } else if (id == kOptionScreenSwitchDelay) { + if (id == kOptionScreenSwitchDelay) { m_switchWaitDelay = 1.0e-3 * static_cast(value); if (m_switchWaitDelay < 0.0) { m_switchWaitDelay = 0.0; @@ -1135,6 +1130,7 @@ void Server::processOptions() stopRelativeMoves(); } m_relativeMoves = newRelativeMoves; + m_protocol = Settings::value(Settings::Server::Protocol).value(); } void Server::handleShapeChanged(BaseClientProxy *client)