diff --git a/dashboard/CMakeLists.txt b/dashboard/CMakeLists.txt deleted file mode 100644 index cf154857..00000000 --- a/dashboard/CMakeLists.txt +++ /dev/null @@ -1,106 +0,0 @@ -# Qt 6.7 changed qt_add_translations() -try_compile(AT_LEAST_QT67 SOURCE_FROM_CONTENT check-qt-version.cpp " -#include - -#if (QT_VERSION < QT_VERSION_CHECK(6, 7, 0)) -#error -#endif - -int main() {} -" LINK_LIBRARIES Qt6::Core) - -qt_add_executable(wivrn-dashboard - main.cpp - main_window.cpp - main_window.h - main_window.ui - manage_headsets.cpp - manage_headsets.h - manage_headsets.ui - settings.cpp - settings.h - settings.ui - wivrn_server.cpp - wivrn_server.h - wizard.cpp - wizard.h - wizard.ui - rectangle_partitionner.cpp - rectangle_partitionner.h - steam_app.cpp - steam_app.h - adb.cpp - adb.h -) - -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/wivrn.png - COMMAND ${RSVG_CONVERT} ${CMAKE_CURRENT_SOURCE_DIR}/../images/wivrn.svg -w 540 -h 540 -o ${CMAKE_CURRENT_BINARY_DIR}/wivrn.png - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../images/wivrn.svg) - -add_custom_target(dashboard-assets ALL DEPENDS - ${CMAKE_CURRENT_BINARY_DIR}/wivrn.png -) - -add_dependencies(wivrn-dashboard dashboard-assets) - -set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../images/wivrn.svg PROPERTIES QT_RESOURCE_ALIAS "images/wivrn.svg") -set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/wivrn.png PROPERTIES QT_RESOURCE_ALIAS "images/wivrn.png") - -qt_add_resources(wivrn-dashboard wivrn-dashboard-resources PREFIX / FILES - ${CMAKE_CURRENT_SOURCE_DIR}/../images/wivrn.svg - ${CMAKE_CURRENT_BINARY_DIR}/wivrn.png -) - -set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../dbus/io.github.wivrn.Server.xml PROPERTIES INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/wivrn_qdbus_types.h") -qt_add_dbus_interface(DBUS_INTERFACE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../dbus/io.github.wivrn.Server.xml wivrn_server_dbus) -target_sources(wivrn-dashboard PRIVATE ${DBUS_INTERFACE_SRC}) - -target_compile_features(wivrn-dashboard PRIVATE cxx_std_20) -target_include_directories(wivrn-dashboard PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) - -configure_file(gui_config.h.in gui_config.h) -configure_file(io.github.wivrn.wivrn.desktop.in io.github.wivrn.wivrn.desktop) - -target_link_libraries(wivrn-dashboard PRIVATE - Qt6::Core - Qt6::Gui - Qt6::Widgets - Qt6::DBus - Qt6::Network - nlohmann_json - wivrn-common-base - Vulkan::Vulkan -) - -target_compile_definitions(wivrn-dashboard PRIVATE JSON_DIAGNOSTICS=1) - -if (WIVRN_CHECK_CAPSYSNICE) - target_link_libraries(wivrn-dashboard PRIVATE PkgConfig::libcap) -endif() - -file(GLOB TRANSLATION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/wivrn_*.ts) - -if (AT_LEAST_QT67) - qt_add_translations(wivrn-dashboard SOURCE_TARGETS wivrn-dashboard TS_FILES ${TRANSLATION_FILES}) -else() - qt_add_translations(wivrn-dashboard TS_FILES ${TRANSLATION_FILES}) -endif() - -# https://16bpp.net/blog/post/localizing-a-qt-app-or-anything-else-for-that-matter/, CMake Setup -# https://gist.github.com/define-private-public/f01ff2f9bbb74eded144558a2e02966c#file-cmakelists-2-txt -add_dependencies(wivrn-dashboard release_translations) - -install(TARGETS wivrn-dashboard) - -install(FILES io.github.wivrn.wivrn.metainfo.xml - DESTINATION share/metainfo -) - -install(FILES ../images/wivrn.svg - DESTINATION share/icons/hicolor/scalable/apps - RENAME io.github.wivrn.wivrn.svg -) - -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/io.github.wivrn.wivrn.desktop - DESTINATION share/applications -) diff --git a/dashboard/adb.cpp b/dashboard/adb.cpp deleted file mode 100644 index 4b31f07b..00000000 --- a/dashboard/adb.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "adb.h" - -#include "utils/flatpak.h" - -#include -#include -#include -#include - -using namespace std::chrono_literals; - -template -std::unique_ptr escape_sandbox(const std::string & executable, Args &&... args_orig) -{ - auto process = std::make_unique(); - QStringList args; - - if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk") - { - process->setProgram("flatpak-spawn"); - args.push_back("--host"); - args.push_back(QString::fromStdString(executable)); - } - else - { - process->setProgram(QString::fromStdString(executable)); - } - - (args.push_back(QString::fromStdString(args_orig)), ...); - - process->setArguments(args); - - return process; -} - -adb::adb() -{ - poll_devices_timer.setInterval(500ms); - connect(&poll_devices_timer, &QTimer::timeout, this, &adb::on_poll_devices_timeout); - - on_poll_devices_timeout(); - poll_devices_timer.start(); -} - -void adb::on_poll_devices_timeout() -{ - if (poll_devices_process) - return; - - poll_devices_process = escape_sandbox("adb", "devices", "-l"); - connect(poll_devices_process.get(), &QProcess::finished, this, &adb::on_poll_devices_process_finished); - poll_devices_process->start(); -} - -void adb::on_poll_devices_process_finished(int exit_code, QProcess::ExitStatus exit_status) -{ - if (exit_code != 0 or exit_status != QProcess::NormalExit) - { - qDebug() << "adb devices exited with code" << exit_code << ", status" << exit_status; - - QString out = poll_devices_process->readAllStandardOutput(); - qDebug() << "stdout:" << out; - - QString err = poll_devices_process->readAllStandardError(); - qDebug() << "stderr:" << err; - } - else - { - auto out = poll_devices_process->readAllStandardOutput(); - auto lines = QString{out}.split('\n'); - - if (not lines.empty()) - lines.pop_front(); - - std::vector devs; - for (auto & line: lines) - { - auto words = line.split(' ', Qt::SkipEmptyParts); - device dev; - - if (words.empty()) - continue; - dev._serial = words.front().toStdString(); - words.pop_front(); - - if (words.empty()) - continue; - dev._state = words.front().toStdString(); - words.pop_front(); - - for (auto & word: words) - { - auto idx = word.indexOf(':'); - if (idx >= 0) - { - dev._properties[word.left(idx).toStdString()] = word.mid(idx + 1).toStdString(); - } - } - - devs.push_back(dev); - } - - _android_devices = std::move(devs); - android_devices_changed(_android_devices); - } - - poll_devices_process.release()->deleteLater(); -} - -std::unique_ptr adb::device::install(const std::filesystem::path & path) -{ - return escape_sandbox("adb", "-s", _serial, "install", "-r", path); -} - -std::unique_ptr adb::device::uninstall(const std::string & app) -{ - return escape_sandbox("adb", "-s", _serial, "uninstall", app); -} - -std::vector adb::device::installed_apps() -{ - auto process = escape_sandbox("adb", "-s", _serial, "shell", "pm", "list", "packages"); - process->start(); - process->waitForFinished(); - - if (process->exitCode() != 0 or process->exitStatus() != QProcess::NormalExit) - throw std::runtime_error("Cannot list packages"); - - auto out = process->readAllStandardOutput(); - auto lines = QString{out}.split('\n'); - - std::vector apps; - - for (auto & line: lines) - { - QString prefix = "package:"; - if (line.startsWith(prefix)) - { - apps.push_back(line.toStdString().substr(prefix.size())); - } - } - - return apps; -} - -// void adb::device::start(const std::string& app) -// { -// auto process = escape_sandbox("adb", "-s", _serial, "shell", "am", "start", app); -// process->start(); -// process->waitForFinished(); -// } -// -// void adb::device::stop(const std::string& app) -// { -// auto process = escape_sandbox("adb", "-s", _serial, "shell", "am", "force-stop", app); -// process->start(); -// process->waitForFinished(); -// } -// -void adb::device::start(const std::string & app, const std::string & action, const std::string & uri) -{ - // action: "android.intent.action.VIEW" or "android.intent.action.MAIN" - auto process = escape_sandbox("adb", "-s", _serial, "shell", "am", "start", "-a", action, "-d", uri, app); - process->start(); - process->waitForFinished(); -} - -void adb::device::reverse_forward(int local_port, int device_port) -{ - auto process = escape_sandbox("adb", "-s", _serial, "reverse", "tcp:" + std::to_string(local_port), "tcp:" + std::to_string(device_port)); - process->start(); - process->waitForFinished(); -} - -#include "moc_adb.cpp" diff --git a/dashboard/adb.h b/dashboard/adb.h deleted file mode 100644 index 664219f2..00000000 --- a/dashboard/adb.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -class QProcess; - -class adb : public QObject -{ - Q_OBJECT - -public: - class device - { - std::string _serial; - std::string _state; - std::map _properties; - - friend class adb; - - public: - device() = default; - device(const device &) = default; - device(device &&) = default; - device & operator=(const device &) = default; - device & operator=(device &&) = default; - - const auto & serial() const - { - return _serial; - }; - - const auto & state() const - { - return _state; - }; - - const auto & properties() const - { - return _properties; - }; - - bool operator==(const device & other) const - { - return _serial == other._serial; - } - - operator bool() const - { - return _serial != ""; - } - - std::unique_ptr install(const std::filesystem::path & path); - std::unique_ptr uninstall(const std::string & app); - void start(const std::string & app, const std::string & action, const std::string & uri); - void reverse_forward(int local_port, int device_port); - std::vector installed_apps(); - }; - -private: - QTimer poll_devices_timer; - std::unique_ptr poll_devices_process; - std::vector _android_devices; - - void on_poll_devices_timeout(); - void on_poll_devices_process_finished(int exit_code, QProcess::ExitStatus exit_status); - -public: - adb(); - adb(const adb &) = delete; - adb & operator=(const adb &) = delete; - - const std::vector & devices() const - { - return _android_devices; - } - - void start() - { - poll_devices_timer.start(); - } - - void stop() - { - poll_devices_timer.stop(); - } - -Q_SIGNALS: - void android_devices_changed(const std::vector &); -}; diff --git a/dashboard/escape_string.h b/dashboard/escape_string.h deleted file mode 100644 index 07a5e77e..00000000 --- a/dashboard/escape_string.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include - -constexpr std::string escape_string(const std::vector & app) -{ - constexpr std::string_view escaped_chars = R"( '"\)"; - std::string app_string; - for (const auto & i: app) - { - for (char c: i) - { - if (escaped_chars.find(c) == std::string_view::npos) - { - app_string += c; - } - else - { - app_string += '\\'; - app_string += c; - } - } - - app_string += ' '; - } - app_string.resize(app_string.size() - 1); - - return app_string; -} - -constexpr std::vector unescape_string(const std::string & app_string) -{ - std::vector app; - app.emplace_back(); - - bool seen_backslash = false; - bool seen_single_quote = false; - bool seen_double_quote = false; - for (auto c: app_string) - { - if (seen_backslash) - { - app.back() += c; - seen_backslash = false; - } - else if (seen_single_quote) - { - if (c == '\'') - seen_single_quote = false; - else if (c == '\\') - seen_backslash = true; - else - app.back() += c; - } - else if (seen_double_quote) - { - if (c == '"') - seen_double_quote = false; - else if (c == '\\') - seen_backslash = true; - else - app.back() += c; - } - else - { - switch (c) - { - case '\\': - seen_backslash = true; - break; - case '\'': - seen_single_quote = true; - break; - case '"': - seen_double_quote = true; - break; - case ' ': - if (not app.back().empty()) - app.emplace_back(); - break; - default: - app.back() += c; - } - } - } - - if (app.back().empty()) - app.pop_back(); - - return app; -} - -#ifdef __clang__ -static_assert(escape_string({"abc", "def"}) == R"(abc def)"); -static_assert(escape_string({"ab\"c", "def"}) == R"(ab\"c def)"); -static_assert(escape_string({"ab'c", "def"}) == R"(ab\'c def)"); -static_assert(escape_string({"ab\\c", "def"}) == R"(ab\\c def)"); - -static_assert(unescape_string(R"(abc def)") == std::vector{"abc", "def"}); -static_assert(unescape_string(R"(ab\"c def)") == std::vector{"ab\"c", "def"}); -static_assert(unescape_string(R"(ab\'c def)") == std::vector{"ab'c", "def"}); -static_assert(unescape_string(R"(ab\\c def)") == std::vector{"ab\\c", "def"}); -#endif diff --git a/dashboard/gui_config.h.in b/dashboard/gui_config.h.in deleted file mode 100644 index f5e9ec42..00000000 --- a/dashboard/gui_config.h.in +++ /dev/null @@ -1,27 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * Copyright (C) 2024 Patrick Nicolas - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#cmakedefine01 WIVRN_CHECK_CAPSYSNICE - -#cmakedefine01 WIVRN_USE_NVENC -#cmakedefine01 WIVRN_USE_VAAPI -#cmakedefine01 WIVRN_USE_VULKAN_ENCODE -#cmakedefine01 WIVRN_USE_X264 diff --git a/dashboard/io.github.wivrn.wivrn.desktop.in b/dashboard/io.github.wivrn.wivrn.desktop.in deleted file mode 100644 index a4d97c1c..00000000 --- a/dashboard/io.github.wivrn.wivrn.desktop.in +++ /dev/null @@ -1,8 +0,0 @@ -[Desktop Entry] -Name=WiVRn server -Comment=Play your PC VR games on a standalone headset -GenericName=WiVRn dashboard -Exec=@CMAKE_INSTALL_PREFIX@/bin/wivrn-dashboard -Icon=io.github.wivrn.wivrn -Type=Application -Categories=Network diff --git a/dashboard/io.github.wivrn.wivrn.metainfo.xml b/dashboard/io.github.wivrn.wivrn.metainfo.xml deleted file mode 100644 index e3138cd9..00000000 --- a/dashboard/io.github.wivrn.wivrn.metainfo.xml +++ /dev/null @@ -1,162 +0,0 @@ - - - io.github.wivrn.wivrn - WiVRn server - FSFAP - GPL-3.0-or-later - Play your PC VR games on a standalone headset - -

WiVRn allows you to run your VR games from your PC and play them from a standalone headset.

- -

You will need to install the WiVRn client on your headset from the Meta Store or by following the wizard in the application.

- -

Supported headsets:

-
    -
  • Meta Quest 1
  • -
  • Meta Quest 2
  • -
  • Meta Quest 3
  • -
  • Meta Quest 3S
  • -
  • Meta Quest Pro
  • -
  • Pico Neo 4
  • -
  • HTC Vive Focus 3
  • -
  • HTC Vive XR Elite
  • -
-

Features:

-
    -
  • Supports OpenXR and OpenVR applications
  • -
  • Controller tracking, hand tracking, eye gaze tracking (if supported by the headset)
  • -
  • Audio streaming and microphone
  • -
  • Video streaming with H264 / HEVC / AV1 compression
  • -
  • Hardware accelerated compression with VAAPI or NVENC
  • -
  • Software compression with x264
  • -
-
- - Guillaume Meunier, Patrick Nicolas et al - - - #F6F5F5 - #424242 - - - io.github.wivrn.wivrn.desktop - - - Game - Network - - - - - https://wivrn.github.io/screenshots/dashboard-2-orig.png - Dashboard - - - https://wivrn.github.io/screenshots/dashboard-1-orig.png - Wizard - - - https://wivrn.github.io/screenshots/dashboard-3-orig.png - Settings - - - - https://wivrn.github.io - https://www.github.com/WiVRn/WiVRn - https://github.com/WiVRn/WiVRn/issues - https://opencollective.com/wivrn - - - - - - https://github.com/WiVRn/WiVRn/releases/tag/v0.22 - -
    -
  • Passthrough streaming support
  • -
  • Fully encrypted connection
  • -
  • Improved compositor pacing
  • -
  • Add support for Quest 3S
  • -
  • Add wivrnctl utility to control server
  • -
  • Add Spanish translation for headset app
  • -
-
-
- - - https://github.com/WiVRn/WiVRn/releases/tag/v0.21 - -
    -
  • Fixed multiple dashboard issues
  • -
  • Improved compositor pacing
  • -
  • Changed default encoder configuration
  • -
  • Inhibit sleeping while a session is active
  • -
  • Avahi publication is now optional
  • -
  • Always set the active runtime even if there was already one
  • -
-
-
- - - https://github.com/WiVRn/WiVRn/releases/tag/v0.20 - -
    -
  • Added server dashboard
  • -
  • Added optional SolarXR support
  • -
  • Network latency improvements
  • -
  • More accurate frame pacing
  • -
  • Smarter default configuration
  • -
-
-
- - - https://github.com/WiVRn/WiVRn/releases/tag/v0.19.1 - -
    -
  • Fix possible crash when requesting Android permissions on client
  • -
-
-
- - - https://github.com/WiVRn/WiVRn/releases/tag/v0.19 - -
    -
  • Added support for eye-tracked foveation
  • -
  • Added support for FB_face_tracking2
  • -
  • More fluid experience with improved frame and input pacing
  • -
  • AV1 support with VAAPI
  • -
  • Reduced aliasing with high foveation
  • -
  • Improved server and client performance
  • -
-
-
- - - https://github.com/WiVRn/WiVRn/releases/tag/v0.18 - -
    -
  • The standard APK is now compatible with Pico headsets
  • -
  • Fixes for position on start and reconnect
  • -
  • Support for EXT_eye_gaze_interaction by @galister
  • -
  • Better support for libmonado, now discoverable in manifest
  • -
  • Server can now be distributed as a flatpak
  • -
-
-
- - - https://github.com/WiVRn/WiVRn/releases/tag/v0.17 - -
    -
  • Add systemd hardening options by @Pandapip1
  • -
  • update monado to 24.0.0 by @galister
  • -
  • Update building doc by @SanyaNya
  • -
  • Multiple tweaks for controller tracking, audio resync
  • -
  • Minor performance improvements
  • -
-
-
-
-
diff --git a/dashboard/main.cpp b/dashboard/main.cpp deleted file mode 100644 index 3fbfacb3..00000000 --- a/dashboard/main.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "main_window.h" -#include "version.h" -#include "wizard.h" - -int main(int argc, char * argv[]) -{ - QApplication app(argc, argv); - - app.setApplicationName("wivrn-dashboard"); - app.setOrganizationName("wivrn"); - app.setApplicationVersion(wivrn::git_version); - app.setDesktopFileName("io.github.wivrn.wivrn"); - - QTranslator translator; - - QLocale locale = QLocale::system(); - if (translator.load(locale, "wivrn", "_", ":/i18n")) - { - qDebug() << "Adding translator for " << locale; - app.installTranslator(&translator); - } - else - { - qDebug() << "Cannot add translator for " << locale; - } - - app.setApplicationDisplayName(QObject::tr("WiVRn dashboard")); - - std::unique_ptr wizard_window; - - // The main window is created before QWizard::finished so that the - // server is started in the wizard - auto main = std::make_unique(); - - QSettings settings; - if (settings.value("wizard/first_run", true).toBool()) - { - wizard_window.reset(new wizard); - wizard_window->show(); - - QObject::connect(wizard_window.get(), &QWizard::finished, [&](int value) { - settings.setValue("wizard/first_run", false); - - wizard_window.release()->deleteLater(); - main->show(); - }); - } - else - { - main->show(); - } - - return app.exec(); -} diff --git a/dashboard/main_window.cpp b/dashboard/main_window.cpp deleted file mode 100644 index eede2555..00000000 --- a/dashboard/main_window.cpp +++ /dev/null @@ -1,868 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "main_window.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "adb.h" -#include "gui_config.h" -#include "manage_headsets.h" -#include "settings.h" -#include "ui_main_window.h" -#include "utils/flatpak.h" -#include "utils/strings.h" -#include "utils/xdg_base_directory.h" -#include "wivrn_server.h" -#include "wizard.h" - -#if WIVRN_CHECK_CAPSYSNICE -#include -#endif - -#include -#include - -Q_LOGGING_CATEGORY(wivrn_log_category, "wivrn") - -enum class server_state -{ - stopped = 0, - started = 1 -}; - -static QString server_path() -{ - return QCoreApplication::applicationDirPath() + "/wivrn-server"; -} - -#if WIVRN_CHECK_CAPSYSNICE -static bool server_has_cap_sys_nice() -{ - auto caps = cap_get_file(server_path().toStdString().c_str()); - - if (not caps) - return false; - - char * cap_text = cap_to_text(caps, nullptr); - qDebug() << "Server capabilities:" << cap_text; - cap_free(cap_text); - - cap_flag_value_t value{}; - if (cap_get_flag(caps, CAP_SYS_NICE, CAP_EFFECTIVE, &value) < 0) - return false; - - cap_free(caps); - - return value == CAP_SET; -} -#endif - -std::vector layer_dirs() -{ - // See https://vulkan.lunarg.com/doc/view/latest/linux/loader_and_layer_interface.html#user-content-linux-layer-discovery - std::vector dirs; - - dirs.push_back(xdg_config_home() / "vulkan/implicit_layer.d"); - - for (auto dir: xdg_config_dirs()) - dirs.push_back(dir / "vulkan/implicit_layer.d"); - - dirs.push_back("/etc/vulkan/implicit_layer.d"); - - dirs.push_back(xdg_data_home() / "vulkan/implicit_layer.d"); - - for (auto dir: xdg_data_dirs()) - dirs.push_back(dir / "vulkan/implicit_layer.d"); - - return dirs; -} - -static std::string read_file(const std::filesystem::path & path) -{ - if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk") - { - QProcess flatpak_spawn; - flatpak_spawn.start("flatpak-spawn", {"--host", "cat", QString::fromStdString(path)}); - flatpak_spawn.waitForFinished(); - return flatpak_spawn.readAllStandardOutput().toStdString(); - } - else - { - std::ifstream f(path); - std::istreambuf_iterator begin{f}, end; - - return {begin, end}; - } -} - -static std::vector list_files(const std::vector & dirs) -{ - std::vector files; - - if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk") - { - QProcess flatpak_spawn; - QStringList args{"--host", "find"}; - for (const std::filesystem::path & dir: dirs) - args.push_back(QString::fromStdString(dir)); - args.push_back("-name"); - args.push_back("*.json"); - - flatpak_spawn.start("flatpak-spawn", args); - flatpak_spawn.waitForFinished(); - - qDebug() << args; - - for (const std::string & file: utils::split(flatpak_spawn.readAllStandardOutput().toStdString())) - { - if (file != "") - files.push_back(file); - } - } - else - { - for (const std::filesystem::path & dir: dirs) - { - try - { - for (auto const & dir_entry: std::filesystem::directory_iterator{dir}) - { - if (dir_entry.path().extension() != ".json") - continue; - - files.push_back(dir / dir_entry.path()); - } - } - catch (...) - { - // Ignore non existing directories - } - } - } - - return files; -} - -static bool nvidia_layer_missing() -{ - vk::raii::Context context; - - vk::ApplicationInfo app_info{"WiVRn dashboard", 1, "No engine", 1, VK_API_VERSION_1_0}; - vk::InstanceCreateInfo instance_info{vk::InstanceCreateFlags{0}, &app_info}; - vk::raii::Instance vulkan{context, instance_info}; - - // Check if an nvidia GPU is present - if (not std::ranges::any_of(vulkan.enumeratePhysicalDevices(), [](vk::raii::PhysicalDevice & device) { return device.getProperties().vendorID == 0x10de; })) - return false; - - // Check if the monado vulkan layer is present - for (auto file: list_files(layer_dirs())) - { - try - { - nlohmann::json json = nlohmann::json::parse(read_file(file)); - if (json["layer"]["name"] == "VK_LAYER_MND_enable_timeline_semaphore") - return false; - } - catch (...) - { - } - } - - return true; -} - -main_window::main_window() -{ - ui = new Ui::MainWindow; - ui->setupUi(this); - - if (QSystemTrayIcon::isSystemTrayAvailable()) - { - action_show.setIcon(QIcon::fromTheme("settings-configure")); - action_hide.setIcon(QIcon::fromTheme("settings-configure")); - action_exit.setIcon(QIcon::fromTheme("application-exit")); - - systray_menu.addAction(&action_show); - systray_menu.addAction(&action_hide); - systray_menu.addAction(&action_exit); - - systray.setToolTip("WiVRn"); - systray.setContextMenu(&systray_menu); - systray.show(); - - connect(&action_show, &QAction::triggered, this, &QMainWindow::show); - connect(&action_hide, &QAction::triggered, this, &QMainWindow::hide); - connect(&action_exit, &QAction::triggered, this, [&]() { QApplication::quit(); }); - - connect(&systray, &QSystemTrayIcon::activated, this, [&](QSystemTrayIcon::ActivationReason reason) { - switch (reason) - { - case QSystemTrayIcon::ActivationReason::Trigger: - setVisible(!isVisible()); - break; - - default: - break; - } - }); - } - - server_process_timeout = new QTimer; - server_process_timeout->setInterval(std::chrono::seconds(1)); - server_process_timeout->setSingleShot(true); - connect(server_process_timeout, &QTimer::timeout, this, &main_window::on_server_start_timeout); - - server_interface = new wivrn_server(this); - - connect(server_interface, &wivrn_server::serverRunningChanged, this, &main_window::on_server_running_changed); - connect(server_interface, &wivrn_server::headsetConnectedChanged, this, &main_window::on_headset_connected_changed); - - on_server_running_changed(server_interface->isServerRunning()); - if (not server_interface->isServerRunning()) - start_server(); - - connect(server_interface, &wivrn_server::recommendedEyeSizeChanged, this, &main_window::on_recommended_eye_size_changed); - connect(server_interface, &wivrn_server::availableRefreshRatesChanged, this, &main_window::on_available_refresh_rates_changed); - connect(server_interface, &wivrn_server::preferredRefreshRateChanged, this, &main_window::on_preferred_refresh_rate_changed); - connect(server_interface, &wivrn_server::eyeGazeChanged, this, &main_window::on_eye_gaze_changed); - connect(server_interface, &wivrn_server::faceTrackingChanged, this, &main_window::on_face_tracking_changed); - connect(server_interface, &wivrn_server::fieldOfViewChanged, this, &main_window::on_field_of_view_changed); - connect(server_interface, &wivrn_server::handTrackingChanged, this, &main_window::on_hand_tracking_changed); - connect(server_interface, &wivrn_server::micChannelsChanged, this, &main_window::on_mic_changed); - connect(server_interface, &wivrn_server::micSampleRateChanged, this, &main_window::on_mic_changed); - connect(server_interface, &wivrn_server::speakerChannelsChanged, this, &main_window::on_speaker_changed); - connect(server_interface, &wivrn_server::speakerSampleRateChanged, this, &main_window::on_speaker_changed); - connect(server_interface, &wivrn_server::supportedCodecsChanged, this, &main_window::on_supported_codecs_changed); - connect(server_interface, &wivrn_server::steamCommandChanged, this, &main_window::on_steam_command_changed); - - connect(server_interface, &wivrn_server::encryptionEnabledChanged, ui->widget_authentication, &QWidget::setVisible); - connect(server_interface, &wivrn_server::pinChanged, this, &main_window::on_pin_changed); - on_pin_changed(server_interface->pin()); - - connect(server_interface, &wivrn_server::pairingEnabledChanged, ui->button_cancel_pairing, &QWidget::setVisible); - connect(server_interface, &wivrn_server::pairingEnabledChanged, ui->button_pair_headset, &QWidget::setHidden); - connect(ui->button_cancel_pairing, &QPushButton::clicked, server_interface, &wivrn_server::disable_pairing); - connect(ui->button_pair_headset, &QPushButton::clicked, server_interface, &wivrn_server::enable_pairing); - connect(ui->button_manage_headsets, &QPushButton::clicked, this, &main_window::on_action_manage_headsets); - - connect(ui->button_start, &QPushButton::clicked, this, &main_window::start_server); - connect(ui->button_stop, &QPushButton::clicked, this, &main_window::stop_server); - connect(ui->button_settings, &QPushButton::clicked, this, &main_window::on_action_settings); - connect(ui->button_disconnect, &QPushButton::clicked, this, &main_window::disconnect_client); - connect(ui->button_wizard, &QPushButton::clicked, this, &main_window::on_action_wizard); - connect(ui->button_details, &QPushButton::toggled, this, &main_window::on_button_details_toggled); - - connect(ui->button_about, &QPushButton::clicked, this, []() { QApplication::aboutQt(); }); - connect(ui->button_exit, &QPushButton::clicked, this, []() { QApplication::quit(); }); - - connect(ui->copy_steam_command, &QPushButton::clicked, this, [&]() { - QGuiApplication::clipboard()->setText(ui->label_steam_command->text()); - }); - - usb_device_menu = new QMenu(this); - ui->button_usb->setMenu(usb_device_menu); - connect(&adb_service, &adb::android_devices_changed, this, &main_window::on_android_device_list_changed); - on_android_device_list_changed(adb_service.devices()); - -#if WIVRN_CHECK_CAPSYSNICE - ui->banner_capsysnice_icon->setPixmap(QIcon::fromTheme("dialog-information").pixmap(ui->banner_capsysnice_dismiss->height())); - connect(ui->banner_capsysnice_text, &QLabel::linkActivated, this, &main_window::on_banner_capsysnice); - - if (server_has_cap_sys_nice()) - ui->banner_capsysnice->hide(); -#else - ui->banner_capsysnice->hide(); -#endif - - ui->banner_nvidia_layer_icon->setPixmap(QIcon::fromTheme("dialog-information").pixmap(ui->banner_nvidia_layer_dismiss->height())); - if (not nvidia_layer_missing()) - ui->banner_nvidia_layer->hide(); - - retranslate(); -} - -main_window::~main_window() -{ - delete server_process_timeout; - server_process_timeout = nullptr; - - if (server_process) - { - // Disconnect signals to avoid receiving signals about the server crashing - disconnect(server_process, &QProcess::finished, this, &main_window::on_server_finished); - disconnect(server_process, &QProcess::errorOccurred, this, &main_window::on_server_error_occurred); - server_process->terminate(); - server_process->waitForFinished(); - delete server_process; - server_process = nullptr; - } - - delete ui; - ui = nullptr; -} - -void main_window::changeEvent(QEvent * e) -{ - QWidget::changeEvent(e); - - switch (e->type()) - { - case QEvent::LanguageChange: - retranslate(); - break; - - default: - break; - } -} - -void main_window::retranslate() -{ - ui->retranslateUi(this); - ui->label_how_to_connect->setText(tr("Start the WiVRn app on your headset and connect to \"%1\".").arg(server_interface->hostname()) + "\n\n" + tr("If the server is not visible or the connection fails, check that port 5353 (UDP) and 9757 (TCP and UDP) are open in your firewall.")); - - action_show.setText(tr("&Show GUI")); - action_hide.setText(tr("&Hide GUI")); - action_exit.setText(tr("&Exit")); - - if (server_interface->isHeadsetConnected()) - { - on_headset_connected_changed(true); - - on_recommended_eye_size_changed(server_interface->recommendedEyeSize()); - on_available_refresh_rates_changed(server_interface->availableRefreshRates()); - on_preferred_refresh_rate_changed(server_interface->preferredRefreshRate()); - on_eye_gaze_changed(server_interface->eyeGaze()); - on_face_tracking_changed(server_interface->faceTracking()); - on_field_of_view_changed(server_interface->fieldOfView()); - on_hand_tracking_changed(server_interface->handTracking()); - on_mic_changed(); - on_speaker_changed(); - on_supported_codecs_changed(server_interface->supportedCodecs()); - on_steam_command_changed(server_interface->steamCommand()); - } - else - { - on_headset_connected_changed(false); - } -} - -void main_window::closeEvent(QCloseEvent * event) -{ - QMainWindow::closeEvent(event); - QCoreApplication::quit(); -} - -void main_window::setVisible(bool visible) -{ - if (visible) - { - action_show.setVisible(false); - action_hide.setVisible(true); - adb_service.start(); - } - else - { - action_show.setVisible(true); - action_hide.setVisible(false); - adb_service.stop(); - } - - QMainWindow::setVisible(visible); -} - -void main_window::on_android_device_list_changed(const std::vector & devices) -{ - ui->button_usb->setDisabled(devices.empty()); - - if (devices.empty()) - ui->button_usb->setToolTip(tr("No device detected")); - else - ui->button_usb->setToolTip(""); - - std::vector to_be_removed; - for (auto & [serial, action]: usb_actions) - { - if (std::ranges::none_of(devices, [&](const adb::device & x) { return x.serial() == serial; })) - { - qDebug() << "Removed" << QString::fromStdString(serial); - - usb_device_menu->removeAction(action.get()); - to_be_removed.push_back(serial); - } - } - - for (const auto & serial: to_be_removed) - { - usb_actions.erase(serial); - } - - for (auto & device: devices) - { - if (std::ranges::none_of(usb_actions, [&](const std::pair> & x) { return x.first == device.serial(); })) - { - qDebug() << "Detected" << QString::fromStdString(device.serial()); - for (auto & [key, value]: device.properties()) - { - qDebug() << " " << QString::fromStdString(key) << ":" << QString::fromStdString(value); - } - - std::unique_ptr device_action = std::make_unique(this); - - if (auto model = device.properties().find("model"); model != device.properties().end()) - device_action->setText(QString::fromStdString(model->second)); - else - device_action->setText("Unknown model"); - - usb_device_menu->addAction(device_action.get()); - - device_action->setData(QString::fromStdString(device.serial())); - connect(device_action.get(), &QAction::triggered, this, [this, serial = device.serial()]() { - on_action_usb(serial); - }); - - usb_actions.insert(std::make_pair(device.serial(), std::move(device_action))); - } - } -} - -void main_window::on_banner_capsysnice(const QString & link) -{ -#if WIVRN_CHECK_CAPSYSNICE - if (link == "setcap" and not setcap_process) - { - setcap_process = new QProcess(this); - setcap_process->setProgram("pkexec"); - setcap_process->setArguments({"setcap", "CAP_SYS_NICE=+ep", server_path()}); - setcap_process->setProcessChannelMode(QProcess::MergedChannels); - setcap_process->start(); - - connect(setcap_process, &QProcess::finished, this, [this](int exit_code, QProcess::ExitStatus exit_status) { - // Exit codes: - // 0: setcap successful - // 1: setcap failed - // 126: pkexec: not authorized or authentication error - // 127: pkexec: dismissed by user - qDebug() << "pkexec setcap exited with code" << exit_code << "and status" << exit_status; - - qDebug() << "--------"; - for (auto line: setcap_process->readAllStandardOutput().split('\n')) - { - QDebug dbg = qDebug(); - dbg.noquote(); - dbg << " " << QString::fromStdString(line.toStdString()); - } - qDebug() << "--------"; - - if (exit_status == QProcess::NormalExit) - { - if (exit_code == 0) - { - if (not server_has_cap_sys_nice()) - { - qDebug() << "pkexec setcap returned successfully but the server does not have the CAP_SYS_NICE capability"; - } - else - { - ui->banner_capsysnice->hide(); - - // Don't restart if it wasn't already started - if (server_interface) - { - QMessageBox msgbox; - msgbox.setIcon(QMessageBox::Information); - msgbox.setText(tr("You have to restart the WiVRn server to use the CAP_SYS_NICE capability.\nDo you want to restart it now?")); - - if (server_interface->isHeadsetConnected()) - { - msgbox.setText(msgbox.text() + "\n\n" + tr("This will disconnect the currently connected headset.")); - } - - auto restart_button = msgbox.addButton(tr("Restart WiVRn"), QMessageBox::YesRole); - auto close_button = msgbox.addButton(QMessageBox::Close); - - msgbox.exec(); - - if (msgbox.clickedButton() == restart_button) - { - server_process_restart = true; - stop_server(); - } - } - } - } - } - else - { - QMessageBox msgbox; - msgbox.setIcon(QMessageBox::Critical); - msgbox.setText(tr("Cannot start setcap: %1").arg(exit_status)); - - auto close_button = msgbox.addButton(QMessageBox::Close); - - msgbox.exec(); - } - - setcap_process->deleteLater(); - setcap_process = nullptr; - }); - } -#endif -} - -void main_window::on_server_running_changed(bool running) -{ - if (running) - { - qDebug() << "Server started"; - server_process_timeout->stop(); - - ui->stacked_widget_server->setCurrentIndex((int)server_state::started); - ui->group_client->setEnabled(true); - - ui->button_stop->setEnabled(true); - ui->button_settings->setEnabled(true); - } - else - { - qDebug() << "Server stopped"; - ui->stacked_widget_server->setCurrentIndex((int)server_state::stopped); - ui->group_client->setEnabled(false); - - ui->button_start->setEnabled(true); - } -} - -void main_window::on_headset_connected_changed(bool connected) -{ - if (connected) - { - qDebug() << "Headset connected"; - ui->label_client_status->setText(tr("Connected")); - } - else - { - qDebug() << "Headset disconnected"; - ui->label_client_status->setText(tr("Not connected")); - } - - ui->button_disconnect->setVisible(connected); - ui->button_wizard->setHidden(connected); - ui->button_details->setVisible(connected); - ui->button_usb->setHidden(connected); - ui->headset_properties->setVisible(connected and ui->button_details->isChecked()); - - ui->label_how_to_connect->setHidden(connected); -} - -void main_window::on_button_details_toggled(bool checked) -{ - ui->headset_properties->setVisible(server_interface->isHeadsetConnected() and checked); -} - -void main_window::on_recommended_eye_size_changed(QSize size) -{ - ui->label_eye_size->setText(tr("%1 \u2a2f %2").arg(size.width()).arg(size.height())); -} - -void main_window::on_available_refresh_rates_changed(const std::vector & rates) -{ - QStringList rates_str; - for (float size: rates) - rates_str.push_back(tr("%1 Hz").arg(size)); - - ui->label_refresh_rates->setText(rates_str.join(", ")); -} - -void main_window::on_preferred_refresh_rate_changed(float rate) -{ - ui->label_prefered_refresh_rate->setText(tr("%1 Hz").arg(std::round(rate))); -} - -void main_window::on_eye_gaze_changed(bool supported) -{ - ui->label_eye_gaze_tracking->setText(supported ? tr("Supported") : tr("Not supported")); -} - -void main_window::on_face_tracking_changed(bool supported) -{ - ui->label_face_tracking->setText(supported ? tr("Supported") : tr("Not supported")); -} - -void main_window::on_field_of_view_changed(const std::vector & fovs) -{ - if (fovs.size() >= 2) - { - ui->label_field_of_view->setText(tr("Left eye: %1° \u2a2f %2°, right eye: %3° \u2a2f %4°") - .arg((fovs[0].angleRight - fovs[0].angleLeft) * 180 / M_PI, 0, 'f', 1) - .arg((fovs[0].angleUp - fovs[0].angleDown) * 180 / M_PI, 0, 'f', 1) - .arg((fovs[1].angleRight - fovs[1].angleLeft) * 180 / M_PI, 0, 'f', 1) - .arg((fovs[1].angleUp - fovs[1].angleDown) * 180 / M_PI, 0, 'f', 1)); - } -} - -void main_window::on_hand_tracking_changed(bool supported) -{ - ui->label_hand_tracking->setText(supported ? tr("Supported") : tr("Not supported")); -} - -void main_window::on_mic_changed() -{ - auto channels = server_interface->micChannels(); - auto sample_rate = server_interface->micSampleRate(); - - if (channels and sample_rate) - ui->label_mic->setText(tr("%n channel(s), %1 Hz", nullptr, channels).arg(sample_rate)); - else - ui->label_mic->setText(tr("N/A")); -} - -void main_window::on_speaker_changed() -{ - auto channels = server_interface->speakerChannels(); - auto sample_rate = server_interface->speakerSampleRate(); - - if (channels and sample_rate) - ui->label_speaker->setText(tr("%n channel(s), %1 Hz", nullptr, channels).arg(sample_rate)); - else - ui->label_speaker->setText(tr("N/A")); -} - -void main_window::on_supported_codecs_changed(QStringList value) -{ - ui->label_codecs->setText(value.join(", ")); -} - -void main_window::on_steam_command_changed(QString value) -{ - ui->label_steam_command->setText(value); -} - -void main_window::on_pin_changed(QString value) -{ - if (value == "") - ui->label_pin->setText(""); - else - ui->label_pin->setText(tr("To pair your headset use the following PIN: %1").arg(value)); -} - -void main_window::on_server_finished(int exit_code, QProcess::ExitStatus status) -{ - qDebug() << "Server exited with code" << exit_code << ", status" << status; - server_process_timeout->stop(); - - disconnect(server_process, &QProcess::finished, this, &main_window::on_server_finished); - disconnect(server_process, &QProcess::errorOccurred, this, &main_window::on_server_error_occurred); - server_process->deleteLater(); - server_process = nullptr; - - if (exit_code != 0) - { - QString error_message = tr("Unknown error (%1), check logs").arg(exit_code); - switch (exit_code) - { - case EXIT_SUCCESS: - case EXIT_FAILURE: - break; - case 2: - case 3: - error_message = tr("Insufficient system resources"); - break; - case 4: - error_message = tr("Cannot connect to avahi, make sure avahi-daemon service is started with \"disable-user-service-publishing\" set to no"); - break; - } - - QMessageBox msgbox; - msgbox.setIcon(QMessageBox::Critical); - msgbox.setText(tr("Server crashed:\n%1").arg(error_message)); - msgbox.setStandardButtons(QMessageBox::Close); - msgbox.exec(); - } - - if (server_process_restart) - { - server_process_restart = false; - start_server(); - } -} - -void main_window::on_server_error_occurred(QProcess::ProcessError error) -{ - qDebug() << "on_server_error_occurred" << error; - server_process_timeout->stop(); - - QString error_message; - switch (error) - { - case QProcess::ProcessError::FailedToStart: - error_message = tr("Failed to start"); - break; - case QProcess::ProcessError::Crashed: - error_message = tr("Crashed"); - break; - case QProcess::ProcessError::Timedout: - error_message = tr("Time out"); - break; - case QProcess::ProcessError::ReadError: - error_message = tr("Read error"); - break; - case QProcess::ProcessError::WriteError: - error_message = tr("Write error"); - break; - case QProcess::ProcessError::UnknownError: - error_message = tr("Unknown error"); - break; - } - - QMessageBox msgbox /*(this)*/; - msgbox.setIcon(QMessageBox::Critical); - msgbox.setText(tr("Failed to start server:\n%1").arg(error_message)); - msgbox.setStandardButtons(QMessageBox::Close); - msgbox.exec(); -} - -void main_window::on_server_start_timeout() -{ - qDebug() << "on_server_start_timeout"; - - if (server_process) - { - // Disconnect signals to avoid receiving signals about the server crashing - disconnect(server_process, &QProcess::finished, this, &main_window::on_server_finished); - disconnect(server_process, &QProcess::errorOccurred, this, &main_window::on_server_error_occurred); - server_process->terminate(); - server_process->deleteLater(); - server_process = nullptr; - } - - QMessageBox msgbox /*(this)*/; - msgbox.setIcon(QMessageBox::Critical); - msgbox.setText(tr("Timeout starting server")); - msgbox.setStandardButtons(QMessageBox::Close); - - msgbox.exec(); -} - -void main_window::on_action_settings() -{ - settings{server_interface}.exec(); -} - -void main_window::on_action_wizard() -{ - wizard{}.exec(); -} - -void main_window::on_action_manage_headsets() -{ - manage_headsets{server_interface}.exec(); -} - -void main_window::on_action_usb(const std::string & serial) -{ - auto devs = adb_service.devices(); - - if (devs.empty()) - return; - - adb::device dev; - for (auto & i: adb_service.devices()) - { - if (i.serial() == serial) - { - dev = i; - break; - } - } - - if (!dev) - return; - - // TODO: in another thread - // TODO: check if adb works - bool ok = false; - for (auto & app: dev.installed_apps()) - { - if (app.starts_with("org.meumeu.wivrn.") or app == "org.meumeu.wivrn") - { - dev.reverse_forward(9757, 9757); - dev.start(app, "android.intent.action.VIEW", "wivrn+tcp://127.0.0.1:9757"); - ok = true; - break; - } - } - - if (not ok) - { - QMessageBox msgbox /*(this)*/; - - msgbox.setIcon(QMessageBox::Critical); - msgbox.setText(tr("The WiVRn app is not installed on your headset.")); - msgbox.setStandardButtons(QMessageBox::Close); - msgbox.exec(); - } -} - -void main_window::start_server() -{ - qDebug() << "Starting server"; - - // TODO activate by dbus? - server_process = new QProcess; - connect(server_process, &QProcess::finished, this, &main_window::on_server_finished); - connect(server_process, &QProcess::errorOccurred, this, &main_window::on_server_error_occurred); - - server_process->setProcessChannelMode(QProcess::ForwardedChannels); - - server_process->start(server_path(), QApplication::arguments().mid(1)); - server_process_timeout->start(); - - ui->button_start->setEnabled(false); -} - -void main_window::stop_server() -{ - qDebug() << "Stopping server"; - - if (server_interface) - server_interface->quit() /*.waitForFinished()*/; - // server_process.terminate(); // TODO timer and kill - ui->button_stop->setEnabled(false); -} - -void main_window::disconnect_client() -{ - qDebug() << "Disconnecting client"; - - if (server_interface) - server_interface->disconnect_headset(); -} - -#include "moc_main_window.cpp" diff --git a/dashboard/main_window.h b/dashboard/main_window.h deleted file mode 100644 index 008463a5..00000000 --- a/dashboard/main_window.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include "adb.h" -#include "wivrn_qdbus_types.h" - -Q_DECLARE_LOGGING_CATEGORY(wivrn_log_category) - -namespace Ui -{ -class MainWindow; -} -class IoGithubWivrnServerInterface; -class OrgFreedesktopDBusPropertiesInterface; - -class settings; -class wivrn_server; -class wizard; - -class main_window : public QMainWindow -{ - Q_OBJECT - - Ui::MainWindow * ui = nullptr; - wivrn_server * server_interface = nullptr; - - QIcon icon{":/images/wivrn.png"}; - QSystemTrayIcon systray{icon}; - - QMenu systray_menu; - QAction action_show; - QAction action_hide; - QAction action_exit; - - QProcess * server_process = nullptr; - QTimer * server_process_timeout = nullptr; - bool server_process_restart = false; - - QMenu * usb_device_menu; - std::map> usb_actions; - - adb adb_service; - - QProcess * setcap_process = nullptr; - -public: - main_window(); - ~main_window(); - - void changeEvent(QEvent * e) override; - void closeEvent(QCloseEvent * event) override; - void setVisible(bool visible) override; - -private: - void on_server_finished(int exit_code, QProcess::ExitStatus status); - void on_server_error_occurred(QProcess::ProcessError error); - void on_server_start_timeout(); - - void on_button_details_toggled(bool); - void on_banner_capsysnice(const QString & link); - - void on_server_running_changed(bool running); - void on_headset_connected_changed(bool connected); - void on_recommended_eye_size_changed(QSize size); - void on_available_refresh_rates_changed(const std::vector & rates); - void on_preferred_refresh_rate_changed(float rate); - void on_eye_gaze_changed(bool supported); - void on_face_tracking_changed(bool supported); - void on_field_of_view_changed(const std::vector & fov); - void on_hand_tracking_changed(bool supported); - void on_mic_changed(); - void on_speaker_changed(); - void on_supported_codecs_changed(QStringList value); - void on_steam_command_changed(QString value); - void on_pin_changed(QString value); - - void on_android_device_list_changed(const std::vector &); - - void on_action_settings(); - void on_action_wizard(); - void on_action_manage_headsets(); - void on_action_usb(const std::string & serial); - void start_server(); - void stop_server(); - void disconnect_client(); - - void retranslate(); -}; diff --git a/dashboard/main_window.ui b/dashboard/main_window.ui deleted file mode 100644 index 09241f08..00000000 --- a/dashboard/main_window.ui +++ /dev/null @@ -1,685 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 895 - 842 - - - - WiVRn dashboard - - - - :/images/wivrn.svg:/images/wivrn.svg - - - - - - - .QFrame -{ -background-color: rgb(255, 170, 127); -border: 1px solid rgb(255, 127, 127); -border-radius: 5px; -} - - - QFrame::Shape::Box - - - - - - - - - - - - - <html><head/><body><p>The server does not have CAP_SYS_NICE capabilities. Click <a href="setcap"><span style=" text-decoration: underline; color:#2980b9;">here</span></a> to grant it.</p></body></html> - - - - - - - - - - - - - - - - - .QFrame -{ -background-color: rgb(255, 170, 127); -border: 1px solid rgb(255, 127, 127); -border-radius: 5px; -} - - - QFrame::Shape::Box - - - - - - - - - - - - - <html><head/><body><p>The <a href="https://github.com/WiVRn/WiVRn/issues/180"><span style=" text-decoration: underline; color:#2980b9;">Monado NVIDIA layer</span></a> is not installed.</p></body></html> - - - true - - - - - - - - - - - - - - - - - Server status - - - false - - - - - - 1 - - - - - - - - - - :/images/wivrn.svg - - - - - - - - - - - - 18 - - - - Stopped - - - - - - - Start - - - - - - - - - - - - Qt::Orientation::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - - :/images/wivrn.svg - - - - - - - - - - - - 18 - - - - Running - - - - - - - Settings - - - - - - - - - - Stop - - - - - - - - - - - - - - - Qt::Orientation::Vertical - - - - 20 - 40 - - - - - - - - For Steam games, set the launch options to: - - - Qt::TextFormat::PlainText - - - true - - - Qt::TextInteractionFlag::NoTextInteraction - - - - - - - - - Copy to clipboard - - - - - - - - - - - - - IBeamCursor - - - PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/wivrn/comp_ipc %command% - - - true - - - Qt::TextInteractionFlag::NoTextInteraction - - - - - - - - - - - - - - - - - - Headset status - - - - - - - - - 18 - - - - client_status - - - - - - - Connect by USB - - - - - - - Wizard - - - - - - - Disconnect - - - - - - - - - - Details - - - true - - - false - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 14 - - - - label_pin - - - - - - - Pair headset - - - - - - - Cancel - - - - - - - Manage headsets - - - - - - - - - - connect_to_this_server - - - true - - - - - - - - 0 - - - 0 - - - - - Eye gaze tracking - - - - - - - Eye resolution - - - - - - - Speaker - - - - - - - Field of view - - - - - - - refresh_rates - - - - - - - eye_size - - - - - - - Microphone - - - - - - - Available refresh rates - - - - - - - Supported codecs - - - - - - - Hand tracking - - - - - - - Preferred refresh rate - - - - - - - Face tracking - - - - - - - preferrred_refresh_rate - - - - - - - speaker - - - - - - - mic - - - - - - - field_of_view - - - - - - - hand_tracking - - - - - - - eye_gaze_tracking - - - - - - - face_tracking - - - - - - - codecs - - - - - - - - - - - - - Qt::Orientation::Vertical - - - - 20 - 104 - - - - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - About - - - - - - - - - - Exit - - - - - - - - - - - - - - - - &Show - - - - - - - - &Hide - - - - - - - - &Exit - - - - - - - - - banner_capsysnice_dismiss - clicked() - banner_capsysnice - hide() - - - 881 - 44 - - - 805 - 51 - - - - - banner_nvidia_layer_dismiss - clicked() - banner_nvidia_layer - hide() - - - 869 - 82 - - - 852 - 102 - - - - - diff --git a/dashboard/manage_headsets.cpp b/dashboard/manage_headsets.cpp deleted file mode 100644 index 8d558320..00000000 --- a/dashboard/manage_headsets.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "manage_headsets.h" -#include "ui_manage_headsets.h" -#include "wivrn_server.h" -#include -#include - -manage_headsets::manage_headsets(wivrn_server * server_interface) : - server_interface(server_interface) -{ - ui = new Ui::ManageHeadsets; - ui->setupUi(this); - ui->headset_list->setModel(new QStandardItemModel); - - connect(server_interface, &wivrn_server::knownKeysChanged, this, &manage_headsets::update_headet_list); - connect(ui->headset_list->selectionModel(), &QItemSelectionModel::selectionChanged, this, &manage_headsets::on_selection_changed); - connect(ui->button_remove, &QPushButton::clicked, this, &manage_headsets::on_remove_selected); - - QStandardItemModel * headsets = dynamic_cast(ui->headset_list->model()); - connect(headsets, &QStandardItemModel::itemChanged, this, &manage_headsets::on_rename_selected); - - update_headet_list(server_interface->knownKeys()); -} - -void manage_headsets::update_headet_list(const std::vector & new_headsets) -{ - QStandardItemModel * current_headsets = dynamic_cast(ui->headset_list->model()); - assert(current_headsets); - - for (int i = 0; i < current_headsets->rowCount();) - { - QString key = current_headsets->item(i)->data().toString(); - if (not std::ranges::any_of(new_headsets, [&](const wivrn_server::HeadsetKey & x) { return x.public_key == key; })) - current_headsets->removeRow(i); - else - i++; - } - - for (const wivrn_server::HeadsetKey & key: new_headsets) - { - bool found = false; - for (int i = 0; i < current_headsets->rowCount(); i++) - { - if (current_headsets->item(i)->data().toString() == key.public_key) - { - found = true; - break; - } - } - - if (not found) - { - QStandardItem * item = new QStandardItem; - item->setText(key.name); - item->setData(key.public_key); - current_headsets->appendRow(item); - } - } -} - -void manage_headsets::on_selection_changed() -{ - ui->button_remove->setDisabled(ui->headset_list->selectionModel()->selection().empty()); -} - -void manage_headsets::on_remove_selected() -{ - QStandardItemModel * current_headsets = dynamic_cast(ui->headset_list->model()); - assert(current_headsets); - - std::vector keys_to_remove; - for (QItemSelectionRange item: ui->headset_list->selectionModel()->selection()) - { - for (QModelIndex index: item.indexes()) - { - keys_to_remove.push_back(current_headsets->item(index.row())->data().toString()); - } - } - - for (QString key: keys_to_remove) - server_interface->revoke_key(key); -} - -void manage_headsets::on_rename_selected(QStandardItem * item) -{ - server_interface->rename_key(item->data().toString(), item->text()); -} diff --git a/dashboard/manage_headsets.h b/dashboard/manage_headsets.h deleted file mode 100644 index 86a23263..00000000 --- a/dashboard/manage_headsets.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include "wivrn_server.h" -#include -#include - -namespace Ui -{ -class ManageHeadsets; -} -class IoGithubWivrnServerInterface; -class OrgFreedesktopDBusPropertiesInterface; - -class settings; -class wivrn_server; -class wizard; - -class manage_headsets : public QDialog -{ - Q_OBJECT - - Ui::ManageHeadsets * ui; - wivrn_server * server_interface; - -public: - manage_headsets(wivrn_server * server_interface); - -private: - void update_headet_list(const std::vector & keys); - void on_selection_changed(); - void on_remove_selected(); - void on_rename_selected(QStandardItem * item); -}; diff --git a/dashboard/manage_headsets.ui b/dashboard/manage_headsets.ui deleted file mode 100644 index 115c13dc..00000000 --- a/dashboard/manage_headsets.ui +++ /dev/null @@ -1,81 +0,0 @@ - - - ManageHeadsets - - - - 0 - 0 - 541 - 446 - - - - Manage headsets - - - - - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - false - - - Remove - - - - - - - - - - Close - - - - - - - - - - - - - - button_close - clicked() - ManageHeadsets - accept() - - - 516 - 426 - - - 494 - 443 - - - - - diff --git a/dashboard/rectangle_partitionner.cpp b/dashboard/rectangle_partitionner.cpp deleted file mode 100644 index df0276ea..00000000 --- a/dashboard/rectangle_partitionner.cpp +++ /dev/null @@ -1,827 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "rectangle_partitionner.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace -{ -const double split_edge_threshold = 0.05; -const double move_edge_threshold = 0.02; -const double magnetism_threshold = 0.05; -const int num_subdiv = 20; -const double epsilon = 1.0 / (2 * num_subdiv); - -enum class side -{ - top, - bottom, - left, - right -}; - -struct edge -{ - side edge_side; - int rectangle_index; - - bool operator==(const edge & other) const noexcept - { - return edge_side == other.edge_side and rectangle_index == other.rectangle_index; - } - - double position = 0; - double min = std::numeric_limits::max(); - double max = std::numeric_limits::lowest(); -}; -} // namespace - -struct rectangle_partitionner_private -{ - std::vector selection; - std::vector hovered; - - double min_drag_position; - double max_drag_position; - - QLine split_line; - - enum class mouse_event_type - { - move, - press, - release - }; -}; - -namespace -{ -int hovered_rectangle(QPointF position, std::vector rectangles) -{ - int n = 0; - for (const QRectF & i: rectangles) - { - if (i.contains(position)) - return n; - n++; - } - - return -1; -} - -Qt::CursorShape get_cursor_shape(QPointF position, std::vector rectangles) -{ - for (QRectF & i: rectangles) - { - if (i.contains(position)) - { - QPointF rel_pos = position - i.topLeft(); - double dx = std::min(rel_pos.x(), i.width() - rel_pos.x()); - double dy = std::min(rel_pos.y(), i.height() - rel_pos.y()); - - if (dx < move_edge_threshold and position.x() >= epsilon and position.x() <= 1 - epsilon) - return Qt::SizeHorCursor; - else if (dy < move_edge_threshold and position.y() >= epsilon and position.y() <= 1 - epsilon) - return Qt::SizeVerCursor; - else if (dx < split_edge_threshold and position.y() >= epsilon and position.y() <= 1 - epsilon) - return Qt::SplitVCursor; - else if (dy < split_edge_threshold and position.x() >= epsilon and position.x() <= 1 - epsilon) - return Qt::SplitHCursor; - else - return Qt::ArrowCursor; - - break; - } - } - - return Qt::ArrowCursor; -} - -std::vector horizontal_edges(std::vector rectangles) -{ - std::vector edges; - - for (int i = 0, n = rectangles.size(); i < n; i++) - { - if (rectangles[i].top() > epsilon) - { - edges.emplace_back(side::top, i, rectangles[i].top(), rectangles[i].left(), rectangles[i].right()); - } - - if (rectangles[i].bottom() < 1 - epsilon) - { - edges.emplace_back(side::bottom, i, rectangles[i].bottom(), rectangles[i].left(), rectangles[i].right()); - } - } - - return edges; -} - -std::vector vertical_edges(std::vector rectangles) -{ - std::vector edges; - - for (int i = 0, n = rectangles.size(); i < n; i++) - { - if (rectangles[i].left() > epsilon) - { - edges.emplace_back(side::left, i, rectangles[i].left(), rectangles[i].top(), rectangles[i].bottom()); - } - - if (rectangles[i].right() < 1 - epsilon) - { - edges.emplace_back(side::right, i, rectangles[i].right(), rectangles[i].top(), rectangles[i].bottom()); - } - } - - return edges; -} - -std::vector> partition_edges(std::vector edges) -{ - auto comp = [](const edge & a, const edge & b) { - if (a.position < b.position) - return true; - if (a.position > b.position) - return false; - - if (a.min < b.min) - return true; - if (a.min > b.min) - return false; - - if (a.max < b.max) - return true; - return false; - }; - - std::ranges::sort(edges, comp); - - std::vector> partitionned; - - double current_position = std::numeric_limits::lowest(); - double current_max = 0; - - for (auto & e: edges) - { - if (e.position != current_position) - { - current_position = e.position; - current_max = e.max; - partitionned.push_back({e}); - } - else - { - if (e.min >= current_max) - { - // All the following edges will be after the last partition - current_max = e.max; - partitionned.push_back({e}); - } - else - { - // Add the edge to the current partition - current_max = std::max(current_max, e.max); - partitionned.back().push_back(e); - } - } - } - - return partitionned; -} - -std::vector hovered_edges(QPointF position, const std::vector> & partitionned_edges, bool horizontal) -{ - if (horizontal) - position = position.transposed(); - - for (const auto & edge_list: partitionned_edges) - { - for (const auto & edge: edge_list) - { - if (std::abs(position.x() - edge.position) < move_edge_threshold and position.y() >= edge.min and position.y() <= edge.max) - { - return edge_list; - } - } - } - - return {}; -} - -bool assert_rectangle_list_is_partition(const std::vector & rectangles) -{ - return true; - - bool ok = true; - - QRectF bounding_box{0, 0, 1, 1}; - - for (const auto & i: rectangles) - { - if (i.width() < 0 or i.height() < 0) - { - qDebug() << "Invalid rectangle" << i; - ok = false; - } - } - - std::vector rectangle_y_boundaries; - for (auto & i: rectangles) - { - rectangle_y_boundaries.push_back(i.top()); - rectangle_y_boundaries.push_back(i.bottom()); - } - - // for (int y = bounding_box.top(); y < bounding_box.bottom(); ++y) - for (double y: rectangle_y_boundaries) - { - if (y < bounding_box.top()) - continue; - if (y >= bounding_box.bottom()) - continue; - - qDebug() << "Checking line" << y; - std::vector> horizontal_segments; - for (const auto & i: rectangles) - { - if (y >= i.top() and y < i.bottom()) - { - horizontal_segments.emplace_back(i.left(), i.right()); - qDebug() << " Adding segment" << i.left() << "-" << i.right(); - } - } - - std::ranges::sort(horizontal_segments); - - if (horizontal_segments.empty()) - { - qDebug() << "Line" << y << "empty"; - ok = false; - } - - if (horizontal_segments.front().first != bounding_box.left()) - { - qDebug() << "Line" << y << "does not start at the left of the bounding box" << (horizontal_segments.front().first - bounding_box.left()); - ok = false; - } - - if (horizontal_segments.back().second != bounding_box.right()) - { - qDebug() << "Last rectangle of line" << y << "does not end at the right of the bounding box" << (horizontal_segments.back().second - bounding_box.right()); - ok = false; - } - - for (int i = 1; i < horizontal_segments.size(); ++i) - { - if (horizontal_segments[i - 1].second < horizontal_segments[i].first) - { - qDebug() << "Overlap in line" << y << (horizontal_segments[i - 1].second - horizontal_segments[i].first); - ok = false; - } - else if (horizontal_segments[i - 1].second > horizontal_segments[i].first) - { - qDebug() << "Gap in line" << y << (horizontal_segments[i - 1].second - horizontal_segments[i].first); - ok = false; - } - } - } - - if (!ok) - { - qDebug() << "Bounding box:" << bounding_box; - int n = 1; - for (auto & i: rectangles) - { - qDebug() << "Rectangle" << (n++) << ":" << i.topLeft() << "-" << i.bottomRight(); - } - } - - return ok; -} - -} // namespace - -rectangle_partitionner::rectangle_partitionner(QWidget * parent) : - QFrame(parent) -{ - p = new rectangle_partitionner_private; - - setMouseTracking(true); - - std::vector encoders; - - encoders.push_back(QRectF{0, 0, 1, 1}); - set_rectangles(encoders); - - m_paint = [](QPainter & painter, QRect rect, const QVariant & data, int index, bool selected) { - if (selected) - { - painter.fillRect(rect.adjusted(1, 1, 0, 0), QColorConstants::Cyan); - } - - QString text = QString("%1").arg(index + 1); - painter.drawText(rect, Qt::AlignCenter, text); - }; -} - -rectangle_partitionner::~rectangle_partitionner() -{ - delete p; -} - -void rectangle_partitionner::paintEvent(QPaintEvent * event) -{ - QFrame::paintEvent(event); - - QPainter painter(this); - - auto positions = rectangles_position(); - - { - QList lines; - for (int i = 1; i < num_subdiv; i++) - { - QPoint p1 = to_position({0, double(i) / num_subdiv}); - QPoint p2 = to_position({1, double(i) / num_subdiv}); - lines.emplace_back(p1, p2); - - QPoint p3 = to_position({double(i) / num_subdiv, 0}); - QPoint p4 = to_position({double(i) / num_subdiv, 1}); - lines.emplace_back(p3, p4); - } - - QPen pen = painter.pen(); - painter.setPen(QPen(Qt::lightGray, 1, Qt::SolidLine)); - painter.drawLines(lines); - painter.setPen(pen); - } - - if (m_paint) - { - int n = 0; - for (QRect & i: positions) - { - painter.drawRect(i); - bool is_selected = n == m_selected_index and isEnabled(); - m_paint(painter, i, m_rectangles_data.at(n), n, is_selected); - - n++; - } - } - - if (not p->hovered.empty() and p->selection.empty()) - { - painter.setPen(QPen(Qt::blue, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - - auto r = frameRect(); - r.adjust(frameWidth(), frameWidth(), -2 * frameWidth(), -2 * frameWidth()); - - QList lines; - lines.reserve(p->hovered.size()); - for (const edge & i: p->hovered) - { - QLineF line; - switch (i.edge_side) - { - case side::top: - case side::bottom: - line = QLineF(i.min, i.position, i.max, i.position); - break; - - case side::left: - case side::right: - line = QLineF(i.position, i.min, i.position, i.max); - break; - } - - int x1 = std::round(r.x() + line.x1() * (r.width() - 1)); - int x2 = std::round(r.x() + line.x2() * (r.width() - 1)); - - int y1 = std::round(r.y() + line.y1() * (r.height() - 1)); - int y2 = std::round(r.y() + line.y2() * (r.height() - 1)); - - lines.emplace_back(x1, y1, x2, y2); - } - - painter.drawLines(lines); - - auto horz_partitionned = partition_edges(horizontal_edges(m_rectangles)); - auto vert_partitionned = partition_edges(vertical_edges(m_rectangles)); - } - else if ((cursor() == Qt::SplitHCursor or cursor() == Qt::SplitVCursor) and not p->split_line.isNull()) - { - auto now = std::chrono::duration_cast>(std::chrono::steady_clock::now().time_since_epoch()).count(); - - QPen pen(Qt::black, 2, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin); - pen.setDashPattern({5, 5}); - pen.setDashOffset(-now * 15); - painter.setPen(pen); - - painter.drawLine(p->split_line); - update(); - } -} - -void rectangle_partitionner::mouseMoveEvent(QMouseEvent * event) -{ - assert(m_rectangles.size() == m_rectangles_data.size()); - - auto r = frameRect(); - r.adjust(frameWidth(), frameWidth(), -2 * frameWidth(), -2 * frameWidth()); - - if (not p->selection.empty()) - { - double position; - - if (p->selection.front().edge_side == side::top or p->selection.front().edge_side == side::bottom) - position = from_position(event->pos()).y(); - else - position = from_position(event->pos()).x(); - - position = std::clamp(position, p->min_drag_position, p->max_drag_position); - position = std::round(position * num_subdiv) / num_subdiv; // magnetism - - for (edge & e: p->selection) - { - switch (e.edge_side) - { - case side::top: - m_rectangles[e.rectangle_index].setTop(position); - break; - - case side::bottom: - m_rectangles[e.rectangle_index].setBottom(position); - break; - - case side::left: - m_rectangles[e.rectangle_index].setLeft(position); - break; - - case side::right: - m_rectangles[e.rectangle_index].setRight(position); - break; - } - } - - // if (not assert_rectangle_list_is_partition(m_rectangles)) - // { - // abort(); - // } - - update(); - rectangles_change(m_rectangles); - } - else - { - p->hovered.clear(); - - if (auto horz_edges = hovered_edges(from_position(event->pos()), partition_edges(horizontal_edges(m_rectangles)), true); not horz_edges.empty()) - { - p->hovered = std::move(horz_edges); - update(); - } - else if (auto vert_edges = hovered_edges(from_position(event->pos()), partition_edges(vertical_edges(m_rectangles)), false); not vert_edges.empty()) - { - p->hovered = std::move(vert_edges); - update(); - } - else - { - int n = hovered_rectangle(from_position(event->pos()), m_rectangles); - } - - auto new_cursor = get_cursor_shape(from_position(event->pos()), m_rectangles); - if (new_cursor != cursor()) - { - update(); - setCursor(new_cursor); - } - } - - if (cursor() == Qt::SplitHCursor) - { - int n = hovered_rectangle(from_position(event->pos()), m_rectangles); - - double x = std::round(from_position(event->pos()).x() * num_subdiv) / num_subdiv; // magnetism - int px = to_position({x, 0}).x(); - - p->split_line = {px, rectangles_position()[n].top(), px, rectangles_position()[n].bottom()}; - update(); - } - else if (cursor() == Qt::SplitVCursor) - { - int n = hovered_rectangle(from_position(event->pos()), m_rectangles); - - double y = std::round(from_position(event->pos()).y() * num_subdiv) / num_subdiv; // magnetism - int py = to_position({0, y}).y(); - - p->split_line = {rectangles_position()[n].left(), py, rectangles_position()[n].right(), py}; - update(); - } - else - { - p->split_line = {0, 0, 0, 0}; - } -} - -void rectangle_partitionner::mousePressEvent(QMouseEvent * event) -{ - assert(m_rectangles.size() == m_rectangles_data.size()); - - auto r = frameRect(); - r.adjust(frameWidth(), frameWidth(), -2 * frameWidth(), -2 * frameWidth()); - - p->selection.clear(); - p->split_line = {0, 0, 0, 0}; - - if (auto horz_edges = hovered_edges(from_position(event->pos()), partition_edges(horizontal_edges(m_rectangles)), true); not horz_edges.empty()) - { - p->selection = std::move(horz_edges); - } - else if (auto vert_edges = hovered_edges(from_position(event->pos()), partition_edges(vertical_edges(m_rectangles)), false); not vert_edges.empty()) - { - p->selection = std::move(vert_edges); - } - else if (int n = hovered_rectangle(from_position(event->pos()), m_rectangles); n >= 0) - { - QRectF & hovered = m_rectangles[n]; - - // Compute distance to edges - auto pos = from_position(event->pos()); - - double dx = std::min(pos.x() - hovered.left(), hovered.right() - pos.x()); - double dy = std::min(pos.y() - hovered.top(), hovered.bottom() - pos.y()); - - if (dx < split_edge_threshold) - { - double y = std::round(pos.y() * num_subdiv) / num_subdiv; // magnetism - - // Split vertically - QRectF new_rectangle = hovered; - - hovered.setBottom(y); - new_rectangle.setTop(hovered.bottom()); - - m_rectangles.push_back(new_rectangle); - m_rectangles_data.push_back(m_rectangles_data[n]); - update(); - rectangles_change(m_rectangles); - - if (not assert_rectangle_list_is_partition(m_rectangles)) - abort(); - } - else if (dy < split_edge_threshold) - { - double x = std::round(pos.x() * num_subdiv) / num_subdiv; // magnetism - - // Split horizontally - QRectF new_rectangle = hovered; - - hovered.setRight(x); - new_rectangle.setLeft(hovered.right()); - - m_rectangles.push_back(new_rectangle); - m_rectangles_data.push_back(m_rectangles_data[n]); - update(); - rectangles_change(m_rectangles); - - if (not assert_rectangle_list_is_partition(m_rectangles)) - abort(); - } - else - { - set_selected_index(n); - } - } - - if (not p->selection.empty()) - { - p->hovered.clear(); - - p->min_drag_position = std::numeric_limits::lowest(); - p->max_drag_position = std::numeric_limits::max(); - - for (auto & e: p->selection) - { - switch (e.edge_side) - { - case side::top: - p->max_drag_position = std::min(p->max_drag_position, m_rectangles[e.rectangle_index].bottom()); - break; - case side::bottom: - p->min_drag_position = std::max(p->min_drag_position, m_rectangles[e.rectangle_index].top()); - break; - case side::left: - p->max_drag_position = std::min(p->max_drag_position, m_rectangles[e.rectangle_index].right()); - break; - case side::right: - p->min_drag_position = std::max(p->min_drag_position, m_rectangles[e.rectangle_index].left()); - break; - } - } - } - assert(m_rectangles.size() == m_rectangles_data.size()); -} - -void rectangle_partitionner::mouseReleaseEvent(QMouseEvent * event) -{ - assert(m_rectangles.size() == m_rectangles_data.size()); - - p->selection.clear(); - - // Delete empty rectangles - assert(m_rectangles.size() == m_rectangles_data.size()); - bool changed = false; - for (int i = 0; i < m_rectangles.size();) - { - if (m_rectangles[i].width() <= 0.0001 or m_rectangles[i].height() <= 0.0001) // TODO configurable thresholds - { - m_rectangles.erase(m_rectangles.begin() + i); - m_rectangles_data.erase(m_rectangles_data.begin() + i); - changed = true; - - if (m_selected_index > i) - m_selected_index--; - else if (m_selected_index == i) - { - m_selected_index = -1; - } - } - else - { - ++i; - } - } - assert(m_rectangles.size() == m_rectangles_data.size()); - - if (changed) - { - if (not assert_rectangle_list_is_partition(m_rectangles)) - abort(); - - rectangles_change(m_rectangles); - selected_index_change(m_selected_index); - update(); - } -} - -void rectangle_partitionner::leaveEvent(QEvent * event) -{ - p->split_line = {0, 0, 0, 0}; -} - -void rectangle_partitionner::keyPressEvent(QKeyEvent * event) -{ - auto r = frameRect(); - r.adjust(frameWidth(), frameWidth(), -2 * frameWidth(), -2 * frameWidth()); - qDebug() << "Bounding box:" << r; - int n = 1; - for (auto & i: m_rectangles) - { - qDebug() << "Rectangle" << (n++) << ":" << i.topLeft() << "-" << i.bottomRight(); - } -} - -void rectangle_partitionner::set_rectangles(rectangle_list value) -{ - assert(m_rectangles.size() == m_rectangles_data.size()); - auto old_value = std::move(m_rectangles); - - m_rectangles = std::move(value); - - for (auto & i: m_rectangles) - { - i.setBottom(std::round(i.bottom() * num_subdiv) / num_subdiv); - i.setTop(std::round(i.top() * num_subdiv) / num_subdiv); - i.setLeft(std::round(i.left() * num_subdiv) / num_subdiv); - i.setRight(std::round(i.right() * num_subdiv) / num_subdiv); - } - - if (not assert_rectangle_list_is_partition(m_rectangles)) - { - m_rectangles = std::move(old_value); - - throw std::runtime_error("Invalid partitionning"); - } - - m_rectangles_data.resize(m_rectangles.size()); - - if (m_selected_index >= m_rectangles.size()) - set_selected_index(m_rectangles.size() - 1); - - update(); - rectangles_change(m_rectangles); - assert(m_rectangles.size() == m_rectangles_data.size()); -} - -void rectangle_partitionner::set_selected_index(int new_index) -{ - new_index = std::clamp(new_index, -1, m_rectangles.size()); - - if (new_index != m_selected_index) - { - m_selected_index = new_index; - update(); - - selected_index_change(new_index); - } -} - -void rectangle_partitionner::set_rectangles_data(const data_list & value) -{ - assert(m_rectangles.size() == m_rectangles_data.size()); - m_rectangles_data = value; - m_rectangles_data.resize(m_rectangles.size()); - assert(m_rectangles.size() == m_rectangles_data.size()); - - update(); -} - -void rectangle_partitionner::set_rectangles_data(int index, QVariant value) -{ - assert(m_rectangles.size() == m_rectangles_data.size()); - assert(index < m_rectangles_data.size() and index >= 0); - m_rectangles_data.at(index) = value; - assert(m_rectangles.size() == m_rectangles_data.size()); - - update(); -} - -void rectangle_partitionner::set_paint(paint_function paint) -{ - m_paint = paint; - update(); -} - -std::vector rectangle_partitionner::rectangles_position() -{ - std::vector positions; - positions.reserve(m_rectangles.size()); - - auto r = frameRect(); - r.adjust(frameWidth(), frameWidth(), -2 * frameWidth(), -2 * frameWidth()); - - for (QRectF & i: m_rectangles) - { - int x1 = std::round(r.x() + i.x() * (r.width() - 1)); - int x2 = std::round(r.x() + (i.x() + i.width()) * (r.width() - 1)); - - int y1 = std::round(r.y() + i.y() * (r.height() - 1)); - int y2 = std::round(r.y() + (i.y() + i.height()) * (r.height() - 1)); - positions.emplace_back(x1, y1, x2 - x1 + 1, y2 - y1 + 1); - } - assert(m_rectangles.size() == positions.size()); - - return positions; -} - -QPointF rectangle_partitionner::from_position(QPoint position) -{ - auto r = frameRect(); - r.adjust(frameWidth(), frameWidth(), -2 * frameWidth(), -2 * frameWidth()); - - return QPointF{ - std::clamp(double(position.x() - r.x()) / (r.width() - 1), 0., 1.), - std::clamp(double(position.y() - r.y()) / (r.height() - 1), 0., 1.), - }; -} - -QPoint rectangle_partitionner::to_position(QPointF position) -{ - auto r = frameRect(); - r.adjust(frameWidth(), frameWidth(), -2 * frameWidth(), -2 * frameWidth()); - - return QPoint( - std::round(r.x() + position.x() * (r.width() - 1)), - std::round(r.y() + position.y() * (r.height() - 1))); -} - -#include "moc_rectangle_partitionner.cpp" diff --git a/dashboard/rectangle_partitionner.h b/dashboard/rectangle_partitionner.h deleted file mode 100644 index 50f7a352..00000000 --- a/dashboard/rectangle_partitionner.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include -#include -#include - -struct rectangle_partitionner_private; - -class rectangle_partitionner : public QFrame -{ - Q_OBJECT - - rectangle_partitionner_private * p; - -public: - explicit rectangle_partitionner(QWidget * parent = nullptr); - rectangle_partitionner(const rectangle_partitionner &) = delete; - rectangle_partitionner & operator=(const rectangle_partitionner &) = delete; - ~rectangle_partitionner(); - - using rectangle_list = std::vector; - using data_list = std::vector; - using paint_function = std::function; - - Q_PROPERTY(rectangle_list rectangles READ rectangles WRITE set_rectangles NOTIFY rectangles_change) - Q_PROPERTY(data_list rectangles_data READ rectangles_data WRITE set_rectangles_data) - Q_PROPERTY(int selected_index READ selected_index WRITE set_selected_index NOTIFY selected_index_change) - Q_PROPERTY(paint_function paint READ paint WRITE set_paint) - - const rectangle_list & rectangles() const - { - return m_rectangles; - } - - int selected_index() const - { - return m_selected_index; - } - - const data_list & rectangles_data() const - { - return m_rectangles_data; - } - - const QVariant & rectangles_data(int index) const - { - return m_rectangles_data.at(index); - } - - const paint_function & paint() const - { - return m_paint; - } - - void set_rectangles(rectangle_list); - void set_rectangles_data(const data_list &); - void set_rectangles_data(int, QVariant); - void set_selected_index(int); - void set_paint(paint_function paint); - -signals: - void selected_index_change(int); - void rectangles_change(const rectangle_list &); - -protected: - rectangle_list m_rectangles; - int m_selected_index = 0; - data_list m_rectangles_data; - paint_function m_paint; - - std::vector rectangles_position(); - QPointF from_position(QPoint position); - QPoint to_position(QPointF position); - - void paintEvent(QPaintEvent * event) override; - void mouseMoveEvent(QMouseEvent * event) override; - void mousePressEvent(QMouseEvent * event) override; - void mouseReleaseEvent(QMouseEvent * event) override; - void leaveEvent(QEvent * event) override; - - void keyPressEvent(QKeyEvent * event) override; -}; diff --git a/dashboard/settings.cpp b/dashboard/settings.cpp deleted file mode 100644 index 7f9058e2..00000000 --- a/dashboard/settings.cpp +++ /dev/null @@ -1,642 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "settings.h" - -#include "escape_string.h" -#include "gui_config.h" -#include "rectangle_partitionner.h" -#include "steam_app.h" -#include "ui_settings.h" -#include "wivrn_server.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace -{ -// The index must match the order in the combo boxes -const std::vector> encoder_ids{ - {0, "auto"}, - {1, "nvenc"}, - {2, "vaapi"}, - {3, "x264"}, - {4, "vulkan"}, -}; - -const std::vector> codec_ids{ - {0, "auto"}, - {1, "h264"}, - {1, "avc"}, - {2, "h265"}, - {2, "hevc"}, - {3, "av1"}, - {3, "AV1"}, -}; - -const std::vector> compatible_combos{ - // Automatically chosen encoder - {0, 0}, - // nvenc - {1, 0}, - {1, 1}, - {1, 2}, - // {1, 3}, - // vaapi - {2, 0}, - {2, 1}, - {2, 2}, - {2, 3}, - // x264 - {3, 1}, - // vulkan - {4, 1}, - // {4, 2}, -}; - -int encoder_id_from_string(std::string_view s) -{ - for (auto & [i, j]: encoder_ids) - { - if (j == s) - return i; - } - return 0; -} - -const std::string & encoder_from_id(int id) -{ - for (auto & [i, j]: encoder_ids) - { - if (i == id) - return j; - } - - static const std::string default_value = "auto"; - return default_value; -} - -int codec_id_from_string(std::string_view s) -{ - for (auto & [i, j]: codec_ids) - { - if (j == s) - return i; - } - return 0; -} - -const std::string & codec_from_id(int id) -{ - for (auto & [i, j]: codec_ids) - { - if (i == id) - return j; - } - - static const std::string default_value = "auto"; - return default_value; -} - -} // namespace - -settings::settings(wivrn_server * server_interface) : - server_interface(server_interface) -{ - ui = new Ui::Settings; - ui->setupUi(this); - - connect(ui->combo_select_game, &QComboBox::currentIndexChanged, this, &settings::on_selected_game_changed); - connect(ui->button_game_browse, &QPushButton::clicked, this, &settings::on_browse_game); - - connect(ui->partitionner, &rectangle_partitionner::selected_index_change, this, &settings::selected_rectangle_changed); - - connect(ui->encoder, &QComboBox::currentIndexChanged, this, &settings::on_selected_encoder_changed); - connect(ui->encoder, &QComboBox::currentIndexChanged, this, &settings::on_encoder_settings_changed); - connect(ui->codec, &QComboBox::currentIndexChanged, this, &settings::on_encoder_settings_changed); - - connect(this, &QDialog::accepted, this, &settings::save_settings); - connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this, &settings::restore_defaults); - - setWindowModality(Qt::WindowModality::ApplicationModal); - - fill_steam_games_list(); - load_settings(); - - // Use a queued connection so that the slot is called after the widgets have been laid out - // Set up the signal connection after loading to avoid scrolling when opening the window - connect(ui->radio_manual_encoder, &QRadioButton::toggled, this, [&](bool value) { - if (value) - ui->scrollArea->ensureWidgetVisible(ui->layout_encoder_config); }, Qt::QueuedConnection); - - auto encoders = dynamic_cast(ui->encoder->model()); -#if !WIVRN_USE_NVENC - encoders->item(1)->setEnabled(false); -#endif -#if !WIVRN_USE_VAAPI - encoders->item(2)->setEnabled(false); -#endif -#if !WIVRN_USE_X264 - encoders->item(3)->setEnabled(false); -#endif -#if !WIVRN_USE_VULKAN_ENCODE - encoders->item(4)->setEnabled(false); -#endif - - ui->partitionner->set_paint([&](QPainter & painter, QRect rect, const QVariant & data, int index, bool selected) { - QPalette palette = QApplication::palette(); - - if (selected) - { - painter.fillRect(rect.adjusted(1, 1, 0, 0), palette.color(QPalette::Highlight)); - } - - auto [encoder_id, codec_id] = data.value>(); - - QString codec = ui->codec->itemText(codec_id); - QString encoder = ui->encoder->itemText(encoder_id); - - QFont font = painter.font(); - QFont font2 = font; - - font2.setPixelSize(24); - - QString text = QString("%1\n%2").arg(encoder, codec); - - QFontMetrics metrics{font2}; - QSize size = metrics.size(0, text); - - if (double ratio = std::max((double)size.width() / rect.width(), (double)size.height() / rect.height()); ratio > 1) - { - int pixel_size = font2.pixelSize() / ratio; - if (pixel_size > 0) - font2.setPixelSize(pixel_size); - } - - painter.setFont(font2); - painter.drawText(rect, Qt::AlignCenter, text); - painter.setFont(font); - }); -} - -settings::~settings() -{ - delete ui; - ui = nullptr; -} - -void settings::fill_steam_games_list() -{ - ui->combo_select_game->clear(); - ui->combo_select_game->addItem(tr("None", "Game selection combo box")); - ui->combo_select_game->addItem(tr("Custom...", "Game selection combo box")); - - auto apps = steam_apps(); - for (auto & app: apps) - { - ui->combo_select_game->addItem(QString::fromUtf8(app.name), QVariant::fromValue(app)); - } -} - -void settings::on_selected_encoder_changed() -{ - int encoder = ui->encoder->currentIndex(); - - QStandardItemModel * model = dynamic_cast(ui->codec->model()); - assert(model); - - for (int i = 0, n = model->rowCount(); i < n; i++) - { - auto * item = model->item(i); - item->setFlags(item->flags() & ~Qt::ItemIsEnabled); - } - - for (auto [i, j]: compatible_combos) - { - if (encoder == i) - { - auto * item = model->item(j); - item->setFlags(item->flags() | Qt::ItemIsEnabled); - } - } -} - -void settings::on_encoder_settings_changed() -{ - if (ui->partitionner->selected_index() < 0) - return; - - QString status; - - int encoder = ui->encoder->currentIndex(); - int codec = ui->codec->currentIndex(); - - bool compatible = false; - - for (auto [i, j]: compatible_combos) - { - if (encoder == i and codec == j) - { - compatible = true; - break; - } - } - - if (!compatible) - { - // Find a compatible codec for this encoder - for (auto [i, j]: compatible_combos) - { - if (encoder == i) - { - codec = j; - ui->codec->setCurrentIndex(j); - } - } - } - - if (codec == 3 /* av1 */) - { - status += tr("Not all headsets and GPUs support AV1\n"); - } - - if (encoder == 4 /* vulkan */) - { - status += tr("Vulkan Video encoder is experimental\n"); - } - - ui->partitionner->set_rectangles_data(ui->partitionner->selected_index(), QVariant::fromValue(std::pair(encoder, codec))); - - ui->message->setText(status); -} - -void settings::on_selected_game_changed(int index) -{ - if (index == 0) // No game selected - { - ui->edit_game_path->setEnabled(false); - ui->button_game_browse->setEnabled(false); - } - else if (index == 1) // Custom path - { - ui->edit_game_path->setEnabled(true); - ui->button_game_browse->setEnabled(true); - } - else // From Steam vrmanifest - { - ui->edit_game_path->setEnabled(false); - ui->button_game_browse->setEnabled(false); - } -} - -void settings::on_browse_game() -{ - QFileInfo info(application().empty() ? QString{} : QString::fromStdString(application().front())); - - QFileDialog dlg(this, tr("Select game")); - dlg.setFilter(QDir::Executable | QDir::Files); - dlg.setFileMode(QFileDialog::ExistingFile); - dlg.setDirectory(info.dir()); - - if (not dlg.exec()) - return; - - auto files = dlg.selectedFiles(); - - if (files.empty()) - return; - - set_application({files.front().toStdString()}); -} - -void settings::selected_rectangle_changed(int index) -{ - if (index >= 0) - { - auto [encoder, codec] = ui->partitionner->rectangles_data(index).value>(); - - ui->encoder->setCurrentIndex(encoder); - ui->codec->setCurrentIndex(codec); - ui->encoder->setEnabled(true); - ui->codec->setEnabled(true); - } - else - { - ui->encoder->setCurrentIndex(-1); - ui->codec->setCurrentIndex(-1); - ui->encoder->setEnabled(false); - ui->codec->setEnabled(false); - } -} - -void settings::restore_defaults() -{ - ui->bitrate->setValue(50); - ui->radio_auto_foveation->setChecked(true); - ui->radio_auto_encoder->setChecked(true); - ui->layout_encoder_config->setVisible(false); - - std::vector rectangles; - std::vector encoder_config; - - rectangles.push_back(QRectF(0, 0, 1, 1)); - std::pair config{0, 0}; - encoder_config.push_back(QVariant::fromValue(config)); - - ui->partitionner->set_rectangles(rectangles); - ui->partitionner->set_rectangles_data(encoder_config); - ui->partitionner->set_selected_index(0); - - ui->combo_select_game->setCurrentIndex(0); - ui->edit_game_path->setText(""); -} - -void settings::set_application(const std::vector & app) -{ - ui->edit_game_path->setText(QString::fromStdString(escape_string(app))); -} - -std::vector settings::application() -{ - return unescape_string(ui->edit_game_path->text().toStdString()); -} - -void settings::load_settings() -{ - std::vector rectangles; - std::vector encoder_config; - - // Encoders configuration - try - { - auto conf = server_interface->jsonConfiguration(); - qDebug() << "Server config" << conf; - json_doc = nlohmann::json::parse(conf.toUtf8()); - } - catch (std::exception & e) - { - qWarning() << "Cannot read configuration: " << e.what(); - restore_defaults(); - return; - } - - try - { - nlohmann::json encoders; - - if (json_doc.contains("encoders")) - { - encoders = json_doc["encoders"]; - ui->radio_auto_encoder->setChecked(false); - ui->radio_manual_encoder->setChecked(true); - } - else if (json_doc.contains("encoders.disabled")) - { - encoders = json_doc["encoders.disabled"]; - ui->radio_auto_encoder->setChecked(true); - ui->radio_manual_encoder->setChecked(false); - ui->layout_encoder_config->setVisible(false); - } - else - { - ui->radio_auto_encoder->setChecked(true); - ui->radio_manual_encoder->setChecked(false); - ui->layout_encoder_config->setVisible(false); - } - - for (auto & i: encoders) - { - int encoder = encoder_id_from_string(i.value("encoder", "auto")); - int codec = codec_id_from_string(i.value("codec", "auto")); - double width = i.value("width", 1.0); - double height = i.value("height", 1.0); - double offset_x = i.value("offset_x", 0.0); - double offset_y = i.value("offset_y", 0.0); - int group = i.value("group", 0); // TODO: handle groups - - rectangles.push_back(QRectF(offset_x, offset_y, width, height)); - encoder_config.push_back(QVariant::fromValue(std::pair(encoder, codec))); - } - } - catch (...) - { - QMessageBox msgbox{QMessageBox::Information, tr("Invalid settings"), tr("The encoder configuration is invalid, the default values will be restored."), QMessageBox::Close, this}; - msgbox.exec(); - - rectangles.clear(); - encoder_config.clear(); - } - - if (rectangles.empty()) - { - ui->radio_auto_encoder->setChecked(true); - ui->radio_manual_encoder->setChecked(false); - ui->layout_encoder_config->setVisible(false); - - rectangles.push_back(QRectF(0, 0, 1, 1)); - std::pair config{0, 0}; - encoder_config.push_back(QVariant::fromValue(config)); - } - - ui->partitionner->set_rectangles(rectangles); - ui->partitionner->set_rectangles_data(encoder_config); - - if (rectangles.size() == 1) - { - ui->partitionner->set_selected_index(0); - // Force updating the combo boxes, if the selected index is already 0 the signal is not called - selected_rectangle_changed(0); - } - else - ui->partitionner->set_selected_index(-1); - - // Foveation - try - { - if (json_doc.contains("scale")) - { - ui->slider_foveation->setValue(std::round((1 - json_doc.value("scale", 1.0)) * 100)); - ui->spin_foveation->setValue(std::round((1 - json_doc.value("scale", 1.0)) * 100)); - ui->radio_auto_foveation->setChecked(false); - ui->radio_manual_foveation->setChecked(true); - } - else - { - ui->radio_auto_foveation->setChecked(true); - ui->radio_manual_foveation->setChecked(false); - } - } - catch (...) - { - ui->radio_auto_foveation->setChecked(true); - ui->radio_manual_foveation->setChecked(false); - } - - // Bitrate - try - { - ui->bitrate->setValue(json_doc.value("bitrate", 50'000'000.0) / 1'000'000); - } - catch (...) - { - ui->bitrate->setValue(50); - } - - // Automatically started application - std::vector application; - try - { - if (json_doc["application"].is_array()) - application = json_doc.value>("application", {}); - else if (json_doc["application"].is_string()) - application.push_back(json_doc["application"]); - - int game_index = 0; - if (application.size() == 2 and application[0] == "steam") - { - auto url = application[1]; - - // Indices 0 and 1 are None and Custom - for (int i = 2, n = ui->combo_select_game->count(); i < n; i++) - { - QVariant data = ui->combo_select_game->itemData(i); - if (data.value().url == url) - { - game_index = i; - break; - } - } - } - - if (game_index == 0 and not application.empty()) - { - game_index = 1; - set_application(application); - } - - ui->combo_select_game->setCurrentIndex(game_index); - } - catch (...) - { - ui->combo_select_game->setCurrentIndex(0); - } - - // Update the compatible codecs - on_selected_encoder_changed(); - - // Update the status text - on_encoder_settings_changed(); -} - -void settings::save_settings() -{ - // Remove all optional keys that might not be overwritten - auto it = json_doc.find("scale"); - if (it != json_doc.end()) - json_doc.erase(it); - - it = json_doc.find("encoders.disabled"); - if (it != json_doc.end()) - json_doc.erase(it); - - it = json_doc.find("encoders"); - if (it != json_doc.end()) - json_doc.erase(it); - - it = json_doc.find("application"); - if (it != json_doc.end()) - json_doc.erase(it); - - if (not ui->radio_auto_foveation->isChecked()) - json_doc["scale"] = 1 - ui->slider_foveation->value() / 100.0; - - json_doc["bitrate"] = static_cast(ui->bitrate->value() * 1'000'000); - - std::vector encoders; - - const auto & rect = ui->partitionner->rectangles(); - const auto & data = ui->partitionner->rectangles_data(); - - for (int i = 0, n = rect.size(); i < n; i++) - { - nlohmann::json encoder; - auto [encoder_id, codec_id] = data[i].value>(); - - if (auto value = encoder_from_id(encoder_id); value != "auto") - encoder["encoder"] = value; - - if (auto value = codec_from_id(codec_id); value != "auto") - encoder["codec"] = value; - - encoder["width"] = rect[i].width(); - encoder["height"] = rect[i].height(); - encoder["offset_x"] = rect[i].x(); - encoder["offset_y"] = rect[i].y(); - - // TODO encoder groups - - encoders.push_back(encoder); - } - - std::ranges::stable_sort(encoders, [](const nlohmann::json & i, const nlohmann::json & j) { - double size_i = i.value("width", 0.0) * i.value("height", 0.0); - double size_j = j.value("width", 0.0) * j.value("height", 0.0); - return size_i < size_j; - }); - - // If there is only one automatic encoder, don't save it - if (encoders.size() != 1 or encoders[0].contains("codec") or encoders[0].contains("encoder")) - { - if (ui->radio_manual_encoder->isChecked()) - json_doc["encoders"] = encoders; - else - json_doc["encoders.disabled"] = encoders; - } - - if (ui->combo_select_game->currentIndex() == 0) - { - } - else if (ui->combo_select_game->currentIndex() == 1) - { - json_doc["application"] = application(); - } - else - { - auto app = qvariant_cast(ui->combo_select_game->currentData()); - - nlohmann::json application; - application.push_back("steam"); - application.push_back(app.url); - json_doc["application"] = application; - } - - server_interface->setJsonConfiguration(QString::fromStdString(json_doc.dump(2))); -} - -#include "moc_settings.cpp" diff --git a/dashboard/settings.h b/dashboard/settings.h deleted file mode 100644 index 7fd2ac88..00000000 --- a/dashboard/settings.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include - -namespace Ui -{ -class Settings; -} -class wivrn_server; - -class settings : public QDialog -{ - Q_OBJECT - - Ui::Settings * ui; - wivrn_server * server_interface; - - nlohmann::json json_doc; - - void selected_rectangle_changed(int); - -public: - settings(wivrn_server * server_interface); - ~settings(); - -private: - void on_encoder_settings_changed(); - void on_selected_encoder_changed(); - void on_selected_game_changed(int index); - void on_browse_game(); - void load_settings(); - void save_settings(); - void restore_defaults(); - - void fill_steam_games_list(); - - void set_application(const std::vector & app); - std::vector application(); -}; diff --git a/dashboard/settings.ui b/dashboard/settings.ui deleted file mode 100644 index 2cfec739..00000000 --- a/dashboard/settings.ui +++ /dev/null @@ -1,768 +0,0 @@ - - - Settings - - - - 0 - 0 - 960 - 762 - - - - Settings - - - - 0 - - - 0 - - - 0 - - - - - - 960 - 0 - - - - QFrame::Shape::NoFrame - - - true - - - - - 0 - 0 - 939 - 1035 - - - - - - - Qt::Orientation::Horizontal - - - - - - - Manual - - - group_foveation - - - - - - - - - Weaker - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - Stronger - - - Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter - - - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - Bitrate: - - - Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter - - - bitrate - - - - - - - Foveation strength: - - - Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter - - - - - - - Automatic - - - true - - - group_encoder - - - - - - - false - - - Browse - - - - - - - Encoder configuration: - - - Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter - - - - - - - Manual - - - group_encoder - - - - - - - Qt::Orientation::Vertical - - - - 0 - 0 - - - - - - - - Automatic - - - true - - - group_foveation - - - - - - - - 0 - 100 - - - - - - - <html><head/><body><p>To add a new encoder, split an existing encoder by clicking near an edge.</p><p>Drag an edge to resize or remove encoders.</p></body></html> - - - - - - - - - - 0 - 0 - - - - - 400 - 400 - - - - false - - - QFrame::Shape::Panel - - - QFrame::Shadow::Sunken - - - 1 - - - 0 - - - - - - - - - - 100 - 0 - - - - Encoder - - - encoder - - - - - - - - 100 - 0 - - - - No encoder selected - - - - Auto - - - - - nvenc (NVIDIA GPUs) - - - - - vaapi (AMD and Intel GPUs) - - - - - x264 (software encoding) - - - - - vulkan (Vulkan Video) - - - - - - - - - 100 - 0 - - - - No encoder selected - - - - Auto - - - - - H.264 - - - - - H.265 - - - - - AV1 - - - - - - - - - 220 - 0 - - - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop - - - true - - - - - - - - 100 - 0 - - - - Codec - - - codec - - - - - - - - - - - - - - Application to start when a headset connects - - - Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter - - - - - - - false - - - - 0 - 0 - - - - 0 - - - 80 - - - 20 - - - Qt::Orientation::Horizontal - - - QSlider::TickPosition::TicksBelow - - - - - - - Qt::Orientation::Horizontal - - - - - - - false - - - false - - - % - - - 80 - - - 20 - - - - - - - Qt::Orientation::Horizontal - - - - - - - - - - false - - - Path - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Orientation::Horizontal - - - - - - - - - Mbit/s - - - 0 - - - 1.000000000000000 - - - 200.000000000000000 - - - 100.000000000000000 - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Qt::Orientation::Horizontal - - - QSizePolicy::Policy::Fixed - - - - 12 - 20 - - - - - - - - - 14 - - - - WiVRn settings - - - - - - - Qt::Orientation::Horizontal - - - QSizePolicy::Policy::Fixed - - - - 12 - 20 - - - - - - - - - - A stronger foveation makes the image sharper in the center than in the periphery and makes the decoding faster. This is better for fast paced games. - -A weaker foveation gives a uniform sharpness in the whole image. - -The recommended values are between 20% and 50% for headsets without eye tracking and between 50% and 70% for headsets with eye tracking. - - - true - - - - - - - - - - - - - Qt::Orientation::Horizontal - - - QSizePolicy::Policy::Fixed - - - - 6 - 20 - - - - - - - - Qt::Orientation::Horizontal - - - QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok|QDialogButtonBox::StandardButton::RestoreDefaults - - - - - - - Qt::Orientation::Horizontal - - - QSizePolicy::Policy::Fixed - - - - 6 - 20 - - - - - - - - - - - rectangle_partitionner - QFrame -
rectangle_partitionner.h
- 1 -
-
- - encoder - codec - - - - - buttonBox - accepted() - Settings - accept() - - - 260 - 1185 - - - 157 - 274 - - - - - buttonBox - rejected() - Settings - reject() - - - 328 - 1185 - - - 286 - 274 - - - - - slider_foveation - valueChanged(int) - spin_foveation - setValue(int) - - - 888 - 530 - - - 1049 - 521 - - - - - spin_foveation - valueChanged(int) - slider_foveation - setValue(int) - - - 1049 - 521 - - - 888 - 530 - - - - - radio_manual_foveation - toggled(bool) - slider_foveation - setEnabled(bool) - - - 888 - 496 - - - 888 - 530 - - - - - radio_manual_foveation - toggled(bool) - spin_foveation - setEnabled(bool) - - - 888 - 496 - - - 1049 - 521 - - - - - radio_manual_encoder - toggled(bool) - layout_encoder_config - setVisible(bool) - - - 805 - 664 - - - 825 - 818 - - - - - - - - -
diff --git a/dashboard/steam_app.cpp b/dashboard/steam_app.cpp deleted file mode 100644 index 6d6f2eb2..00000000 --- a/dashboard/steam_app.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "steam_app.h" -#include "utils/flatpak.h" -#include -#include -#include -#include -#include -#include -#include -#include - -namespace -{ -std::string read_vr_manifest() -{ - const char * home = getenv("HOME"); - - std::filesystem::path vrmanifest = std::string{home ? home : ""} + "/.steam/steam/config/steamapps.vrmanifest"; - - if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk") - { - QProcess flatpak_spawn; - flatpak_spawn.start("flatpak-spawn", {"--host", "cat", QString::fromStdString(vrmanifest)}); - flatpak_spawn.waitForFinished(); - return flatpak_spawn.readAllStandardOutput().toStdString(); - } - else - { - std::ifstream f(vrmanifest); - std::istreambuf_iterator begin{f}, end; - - return {begin, end}; - } -} -} // namespace - -std::vector steam_apps(const std::string & locale) -{ - std::vector apps; - - auto manifest = read_vr_manifest(); - if (manifest.empty()) - { - return apps; - } - - nlohmann::json json; - try - { - json = nlohmann::json::parse(manifest); - } - catch (std::exception & e) - { - std::cerr << e.what() << std::endl; - return apps; - } - - for (auto & i: json["applications"]) - { - try - { - steam_app app; - - app.image_path = i.value("image_path", ""); - app.name = i["strings"]["en_us"]["name"]; - - if (i["launch_type"] == "url") - { - app.url = i["url"]; - } - else if (i["launch_type"] == "binary") - { - std::string app_key = i["app_key"]; - - const char prefix[] = "steam.app."; - if (app_key.starts_with(prefix)) - { - // ¯\_(ツ)_/¯ - uint64_t appkey = stoll(app_key.substr(strlen(prefix))); - app.url = "steam://rungameid/" + std::to_string((appkey << 32) + 0x2000000); - } - } - - if (app.url != "") - apps.push_back(app); - } - catch (std::exception & e) - { - std::cerr << e.what() << std::endl; - } - } - - std::ranges::sort(apps, [](const steam_app & a, const steam_app & b) { - return a.name < b.name; - }); - - return apps; -} diff --git a/dashboard/steam_app.h b/dashboard/steam_app.h deleted file mode 100644 index 5d0cb869..00000000 --- a/dashboard/steam_app.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include - -struct steam_app -{ - std::string name; - std::string image_path; - std::string url; -}; - -std::vector steam_apps(const std::string & locale = "en_us"); diff --git a/dashboard/wivrn_en.ts b/dashboard/wivrn_en.ts deleted file mode 100644 index 55ab919b..00000000 --- a/dashboard/wivrn_en.ts +++ /dev/null @@ -1,872 +0,0 @@ - - - - - MainWindow - - - Start - Start - - - - Stop - Stop - - - - Settings - Settings - - - - For Steam games, set the launch options to: - For Steam games, set the command to: - For Steam games, set the launch options to: - - - - Copy to clipboard - Copy to clipboard - - - - Disconnect - Disconnect - - - - Field of view - Field of view - - - - Microphone - Microphone - - - - Speaker - Speaker - - - - WiVRn dashboard - WiVRn dashboard - - - - <html><head/><body><p>The server does not have CAP_SYS_NICE capabilities. Click <a href="setcap"><span style=" text-decoration: underline; color:#2980b9;">here</span></a> to grant it.</p></body></html> - <html><head/><body><p>The server does not have CAP_SYS_NICE capabilities. Click <a href="setcap"><span style=" text-decoration: underline; color:#2980b9;">here</span></a> to grant it.</p></body></html> - - - - <html><head/><body><p>The <a href="https://github.com/WiVRn/WiVRn/issues/180"><span style=" text-decoration: underline; color:#2980b9;">Monado NVIDIA layer</span></a> is not installed.</p></body></html> - <html><head/><body><p>The <a href="https://github.com/WiVRn/WiVRn/issues/180"><span style=" text-decoration: underline; color:#2980b9;">Monado NVIDIA layer</span></a> is not installed.</p></body></html> - - - - Server status - Server - Server status - - - - Stopped - Stopped - - - - Running - Running - - - - Connect by USB - Connect by USB - - - - Pair headset - Pair headset - - - - Cancel - Cancel - - - - Manage headsets - Known headsets - Manage headsets - - - - Eye gaze tracking - Eye gaze tracking - - - - Hand tracking - Hand tracking - - - - Supported codecs - Supported codecs - - - - Face tracking - Face tracking - - - - Available refresh rates - Available refresh rates - - - - Eye resolution - Eye resolution - - - - Preferred refresh rate - Preferred refresh rate - - - - &Exit - &Exit - - - - &Show - &Show - - - - Headset status - Headset status - - - - Wizard - Wizard - - - - Details - Details - - - - About - About - - - - Exit - Exit - - - - &Hide - &Hide - - - - ManageHeadsets - - - Manage headsets - Manage headsets - - - - Remove - Remove - - - - Close - Close - - - - QObject - - - WiVRn dashboard - WiVRn dashboard - - - - QWizard - - - &Next > - do not translate, the QWizard translation will be used - - - - - Settings - - - Settings - Settings - - - - Bitrate: - Bi&trate: - Bitrate: - - - - Foveation strength: - Foveation strength: - - - - Manual - &Manual - Encoder - Manual - - - <html><head/><body><p>To add a new encoder, split an existing encoder by clicking near an edge.</p><p>You can drag an edge to resize or remove encoders.</p></body></html> - <html><head/><body><p>To add a new encoder, split an existing encoder by clicking near an edge.</p><p>You can drag an edge to resize or remove an encoder.</p></body></html> - <html><head/><body><p>To add a new encoder, split an existing encoder by clicking near an edge.</p><p>You can drag an edge to resize or remove encoders.</p></body></html> - - - - nvenc (NVIDIA GPUs) - nvenc (NVIDIA GPUs) - - - - vaapi (AMD and Intel GPUs) - vaapi (AMD and Intel GPUs) - - - - x264 (software encoding) - x264 (software encoding) - - - - Manual - &Manual - Foveation - Manual - - - - vulkan (Vulkan Video) - vulkan (Vulkan Video) - - - - Application to start when a headset connects - Application to start when a headset connects - - - - Path - Path - - - - Encoder configuration: - Encoder configuration: - - - <html><head/><body><p>A stronger foveation makes the image sharper in the center than in the periphery and makes the decoding faster. This is better for fast paced games.</p><p>A weaker foveation gives a uniform sharpness in the whole image.</p><p>The recommended values are between 20% and 50% for headsets without eye tracking and between 50% and 70% for headsets with eye tracking.</p></body></html> - <html><head/><body><p>A stronger foveation makes the image sharper in the center than in the periphery and makes the decoding faster. This is better for fast paced games.</p><p>A weaker foveation gives a uniform sharpness in the whole image.</p><p>The recommended values are between 20% and 50% for headsets without eye tracking and between 50% and 70% for headsets with eye tracking.</p></body></html> - - - - Weaker - Weaker - - - - Stronger - Stronger - - - - <html><head/><body><p>To add a new encoder, split an existing encoder by clicking near an edge.</p><p>Drag an edge to resize or remove encoders.</p></body></html> - <html><head/><body><p>To add a new encoder, split an existing encoder by clicking near an edge.</p><p>Drag an edge to resize or remove encoders.</p></body></html> - - - - Encoder - Encoder - - - - - No encoder selected - No encoder selected - - - - - Auto - Auto - - - - Automatic - Encoder - Automatic - - - - A stronger foveation makes the image sharper in the center than in the periphery and makes the decoding faster. This is better for fast paced games. - -A weaker foveation gives a uniform sharpness in the whole image. - -The recommended values are between 20% and 50% for headsets without eye tracking and between 50% and 70% for headsets with eye tracking. - A stronger foveation makes the image sharper in the center than in the periphery and makes the decoding faster. This is better for fast paced games. - -A weaker foveation gives a uniform sharpness in the whole image. - -The recommended values are between 20% and 50% for headsets without eye tracking and between 50% and 70% for headsets with eye tracking. - - - - Automatic - Au&tomatic - Foveation - Automatic - - - - WiVRn settings - WiVRn settings - - - - Codec - Codec - - - - Mbit/s - Mbit/s - - - You can use several encoders in order to split the workload between your CPU and your GPU and reduce the latency. - You can use several encoders in order to split the workload between your CPU and your GPU and reduce the latency. - - - You can choose a game to be started automatically when the headset connects. - You can choose a game to be started automatically when the headset connects. - - - - Browse - Browse - - - - % - % - - - - Wizard - - - Connection wizard - Connection wizard - - - - Welcome - Welcome - - - - Select your headset - Select your headset - - - - Getting latest release information... - Getting latest release information... - - - - - Install the WiVRn app on your headset - Install the WiVRn app on your headset - - - - You will need to have the WiVRn client installed on your headset. If the client is already installed, click "Skip". - You will need to have the WiVRn client installed on your headset. - You will need to have the WiVRn client installed on your headset. If the client is already installed, click "Skip". - - - - I want to sideload the client instead - I want to sideload the client instead - - - - Go to the store to install the client app on your headset. - Go to the store to install the client app on your headset. - - - Once this is done, click "Next". - Once this is done, click next. - Once this is done, click next. - - - - Downloading the WiVRn app - Downloading the WiVRn app - - - - Cancel - Cancel - - - - Downloading - Downloading - - - - Make sure your headset is in developer mode to continue. - Make sure your headset is in developer mode to continue. - - - Run the following command to install the client: - Run the following command to install the client - Run the following command to install the client: - - - - Copy to clipboard - Copy to clipboard - - - - Start the WiVRn app and connect to this computer - Start the WiVRn app and connect to this computer - - - - Installing... - Installing... - - - - Use the following PIN to connect your headset: - Use the following PIN to connect your headset: - - - - If the server is not visible or the connection fails, check that port 5353 (UDP) and 9757 (TCP and UDP) are open in your firewall. - If the server is not visible or the connection fails, check that port 5353 (UDP) and 9757 (TCP and UDP) are open in your firewall. - - - - Finished - Finished - - - - You can now start an OpenXR application on this computer. - You can now start an OpenXR application on this computer. - - - - For Steam games, set the launch options to: - For Steam games, set the command to: - For Steam games, set the launch options to: - - - - main_window - - - &Show GUI - &Show GUI - - - - &Hide GUI - &Hide GUI - - - - &Exit - &Exit - - - - You have to restart the WiVRn server to use the CAP_SYS_NICE capability. -Do you want to restart it now? - You have to restart the WiVRn server to use the CAP_SYS_NICE capability. -Do you want to restart it now? - - - - This will disconnect the currently connected headset. - This will disconnect the currently connected headset. - - - - Restart WiVRn - Restart WiVRn - - - - Cannot start setcap: %1 - Cannot start setcap: %1 - - - - %1 ⨯ %2 - %1 ⨯ %2 - - - - - %1 Hz - %1 Hz - - - - - - Supported - Supported - - - - - - Not supported - Not supported - - - - Left eye: %1° ⨯ %2°, right eye: %3° ⨯ %4° - Left eye: %1° ⨯ %2°, right eye: %3° ⨯ %4° - - - - - %n channel(s), %1 Hz - %1 channel(s), %2 Hz - - %n channel, %1 Hz - %n channels, %1 Hz - - - - - - N/A - N/A - - - - To pair your headset use the following PIN: %1 - To pair your headset use the following PIN: %1 - - - - Cannot connect to avahi, make sure avahi-daemon service is started with "disable-user-service-publishing" set to no - Cannot connect to avahi, make sure avahi-daemon service is started with "disable-user-service-publishing" set to no - - - - The WiVRn app is not installed on your headset. - The WiVRn app is not installed on your headset. - - - The WiVRn app is not installed on your headset. -Do you want to install it? - The WiVRn app is not installed on your headset. -Do you want to install it? - - - WiVRn - WiVRn - - - - Failed to start - Failed to start - - - - Crashed - Crashed - - - - Time out - Time out - - - - Read error - Read error - - - - Write error - write error - Write error - - - - Unknown error - Unknown error - - - Server error - Server error - - - - Failed to start server: -%1 - Failed to start server: -%1 - - - - Unknown error (%1), check logs - Unknown error (%1), check logs - - - - No device detected - No device detected - - - - Start the WiVRn app on your headset and connect to "%1". - Start the WiVRn app on your headset and connect to "%1". - - - - If the server is not visible or the connection fails, check that port 5353 (UDP) and 9757 (TCP and UDP) are open in your firewall. - If the server is not visible or the connection fails, check that port 5353 (UDP) and 9757 (TCP and UDP) are open in your firewall. - - - - Connected - Connected - - - - Not connected - Not connected - - - Cannot connect to avahi, make sure avahi-daemon service is started - Cannot connect to avahi, make sure avahi_daemon.service is started - Cannot connect to avahi, make sure avahi-daemon service is started - - - - Insufficient system resources - Insufficient system resources - - - - Server crashed: -%1 - Server crashed: -%1 - - - - Timeout starting server - Timeout starting server - - - - settings - - - Invalid settings - Invalid settings - - - - The encoder configuration is invalid, the default values will be restored. - The encoder configuration is invalid, the default values will be restored. - - - - None - Game selection combo box - None - - - - Custom... - Game selection combo box - Custom... - - - - Not all headsets and GPUs support AV1 - - Not all headsets and GPUs support AV1 - - - - - Vulkan Video encoder is experimental - - Vulkan Video encoder is experimental - - - - - Select game - Select game - - - - wizard - - - - Download - Download - - - - Other - Other - - - - This is not a tagged release. - This is not a tagged release. - - - - - If you install the headset app from the store, it might not be compatible with this server. - If you install the headset app from the store, it might not be compatible with this server. - - - - - If you install the headset app manually, this wizard will download the version that matches the dashboard. - If you install the headset app manually, this wizard will download the version that matches the dashboard. - - - - This is the latest WiVRn release. - This is the latest WiVRn release. - - - - A new release is available (%1 → %2). - A new release is available (%1 → %2). - - - - Cannot get latest release: %1 - Cannot get latest release: %1 - - - - There is no precompiled APK for this version. - There is no precompiled APK for this version. - - - - Follow the <a href="https://github.com/WiVRn/WiVRn/blob/master/docs/building.md#client-headset"><span style="text-decoration: underline; color:#2980b9;">documentation</span></a> to build your own client. - Follow the <a href="https://github.com/WiVRn/WiVRn/blob/master/docs/building.md#client-headset"><span style="text-decoration: underline; color:#2980b9;">documentation</span></a> to build your own client. - - - - Cannot get APK information: %1 - Cannot get APK information: %1 - - - - How? - How? - - - - - Skip - Skip - - - - Start the WiVRn app on your headset and connect to "%1". - Start the WiVRn app on your headset and connect to "%1". - - - - No device detected. - No device detected. - - - - %n device(s) detected. - - %n device detected. - %n devices detected. - - - - Downloading - Downloading - - - Download aborted - Download aborted - - - WiVRn - WiVRn - - - - Error downloading the client: -%1 - Error downloading the client: -%1 - - - Download error: %1 - Download error: % - Download error: %1 - - - - The headset is connected. - The headset is connected. - - - - The headset is not connected. - The headset is not connected. - - - diff --git a/dashboard/wivrn_fr.ts b/dashboard/wivrn_fr.ts deleted file mode 100644 index eae3bd27..00000000 --- a/dashboard/wivrn_fr.ts +++ /dev/null @@ -1,872 +0,0 @@ - - - - - MainWindow - - - Start - Démarrer - - - - Stop - Arrêter - - - - Settings - Paramètres - - - - For Steam games, set the launch options to: - For Steam games, set the command to: - Pour les jeux Steam, définir les options de lancement à : - - - - Copy to clipboard - Copier dans le presse-papier - - - - Disconnect - Déconnecter - - - - Field of view - Champ de vue - - - - Microphone - Microphone - - - - Speaker - Haut-parleur - - - - WiVRn dashboard - Tableau de bord de WiVRn - - - - <html><head/><body><p>The server does not have CAP_SYS_NICE capabilities. Click <a href="setcap"><span style=" text-decoration: underline; color:#2980b9;">here</span></a> to grant it.</p></body></html> - <html><head/><body><p>Le serveur n'a pas la capacité CAP_SYS_NICE. Cliquez <a href="setcap"><span style=" text-decoration: underline; color:#2980b9;">ici</span></a> pour la donner.</p></body></html> - - - - <html><head/><body><p>The <a href="https://github.com/WiVRn/WiVRn/issues/180"><span style=" text-decoration: underline; color:#2980b9;">Monado NVIDIA layer</span></a> is not installed.</p></body></html> - <html><head/><body><p>Le <a href="https://github.com/WiVRn/WiVRn/issues/180"><span style=" text-decoration: underline; color:#2980b9;">layer Monado NVIDIA</span></a> n'est pas installé.</p></body></html> - - - - Server status - Server - État du serveur - - - - Stopped - Arrêté - - - - Running - Démarré - - - - Connect by USB - Connexion par USB - - - - Pair headset - Appairer le casque - - - - Cancel - Annuler - - - - Manage headsets - Known headsets - Casques - - - - Eye gaze tracking - Suivi des yeux - - - - Hand tracking - Suivi des mains - - - - Supported codecs - Codecs supportés - - - - Face tracking - Suivi du visage - - - - Available refresh rates - Taux de rafraîchissment disponibles - - - - Eye resolution - Résolution par œil - - - - Preferred refresh rate - Taux de rafraîchisement préféré - - - - &Exit - &Quitter - - - - &Show - &Afficher - - - - Headset status - État du casque - - - - Wizard - Assistant - - - - Details - Détails - - - - About - À propos - - - - Exit - Quitter - - - - &Hide - &Cacher - - - - ManageHeadsets - - - Manage headsets - Casques - - - - Remove - Supprimer - - - - Close - Fermer - - - - QObject - - - WiVRn dashboard - Tableau de bord de WiVRn - - - - QWizard - - - &Next > - do not translate, the QWizard translation will be used - - - - - Settings - - - Settings - Paramètres - - - - Bitrate: - Bi&trate: - Débit : - - - - Foveation strength: - Intensité de la fovéation: - - - - Manual - &Manual - Encoder - Manuelle - - - <html><head/><body><p>To add a new encoder, split an existing encoder by clicking near an edge.</p><p>You can drag an edge to resize or remove encoders.</p></body></html> - <html><head/><body><p>To add a new encoder, split an existing encoder by clicking near an edge.</p><p>You can drag an edge to resize or remove an encoder.</p></body></html> - <html><head/><body><p>Pour ajouter un encodeur, découpez un encodeur existant en cliquant près d'un bord.</p><p>Vous pouvez déplacer un bord pour redimensionner ou supprimer un encodeur.</p></body></html> - - - - nvenc (NVIDIA GPUs) - nvenc (GPUs NVIDIA) - - - - vaapi (AMD and Intel GPUs) - vaapi (GPUs AMD et Intel) - - - - x264 (software encoding) - x264 (encodage logiciel) - - - - Manual - &Manual - Foveation - Manuelle - - - - vulkan (Vulkan Video) - vulkan (Vulkan Vidéo) - - - - Application to start when a headset connects - Application à démarrer quand un casque est connecté - - - - Path - Chemin - - - - Encoder configuration: - Configuration de l'encodeur: - - - <html><head/><body><p>A stronger foveation makes the image sharper in the center than in the periphery and makes the decoding faster. This is better for fast paced games.</p><p>A weaker foveation gives a uniform sharpness in the whole image.</p><p>The recommended values are between 20% and 50% for headsets without eye tracking and between 50% and 70% for headsets with eye tracking.</p></body></html> - <html><head/><body><p>Une fovéation plus forte rend l'image plus nette au centre qu'en périphérie et accélère le décodage. C'est un meilleur choix pour les jeux rapides.</p><p>Une fovéation plus faible donne une netteté uniforme sur toute l'image.</p><p>Les valeurs recommandées sont entre 20% et 50% pour les casques sans suivi des yeux et entre 50% et 70% pour les casques avec suivi des yeux.</p></body></html> - - - - Weaker - Plus faible - - - - Stronger - Plus forte - - - - <html><head/><body><p>To add a new encoder, split an existing encoder by clicking near an edge.</p><p>Drag an edge to resize or remove encoders.</p></body></html> - <html><head/><body><p>Pour ajouter un encodeur, découpez un encodeur existant en cliquant près d'un bord.</p><p>Déplacez un bord pour redimensionner ou supprimer un encodeur.</p></body></html> - - - - Encoder - Encodeur - - - - - No encoder selected - Aucun encodeur sélectionné - - - - - Auto - Automatique - - - - Automatic - Encoder - Automatique - - - - A stronger foveation makes the image sharper in the center than in the periphery and makes the decoding faster. This is better for fast paced games. - -A weaker foveation gives a uniform sharpness in the whole image. - -The recommended values are between 20% and 50% for headsets without eye tracking and between 50% and 70% for headsets with eye tracking. - Une fovéation plus forte rend l'image plus nette au centre qu'en périphérie et accélère le décodage. C'est un meilleur choix pour les jeux rapides. - -Une fovéation plus faible donne une netteté uniforme sur toute l'image. - -Les valeurs recommandées sont entre 20% et 50% pour les casques sans suivi des yeux et entre 50% et 70% pour les casques avec suivi des yeux. - - - - Automatic - Au&tomatic - Foveation - Automatique - - - - WiVRn settings - Paramètres de WiVRn - - - - Codec - Codec - - - - Mbit/s - Mbit/s - - - You can use several encoders in order to split the workload between your CPU and your GPU and reduce the latency. - Vous pouvez utiliser plusieurs encodeurs pour partager le travail entre votre CPU et votre GPU et réduire la latence. - - - You can choose a game to be started automatically when the headset connects. - Vous pouvez choisir un jeu à démarrer automatiquement quand le casque est connecté. - - - - Browse - Parcourir - - - - % - % - - - - Wizard - - - Connection wizard - Assistant de connexion - - - - Welcome - Bienvenue - - - - Select your headset - Choisissez votre casque - - - - Getting latest release information... - Récupération de la dernière version... - - - - - Install the WiVRn app on your headset - Installation de l'application WiVRn sur votre casque - - - - You will need to have the WiVRn client installed on your headset. If the client is already installed, click "Skip". - You will need to have the WiVRn client installed on your headset. - Vous aurez besoin d'avoir le client WiVRn installé sur votre casque. Si le client est déjà installé, cliquez sur « Passer ». - - - - I want to sideload the client instead - Je préfère installer le client manuellement - - - - Go to the store to install the client app on your headset. - Allez sur la boutique pour installer l'application client sur votre casque. - - - Once this is done, click "Next". - Once this is done, click next. - Une fois que c'est fait, cliquez sur suivant. - - - - Downloading the WiVRn app - Téléchargement de l'application WiVRn - - - - Cancel - Annuler - - - - Downloading - Téléchargement en cours - - - - Make sure your headset is in developer mode to continue. - Assurez-vous que le casque soit en mode développeur pour continuer. - - - Run the following command to install the client: - Run the following command to install the client - Exécutez la commande suivante pour installer le client: - - - - Copy to clipboard - Copier dans le presse-papier - - - - Start the WiVRn app and connect to this computer - Démarrez l'appli WiVRn et connectez-vous à cet ordinateur - - - - Installing... - Installation en cours... - - - - Use the following PIN to connect your headset: - Utilisez ce code PIN pour connecter votre casque : - - - - If the server is not visible or the connection fails, check that port 5353 (UDP) and 9757 (TCP and UDP) are open in your firewall. - Si le serveur n'est pas visible ou que la connexion échoue, vérifiez que les ports 5353 (UDP) et 9757 (TCP et UDP) sont ouverts dans votre pare-feu. - - - - Finished - Terminé - - - - You can now start an OpenXR application on this computer. - Vous pouvez maintenant démarrer une application OpenXR sur cet ordinateur. - - - - For Steam games, set the launch options to: - For Steam games, set the command to: - Pour les jeux Steam, définir les options de lancement à : - - - - main_window - - - &Show GUI - &Afficher la GUI - - - - &Hide GUI - &Cacher la GUI - - - - &Exit - &Quitter - - - - You have to restart the WiVRn server to use the CAP_SYS_NICE capability. -Do you want to restart it now? - Vous devez redémarrer le serveur WiVRn pour utiliser la capacité CAP_SYS_NICE. -Voulez-vous le redémarrer maintenant? - - - - This will disconnect the currently connected headset. - Cela va déconnecter le casque actuellement connecté. - - - - Restart WiVRn - Redémarrer WiVRn - - - - Cannot start setcap: %1 - Impossible de démarrer setcap: %1 - - - - %1 ⨯ %2 - %1 ⨯ %2 - - - - - %1 Hz - %1 Hz - - - - - - Supported - Supporté - - - - - - Not supported - Non supporté - - - - Left eye: %1° ⨯ %2°, right eye: %3° ⨯ %4° - Œil gauche: %1° ⨯ %2°, œil droit: %3° ⨯ %4° - - - - - %n channel(s), %1 Hz - %1 channel(s), %2 Hz - - %n canal, %1 Hz - %n canaux, %1 Hz - - - - - - N/A - Non disponible - - - - To pair your headset use the following PIN: %1 - Pour connecter votre casque utilisez ce code PIN : %1 - - - - Cannot connect to avahi, make sure avahi-daemon service is started with "disable-user-service-publishing" set to no - Impossible de se connecter à avahi, vérifiez que le service avahi-daemon est démarré avec « disable-user-service-publishing » à « no » - - - - The WiVRn app is not installed on your headset. - L'application WiVRn n'est pas installée sur votre casque. - - - The WiVRn app is not installed on your headset. -Do you want to install it? - L'application WiVRn n'est pas installée sur votre casque. -Voulez-vous l'installer ? - - - WiVRn - WiVRn - - - - Failed to start - Impossible de démarrer - - - - Crashed - Planté - - - - Time out - Délai d'attente dépassé - - - - Read error - Erreur de lecture - - - - Write error - write error - Erreur d'écriture - - - - Unknown error - Erreur inconnue - - - Server error - Erreur du serveur - - - - Failed to start server: -%1 - Impossible de démarrer le serveur: -%1 - - - - Unknown error (%1), check logs - Erreur inconnue (%1), vérifier les logs - - - - No device detected - Aucun périphérique détecté - - - - Start the WiVRn app on your headset and connect to "%1". - Démarrez l'application WiVRn sur votre casque et connectez-vous à « %1 ». - - - - If the server is not visible or the connection fails, check that port 5353 (UDP) and 9757 (TCP and UDP) are open in your firewall. - Si le serveur n'est pas visible ou que la connexion échoue, vérifiez que les ports 5353 (UDP) et 9757 (TCP et UDP) sont ouverts dans votre pare-feu. - - - - Connected - Connecté - - - - Not connected - Non connecté - - - Cannot connect to avahi, make sure avahi-daemon service is started - Cannot connect to avahi, make sure avahi_daemon.service is started - Impossible de se connecter à avahi, vérifiez que le service avahi-daemon est démarré - - - - Insufficient system resources - Ressources système insuffisantes - - - - Server crashed: -%1 - Le serveur a planté: -%1 - - - - Timeout starting server - Délai d'attente dépassé lors du démarrage du serveur - - - - settings - - - Invalid settings - Paramètres invalides - - - - The encoder configuration is invalid, the default values will be restored. - La configuration des encodeurs est invalide, les valeurs par défaut seront restaurées. - - - - None - Game selection combo box - Aucun - - - - Custom... - Game selection combo box - Personnalisé... - - - - Not all headsets and GPUs support AV1 - - Tous les casques et GPUs ne supportent pas AV1 - - - - - Vulkan Video encoder is experimental - - L'encodeur Vulkan Vidéo est expérimental - - - - - Select game - Choisir un jeu - - - - wizard - - - - Download - Télécharger - - - - Other - Autre - - - - This is not a tagged release. - Ce n'est pas une version taguée. - - - - - If you install the headset app from the store, it might not be compatible with this server. - Si vous installez l'application du casque depuis le store, il risque de ne pas être compatible avec ce serveur. - - - - - If you install the headset app manually, this wizard will download the version that matches the dashboard. - Si vous installez l'application du casque manuellement, l'assistant va télécharger la version correspondant au tableau de bord. - - - - This is the latest WiVRn release. - Ceci est la dernière version de WiVRn. - - - - A new release is available (%1 → %2). - Une nouvelle version est disponible (%1 → %2). - - - - Cannot get latest release: %1 - Impossible de récupérer la dernière version: %1 - - - - There is no precompiled APK for this version. - Il n'y a pas d'APK précompilé pour cette version. - - - - Follow the <a href="https://github.com/WiVRn/WiVRn/blob/master/docs/building.md#client-headset"><span style="text-decoration: underline; color:#2980b9;">documentation</span></a> to build your own client. - Suivez la <a href="https://github.com/WiVRn/WiVRn/blob/master/docs/building.md#client-headset"><span style="text-decoration: underline; color:#2980b9;">documentation</span></a> pour compiler votre propre client. - - - - Cannot get APK information: %1 - Impossible de récupérer les informations sur l'APK: %1 - - - - How? - Comment ? - - - - - Skip - Passer - - - - Start the WiVRn app on your headset and connect to "%1". - Démarrez l'application WiVRn sur votre casque et connectez-vous à « %1 ». - - - - No device detected. - Aucun périphérique détecté. - - - - %n device(s) detected. - - %n périphérique détecté. - %n périphériques détectés. - - - - Downloading - Téléchargement en cours - - - Download aborted - Téléchargement annulé - - - WiVRn - WiVRn - - - - Error downloading the client: -%1 - Erreur lors du téléchargement du client : -%1 - - - Download error: %1 - Download error: % - Erreur lors du téléchargement :%1 - - - - The headset is connected. - Le casque est connecté. - - - - The headset is not connected. - Le casque n'est pas connecté. - - - diff --git a/dashboard/wivrn_qdbus_types.h b/dashboard/wivrn_qdbus_types.h deleted file mode 100644 index 2c406b8f..00000000 --- a/dashboard/wivrn_qdbus_types.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -// Same as XrFovf -struct field_of_view -{ - float angleLeft; - float angleRight; - float angleUp; - float angleDown; -}; diff --git a/dashboard/wivrn_server.cpp b/dashboard/wivrn_server.cpp deleted file mode 100644 index c668ce15..00000000 --- a/dashboard/wivrn_server.cpp +++ /dev/null @@ -1,302 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "wivrn_server.h" -#include "wivrn_server_dbus.h" - -Q_DECLARE_METATYPE(field_of_view) - -wivrn_server::wivrn_server(QObject * parent) : - QObject(parent) -{ - dbus_watcher.setConnection(QDBusConnection::sessionBus()); - dbus_watcher.addWatchedService("io.github.wivrn.Server"); - - connect(&dbus_watcher, &QDBusServiceWatcher::serviceRegistered, this, &wivrn_server::on_server_dbus_registered); - connect(&dbus_watcher, &QDBusServiceWatcher::serviceUnregistered, this, &wivrn_server::on_server_dbus_unregistered); - - const QStringList services = QDBusConnection::sessionBus().interface()->registeredServiceNames(); - if (services.contains("io.github.wivrn.Server")) - on_server_dbus_registered(); -} - -wivrn_server::~wivrn_server() -{ -} - -void wivrn_server::on_server_dbus_registered() -{ - if (server_interface) - server_interface->deleteLater(); - if (server_properties_interface) - server_properties_interface->deleteLater(); - - server_interface = new IoGithubWivrnServerInterface("io.github.wivrn.Server", "/io/github/wivrn/Server", QDBusConnection::sessionBus(), this); - server_properties_interface = new OrgFreedesktopDBusPropertiesInterface("io.github.wivrn.Server", "/io/github/wivrn/Server", QDBusConnection::sessionBus(), this); - - connect(server_properties_interface, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, this, &wivrn_server::on_server_properties_changed); - - serverRunningChanged(m_serverRunning = true); - refresh_server_properties(); -} - -void wivrn_server::on_server_dbus_unregistered() -{ - if (server_interface) - server_interface->deleteLater(); - server_interface = nullptr; - - if (server_properties_interface) - server_properties_interface->deleteLater(); - server_properties_interface = nullptr; - - serverRunningChanged(m_serverRunning = false); - - if (isHeadsetConnected()) - headsetConnectedChanged(m_headsetConnected = false); -} - -void wivrn_server::refresh_server_properties() -{ - if (!server_properties_interface) - return; - - QDBusPendingReply props_pending = server_properties_interface->GetAll("io.github.wivrn.Server"); - - if (get_all_properties_call_watcher) - get_all_properties_call_watcher->deleteLater(); - get_all_properties_call_watcher = new QDBusPendingCallWatcher{props_pending, this}; - - connect(get_all_properties_call_watcher, &QDBusPendingCallWatcher::finished, [this, props_pending]() { - on_server_properties_changed("io.github.wivrn.Server", props_pending.value(), {}); - }); -} - -void wivrn_server::on_server_properties_changed(const QString & interface_name, const QVariantMap & changed_properties, const QStringList & invalidated_properties) -{ - if (interface_name != IoGithubWivrnServerInterface::staticInterfaceName()) - return; - - if (changed_properties.contains("HeadsetConnected")) - { - headsetConnectedChanged(m_headsetConnected = changed_properties["HeadsetConnected"].toBool()); - } - - if (changed_properties.contains("JsonConfiguration")) - { - m_jsonConfiguration = changed_properties["JsonConfiguration"].toString(); - } - - if (changed_properties.contains("Pin")) - { - pinChanged(m_pin = changed_properties["Pin"].toString()); - } - - if (changed_properties.contains("KnownKeys")) - { - m_knownKeys.clear(); - - const auto keys = qvariant_cast(changed_properties["KnownKeys"]); - keys.beginArray(); - - while (not keys.atEnd()) - { - keys.beginStructure(); - QString public_key; - QString name; - keys >> name >> public_key; - keys.endStructure(); - - m_knownKeys.push_back(HeadsetKey{public_key, name}); - } - keys.endArray(); - - knownKeysChanged(m_knownKeys); - } - - if (changed_properties.contains("PairingEnabled")) - { - pairingEnabledChanged(m_isPairingEnabled = changed_properties["PairingEnabled"].toBool()); - } - - if (changed_properties.contains("EncryptionEnabled")) - { - encryptionEnabledChanged(m_isEncryptionEnabled = changed_properties["EncryptionEnabled"].toBool()); - } - - if (changed_properties.contains("RecommendedEyeSize")) - { - const auto arg = qvariant_cast(changed_properties["RecommendedEyeSize"]); - - arg.beginStructure(); - arg >> m_recommendedEyeSize.rwidth() >> m_recommendedEyeSize.rheight(); - arg.endStructure(); - recommendedEyeSizeChanged(m_recommendedEyeSize); - } - - if (changed_properties.contains("AvailableRefreshRates")) - { - const auto rates = qvariant_cast(changed_properties["AvailableRefreshRates"]); - - m_availableRefreshRates.clear(); - rates.beginArray(); - while (!rates.atEnd()) - { - double element; - rates >> element; - m_availableRefreshRates.push_back(element); - } - rates.endArray(); - - availableRefreshRatesChanged(m_availableRefreshRates); - } - - if (changed_properties.contains("PreferredRefreshRate")) - { - preferredRefreshRateChanged(m_preferredRefreshRate = changed_properties["PreferredRefreshRate"].toFloat()); - } - - if (changed_properties.contains("EyeGaze")) - { - eyeGazeChanged(m_eyeGaze = changed_properties["EyeGaze"].toBool()); - } - - if (changed_properties.contains("FaceTracking")) - { - faceTrackingChanged(m_faceTracking = changed_properties["FaceTracking"].toBool()); - } - - if (changed_properties.contains("FieldOfView")) - { - const auto fovs = qvariant_cast(changed_properties["FieldOfView"]); - fovs.beginArray(); - - QStringList fov_str; - m_fieldOfView.clear(); - while (!fovs.atEnd()) - { - fovs.beginStructure(); - double left, right, up, down; - fovs >> left >> right >> up >> down; - fovs.endStructure(); - m_fieldOfView.push_back(field_of_view(left, right, up, down)); - } - fovs.endArray(); - - fieldOfViewChanged(m_fieldOfView); - } - - if (changed_properties.contains("HandTracking")) - { - handTrackingChanged(m_handTracking = changed_properties["HandTracking"].toBool()); - } - - if (changed_properties.contains("MicChannels")) - { - micChannelsChanged(m_micChannels = changed_properties["MicChannels"].toInt()); - } - - if (changed_properties.contains("MicSampleRate")) - { - micSampleRateChanged(m_micSampleRate = changed_properties["MicSampleRate"].toInt()); - } - - if (changed_properties.contains("SpeakerChannels")) - { - speakerChannelsChanged(m_speakerChannels = changed_properties["SpeakerChannels"].toInt()); - } - - if (changed_properties.contains("SpeakerSampleRate")) - { - speakerSampleRateChanged(m_speakerSampleRate = changed_properties["SpeakerSampleRate"].toInt()); - } - - if (changed_properties.contains("SupportedCodecs")) - { - supportedCodecsChanged(m_supportedCodecs = changed_properties["SupportedCodecs"].toStringList()); - } - - if (changed_properties.contains("SteamCommand")) - { - steamCommandChanged(m_steamCommand = changed_properties["SteamCommand"].toString()); - } -} - -void wivrn_server::setJsonConfiguration(QString new_configuration) -{ - server_interface->setJsonConfiguration(m_jsonConfiguration = new_configuration); -} - -void wivrn_server::revoke_key(QString public_key) -{ - server_interface->RevokeKey(public_key); -} - -void wivrn_server::rename_key(QString public_key, QString name) -{ - server_interface->RenameKey(public_key, name); -} - -QString wivrn_server::enable_pairing(int timeout_secs) -{ - return server_interface->EnablePairing(timeout_secs).value(); -} - -void wivrn_server::disable_pairing() -{ - server_interface->DisablePairing(); -} - -QString wivrn_server::hostname() -{ - static auto _hostname = []() -> QString { - OrgFreedesktopDBusPropertiesInterface hostname1("org.freedesktop.hostname1", "/org/freedesktop/hostname1", QDBusConnection::systemBus()); - - for (auto property: {"PrettyHostname", "StaticHostname", "Hostname"}) - { - QString name = hostname1.Get("org.freedesktop.hostname1", property).value().variant().toString(); - - if (name != "") - return name; - }; - - char buf[HOST_NAME_MAX]; - int code = gethostname(buf, sizeof(buf)); - if (code == 0) - return buf; - - qDebug() << "Failed to get hostname"; - return "no-hostname"; - }(); - - return _hostname; -} - -void wivrn_server::disconnect_headset() -{ - if (server_interface) - server_interface->Disconnect(); -} - -void wivrn_server::quit() -{ - if (server_interface) - server_interface->Quit(); -} - -#include "moc_wivrn_server.cpp" diff --git a/dashboard/wivrn_server.h b/dashboard/wivrn_server.h deleted file mode 100644 index c24fb194..00000000 --- a/dashboard/wivrn_server.h +++ /dev/null @@ -1,244 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include -#include -#include -#include - -#include "wivrn_qdbus_types.h" - -class IoGithubWivrnServerInterface; -class OrgFreedesktopDBusPropertiesInterface; - -class wivrn_server : public QObject -{ - Q_OBJECT - - IoGithubWivrnServerInterface * server_interface = nullptr; - OrgFreedesktopDBusPropertiesInterface * server_properties_interface = nullptr; - QDBusServiceWatcher dbus_watcher; - QDBusPendingCallWatcher * get_all_properties_call_watcher = nullptr; - -public: - struct HeadsetKey - { - QString public_key; - QString name; - }; - using HeadsetKeys = std::vector; - - wivrn_server(QObject * parent = nullptr); - wivrn_server(const wivrn_server &) = delete; - wivrn_server & operator=(const wivrn_server &) = delete; - ~wivrn_server(); - - // Server information - Q_PROPERTY(bool serverRunning READ isServerRunning NOTIFY serverRunningChanged) - Q_PROPERTY(bool headsetConnected READ isHeadsetConnected NOTIFY headsetConnectedChanged) - Q_PROPERTY(QString jsonConfiguration READ jsonConfiguration WRITE setJsonConfiguration) - - // Authentication - Q_PROPERTY(QString pin READ pin NOTIFY pinChanged) - Q_PROPERTY(HeadsetKeys knownKeys READ knownKeys NOTIFY knownKeysChanged) - Q_PROPERTY(bool pairingEnabled READ isPairingEnabled NOTIFY pairingEnabledChanged) - Q_PROPERTY(bool encryptionEnabled READ isEncryptionEnabled NOTIFY encryptionEnabledChanged) - void revoke_key(QString public_key); - void rename_key(QString public_key, QString name); - QString enable_pairing(int timeout_secs = 120); - void disable_pairing(); - - // Headset information, valid only if HeadsetConnected is true - Q_PROPERTY(QSize recommendedEyeSize READ recommendedEyeSize NOTIFY recommendedEyeSizeChanged) - Q_PROPERTY(std::vector availableRefreshRates READ availableRefreshRates NOTIFY availableRefreshRatesChanged) - Q_PROPERTY(float preferredRefreshRate READ preferredRefreshRate NOTIFY preferredRefreshRateChanged) - Q_PROPERTY(bool eyeGaze READ eyeGaze NOTIFY eyeGazeChanged) - Q_PROPERTY(bool faceTracking READ faceTracking NOTIFY faceTrackingChanged) - Q_PROPERTY(std::vector fieldOfView READ fieldOfView NOTIFY fieldOfViewChanged) - Q_PROPERTY(bool handTracking READ handTracking NOTIFY handTrackingChanged) - Q_PROPERTY(int micChannels READ micChannels NOTIFY micChannelsChanged) - Q_PROPERTY(int micSampleRate READ micSampleRate NOTIFY micSampleRateChanged) - Q_PROPERTY(int speakerChannels READ speakerChannels NOTIFY speakerChannelsChanged) - Q_PROPERTY(int speakerSampleRate READ speakerSampleRate NOTIFY speakerSampleRateChanged) - Q_PROPERTY(QStringList supportedCodecs READ supportedCodecs NOTIFY supportedCodecsChanged) - Q_PROPERTY(QString steamCommand READ steamCommand NOTIFY steamCommandChanged) - - // hostnamed - Q_PROPERTY(QString hostname READ hostname()) - - bool isServerRunning() const - { - return m_serverRunning; - } - - bool isHeadsetConnected() const - { - return m_headsetConnected; - } - - QString jsonConfiguration() const - { - return m_jsonConfiguration; - } - - void setJsonConfiguration(QString); - - QString pin() const - { - return m_pin; - } - - HeadsetKeys knownKeys() const - { - return m_knownKeys; - } - - bool isPairingEnabled() const - { - return m_isPairingEnabled; - } - - bool isEncryptionEnabled() const - { - return m_isEncryptionEnabled; - } - - QSize recommendedEyeSize() const - { - return m_recommendedEyeSize; - } - - const std::vector & availableRefreshRates() const - { - return m_availableRefreshRates; - } - - float preferredRefreshRate() const - { - return m_preferredRefreshRate; - } - - bool eyeGaze() const - { - return m_eyeGaze; - } - - bool faceTracking() const - { - return m_faceTracking; - } - - const std::vector & fieldOfView() const - { - return m_fieldOfView; - } - - bool handTracking() const - { - return m_handTracking; - } - - int micChannels() const - { - return m_micChannels; - } - - int micSampleRate() const - { - return m_micSampleRate; - } - - int speakerChannels() const - { - return m_speakerChannels; - } - - int speakerSampleRate() const - { - return m_speakerSampleRate; - } - - QStringList supportedCodecs() const - { - return m_supportedCodecs; - } - - QString steamCommand() const - { - return m_steamCommand; - } - - QString hostname(); - - void disconnect_headset(); - void quit(); - -private: - void on_server_dbus_registered(); - void on_server_dbus_unregistered(); - void on_server_properties_changed(const QString & interface_name, const QVariantMap & changed_properties, const QStringList & invalidated_properties); - - void refresh_server_properties(); - - bool m_serverRunning{}; - bool m_headsetConnected{}; - QString m_jsonConfiguration{}; - - QString m_pin{}; - HeadsetKeys m_knownKeys; - bool m_isPairingEnabled{}; - bool m_isEncryptionEnabled{}; - - QSize m_recommendedEyeSize{}; - std::vector m_availableRefreshRates{}; - float m_preferredRefreshRate{}; - bool m_eyeGaze{}; - bool m_faceTracking{}; - std::vector m_fieldOfView{}; - bool m_handTracking{}; - int m_micChannels{}; - int m_micSampleRate{}; - int m_speakerChannels{}; - int m_speakerSampleRate{}; - QStringList m_supportedCodecs{}; - QString m_steamCommand{}; - -Q_SIGNALS: - void serverRunningChanged(bool); - void headsetConnectedChanged(bool); - void pinChanged(QString); - void knownKeysChanged(HeadsetKeys); - void pairingEnabledChanged(bool); - void encryptionEnabledChanged(bool); - - void recommendedEyeSizeChanged(QSize); - void availableRefreshRatesChanged(const std::vector &); - void preferredRefreshRateChanged(float); - void eyeGazeChanged(bool); - void faceTrackingChanged(bool); - void fieldOfViewChanged(const std::vector &); - void handTrackingChanged(bool); - void micChannelsChanged(int); - void micSampleRateChanged(int); - void speakerChannelsChanged(int); - void speakerSampleRateChanged(int); - void supportedCodecsChanged(QStringList); - void steamCommandChanged(QString); -}; diff --git a/dashboard/wizard.cpp b/dashboard/wizard.cpp deleted file mode 100644 index c22f476b..00000000 --- a/dashboard/wizard.cpp +++ /dev/null @@ -1,720 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "wizard.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "adb.h" -#include "gui_config.h" -#include "ui_wizard.h" -#include "version.h" -#include "wivrn_server.h" -#include -#include - -using namespace Qt::Literals::StringLiterals; - -enum class wizard_page -{ - select_headset_model, - sideload_download, - sideload_devmode, - sideload_install, - connect_hmd, - start_game -}; - -struct headset -{ - QString name; - QString devmode_url; - QString store_name; - QString store_url; -}; - -static const std::vector headsets_info = { - // clang-format off - {"HTC Vive Focus 3", "https://developer.vive.com/resources/hardware-guides/vive-focus-specs-user-guide/how-do-i-put-focus-developer-mode/"}, - {"HTC Vive XR Elite", "https://developer.vive.com/resources/hardware-guides/vive-focus-specs-user-guide/how-do-i-put-focus-developer-mode/"}, - {"Meta Quest 1", "https://developers.meta.com/horizon/documentation/native/android/mobile-device-setup/#enable-developer-mode"}, - {"Meta Quest 2", "https://developers.meta.com/horizon/documentation/native/android/mobile-device-setup/#enable-developer-mode", "Meta Store", "https://www.meta.com/experiences/7959676140827574/"}, - {"Meta Quest 3", "https://developers.meta.com/horizon/documentation/native/android/mobile-device-setup/#enable-developer-mode", "Meta Store", "https://www.meta.com/experiences/7959676140827574/"}, - {"Meta Quest Pro", "https://developers.meta.com/horizon/documentation/native/android/mobile-device-setup/#enable-developer-mode", "Meta Store", "https://www.meta.com/experiences/7959676140827574/"}, - {"Pico Neo 4", "https://developer.picoxr.com/document/unreal/test-and-build/#Enable%20developer%20mode"}, - // clang-format on -}; - -static constexpr int role_devmode_url = Qt::UserRole + 1; -static constexpr int role_store_name = Qt::UserRole + 2; -static constexpr int role_store_url = Qt::UserRole + 3; - -// #define TEST 1 // Not in the WiVRn-APK repo -// #define TEST 2 // In the WiVRn-APK repo, not a tagged version -// #define TEST 3 // Current version -// #define TEST 4 // Old version - -#if !defined(TEST) || TEST == 0 // Normal case -static const std::string git_version = wivrn::git_version; -static const std::string git_commit = wivrn::git_commit; -#elif TEST == 1 -static const std::string git_version = "v0.19.1-60-g66ce2c5"; -static const std::string git_commit = "66ce2c547dedf9b320af677ed42f32f361b32832"; -#elif TEST == 2 -static const std::string git_version = "v0.19.1-59-g0d62929"; -static const std::string git_commit = "554c0f7ad647d9cd66e380f567f2e842fff6a27a"; -#elif TEST == 3 -static const std::string git_version = "v0.19.1"; -static const std::string git_commit = "bcffadcd4e043d7bacd700b1331c2e98f96ca178"; -#elif TEST == 4 -static const std::string git_version = "v0.19"; -static const std::string git_commit = "d0014823480bc0e54594b74d2475882554ed5829"; -#endif - -wizard::wizard() : - server(new wivrn_server(this)) -{ - ui = new Ui::Wizard; - ui->setupUi(this); - - retranslate(); - - connect(this, &QWizard::currentIdChanged, this, &wizard::on_page_changed); - connect(this, &QWizard::customButtonClicked, this, &wizard::on_custom_button_clicked); - - connect(ui->copy_steam_command, &QPushButton::clicked, this, [&]() { - QGuiApplication::clipboard()->setText(ui->label_steam_command->text()); - }); - - connect(server, &wivrn_server::headsetConnectedChanged, this, &wizard::on_headset_connected_changed); - - connect(ui->button_cancel_download, &QPushButton::clicked, this, &wizard::cancel_download); - - connect(server, &wivrn_server::steamCommandChanged, this, [this](QString value) { - ui->label_steam_command->setText(value); - }); - ui->label_steam_command->setText(server->steamCommand()); - - connect(server, &wivrn_server::pinChanged, this, &wizard::on_pin_changed); - on_pin_changed(server->pin()); - - setPixmap(WatermarkPixmap, QPixmap(":/images/wivrn.svg")); - for (const headset & i: headsets_info) - { - auto item = new QStandardItem(i.name); - - item->setData(i.devmode_url, role_devmode_url); - item->setData(i.store_name, role_store_name); - item->setData(i.store_url, role_store_url); - - headsets.appendRow(item); - } - headsets.appendRow(new QStandardItem(tr("Other"))); // TODO retranslatable - - ui->combo_hmd_model->setModel(&headsets); - ui->combo_hmd_model->setCurrentIndex(-1); - connect(ui->combo_hmd_model, &QComboBox::currentIndexChanged, this, &wizard::update_welcome_page); - connect(ui->check_sideload, &QCheckBox::clicked, this, &wizard::update_welcome_page); - - setWindowModality(Qt::WindowModality::ApplicationModal); - - if (std::regex_match(git_version, std::regex(".*-g[0-9a-f]+"))) - { - apk_file.setFileName(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/wivrn-" + QString::fromStdString(git_commit) + ".apk"); - - qDebug() << "Not a tagged version" << git_version.c_str(); - - ui->label_release_info->setText( - tr("This is not a tagged release.") + - "\n" + - tr("If you install the headset app from the store, it might not be compatible with this server.") + - "\n" + - tr("If you install the headset app manually, this wizard will download the version that matches the dashboard.")); - - std::string url = "https://api.github.com/repos/WiVRn/WiVRn-APK/releases/tags/apk-" + git_commit; - qDebug() << "Downloading metadata from" << url.c_str(); - - apk_release_reply = manager.get(QNetworkRequest{QUrl{url.c_str()}}); - connect(apk_release_reply, &QNetworkReply::finished, this, &wizard::on_apk_release_finished); - } - else - { - apk_file.setFileName(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/wivrn-" + QString::fromStdString(git_version) + ".apk"); - - qDebug() << "Tagged version" << git_version.c_str(); - - // Get the current release information - std::string url = "https://api.github.com/repos/WiVRn/WiVRn/releases/tags/" + git_version; - qDebug() << "Downloading metadata from" << url.c_str(); - apk_release_reply = manager.get(QNetworkRequest{QUrl{url.c_str()}}); - connect(apk_release_reply, &QNetworkReply::finished, this, &wizard::on_apk_release_finished); - - // Get the latest release information - latest_release_reply = manager.get(QNetworkRequest{QUrl{"https://api.github.com/repos/WiVRn/WiVRn/releases/latest"}}); - connect(latest_release_reply, &QNetworkReply::finished, this, &wizard::on_latest_release_finished); - } - - // Detect connected android devices - connect(&adb_service, &adb::android_devices_changed, this, &wizard::on_android_device_list_changed); - on_android_device_list_changed(adb_service.devices()); - - connect(ui->list_devices, &QListWidget::itemSelectionChanged, this, &wizard::on_selected_android_device_changed); -} - -void wizard::on_latest_release_finished() -{ - disconnect(latest_release_reply, &QNetworkReply::finished, this, &wizard::on_latest_release_finished); - - // By default, assume this is the latest release - latest_release = git_version; - - try - { - if (latest_release_reply->error()) - throw std::runtime_error(latest_release_reply->errorString().toStdString()); - - auto json = nlohmann::json::parse(latest_release_reply->readAll()); - - latest_release = json["tag_name"]; - - if (latest_release == git_version) - { - // This is already the latest release - ui->label_release_info->setText(tr("This is the latest WiVRn release.")); - } - else - { - ui->label_release_info->setText( - tr("A new release is available (%1 → %2).").arg(QString::fromLatin1(git_version)).arg(QString::fromLatin1(latest_release)) + - "\n" + - tr("If you install the headset app from the store, it might not be compatible with this server.") + - "\n" + - tr("If you install the headset app manually, this wizard will download the version that matches the dashboard.")); - } - } - catch (std::exception & e) - { - qWarning() << "Cannot get latest release: " << e.what(); - ui->label_release_info->setText(tr("Cannot get latest release: %1").arg(e.what())); - } - - latest_release_reply->deleteLater(); - latest_release_reply = nullptr; - update_welcome_page(); -} - -void wizard::on_apk_release_finished() -{ - disconnect(apk_release_reply, &QNetworkReply::finished, this, &wizard::on_apk_release_finished); - - try - { - auto error = apk_release_reply->error(); - - if (error == QNetworkReply::NetworkError::ContentNotFoundError) - { - ui->label_release_info->setText( - "

" + - tr("There is no precompiled APK for this version.") + - "

\n

" + - tr("Follow the documentation to build your own client.") + - "

"); - - ui->combo_hmd_model->setEnabled(false); - ui->combo_hmd_model->setCurrentIndex(-1); - ui->check_sideload->setEnabled(false); - } - else if (error != QNetworkReply::NetworkError::NoError) - { - throw std::runtime_error(apk_release_reply->errorString().toStdString()); - } - else - { - auto json = nlohmann::json::parse(apk_release_reply->readAll()); - - for (auto & i: json["assets"]) - { - std::string name = i["name"]; - - if (name.ends_with("-standard-release.apk")) - { - apk_url = i["browser_download_url"]; - qDebug() << "Using APK URL" << apk_url.c_str(); - break; - } - } - - apk_downloaded = QFileInfo(apk_file).exists(); - } - } - catch (std::exception & e) - { - qWarning() << "Cannot get APK information: " << e.what(); - ui->label_release_info->setText(tr("Cannot get APK information: %1").arg(e.what())); - } - - apk_release_reply->deleteLater(); - apk_release_reply = nullptr; - update_welcome_page(); -} - -void wizard::update_welcome_page() -{ - if (latest_release == "") - { - // We don't have the latest release information yet - ui->widget_store->setVisible(false); - ui->check_sideload->setVisible(false); - button(NextButton)->setEnabled(false); - } - - auto devmode_url = ui->combo_hmd_model->currentData(role_devmode_url).toString(); - auto store_name = ui->combo_hmd_model->currentData(role_store_name).toString(); - auto store_url = ui->combo_hmd_model->currentData(role_store_url).toString(); - - ui->label_store_url->setText(QString(R"(

%2

)").arg(store_url).arg(store_name)); - ui->label_devmode_url->setText(QString(R"(

%2

)").arg(devmode_url).arg(tr("How?"))); - - if (ui->combo_hmd_model->currentIndex() < 0) - { - // No headset selected - ui->widget_store->setVisible(false); - ui->check_sideload->setVisible(false); - button(NextButton)->setEnabled(false); - } - else if (store_name != "") - { - // Headset with a link to a store - ui->widget_store->setVisible(not ui->check_sideload->isChecked()); - ui->check_sideload->setVisible(true); - button(NextButton)->setEnabled(apk_url != "" or nextId() != (int)wizard_page::sideload_download); - } - else - { - // Headset without store - ui->widget_store->setVisible(false); - ui->check_sideload->setVisible(false); - button(NextButton)->setEnabled(apk_url != ""); - } - - ui->label_devmode_url->setVisible(devmode_url != ""); - - if (nextId() == (int)wizard_page::sideload_download and ui->combo_hmd_model->currentIndex() >= 0 and apk_url != "") - button(NextButton)->setText(tr("Download")); - else - button(NextButton)->setText(QWizard::tr("&Next >", "do not translate, the QWizard translation will be used")); -} - -void wizard::on_custom_button_clicked(int which) -{ - switch ((wizard_page)currentId()) - { - case wizard_page::select_headset_model: - if (which == QWizard::CustomButton1) // Download - next(); - else if (which == QWizard::CustomButton2) // Skip - setCurrentId((int)wizard_page::connect_hmd); - return; - - case wizard_page::sideload_download: - return; - - case wizard_page::sideload_devmode: - return; - - case wizard_page::sideload_install: - return; - - case wizard_page::connect_hmd: - if (which == QWizard::CustomButton1) // Skip - next(); - return; - - case wizard_page::start_game: - return; - } -} - -void wizard::on_page_changed(int id) -{ - switch ((wizard_page)id) - { - case wizard_page::select_headset_model: - button(WizardButton::CustomButton1)->setText(tr("Download")); - button(WizardButton::CustomButton2)->setText(tr("Skip")); - - setButtonLayout({QWizard::Stretch, QWizard::BackButton, QWizard::NextButton, QWizard::CustomButton2, QWizard::CancelButton}); - update_welcome_page(); - return; - - case wizard_page::sideload_download: - assert(not apk_downloaded); - start_download(); - - setButtonLayout({QWizard::Stretch, QWizard::BackButton, QWizard::NextButton, QWizard::CancelButton}); - button(BackButton)->setEnabled(false); - button(NextButton)->setEnabled(false); - return; - - case wizard_page::sideload_devmode: - setButtonLayout({QWizard::Stretch, QWizard::BackButton, QWizard::NextButton, QWizard::CancelButton}); - button(NextButton)->setEnabled(false); - return; - - case wizard_page::sideload_install: - start_install(); - setButtonLayout({QWizard::Stretch, QWizard::BackButton, QWizard::NextButton, QWizard::CancelButton}); - button(BackButton)->setEnabled(false); - button(NextButton)->setEnabled(false); - return; - - case wizard_page::connect_hmd: - button(WizardButton::CustomButton1)->setText(tr("Skip")); - setButtonLayout({QWizard::Stretch, QWizard::BackButton, QWizard::NextButton, QWizard::CustomButton1, QWizard::CancelButton}); - on_headset_connected_changed(server->isHeadsetConnected()); - - if (not server->isPairingEnabled()) - server->enable_pairing(-1); - - return; - - case wizard_page::start_game: - setButtonLayout({QWizard::Stretch, QWizard::BackButton, QWizard::FinishButton, QWizard::CancelButton}); - return; - } -} - -void wizard::changeEvent(QEvent * e) -{ - QWidget::changeEvent(e); - - switch (e->type()) - { - case QEvent::LanguageChange: - retranslate(); - break; - - default: - break; - } -} - -int wizard::nextId() const -{ - switch ((wizard_page)currentId()) - { - case wizard_page::select_headset_model: - if (ui->combo_hmd_model->currentData(role_store_name).toString() != "" and not ui->check_sideload->isChecked()) - return (int)wizard_page::connect_hmd; - else if (apk_downloaded) - return (int)wizard_page::sideload_devmode; - else - return (int)wizard_page::sideload_download; - - case wizard_page::sideload_install: - return (int)wizard_page::connect_hmd; - - default: - return QWizard::nextId(); - } -} - -void wizard::retranslate() -{ - ui->retranslateUi(this); - ui->label_how_to_connect->setText(tr("Start the WiVRn app on your headset and connect to \"%1\".").arg(server->hostname())); - on_headset_connected_changed(server->isHeadsetConnected()); -} - -wizard::~wizard() -{ - server->disable_pairing(); - - // android_devices_changed can be emitted when adb_service is destroyed, disconnect it before destroying - // the GUI - disconnect(&adb_service, &adb::android_devices_changed, this, &wizard::on_android_device_list_changed); - - delete ui; - ui = nullptr; -} - -void wizard::start_download() -{ - ui->button_cancel_download->setEnabled(true); - - QUrl url(apk_url.c_str()); - - qDebug() << "Downloading from" << url.toString(); - - auto apk_dir = std::filesystem::path(apk_file.fileName().toStdString()).parent_path(); - std::filesystem::create_directories(apk_dir); - - apk_file.open(QIODeviceBase::WriteOnly | QIODeviceBase::Truncate); - - QNetworkRequest request(url); - - if (apk_reply) - { - disconnect(apk_reply, &QNetworkReply::downloadProgress, this, &wizard::on_download_progress); - disconnect(apk_reply, &QNetworkReply::errorOccurred, this, &wizard::on_download_error); - disconnect(apk_reply, &QNetworkReply::finished, this, &wizard::on_download_finished); - apk_reply->abort(); - apk_reply->deleteLater(); - } - - apk_reply = manager.get(request); - - connect(apk_reply, &QNetworkReply::downloadProgress, this, &wizard::on_download_progress); - connect(apk_reply, &QNetworkReply::errorOccurred, this, &wizard::on_download_error); - connect(apk_reply, &QNetworkReply::finished, this, &wizard::on_download_finished); - - ui->progress_download->setValue(0); -} - -void wizard::cancel_download() -{ - assert(apk_reply); - - disconnect(apk_reply, &QNetworkReply::downloadProgress, this, &wizard::on_download_progress); - disconnect(apk_reply, &QNetworkReply::errorOccurred, this, &wizard::on_download_error); - disconnect(apk_reply, &QNetworkReply::finished, this, &wizard::on_download_finished); - apk_reply->abort(); - apk_reply->deleteLater(); - apk_reply = nullptr; - - // Cancel and commit to close without saving the already written data, so that it can be reopened - apk_file.cancelWriting(); - apk_file.commit(); - - back(); -} - -void wizard::on_download_progress(qint64 bytesReceived, qint64 bytesTotal) -{ - assert(apk_reply); - - if (not apk_reply->error()) - { - if (bytesTotal > 0) - ui->progress_download->setValue(bytesReceived * 100 / bytesTotal); - - apk_file.write(apk_reply->readAll()); - } -} - -void wizard::on_download_error(QNetworkReply::NetworkError code) -{ - qDebug() << "Download error" << code; - - // Cancel and commit to close without saving the already written data, so that it can be reopened - apk_file.cancelWriting(); - apk_file.commit(); - - QMessageBox msgbox /*(this)*/; - msgbox.setIcon(QMessageBox::Critical); - msgbox.setText(tr("Error downloading the client:\n%1").arg(apk_reply->errorString())); - msgbox.setStandardButtons(QMessageBox::Retry | QMessageBox::Cancel); - -#ifdef WORKAROUND_QTBUG_90005 - setEnabled(false); -#endif - - switch (msgbox.exec()) - { - case QMessageBox::Retry: - start_download(); - break; - - case QMessageBox::Cancel: - back(); - break; - } - -#ifdef WORKAROUND_QTBUG_90005 - setEnabled(true); -#endif -} - -void wizard::on_download_finished() -{ - assert(apk_reply); - - if (not apk_reply->error()) - { - auto last_modified = apk_reply->header(QNetworkRequest::LastModifiedHeader).value(); - apk_file.setFileTime(last_modified, QFileDevice::FileModificationTime); - - apk_reply->deleteLater(); - apk_reply = nullptr; - - ui->button_cancel_download->setEnabled(false); - apk_file.commit(); - apk_downloaded = true; - - back(); // Remove current page from history before going to the install page - setCurrentId((int)wizard_page::sideload_devmode); - } -} - -void wizard::on_android_device_list_changed(const std::vector & new_devs) -{ - auto old_devs = std::move(android_devices); - android_devices = new_devs; - - if (android_devices.empty()) - ui->label_device_detected->setText(tr("No device detected.")); - else - ui->label_device_detected->setText(tr("%n device(s) detected.", nullptr, android_devices.size())); - - // Removed devices - for (int i = 0; i < ui->list_devices->count();) - { - QListWidgetItem * item = ui->list_devices->item(i); - - std::string serial = item->data(QListWidgetItem::UserType).toString().toStdString(); - - if (std::ranges::none_of(android_devices, [&](const adb::device & x) { return x.serial() == serial; })) - delete item; - else - i++; - } - - // Added devices - for (const auto & i: android_devices) - { - if (std::ranges::none_of(old_devs, [&](const adb::device & x) { return x == i; })) - { - auto it = i.properties().find("model"); - - const std::string model = (it == i.properties().end()) ? "Unknown model (" + i.serial() + ")" : it->second; - - QListWidgetItem * item = new QListWidgetItem(QString::fromStdString(model)); - - item->setData(QListWidgetItem::UserType, QString::fromStdString(i.serial())); - - ui->list_devices->addItem(item); - } - } -} - -void wizard::on_selected_android_device_changed() -{ - if (ui->list_devices->currentItem()) - button(NextButton)->setEnabled(true); - else - button(NextButton)->setEnabled(false); -} - -void wizard::start_install() -{ - QListWidgetItem * item = ui->list_devices->currentItem(); - - if (not item) - { - back(); - return; - } - - const std::string serial = item->data(QListWidgetItem::UserType).toString().toStdString(); - - for (adb::device & i: android_devices) - { - if (i.serial() == serial) - { - process_adb_install = i.install(apk_file.fileName().toStdString()); - - connect(process_adb_install.get(), &QProcess::finished, this, &wizard::on_install_finished); - connect(process_adb_install.get(), &QProcess::readyReadStandardOutput, this, &wizard::on_install_stdout); - connect(process_adb_install.get(), &QProcess::readyReadStandardError, this, &wizard::on_install_stderr); - process_adb_install->setParent(this); - process_adb_install->start(); - ui->adb_install_logs->setPlainText(""); - break; - } - } -} - -void wizard::on_install_stdout() -{ - ui->adb_install_logs->appendPlainText(process_adb_install->readAllStandardOutput()); - ui->adb_install_logs->verticalScrollBar()->setValue(ui->adb_install_logs->verticalScrollBar()->maximum()); -} - -void wizard::on_install_stderr() -{ - ui->adb_install_logs->appendPlainText(process_adb_install->readAllStandardError()); - ui->adb_install_logs->verticalScrollBar()->setValue(ui->adb_install_logs->verticalScrollBar()->maximum()); -} - -void wizard::on_install_finished(int exit_code, QProcess::ExitStatus exit_status) -{ - if (exit_code == 0 and exit_status == QProcess::NormalExit) - { - // back(); // Remove current page from history before going to the connect page - // setCurrentId((int)wizard_page::connect_hmd); - - button(NextButton)->setEnabled(true); - } -} - -void wizard::on_headset_connected_changed(bool connected) -{ - if (currentId() == (int)wizard_page::connect_hmd) - { - if (connected) - ui->label_client_status->setText(tr("The headset is connected.")); - else - ui->label_client_status->setText(tr("The headset is not connected.")); - - button(NextButton)->setEnabled(connected); - ui->widget_troubleshoot->setHidden(connected); - } -} - -void wizard::on_pin_changed(QString pin) -{ - if (pin == "") - { - ui->label_pin_1->setVisible(false); - ui->label_pin_2->setVisible(false); - } - else - { - ui->label_pin_1->setVisible(true); - ui->label_pin_2->setVisible(true); - } - - ui->label_pin_2->setText(pin); -} - -#include "moc_wizard.cpp" diff --git a/dashboard/wizard.h b/dashboard/wizard.h deleted file mode 100644 index f515edb3..00000000 --- a/dashboard/wizard.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include "adb.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Ui -{ -class Wizard; -} - -class wivrn_server; - -class wizard : public QWizard -{ - Q_OBJECT - - Ui::Wizard * ui = nullptr; - QStandardItemModel headsets; - - wivrn_server * server; - - QSettings settings; - QNetworkAccessManager manager; - - // Used to download the APK - QNetworkReply * apk_reply = nullptr; - - // Used to query the latest release on github - QNetworkReply * latest_release_reply = nullptr; - - // Used to get the info about the current version on github, either from the WiVRn or the WiVRn-APK repo - QNetworkReply * apk_release_reply = nullptr; - - QSaveFile apk_file; - std::string apk_url; - bool apk_downloaded = false; - - std::string latest_release; - - adb adb_service; - - std::vector android_devices; - std::unique_ptr process_adb_install; - -public: - wizard(); - ~wizard(); - - void changeEvent(QEvent * e) override; - void retranslate(); - - int nextId() const override; - - void on_page_changed(int id); - - void start_download(); - void cancel_download(); - void on_download_progress(qint64 bytesReceived, qint64 bytesTotal); - void on_download_error(QNetworkReply::NetworkError code); - void on_download_finished(); - - void on_android_device_list_changed(const std::vector &); - void on_selected_android_device_changed(); - - void start_install(); - void on_install_finished(int exit_code, QProcess::ExitStatus exit_status); - void on_install_stdout(); - void on_install_stderr(); - - void on_latest_release_finished(); - void on_apk_release_finished(); - - void update_welcome_page(); - void on_headset_connected_changed(bool); - void on_custom_button_clicked(int which); - - void on_pin_changed(QString pin); -}; diff --git a/dashboard/wizard.ui b/dashboard/wizard.ui deleted file mode 100644 index 2b7734b9..00000000 --- a/dashboard/wizard.ui +++ /dev/null @@ -1,588 +0,0 @@ - - - Wizard - - - - 0 - 0 - 846 - 586 - - - - Connection wizard - - - true - - - - Welcome - - - - - - - - - Qt::Orientation::Vertical - - - QSizePolicy::Policy::Fixed - - - - 20 - 40 - - - - - - - - You will need to have the WiVRn client installed on your headset. If the client is already installed, click "Skip". - - - true - - - - - - - - - -1 - - - Select your headset - - - - - - - Qt::Orientation::Horizontal - - - - 40 - 20 - - - - - - - - - - Getting latest release information... - - - true - - - true - - - - - - - I want to sideload the client instead - - - - - - - - 0 - - - 0 - - - - - - - Go to the store to install the client app on your headset. - - - true - - - true - - - - - - - store_url - - - Qt::TextFormat::RichText - - - true - - - - - - - - - - - - Qt::Orientation::Vertical - - - - 20 - 40 - - - - - - - - - Downloading the WiVRn app - - - - - - - - - Qt::Orientation::Vertical - - - QSizePolicy::Policy::Fixed - - - - 20 - 40 - - - - - - - - - - 0 - - - - - - - Cancel - - - - - - - - - Downloading - - - - - - - Qt::Orientation::Vertical - - - - 20 - 40 - - - - - - - - - Install the WiVRn app on your headset - - - - - - - - - Qt::Orientation::Vertical - - - QSizePolicy::Policy::Fixed - - - - 20 - 40 - - - - - - - - - - Make sure your headset is in developer mode to continue. - - - true - - - - - - - devmode_url - - - Qt::TextFormat::RichText - - - true - - - - - - - - - Qt::Orientation::Vertical - - - QSizePolicy::Policy::Fixed - - - - 20 - 20 - - - - - - - - label_device_detected - - - - - - - Qt::Orientation::Vertical - - - QSizePolicy::Policy::Fixed - - - - 20 - 20 - - - - - - - - - - - - Install the WiVRn app on your headset - - - - - - Qt::Orientation::Vertical - - - QSizePolicy::Policy::Fixed - - - - 20 - 40 - - - - - - - - Installing... - - - - - - - Qt::Orientation::Vertical - - - QSizePolicy::Policy::Fixed - - - - 20 - 20 - - - - - - - - - Noto Sans Mono - - - - true - - - - - - - - - - - Start the WiVRn app and connect to this computer - - - - - - - - - Qt::Orientation::Vertical - - - QSizePolicy::Policy::Fixed - - - - 20 - 40 - - - - - - - - client_status - - - true - - - - - - - Qt::Orientation::Vertical - - - QSizePolicy::Policy::Fixed - - - - 20 - 40 - - - - - - - - - 0 - - - 0 - - - - - connect_to_this_server - - - - - - - Use the following PIN to connect your headset: - - - - - - - - 14 - - - - 000000 - - - 12 - - - - - - - If the server is not visible or the connection fails, check that port 5353 (UDP) and 9757 (TCP and UDP) are open in your firewall. - - - true - - - - - - - - - - Qt::Orientation::Vertical - - - - 20 - 40 - - - - - - - - - Finished - - - - - - - - - Qt::Orientation::Vertical - - - QSizePolicy::Policy::Fixed - - - - 20 - 40 - - - - - - - - You can now start an OpenXR application on this computer. - - - - - - - For Steam games, set the launch options to: - - - Qt::TextFormat::PlainText - - - true - - - Qt::TextInteractionFlag::NoTextInteraction - - - - - - - - - Copy to clipboard - - - - - - - - - - - - - IBeamCursor - - - steam_command - - - Qt::TextInteractionFlag::NoTextInteraction - - - - - - - - - Qt::Orientation::Vertical - - - - 20 - 40 - - - - - - - - - -