From bac0f9cbb2d366114e89fa27ae6ae461e125fba8 Mon Sep 17 00:00:00 2001
From: Guillaume Meunier
Date: Sat, 7 Dec 2024 21:48:34 +0100
Subject: [PATCH] Added QML dashboard
---
CMakeLists.txt | 8 +-
CMakePresets.json | 6 +-
README.md | 1 +
dashboard/CMakeLists.txt | 103 ++
dashboard/adb.cpp | 323 +++++++
dashboard/adb.h | 86 ++
dashboard/apk_installer.cpp | 254 +++++
dashboard/apk_installer.h | 130 +++
dashboard/dashboard-qml/.gitignore | 2 +
dashboard/escape_sandbox.h | 58 ++
dashboard/escape_string.cpp | 107 +++
dashboard/escape_string.h | 26 +
dashboard/gui_config.h.in | 27 +
dashboard/io.github.wivrn.wivrn.desktop.in | 8 +
dashboard/io.github.wivrn.wivrn.metainfo.xml | 150 +++
dashboard/main.cpp | 51 +
dashboard/qml/ApkInstallPage.qml | 56 ++
dashboard/qml/BetterLabel.qml | 14 +
dashboard/qml/ConnectUsbDialog.qml | 80 ++
dashboard/qml/DeviceCard.qml | 104 +++
dashboard/qml/HeadsetStatsPage.qml | 46 +
dashboard/qml/HeadsetsPage.qml | 180 ++++
dashboard/qml/Main.qml | 335 +++++++
dashboard/qml/SelectGame.qml | 131 +++
dashboard/qml/SettingsPage.qml | 363 +++++++
dashboard/qml/SteamLaunchOptions.qml | 34 +
dashboard/qml/WizardPage.qml | 531 +++++++++++
dashboard/qml/WizardStep.qml | 30 +
dashboard/rectangle_partitionner.cpp | 21 +
dashboard/rectangle_partitionner.h | 935 +++++++++++++++++++
dashboard/settings.cpp | 321 +++++++
dashboard/settings.h | 150 +++
dashboard/steam_apps.cpp | 112 +++
dashboard/steam_apps.h | 108 +++
dashboard/vulkan_info.cpp | 74 ++
dashboard/vulkan_info.h | 65 ++
dashboard/wivrn_qdbus_types.cpp | 3 +
dashboard/wivrn_qdbus_types.h | 60 ++
dashboard/wivrn_server.cpp | 532 +++++++++++
dashboard/wivrn_server.h | 312 +++++++
flatpak/io.github.wivrn.wivrn.yml.in | 1 +
tools/check_messages.sh | 63 +-
tools/update_messages.sh | 36 +-
43 files changed, 6000 insertions(+), 37 deletions(-)
create mode 100644 dashboard/CMakeLists.txt
create mode 100644 dashboard/adb.cpp
create mode 100644 dashboard/adb.h
create mode 100644 dashboard/apk_installer.cpp
create mode 100644 dashboard/apk_installer.h
create mode 100644 dashboard/dashboard-qml/.gitignore
create mode 100644 dashboard/escape_sandbox.h
create mode 100644 dashboard/escape_string.cpp
create mode 100644 dashboard/escape_string.h
create mode 100644 dashboard/gui_config.h.in
create mode 100644 dashboard/io.github.wivrn.wivrn.desktop.in
create mode 100644 dashboard/io.github.wivrn.wivrn.metainfo.xml
create mode 100644 dashboard/main.cpp
create mode 100644 dashboard/qml/ApkInstallPage.qml
create mode 100644 dashboard/qml/BetterLabel.qml
create mode 100644 dashboard/qml/ConnectUsbDialog.qml
create mode 100644 dashboard/qml/DeviceCard.qml
create mode 100644 dashboard/qml/HeadsetStatsPage.qml
create mode 100644 dashboard/qml/HeadsetsPage.qml
create mode 100644 dashboard/qml/Main.qml
create mode 100644 dashboard/qml/SelectGame.qml
create mode 100644 dashboard/qml/SettingsPage.qml
create mode 100644 dashboard/qml/SteamLaunchOptions.qml
create mode 100644 dashboard/qml/WizardPage.qml
create mode 100644 dashboard/qml/WizardStep.qml
create mode 100644 dashboard/rectangle_partitionner.cpp
create mode 100644 dashboard/rectangle_partitionner.h
create mode 100644 dashboard/settings.cpp
create mode 100644 dashboard/settings.h
create mode 100644 dashboard/steam_apps.cpp
create mode 100644 dashboard/steam_apps.h
create mode 100644 dashboard/vulkan_info.cpp
create mode 100644 dashboard/vulkan_info.h
create mode 100644 dashboard/wivrn_qdbus_types.cpp
create mode 100644 dashboard/wivrn_qdbus_types.h
create mode 100644 dashboard/wivrn_server.cpp
create mode 100644 dashboard/wivrn_server.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dba07537..fcc337dc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -181,8 +181,12 @@ if (WIVRN_BUILD_SERVER)
endif()
if (WIVRN_BUILD_DASHBOARD)
- find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets DBus Network LinguistTools)
+ find_package(Qt6 REQUIRED COMPONENTS Core Quick QuickControls2 Gui Widgets DBus Network LinguistTools)
find_package(nlohmann_json REQUIRED)
+ find_package(QCoro6 REQUIRED COMPONENTS Core Network Qml)
+ find_package(KF6Kirigami)
+ qcoro_enable_coroutines()
+
if (WIVRN_CHECK_CAPSYSNICE)
pkg_check_modules(libcap REQUIRED IMPORTED_TARGET libcap)
endif()
@@ -194,10 +198,10 @@ endif()
if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_DASHBOARD)
find_program(RSVG_CONVERT rsvg-convert REQUIRED)
+ find_package(Gettext REQUIRED)
endif()
if (WIVRN_BUILD_CLIENT)
- find_package(Gettext REQUIRED)
if (WIVRN_USE_LIBKTX STREQUAL "AUTO")
if (ANDROID)
set(WIVRN_USE_LIBKTX ON)
diff --git a/CMakePresets.json b/CMakePresets.json
index 617c5705..d0a4b15b 100644
--- a/CMakePresets.json
+++ b/CMakePresets.json
@@ -39,7 +39,8 @@
"WIVRN_BUILD_SERVER": "ON",
"WIVRN_BUILD_WIVRNCTL": "ON",
"WIVRN_BUILD_DASHBOARD": "ON",
- "WIVRN_BUILD_DISSECTOR": "ON"
+ "WIVRN_BUILD_DISSECTOR": "ON",
+ "QT_QML_GENERATE_QMLLS_INI": "ON"
}
},
{
@@ -67,7 +68,8 @@
"inherits": "base",
"binaryDir": "${sourceDir}/build-dashboard",
"cacheVariables": {
- "WIVRN_BUILD_DASHBOARD": "ON"
+ "WIVRN_BUILD_DASHBOARD": "ON",
+ "QT_QML_GENERATE_QMLLS_INI": "ON"
}
},
{
diff --git a/README.md b/README.md
index 200f12d7..731a9434 100644
--- a/README.md
+++ b/README.md
@@ -139,6 +139,7 @@ WiVRn uses the following software:
- [HarfBuzz](https://harfbuzz.github.io/)
- [Monado](https://monado.freedesktop.org/)
- [nvenc](https://developer.nvidia.com/nvidia-video-codec-sdk) optional, for hardware encoding on Nvidia
+- [qCoro](https://qcoro.dev/)
- [Qt 6](https://www.qt.io/) optional, for the dashboard
- [spdlog](https://github.com/gabime/spdlog)
- [VulkanMemoryAllocator](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator)
diff --git a/dashboard/CMakeLists.txt b/dashboard/CMakeLists.txt
new file mode 100644
index 00000000..41348aa0
--- /dev/null
+++ b/dashboard/CMakeLists.txt
@@ -0,0 +1,103 @@
+# cmake_minimum_required(VERSION 3.20)
+# project(kirigami-tutorial)
+
+find_package(ECM 5.115 REQUIRED NO_MODULE)
+list(APPEND CMAKE_MODULE_PATH "${ECM_MODULE_PATH}")
+
+include(KDEInstallDirs)
+include(KDECMakeSettings)
+# include(KDECompilerSettings NO_POLICY_SCOPE)
+include(ECMFindQmlModule)
+include(ECMQmlModule)
+
+find_package(Qt6 REQUIRED COMPONENTS
+ Core
+ Quick
+ Test
+ Gui
+ QuickControls2
+ Widgets
+)
+
+find_package(KF6 REQUIRED COMPONENTS
+ Kirigami
+ I18n
+ CoreAddons
+ QQC2DesktopStyle
+ IconThemes
+)
+
+ecm_find_qmlmodule(org.kde.kirigami REQUIRED)
+
+
+add_executable(wivrn-dashboard
+ main.cpp
+ wivrn_server.cpp
+ wivrn_qdbus_types.cpp
+ steam_apps.cpp
+ escape_string.cpp
+ settings.cpp
+ rectangle_partitionner.cpp
+ adb.cpp
+ apk_installer.cpp
+ vulkan_info.cpp
+)
+
+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})
+
+set_source_files_properties(../images/wivrn.svg PROPERTIES QT_RESOURCE_ALIAS qml/wivrn.svg)
+
+qt_add_qml_module(wivrn-dashboard
+ URI io.github.wivrn.wivrn
+ QML_FILES
+ qml/Main.qml
+ qml/ApkInstallPage.qml
+ qml/SettingsPage.qml
+ qml/HeadsetsPage.qml
+ qml/HeadsetStatsPage.qml
+ qml/WizardPage.qml
+ qml/WizardStep.qml
+ qml/DeviceCard.qml
+ qml/BetterLabel.qml
+ qml/ConnectUsbDialog.qml
+ qml/SelectGame.qml
+ qml/SteamLaunchOptions.qml
+ RESOURCES
+ ../images/wivrn.svg
+)
+
+
+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::DBus
+ Qt6::Quick
+ Qt6::Qml
+ Qt6::Gui
+ Qt6::QuickControls2
+ Qt6::Widgets
+ KF6::I18n
+ KF6::CoreAddons
+ KF6::IconThemes
+ KF6::Kirigami
+ QCoro::Core
+ QCoro::Network
+ QCoro::Qml
+ wivrn-common-base
+ wivrn-external
+)
+
+if (WIVRN_CHECK_CAPSYSNICE)
+ target_link_libraries(wivrn-dashboard PRIVATE PkgConfig::libcap)
+endif()
+
+install(TARGETS wivrn-dashboard ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
+ki18n_install(${CMAKE_CURRENT_SOURCE_DIR}/../locale)
+
+# install(PROGRAMS org.kde.tutorial.desktop DESTINATION ${KDE_INSTALL_APPDIR})
+
+# feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
diff --git a/dashboard/adb.cpp b/dashboard/adb.cpp
new file mode 100644
index 00000000..e74de2af
--- /dev/null
+++ b/dashboard/adb.cpp
@@ -0,0 +1,323 @@
+/*
+ * 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 "escape_sandbox.h"
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace std::chrono_literals;
+
+adb::adb()
+{
+ QTimer::singleShot(0, this, &adb::checkIfAdbIsInstalled);
+}
+
+QCoro::Task<> adb::checkIfAdbIsInstalled()
+{
+ auto which_adb = escape_sandbox("which", "adb");
+ which_adb->setProcessChannelMode(QProcess::ForwardedErrorChannel);
+ auto co_which_adb = qCoro(*which_adb);
+
+ co_await co_which_adb.start();
+ co_await co_which_adb.waitForFinished();
+
+ if (which_adb->exitStatus() == QProcess::NormalExit and which_adb->exitCode() == 0)
+ {
+ qDebug() << "adb found at" << QString{which_adb->readAllStandardOutput()}.trimmed();
+
+ if (!m_adb_installed)
+ {
+ adbInstalledChanged(m_adb_installed = true);
+ co_await on_poll_devices_timeout();
+ }
+ }
+ else
+ {
+ qDebug() << "adb not found";
+
+ if (m_adb_installed)
+ {
+ adbInstalledChanged(m_adb_installed = false);
+ }
+ }
+}
+
+// BEGIN Poll devices
+QCoro::Task<> adb::on_poll_devices_timeout()
+{
+ if (m_android_devices.empty())
+ {
+ auto wait_for_usb_device = escape_sandbox("adb", "wait-for-usb-device");
+ auto co_wait_for_usb_device = qCoro(*wait_for_usb_device);
+
+ co_await co_wait_for_usb_device.start();
+ co_await co_wait_for_usb_device.waitForFinished(-1);
+ }
+
+ auto adb_devices = escape_sandbox("adb", "devices");
+ adb_devices->setProcessChannelMode(QProcess::ForwardedErrorChannel);
+ auto co_adb_devices = qCoro(*adb_devices);
+
+ co_await co_adb_devices.start();
+ co_await co_adb_devices.waitForFinished();
+
+ if (adb_devices->exitStatus() == QProcess::NormalExit and adb_devices->exitCode() == 0)
+ {
+ auto out = adb_devices->readAllStandardOutput();
+ auto lines = QString{out}.split('\n');
+
+ // Remove "List of devices attached"
+ if (not lines.empty())
+ lines.pop_front();
+
+ std::vector devs;
+ for (auto & line: lines)
+ {
+ auto words = line.split('\t', Qt::SkipEmptyParts);
+ if (words.size() < 2)
+ continue;
+
+ const QString & serial = words[0];
+ const QString & state = words[1];
+
+ if (state != "device")
+ continue;
+
+ devs.push_back(serial);
+ }
+
+ for (size_t i = 0; i < m_android_devices.size();)
+ {
+ auto it = std::ranges::find(devs, m_android_devices[i].serial);
+ if (it == devs.end())
+ {
+ beginRemoveRows({}, i, i);
+ m_android_devices.erase(m_android_devices.begin() + i);
+ endRemoveRows();
+ }
+ else
+ {
+ ++i;
+ }
+ }
+
+ for (const QString & serial: devs)
+ {
+ if (not std::ranges::contains(m_android_devices, serial, &device::serial))
+ co_await add_device(serial);
+ }
+
+ QTimer::singleShot(500, this, &adb::on_poll_devices_timeout);
+ }
+ else
+ {
+ qDebug() << "adb failed";
+ }
+}
+// END
+
+// BEGIN Add device
+QCoro::QmlTask adb::checkIfWivrnIsInstalled(QString serial)
+{
+ return add_device(std::move(serial));
+}
+
+QCoro::Task<> adb::add_device(QString serial)
+{
+ device new_dev{.serial = serial};
+
+ auto list_packages = escape_sandbox("adb", "-s", serial, "shell", "pm", "list", "packages");
+ list_packages->setProcessChannelMode(QProcess::ForwardedErrorChannel);
+
+ auto co_list_packages = qCoro(*list_packages);
+
+ co_await co_list_packages.start();
+ co_await co_list_packages.waitForFinished();
+
+ if (list_packages->exitStatus() != QProcess::NormalExit or list_packages->exitCode() != 0)
+ {
+ co_return;
+ }
+
+ auto out_list_packages = list_packages->readAllStandardOutput();
+
+ for (auto & line: QString{out_list_packages}.split('\n'))
+ {
+ if (line == "package:org.meumeu.wivrn" or line.startsWith("package:org.meumeu.wivrn."))
+ {
+ new_dev.is_wivrn_installed = true;
+ new_dev.app = line.mid(8);
+ break;
+ }
+ }
+
+ auto getprop = escape_sandbox("adb", "-s", new_dev.serial, "shell", "getprop");
+ getprop->setProcessChannelMode(QProcess::ForwardedErrorChannel);
+
+ auto co_get_prop = qCoro(*getprop);
+
+ co_await co_get_prop.start();
+ co_await co_get_prop.waitForFinished();
+
+ if (getprop->exitStatus() != QProcess::NormalExit or getprop->exitCode() != 0)
+ {
+ co_return;
+ }
+
+ auto out_getprop = getprop->readAllStandardOutput();
+ static const QRegularExpression re{R"(\[(?.*)\]: \[(?.*)\])"};
+
+ for (auto & line: QString{out_getprop}.split('\n'))
+ {
+ if (auto match = re.match(line); match.hasMatch())
+ {
+ new_dev.properties.insert({match.captured("name"), match.captured("value")});
+ }
+ }
+
+ if (not new_dev.properties.contains("ro.product.manufacturer") or not new_dev.properties.contains("ro.product.model"))
+ co_return;
+
+ auto it = std::ranges::find(m_android_devices, new_dev.serial, &device::serial);
+ if (it == m_android_devices.end())
+ {
+ auto idx = m_android_devices.size();
+ beginInsertRows({}, idx, idx);
+ m_android_devices.push_back(new_dev);
+ endInsertRows();
+ }
+ else
+ {
+ *it = std::move(new_dev);
+ auto idx = index(m_android_devices.begin() - it);
+ dataChanged(idx, idx);
+ }
+}
+// END
+
+// BEGIN Model implementation
+QHash adb::roleNames() const
+{
+ return QHash{
+ {RoleSerial, "serial"},
+ {RoleIsWivrnInstalled, "isWivrnInstalled"},
+ {RoleManufacturer, "manufacturer"},
+ {RoleModel, "model"},
+ {RoleProduct, "product"},
+ {RoleDevice, "device"},
+ };
+}
+
+QVariant adb::data(const QModelIndex & index, int role) const
+{
+ switch (role)
+ {
+ case RoleSerial:
+ return m_android_devices.at(index.row()).serial;
+
+ case RoleProduct: {
+ auto it = m_android_devices.at(index.row()).properties.find("ro.product.name");
+ if (it == m_android_devices.at(index.row()).properties.end())
+ return "";
+ else
+ return it->second;
+ }
+
+ case RoleManufacturer: {
+ auto it = m_android_devices.at(index.row()).properties.find("ro.product.manufacturer");
+ if (it == m_android_devices.at(index.row()).properties.end())
+ return "";
+ else
+ return it->second;
+ }
+
+ case RoleModel: {
+ auto it = m_android_devices.at(index.row()).properties.find("ro.product.model");
+ if (it == m_android_devices.at(index.row()).properties.end())
+ return "";
+ else
+ return it->second;
+ }
+
+ case RoleDevice: {
+ auto it = m_android_devices.at(index.row()).properties.find("ro.product.device");
+ if (it == m_android_devices.at(index.row()).properties.end())
+ return "";
+ else
+ return it->second;
+ }
+
+ case RoleIsWivrnInstalled:
+ return m_android_devices.at(index.row()).is_wivrn_installed;
+
+ default:
+ return {};
+ }
+}
+// END
+
+QCoro::QmlTask adb::startUsbConnection(QString serial, QString pin)
+{
+ return doStartUsbConnection(serial, pin);
+}
+
+QCoro::Task<> adb::doStartUsbConnection(QString serial, QString pin)
+{
+ auto it = std::ranges::find(m_android_devices, serial, &device::serial);
+
+ if (it == m_android_devices.end())
+ co_return;
+
+ auto adb_reverse = escape_sandbox("adb", "-s", serial, "reverse", "tcp:9757", "tcp:9757");
+ adb_reverse->setProcessChannelMode(QProcess::ForwardedChannels);
+ auto co_process = qCoro(*adb_reverse);
+
+ co_await co_process.start();
+ co_await co_process.waitForFinished();
+
+ if (adb_reverse->exitStatus() != QProcess::NormalExit or adb_reverse->exitCode() != 0)
+ {
+ // TODO display error
+ co_return;
+ }
+
+ QString uri = pin == "" ? "wivrn+tcp://127.0.0.1:9757" : "wivrn+tcp://:" + pin + "@127.0.0.1:9757";
+
+ auto adb_start_activity = escape_sandbox("adb", "-s", serial, "shell", "am", "start", "-a", "android.intent.action.VIEW", "-d", uri, it->app);
+ adb_start_activity->setProcessChannelMode(QProcess::ForwardedChannels);
+ auto co_adb_start_activity = qCoro(*adb_start_activity);
+
+ co_await co_adb_start_activity.start();
+ co_await co_adb_start_activity.waitForFinished();
+
+ if (adb_start_activity->exitStatus() != QProcess::NormalExit or adb_start_activity->exitCode() != 0)
+ {
+ // TODO display error
+ co_return;
+ }
+
+ // TODO display success
+}
+
+#include "moc_adb.cpp"
diff --git a/dashboard/adb.h b/dashboard/adb.h
new file mode 100644
index 00000000..6090cb5f
--- /dev/null
+++ b/dashboard/adb.h
@@ -0,0 +1,86 @@
+/*
+ * 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
+
+class adb : public QAbstractListModel
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(Adb)
+ QML_SINGLETON
+
+ struct device
+ {
+ QString serial;
+ QString app;
+ std::map properties;
+ bool is_wivrn_installed = false;
+ };
+
+ Q_PROPERTY(bool adbInstalled READ adbInstalled NOTIFY adbInstalledChanged)
+
+ bool m_adb_installed = false;
+ std::vector m_android_devices;
+
+ QCoro::Task<> on_poll_devices_timeout();
+
+public:
+ enum Roles
+ {
+ RoleSerial = Qt::UserRole + 1,
+ RoleIsWivrnInstalled,
+ RoleManufacturer,
+ RoleModel,
+ RoleProduct,
+ RoleDevice,
+ };
+ adb();
+
+ bool adbInstalled() const
+ {
+ return m_adb_installed;
+ }
+
+ Q_INVOKABLE QCoro::QmlTask startUsbConnection(QString serial, QString pin);
+ Q_INVOKABLE QCoro::QmlTask checkIfWivrnIsInstalled(QString serial);
+
+ int rowCount(const QModelIndex & parent) const override
+ {
+ return m_android_devices.size();
+ }
+
+ QVariant data(const QModelIndex & index, int role) const override;
+
+protected:
+ QHash roleNames() const override;
+
+Q_SIGNALS:
+ void adbInstalledChanged(bool);
+
+private:
+ QCoro::Task<> checkIfAdbIsInstalled();
+ QCoro::Task<> add_device(QString serial);
+ QCoro::Task<> doStartUsbConnection(QString serial, QString pin);
+};
diff --git a/dashboard/apk_installer.cpp b/dashboard/apk_installer.cpp
new file mode 100644
index 00000000..6605ce03
--- /dev/null
+++ b/dashboard/apk_installer.cpp
@@ -0,0 +1,254 @@
+/*
+ * WiVRn VR streaming
+ * Copyright (C) 2025 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 "apk_installer.h"
+#include "escape_sandbox.h"
+#include "version.h"
+#include
+#include
+#include
+#include
+#include
+
+using namespace std::chrono_literals;
+
+apk_installer::apk_installer()
+{
+ if (isTagged())
+ m_apkFile.setFileName(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/wivrn-" + QString::fromStdString(wivrn::git_version) + ".apk");
+ else
+ m_apkFile.setFileName(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/wivrn-" + QString::fromStdString(wivrn::git_commit) + ".apk");
+}
+
+bool apk_installer::isTagged() const
+{
+ return not std::regex_match(wivrn::git_version, std::regex(".*-g[0-9a-f]+"));
+}
+
+QString apk_installer::currentVersion() const
+{
+ if (wivrn::git_version[0] == 'v')
+ return &wivrn::git_version[1];
+ return wivrn::git_version;
+}
+
+QCoro::Task<> apk_installer::doRefreshLatestVersion()
+{
+ assert(not m_busy);
+ m_apkUrl = QUrl{};
+
+ busyChanged(m_busy = true);
+ if (m_latestVersion != "")
+ latestVersionChanged(m_latestVersion = "");
+
+ std::unique_ptr reply{co_await manager.get(QNetworkRequest{QUrl{"https://api.github.com/repos/WiVRn/WiVRn/releases/latest"}})};
+
+ if (auto error = reply->error(); error != QNetworkReply::NetworkError::NoError)
+ {
+ qWarning() << "Cannot get version information" << error;
+ }
+ else
+ {
+ auto json = nlohmann::json::parse(reply->readAll());
+ m_latestVersion = QString::fromStdString(json["tag_name"]);
+ if (m_latestVersion.startsWith('v'))
+ m_latestVersion = m_latestVersion.mid(1);
+
+ latestVersionChanged(m_latestVersion);
+ qDebug() << "Latest version is" << m_latestVersion;
+
+ qDebug() << "Getting release metadata";
+ }
+
+ QUrl metadata_url;
+ if (isTagged())
+ metadata_url = QString{"https://api.github.com/repos/WiVRn/WiVRn/releases/tags/"} + wivrn::git_version;
+ else
+ metadata_url = QString{"https://api.github.com/repos/WiVRn/WiVRn-APK/releases/tags/apk-"} + wivrn::git_commit;
+
+ reply.reset(co_await manager.get(QNetworkRequest{metadata_url}));
+
+ if (auto error = reply->error(); error != QNetworkReply::NoError)
+ {
+ qWarning() << "Cannot get release metadata" << error;
+ }
+ else
+ {
+ auto json = nlohmann::json::parse(reply->readAll());
+ for (auto & i: json["assets"])
+ {
+ std::string name = i["name"];
+
+ if (name.ends_with("-standard-release.apk"))
+ {
+ m_apkUrl = QString::fromStdString(i["browser_download_url"]);
+ break;
+ }
+ }
+ }
+
+ if (apkAvailable())
+ {
+ apkAvailableChanged(true);
+ qDebug() << "APK URL is" << m_apkUrl.toString();
+ }
+ else
+ {
+ apkAvailableChanged(false);
+ qDebug() << "No precompiled APK is available for this version";
+ }
+
+ busyChanged(m_busy = false);
+}
+
+QCoro::Task<> apk_installer::doInstallApk(QString serial)
+{
+ assert(not m_apkFile.isOpen());
+ assert(not m_busy);
+ assert(m_apkUrl != QUrl{});
+
+ busyChanged(m_busy = true);
+
+ if (QFile::exists(m_apkFile.fileName()))
+ {
+ qDebug() << "Already downloaded";
+ }
+ else
+ {
+ cancellableChanged(m_cancellable = true);
+
+ auto apk_dir = std::filesystem::path(m_apkFile.fileName().toStdString()).parent_path();
+ std::filesystem::create_directories(apk_dir);
+ m_apkFile.open(QIODeviceBase::WriteOnly | QIODeviceBase::Truncate);
+
+ qDebug() << "Downloading from" << m_apkUrl.toString() << "to" << m_apkFile.fileName();
+
+ std::unique_ptr reply{manager.get(QNetworkRequest{m_apkUrl})};
+
+ auto co_reply = qCoro(*reply);
+ int64_t size_total = -1;
+
+ m_bytesReceived = 0;
+ m_bytesTotal = -1;
+ bytesReceivedChanged(m_bytesReceived);
+ bytesTotalChanged(m_bytesTotal);
+
+ while ((reply->bytesAvailable() > 0 or not reply->isFinished()) and m_apkFile.isOpen())
+ {
+ m_apkFile.write(co_await co_reply.read(100'000, 250ms));
+
+ if (QVariant content_length = reply->header(QNetworkRequest::KnownHeaders::ContentLengthHeader); content_length.isValid())
+ {
+ int64_t new_total_size = content_length.toLongLong();
+ if (size_total != new_total_size)
+ size_total = new_total_size;
+ }
+
+ m_bytesReceived = m_apkFile.size();
+ m_bytesTotal = size_total;
+ bytesReceivedChanged(m_bytesReceived);
+ bytesTotalChanged(m_bytesTotal);
+
+ if (m_bytesTotal > 0)
+ installStatusChanged(m_installStatus = ki18n("Downloading APK: %1 MB / %2 MB").subs(m_bytesReceived / 1'000'000., 0, 'f', 1).subs(m_bytesTotal / 1'000'000., 0, 'f', 1).toString());
+ else
+ installStatusChanged(m_installStatus = ki18n("Downloading APK: %1 MB").subs(m_bytesReceived / 1'000'000., 0, 'f', 1).toString());
+ };
+
+ if (not m_apkFile.isOpen())
+ {
+ qDebug() << "Download cancelled";
+ m_bytesReceived = 0;
+ m_bytesTotal = -1;
+
+ installStatusChanged(m_installStatus = i18n("Download cancelled"));
+ bytesReceivedChanged(m_bytesReceived);
+ bytesTotalChanged(m_bytesTotal);
+ busyChanged(m_busy = false);
+ co_return;
+ }
+ else if (auto error = reply->error(); error != QNetworkReply::NoError)
+ {
+ qDebug() << "Cannot download APK" << error;
+
+ // Cancel and commit to close without saving the already written data, so that it can be reopened
+ m_apkFile.cancelWriting();
+ m_apkFile.commit();
+ m_bytesReceived = 0;
+ m_bytesTotal = -1;
+
+ installStatusChanged(m_installStatus = i18n("Cannot download APK: %1", reply->errorString()));
+ bytesReceivedChanged(m_bytesReceived);
+ bytesTotalChanged(m_bytesTotal);
+ busyChanged(m_busy = false);
+ co_return;
+ }
+ else
+ {
+ qDebug() << "Download successful";
+ auto last_modified = reply->header(QNetworkRequest::LastModifiedHeader).value();
+ m_apkFile.setFileTime(last_modified, QFileDevice::FileModificationTime);
+ m_apkFile.commit();
+ }
+ }
+
+ cancellableChanged(m_cancellable = false);
+ bytesTotalChanged(m_bytesTotal = -1); // Make the progress bar indeterminate
+
+ auto adb_install = escape_sandbox("adb", "-s", serial, "install", "-r", m_apkFile.fileName());
+ adb_install->setProcessChannelMode(QProcess::ForwardedChannels);
+
+ auto co_adb_install = qCoro(*adb_install);
+
+ installStatusChanged(m_installStatus = i18n("Installing APK"));
+ if (not co_await co_adb_install.start())
+ {
+ qDebug() << "adb failed to start:" << adb_install->error();
+ installStatusChanged(m_installStatus = i18n("adb failed to start: %1", adb_install->error()));
+ busyChanged(m_busy = false);
+ co_return;
+ }
+
+ co_await co_adb_install.waitForFinished();
+
+ if (adb_install->exitStatus() != QProcess::NormalExit)
+ {
+ qDebug() << "adb exited abnormally" << adb_install->error();
+ installStatusChanged(m_installStatus = i18n("adb exited abnormally: %1", adb_install->error()));
+ busyChanged(m_busy = false);
+ co_return;
+ }
+
+ if (adb_install->exitCode() != 0)
+ {
+ qDebug() << "The 'adb install' command failed: exit code" << adb_install->exitCode();
+ installStatusChanged(m_installStatus = i18n("The 'adb install' command failed: exit code %1", adb_install->exitCode()));
+ busyChanged(m_busy = false);
+ co_return;
+ }
+
+ installStatusChanged(m_installStatus = i18n("Installation successful"));
+ busyChanged(m_busy = false);
+}
+
+void apk_installer::cancelInstallApk()
+{
+ qDebug() << "Cancelling download";
+ m_apkFile.cancelWriting();
+ m_apkFile.commit();
+}
diff --git a/dashboard/apk_installer.h b/dashboard/apk_installer.h
new file mode 100644
index 00000000..85d1d2dd
--- /dev/null
+++ b/dashboard/apk_installer.h
@@ -0,0 +1,130 @@
+/*
+ * WiVRn VR streaming
+ * Copyright (C) 2025 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
+
+class apk_installer : public QObject
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(ApkInstaller)
+ QML_SINGLETON
+
+ QNetworkAccessManager manager;
+
+ QSaveFile m_apkFile;
+ int64_t m_bytesReceived = 0;
+ int64_t m_bytesTotal = -1;
+ QString m_installStatus = "";
+ bool m_cancellable = true;
+ bool m_busy = false;
+
+ QUrl m_apkUrl;
+ QString m_latestVersion;
+
+public:
+ apk_installer();
+
+ // Version information
+ Q_PROPERTY(bool isTagged READ isTagged CONSTANT)
+ Q_PROPERTY(QString currentVersion READ currentVersion CONSTANT)
+ Q_PROPERTY(QString latestVersion READ latestVersion NOTIFY latestVersionChanged)
+ bool isTagged() const;
+ QString currentVersion() const;
+ QString latestVersion() const
+ {
+ return m_latestVersion;
+ }
+
+ Q_PROPERTY(QString filePath READ filePath NOTIFY filePathChanged)
+ Q_PROPERTY(double bytesReceived READ bytesReceived NOTIFY bytesReceivedChanged)
+ Q_PROPERTY(double bytesTotal READ bytesTotal NOTIFY bytesTotalChanged)
+ Q_PROPERTY(QString installStatus READ installStatus NOTIFY installStatusChanged)
+ Q_PROPERTY(bool cancellable READ cancellable NOTIFY cancellableChanged)
+ Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
+ Q_PROPERTY(bool apkAvailable READ apkAvailable NOTIFY apkAvailableChanged)
+
+ QString filePath() const
+ {
+ return m_apkFile.fileName();
+ }
+
+ double bytesTotal() const
+ {
+ return m_bytesTotal;
+ }
+
+ double bytesReceived() const
+ {
+ return m_bytesReceived;
+ }
+
+ QString installStatus() const
+ {
+ return m_installStatus;
+ }
+
+ bool cancellable() const
+ {
+ return m_cancellable;
+ }
+
+ bool busy() const
+ {
+ return m_busy;
+ }
+
+ bool apkAvailable() const
+ {
+ return m_apkUrl != QUrl{};
+ }
+
+ Q_INVOKABLE QCoro::QmlTask refreshLatestVersion()
+ {
+ return doRefreshLatestVersion();
+ }
+
+ Q_INVOKABLE QCoro::QmlTask installApk(QString serial)
+ {
+ return doInstallApk(serial);
+ }
+
+ Q_INVOKABLE void cancelInstallApk();
+
+private:
+ QCoro::Task<> doRefreshLatestVersion();
+ QCoro::Task<> doInstallApk(QString serial);
+
+Q_SIGNALS:
+ void latestVersionChanged(QString);
+ void filePathChanged(QString);
+ void bytesReceivedChanged(double);
+ void bytesTotalChanged(double);
+ void installStatusChanged(QString);
+ void cancellableChanged(bool);
+ void busyChanged(bool);
+ void apkAvailableChanged(bool);
+};
diff --git a/dashboard/dashboard-qml/.gitignore b/dashboard/dashboard-qml/.gitignore
new file mode 100644
index 00000000..06d7d7c1
--- /dev/null
+++ b/dashboard/dashboard-qml/.gitignore
@@ -0,0 +1,2 @@
+.qmlformat.ini
+.qmlls.ini
diff --git a/dashboard/escape_sandbox.h b/dashboard/escape_sandbox.h
new file mode 100644
index 00000000..b7f4b9ed
--- /dev/null
+++ b/dashboard/escape_sandbox.h
@@ -0,0 +1,58 @@
+/*
+ * 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 "utils/flatpak.h"
+#include
+#include
+
+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));
+ }
+
+ auto to_QString = [](const auto & s) {
+ using T = std::decay_t>>;
+
+ if constexpr (std::is_same_v)
+ return s;
+ if constexpr (std::is_same_v)
+ return s;
+ if constexpr (std::is_same_v)
+ return QString::fromStdString(s);
+ };
+
+ (args.push_back(to_QString(args_orig)), ...);
+
+ process->setArguments(args);
+
+ return process;
+}
diff --git a/dashboard/escape_string.cpp b/dashboard/escape_string.cpp
new file mode 100644
index 00000000..995e975a
--- /dev/null
+++ b/dashboard/escape_string.cpp
@@ -0,0 +1,107 @@
+/*
+ * 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 "escape_string.h"
+
+QString escape_string(const std::vector & app)
+{
+ std::string_view escaped_chars = R"( '"\)";
+ std::string app_string;
+ for (const std::string & i: app)
+ {
+ for (char c: i)
+ {
+ if (not escaped_chars.contains(c))
+ {
+ app_string += c;
+ }
+ else
+ {
+ app_string += '\\';
+ app_string += c;
+ }
+ }
+
+ app_string += ' ';
+ }
+ app_string.resize(app_string.size() - 1);
+
+ return QString::fromStdString(app_string);
+}
+
+std::vector unescape_string(const QString & 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.toStdString())
+ {
+ 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 (app.back() != "")
+ app.emplace_back();
+ break;
+ default:
+ app.back() += c;
+ }
+ }
+ }
+
+ if (app.back() == "")
+ app.pop_back();
+
+ return app;
+}
diff --git a/dashboard/escape_string.h b/dashboard/escape_string.h
new file mode 100644
index 00000000..9ac1fa09
--- /dev/null
+++ b/dashboard/escape_string.h
@@ -0,0 +1,26 @@
+/*
+ * 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
+
+QString escape_string(const std::vector & app);
+std::vector unescape_string(const QString & app_string);
diff --git a/dashboard/gui_config.h.in b/dashboard/gui_config.h.in
new file mode 100644
index 00000000..f5e9ec42
--- /dev/null
+++ b/dashboard/gui_config.h.in
@@ -0,0 +1,27 @@
+/*
+ * 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
new file mode 100644
index 00000000..adee079e
--- /dev/null
+++ b/dashboard/io.github.wivrn.wivrn.desktop.in
@@ -0,0 +1,8 @@
+[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;Game
diff --git a/dashboard/io.github.wivrn.wivrn.metainfo.xml b/dashboard/io.github.wivrn.wivrn.metainfo.xml
new file mode 100644
index 00000000..ed719605
--- /dev/null
+++ b/dashboard/io.github.wivrn.wivrn.metainfo.xml
@@ -0,0 +1,150 @@
+
+
+ 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
+
+ io.github.wivrn.wivrn
+
+
+
+
+
+ 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
new file mode 100644
index 00000000..d8accce5
--- /dev/null
+++ b/dashboard/main.cpp
@@ -0,0 +1,51 @@
+#include "version.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+int main(int argc, char * argv[])
+{
+ KIconTheme::initTheme();
+ QApplication app(argc, argv);
+ KLocalizedString::setApplicationDomain("wivrn-dashboard");
+ app.setOrganizationName(QStringLiteral("wivrn"));
+ app.setOrganizationDomain(QStringLiteral("wivrn.github.io"));
+ app.setApplicationName(QStringLiteral("wivrn-dashboard"));
+ app.setDesktopFileName(QStringLiteral("io.github.wivrn.wivrn"));
+ app.setApplicationVersion(QString(wivrn::git_version));
+
+ app.setApplicationDisplayName(i18n("WiVRn dashboard"));
+
+ QCoro::Qml::registerTypes();
+
+ // Work around QTBUG-45105, QTBUG-46074, QTBUG-51112: flicker when resizing
+ QQuickWindow::setSceneGraphBackend(QString::fromLatin1("software"));
+
+ QApplication::setStyle(QStringLiteral("breeze"));
+ if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE"))
+ {
+ QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
+ }
+
+ QQmlApplicationEngine engine;
+
+ engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
+ engine.loadFromModule("io.github.wivrn.wivrn", "Main");
+
+ if (engine.rootObjects().isEmpty())
+ {
+ return -1;
+ }
+
+ return app.exec();
+}
diff --git a/dashboard/qml/ApkInstallPage.qml b/dashboard/qml/ApkInstallPage.qml
new file mode 100644
index 00000000..e290518d
--- /dev/null
+++ b/dashboard/qml/ApkInstallPage.qml
@@ -0,0 +1,56 @@
+pragma ComponentBehavior: Bound
+
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Controls as Controls
+import org.kde.kirigami as Kirigami
+
+import io.github.wivrn.wivrn
+
+Kirigami.ScrollablePage {
+ id: apk_install
+ title: i18n("Install the WiVRn app on your headset")
+
+ flickable.interactive: false
+
+ Kirigami.CardsListView {
+ model: Adb
+ delegate: DeviceCard {
+ id: device_card
+ required property string serial
+ required property string model
+ required property string manufacturer
+ required property bool isWivrnInstalled
+
+ name: device_card.manufacturer + " " + device_card.model
+ serial_number: device_card.serial
+ is_wivrn_installed: device_card.isWivrnInstalled
+ }
+
+ Kirigami.PlaceholderMessage {
+ id: placeholder_message
+ anchors.centerIn: parent
+ width: parent.width - (Kirigami.Units.largeSpacing * 4)
+
+ visible: parent.count == 0
+
+ text: Adb.adbInstalled ? i18n("Connect a headset and make sure developper mode is enabled.") : i18n("ADB is not installed.")
+ }
+ }
+
+ footer: Controls.DialogButtonBox {
+ standardButtons: Controls.DialogButtonBox.NoButton
+ onAccepted: applicationWindow().pageStack.pop()
+
+ Controls.Button {
+ text: i18nc("go back to the home page", "Back")
+ icon.name: "go-previous"
+ Controls.DialogButtonBox.buttonRole: Controls.DialogButtonBox.AcceptRole
+ }
+ }
+
+ Shortcut {
+ sequences: [StandardKey.Cancel]
+ onActivated: applicationWindow().pageStack.pop()
+ }
+}
diff --git a/dashboard/qml/BetterLabel.qml b/dashboard/qml/BetterLabel.qml
new file mode 100644
index 00000000..7176e39b
--- /dev/null
+++ b/dashboard/qml/BetterLabel.qml
@@ -0,0 +1,14 @@
+import QtQuick
+import QtQuick.Controls as Controls
+
+Controls.Label {
+ // Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+
+ onLinkActivated: link => Qt.openUrlExternally(link)
+ MouseArea {
+ anchors.fill: parent
+ cursorShape: (parent as Controls.Label).hoveredLink == "" ? Qt.ArrowCursor : Qt.PointingHandCursor
+ acceptedButtons: Qt.NoButton
+ }
+}
diff --git a/dashboard/qml/ConnectUsbDialog.qml b/dashboard/qml/ConnectUsbDialog.qml
new file mode 100644
index 00000000..f156861a
--- /dev/null
+++ b/dashboard/qml/ConnectUsbDialog.qml
@@ -0,0 +1,80 @@
+import QtQuick
+import org.kde.kirigami as Kirigami
+import io.github.wivrn.wivrn
+
+Kirigami.MenuDialog {
+ id: select_usb_device
+
+ property int connected_headset_count: 0
+ property string connected_headset_serial: ""
+
+ title: i18n("Select your headset")
+ showCloseButton: true
+
+ Connections {
+ target: Adb
+
+ function onRowsInserted() {
+ select_usb_device.connected_devices_changed();
+ }
+
+ function onRowsRemoved() {
+ select_usb_device.connected_devices_changed();
+ }
+
+ function onDataChanged() {
+ select_usb_device.connected_devices_changed();
+ }
+ }
+
+ Component {
+ id: usb_device_component
+ Kirigami.Action {
+ property string serial
+ property string label
+
+ text: label
+ onTriggered: Adb.startUsbConnection(serial, WivrnServer.pin)
+ }
+ }
+
+ Component.onCompleted: select_usb_device.connected_devices_changed()
+
+ actions: []
+
+ function connect() {
+ if (select_usb_device.connected_headset_count == 1) {
+ Adb.startUsbConnection(select_usb_device.connected_headset_serial, WivrnServer.pin);
+ } else {
+ select_usb_device.open();
+ }
+ }
+
+ function connected_devices_changed() {
+ var n = Adb.rowCount();
+ var nb_found = 0;
+
+ select_usb_device.actions.length = 0;
+
+ for (var i = 0; i < n; i++) {
+ var serial = Adb.data(Adb.index(i, 0), 257);
+ var isWivrnInstalled = Adb.data(Adb.index(i, 0), 258);
+ var manufacturer = Adb.data(Adb.index(i, 0), 259);
+ var model = Adb.data(Adb.index(i, 0), 260);
+
+ if (isWivrnInstalled) {
+ nb_found++;
+ select_usb_device.connected_headset_serial = serial;
+
+ select_usb_device.actions.push(usb_device_component.createObject(select_usb_device, {
+ "label": manufacturer + " " + model,
+ "serial": serial
+ }));
+ }
+ }
+
+ select_usb_device.connected_headset_count = nb_found;
+ if (nb_found != 1)
+ select_usb_device.connected_headset_serial = "";
+ }
+}
diff --git a/dashboard/qml/DeviceCard.qml b/dashboard/qml/DeviceCard.qml
new file mode 100644
index 00000000..c94e08cb
--- /dev/null
+++ b/dashboard/qml/DeviceCard.qml
@@ -0,0 +1,104 @@
+pragma ComponentBehavior: Bound
+
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Controls as Controls
+import org.kde.kirigami as Kirigami
+
+import io.github.wivrn.wivrn
+
+Kirigami.Card {
+ id: device_card
+
+ property alias name: label_name.text
+ property string serial_number
+ property bool is_wivrn_installed
+ property bool installing: false
+
+ Connections {
+ target: ApkInstaller
+ function onBusyChanged(value) {
+ if (!value)
+ device_card.installing = false;
+ }
+ }
+
+ implicitHeight: contentItem.implicitHeight + 2 * Kirigami.Units.largeSpacing
+
+ contentItem: GridLayout {
+ id: delegate_layout
+ rowSpacing: Kirigami.Units.largeSpacing
+ columnSpacing: Kirigami.Units.largeSpacing
+ columns: 2
+
+ Controls.Label {
+ id: label_name
+ Layout.fillWidth: true
+ Layout.column: 0
+ Layout.row: 0
+ font.pixelSize: 20
+ }
+
+ Controls.Label {
+ Layout.fillWidth: true
+ Layout.column: 0
+ Layout.row: 1
+ text: device_card.is_wivrn_installed ? i18n("WiVRn is already installed on this device") : ""
+ }
+
+ Controls.Button {
+ id: install_button
+ Layout.column: 1
+ Layout.row: 0
+ Layout.rowSpan: 2
+ text: device_card.is_wivrn_installed ? i18n("Reinstall WiVRn") : i18n("Install WiVRn")
+ icon.name: "install-symbolic"
+ onClicked: device_card.install()
+ enabled: !ApkInstaller.busy
+ }
+
+ Controls.Label {
+ id: progress_label
+ Layout.column: 0
+ Layout.row: 2
+ Layout.columnSpan: 2
+ visible: device_card.installing
+ text: ApkInstaller.installStatus
+ }
+
+ RowLayout {
+ Layout.column: 0
+ Layout.row: 3
+ Layout.columnSpan: 2
+ visible: device_card.installing
+
+ Controls.ProgressBar {
+ id: progress
+ Layout.fillWidth: true
+ from: 0
+ to: ApkInstaller.bytesTotal > 0 ? ApkInstaller.bytesTotal : 1
+ indeterminate: ApkInstaller.bytesTotal < 0
+ value: ApkInstaller.bytesReceived
+ }
+ Controls.Button {
+ icon.name: "dialog-cancel"
+ onClicked: device_card.cancel_install()
+ enabled: ApkInstaller.cancellable
+ }
+ }
+ }
+
+ function install() {
+ console.log("Installing WiVRn on " + device_card.serial_number);
+ installing = true;
+ ApkInstaller.installApk(device_card.serial_number).then(() => {
+ Adb.checkIfWivrnIsInstalled(device_card.serial_number);
+ applicationWindow().showPassiveNotification(ApkInstaller.installStatus);
+ });
+ }
+
+ function cancel_install() {
+ console.log("Cancelling installation");
+ ApkInstaller.cancelInstallApk();
+ }
+}
diff --git a/dashboard/qml/HeadsetStatsPage.qml b/dashboard/qml/HeadsetStatsPage.qml
new file mode 100644
index 00000000..3bd5d9e8
--- /dev/null
+++ b/dashboard/qml/HeadsetStatsPage.qml
@@ -0,0 +1,46 @@
+pragma ComponentBehavior: Bound
+
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Controls as Controls
+import org.kde.kirigami as Kirigami
+
+import io.github.wivrn.wivrn
+
+Kirigami.ScrollablePage {
+ id: headsets
+ title: i18n("Headset statistics")
+
+ Connections {
+ target: WivrnServer
+ function onHeadsetConnectedChanged(value) {
+ if (!value)
+ applicationWindow().pageStack.pop();
+ }
+ }
+
+ // TODO: bling
+
+ // Controls.Label {
+ // anchors.fill: parent
+ // horizontalAlignment: Qt.AlignHCenter
+ // verticalAlignment: Qt.AlignVCenter
+ // text: i18n("Connected headset")
+ // }
+
+ footer: Controls.DialogButtonBox {
+ standardButtons: Controls.DialogButtonBox.NoButton
+ onAccepted: applicationWindow().pageStack.pop()
+
+ Controls.Button {
+ text: i18nc("go back to the home page", "Back")
+ icon.name: "go-previous"
+ Controls.DialogButtonBox.buttonRole: Controls.DialogButtonBox.AcceptRole
+ }
+ }
+
+ Shortcut {
+ sequences: [StandardKey.Cancel]
+ onActivated: applicationWindow().pageStack.pop()
+ }
+}
diff --git a/dashboard/qml/HeadsetsPage.qml b/dashboard/qml/HeadsetsPage.qml
new file mode 100644
index 00000000..d8f36386
--- /dev/null
+++ b/dashboard/qml/HeadsetsPage.qml
@@ -0,0 +1,180 @@
+pragma ComponentBehavior: Bound
+
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Controls as Controls
+import org.kde.kirigami as Kirigami
+
+import io.github.wivrn.wivrn
+
+Kirigami.ScrollablePage {
+ id: headsets
+ title: i18n("Headsets")
+
+ // flickable.interactive: false
+
+ Kirigami.PromptDialog {
+ id: rename_headset
+ title: i18n("Rename headset")
+
+ property string publicKey
+ property alias headset_name: text_field.text
+
+ standardButtons: Kirigami.Dialog.NoButton
+ customFooterActions: [
+ Kirigami.Action {
+ text: i18n("Rename")
+ icon.name: "dialog-ok"
+ onTriggered: rename_headset.accept()
+
+ enabled: rename_headset.headset_name != ""
+ },
+ Kirigami.Action {
+ text: i18n("Cancel")
+ icon.name: "dialog-cancel"
+ onTriggered: rename_headset.close();
+ }
+ ]
+ ColumnLayout {
+ Controls.TextField {
+ id: text_field
+ Layout.fillWidth: true
+ placeholderText: i18n("Headset name…")
+ }
+ }
+
+ onAccepted: {
+ WivrnServer.rename_key(rename_headset.publicKey, rename_headset.headset_name);
+ rename_headset.close();
+ }
+
+ Shortcut {
+ sequences: ["Enter", "Return"]
+ onActivated: rename_headset.accept()
+ }
+
+ onAboutToShow: text_field.selectAll()
+ }
+
+ Component {
+ id: headset_delegate
+ Kirigami.Card {
+ id: headset
+ required property string name
+ required property string publicKey
+
+ contentItem: GridLayout {
+ id: delegate_layout
+ rowSpacing: Kirigami.Units.largeSpacing
+ columnSpacing: Kirigami.Units.largeSpacing
+ columns: 3
+
+ Controls.Label {
+ // TextInput {
+ Layout.fillWidth: true
+ Layout.column: 0
+ Layout.row: 0
+ wrapMode: Text.WordWrap
+ font.pixelSize: 20
+ text: headset.name
+ }
+
+ Controls.Label {
+ Layout.fillWidth: true
+ Layout.column: 0
+ Layout.row: 1
+ wrapMode: Text.WordWrap
+ // text: "Last connection: unknown"
+ text: ""
+ }
+
+ Controls.Button {
+ Layout.column: 1
+ Layout.rowSpan: 2
+ text: i18n("Rename")
+ icon.name: "edit-symbolic"
+ onClicked: {
+ rename_headset.publicKey = headset.publicKey;
+ rename_headset.headset_name = headset.name;
+ rename_headset.open();
+ }
+ }
+
+ Controls.Button {
+ Layout.column: 2
+ Layout.rowSpan: 2
+ text: i18n("Remove")
+ icon.name: "delete-symbolic"
+ onClicked: WivrnServer.revoke_key(headset.publicKey)
+ }
+ }
+ }
+ }
+
+ header: RowLayout {
+ Kirigami.InlineMessage {
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ Layout.topMargin: 2 * Kirigami.Units.largeSpacing
+ Layout.leftMargin: 2 * Kirigami.Units.largeSpacing
+ Layout.rightMargin: 2 * Kirigami.Units.largeSpacing
+ text: i18n("Pairing enabled, PIN: %1", WivrnServer.pin)
+ type: Kirigami.MessageType.Information
+ visible: WivrnServer.pairingEnabled && !placeholder_message.visible
+ actions: [
+ Kirigami.Action {
+ text: i18n("Disable pairing")
+ onTriggered: WivrnServer.disable_pairing()
+ }
+ ]
+ }
+ }
+
+ Kirigami.CardsListView {
+ model: WivrnServer.knownKeys
+ delegate: headset_delegate
+
+ Kirigami.PlaceholderMessage {
+ id: placeholder_message
+ anchors.centerIn: parent
+ width: parent.width - (Kirigami.Units.largeSpacing * 4)
+
+ visible: parent.count == 0
+
+ text: WivrnServer.pairingEnabled ? i18n("Start the WiVRn app on your headset and use the PIN: %1", WivrnServer.pin) : i18n("Enable pairing to allow your headset to connect to this computer")
+
+ // explanation: ""
+
+ helpfulAction: Kirigami.Action {
+ text: i18n("Enable pairing")
+ onTriggered: WivrnServer.enable_pairing()
+ enabled: !WivrnServer.pairingEnabled
+ }
+ }
+ }
+
+ footer: Controls.DialogButtonBox {
+ standardButtons: Controls.DialogButtonBox.NoButton
+ onAccepted: applicationWindow().pageStack.pop()
+
+ Controls.Button {
+ text: i18nc("go back to the home page", "Back")
+ icon.name: "go-previous"
+ Controls.DialogButtonBox.buttonRole: Controls.DialogButtonBox.AcceptRole
+ }
+ }
+
+ actions: [
+ Kirigami.Action {
+ text: i18n("Pair a new headset")
+ icon.name: "list-add-symbolic"
+ onTriggered: WivrnServer.enable_pairing()
+ enabled: !WivrnServer.pairingEnabled
+ }
+ ]
+
+ Shortcut {
+ sequences: [StandardKey.Cancel]
+ onActivated: applicationWindow().pageStack.pop()
+ }
+}
diff --git a/dashboard/qml/Main.qml b/dashboard/qml/Main.qml
new file mode 100644
index 00000000..0d0856a9
--- /dev/null
+++ b/dashboard/qml/Main.qml
@@ -0,0 +1,335 @@
+import QtCore as Core
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Dialogs as Dialogs
+import QtQuick.Controls as Controls
+import Qt.labs.platform
+import org.kde.kirigami as Kirigami
+
+import io.github.wivrn.wivrn
+
+Kirigami.ApplicationWindow {
+ id: root
+ title: i18n("WiVRn dashboard")
+
+ Settings {
+ id: config
+ }
+
+ ConnectUsbDialog {
+ id: select_usb_device
+ }
+
+ SystemTrayIcon {
+ id: systray
+ visible: true
+ icon.source: Qt.resolvedUrl("wivrn.svg")
+ onActivated: root.visible = !root.visible
+ }
+ onClosing: Qt.quit()
+
+ Core.Settings {
+ id: settings
+ property alias first_run: root.first_run
+ }
+ property bool first_run: true
+
+ width: 900
+ height: 800
+
+ property bool server_started: WivrnServer.serverStatus == WivrnServer.Started
+ property bool json_loaded: false
+ property bool prev_headset_connected: false
+
+ Connections {
+ target: WivrnServer
+ function onCapSysNiceChanged(value) {
+ if (WivrnServer.serverStatus != WivrnServer.Stopped)
+ restart_capsysnice.visible = true;
+ }
+
+ function onServerStatusChanged(value) {
+ var started = value == WivrnServer.Started;
+
+ if (switch_running.checked != started)
+ switch_running.checked = started;
+ }
+
+ function onPairingEnabledChanged(value) {
+ if (switch_pairing.checked != WivrnServer.pairingEnabled)
+ switch_pairing.checked = WivrnServer.pairingEnabled;
+ }
+
+ // function onHeadsetConnectedChanged(value) {
+ // if (value != root.prev_headset_connected) {
+ // root.prev_headset_connected = value;
+ //
+ // if (value && root.pageStack.depth == 1)
+ // root.pageStack.push(Qt.resolvedUrl("HeadsetStatsPage.qml"));
+ // }
+ // }
+ }
+
+ Component.onCompleted: {
+ if (WivrnServer.serverStatus == WivrnServer.Stopped)
+ WivrnServer.start_server();
+
+ console.log("Settings at " + settings.location);
+ if (root.first_run)
+ {
+ console.log("First run");
+ root.pageStack.push(Qt.resolvedUrl("WizardPage.qml"));
+ root.first_run = false;
+ }
+ }
+
+ pageStack.globalToolBar.showNavigationButtons: Kirigami.ApplicationHeaderStyle.NoNavigationButtons
+ pageStack.defaultColumnWidth: width // Force non-wide mode
+ pageStack.interactive: false // Don't let the back/forward mouse button handle the pagestack
+
+ pageStack.initialPage: Kirigami.ScrollablePage {
+ ColumnLayout {
+ anchors.fill: parent
+ Kirigami.InlineMessage {
+ Layout.fillWidth: true
+ text: i18n("The server does not have CAP_SYS_NICE capabilities.")
+ // type: Kirigami.MessageType.Warning
+ type: Kirigami.MessageType.Information
+ showCloseButton: true
+ visible: !WivrnServer.capSysNice
+ actions: [
+ Kirigami.Action {
+ text: i18n("Fix it")
+ onTriggered: WivrnServer.grant_cap_sys_nice()
+ }
+ ]
+ }
+
+ Kirigami.InlineMessage {
+ id: restart_capsysnice
+ Layout.fillWidth: true
+ text: i18n("The CAP_SYS_NICE capability will be used when the server is restarted.")
+ type: Kirigami.MessageType.Information
+ showCloseButton: true
+ visible: false
+ actions: [
+ Kirigami.Action {
+ text: i18nc("restart the server", "Restart now")
+ onTriggered: {
+ WivrnServer.restart_server();
+ restart_capsysnice.visible = false;
+ }
+ }
+ ]
+ }
+
+ Kirigami.InlineMessage {
+ Layout.fillWidth: true
+ text: i18n("ADB is not installed.")
+ type: Kirigami.MessageType.Information
+ showCloseButton: true
+ visible: !Adb.adbInstalled
+ }
+
+ Kirigami.InlineMessage {
+ Layout.fillWidth: true
+ text: i18n("NVIDIA GPUs require at least driver version 565.77, current version is %1", VulkanInfo.driverVersion)
+ type: Kirigami.MessageType.Error
+ showCloseButton: true
+ visible: VulkanInfo.driverId == "NvidiaProprietary" && VulkanInfo.driverVersionCode < 2371043328 /* Version 565.77 */
+ actions: [
+ Kirigami.Action {
+ text: i18n("More info")
+ onTriggered: Qt.openUrlExternally("https://github.com/WiVRn/WiVRn/issues/180")
+ }
+ ]
+ }
+
+ Kirigami.InlineMessage {
+ Layout.fillWidth: true
+ text: i18n("Use the Mesa (radv) driver for AMD GPUs\nHardware encoding with vaapi does not work with AMDVLK and AMDGPU-PRO")
+ type: Kirigami.MessageType.Warning
+ showCloseButton: true
+ visible: VulkanInfo.driverId == "AmdProprietary" || VulkanInfo.driverId == "AmdOpenSource"
+ }
+
+ // RowLayout {
+ // Controls.Button {
+ // text: "refresh latest version"
+ // onClicked: ApkInstaller.refreshLatestVersion()
+ // }
+ // Controls.Label {
+ // text: "current version " + ApkInstaller.currentVersion + "\nlatest version " + ApkInstaller.latestVersion
+ // }
+ // }
+
+ GridLayout {
+ columns: 2
+
+ Layout.leftMargin: Kirigami.Units.largeSpacing
+ Layout.rightMargin: Kirigami.Units.largeSpacing
+ Item {}
+ Item {
+ Layout.fillWidth: true
+ }
+
+ Image {
+ source: Qt.resolvedUrl("wivrn.svg")
+ }
+
+ GridLayout {
+ columns: 2
+ Layout.fillWidth: true
+ Controls.Switch {
+ id: switch_running
+ Layout.row: 0
+ Layout.column: 0
+ text: i18nc("whether the server is running, displayed in front of a checkbox", "Running")
+
+ checked: true
+ onCheckedChanged: {
+ if (checked && !root.server_started)
+ WivrnServer.start_server();
+ else if (!checked && root.server_started)
+ WivrnServer.stop_server();
+ }
+ }
+
+ Controls.Switch {
+ id: switch_pairing
+ Layout.row: 1
+ Layout.column: 0
+ text: i18nc("whether pairing is enabled, displayed in front of a checkbox", "Pairing")
+ onCheckedChanged: {
+ if (checked && !WivrnServer.pairingEnabled)
+ WivrnServer.enable_pairing();
+ else if (!checked && WivrnServer.pairingEnabled)
+ WivrnServer.disable_pairing();
+ }
+ enabled: root.server_started
+ }
+
+ Controls.Label {
+ Layout.row: 1
+ Layout.column: 1
+ text: WivrnServer.pairingEnabled ? i18n("PIN: %1", WivrnServer.pin) : ""
+ wrapMode: Text.WordWrap
+ Layout.fillWidth: true
+ }
+
+ Controls.Button {
+ Layout.row: 2
+ Layout.column: 0
+ text: i18n("Connect by USB")
+ onClicked: select_usb_device.connect()
+ enabled: root.server_started && Adb.adbInstalled && !WivrnServer.headsetConnected && select_usb_device.connected_headset_count > 0
+ visible: !WivrnServer.headsetConnected
+ }
+
+ Controls.Button {
+ Layout.row: 2
+ Layout.column: 0
+ text: i18n("Disconnect")
+ icon.name: "network-disconnect-symbolic"
+ onClicked: WivrnServer.disconnect_headset()
+ visible: root.server_started && WivrnServer.headsetConnected
+ }
+ }
+
+ Kirigami.Separator {
+ Layout.columnSpan: 2
+ Layout.fillWidth: true
+ opacity: root.server_started
+ Layout.maximumHeight: root.server_started ? -1 : 0
+ }
+
+ Kirigami.Heading {
+ level: 1
+ wrapMode: Text.WordWrap
+ text: i18nc("automatically started application", "Application")
+ opacity: root.server_started
+ Layout.maximumHeight: root.server_started ? -1 : 0
+ }
+
+ SelectGame {
+ id: select_game
+ opacity: root.server_started
+ Layout.maximumHeight: root.server_started ? -1 : 0
+ }
+
+ Kirigami.Separator {
+ Layout.columnSpan: 2
+ Layout.fillWidth: true
+ opacity: root.server_started
+ Layout.maximumHeight: root.server_started ? -1 : 0
+ }
+
+ Kirigami.Heading {
+ level: 1
+ wrapMode: Text.WordWrap
+ text: i18n("Steam informations")
+ opacity: root.server_started
+ Layout.maximumHeight: root.server_started ? -1 : 0
+ }
+ SteamLaunchOptions {
+ opacity: root.server_started
+ Layout.maximumHeight: root.server_started ? -1 : 0
+ }
+
+ Item {
+ // spacer item
+ Layout.fillHeight: true
+ }
+ }
+ }
+
+ actions: [
+ Kirigami.Action {
+ text: i18n("Wizard")
+ icon.name: "tools-wizard-symbolic"
+ onTriggered: root.pageStack.push(Qt.resolvedUrl("WizardPage.qml"))
+ visible: root.pageStack.depth == 1
+ enabled: root.server_started
+ },
+ Kirigami.Action {
+ text: i18n("Install the app")
+ icon.name: "install-symbolic"
+ onTriggered: root.pageStack.push(Qt.resolvedUrl("ApkInstallPage.qml"))
+ visible: root.pageStack.depth == 1
+ enabled: root.server_started && Adb.adbInstalled
+ },
+ // Kirigami.Action {
+ // text: i18n("Statistics")
+ // icon.name: "office-chart-line-symbolic"
+ // onTriggered: root.pageStack.push(Qt.resolvedUrl("HeadsetStatsPage.qml"))
+ // visible: root.pageStack.depth == 1
+ // enabled: root.server_started && Adb.adbInstalled && WivrnServer.headsetConnected
+ // },
+
+ Kirigami.Action {
+ text: i18n("Headsets")
+ icon.name: "item-symbolic"
+ onTriggered: root.pageStack.push(Qt.resolvedUrl("HeadsetsPage.qml"))
+ visible: root.pageStack.depth == 1
+ enabled: root.server_started
+ },
+ Kirigami.Action {
+ text: i18n("Settings")
+ icon.name: "settings-configure-symbolic"
+ onTriggered: root.pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
+ visible: root.pageStack.depth == 1
+ enabled: root.server_started
+ }/*,
+ Kirigami.Action {
+ text: i18n("Troubleshoot")
+ icon.name: "help-contents-symbolic"
+ onTriggered: root.pageStack.push(Qt.resolvedUrl("TroubleshootPage.qml"))
+ enabled: root.server_started && root.pageStack.depth == 1
+ }*/
+
+
+ ]
+ }
+
+ pageStack.onCurrentItemChanged: select_game.reload()
+}
diff --git a/dashboard/qml/SelectGame.qml b/dashboard/qml/SelectGame.qml
new file mode 100644
index 00000000..f92fe11f
--- /dev/null
+++ b/dashboard/qml/SelectGame.qml
@@ -0,0 +1,131 @@
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Dialogs as Dialogs
+import QtQuick.Controls as Controls
+import io.github.wivrn.wivrn
+
+ColumnLayout {
+ id: select_game
+
+ property bool json_loaded: false
+
+ Component.onCompleted: {
+ apps.append({
+ "name": i18nc("don't start an application automatically", "None"),
+ "image_path": "",
+ "command": "",
+ "is_custom": false
+ });
+
+ apps.append({
+ "name": i18nc("choose a custom application to start", "Custom"),
+ "image_path": "",
+ "command": "",
+ "is_custom": true
+ });
+
+ var steam_apps = SteamApps.apps;
+ for (var i = 0; i < steam_apps.length; i++) {
+ apps.append({
+ "name": steam_apps[i].name,
+ "image_path": steam_apps[i].imagePath,
+ "command": steam_apps[i].command,
+ "is_custom": false
+ });
+ }
+
+ select_game.load();
+ }
+
+ ListModel {
+ id: apps
+ }
+
+ Settings {
+ id: config
+ }
+
+ Connections {
+ target: WivrnServer
+ function onJsonConfigurationChanged() {
+ select_game.load();
+ }
+ }
+
+ Dialogs.FileDialog {
+ id: app_browse
+ onAccepted: {
+ app_text.text = new URL(selectedFile).pathname;
+ select_game.save();
+ }
+ }
+ RowLayout {
+ Layout.fillWidth: true
+ Controls.ComboBox {
+ id: app_combobox
+ Layout.columnSpan: 2
+ textRole: "name"
+ model: apps
+ onActivated: select_game.save()
+ }
+ Controls.TextField {
+ id: app_text
+ placeholderText: app_combobox.currentText
+ visible: !!app_combobox.model.get(app_combobox.currentIndex)?.is_custom && WivrnServer.serverStatus == WivrnServer.Started
+ Layout.fillWidth: true
+ onTextEdited: select_game.save()
+ }
+ Controls.Button {
+ text: i18nc("browse a file to choose the application to start", "Browse")
+ visible: app_text.visible
+ onClicked: app_browse.open()
+ }
+ }
+
+ function reload() {
+ select_game.json_loaded = false;
+ load();
+ }
+
+ function load() {
+ if (select_game.json_loaded || WivrnServer.serverStatus != WivrnServer.Started || WivrnServer.jsonConfiguration == "")
+ return;
+
+ config.load(WivrnServer);
+
+ var found = false;
+ var custom_idx = -1;
+ for (var i = 0; i < apps.count; i++) {
+ var app = apps.get(i);
+ if (app.is_custom)
+ custom_idx = i;
+ else if (app.command == config.application) {
+ app_combobox.currentIndex = i;
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ app_text.text = config.application;
+ app_combobox.currentIndex = custom_idx;
+ }
+
+ select_game.json_loaded = true;
+ }
+
+ function save() {
+ var new_application;
+
+ if (apps.get(app_combobox.currentIndex).is_custom)
+ new_application = app_text.text;
+ else
+ new_application = apps.get(app_combobox.currentIndex).command;
+
+ config.load(WivrnServer);
+ if (config.application != new_application) {
+ config.application = new_application;
+ config.save(WivrnServer);
+ }
+ }
+}
diff --git a/dashboard/qml/SettingsPage.qml b/dashboard/qml/SettingsPage.qml
new file mode 100644
index 00000000..d16e9600
--- /dev/null
+++ b/dashboard/qml/SettingsPage.qml
@@ -0,0 +1,363 @@
+pragma ComponentBehavior: Bound
+
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Controls as Controls
+import org.kde.kirigami as Kirigami
+
+import io.github.wivrn.wivrn
+
+Kirigami.ScrollablePage {
+ id: settings
+ title: i18n("Settings")
+
+ flickable.interactive: false // Make sure the Kirigami.ScrollablePage does not eat the vertical mouse dragging events
+
+ Settings {
+ id: config
+ }
+
+ ColumnLayout {
+ id: column
+ anchors.fill: parent
+
+ Kirigami.FormLayout {
+
+ Controls.CheckBox {
+ id: manual_foveation
+ checked: true
+ Layout.row: 0
+ Layout.column: 0
+ text: i18nc("automatic foveation setup", "Manual foveation")
+ }
+
+ GridLayout {
+ columns: 5
+ enabled: manual_foveation.checked
+ Kirigami.FormData.label: i18n("Foveation strength:")
+
+ Controls.Slider {
+ id: scale_slider
+ Layout.row: 0
+ Layout.column: 0
+ Layout.columnSpan: 3
+ implicitWidth: 20 * Kirigami.Units.gridUnit
+ from: 0
+ to: 80
+ stepSize: 1
+ }
+
+ Controls.Label {
+ Layout.row: 0
+ Layout.column: 3
+ text: i18n("%1 %", scale_slider.value)
+ }
+
+ Kirigami.ContextualHelpButton {
+ Layout.row: 0
+ Layout.column: 4
+ toolTipText: i18n("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.\n\nA weaker foveation gives a uniform sharpness in the whole image.\n\nThe recommended values are between 20% and 50% for headsets without eye tracking and between 50% and 70% for headsets with eye tracking.")
+ }
+
+ Controls.Label {
+ Layout.row: 1
+ Layout.column: 0
+ text: i18nc("weaker foveation", "Weaker")
+ }
+ Item {
+ Layout.row: 1
+ Layout.column: 1
+ // spacer item
+ Layout.fillWidth: true
+ }
+ Controls.Label {
+ Layout.row: 1
+ Layout.column: 2
+ text: i18nc("stronger foveation", "Stronger")
+ }
+ }
+
+ Kirigami.Separator {
+ Kirigami.FormData.isSection: true
+ }
+
+ Controls.SpinBox {
+ id: bitrate
+ Kirigami.FormData.label: i18n("Bitrate:")
+ from: 1
+ to: 200
+
+ textFromValue: (value, locale) => i18nc("bitrate", "%1 Mbit/s", value)
+ valueFromText: function (text, locale) {
+ var prefix_suffix = i18nc("bitrate", "%1 Mbit/s", "%1").split('%1');
+ for (var i of prefix_suffix) {
+ text = text.replace(i, "");
+ }
+ return Number.fromLocaleString(text);
+ }
+ }
+
+ Controls.ComboBox {
+ id: encoder_layout
+ Kirigami.FormData.label: i18n("Encoder layout:")
+ model: [
+ {
+ label: i18nc("encoder preset", "Automatic"),
+ value: null
+ },
+ {
+ label: i18nc("encoder preset", "Manual"),
+ value: null
+ },
+ {
+ label: i18nc("encoder preset", "Default preset"),
+ value: [
+ {
+ width: 0.5,
+ height: 1,
+ offset_x: 0,
+ offset_y: 0
+ },
+ {
+ width: 0.5,
+ height: 0.75,
+ offset_x: 0.5,
+ offset_y: 0
+ },
+ {
+ width: 0.5,
+ height: 0.25,
+ offset_x: 0.5,
+ offset_y: 0.75
+ }
+ ]
+ },
+ {
+ label: i18nc("encoder preset", "Low latency preset"),
+ value: [
+ {
+ width: 0.5,
+ height: 1,
+ offset_x: 0.5,
+ offset_y: 0,
+ encoder: 'x264',
+ codec: 'h264'
+ },
+ {
+ width: 0.5,
+ height: 0.75,
+ offset_x: 0,
+ offset_y: 0
+ },
+ {
+ width: 0.5,
+ height: 0.25,
+ offset_x: 0,
+ offset_y: 0.75
+ }
+ ]
+ },
+ {
+ label: i18nc("encoder preset", "Safe preset"),
+ value: [
+ {
+ width: 1,
+ height: 1,
+ offset_x: 0,
+ offset_y: 0
+ }]
+ }
+ ]
+ textRole: "label"
+ valueRole: "value"
+ onCurrentValueChanged: {
+ if (currentValue)
+ {
+ config.set_encoder_preset(currentValue);
+ partitionner.currentIndex = -1;
+ }
+ }
+ }
+
+ Controls.Label {
+ visible: encoder_layout.currentIndex > 0
+ text: i18n("To add a new encoder, split an existing encoder by clicking near an edge.\nDrag an edge to resize or remove encoders.")
+ wrapMode: Text.WordWrap
+ Layout.fillWidth: true
+ }
+
+ RectanglePartitionner {
+ id: partitionner
+ implicitWidth: 600
+ implicitHeight: 300
+ visible: encoder_layout.currentIndex > 0
+ settings: config
+ onCodecChanged: {
+ for (var i = 0; i < codec_combo.model.length; i++) {
+ if (codec_combo.model[i].name == codec)
+ codec_combo.currentIndex = i;
+ }
+ }
+ onEncoderChanged: {
+ for (var i = 0; i < encoder_combo.model.length; i++) {
+ if (encoder_combo.model[i].name == encoder)
+ encoder_combo.currentIndex = i;
+ }
+ }
+ onEncoderLayoutChanged: encoder_layout.currentIndex = 1 // Manual layout
+ }
+
+ RowLayout {
+ Kirigami.FormData.label: i18n("Encoder:")
+ enabled: partitionner.selected
+ visible: encoder_layout.currentIndex > 0
+ Controls.ComboBox {
+ id: encoder_combo
+ model: [
+ // Keep it in sync with rectangle_partitionner.h (encoder_name_from_setting)
+ {
+ name: "auto",
+ label: i18nc("automatic encoder setup", "Auto"),
+ codecs: "auto"
+ },
+ {
+ name: "nvenc",
+ label: i18n("nvenc (NVIDIA GPUs)"),
+ codecs: "auto,h264,h265"
+ },
+ {
+ name: "vaapi",
+ label: i18n("vaapi (AMD and Intel GPUs)"),
+ codecs: "auto,h264,h265,av1"
+ },
+ {
+ name: "x264",
+ label: i18n("x264 (software encoding)"),
+ codecs: "h264"
+ },
+ {
+ name: "vulkan",
+ label: i18n("Vulkan (Vulkan Video)"),
+ codecs: "h264"
+ }
+ ]
+ textRole: "label"
+ onCurrentIndexChanged: {
+ partitionner.encoder = encoder_combo.model[currentIndex].name;
+
+ // Check if the currently selected codec is supported by the new encoder
+ var supported_codecs = model[currentIndex].codecs.split(",");
+ var current_codec = codec_combo.model[codec_combo.currentIndex].name;
+
+ if (!supported_codecs.includes(current_codec)) {
+ for (var i = 0; i < codec_combo.model.length; i++) {
+ if (supported_codecs.includes(codec_combo.model[i].name)) {
+ codec_combo.currentIndex = i;
+ break;
+ }
+ }
+ }
+ }
+ }
+ Kirigami.ContextualHelpButton {
+ toolTipText: i18n("\"Auto\" will use hardware acceleration if it is available")
+ }
+ }
+
+ Controls.ComboBox {
+ id: codec_combo
+ Kirigami.FormData.label: i18n("Codec:")
+ enabled: partitionner.selected
+ visible: encoder_layout.currentIndex > 0
+ model: [
+ // Keep it in sync with rectangle_partitionner.h (codec_name_from_setting)
+ {
+ name: "auto",
+ label: i18nc("automatic codec setup", "Auto")
+ },
+ {
+ name: "h264",
+ label: i18n("H.264")
+ },
+ {
+ name: "h265",
+ label: i18n("H.265")
+ },
+ {
+ name: "av1",
+ label: i18n("AV1")
+ }
+ ]
+ textRole: "label"
+ onCurrentIndexChanged: partitionner.codec = model[currentIndex].name
+
+ delegate: Controls.ItemDelegate {
+ required property int index
+ required property string label
+ required property string name
+
+ width: codec_combo.width
+ text: i18n(label)
+ highlighted: ListView.isCurrentItem
+ enabled: encoder_combo.model[encoder_combo.currentIndex].codecs.split(",").includes(name)
+ }
+ }
+ }
+
+ Item {
+ // spacer item
+ Layout.fillHeight: true
+ }
+ }
+
+ footer: Controls.DialogButtonBox {
+ standardButtons: Controls.DialogButtonBox.Ok | Controls.DialogButtonBox.Cancel | Controls.DialogButtonBox.Reset
+
+ onAccepted: {
+ settings.save();
+ config.save(WivrnServer);
+
+ applicationWindow().pageStack.pop();
+ }
+ onReset: {
+ config.restore_defaults();
+ settings.load();
+ }
+ onRejected: applicationWindow().pageStack.pop()
+ }
+
+ Component.onCompleted: {
+ config.load(WivrnServer);
+ settings.load();
+ }
+
+ function save() {
+ config.bitrate = bitrate.value * 1000000;
+ config.scale = manual_foveation.checked ? 1 - scale_slider.value / 100.0 : -1;
+ config.manualEncoders = encoder_layout.currentIndex > 0;
+ }
+
+ function load() {
+ bitrate.value = config.bitrate / 1000000;
+
+ if (config.scale > 0) {
+ scale_slider.value = Math.round(100 - config.scale * 100);
+ manual_foveation.checked = true;
+ } else {
+ manual_foveation.checked = false;
+ }
+
+ if (config.manualEncoders) {
+ // auto_encoders.checked = false;
+ encoder_layout.currentIndex = 1;
+ } else {
+ // auto_encoders.checked = true;
+ encoder_layout.currentIndex = 0;
+ }
+ }
+
+ Shortcut {
+ sequences: [StandardKey.Cancel]
+ onActivated: applicationWindow().pageStack.pop()
+ }
+}
diff --git a/dashboard/qml/SteamLaunchOptions.qml b/dashboard/qml/SteamLaunchOptions.qml
new file mode 100644
index 00000000..8f984d9e
--- /dev/null
+++ b/dashboard/qml/SteamLaunchOptions.qml
@@ -0,0 +1,34 @@
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Controls as Controls
+import io.github.wivrn.wivrn
+
+ColumnLayout {
+ Controls.Label {
+ text: i18n("For Steam games, right click on the game in Steam, go in Properties > Shortcut and paste this in \"Launch options\":")
+ wrapMode: Text.WordWrap
+ Layout.fillWidth: true
+ }
+
+ RowLayout {
+ Controls.TextField {
+ text: WivrnServer.steamCommand
+ wrapMode: Text.WordWrap
+ Layout.fillWidth: true
+ readOnly: true
+ // cursorVisible: true
+ Controls.ToolTip.text: i18n("Paste this in the Steam launch options for the app you want to start")
+ Controls.ToolTip.visible: hovered
+ Controls.ToolTip.delay: 1000
+ }
+
+ Controls.Button {
+ text: i18nc("copy text to the clipboard", "Copy")
+ icon.name: "edit-copy-symbolic"
+ onClicked: {
+ WivrnServer.copy_steam_command();
+ showPassiveNotification(i18n("Copied Steam launch command"), 2000);
+ }
+ }
+ }
+}
diff --git a/dashboard/qml/WizardPage.qml b/dashboard/qml/WizardPage.qml
new file mode 100644
index 00000000..c25c11b1
--- /dev/null
+++ b/dashboard/qml/WizardPage.qml
@@ -0,0 +1,531 @@
+pragma ComponentBehavior: Bound
+
+import QtQuick
+import QtQuick.Layouts
+import QtQuick.Dialogs as Dialogs
+import QtQuick.Controls as Controls
+import QtQuick.Templates as Templates
+import org.kde.kirigami as Kirigami
+
+import io.github.wivrn.wivrn
+
+Kirigami.ScrollablePage {
+ id: wizard
+ title: i18n("Getting started")
+
+ // flickable.interactive: false
+
+ Component {
+ id: page_component
+ WizardStep {
+ Rectangle {
+ Layout.fillHeight: true
+ Layout.fillWidth: true
+ color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
+ }
+ Component.onDestruction: console.log("page destroyed")
+ actions: [
+ Kirigami.Action {
+ text: i18n("Back")
+ icon.name: "go-previous"
+ onTriggered: pageStack.pop()
+ },
+ Kirigami.Action {
+ text: "test"
+ onTriggered: pageStack.push(page_component.createObject(pageStack))
+ },
+ Kirigami.Action {
+ text: i18n("Cancel")
+ onTriggered: wizard.cancel()
+ }
+ ]
+ }
+ }
+
+ property bool is_tagged: ApkInstaller.isTagged
+ property bool is_latest: ApkInstaller.currentVersion == ApkInstaller.latestVersion
+ property bool checking_newer: ApkInstaller.latestVersion == "" && ApkInstaller.isTagged
+ property bool newer_version: ApkInstaller.currentVersion != ApkInstaller.latestVersion && ApkInstaller.latestVersion != "" && ApkInstaller.isTagged
+
+ ConnectUsbDialog {
+ id: select_usb_device
+ }
+
+ Component.onCompleted: {
+ ApkInstaller.refreshLatestVersion();
+ }
+
+ Component {
+ id: page_welcome_component
+ WizardStep {
+ id: page_welcome
+ Controls.Label {
+ font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.35
+ text: i18n("Welcome to WiVRn")
+ }
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("This wizard will help you set up WiVRn on your headset and connect it to your computer.")
+ }
+
+ Item {
+ Layout.fillHeight: true
+ }
+
+ actions: [
+ Kirigami.Action {
+ text: i18n("Back")
+ icon.name: "go-previous"
+ enabled: false
+ },
+ Kirigami.Action {
+ text: i18n("Next")
+ icon.name: "go-next"
+ onTriggered: pageStack.push(page_install_component.createObject(pageStack))
+ },
+ Kirigami.Action {
+ text: i18n("Cancel")
+ onTriggered: wizard.cancel()
+ }
+ ]
+ }
+ }
+
+ ListModel {
+ id: devmode_url
+ ListElement {
+ manufacturer: "HTC"
+ url: "https://developer.vive.com/resources/hardware-guides/vive-focus-specs-user-guide/how-do-i-put-focus-developer-mode/"
+ }
+ ListElement {
+ manufacturer: "Meta"
+ url: "https://developers.meta.com/horizon/documentation/native/android/mobile-device-setup/#enable-developer-mode"
+ }
+ ListElement {
+ manufacturer: "Pico"
+ url: "https://developer.picoxr.com/document/unreal/test-and-build/#Enable%20developer%20mode"
+ }
+ }
+ Kirigami.Dialog {
+ id: devmode_dialog
+ title: i18n("How to enable developper mode")
+ showCloseButton: false
+ padding: 2 * Kirigami.Units.largeSpacing
+ ColumnLayout {
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("Follow the manufacturer's instructions below:")
+ }
+ Repeater {
+ model: devmode_url
+ delegate: BetterLabel {
+ required property string manufacturer
+ required property string url
+ Layout.fillWidth: true
+ text: "%2".arg(url).arg(manufacturer)
+ }
+ }
+ }
+ }
+ Component {
+ id: page_install_component
+ WizardStep {
+ Controls.Label {
+ font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.35
+ text: i18n("Install the WiVRn app on your headset")
+ }
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("In order to use WiVRn, you will have to install the client app on your headset.\nYou can either install it from the Meta store or directly over USB.")
+ }
+
+ Controls.Label {
+ Layout.topMargin: 4 * Kirigami.Units.largeSpacing
+ font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.35
+ text: i18n("Install from the Meta store")
+ }
+ BetterLabel {
+ Layout.fillWidth: true
+ text: i18n("For the Quest 2, 3, 3S, and Pro, you can get the app from the Meta store.")
+ }
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("Checking latest release...")
+ visible: wizard.checking_newer
+ }
+
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("A newer release is available: %1 → %2, the client app on the Meta store may not be compatible.", ApkInstaller.currentVersion, ApkInstaller.latestVersion)
+ visible: wizard.newer_version
+ }
+
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("This is a nightly build, the client app on the Meta store may not be compatible.")
+ visible: !wizard.is_tagged
+ }
+
+ Controls.Label {
+ font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.5
+ Layout.topMargin: 4 * Kirigami.Units.largeSpacing
+ Layout.bottomMargin: 4 * Kirigami.Units.largeSpacing
+ Layout.preferredWidth: 20 * Kirigami.Units.largeSpacing
+ horizontalAlignment: Qt.AlignHCenter
+ text: i18nc("displayed between 'meta store' and 'install over USB' in the wizard", "Or")
+ }
+
+ Controls.Label {
+ Layout.bottomMargin: 2 * Kirigami.Units.largeSpacing
+ font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.35
+ text: i18n("Install over USB")
+ }
+
+ BetterLabel {
+ Layout.fillWidth: true
+ text: i18n("No precompiled APK is available for this version. Follow the instructions in the documentation to build your own client.")
+ visible: !ApkInstaller.apkAvailable
+ }
+
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("ADB is not installed")
+ visible: device_list.count == 0 && !Adb.adbInstalled
+ }
+
+ // TODO link to adb/udev rules depending on the distribution
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("No headset detected. Make sure that:\n
")
+ onLinkActivated: devmode_dialog.open()
+ MouseArea {
+ anchors.fill: parent
+ cursorShape: (parent as Controls.Label).hoveredLink == "" ? Qt.ArrowCursor : Qt.PointingHandCursor
+ acceptedButtons: Qt.NoButton
+ }
+ visible: device_list.count == 0 && Adb.adbInstalled && ApkInstaller.apkAvailable
+ }
+
+ Repeater {
+ id: device_list
+ model: Adb
+ delegate: DeviceCard {
+ id: device_card
+ required property string serial
+ required property string model
+ required property string manufacturer
+ required property bool isWivrnInstalled
+
+ name: device_card.manufacturer + " " + device_card.model
+ serial_number: device_card.serial
+ is_wivrn_installed: device_card.isWivrnInstalled
+ }
+ visible: ApkInstaller.apkAvailable
+ }
+
+ Item {
+ Layout.fillHeight: true
+ }
+
+ // image: Qt.resolvedUrl("wivrn.svg")
+
+ actions: [
+ Kirigami.Action {
+ text: i18n("Back")
+ icon.name: "go-previous"
+ onTriggered: pageStack.goBack()
+ },
+ Kirigami.Action {
+ text: i18n("Next")
+ icon.name: "go-next"
+ onTriggered: pageStack.push(page_selectgame_component.createObject(pageStack))
+ },
+ Kirigami.Action {
+ text: i18n("Cancel")
+ onTriggered: wizard.cancel()
+ }
+ ]
+ }
+ }
+
+ Component {
+ id: page_selectgame_component
+
+ WizardStep {
+ id: page_selectgame
+
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.35
+ text: i18n("Select the application you want to start")
+ }
+
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("The application you choose will be started automatically when you connect your headset.")
+ Layout.topMargin: 2 * Kirigami.Units.largeSpacing
+ }
+
+ SelectGame {}
+
+ SteamLaunchOptions {
+ Layout.topMargin: 2 * Kirigami.Units.largeSpacing
+ }
+
+ Item {
+ Layout.fillHeight: true
+ }
+
+ actions: [
+ Kirigami.Action {
+ text: i18n("Back")
+ icon.name: "go-previous"
+ onTriggered: pageStack.goBack()
+ },
+ Kirigami.Action {
+ text: i18n("Next")
+ icon.name: "go-next"
+ onTriggered: pageStack.push(page_startwivrn_component.createObject(pageStack))
+ },
+ Kirigami.Action {
+ text: i18n("Cancel")
+ onTriggered: wizard.cancel()
+ }
+ ]
+ }
+ }
+
+ Component {
+ id: page_startwivrn_component
+
+ WizardStep {
+ id: page_startwivrn
+ Component.onCompleted: {
+ WivrnServer.headsetConnectedChanged.connect(onHeadsetConnectedChanged);
+ WivrnServer.pairingEnabledChanged.connect(onCurrentItemChanged_or_PairingEnabledChanged);
+ pageStack.currentItemChanged.connect(onCurrentItemChanged_or_PairingEnabledChanged);
+ }
+
+ function onCurrentItemChanged_or_PairingEnabledChanged() {
+ if (pageStack?.currentItem === page_startwivrn && !WivrnServer.pairingEnabled)
+ WivrnServer.enable_pairing();
+ }
+
+ function onHeadsetConnectedChanged(value) {
+ if (value && pageStack?.currentItem === page_startwivrn)
+ pageStack.push(page_connected_component.createObject(pageStack));
+ }
+
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.35
+ text: i18n("Start the WiVRn app on your headset")
+ }
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("To connect over WiFi, start the WiVRn app on your headset, connect to \"%1\" and enter PIN \"%2\".", WivrnServer.hostname, WivrnServer.pin)
+ }
+
+ RowLayout {
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("To connect over USB, click on \"Connect by USB\".")
+ }
+ Controls.Button {
+ text: i18n("Connect by USB")
+ onClicked: select_usb_device.connect()
+ enabled: select_usb_device.connected_headset_count > 0
+ }
+ }
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ Layout.topMargin: 4 * Kirigami.Units.largeSpacing
+ font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.35
+ text: i18n("Troubleshooting")
+ }
+ BetterLabel {
+ Layout.fillWidth: true
+ text: i18n("If you installed WiVRn over USB on a Meta headset, the app is in the \"unknown sources\" section.")
+ Layout.topMargin: Kirigami.Units.largeSpacing
+ }
+ BetterLabel {
+ Layout.fillWidth: true
+ text: i18n("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.")
+ Layout.topMargin: Kirigami.Units.largeSpacing
+ }
+ Item {
+ Layout.fillHeight: true
+ }
+ actions: [
+ Kirigami.Action {
+ text: i18n("Back")
+ icon.name: "go-previous"
+ onTriggered: pageStack.goBack()
+ },
+ Kirigami.Action {
+ text: i18n("Skip")
+ // icon.name: "go-next"
+ onTriggered: pageStack.push(page_connection_skipped_component.createObject(pageStack))
+ },
+ Kirigami.Action {
+ text: i18n("Cancel")
+ onTriggered: wizard.cancel()
+ }
+ ]
+ }
+ }
+
+ Component {
+ id: page_connected_component
+ WizardStep {
+ id: page_connected
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.35
+ text: i18n("Connection established")
+ }
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("Your headset is now connected.")
+ }
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("To connect another headset, make sure pairing is enabled in the dashboard before connecting.")
+ }
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("When the headset is connected, select \"WiVRn\" as the default audio output device for applications to use it.")
+ }
+ Item {
+ Layout.fillHeight: true
+ }
+ actions: [
+ Kirigami.Action {
+ text: i18n("Back")
+ icon.name: "go-previous"
+ onTriggered: pageStack.goBack()
+ },
+ Kirigami.Action {
+ text: i18n("Next")
+ icon.name: "go-next"
+ enabled: false
+ },
+ Kirigami.Action {
+ text: i18n("Finish")
+ onTriggered: wizard.cancel()
+ }
+ ]
+ }
+ }
+
+ Component {
+ id: page_connection_skipped_component
+ WizardStep {
+ id: page_finished
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ font.pointSize: Kirigami.Theme.defaultFont.pointSize * 1.35
+ text: i18n("Finished")
+ }
+ Controls.Label {
+ Layout.fillWidth: true
+ wrapMode: Text.WordWrap
+ text: i18n("To connect another headset, make sure pairing is enabled in the dashboard before connecting.")
+ }
+ Item {
+ Layout.fillHeight: true
+ }
+ actions: [
+ Kirigami.Action {
+ text: i18n("Back")
+ icon.name: "go-previous"
+ onTriggered: pageStack.goBack()
+ },
+ Kirigami.Action {
+ text: i18n("Next")
+ icon.name: "go-next"
+ enabled: false
+ },
+ Kirigami.Action {
+ text: i18n("Finish")
+ onTriggered: wizard.cancel()
+ }
+ ]
+ }
+ }
+
+ Kirigami.PageRow {
+ id: pageStack
+ globalToolBar.style: Kirigami.ApplicationHeaderStyle.Auto
+ anchors.fill: parent
+ focus: true
+
+ globalToolBar {
+ showNavigationButtons: Kirigami.ApplicationHeaderStyle.NoNavigationButtons
+ // style: Kirigami.ApplicationHeaderStyle.None
+ }
+
+ defaultColumnWidth: width // Force non-wide mode
+ interactive: false // Don't let the back/forward mouse button handle the pagestack
+ popHiddenPages: true // pop hidden pages and use goBack() instead of pop() to animate the pages correctly when going back
+
+ initialPage: page_welcome_component.createObject(pageStack)
+ }
+
+ footer: Item {
+ Layout.fillWidth: true
+ implicitHeight: footer_row.implicitHeight + 2 * Kirigami.Units.largeSpacing
+
+ ColumnLayout {
+ id: footer_row
+ anchors.fill: parent
+ Kirigami.Separator {
+ Layout.fillWidth: true
+ }
+ RowLayout {
+ Layout.leftMargin: Kirigami.Units.largeSpacing
+ Layout.rightMargin: Kirigami.Units.largeSpacing
+
+ spacing: Kirigami.Units.largeSpacing
+
+ Item {
+ // spacer item
+ Layout.fillWidth: true
+ }
+
+ Repeater {
+ model: (pageStack.trailingVisibleItem as WizardStep)?.actions
+ Controls.Button {
+ required property Kirigami.Action modelData
+ action: modelData
+ // enabled: pageStack.trailingVisibleItem == pageStack.leadingVisibleItem && modelData.enabled
+ visible: modelData.visible
+ }
+ }
+ }
+ }
+ }
+
+ function cancel() {
+ applicationWindow().pageStack.pop();
+ }
+}
diff --git a/dashboard/qml/WizardStep.qml b/dashboard/qml/WizardStep.qml
new file mode 100644
index 00000000..afb3332b
--- /dev/null
+++ b/dashboard/qml/WizardStep.qml
@@ -0,0 +1,30 @@
+import QtQuick
+import QtQuick.Layouts
+import org.kde.kirigami as Kirigami
+
+Kirigami.Page {
+ default property alias content: inner.children
+ property alias image: img.source
+
+ property list actions
+
+ globalToolBarStyle: Kirigami.ApplicationHeaderStyle.None
+ RowLayout {
+ anchors.fill: parent
+ ColumnLayout {
+ Image {
+ id: img
+ source: Qt.resolvedUrl("wivrn.svg")
+ }
+ Item {
+ Layout.fillHeight: true
+ }
+ }
+
+ ColumnLayout {
+ id: inner
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ }
+ }
+}
diff --git a/dashboard/rectangle_partitionner.cpp b/dashboard/rectangle_partitionner.cpp
new file mode 100644
index 00000000..68bc5801
--- /dev/null
+++ b/dashboard/rectangle_partitionner.cpp
@@ -0,0 +1,21 @@
+/*
+ * 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 "moc_rectangle_partitionner.cpp"
diff --git a/dashboard/rectangle_partitionner.h b/dashboard/rectangle_partitionner.h
new file mode 100644
index 00000000..b2373bc4
--- /dev/null
+++ b/dashboard/rectangle_partitionner.h
@@ -0,0 +1,935 @@
+/*
+ * 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
+#include
+#include
+#include
+
+#include "settings.h"
+#include
+
+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
+{
+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);
+
+QRectF rectangle_from_encoder(const encoder & enc)
+{
+ QRectF r;
+ r.setX(enc.offset_x);
+ r.setY(enc.offset_y);
+ r.setWidth(enc.width);
+ r.setHeight(enc.height);
+ return r;
+}
+
+int hovered_rectangle(QPointF position, const std::vector & encoders)
+{
+ for (const auto [i, enc]: std::views::enumerate(encoders))
+ {
+ if (rectangle_from_encoder(enc).contains(position))
+ return i;
+ }
+
+ return -1;
+}
+
+Qt::CursorShape get_cursor_shape(QPointF position, const std::vector & rectangles)
+{
+ for (const encoder & i: rectangles)
+ {
+ QRectF r = rectangle_from_encoder(i);
+ if (r.contains(position))
+ {
+ QPointF rel_pos = position - r.topLeft();
+ double dx = std::min(rel_pos.x(), r.width() - rel_pos.x());
+ double dy = std::min(rel_pos.y(), r.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(const std::vector & rectangles)
+{
+ std::vector edges;
+
+ for (const auto & [i, enc]: std::views::enumerate(rectangles))
+ {
+ if (enc.top() > epsilon)
+ {
+ edges.emplace_back(side::top, i, enc.top(), enc.left(), enc.right());
+ }
+
+ if (rectangles[i].bottom() < 1 - epsilon)
+ {
+ edges.emplace_back(side::bottom, i, enc.bottom(), enc.left(), enc.right());
+ }
+ }
+
+ return edges;
+}
+
+std::vector vertical_edges(const std::vector & rectangles)
+{
+ std::vector edges;
+
+ for (const auto & [i, enc]: std::views::enumerate(rectangles))
+ {
+ if (enc.left() > epsilon)
+ {
+ edges.emplace_back(side::left, i, enc.left(), enc.top(), enc.bottom());
+ }
+
+ if (enc.right() < 1 - epsilon)
+ {
+ edges.emplace_back(side::right, i, enc.right(), enc.top(), enc.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 (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;
+ }
+ }
+ }
+
+ return ok;
+}
+} // namespace
+
+class RectanglePartitionner : public QQuickPaintedItem
+{
+ Q_OBJECT
+ QML_ELEMENT
+
+ Q_PROPERTY(Settings * settings READ settings WRITE setSettings NOTIFY settingsChanged)
+ Q_PROPERTY(bool selected READ selected NOTIFY selectedChanged)
+ Q_PROPERTY(QString encoder READ encoder WRITE setEncoder NOTIFY encoderChanged)
+ Q_PROPERTY(QString codec READ codec WRITE setCodec NOTIFY codecChanged)
+ Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
+
+ int m_currentIndex = -1;
+ Settings * m_settings = nullptr;
+
+ std::vector selection;
+ std::vector hovered;
+
+ double min_drag_position;
+ double max_drag_position;
+
+ QLine split_line;
+ QRect split_clip_rect;
+ Qt::CursorShape cursor_shape = Qt::ArrowCursor;
+
+ enum class mouse_event_type
+ {
+ move,
+ press,
+ release
+ };
+
+ Kirigami::Platform::PlatformTheme theme;
+
+public:
+ RectanglePartitionner(QQuickItem * parent = nullptr) :
+ QQuickPaintedItem(parent),
+ theme(this)
+ {
+ setFlag(ItemHasContents);
+ setAcceptedMouseButtons(Qt::LeftButton);
+ setAcceptHoverEvents(true);
+
+ theme.setColorSet(Kirigami::Platform::PlatformTheme::View);
+ setFillColor(theme.backgroundColor());
+
+ connect(&theme, &Kirigami::Platform::PlatformTheme::colorsChanged, this, [&]() {
+ setFillColor(theme.backgroundColor());
+ update();
+ });
+
+ // connect(this, &QQuickItem::enabledChanged, this, [&](){
+ // if (isEnabled())
+ // theme.setColorGroup(Kirigami::Platform::PlatformTheme::Active);
+ // else
+ // theme.setColorGroup(Kirigami::Platform::PlatformTheme::Disabled);
+ // });
+ }
+
+ int currentIndex() const
+ {
+ return m_currentIndex;
+ }
+
+ bool selected() const
+ {
+ return m_currentIndex >= 0 and m_currentIndex < m_settings->encoders().size();
+ }
+
+ void setCurrentIndex(int value)
+ {
+ if (m_currentIndex != value)
+ {
+ m_currentIndex = value;
+ currentIndexChanged(value);
+ selectedChanged(selected());
+ encoderChanged(encoder());
+ codecChanged(codec());
+
+ update();
+ }
+ }
+
+ Settings * settings() const
+ {
+ return m_settings;
+ }
+
+ void onEncodersChanged()
+ {
+ update();
+ }
+
+ void setSettings(Settings * value)
+ {
+ if (m_settings != value)
+ {
+ if (m_settings)
+ disconnect(m_settings, &Settings::encodersChanged, this, &RectanglePartitionner::onEncodersChanged);
+
+ settingsChanged(m_settings = value);
+
+ if (m_settings)
+ connect(m_settings, &Settings::encodersChanged, this, &RectanglePartitionner::onEncodersChanged);
+ }
+ }
+
+ QString encoder() const
+ {
+ if (not m_settings or m_currentIndex < 0 or m_currentIndex >= m_settings->encoders().size())
+ return "";
+
+ return QString::fromStdString(Settings::encoder_from_id(m_settings->encoders()[m_currentIndex].name));
+ }
+
+ QString codec() const
+ {
+ if (not m_settings or m_currentIndex < 0 or m_currentIndex >= m_settings->encoders().size())
+ return "";
+
+ return QString::fromStdString(Settings::codec_from_id(m_settings->encoders()[m_currentIndex].codec));
+ }
+
+ void setEncoder(QString value)
+ {
+ qDebug() << "Setting encoder to " << value;
+ auto encoders = m_settings->encoders();
+ auto converted_value = Settings::encoder_id_from_string(value.toStdString());
+
+ if (not m_settings or m_currentIndex < 0 or m_currentIndex >= encoders.size())
+ return;
+
+ if (encoders[m_currentIndex].name == converted_value)
+ return;
+
+ encoders[m_currentIndex].name = converted_value;
+ m_settings->set_encoders(encoders);
+ update();
+ encoderLayoutChanged();
+ }
+
+ void setCodec(QString value)
+ {
+ qDebug() << "Setting codec to " << value;
+ auto encoders = m_settings->encoders();
+ auto converted_value = Settings::codec_id_from_string(value.toStdString());
+
+ if (not m_settings or m_currentIndex < 0 or m_currentIndex >= encoders.size())
+ return;
+
+ if (encoders[m_currentIndex].codec == converted_value)
+ return;
+
+ encoders[m_currentIndex].codec = Settings::codec_id_from_string(value.toStdString());
+ m_settings->set_encoders(encoders);
+ update();
+ encoderLayoutChanged();
+ }
+
+ QRect frameRect()
+ {
+ return {0, 0, (int)width() - 1, (int)height() - 1};
+ }
+
+ QPointF from_position(QPoint position)
+ {
+ auto r = frameRect();
+
+ 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 to_position(QPointF position)
+ {
+ auto r = frameRect();
+
+ return QPoint(
+ std::round(r.x() + position.x() * (r.width() - 1)),
+ std::round(r.y() + position.y() * (r.height() - 1)));
+ }
+
+ QRect to_position(QRectF position)
+ {
+ return QRect{to_position(position.topLeft()), to_position(position.bottomRight())};
+ }
+
+ QRect rectangle_position(int index)
+ {
+ return to_position(rectangle_from_encoder(m_settings->encoders().at(index)));
+ }
+
+ // Keep it in sync with SettingsPage.qml (codec_combo.model)
+ QString codec_name_from_setting(QString value)
+ {
+ if (value == "h264")
+ return i18n("H.264");
+ if (value == "h265")
+ return i18n("H.265");
+ if (value == "av1")
+ return i18n("AV1");
+
+ return i18nc("automatic codec setup", "Auto");
+ }
+
+ // Keep it in sync with SettingsPage.qml (encoder_combo.model)
+ QString encoder_name_from_setting(QString value)
+ {
+ if (value == "nvenc")
+ return i18n("nvenc");
+ if (value == "vaapi")
+ return i18n("vaapi");
+ if (value == "x264")
+ return i18n("x264");
+ if (value == "vulkan")
+ return i18n("Vulkan");
+
+ return i18nc("automatic encoder setup", "Auto");
+ }
+
+ // BEGIN Painting functions
+ void paint_single_rectangle_border(QPainter * painter, const ::encoder & enc)
+ {
+ QRectF r = rectangle_from_encoder(enc);
+ QRect rect = to_position(r);
+
+ QPen pen = painter->pen();
+ painter->setPen(QPen{theme.disabledTextColor()});
+ painter->drawRect(rect);
+ painter->setPen(pen);
+ }
+
+ void paint_single_rectangle(QPainter * painter, const ::encoder & enc, bool selected)
+ {
+ QRectF r = rectangle_from_encoder(enc);
+ QRect rect = to_position(r);
+
+ if (selected)
+ {
+ painter->fillRect(rect.adjusted(1, 1, 0, 0), theme.focusColor());
+ }
+
+ QString codec = QString::fromStdString(Settings::codec_from_id(enc.codec));
+ QString encoder = QString::fromStdString(Settings::encoder_from_id(enc.name));
+
+ QFont font = painter->font();
+ QFont font2 = font;
+
+ font2.setPixelSize(24);
+
+ QString text = QString("%1\n%2").arg(encoder_name_from_setting(encoder), codec_name_from_setting(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);
+ }
+
+ QPen pen = painter->pen();
+
+ painter->setPen(QPen{theme.textColor()});
+ painter->setFont(font2);
+ painter->drawText(rect, Qt::AlignCenter, text);
+ painter->setFont(font);
+ painter->setPen(pen);
+ }
+
+ void paint(QPainter * painter) override
+ {
+ if (not m_settings)
+ return;
+
+ for (auto [i, enc]: std::views::enumerate(m_settings->encoders()))
+ {
+ bool is_selected = i == m_currentIndex and isEnabled();
+ paint_single_rectangle(painter, enc, is_selected);
+ }
+
+ if (not hovered.empty() and selection.empty())
+ {
+ for (auto & enc: m_settings->encoders())
+ {
+ paint_single_rectangle_border(painter, enc);
+ }
+
+ painter->setPen(QPen(Qt::blue, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
+
+ auto r = frameRect();
+
+ QList lines;
+ lines.reserve(hovered.size());
+ for (const edge & i: 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_settings->encoders()));
+ auto vert_partitionned = partition_edges(vertical_edges(m_settings->encoders()));
+ }
+ else if ((cursor_shape == Qt::SplitHCursor or cursor_shape == Qt::SplitVCursor) and not split_line.isNull())
+ {
+ auto now = std::chrono::duration_cast>(std::chrono::steady_clock::now().time_since_epoch()).count();
+
+ QPen pen(theme.disabledTextColor(), 2, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin);
+ pen.setDashPattern({5, 5});
+ pen.setDashOffset(-now * 15);
+ painter->setPen(pen);
+
+ painter->setClipping(true);
+ painter->setClipRect(split_clip_rect.adjusted(1, 1, 0, 0));
+ painter->drawLine(split_line);
+ painter->setClipping(false);
+ update();
+
+ for (auto & enc: m_settings->encoders())
+ {
+ paint_single_rectangle_border(painter, enc);
+ }
+ }
+ else
+ {
+ for (auto & enc: m_settings->encoders())
+ {
+ paint_single_rectangle_border(painter, enc);
+ }
+ }
+ }
+ // END Painting functions
+
+ // BEGIN Mouse callbacks
+ void mouseMoveEvent(QMouseEvent * event) override
+ {
+ auto pos = event->position().toPoint();
+
+ auto encoders = m_settings->encoders();
+
+ if (not selection.empty())
+ {
+ double position;
+
+ if (selection.front().edge_side == side::top or selection.front().edge_side == side::bottom)
+ position = from_position(pos).y();
+ else
+ position = from_position(pos).x();
+
+ position = std::clamp(position, min_drag_position, max_drag_position);
+ position = std::round(position * num_subdiv) / num_subdiv; // magnetism
+
+ for (edge & e: selection)
+ {
+ switch (e.edge_side)
+ {
+ case side::top:
+ encoders[e.rectangle_index].set_top(position);
+ break;
+
+ case side::bottom:
+ encoders[e.rectangle_index].set_bottom(position);
+ break;
+
+ case side::left:
+ encoders[e.rectangle_index].set_left(position);
+ break;
+
+ case side::right:
+ encoders[e.rectangle_index].set_right(position);
+ break;
+ }
+ }
+
+ update();
+ m_settings->set_encoders(encoders);
+ encoderLayoutChanged();
+ }
+ }
+
+ void hoverMoveEvent(QHoverEvent * event) override
+ {
+ if (not m_settings)
+ return;
+
+ QPoint pos = event->position().toPoint();
+
+ const auto & encoders = m_settings->encoders();
+
+ hovered.clear();
+
+ if (auto horz_edges = hovered_edges(from_position(pos), partition_edges(horizontal_edges(encoders)), true); not horz_edges.empty())
+ {
+ hovered = std::move(horz_edges);
+ update();
+ }
+ else if (auto vert_edges = hovered_edges(from_position(pos), partition_edges(vertical_edges(encoders)), false); not vert_edges.empty())
+ {
+ hovered = std::move(vert_edges);
+ update();
+ }
+ else
+ {
+ int n = hovered_rectangle(from_position(pos), encoders);
+ }
+
+ Qt::CursorShape new_cursor = get_cursor_shape(from_position(pos), encoders);
+ if (new_cursor != cursor_shape)
+ {
+ update();
+ cursor_shape = new_cursor;
+ setCursor(QCursor(new_cursor));
+ }
+
+ if (cursor_shape == Qt::SplitHCursor)
+ {
+ int n = hovered_rectangle(from_position(pos), encoders);
+
+ double x = std::round(from_position(pos).x() * num_subdiv) / num_subdiv; // magnetism
+ int px = to_position({x, 0}).x();
+
+ split_line = {px, rectangle_position(n).top(), px, rectangle_position(n).bottom()};
+ split_clip_rect = rectangle_position(n);
+ update();
+ }
+ else if (cursor_shape == Qt::SplitVCursor)
+ {
+ int n = hovered_rectangle(from_position(pos), encoders);
+
+ double y = std::round(from_position(pos).y() * num_subdiv) / num_subdiv; // magnetism
+ int py = to_position({0, y}).y();
+
+ split_line = {rectangle_position(n).left(), py, rectangle_position(n).right(), py};
+ split_clip_rect = rectangle_position(n);
+ update();
+ }
+ else
+ {
+ split_line = {0, 0, 0, 0};
+ split_clip_rect = {0, 0, 0, 0};
+ }
+ }
+
+ void mousePressEvent(QMouseEvent * event) override
+ {
+ if (not m_settings)
+ return;
+
+ selection.clear();
+ split_line = {0, 0, 0, 0};
+ auto encoders = m_settings->encoders();
+
+ if (auto horz_edges = hovered_edges(from_position(event->pos()), partition_edges(horizontal_edges(encoders)), true); not horz_edges.empty())
+ {
+ selection = std::move(horz_edges);
+ }
+ else if (auto vert_edges = hovered_edges(from_position(event->pos()), partition_edges(vertical_edges(encoders)), false); not vert_edges.empty())
+ {
+ selection = std::move(vert_edges);
+ }
+ else if (int n = hovered_rectangle(from_position(event->pos()), encoders); n >= 0)
+ {
+ ::encoder & hovered = encoders[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)
+ {
+ qDebug() << "Splitting rectangle " << n << " vertically";
+ double y = std::round(pos.y() * num_subdiv) / num_subdiv; // magnetism
+
+ // Split vertically
+ ::encoder new_rectangle = hovered;
+
+ hovered.set_bottom(y);
+ new_rectangle.set_top(hovered.bottom());
+
+ encoders.push_back(new_rectangle);
+ update();
+ m_settings->set_encoders(encoders);
+ encoderLayoutChanged();
+
+ if (not assert_rectangle_list_is_partition(encoders))
+ abort();
+ }
+ else if (dy < split_edge_threshold)
+ {
+ qDebug() << "Splitting rectangle " << n << " horizontally";
+ double x = std::round(pos.x() * num_subdiv) / num_subdiv; // magnetism
+
+ // Split horizontally
+ ::encoder new_rectangle = hovered;
+
+ hovered.set_right(x);
+ new_rectangle.set_left(hovered.right());
+
+ encoders.push_back(new_rectangle);
+ update();
+ m_settings->set_encoders(encoders);
+ encoderLayoutChanged();
+
+ if (not assert_rectangle_list_is_partition(encoders))
+ abort();
+ }
+ else
+ {
+ qDebug() << "Selecting rectangle " << n;
+ setCurrentIndex(n);
+ }
+ }
+
+ if (not selection.empty())
+ {
+ hovered.clear();
+
+ min_drag_position = std::numeric_limits::lowest();
+ max_drag_position = std::numeric_limits::max();
+
+ for (auto & e: selection)
+ {
+ switch (e.edge_side)
+ {
+ case side::top:
+ max_drag_position = std::min(max_drag_position, encoders[e.rectangle_index].bottom());
+ break;
+ case side::bottom:
+ min_drag_position = std::max(min_drag_position, encoders[e.rectangle_index].top());
+ break;
+ case side::left:
+ max_drag_position = std::min(max_drag_position, encoders[e.rectangle_index].right());
+ break;
+ case side::right:
+ min_drag_position = std::max(min_drag_position, encoders[e.rectangle_index].left());
+ break;
+ }
+ }
+ }
+ }
+
+ void mouseReleaseEvent(QMouseEvent * event) override
+ {
+ if (not m_settings)
+ return;
+
+ selection.clear();
+ auto encoders = m_settings->encoders();
+
+ // Delete empty rectangles
+ bool changed = false;
+ for (int i = 0; i < encoders.size();)
+ {
+ if (encoders[i].width <= 0.0001 or encoders[i].height <= 0.0001) // TODO configurable thresholds
+ {
+ qDebug() << "Removing rectangle " << i;
+ encoders.erase(encoders.begin() + i);
+ changed = true;
+
+ if (m_currentIndex > i)
+ m_currentIndex--;
+ else if (m_currentIndex == i)
+ {
+ m_currentIndex = -1;
+ }
+ }
+ else
+ {
+ ++i;
+ }
+ }
+
+ if (changed)
+ {
+ if (not assert_rectangle_list_is_partition(encoders))
+ abort();
+
+ m_settings->set_encoders(encoders);
+ setCurrentIndex(m_currentIndex);
+ update();
+ encoderLayoutChanged();
+ }
+ }
+
+ void hoverLeaveEvent(QHoverEvent * event) override
+ {
+ hovered.clear();
+ split_line = {0, 0, 0, 0};
+ split_clip_rect = {0, 0, 0, 0};
+ update();
+ }
+ // END Mouse callbacks
+
+Q_SIGNALS:
+ void settingsChanged(Settings *);
+ void selectedChanged(bool);
+ void encoderChanged(QString);
+ void codecChanged(QString);
+ void currentIndexChanged(int);
+
+ void encoderLayoutChanged();
+};
diff --git a/dashboard/settings.cpp b/dashboard/settings.cpp
new file mode 100644
index 00000000..066a160c
--- /dev/null
+++ b/dashboard/settings.cpp
@@ -0,0 +1,321 @@
+/*
+ * 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 "wivrn_server.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace
+{
+const std::vector> encoder_ids{
+ {encoder::encoder_name::nvenc, "nvenc"},
+ {encoder::encoder_name::vaapi, "vaapi"},
+ {encoder::encoder_name::x264, "x264"},
+ {encoder::encoder_name::vulkan, "vulkan"},
+};
+
+const std::vector> codec_ids{
+ {encoder::video_codec::h264, "h264"},
+ {encoder::video_codec::h264, "avc"},
+ {encoder::video_codec::h265, "h265"},
+ {encoder::video_codec::h265, "hevc"},
+ {encoder::video_codec::av1, "av1"},
+ {encoder::video_codec::av1, "AV1"},
+};
+} // namespace
+
+std::optional Settings::encoder_id_from_string(std::string_view s)
+{
+ for (auto & [i, j]: encoder_ids)
+ {
+ if (j == s)
+ return i;
+ }
+ return std::nullopt;
+}
+
+std::optional Settings::codec_id_from_string(std::string_view s)
+{
+ for (auto & [i, j]: codec_ids)
+ {
+ if (j == s)
+ return i;
+ }
+ return std::nullopt;
+}
+
+const std::string & Settings::encoder_from_id(std::optional id)
+{
+ static const std::string default_value = "auto";
+ if (not id)
+ return default_value;
+
+ for (auto & [i, j]: encoder_ids)
+ {
+ if (i == *id)
+ return j;
+ }
+
+ return default_value;
+}
+
+const std::string & Settings::codec_from_id(std::optional id)
+{
+ static const std::string default_value = "auto";
+ if (not id)
+ return default_value;
+
+ for (auto & [i, j]: codec_ids)
+ {
+ if (i == *id)
+ return j;
+ }
+
+ return default_value;
+}
+
+void Settings::load(const wivrn_server * server)
+{
+ // Encoders configuration
+ nlohmann::json json_doc;
+ try
+ {
+ auto conf = server->jsonConfiguration();
+ json_doc = nlohmann::json::parse(conf.toUtf8());
+ }
+ catch (std::exception & e)
+ {
+ qWarning() << "Cannot read configuration: " << e.what();
+ restore_defaults();
+ return;
+ }
+
+ std::vector new_encoders;
+ try
+ {
+ nlohmann::json json_encoders;
+
+ if (json_doc.contains("encoders"))
+ {
+ json_encoders = json_doc["encoders"];
+ set_manualEncoders(true);
+ }
+ else if (json_doc.contains("encoders.disabled"))
+ {
+ json_encoders = json_doc["encoders.disabled"];
+ set_manualEncoders(false);
+ }
+ else
+ {
+ set_manualEncoders(false);
+ }
+
+ for (auto & i: json_encoders)
+ {
+ encoder enc;
+ enc.name = encoder_id_from_string(i.value("encoder", "auto"));
+ enc.codec = codec_id_from_string(i.value("codec", "auto"));
+ enc.width = i.value("width", 1.0);
+ enc.height = i.value("height", 1.0);
+ enc.offset_x = i.value("offset_x", 0.0);
+ enc.offset_y = i.value("offset_y", 0.0);
+ enc.group = i.value("group", 0); // TODO: handle groups
+ new_encoders.push_back(enc);
+ }
+ }
+ 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();
+
+ new_encoders.clear();
+ }
+ set_encoders(new_encoders);
+
+ if (encoders().empty())
+ {
+ set_manualEncoders(false);
+ std::vector new_encoders;
+ new_encoders.push_back(encoder{
+ .width = 1,
+ .height = 1,
+ .offset_x = 0,
+ .offset_y = 0,
+ });
+ set_encoders(new_encoders);
+ }
+
+ // Foveation
+ try
+ {
+ if (json_doc.contains("scale"))
+ {
+ set_scale(json_doc.value("scale", 1.0));
+ }
+ else
+ {
+ set_scale(-1);
+ }
+ }
+ catch (...)
+ {
+ set_scale(-1);
+ }
+
+ // Bitrate
+ try
+ {
+ set_bitrate(json_doc.value("bitrate", 50'000'000));
+ }
+ catch (...)
+ {
+ set_bitrate(50'000'000);
+ }
+
+ // 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"]);
+
+ set_application(escape_string(application));
+ }
+ catch (...)
+ {
+ set_application("");
+ }
+}
+
+void Settings::save(wivrn_server * server)
+{
+ nlohmann::json json_doc;
+ try
+ {
+ auto conf = server->jsonConfiguration();
+ json_doc = nlohmann::json::parse(conf.toUtf8());
+ }
+ catch (...)
+ {
+ }
+
+ // 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 (scale() > 0)
+ json_doc["scale"] = scale();
+
+ json_doc["bitrate"] = bitrate();
+
+ std::vector encoders;
+
+ for (auto & enc: m_encoders)
+ {
+ nlohmann::json encoder;
+
+ if (auto value = encoder_from_id(enc.name); value != "auto")
+ encoder["encoder"] = value;
+ if (auto value = codec_from_id(enc.codec); value != "auto")
+ encoder["codec"] = value;
+ encoder["width"] = enc.width;
+ encoder["height"] = enc.height;
+ encoder["offset_x"] = enc.offset_x;
+ encoder["offset_y"] = enc.offset_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 (manualEncoders())
+ json_doc["encoders"] = encoders;
+ else
+ json_doc["encoders.disabled"] = encoders;
+
+ if (application() != "")
+ json_doc["application"] = unescape_string(application());
+
+ server->setJsonConfiguration(QString::fromStdString(json_doc.dump(2)));
+}
+
+void Settings::restore_defaults()
+{
+ set_encoders({});
+ set_encoderPassthrough({});
+ set_bitrate(50'000'000);
+ set_scale(-1);
+ set_application("");
+ set_tcpOnly(false);
+}
+
+void Settings::set_encoder_preset(QJSValue preset)
+{
+ QJSEngine engine;
+ const QJsonArray json_encoders = engine.fromScriptValue(preset).toArray();
+
+ std::vector encoders;
+ for (const QJsonValue & json_encoder_value: json_encoders)
+ {
+ QJsonObject json_encoder = json_encoder_value.toObject();
+
+ encoders.push_back(encoder{
+ .name = encoder_id_from_string(json_encoder["encoder"].toString("auto").toStdString()),
+ .width = json_encoder["width"].toDouble(),
+ .height = json_encoder["height"].toDouble(),
+ .offset_x = json_encoder["offset_x"].toDouble(),
+ .offset_y = json_encoder["offset_y"].toDouble(),
+ .codec = codec_id_from_string(json_encoder["codec"].toString("auto").toStdString()),
+ });
+ }
+
+ set_manualEncoders(true);
+ set_encoders(encoders);
+}
+
+#include "moc_settings.cpp"
diff --git a/dashboard/settings.h b/dashboard/settings.h
new file mode 100644
index 00000000..bd53f3f3
--- /dev/null
+++ b/dashboard/settings.h
@@ -0,0 +1,150 @@
+/*
+ * 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
+
+#define SETTER_GETTER_NOTIFY(type, prop_name) \
+private: \
+ type m_##prop_name; \
+ \
+public: \
+ const type & prop_name() const \
+ { \
+ return m_##prop_name; \
+ } \
+ void set_##prop_name(const type & value) \
+ { \
+ m_##prop_name = value; \
+ prop_name##Changed(value); \
+ } \
+Q_SIGNALS: \
+ void prop_name##Changed(const type &);
+
+class wivrn_server;
+
+struct encoder
+{
+ enum class video_codec
+ {
+ h264,
+ h265,
+ av1,
+ };
+
+ enum class encoder_name
+ {
+ nvenc,
+ vaapi,
+ x264,
+ vulkan
+ };
+
+ std::optional name;
+ double width;
+ double height;
+ double offset_x;
+ double offset_y;
+ std::optional group;
+ std::optional codec;
+ std::map options;
+ std::optional device;
+
+ double top() const
+ {
+ return offset_y;
+ }
+ void set_top(double value)
+ {
+ height = bottom() - value;
+ offset_y = value;
+ }
+
+ double bottom() const
+ {
+ return offset_y + height;
+ }
+ void set_bottom(double value)
+ {
+ height = value - top();
+ }
+
+ double left() const
+ {
+ return offset_x;
+ }
+ void set_left(double value)
+ {
+ width = right() - value;
+ offset_x = value;
+ }
+
+ double right() const
+ {
+ return offset_x + width;
+ }
+ void set_right(double value)
+ {
+ width = value - left();
+ }
+};
+
+class Settings : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+
+ Q_PROPERTY(bool manualEncoders READ manualEncoders WRITE set_manualEncoders NOTIFY manualEncodersChanged)
+ Q_PROPERTY(std::vector encoders READ encoders WRITE set_encoders NOTIFY encodersChanged)
+ Q_PROPERTY(encoder encoderPassthrough READ encoderPassthrough WRITE set_encoderPassthrough NOTIFY encoderPassthroughChanged)
+ Q_PROPERTY(int bitrate READ bitrate WRITE set_bitrate NOTIFY bitrateChanged)
+ Q_PROPERTY(float scale READ scale WRITE set_scale NOTIFY scaleChanged)
+ Q_PROPERTY(QString application READ application WRITE set_application NOTIFY applicationChanged)
+ Q_PROPERTY(bool tcpOnly READ tcpOnly WRITE set_tcpOnly NOTIFY tcpOnlyChanged)
+
+ SETTER_GETTER_NOTIFY(bool, manualEncoders)
+ SETTER_GETTER_NOTIFY(std::vector, encoders)
+ SETTER_GETTER_NOTIFY(encoder, encoderPassthrough)
+ SETTER_GETTER_NOTIFY(int, bitrate)
+ SETTER_GETTER_NOTIFY(float, scale)
+ SETTER_GETTER_NOTIFY(QString, application)
+ SETTER_GETTER_NOTIFY(bool, tcpOnly)
+
+public:
+ Settings(QObject * parent = nullptr) :
+ QObject(parent) {}
+
+ Q_INVOKABLE void load(const wivrn_server * server);
+ Q_INVOKABLE void save(wivrn_server * server);
+ Q_INVOKABLE void restore_defaults();
+ Q_INVOKABLE void set_encoder_preset(QJSValue preset);
+
+ static std::optional encoder_id_from_string(std::string_view s);
+ static std::optional codec_id_from_string(std::string_view s);
+ static const std::string & encoder_from_id(std::optional id);
+ static const std::string & codec_from_id(std::optional id);
+};
+
+#undef SETTER_GETTER_NOTIFY
diff --git a/dashboard/steam_apps.cpp b/dashboard/steam_apps.cpp
new file mode 100644
index 00000000..0fd18ed4
--- /dev/null
+++ b/dashboard/steam_apps.cpp
@@ -0,0 +1,112 @@
+/*
+ * 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_apps.h"
+#include "escape_string.h"
+#include "utils/flatpak.h"
+#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
+
+SteamApps::SteamApps(QObject * parent)
+{
+ auto manifest = read_vr_manifest();
+ if (manifest.empty())
+ {
+ return;
+ }
+
+ nlohmann::json json;
+ try
+ {
+ json = nlohmann::json::parse(manifest);
+ }
+ catch (std::exception & e)
+ {
+ qWarning() << "Error parsing VR manifest: " << e.what();
+ return;
+ }
+
+ for (auto & i: json["applications"])
+ {
+ try
+ {
+ steamApp app;
+
+ app.setImagePath(i.value("image_path", ""));
+ app.setName(i["strings"]["en_us"]["name"]);
+
+ if (i["launch_type"] == "url")
+ {
+ app.setCommand("steam " + (std::string)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.setCommand("steam steam://rungameid/" + std::to_string((appkey << 32) + 0x2000000));
+ }
+ }
+
+ if (app.command() != "")
+ m_apps.push_back(app);
+ }
+ catch (std::exception & e)
+ {
+ qWarning() << "Error adding app from VR manifest: " << e.what();
+ }
+ }
+
+ std::ranges::sort(m_apps, [](const steamApp & a, const steamApp & b) {
+ return a.name() < b.name();
+ });
+}
+
+#include "moc_steam_apps.cpp"
diff --git a/dashboard/steam_apps.h b/dashboard/steam_apps.h
new file mode 100644
index 00000000..d76a8b39
--- /dev/null
+++ b/dashboard/steam_apps.h
@@ -0,0 +1,108 @@
+/*
+ * 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
+
+class steamApp
+{
+ Q_GADGET
+ QML_VALUE_TYPE(steamApp)
+ QML_ELEMENT
+ Q_PROPERTY(QString name READ name WRITE setName)
+ Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath)
+ Q_PROPERTY(QString command READ command WRITE setCommand)
+
+ QString m_name;
+ QString m_imagePath;
+ QString m_command;
+
+public:
+ steamApp() = default;
+ steamApp(const steamApp &) = default;
+ steamApp(steamApp &&) = default;
+ steamApp & operator=(const steamApp &) = default;
+ steamApp & operator=(steamApp &&) = default;
+ steamApp(QString name, QString imagePath, QString command) :
+ m_name(name), m_imagePath(imagePath), m_command(command) {}
+
+ QString name() const
+ {
+ return m_name;
+ }
+
+ QString imagePath() const
+ {
+ return m_imagePath;
+ }
+
+ QString command() const
+ {
+ return m_command;
+ }
+
+ void setName(QString value)
+ {
+ m_name = value;
+ }
+
+ void setImagePath(QString value)
+ {
+ m_imagePath = value;
+ }
+
+ void setCommand(QString value)
+ {
+ m_command = value;
+ }
+
+ void setName(const std::string & value)
+ {
+ m_name = QString::fromStdString(value);
+ }
+
+ void setImagePath(const std::string & value)
+ {
+ m_imagePath = QString::fromStdString(value);
+ }
+
+ void setCommand(const std::string & value)
+ {
+ m_command = QString::fromStdString(value);
+ }
+};
+
+class SteamApps : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_SINGLETON
+
+ Q_PROPERTY(QList apps READ apps)
+ QList m_apps;
+
+public:
+ SteamApps(QObject * parent = nullptr);
+
+ const QList & apps() const
+ {
+ return m_apps;
+ }
+};
diff --git a/dashboard/vulkan_info.cpp b/dashboard/vulkan_info.cpp
new file mode 100644
index 00000000..52092eeb
--- /dev/null
+++ b/dashboard/vulkan_info.cpp
@@ -0,0 +1,74 @@
+/*
+ * 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 "vulkan_info.h"
+
+#include
+#include
+#include
+
+vulkan_info::vulkan_info()
+{
+ vk::raii::Context context;
+
+ vk::ApplicationInfo app_info{"WiVRn dashboard", 1, "No engine", 1, VK_API_VERSION_1_1};
+ vk::InstanceCreateInfo instance_info{vk::InstanceCreateFlags{0}, &app_info};
+ vk::raii::Instance vulkan{context, instance_info};
+
+ auto devices = vulkan.enumeratePhysicalDevices();
+ set_info(choose_device(devices));
+}
+
+vk::raii::PhysicalDevice & vulkan_info::choose_device(std::vector & devices)
+{
+ for (vk::raii::PhysicalDevice & device: devices)
+ {
+ if (device.getProperties().deviceType == vk::PhysicalDeviceType::eDiscreteGpu)
+ return device;
+ }
+
+ return devices.front();
+}
+
+void vulkan_info::set_info(vk::raii::PhysicalDevice & device)
+{
+ auto [prop, driver_prop] = device.getProperties2();
+
+ m_driverId = QString::fromStdString(vk::to_string(driver_prop.driverID));
+
+ m_driverVersionCode = prop.properties.driverVersion;
+ switch (driver_prop.driverID)
+ {
+ case vk::DriverId::eNvidiaProprietary:
+ m_driverVersion = QString("%1.%2.%3.%4")
+ .arg((prop.properties.driverVersion >> 22) & 0x3ff)
+ .arg((prop.properties.driverVersion >> 14) & 0xff)
+ .arg((prop.properties.driverVersion >> 6) & 0xff)
+ .arg(prop.properties.driverVersion & 0x3f);
+ break;
+
+ default:
+ m_driverVersion = QString("%1.%2.%3")
+ .arg(VK_VERSION_MAJOR(prop.properties.driverVersion))
+ .arg(VK_VERSION_MINOR(prop.properties.driverVersion))
+ .arg(VK_VERSION_PATCH(prop.properties.driverVersion));
+ break;
+ }
+
+ qDebug() << "Driver" << m_driverId << m_driverVersion;
+}
diff --git a/dashboard/vulkan_info.h b/dashboard/vulkan_info.h
new file mode 100644
index 00000000..662265cb
--- /dev/null
+++ b/dashboard/vulkan_info.h
@@ -0,0 +1,65 @@
+/*
+ * 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
+
+namespace vk::raii
+{
+class PhysicalDevice;
+}
+
+class vulkan_info : public QObject
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(VulkanInfo)
+ QML_SINGLETON
+
+ Q_PROPERTY(QString driverId READ driverId CONSTANT)
+ Q_PROPERTY(QString driverVersion READ driverVersion CONSTANT)
+ Q_PROPERTY(int driverVersionCode READ driverVersionCode CONSTANT)
+
+ QString m_driverId;
+ QString m_driverVersion;
+ int m_driverVersionCode;
+
+ vk::raii::PhysicalDevice & choose_device(std::vector & devices);
+ void set_info(vk::raii::PhysicalDevice & device);
+
+public:
+ vulkan_info();
+
+ QString driverId() const
+ {
+ return m_driverId;
+ }
+
+ QString driverVersion() const
+ {
+ return m_driverVersion;
+ }
+
+ int driverVersionCode() const
+ {
+ return m_driverVersionCode;
+ }
+};
diff --git a/dashboard/wivrn_qdbus_types.cpp b/dashboard/wivrn_qdbus_types.cpp
new file mode 100644
index 00000000..87696860
--- /dev/null
+++ b/dashboard/wivrn_qdbus_types.cpp
@@ -0,0 +1,3 @@
+#include "wivrn_qdbus_types.h"
+
+#include "moc_wivrn_qdbus_types.cpp"
diff --git a/dashboard/wivrn_qdbus_types.h b/dashboard/wivrn_qdbus_types.h
new file mode 100644
index 00000000..92b3ed23
--- /dev/null
+++ b/dashboard/wivrn_qdbus_types.h
@@ -0,0 +1,60 @@
+#pragma once
+
+#include
+#include
+
+// Same as XrFovf
+struct field_of_view
+{
+ Q_GADGET
+ Q_PROPERTY(float angleLeft READ getAngleLeft WRITE setAngleLeft)
+ Q_PROPERTY(float angleRight READ getAngleRight WRITE setAngleRight)
+ Q_PROPERTY(float angleUp READ getAngleUp WRITE setAngleUp)
+ Q_PROPERTY(float angleDown READ getAngleDown WRITE setAngleDown)
+ QML_VALUE_TYPE(field_of_view)
+public:
+ float angleLeft;
+ float angleRight;
+ float angleUp;
+ float angleDown;
+
+ float getAngleLeft() const
+ {
+ return angleLeft;
+ }
+
+ float getAngleRight() const
+ {
+ return angleRight;
+ }
+
+ float getAngleUp() const
+ {
+ return angleUp;
+ }
+
+ float getAngleDown() const
+ {
+ return angleDown;
+ }
+
+ void setAngleLeft(float value)
+ {
+ angleLeft = value;
+ }
+
+ void setAngleRight(float value)
+ {
+ angleRight = value;
+ }
+
+ void setAngleUp(float value)
+ {
+ angleUp = value;
+ }
+
+ void setAngleDown(float value)
+ {
+ angleDown = value;
+ }
+};
diff --git a/dashboard/wivrn_server.cpp b/dashboard/wivrn_server.cpp
new file mode 100644
index 00000000..be041f7d
--- /dev/null
+++ b/dashboard/wivrn_server.cpp
@@ -0,0 +1,532 @@
+/*
+ * 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 "gui_config.h"
+#include "magic_enum.hpp"
+#include "wivrn_server_dbus.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#if WIVRN_CHECK_CAPSYSNICE
+#include
+#endif
+
+#include
+#include
+
+using namespace std::chrono_literals;
+
+static QString server_path()
+{
+ return QCoreApplication::applicationDirPath() + "/wivrn-server";
+}
+
+#if WIVRN_CHECK_CAPSYSNICE
+static bool 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
+
+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();
+
+#if WIVRN_CHECK_CAPSYSNICE
+ m_capSysNice = has_cap_sys_nice();
+#else
+ m_capSysNice = true;
+#endif
+}
+
+wivrn_server::~wivrn_server()
+{
+ if (server_process)
+ {
+ server_process->terminate();
+ server_process->waitForFinished(1000);
+ }
+}
+
+void wivrn_server::start_server()
+{
+ switch (serverStatus())
+ {
+ case Status::Stopped:
+ serverStatusChanged(m_serverStatus = Status::Starting);
+ [[fallthrough]];
+
+ case Status::Restarting:
+ assert(server_process == nullptr);
+
+ server_process = std::make_unique();
+
+ // 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();
+
+ break;
+
+ case Status::Starting:
+ case Status::Started:
+ case Status::Stopping:
+ qWarning() << "start_server: unexpected status " << std::string(magic_enum::enum_name(serverStatus()));
+ }
+}
+
+void wivrn_server::stop_server()
+{
+ if (serverStatus() == Status::Started)
+ {
+ serverStatusChanged(m_serverStatus = Status::Stopping);
+ if (server_interface)
+ server_interface->Quit();
+ }
+ else
+ qWarning() << "stop_server: unexpected status " << std::string(magic_enum::enum_name(serverStatus()));
+}
+
+void wivrn_server::restart_server()
+{
+ if (serverStatus() == Status::Started)
+ {
+ serverStatusChanged(m_serverStatus = Status::Restarting);
+ if (server_interface)
+ server_interface->Quit();
+ }
+ else
+ qWarning() << "restart_server: unexpected status " << std::string(magic_enum::enum_name(serverStatus()));
+}
+
+void wivrn_server::on_server_dbus_registered()
+{
+ serverStatusChanged(m_serverStatus = Status::Started);
+
+ if (server_interface)
+ server_interface->deleteLater();
+ if (server_properties_interface)
+ server_properties_interface->deleteLater();
+
+ server_interface = std::make_unique("io.github.wivrn.Server", "/io/github/wivrn/Server", QDBusConnection::sessionBus(), this);
+ server_properties_interface = std::make_unique("io.github.wivrn.Server", "/io/github/wivrn/Server", QDBusConnection::sessionBus(), this);
+
+ connect(server_properties_interface.get(), &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, this, &wivrn_server::on_server_properties_changed);
+
+ serverStatusChanged(m_serverStatus = Status::Started);
+ refresh_server_properties();
+}
+
+void wivrn_server::on_server_dbus_unregistered()
+{
+ if (serverStatus() != Status::Restarting)
+ serverStatusChanged(m_serverStatus = Status::Stopped);
+
+ if (server_process)
+ server_process.release()->deleteLater();
+
+ if (server_interface)
+ server_interface.release()->deleteLater();
+
+ if (server_properties_interface)
+ server_properties_interface.release()->deleteLater();
+
+ if (isHeadsetConnected())
+ headsetConnectedChanged(m_headsetConnected = false);
+
+ if (isPairingEnabled())
+ pairingEnabledChanged(m_isPairingEnabled = false);
+
+ if (serverStatus() == Status::Restarting)
+ start_server();
+}
+
+void wivrn_server::grant_cap_sys_nice()
+{
+#if WIVRN_CHECK_CAPSYSNICE
+ if (not setcap_process)
+ {
+ setcap_process = std::make_unique();
+ setcap_process->setProgram("pkexec");
+ setcap_process->setArguments({"setcap", "CAP_SYS_NICE=+ep", server_path()});
+ setcap_process->setProcessChannelMode(QProcess::MergedChannels);
+ setcap_process->start();
+
+ QObject::connect(setcap_process.get(), &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
+
+ if (exit_status == QProcess::NormalExit and exit_code == 0)
+ {
+ if (not has_cap_sys_nice())
+ {
+ qDebug() << "pkexec setcap returned successfully but the server does not have the CAP_SYS_NICE capability";
+ }
+ else
+ {
+ qDebug() << "setcap sucessful";
+ capSysNiceChanged(m_capSysNice = true);
+ }
+ }
+ else
+ {
+ qWarning() << "setcap exited with status" << exit_status << "and code" << exit_code;
+ }
+
+ setcap_process.release()->deleteLater();
+ });
+ }
+#endif
+}
+
+// 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 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};
+// }
+// }
+
+// QString wivrn_server::apkUrl() const
+// {
+// }
+
+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.release()->deleteLater();
+ get_all_properties_call_watcher = std::make_unique(props_pending, this);
+
+ connect(get_all_properties_call_watcher.get(), &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"))
+ {
+ jsonConfigurationChanged(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(headset{name, public_key});
+ }
+ 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);
+ jsonConfigurationChanged(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)
+{
+ qDebug() << "Enabling pairing for" << timeout_secs << "seconds";
+ 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::copy_steam_command()
+{
+ QGuiApplication::clipboard()->setText(m_steamCommand);
+}
+
+#include "moc_wivrn_server.cpp"
diff --git a/dashboard/wivrn_server.h b/dashboard/wivrn_server.h
new file mode 100644
index 00000000..7f01a7ba
--- /dev/null
+++ b/dashboard/wivrn_server.h
@@ -0,0 +1,312 @@
+/*
+ * 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
+
+#include "wivrn_qdbus_types.h"
+
+class IoGithubWivrnServerInterface;
+class OrgFreedesktopDBusPropertiesInterface;
+
+class headset
+{
+ Q_GADGET
+ QML_VALUE_TYPE(headset)
+ QML_ELEMENT
+ Q_PROPERTY(QString name READ name WRITE setName)
+ Q_PROPERTY(QString publicKey READ publicKey WRITE setPublicKey)
+
+ QString m_name;
+ QString m_publicKey;
+
+public:
+ headset() = default;
+ headset(const headset &) = default;
+ headset(headset &&) = default;
+ headset & operator=(const headset &) = default;
+ headset & operator=(headset &&) = default;
+ headset(QString name, QString publicKey) :
+ m_name(name), m_publicKey(publicKey) {}
+
+ QString name() const
+ {
+ return m_name;
+ }
+
+ QString publicKey() const
+ {
+ return m_publicKey;
+ }
+
+ void setName(QString value)
+ {
+ m_name = value;
+ }
+
+ void setPublicKey(QString value)
+ {
+ m_publicKey = value;
+ }
+};
+
+class wivrn_server : public QObject
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(WivrnServer)
+ QML_SINGLETON
+
+ std::unique_ptr server_interface{};
+ std::unique_ptr server_properties_interface{};
+ QDBusServiceWatcher dbus_watcher;
+ std::unique_ptr get_all_properties_call_watcher;
+
+ std::unique_ptr server_process;
+ std::unique_ptr setcap_process;
+
+public:
+ wivrn_server(QObject * parent = nullptr);
+ wivrn_server(const wivrn_server &) = delete;
+ wivrn_server & operator=(const wivrn_server &) = delete;
+ ~wivrn_server();
+
+ enum class Status
+ {
+ Stopped,
+ Started,
+ Stopping,
+ Starting,
+ Restarting,
+ };
+
+ Q_ENUMS(Status)
+
+ // Server information
+ Q_PROPERTY(Status serverStatus READ serverStatus NOTIFY serverStatusChanged)
+ Q_PROPERTY(bool capSysNice READ capSysNice NOTIFY capSysNiceChanged)
+ Q_PROPERTY(bool headsetConnected READ isHeadsetConnected NOTIFY headsetConnectedChanged)
+ Q_PROPERTY(QString jsonConfiguration READ jsonConfiguration WRITE setJsonConfiguration NOTIFY jsonConfigurationChanged)
+ Q_INVOKABLE void start_server();
+ Q_INVOKABLE void stop_server();
+ Q_INVOKABLE void restart_server();
+ Q_INVOKABLE void grant_cap_sys_nice();
+
+ // Authentication
+ Q_PROPERTY(QString pin READ pin NOTIFY pinChanged)
+ Q_PROPERTY(QList knownKeys READ knownKeys NOTIFY knownKeysChanged)
+ Q_PROPERTY(bool pairingEnabled READ isPairingEnabled NOTIFY pairingEnabledChanged)
+ Q_PROPERTY(bool encryptionEnabled READ isEncryptionEnabled NOTIFY encryptionEnabledChanged)
+ Q_INVOKABLE void revoke_key(QString public_key);
+ Q_INVOKABLE void rename_key(QString public_key, QString name);
+ Q_INVOKABLE QString enable_pairing(int timeout_secs = 120);
+ Q_INVOKABLE 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 CONSTANT)
+
+ Status serverStatus() const
+ {
+ return m_serverStatus;
+ }
+
+ bool capSysNice() const
+ {
+ return m_capSysNice;
+ }
+
+ bool isHeadsetConnected() const
+ {
+ return m_headsetConnected;
+ }
+
+ QString jsonConfiguration() const
+ {
+ return m_jsonConfiguration;
+ }
+
+ void setJsonConfiguration(QString);
+
+ QString pin() const
+ {
+ return m_pin;
+ }
+
+ QList 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();
+
+ Q_INVOKABLE void disconnect_headset();
+ Q_INVOKABLE void copy_steam_command();
+
+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();
+
+ Status m_serverStatus{Status::Stopped};
+ bool m_capSysNice{};
+ bool m_headsetConnected{};
+ QString m_jsonConfiguration{};
+
+ QString m_pin{};
+ QList 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 serverStatusChanged(Status);
+ void capSysNiceChanged(bool);
+ void headsetConnectedChanged(bool);
+ void jsonConfigurationChanged(QString);
+ void needMonadoVulkanLayerChanged(bool);
+ void pinChanged(QString);
+ void knownKeysChanged(QList);
+ 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/flatpak/io.github.wivrn.wivrn.yml.in b/flatpak/io.github.wivrn.wivrn.yml.in
index 155b4f5a..04a0c8e6 100644
--- a/flatpak/io.github.wivrn.wivrn.yml.in
+++ b/flatpak/io.github.wivrn.wivrn.yml.in
@@ -4,6 +4,7 @@ runtime: org.kde.Platform
runtime-version: '6.7'
sdk: org.kde.Sdk
command: wivrn-dashboard
+separate-locales: false
finish-args:
# X11 + XShm access
diff --git a/tools/check_messages.sh b/tools/check_messages.sh
index 132bef23..56d5af30 100755
--- a/tools/check_messages.sh
+++ b/tools/check_messages.sh
@@ -2,37 +2,54 @@
cd $(dirname $0)/..
-WIVRN_POT=$(mktemp)
-xgettext --keyword=_:1,1t --keyword=_S:1,1t --keyword=_F:1,1t $(find client/ -name "*.cpp" | sort) --output=$WIVRN_POT --package-name=WiVRn
-sed -i 's/charset=CHARSET/charset=UTF-8/g' $WIVRN_POT
+WIVRN_CLIENT_POT=$(mktemp)
+WIVRN_DASHBOARD_POT=$(mktemp)
+
+xgettext \
+ --c++ --from-code=UTF-8 \
+ --keyword=_:1,1t \
+ --keyword=_S:1,1t \
+ --keyword=_F:1,1t \
+ --output=$WIVRN_CLIENT_POT \
+ --package-name=WiVRn \
+ $(find client/ -name "*.cpp" | sort)
+
+xgettext \
+ --c++ --kde --from-code=UTF-8 \
+ --keyword=i18n:1 \
+ --keyword=i18nc:1c,2 \
+ --keyword=i18np:1,2 \
+ --keyword=i18ncp:1c,2,3 \
+ --output=$WIVRN_DASHBOARD_POT \
+ --package-name=WiVRn-dashboard \
+ $(find dashboard-qml/ -name "*.qml" -o -name "*.cpp" | sort)
+
+sed -i 's/charset=CHARSET/charset=UTF-8/g' $WIVRN_CLIENT_POT $WIVRN_DASHBOARD_POT
RC=0
for i in locale/*
do
- tools/check_po.py $WIVRN_POT $i/wivrn.po $(basename $i)
- if [ $? != 0 ]
+ if [ -f $i/wivrn.po ]
then
- RC=1
+ tools/check_po.py $WIVRN_CLIENT_POT $i/wivrn.po $(basename $i)
+ if [ $? != 0 ]
+ then
+ RC=1
+ fi
+ fi
+
+ if [ -f $i/wivrn-dashboard.po ]
+ then
+ tools/check_po.py $WIVRN_DASHBOARD_POT $i/wivrn-dashboard.po $(basename $i)
+
+ if [ $? != 0 ]
+ then
+ RC=1
+ fi
fi
done
-for i in $(find dashboard -name "wivrn_*.ts")
-do
- cp $i $i.bak
- lupdate -silent dashboard/*.{cpp,ui} -ts $i
- mv $i $i.new
- mv $i.bak $i
-
- diff -U 3 -I '.*' $i $i.new
-
- if [ $? != 0 ]
- then
- RC=1
- fi
-
- rm $i.new
-done
-
+rm $WIVRN_CLIENT_POT $WIVRN_DASHBOARD_POT
exit $RC
diff --git a/tools/update_messages.sh b/tools/update_messages.sh
index cc2a790f..003fa273 100755
--- a/tools/update_messages.sh
+++ b/tools/update_messages.sh
@@ -3,17 +3,28 @@
cd $(dirname $0)/..
WIVRN_CLIENT_POT=$(mktemp)
+WIVRN_DASHBOARD_POT=$(mktemp)
xgettext \
- --c++ --from-code=UTF-8 \
- --keyword=_:1,1t \
- --keyword=_S:1,1t \
- --keyword=_F:1,1t \
- --output=$WIVRN_CLIENT_POT \
- --package-name=WiVRn \
+ --c++ --from-code=UTF-8 \
+ --keyword=_:1,1t \
+ --keyword=_S:1,1t \
+ --keyword=_F:1,1t \
+ --output=$WIVRN_CLIENT_POT \
+ --package-name=WiVRn \
$(find client/ -name "*.cpp" | sort)
-sed -i 's/charset=CHARSET/charset=UTF-8/g' $WIVRN_CLIENT_POT
+xgettext \
+ --c++ --kde --from-code=UTF-8 \
+ --keyword=i18n:1 \
+ --keyword=i18nc:1c,2 \
+ --keyword=i18np:1,2 \
+ --keyword=i18ncp:1c,2,3 \
+ --output=$WIVRN_DASHBOARD_POT \
+ --package-name=WiVRn-dashboard \
+ $(find dashboard-qml/ -name "*.qml" -o -name "*.cpp" | sort)
+
+sed -i 's/charset=CHARSET/charset=UTF-8/g' $WIVRN_CLIENT_POT $WIVRN_DASHBOARD_POT
LANGS="es fr it ja"
@@ -27,8 +38,13 @@ do
else
msgmerge --quiet --no-fuzzy-matching --update locale/$i/wivrn.po $WIVRN_CLIENT_POT
fi
+
+ if [ ! -f locale/$i/wivrn-dashboard.po ]
+ then
+ cp $WIVRN_DASHBOARD_POT locale/$i/wivrn-dashboard.po
+ else
+ msgmerge --quiet --no-fuzzy-matching --update locale/$i/wivrn-dashboard.po $WIVRN_DASHBOARD_POT
+ fi
done
-rm $WIVRN_CLIENT_POT
-
-lupdate dashboard/*.{cpp,ui} -ts dashboard/wivrn_*.ts
+rm $WIVRN_CLIENT_POT $WIVRN_DASHBOARD_POT