From 6209d5e6d5cd0b60c985c89a1cbd8bec944e09fb Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Sun, 24 Nov 2024 20:23:59 +0100 Subject: [PATCH] Dashboard GUI update: add button to start pairing, add banner warning about missing monado layers --- common/CMakeLists.txt | 2 + {client => common}/utils/strings.cpp | 0 {client => common}/utils/strings.h | 0 common/utils/xdg_base_directory.cpp | 63 ++++++++-- common/utils/xdg_base_directory.h | 4 + dashboard/CMakeLists.txt | 1 + dashboard/main_window.cpp | 143 +++++++++++++++++++++- dashboard/main_window.ui | 172 ++++++++++++++++++--------- 8 files changed, 314 insertions(+), 71 deletions(-) rename {client => common}/utils/strings.cpp (100%) rename {client => common}/utils/strings.h (100%) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 7830e29f..6c3a62a9 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -26,6 +26,7 @@ configure_file(wivrn_config.h.in wivrn_config.h) add_library(wivrn-common-base STATIC utils/xdg_base_directory.cpp utils/flatpak.cpp + utils/strings.cpp ${CMAKE_CURRENT_BINARY_DIR}/version.cpp ) @@ -34,6 +35,7 @@ add_library(wivrn-common STATIC secrets.cpp wivrn_sockets.cpp utils/xdg_base_directory.cpp + utils/strings.cpp vk/allocation.cpp vk/error_category.cpp vk/vk_allocator.cpp diff --git a/client/utils/strings.cpp b/common/utils/strings.cpp similarity index 100% rename from client/utils/strings.cpp rename to common/utils/strings.cpp diff --git a/client/utils/strings.h b/common/utils/strings.h similarity index 100% rename from client/utils/strings.h rename to common/utils/strings.h diff --git a/common/utils/xdg_base_directory.cpp b/common/utils/xdg_base_directory.cpp index addad42a..5fe65d12 100644 --- a/common/utils/xdg_base_directory.cpp +++ b/common/utils/xdg_base_directory.cpp @@ -17,27 +17,74 @@ * along with this program. If not, see . */ +#include "strings.h" #include #include std::filesystem::path xdg_config_home() { - const char * xdg_config_home = std::getenv("XDG_CONFIG_HOME"); - if (xdg_config_home) + if (const char * xdg_config_home = std::getenv("XDG_CONFIG_HOME")) return xdg_config_home; - const char * home = std::getenv("HOME"); - if (home) + + if (const char * home = std::getenv("HOME")) return std::filesystem::path(home) / ".config"; + return "."; } std::filesystem::path xdg_cache_home() { - const char * xdg_cache_home = std::getenv("XDG_CACHE_HOME"); - if (xdg_cache_home) + if (const char * xdg_cache_home = std::getenv("XDG_CACHE_HOME")) return xdg_cache_home; - const char * home = std::getenv("HOME"); - if (home) + + if (const char * home = std::getenv("HOME")) return std::filesystem::path(home) / ".cache"; + return "."; } + +std::filesystem::path xdg_data_home() +{ + if (const char * xdg_data_home = std::getenv("XDG_DATA_HOME")) + return xdg_data_home; + + if (const char * home = std::getenv("HOME")) + return std::filesystem::path(home) / ".local/share"; + + return "."; +} + +std::vector xdg_config_dirs() +{ + std::vector paths; + + if (const char * xdg_config_dirs = std::getenv("XDG_CONFIG_DIRS")) + { + for (const auto & path: utils::split(xdg_config_dirs, ":")) + paths.push_back(path); + } + else + { + paths.push_back("/etc/xdg"); + } + + return paths; +} + +std::vector xdg_data_dirs() +{ + std::vector paths; + + if (const char * xdg_config_dirs = std::getenv("XDG_DATA_DIRS")) + { + for (const auto & path: utils::split(xdg_config_dirs, ":")) + paths.push_back(path); + } + else + { + paths.push_back("/usr/local/share"); + paths.push_back("/usr/share"); + } + + return paths; +} diff --git a/common/utils/xdg_base_directory.h b/common/utils/xdg_base_directory.h index caf0ff1f..ef56baae 100644 --- a/common/utils/xdg_base_directory.h +++ b/common/utils/xdg_base_directory.h @@ -20,6 +20,10 @@ #pragma once #include +#include std::filesystem::path xdg_config_home(); std::filesystem::path xdg_cache_home(); +std::filesystem::path xdg_data_home(); +std::vector xdg_config_dirs(); +std::vector xdg_data_dirs(); diff --git a/dashboard/CMakeLists.txt b/dashboard/CMakeLists.txt index 3345f0b2..e4e2b7f6 100644 --- a/dashboard/CMakeLists.txt +++ b/dashboard/CMakeLists.txt @@ -66,6 +66,7 @@ target_link_libraries(wivrn-dashboard PRIVATE Qt6::Network nlohmann_json wivrn-common-base + Vulkan::Vulkan ) target_compile_definitions(wivrn-dashboard PRIVATE JSON_DIAGNOSTICS=1) diff --git a/dashboard/main_window.cpp b/dashboard/main_window.cpp index ed834796..921375d5 100644 --- a/dashboard/main_window.cpp +++ b/dashboard/main_window.cpp @@ -27,11 +27,15 @@ #include #include +#include #include "adb.h" #include "gui_config.h" #include "settings.h" #include "ui_main_window.h" +#include "utils/flatpak.h" +#include "utils/strings.h" +#include "utils/xdg_base_directory.h" #include "wivrn_server.h" #include "wizard.h" @@ -39,6 +43,9 @@ #include #endif +#include +#include + Q_LOGGING_CATEGORY(wivrn_log_category, "wivrn") enum class server_state @@ -74,6 +81,121 @@ static bool server_has_cap_sys_nice() } #endif +std::vector layer_dirs() +{ + // See https://vulkan.lunarg.com/doc/view/latest/linux/loader_and_layer_interface.html#user-content-linux-layer-discovery + std::vector dirs; + + dirs.push_back(xdg_config_home() / "vulkan/implicit_layer.d"); + + for (auto dir: xdg_config_dirs()) + dirs.push_back(dir / "vulkan/implicit_layer.d"); + + dirs.push_back("/etc/vulkan/implicit_layer.d"); + + dirs.push_back(xdg_data_home() / "vulkan/implicit_layer.d"); + + for (auto dir: xdg_data_dirs()) + dirs.push_back(dir / "vulkan/implicit_layer.d"); + + return dirs; +} + +static std::string read_file(const std::filesystem::path & path) +{ + if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk") + { + QProcess flatpak_spawn; + flatpak_spawn.start("flatpak-spawn", {"--host", "cat", QString::fromStdString(path)}); + flatpak_spawn.waitForFinished(); + return flatpak_spawn.readAllStandardOutput().toStdString(); + } + else + { + std::ifstream f(path); + std::istreambuf_iterator begin{f}, end; + + return {begin, end}; + } +} + +static std::vector list_files(const std::vector & dirs) +{ + std::vector files; + + if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk") + { + QProcess flatpak_spawn; + QStringList args{"--host", "find"}; + for (const std::filesystem::path & dir: dirs) + args.push_back(QString::fromStdString(dir)); + args.push_back("-name"); + args.push_back("*.json"); + + flatpak_spawn.start("flatpak-spawn", args); + flatpak_spawn.waitForFinished(); + + qDebug() << args; + + for (const std::string & file: utils::split(flatpak_spawn.readAllStandardOutput().toStdString())) + { + if (file != "") + files.push_back(file); + } + } + else + { + for (const std::filesystem::path & dir: dirs) + { + try + { + for (auto const & dir_entry: std::filesystem::directory_iterator{dir}) + { + if (dir_entry.path().extension() != ".json") + continue; + + files.push_back(dir / dir_entry.path()); + } + } + catch (...) + { + // Ignore non existing directories + } + } + } + + return files; +} + +static bool nvidia_layer_missing() +{ + vk::raii::Context context; + + vk::ApplicationInfo app_info{"WiVRn dashboard", 1, "No engine", 1, VK_API_VERSION_1_0}; + vk::InstanceCreateInfo instance_info{vk::InstanceCreateFlags{0}, &app_info}; + vk::raii::Instance vulkan{context, instance_info}; + + // Check if an nvidia GPU is present + if (not std::ranges::any_of(vulkan.enumeratePhysicalDevices(), [](vk::raii::PhysicalDevice & device) { return device.getProperties().vendorID == 0x10de; })) + return false; + + // Check if the monado vulkan layer is present + for (auto file: list_files(layer_dirs())) + { + try + { + nlohmann::json json = nlohmann::json::parse(read_file(file)); + if (json["layer"]["name"] == "VK_LAYER_MND_enable_timeline_semaphore") + return false; + } + catch (...) + { + } + } + + return true; +} + main_window::main_window() { ui = new Ui::MainWindow; @@ -138,9 +260,15 @@ main_window::main_window() connect(server_interface, &wivrn_server::supportedCodecsChanged, this, &main_window::on_supported_codecs_changed); connect(server_interface, &wivrn_server::steamCommandChanged, this, &main_window::on_steam_command_changed); + connect(server_interface, &wivrn_server::encryptionEnabledChanged, ui->widget_authentication, &QWidget::setVisible); connect(server_interface, &wivrn_server::pinChanged, this, &main_window::on_pin_changed); on_pin_changed(server_interface->pin()); + connect(server_interface, &wivrn_server::enrollEnabledChanged, ui->button_cancel_pairing, &QWidget::setVisible); + connect(server_interface, &wivrn_server::enrollEnabledChanged, ui->button_pair_headset, &QWidget::setHidden); + connect(ui->button_cancel_pairing, &QPushButton::clicked, server_interface, &wivrn_server::disable_enroll_headset); + connect(ui->button_pair_headset, &QPushButton::clicked, server_interface, &wivrn_server::enroll_headset); + connect(ui->button_start, &QPushButton::clicked, this, &main_window::start_server); connect(ui->button_stop, &QPushButton::clicked, this, &main_window::stop_server); connect(ui->button_settings, &QPushButton::clicked, this, &main_window::on_action_settings); @@ -161,8 +289,7 @@ main_window::main_window() on_android_device_list_changed(adb_service.devices()); #if WIVRN_CHECK_CAPSYSNICE - QIcon icon = QIcon::fromTheme("dialog-information"); - ui->banner_capsysnice_icon->setPixmap(icon.pixmap(ui->banner_capsysnice_dismiss->height())); + ui->banner_capsysnice_icon->setPixmap(QIcon::fromTheme("dialog-information").pixmap(ui->banner_capsysnice_dismiss->height())); connect(ui->banner_capsysnice_text, &QLabel::linkActivated, this, &main_window::on_banner_capsysnice); if (server_has_cap_sys_nice()) @@ -171,6 +298,10 @@ main_window::main_window() ui->banner_capsysnice->hide(); #endif + ui->banner_nvidia_layer_icon->setPixmap(QIcon::fromTheme("dialog-information").pixmap(ui->banner_nvidia_layer_dismiss->height())); + if (not nvidia_layer_missing()) + ui->banner_nvidia_layer->hide(); + // TODO implement this ui->button_known_headsets->hide(); @@ -536,8 +667,10 @@ void main_window::on_steam_command_changed(QString value) void main_window::on_pin_changed(QString value) { - ui->widget_authentication->setVisible(value != ""); - ui->label_pin->setText(value); + if (value == "") + ui->label_pin->setText(""); + else + ui->label_pin->setText(tr("To pair your headset use the following PIN: %1").arg(value)); } void main_window::on_server_finished(int exit_code, QProcess::ExitStatus status) @@ -563,7 +696,7 @@ void main_window::on_server_finished(int exit_code, QProcess::ExitStatus status) error_message = tr("Insufficient system resources"); break; case 4: - error_message = tr("Cannot connect to avahi, make sure avahi-daemon service is started"); + error_message = tr("Cannot connect to avahi, make sure avahi-daemon service is started with \"disable-user-service-publishing\" set to no"); break; } diff --git a/dashboard/main_window.ui b/dashboard/main_window.ui index 3003ba46..d5dbbc77 100644 --- a/dashboard/main_window.ui +++ b/dashboard/main_window.ui @@ -6,8 +6,8 @@ 0 0 - 898 - 757 + 895 + 842 @@ -18,11 +18,11 @@ :/images/wivrn.svg:/images/wivrn.svg - + - #banner_capsysnice + .QFrame { background-color: rgb(255, 170, 127); border: 1px solid rgb(255, 127, 127); @@ -57,6 +57,44 @@ border-radius: 5px; + + + + .QFrame +{ +background-color: rgb(255, 170, 127); +border: 1px solid rgb(255, 127, 127); +border-radius: 5px; +} + + + QFrame::Shape::Box + + + + + + + + + + + + + <html><head/><body><p>The Monado NVIDIA layer is not installed.</p></body></html> + + + + + + + + + + + + + @@ -179,56 +217,7 @@ border-radius: 5px; - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 14 - - - - PIN: - - - - - - - - 14 - - - - 000000 - - - - - - - Known headsets - - - - - + @@ -360,6 +349,57 @@ border-radius: 5px; + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 14 + + + + label_pin + + + + + + + Pair headset + + + + + + + Cancel + + + + + + + Known headsets + + + + + + @@ -613,12 +653,28 @@ border-radius: 5px; hide() - 837 - 31 + 881 + 44 - 799 - 54 + 805 + 51 + + + + + banner_nvidia_layer_dismiss + clicked() + banner_nvidia_layer + hide() + + + 869 + 82 + + + 852 + 102