diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index df2800ed..d2fb4b61 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -244,7 +244,7 @@ jobs: WIVRN_SERVER_PID=$! mkdir -p ~/.config/wivrn - echo '{"servers": [{"autoconnect": false, "manual": true, "pretty_name": "Deep Thought", "hostname": "localhost", "port": 9757, "tcp_only": false, "cookie": ""}]}' > ~/.config/wivrn/client.json.in + echo '{"servers": [{"autoconnect": false, "manual": true, "pretty_name": "Deep Thought", "hostname": "localhost", "port": 9757, "tcp_only": false, "cookie": ""}], "first_run": false}' > ~/.config/wivrn/client.json.in for LANG in en $(basename -a ${{github.workspace}}/locale/*) do diff --git a/client/configuration.cpp b/client/configuration.cpp index dc38b6b5..259d92e5 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -254,6 +254,9 @@ configuration::configuration(xr::system & system) if (auto val = root["override_foveation_distance"]; val.is_double()) override_foveation_distance = val.get_double(); + + if (auto val = root["first_run"]; val.is_bool()) + first_run = val.get_bool(); } catch (std::exception & e) { @@ -373,5 +376,6 @@ void configuration::save() json << ",\"override_foveation_enable\":" << std::boolalpha << override_foveation_enable; json << ",\"override_foveation_pitch\":" << override_foveation_pitch; json << ",\"override_foveation_distance\":" << override_foveation_distance; + json << ",\"first_run\":" << std::boolalpha << first_run; json << "}"; } diff --git a/client/configuration.h b/client/configuration.h index 333cc853..16fa76f9 100644 --- a/client/configuration.h +++ b/client/configuration.h @@ -82,6 +82,8 @@ public: float override_foveation_pitch = 10 * M_PI / 180; float override_foveation_distance = 3; + bool first_run = true; + bool check_feature(feature f) const; void set_feature(feature f, bool state); diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index 5fa711dd..3ff6186f 100644 --- a/client/render/imgui_impl.cpp +++ b/client/render/imgui_impl.cpp @@ -1122,11 +1122,11 @@ void imgui_context::tooltip(std::string_view text) ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::tooltip_padding); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::tooltip_rounding); - // Clamp position to avoid overflowing on the right + // Clamp position to avoid overflowing on the left or the right auto & style = ImGui::GetStyle(); const ImVec2 text_size = ImGui::CalcTextSize(text.data(), text.data() + text.size(), true); const ImVec2 size = {text_size.x + style.WindowPadding.x * 2.0f, text_size.y + style.WindowPadding.y * 2.0f}; - pos.x = std::min(pos.x, viewport->Pos.x + viewport->Size.x - size.x / 2); + pos.x = std::clamp(pos.x, viewport->Pos.x + size.x / 2, viewport->Pos.x + viewport->Size.x - size.x / 2); ImVec2 pivot = {0.5, 1}; // Move tooltip below the item if it overflows on the top diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 8ce37c32..c2b6bf53 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -21,18 +21,14 @@ #include "application.h" #include "constants.h" #include "glm/geometric.hpp" +#include "hand_model.h" #include "hardware.h" #include "imgui.h" -#include "input_profile.h" #include "openxr/openxr.h" #include "protocol_version.h" #include "render/scene_data.h" -#include "render/scene_loader.h" -#include "render/scene_renderer.h" #include "stream.h" #include "utils/i18n.h" -#include "utils/overloaded.h" -#include "utils/ranges.h" #include "wivrn_client.h" #include "wivrn_discover.h" #include "wivrn_sockets.h" @@ -40,9 +36,7 @@ #include "xr/space.h" #include -#include #include // IWYU pragma: keep -#include #include #include #include @@ -130,14 +124,19 @@ scenes::lobby::lobby() : if (std::getenv("WIVRN_AUTOCONNECT")) force_autoconnect = true; - auto & servers = application::get_config().servers; + auto & config = application::get_config(); + + auto & servers = config.servers; spdlog::info("{} known server(s):", servers.size()); for (auto & i: servers) { spdlog::info(" {}", i.second.service.name); } - keyboard.set_layout(application::get_config().virtual_keyboard_layout); + keyboard.set_layout(config.virtual_keyboard_layout); + + if (config.first_run) + current_tab = tab::first_run; const auto keypair_path = application::get_config_path() / "private_key.pem"; try @@ -435,7 +434,7 @@ std::optional scenes::lobby::check_recenter_action(XrTime predicted_d imgui_ctx->compute_pointer_position(state); - if (state.pointer_position) + if (state.pointer_position) // TODO: check that the pointer is inside an imgui window { auto M = glm::mat3_cast(imgui_ctx->layers()[0].orientation); diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index 22be7475..98cc4cae 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -101,6 +101,7 @@ class lobby : public scene_impl enum class tab { + first_run, server_list, settings, post_processing, @@ -114,6 +115,7 @@ class lobby : public scene_impl tab current_tab = tab::server_list; tab last_current_tab = tab::server_list; + int optional_feature_index = 0; // Which step of the first run screen are we in ImTextureID about_picture; virtual_keyboard keyboard; @@ -139,6 +141,7 @@ class lobby : public scene_impl void gui_about(); void gui_licenses(); void gui_keyboard(); + void gui_first_run(); void setup_passthrough(); diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index b07be452..9cc8a570 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -36,6 +36,7 @@ #include "version.h" #include #include +#include #include #include #include @@ -631,7 +632,6 @@ void scenes::lobby::gui_settings() if (ImGui::Checkbox(_S("Enable microphone"), &enabled)) { config.set_feature(feature::microphone, enabled); - config.save(); } imgui_ctx->vibrate_on_hover(); } @@ -654,7 +654,6 @@ void scenes::lobby::gui_settings() if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled)) { config.set_feature(feature::hand_tracking, enabled); - config.save(); } imgui_ctx->vibrate_on_hover(); if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) and (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled)) @@ -667,7 +666,6 @@ void scenes::lobby::gui_settings() if (ImGui::Checkbox(_S("Enable eye tracking"), &enabled)) { config.set_feature(feature::eye_gaze, enabled); - config.save(); } imgui_ctx->vibrate_on_hover(); if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) and (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled)) @@ -680,7 +678,6 @@ void scenes::lobby::gui_settings() if (ImGui::Checkbox(_S("Enable face tracking"), &enabled)) { config.set_feature(feature::face_tracking, enabled); - config.save(); } ImGui::EndDisabled(); if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) and (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled)) @@ -694,7 +691,6 @@ void scenes::lobby::gui_settings() if (ImGui::Checkbox(_S("Enable body tracking"), &enabled)) { config.set_feature(feature::body_tracking, enabled); - config.save(); } ImGui::EndDisabled(); if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) @@ -1024,6 +1020,10 @@ void scenes::lobby::gui_debug() ImGui::DragFloat("Ray offset", &ray_offset, 0.0001); imgui_ctx->vibrate_on_hover(); + if (ImGui::Button("Delete configuration file")) + std::filesystem::remove(application::get_config_path() / "client.json"); + imgui_ctx->vibrate_on_hover(); + ImGui::PopStyleVar(); } #endif @@ -1042,6 +1042,92 @@ void scenes::lobby::gui_about() ImGui::Image(about_picture, {win_width / 2, win_width / 2}); } +void scenes::lobby::gui_first_run() +{ + float win_width = ImGui::GetWindowSize().x; + auto & config = application::get_config(); + const ImGuiStyle & style = ImGui::GetStyle(); + + struct item + { + feature f; + std::string text; + bool supported; + }; + + std::array optional_features{ + item{ + .f = feature::microphone, + .text = _S("Enable the microphone?"), + .supported = true, + }, + item{ + .f = feature::eye_gaze, + .text = _S("Enable eye tracking?"), + .supported = application::get_eye_gaze_supported(), + }, + item{ + .f = feature::face_tracking, + .text = _S("Enable face tracking?"), + .supported = application::get_face_tracking_supported(), + }, + item{ + .f = feature::body_tracking, + .text = _S("Enable body tracking?"), + .supported = application::get_body_tracking_supported(), + }, + }; + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 40}); + + ImGui::PushFont(nullptr, constants::gui::font_size_large); + CenterTextH(_("Welcome to WiVRn")); + ImGui::PopFont(); + + while (optional_feature_index < optional_features.size() and + (not optional_features[optional_feature_index].supported or + config.check_feature(optional_features[optional_feature_index].f))) + + optional_feature_index++; + + if (optional_feature_index == optional_features.size()) + { + current_tab = tab::server_list; + config.first_run = false; + config.save(); + } + + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10); + + CenterTextH(optional_features[optional_feature_index].text); + + float button_width = constants::style::button_size.x; + float buttons_width = 2 * button_width + style.ItemSpacing.x; + ImGui::SetCursorPosX((win_width - buttons_width) / 2); + + if (ImGui::Button(_S("Yes"), constants::style::button_size)) + { + config.set_feature(optional_features[optional_feature_index].f, true); + } + imgui_ctx->vibrate_on_hover(); + + ImGui::SameLine(); + if (ImGui::Button(_S("No"), constants::style::button_size)) + { + config.set_feature(optional_features[optional_feature_index].f, false); + optional_feature_index++; + } + imgui_ctx->vibrate_on_hover(); + ImGui::PopStyleVar(2); // ImGuiStyleVar_ItemSpacing + + if (optional_feature_index == optional_features.size()) + { + current_tab = tab::server_list; + config.first_run = false; + config.save(); + } +} + void scenes::lobby::gui_licenses() { ImGui::PushFont(nullptr, constants::gui::font_size_large); @@ -1465,7 +1551,6 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) { // button doesn't alter the bool config.set_feature(i.f, not i.enabled); - config.save(); } imgui_ctx->vibrate_on_hover(); @@ -1594,25 +1679,39 @@ std::vector> scenes::lobby::draw_gui(XrTi gui_keyboard(); } - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0}); ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, 30); ImGui::PushStyleColor(ImGuiCol_WindowBg, IM_COL32(8, 8, 8, 224)); ImGui::SetNextWindowPos(imgui_ctx->layers()[0].vp_center(), ImGuiCond_Always, {0.5, 0.5}); - ImGui::SetNextWindowSize({1400, 900}); - - ImGui::Begin("WiVRn", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove); - - ImGui::SetCursorPos({TabWidth + 20, 0}); + if (current_tab == tab::first_run) { + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::window_padding * 2); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::window_rounding); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, constants::style::window_border_size); + ImGui::Begin("WiVRn", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize); + gui_first_run(); + ImGui::End(); + ImGui::PopStyleVar(4); // ImGuiStyleVar_FrameRounding, ImGuiStyleVar_WindowPadding, ImGuiStyleVar_WindowRounding, ImGuiStyleVar_WindowBorderSize + } + else + { + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0}); + ImGui::SetNextWindowSize({1400, 900}); + ImGui::Begin("WiVRn", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove); + ImGui::SetCursorPos({TabWidth + 20, 0}); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 20}); - ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0)); + ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0), 0); ImGui::SetCursorPosY(20); switch (current_tab) { + case tab::first_run: + __builtin_unreachable(); + case tab::server_list: ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10}); draw_features_status(predicted_display_time); @@ -1659,45 +1758,47 @@ std::vector> scenes::lobby::draw_gui(XrTi ScrollWhenDraggingOnVoid(); ImGui::EndChild(); ImGui::PopStyleVar(2); // ImGuiStyleVar_FrameRounding, ImGuiStyleVar_WindowPadding - } - ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0, 0, 0, 255)); - ImGui::SetCursorPos(style.WindowPadding); - { - ImGui::BeginChild("Tabs", {TabWidth, ImGui::GetContentRegionMax().y - ImGui::GetWindowContentRegionMin().y}); + ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0, 0, 0, 255)); + ImGui::SetCursorPos(style.WindowPadding); + { + ImGui::BeginChild("Tabs", {TabWidth, ImGui::GetContentRegionMax().y - ImGui::GetWindowContentRegionMin().y}); - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10)); - RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " " + _("Server list"), ¤t_tab, tab::server_list, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10)); + RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " " + _("Server list"), ¤t_tab, tab::server_list, {TabWidth, 0}); + imgui_ctx->vibrate_on_hover(); - RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), ¤t_tab, tab::settings, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); + RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), ¤t_tab, tab::settings, {TabWidth, 0}); + imgui_ctx->vibrate_on_hover(); - RadioButtonWithoutCheckBox(ICON_FA_WAND_MAGIC_SPARKLES " " + _("Post-processing"), ¤t_tab, tab::post_processing, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); + RadioButtonWithoutCheckBox(ICON_FA_WAND_MAGIC_SPARKLES " " + _("Post-processing"), ¤t_tab, tab::post_processing, {TabWidth, 0}); + imgui_ctx->vibrate_on_hover(); #if WIVRN_CLIENT_DEBUG_MENU - RadioButtonWithoutCheckBox(ICON_FA_BUG_SLASH " " + _("Debug"), ¤t_tab, tab::debug, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); + RadioButtonWithoutCheckBox(ICON_FA_BUG_SLASH " " + _("Debug"), ¤t_tab, tab::debug, {TabWidth, 0}); + imgui_ctx->vibrate_on_hover(); #endif - ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 3 * ImGui::GetCurrentContext()->FontSize - 6 * style.FramePadding.y - 2 * style.ItemSpacing.y - style.WindowPadding.y); - RadioButtonWithoutCheckBox(ICON_FA_CIRCLE_INFO " " + _("About"), ¤t_tab, tab::about, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); + ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 3 * ImGui::GetCurrentContext()->FontSize - 6 * style.FramePadding.y - 2 * style.ItemSpacing.y - style.WindowPadding.y); + RadioButtonWithoutCheckBox(ICON_FA_CIRCLE_INFO " " + _("About"), ¤t_tab, tab::about, {TabWidth, 0}); + imgui_ctx->vibrate_on_hover(); - RadioButtonWithoutCheckBox(ICON_FA_SCALE_BALANCED " " + _("Licenses"), ¤t_tab, tab::licenses, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); + RadioButtonWithoutCheckBox(ICON_FA_SCALE_BALANCED " " + _("Licenses"), ¤t_tab, tab::licenses, {TabWidth, 0}); + imgui_ctx->vibrate_on_hover(); - RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " " + _("Exit"), ¤t_tab, tab::exit, {TabWidth, 0}); - imgui_ctx->vibrate_on_hover(); + RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " " + _("Exit"), ¤t_tab, tab::exit, {TabWidth, 0}); + imgui_ctx->vibrate_on_hover(); - ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding - ImGui::EndChild(); + ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding + ImGui::EndChild(); + } + ImGui::PopStyleColor(); // ImGuiCol_ChildBg + ImGui::End(); + ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding } - ImGui::PopStyleColor(); // ImGuiCol_ChildBg - ImGui::End(); + ImGui::PopStyleColor(); // ImGuiCol_WindowBg - ImGui::PopStyleVar(2); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_ScrollbarSize + ImGui::PopStyleVar(); // ImGuiStyleVar_ScrollbarSize if (not is_gui_visible(*imgui_ctx, predicted_display_time)) {