From 488d620b3b3677c50e771a09268ffa42999596fa Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Sun, 14 Jun 2026 21:07:35 -0400 Subject: [PATCH] refactor(Settings): Move heartbeat to general settings --- docs/user/configuration.md | 6 ++---- src/lib/common/Settings.cpp | 3 +++ src/lib/common/Settings.h | 3 +++ src/lib/gui/config/ServerConfig.cpp | 6 ------ src/lib/gui/config/ServerConfig.h | 9 --------- src/lib/gui/dialogs/ServerConfigDialog.cpp | 12 +++++++++--- src/lib/gui/dialogs/ServerConfigDialog.h | 1 + src/lib/server/Config.cpp | 17 ++++++++++------- 8 files changed, 28 insertions(+), 29 deletions(-) diff --git a/docs/user/configuration.md b/docs/user/configuration.md index 20c015bfd..832dc9575 100644 --- a/docs/user/configuration.md +++ b/docs/user/configuration.md @@ -149,6 +149,7 @@ This section contains options used when in server mode it will begin with `[serv | externalConfigFile | Filepath | Path the server config file if it does not exist the GUI will it generated based on the `internalConfig` section.| | gridHeight | int | Height of the server's intenal grid used for the computer layout (default: 3)| | gridWidth | int | Width of the server's intenal grid used for the computer layout (default: 5) | +| heartbeat | int | 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. | | 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 | | xdpRestoreToken | UUID | Restore token provided by XDG portals | @@ -163,7 +164,6 @@ clipboardSharing=true clipboardSharingSize=@Variant(\0\0\0\x84\0\0\0\0\0\0<\0) defaultLockToScreenState=false disableLockToScreen=false -heartbeat=5000 hotkeys\1\actions\1\activeOnRelease=false hotkeys\1\actions\1\hasScreens=true hotkeys\1\actions\1\keys\1\key=83 @@ -390,8 +390,7 @@ Note that links do not have to be symmetrical; for instance, here the edge betwe ``` section: options - heartbeat = 5000 - switchDelay = 500 + switchDelay = 500 end ``` @@ -399,7 +398,6 @@ end | Options | Value Values| Description| |:--------|:-----------:|:-----------| -|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.| |switchDelay | integer| Deskflow won't switch computers when the mouse reaches edge of a computer unless it stays on the edge for `N` milliseconds. This helps prevent unintentional switching when working near an edge.| diff --git a/src/lib/common/Settings.cpp b/src/lib/common/Settings.cpp index 1b380e3e9..576ebc01f 100644 --- a/src/lib/common/Settings.cpp +++ b/src/lib/common/Settings.cpp @@ -216,6 +216,9 @@ QVariant Settings::defaultValue(const QString &key) if (key == Server::GridHeight) return kServerGridHeight; + if (key == Server::Heartbeat) + return 5000; + return QVariant(); } diff --git a/src/lib/common/Settings.h b/src/lib/common/Settings.h index c8778fe5f..11355bca0 100644 --- a/src/lib/common/Settings.h +++ b/src/lib/common/Settings.h @@ -111,6 +111,7 @@ public: inline static const auto ExternalConfigFile = QStringLiteral("server/externalConfigFile"); inline static const auto GridHeight = QStringLiteral("server/gridHeight"); inline static const auto GridWidth = QStringLiteral("server/gridWidth"); + inline static const auto Heartbeat = QStringLiteral("server/heartbeat"); inline static const auto Protocol = QStringLiteral("server/protocol"); inline static const auto XdpRestoreToken = QStringLiteral("server/xdpRestoreToken"); }; @@ -253,6 +254,7 @@ private: , Settings::Server::ExternalConfigFile , Settings::Server::GridHeight , Settings::Server::GridWidth + , Settings::Server::Heartbeat , Settings::Server::Protocol , Settings::Server::XdpRestoreToken }; @@ -305,6 +307,7 @@ private: QStringLiteral("internalConfig/hasHeartbeat") , QStringLiteral("internalConfig/hasSwitchDelay") , QStringLiteral("internalConfig/hasSwitchDoubleTap") + , QStringLiteral("internalConfig/heartbeat") , QStringLiteral("internalConfig/protocol") , QStringLiteral("internalConfig/numColumns") , QStringLiteral("internalConfig/numRows") diff --git a/src/lib/gui/config/ServerConfig.cpp b/src/lib/gui/config/ServerConfig.cpp index e48329da0..feb4bbcdd 100644 --- a/src/lib/gui/config/ServerConfig.cpp +++ b/src/lib/gui/config/ServerConfig.cpp @@ -53,7 +53,6 @@ bool ServerConfig::save(const QString &fileName) const bool ServerConfig::operator==(const ServerConfig &sc) const { return m_Screens == sc.m_Screens && // - m_Heartbeat == sc.m_Heartbeat && // m_RelativeMouseMoves == sc.m_RelativeMouseMoves && // m_Win32KeepForeground == sc.m_Win32KeepForeground && // m_SwitchDelay == sc.m_SwitchDelay && // @@ -96,7 +95,6 @@ void ServerConfig::commit() settings().beginGroup("internalConfig"); settings().remove(""); - settings().setValue("heartbeat", heartbeat()); settings().setValue("relativeMouseMoves", relativeMouseMoves()); settings().setValue("win32KeepForeground", win32KeepForeground()); settings().setValue("switchDelay", switchDelay()); @@ -144,7 +142,6 @@ void ServerConfig::recall() // ourselves setupScreens(); - setHeartbeat(settings().value("heartbeat", 5000).toInt()); setRelativeMouseMoves(settings().value("relativeMouseMoves", false).toBool()); setWin32KeepForeground(settings().value("win32KeepForeground", false).toBool()); setSwitchDelay(settings().value("switchDelay", 250).toInt()); @@ -238,9 +235,6 @@ QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config) outStream << "section: options" << Qt::endl; - if (Settings::value(Settings::Server::EnableHeatbeat).toBool()) - outStream << "\t" << "heartbeat = " << config.heartbeat() << Qt::endl; - outStream << "\t" << "relativeMouseMoves = " << (config.relativeMouseMoves() ? "true" : "false") << Qt::endl; outStream << "\t" diff --git a/src/lib/gui/config/ServerConfig.h b/src/lib/gui/config/ServerConfig.h index 6c0b78026..c65ed2efd 100644 --- a/src/lib/gui/config/ServerConfig.h +++ b/src/lib/gui/config/ServerConfig.h @@ -40,10 +40,6 @@ public: // // New methods // - int heartbeat() const - { - return m_Heartbeat; - } bool relativeMouseMoves() const { return m_RelativeMouseMoves; @@ -122,10 +118,6 @@ private: { m_Screens.append(screen); } - void setHeartbeat(int val) - { - m_Heartbeat = val; - } void setRelativeMouseMoves(bool on) { m_RelativeMouseMoves = on; @@ -178,7 +170,6 @@ private: bool fixNoServer(const QString &name, int &index); private: - int m_Heartbeat = 0; bool m_RelativeMouseMoves = false; bool m_Win32KeepForeground = false; int m_SwitchDelay = 0; diff --git a/src/lib/gui/dialogs/ServerConfigDialog.cpp b/src/lib/gui/dialogs/ServerConfigDialog.cpp index d97cc6a24..d7edb549f 100644 --- a/src/lib/gui/dialogs/ServerConfigDialog.cpp +++ b/src/lib/gui/dialogs/ServerConfigDialog.cpp @@ -77,6 +77,7 @@ void ServerConfigDialog::accept() setOriginalServerConfig(serverConfig()); Settings::setValue(Settings::Server::Protocol, networkProtocolToOption(m_protocol)); Settings::setValue(Settings::Server::EnableHeatbeat, m_enableHeartbeat); + Settings::setValue(Settings::Server::Heartbeat, m_heartbeatRate); Settings::setValue(Settings::Server::EnableSwitchDelay, m_enableSwitchDelay); Settings::setValue(Settings::Server::EnableSwitchDoubleTap, m_enableSwitchDoubleTap); @@ -234,7 +235,9 @@ void ServerConfigDialog::toggleHeartbeat(bool enabled) void ServerConfigDialog::setHeartbeat(int rate) { - serverConfig().setHeartbeat(rate); + if (rate == m_heartbeatRate) + return; + m_heartbeatRate = rate; onChange(); } @@ -350,7 +353,6 @@ void ServerConfigDialog::toggleExternalConfig(bool checked) ui->groupMisc->setEnabled(!checked); ui->groupCorners->setEnabled(!checked); ui->groupSwitch->setEnabled(!checked); - ui->widgetHeartbeat->setEnabled(!checked); serverConfig().setUseExternalConfig(checked); onChange(); } @@ -385,7 +387,10 @@ void ServerConfigDialog::loadFromConfig() m_enableHeartbeat = Settings::value(Settings::Server::EnableHeatbeat).toBool(); ui->cbHeartbeat->setChecked(m_enableHeartbeat); ui->sbHeartbeat->setEnabled(ui->cbHeartbeat->isChecked()); - ui->sbHeartbeat->setValue(serverConfig().heartbeat()); + + m_heartbeatRate = Settings::value(Settings::Server::Heartbeat).toInt(); + ui->sbHeartbeat->setValue(m_heartbeatRate); + ui->cbRelativeMouseMoves->setChecked(serverConfig().relativeMouseMoves()); ui->cbWin32KeepForeground->setChecked(serverConfig().win32KeepForeground()); @@ -516,6 +521,7 @@ void ServerConfigDialog::onChange() m_originalServerConfigUsesExternalFile == serverConfig().configFile() && m_protocol == Settings::networkProtocol() && m_enableHeartbeat == Settings::value(Settings::Server::EnableHeatbeat).toBool() && + m_heartbeatRate == Settings::value(Settings::Server::Heartbeat).toInt() && m_enableSwitchDelay == Settings::value(Settings::Server::EnableSwitchDelay).toBool() && m_enableSwitchDoubleTap == Settings::value(Settings::Server::EnableSwitchDoubleTap).toBool(); ui->buttonBox->button(QDialogButtonBox::Ok) diff --git a/src/lib/gui/dialogs/ServerConfigDialog.h b/src/lib/gui/dialogs/ServerConfigDialog.h index f39180302..9b73405f3 100644 --- a/src/lib/gui/dialogs/ServerConfigDialog.h +++ b/src/lib/gui/dialogs/ServerConfigDialog.h @@ -105,6 +105,7 @@ private: ServerConfig &m_originalServerConfig; NetworkProtocol m_protocol; bool m_enableHeartbeat; + int m_heartbeatRate; bool m_enableSwitchDelay; bool m_enableSwitchDoubleTap; bool m_originalServerConfigIsExternal; diff --git a/src/lib/server/Config.cpp b/src/lib/server/Config.cpp index 2f8d4850f..2c09d3b44 100644 --- a/src/lib/server/Config.cpp +++ b/src/lib/server/Config.cpp @@ -9,7 +9,6 @@ #include "server/Config.h" #include "base/IEventQueue.h" -#include "deskflow/DeskflowException.h" #include "deskflow/KeyMap.h" #include "deskflow/KeyTypes.h" #include "deskflow/OptionTypes.h" @@ -635,12 +634,13 @@ 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; + // Skip old protocol name + if (name == "protocol" || name == "heartbeat") { + continue; + } + if (name == "address") { try { m_deskflowAddress = NetworkAddress(value, kDefaultPort); @@ -648,8 +648,6 @@ void Config::readSectionOptions(ConfigReadContext &s) } catch (SocketAddressException &e) { throw ServerConfigReadException(s, std::string("invalid address argument ") + e.what()); } - } else if (name == "heartbeat") { - addOption("", kOptionHeartbeat, s.parseInt(value)); } else if (name == "switchCorners") { addOption("", kOptionScreenSwitchCorners, s.parseCorners(value)); } else if (name == "switchCornerSize") { @@ -723,6 +721,11 @@ void Config::readSectionOptions(ConfigReadContext &s) m_inputFilter.addFilterRule(rule); } } + + if (Settings::value(Settings::Server::EnableHeatbeat).toBool()) { + addOption("", kOptionHeartbeat, Settings::value(Settings::Server::Heartbeat).toInt()); + } + throw ServerConfigReadException(s, "unexpected end of options section"); }