diff --git a/dashboard/qml/Main.qml b/dashboard/qml/Main.qml index 3b1b7612..88144639 100644 --- a/dashboard/qml/Main.qml +++ b/dashboard/qml/Main.qml @@ -165,7 +165,7 @@ Kirigami.ApplicationWindow { text: i18n("Firewall may not allow port 9757") type: Kirigami.MessageType.Warning showCloseButton: true - visible: DashboardSettings.show_system_checks && Firewall.needSetup + visible: DashboardSettings.show_system_checks && Firewall.needSetup && Settings.port == Settings.default_port actions: [ Kirigami.Action { text: i18n("Fix it") diff --git a/dashboard/settings.cpp b/dashboard/settings.cpp index 6f2a7bcc..e378c558 100644 --- a/dashboard/settings.cpp +++ b/dashboard/settings.cpp @@ -21,6 +21,7 @@ #include "escape_string.h" #include "gui_config.h" #include "utils/flatpak.h" +#include "wivrn_config.h" #include "wivrn_server.h" #include #include @@ -121,6 +122,8 @@ void Settings::emitAllChanged() debugGuiChanged(); steamVrLhChanged(); hidForwardingChanged(); + portChanged(); + hostnameChanged(); } void Settings::load(const wivrn_server * server) @@ -429,6 +432,40 @@ void Settings::set_tcpOnly(const bool & value) tcpOnlyChanged(); } +int Settings::port() const +{ + auto it = m_jsonSettings.find("port"); + if (it != m_jsonSettings.end() and it->is_number_integer()) + return *it; + return wivrn::default_port; +} + +void Settings::set_port(const int & value) +{ + auto old = port(); + m_jsonSettings["port"] = value; + if (old != value) + portChanged(); +} + +QString Settings::hostname() const +{ + if (auto it = m_jsonSettings.find("hostname"); it != m_jsonSettings.end() and it->is_string()) + return QString::fromStdString(*it); + return ""; +} + +void Settings::set_hostname(const QString & value) +{ + auto old = hostname(); + if (value == "") + m_jsonSettings.erase("hostname"); + else + m_jsonSettings["hostname"] = value.toStdString(); + if (old != value) + hostnameChanged(); +} + QString Settings::openvr() const { // OpenVR compat library @@ -504,6 +541,8 @@ void Settings::restore_defaults() m_jsonSettings.erase("use-steamvr-lh"); m_jsonSettings.erase("tcp-only"); m_jsonSettings.erase("application"); + m_jsonSettings.erase("port"); + m_jsonSettings.erase("hostname"); emitAllChanged(); } @@ -512,6 +551,11 @@ bool Settings::flatpak() const return wivrn::is_flatpak(); } +int Settings::default_port() const +{ + return wivrn::default_port; +} + bool Settings::debug_gui() const { #if WIVRN_FEATURE_DEBUG_GUI diff --git a/dashboard/settings.h b/dashboard/settings.h index 473a2e9a..5342a22b 100644 --- a/dashboard/settings.h +++ b/dashboard/settings.h @@ -68,6 +68,8 @@ public: Q_PROPERTY(bool tenbit READ tenbit WRITE set_tenbit NOTIFY tenbitChanged) Q_PROPERTY(bool tcpOnly READ tcpOnly WRITE set_tcpOnly NOTIFY tcpOnlyChanged) + Q_PROPERTY(int port READ port WRITE set_port NOTIFY portChanged) + Q_PROPERTY(QString hostname READ hostname WRITE set_hostname NOTIFY hostnameChanged) Q_PROPERTY(QString application READ application WRITE set_application NOTIFY applicationChanged) Q_PROPERTY(QString openvr READ openvr WRITE set_openvr NOTIFY openvrChanged) @@ -76,6 +78,7 @@ public: Q_PROPERTY(bool steamVrLh READ steamVrLh WRITE set_steamVrLh NOTIFY steamVrLhChanged) Q_PROPERTY(bool flatpak READ flatpak CONSTANT) + Q_PROPERTY(int default_port READ default_port CONSTANT) Q_PROPERTY(bool hid_forwarding_supported READ hid_forwarding CONSTANT) Q_PROPERTY(bool debug_gui_supported READ debug_gui CONSTANT) Q_PROPERTY(bool steamvr_lh_supported READ steamvr_lh CONSTANT) @@ -89,6 +92,8 @@ public: SETTER_GETTER_NOTIFY(bool, debugGui) SETTER_GETTER_NOTIFY(bool, steamVrLh) SETTER_GETTER_NOTIFY(bool, tcpOnly) + SETTER_GETTER_NOTIFY(int, port) + SETTER_GETTER_NOTIFY(QString, hostname) SETTER_GETTER_NOTIFY(QString, openvr) private: nlohmann::json m_jsonSettings = nlohmann::json::object(); @@ -107,6 +112,7 @@ public: bool can10bit() const; bool flatpak() const; + int default_port() const; bool debug_gui() const; bool steamvr_lh() const; bool hid_forwarding() const; diff --git a/docs/configuration.md b/docs/configuration.md index 4b9dff6c..da108923 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -158,3 +158,13 @@ Default value: `false` Only available when built with `WIVRN_FEATURE_STEAMVR_LIGHTHOUSE` Enables the driver to load SteamVR Lighthouse devices. + +## `port` +Default value: `9757` + +Change the TCP/UDP port used for the connection. + +## `hostname` +Default value: unset + +If set, overrides the name displayed in the server list. diff --git a/server/accept_connection.cpp b/server/accept_connection.cpp index fb6a011f..e7961e35 100644 --- a/server/accept_connection.cpp +++ b/server/accept_connection.cpp @@ -22,8 +22,8 @@ #include "util/u_logging.h" #include "utils/overloaded.h" +#include "driver/configuration.h" #include "driver/wivrn_session.h" -#include "wivrn_config.h" #include "wivrn_ipc.h" #include "wivrn_sockets.h" @@ -33,7 +33,7 @@ std::unique_ptr wivrn::accept_connection(wivrn_session & cnx, std::s { wivrn_ipc_socket_monado->send(from_monado::headset_disconnected{}); - wivrn::TCPListener listener(wivrn::default_port); + wivrn::TCPListener listener(configuration().port); pollfd fds[2]{ {.fd = listener.get_fd(), .events = POLLIN}, diff --git a/server/driver/configuration.cpp b/server/driver/configuration.cpp index 436c0f94..da4a9f9e 100644 --- a/server/driver/configuration.cpp +++ b/server/driver/configuration.cpp @@ -204,6 +204,12 @@ configuration::configuration() if (auto it = json.find("tcp-only"); it != json.end()) tcp_only = *it; + if (auto it = json.find("port"); it != json.end()) + port = *it; + + if (auto it = json.find("hostname"); it != json.end()) + hostname = *it; + if (auto it = json.find("publish-service"); it != json.end()) { publication = *it; diff --git a/server/driver/configuration.h b/server/driver/configuration.h index 37879ec5..a1fcd191 100644 --- a/server/driver/configuration.h +++ b/server/driver/configuration.h @@ -19,6 +19,8 @@ #pragma once +#include "hostname.h" +#include "wivrn_config.h" #include #include #include @@ -57,6 +59,8 @@ struct configuration bool use_steamvr_lh = false; bool hid_forwarding = false; bool tcp_only = false; + int port = wivrn::default_port; + std::string hostname = wivrn::hostname(); service_publication publication = service_publication::avahi; // monostate: default value, string: user defined, nullptr: disabled diff --git a/server/main.cpp b/server/main.cpp index bcb6bd57..f78ebf09 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -15,7 +15,6 @@ #include "driver/configuration.h" #include "driver/wivrn_connection.h" #include "exit_codes.h" -#include "hostname.h" #include "ipc_server_cb.h" #include "protocol_version.h" #include "start_application.h" @@ -315,7 +314,7 @@ void start_listening() assert(listener_watch == 0); - listener = std::make_unique(wivrn::default_port); + listener = std::make_unique(configuration().port); auto source_listener = g_unix_fd_source_new(listener->get_fd(), GIOCondition::G_IO_IN); g_source_set_callback(source_listener, G_SOURCE_FUNC(&headset_connected), nullptr, nullptr); listener_watch = g_source_attach(source_listener, nullptr); @@ -352,7 +351,8 @@ void start_publishing() {"version", wivrn::display_version()}, {"cookie", server_cookie()}, }; - publisher.emplace(poll_api, hostname(), "_wivrn._tcp", wivrn::default_port, TXT); + auto configuration = wivrn::configuration(); + publisher.emplace(poll_api, configuration.hostname, "_wivrn._tcp", configuration.port, TXT); } } }