Files
WiVRn/client/scenes/gui_settings.cpp

961 lines
38 KiB
C++

/*
* WiVRn VR streaming
* Copyright (C) 2026 Guillaume Meunier <[email protected]>
* Copyright (C) 2026 Patrick Nicolas <[email protected]>
*
* 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 <https://www.gnu.org/licenses/>.
*/
// each page builds a list of `setting` descriptors, render_settings() draws the matching
// ui:: widget for each, rebuilt every frame so dynamic options/descriptions just work
// same pages serve the lobby and the in-stream window, gated by ctx.in_game
#include "scenes/gui_common.h"
#include "gui_settings.h"
#include "application.h"
#include "configuration.h"
#include "decoder/decoder.h"
#include "render/imgui_impl.h"
#include "render/ui_theme.h"
#include "render/ui_widgets.h"
#include "stream.h"
#include "utils/i18n.h"
#include "xr/instance.h"
#include "xr/session.h"
#include "xr/system.h"
#include "imgui.h"
#include <algorithm>
#include <array>
#include <boost/locale.hpp>
#include <cmath>
#include <functional>
#include <locale>
#include <optional>
#include <spdlog/fmt/fmt.h>
#include <string>
#include <tuple>
#include <vector>
namespace ui = wivrn::ui;
namespace
{
constexpr float control_w = ui::metrics::setting_control_width;
float toggle_width()
{
return ImGui::GetFrameHeight() * ui::metrics::control_height * ui::metrics::toggle_aspect;
}
enum class ui_kind
{
toggle,
slider,
segmented,
combo,
combo_multi,
button,
};
// one declarative setting, `enabled` greys the row out without hiding it
struct setting
{
const char * id; // stable imgui id
std::string label;
std::string description;
ui_kind ui = ui_kind::toggle;
std::function<bool()> get_bool;
std::function<void(bool)> set_bool;
std::function<int()> get_int;
std::function<void(int)> set_int;
int v_min = 0;
int v_max = 0;
std::function<bool(int)> get_multi;
std::function<void(int, bool)> set_multi;
std::string fmt;
std::function<std::vector<std::string>()> options;
std::string title; // combo modal title
std::string button_label; // ui_kind::button
std::function<void()> on_click; // ui_kind::button
std::optional<bool> default_bool; // reset target for toggles
std::optional<int> default_int; // reset target for slider/segmented/combo
std::optional<std::vector<char>> default_multi; // reset target for multicombo
std::function<bool()> enabled;
std::string disabled_tooltip; // shown on a disabled row
};
void render_settings(const wivrn::gui::settings_context & ctx, const char * card_id, const std::vector<setting> & list)
{
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ui::metrics::card_item_spacing);
ui::begin_card(card_id);
for (const auto & s: list)
{
const bool enabled = s.enabled ? s.enabled() : true;
ImGui::BeginDisabled(not enabled);
// stable storage for the reset defaults during this call
bool def_b = s.default_bool.value_or(false);
int def_i = s.default_int.value_or(0);
const bool * dpb = s.default_bool ? &def_b : nullptr;
const int * dpi = s.default_int ? &def_i : nullptr;
const std::vector<char> * dpm = s.default_multi ? &s.default_multi.value() : nullptr;
const ImVec2 row_min = ImGui::GetCursorScreenPos();
const float w = s.ui == ui_kind::toggle ? toggle_width() + (s.default_bool ? ui::reset_slot_width() : 0) : control_w;
const float label_bottom = ui::setting_label(s.label, s.description, w);
switch (s.ui)
{
case ui_kind::toggle: {
bool v = s.get_bool();
if (ui::toggle(s.id, &v, dpb))
s.set_bool(v);
break;
}
case ui_kind::slider: {
int v = s.get_int();
if (ui::slider_int(s.id, &v, s.v_min, s.v_max, s.fmt.c_str(), {control_w, 0}, dpi))
s.set_int(v);
break;
}
case ui_kind::segmented: {
const auto opts = s.options();
int v = s.get_int();
if (ui::segmented(s.id, opts, &v, {control_w, 0}, dpi))
s.set_int(v);
break;
}
case ui_kind::combo: {
const auto opts = s.options();
std::vector<ui::combo_item> items;
for (const auto & o: opts)
items.push_back({o.c_str()});
int v = s.get_int();
if (ui::combo(s.id, s.title, items, &v, control_w, dpi))
s.set_int(v);
break;
}
case ui_kind::combo_multi: {
const auto opts = s.options();
std::vector<ui::combo_item> items;
std::vector<char> selected;
for (const auto & o: opts)
items.push_back({o.c_str()});
for (size_t i = 0; i < items.size(); ++i)
selected.push_back(s.get_multi(i));
if (ui::combo_multi(s.id, s.title, s.title, items, &selected, control_w, dpm))
{
// TODO only set the changed value
for (size_t i = 0; i < items.size(); ++i)
s.set_multi(i, selected[i]);
}
break;
}
case ui_kind::button: {
if (ui::button(s.button_label, ui::button_style::secondary, {control_w, 0}) and s.on_click)
s.on_click();
break;
}
}
ImGui::EndDisabled();
// reserve row height for a multi-line description plus padding, Dummy grows content size
const float pad = std::max(label_bottom - ImGui::GetCursorPosY(), 0.f) + ui::metrics::label_bottom_pad;
ImGui::Dummy({0, pad});
// disabled rows can't fire the widget tooltip hook, do it on the row
if (not enabled and not s.disabled_tooltip.empty())
{
const ImVec2 row_max{row_min.x + ImGui::GetContentRegionAvail().x, ImGui::GetCursorScreenPos().y};
if (ImGui::IsMouseHoveringRect(row_min, row_max))
ctx.imgui_ctx.tooltip(s.disabled_tooltip, (row_min + row_max) / 2);
}
}
ui::end_card();
ImGui::PopStyleVar();
}
template <typename Range, typename T>
std::optional<int> index(const Range & range, const T & value)
{
auto it = std::ranges::find(range, value);
if (it == range.end())
return std::nullopt;
else
return (it - range.begin());
}
} // namespace
namespace wivrn::gui
{
void settings_video(const settings_context & ctx)
{
auto & config = ctx.config;
auto & default_config = ctx.default_config;
const std::string disconnect_tip = ctx.in_game ? _C("tooltip for disabled settings", "Disconnect to change this setting.") : std::string{};
std::vector<setting> list;
const auto rates = ctx.session.get_refresh_rates();
if (not rates.empty())
{
const auto system_managed = rates.size() < 2;
int default_rate_index = index(rates, default_config.preferred_refresh_rate).value_or(-1) + 1;
list.push_back({
.id = "##refresh",
.label = _("Refresh rate"),
.description = system_managed
? _("WiVRn can't directly change the refresh rate on this device. See your device's settings to change the refresh rate.")
: _("Use 'auto' to select the refresh rate based on measured application performance. May cause flicker when a change happens."),
.ui = rates.size() < 7 ? ui_kind::segmented : ui_kind::combo,
.get_int = [&config, rates] {
for (size_t i = 0; i < rates.size(); ++i)
if (rates[i] == config.preferred_refresh_rate)
return int(i) + 1;
return 0; },
.set_int = [&ctx, &config, rates](int v) {
if (v == 0)
{
config.preferred_refresh_rate = 0;
config.fps_divider = 1;
}
else
{
ctx.session.set_refresh_rate(rates[v - 1]);
config.preferred_refresh_rate = rates[v - 1];
}
config.save();
if (ctx.on_streaming_changed)
ctx.on_streaming_changed(); },
.options = [rates] {
std::vector<std::string> opts;
opts.push_back(_C("automatic refresh rate, use a short string", "Auto"));
for (float r: rates)
opts.push_back(fmt::format("{}", int(r)));
return opts; },
.default_int = default_rate_index,
.enabled = [system_managed] { return not system_managed; },
});
}
{
const auto width = ctx.recommended_width;
const auto height = ctx.recommended_height;
list.push_back({
.id = "##resolution",
.label = _("Render resolution"),
.description = fmt::format(_cF("render resolution", "Pixels rendered per eye ({}x{}). Lower to gain performance."), int(width * config.resolution_scale), int(height * config.resolution_scale)),
.ui = ui_kind::slider,
.get_int = [&config] { return int(std::lround(config.resolution_scale * 100)); },
.set_int = [&config](int v) { config.resolution_scale = v / 100.0; config.save(); },
.v_min = 50,
.v_max = config.extended_config ? 350 : 150,
.fmt = "%d%%",
.default_int = int(std::lround(default_config.resolution_scale * 100)),
.enabled = [&ctx] { return not ctx.in_game; },
.disabled_tooltip = disconnect_tip,
});
}
if (rates.size() > 1 && ctx.instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME))
{
list.push_back({
.id = "##spacewarp",
.label = _("Application SpaceWarp"),
.description = _("Renders at half the refresh rate. The headset may synthesise frames."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.fps_divider == 2; },
.set_bool = [&ctx, &config](bool v) { config.fps_divider = v ? 2 : 1; config.save(); if (ctx.on_streaming_changed) ctx.on_streaming_changed(); },
.default_bool = default_config.fps_divider == 2,
.enabled = [&config] { return config.preferred_refresh_rate != 0; },
.disabled_tooltip = _("Set a refresh rate other than auto to enable this setting."),
});
}
ui::page_header(_cS("page header title", "Video"), _cS("page header subtitle", "Frame rate and resolution."));
render_settings(ctx, "##video", list);
}
void settings_streaming(const settings_context & ctx)
{
auto & config = ctx.config;
auto & default_config = ctx.default_config;
const std::string disconnect_tip = ctx.in_game ? _C("tooltip for disabled settings", "Disconnect to change this setting.") : std::string{};
std::vector<setting> list;
list.push_back({
.id = "##foveation",
.label = _("Foveated encoding"),
.description = config.check_feature(feature::eye_gaze)
? _("Higher values focus image quality where you look at, improving latency, power efficiency and quality.")
: _("Higher values focus image quality at the center, improving latency, power efficiency and quality."),
.ui = ui_kind::slider,
.get_int = [&config] { return int(std::lround((1 - config.get_stream_scale()) * 100)); },
.set_int = [&config](int v) {
if (not config.extended_config)
v = std::clamp(v, 30, 80);
config.set_stream_scale(1 - v * 0.01);
config.save(); },
.v_min = 0,
.v_max = 80,
.fmt = "%d%%",
.default_int = int(std::lround((1 - default_config.get_stream_scale()) * 100)),
.enabled = [&ctx] { return not ctx.in_game; },
.disabled_tooltip = disconnect_tip,
});
auto codec_name = [](std::optional<wivrn::video_codec> codec) -> std::string {
if (not codec)
return _C("Codec", "Automatic");
switch (*codec)
{
case wivrn::h264:
return _C("Codec", "H.264");
case wivrn::h265:
return _C("Codec", "HEVC (H.265)");
case wivrn::av1:
return _C("Codec", "AV1");
case wivrn::raw:
break;
}
return _C("Codec", "Automatic");
};
std::vector<wivrn::video_codec> codecs;
for (auto capability: wivrn::decoder::supported_codecs())
if (capability.codec != wivrn::raw)
codecs.push_back(capability.codec);
list.push_back({
.id = "##codec",
.label = _C("setting name", "Video codec"),
.description = _("How video is compressed before it is sent to the headset."),
.ui = ui_kind::combo,
.get_int = [&config, codecs] { return config.codec ? index(codecs, *config.codec).value_or(-1) + 1 : 0; },
.set_int = [&config, codecs](int v) {
config.codec = v == 0 ? std::nullopt : std::optional(codecs[v - 1]);
config.save(); },
.options = [codecs, codec_name] {
std::vector<std::string> opts;
opts.push_back(codec_name(std::nullopt));
for (auto c: codecs)
opts.push_back(codec_name(c));
return opts; },
.title = _C("setting name", "Video codec"),
.default_int = default_config.codec ? index(codecs, *default_config.codec).value_or(-1) + 1 : 0,
.enabled = [&ctx] { return not ctx.in_game; },
.disabled_tooltip = disconnect_tip,
});
if (config.codec && wivrn::decoder::supports_10bit(*config.codec))
{
list.push_back({
.id = "##ten_bit",
.label = _C("setting name", "10-bit color"),
.description = _("Higher color precision, supported by HEVC and AV1."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.bit_depth == 10; },
.set_bool = [&config](bool v) { config.bit_depth = v ? 10 : 8; config.save(); },
.default_bool = default_config.bit_depth == 10,
.enabled = [&ctx] { return not ctx.in_game; },
.disabled_tooltip = disconnect_tip,
});
}
const int mb = 1'000'000;
list.push_back({
.id = "##bitrate",
.label = _("Bitrate"),
.description = _("Video data rate sent to the headset."),
.ui = ui_kind::slider,
.get_int = [&config] { return int(config.bitrate_bps / mb); },
.set_int = [&ctx, &config](int v) { config.bitrate_bps = uint32_t(v) * mb; config.save(); if (ctx.on_streaming_changed) ctx.on_streaming_changed(); },
.v_min = 5,
.v_max = int(config.max_bitrate() / mb),
.fmt = "%d Mbit/s",
.default_int = int(default_config.bitrate_bps / mb),
});
// in-stream: steer where foveation focuses quality
if (ctx.in_game)
{
list.push_back({
.id = "##fov_override",
.label = _C("setting name", "Foveation center override"),
.description = _("Manually set where image quality is focused, instead of the center or your gaze."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.override_foveation_enable; },
.set_bool = [&ctx, &config](bool v) {
config.override_foveation_enable = v;
config.save();
if (ctx.on_foveation_override_changed)
ctx.on_foveation_override_changed(); },
.default_bool = default_config.override_foveation_enable,
});
list.push_back({
.id = "##fov_adjust",
.label = _C("setting name", "Foveation center"),
.description = fmt::format(_F("Height {:.1f} °, distance {:.2f} m"), -config.override_foveation_pitch * 180 / M_PI, config.override_foveation_distance),
.ui = ui_kind::button,
.button_label = _C("button label to change the foveation center", "Change"),
.on_click = [&ctx] { if (ctx.enter_foveation_adjust) ctx.enter_foveation_adjust(); },
.enabled = [&config] { return config.override_foveation_enable; },
.disabled_tooltip = _("Enable foveation center override to change this setting."),
});
}
ui::page_header(_cS("page header title", "Streaming"), _cS("page header subtitle", "How video is encoded and sent to the headset."));
render_settings(ctx, "##streaming", list);
if (wivrn::ui::confirm_modal(
"confirm disable in stream gui",
_C("confirmation messagebox title", "Disable in-stream window"),
_C("confirmation message", "Do you really want to disable the in-stream window?\nYou will not be able to re-open it with the thumbsticks."),
_("Yes"),
_("No"),
true) == 1)
{
config.enable_stream_gui = false;
config.save();
}
}
void settings_post_processing(const settings_context & ctx)
{
auto & config = ctx.config;
auto & default_config = ctx.default_config;
std::vector<setting> list;
if (application::get_openxr_post_processing_supported())
{
auto flag_name = [](XrCompositionLayerSettingsFlagsFB f) -> std::string {
switch (f)
{
case XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB:
case XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB:
return _C("openxr_post_processing", "Normal");
case XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB:
case XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB:
return _C("openxr_post_processing", "Quality");
default:
return _C("openxr_post_processing", "Disabled");
}
};
auto flag_combo = [&](const char * id, std::string label, std::string desc, std::array<XrCompositionLayerSettingsFlagsFB, 3> flags, XrCompositionLayerSettingsFlagsFB configuration::openxr_post_processing_settings::* member) {
std::string title = label;
list.push_back({
.id = id,
.label = std::move(label),
.description = std::move(desc),
.ui = ui_kind::combo,
.get_int = [&config, flags, member] { return index(flags, config.openxr_post_processing.*member).value_or(0); },
.set_int = [&config, flags, member](int v) {
config.openxr_post_processing.*member = flags[v];
config.save(); },
.options = [flags, flag_name] {
std::vector<std::string> o;
for (auto f: flags)
o.push_back(flag_name(f));
return o; },
.title = std::move(title),
.default_int = index(flags, config.openxr_post_processing.*member).value_or(0),
});
};
flag_combo("##supersampling", _("Supersampling"), _("Reduce flicker for high contrast edges. Useful when the input resolution is high compared to the headset display."), {0, XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SUPER_SAMPLING_BIT_FB, XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SUPER_SAMPLING_BIT_FB}, &configuration::openxr_post_processing_settings::super_sampling);
flag_combo("##sharpening", _("Sharpening"), _("Improve clarity of high contrast edges and counteract blur. Useful when the input resolution is low compared to the headset display."), {0, XR_COMPOSITION_LAYER_SETTINGS_NORMAL_SHARPENING_BIT_FB, XR_COMPOSITION_LAYER_SETTINGS_QUALITY_SHARPENING_BIT_FB}, &configuration::openxr_post_processing_settings::sharpening);
}
ui::page_header(_S("Post-processing"), _cS("page header subtitle", "OpenXR layer supersampling and sharpening."));
render_settings(ctx, "##post_processing", list);
}
void settings_audio(const settings_context & ctx)
{
auto & config = ctx.config;
auto & default_config = ctx.default_config;
const std::string disconnect_tip = ctx.in_game ? _C("tooltip for disabled settings", "Disconnect to change this setting.") : std::string{};
std::vector<setting> list;
list.push_back({
.id = "##microphone",
.label = _C("setting name", "Microphone"),
.description = _("Stream the headset microphone to the PC."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.check_feature(feature::microphone); },
.set_bool = [&config](bool v) { config.set_feature(feature::microphone, v); },
.default_bool = default_config.check_feature(feature::microphone),
.enabled = [&ctx] { return not ctx.in_game; },
.disabled_tooltip = disconnect_tip,
});
#ifdef __ANDROID__
list.push_back({
.id = "##unprocessed",
.label = _C("setting name", "Unprocessed audio"),
.description = _("Disable audio filters, such as noise cancellation."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.mic_unprocessed_audio; },
.set_bool = [&config](bool v) { config.mic_unprocessed_audio = v; config.save(); },
.default_bool = default_config.mic_unprocessed_audio,
.enabled = [&ctx, &config] { return not ctx.in_game and config.check_feature(feature::microphone); },
.disabled_tooltip = disconnect_tip,
});
#endif
ui::page_header(_cS("page header title", "Audio"), _cS("page header subtitle", "Microphone streamed to the PC."));
render_settings(ctx, "##audio", list);
}
void settings_devices(const settings_context & ctx)
{
auto & config = application::get_config();
auto & default_config = ctx.default_config;
std::vector<setting> list;
#ifdef __ANDROID__
list.push_back({
.id = "##keyboard",
.label = _C("setting name", "Keyboard"),
.description = _("Forward the keyboard from the headset to the PC."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.forward_keyboard; },
.set_bool = [&config](bool v) { config.forward_keyboard = v; config.save(); },
.default_bool = default_config.forward_keyboard,
});
list.push_back({
.id = "##mouse",
.label = _C("setting name", "Mouse"),
.description = _("Forward the mouse from the headset to the PC."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.forward_mouse; },
.set_bool = [&config](bool v) { config.forward_mouse = v; config.save(); },
.default_bool = default_config.forward_mouse,
});
#endif
list.push_back({
.id = "##gamepad",
.label = _C("setting name", "Gamepad"),
.description = _("Forward the gamepad from the headset to the PC."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.forward_gamepad; },
.set_bool = [&config](bool v) { config.forward_gamepad = v; config.save(); },
.default_bool = default_config.forward_gamepad,
});
ui::page_header(_cS("page header title", "Devices"), _cS("page header subtitle", "Forward input devices to the PC."));
render_settings(ctx, "##devices", list);
if (ctx.server_hid_forwarding == false and (config.forward_keyboard or config.forward_mouse or config.forward_gamepad))
ui::chip(_("The server does not allow forwarded input devices"), ui::chip_style::warning);
}
bool settings_tracking(const settings_context & ctx)
{
auto & config = ctx.config;
auto & default_config = ctx.default_config;
const std::string disconnect_tip = ctx.in_game ? _C("tooltip for disabled settings", "Disconnect to change this setting.") : std::string{};
std::vector<setting> list, posture_items;
const posture current_posture = config.get_posture();
const bool seated = current_posture == posture::seated;
const float default_height_offset = seated ? configuration::default_height_offset_seated : configuration::default_height_offset_standing;
posture_items.push_back({
.id = "##posture",
.label = _C("setting name", "Posture"),
.description = _("Posture assumed when a stream connects."),
.ui = ui_kind::segmented,
.get_int = [seated] { return seated ? 1 : 0; },
.set_int = [&config](int v) { config.set_posture(v ? posture::seated : posture::standing); config.save(); },
.options = [] { return std::vector<std::string>{_C("posture", "Standing"), _C("posture", "Seated")}; },
.default_int = default_config.get_posture() == posture::seated ? 1 : 0,
});
posture_items.push_back({
.id = "##height_offset",
.label = _C("setting name", "Height adjustment"),
.description = seated
? _("Corrects the height reported to the PC when seated, useful for games without native seated support.")
: _("Corrects the height reported to the PC when standing, useful for a miscalibrated floor."),
.ui = ui_kind::slider,
.get_int = [&config] { return int(std::lround(config.get_height_offset() * 100)); },
.set_int = [&config](int v) { config.set_height_offset(v / 100.f); config.save(); },
.v_min = -30,
.v_max = 70,
.fmt = "%d cm",
.default_int = int(std::lround(default_height_offset * 100)),
});
auto feature_toggle = [&](const char * id, std::string label, std::string desc, feature f) {
list.push_back({
.id = id,
.label = std::move(label),
.description = std::move(desc),
.ui = ui_kind::toggle,
.get_bool = [&config, f] { return config.check_feature(f); },
.set_bool = [&config, f](bool v) { config.set_feature(f, v); },
.default_bool = default_config.check_feature(f),
.enabled = [&ctx] { return not ctx.in_game; },
.disabled_tooltip = disconnect_tip,
});
};
if (ctx.system.hand_tracking_supported())
feature_toggle("##hand", _C("setting name", "Hand tracking"), _("Track your hands for input when controllers are down."), feature::hand_tracking);
if (application::get_eye_gaze_supported())
feature_toggle("##eye", _C("setting name", "Eye tracking"), _("Used by foveated encoding to focus quality where you look."), feature::eye_gaze);
if (ctx.system.face_tracker_supported() != xr::face_tracker_type::none)
feature_toggle("##face", _C("setting name", "Face tracking"), _("Stream facial expressions to the PC."), feature::face_tracking);
const auto body_tracker = ctx.system.body_tracker_supported();
std::vector<char> body_parts_default;
std::vector<std::string> body_parts_names;
std::vector<from_headset::body_part_mask> body_parts_bit;
for (const auto & [bit, name]: {
std::make_pair(from_headset::body_part_mask::chest, _C("virtual body tracker selection", "Chest")),
std::make_pair(from_headset::body_part_mask::left_elbow, _C("virtual body tracker selection", "Left elbow")),
std::make_pair(from_headset::body_part_mask::right_elbow, _C("virtual body tracker selection", "Right elbow")),
std::make_pair(from_headset::body_part_mask::hip, _C("virtual body tracker selection", "Hip")),
std::make_pair(from_headset::body_part_mask::left_knee, _C("virtual body tracker selection", "Left knee")),
std::make_pair(from_headset::body_part_mask::right_knee, _C("virtual body tracker selection", "Right knee")),
std::make_pair(from_headset::body_part_mask::left_foot, _C("virtual body tracker selection", "Left foot")),
std::make_pair(from_headset::body_part_mask::right_foot, _C("virtual body tracker selection", "Right foot")),
})
{
if (body_tracker == xr::body_tracker_type::fb and bit > from_headset::body_part_mask::hip)
break;
body_parts_default.push_back((default_config.body_part_mask & std::to_underlying(bit)) != 0);
body_parts_names.push_back(name);
body_parts_bit.push_back(bit);
}
bool changed = false;
if (body_tracker != xr::body_tracker_type::none)
{
list.push_back({
.id = "##body",
.label = _C("setting name", "Body tracking"),
.description = body_tracker == xr::body_tracker_type::fb or body_tracker == xr::body_tracker_type::meta
? _("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings, otherwise body data will be guessed from controller and headset positions.")
: _("Stream body joint positions to the PC."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.check_feature(feature::body_tracking); },
.set_bool = [&config](bool v) { config.set_feature(feature::body_tracking, v); },
.default_bool = default_config.check_feature(feature::body_tracking),
.enabled = [&ctx] { return not ctx.in_game; },
.disabled_tooltip = disconnect_tip,
});
list.push_back({
.id = "##body_tracking_parts",
.label = _C("setting name", "Virtual body trackers"),
.description = _("Create virtual tracker devices."),
.ui = ui_kind::combo_multi,
.get_multi = [&config, &body_parts_bit](int index) {
const auto underlying = std::to_underlying(body_parts_bit[index]);
return config.body_part_mask & underlying; },
.set_multi = [&config, &body_parts_bit, &changed](int index, bool value) {
const auto underlying = std::to_underlying(body_parts_bit[index]);
if (value)
config.body_part_mask |= underlying;
else
config.body_part_mask &= ~underlying;
config.save();
changed = true; },
.options = [&body_parts_names]() { return body_parts_names; },
.title = _C("setting name", "Virtual body trackers"),
.default_multi = body_parts_default,
.disabled_tooltip = disconnect_tip,
});
}
ui::page_header(_cS("page header title", "Tracking"), _cS("page header subtitle", "Body and input tracking sent to the PC."));
render_settings(ctx, "##tracking", list);
render_settings(ctx, "##posture", posture_items);
return changed;
}
void settings_system(const settings_context & ctx)
{
auto & config = ctx.config;
auto & default_config = ctx.default_config;
std::vector<setting> list;
auto language_name = [](const std::locale & loc = std::locale()) {
return boost::locale::pgettext("language selection, replace with the name of the language", "English", loc);
};
std::vector<std::tuple<std::string, std::locale, std::string>> languages;
for (const auto & msg_info: get_locales())
{
std::string code = msg_info.language;
if (not msg_info.country.empty())
code += "_" + msg_info.country;
std::locale loc(std::locale(), boost::locale::gnu_gettext::create_messages_facet<char>(msg_info));
languages.emplace_back(language_name(loc), loc, std::move(code));
}
std::ranges::sort(languages, [](auto & l, auto & r) { return std::get<0>(l) < std::get<0>(r); });
auto language_index = [languages](const configuration & cfg) {
if (cfg.locale != "")
for (size_t i = 0; i < languages.size(); ++i)
if (std::get<2>(languages[i]) == cfg.locale)
return int(i) + 1;
return 0;
};
list.push_back({
.id = "##language",
.label = _("Language"),
.description = _C("setting name", "Interface language."),
.ui = ui_kind::combo,
.get_int = [&config, language_index] { return language_index(config); },
.set_int = [&config, languages](int v) {
config.locale = v == 0 ? "" : std::get<2>(languages[v - 1]);
config.save();
application::instance().load_locale(); },
.options = [languages] {
std::vector<std::string> opts;
opts.push_back(_C("item in the interface language combobox", "System language"));
for (const auto & [lang, loc, code]: languages)
opts.push_back(lang);
return opts; },
.title = _("Language"),
.default_int = language_index(default_config),
});
#ifdef __ANDROID__
if (application::get_hmd_traits().usb_net)
list.push_back({
.id = "##usbnet",
.label = _C("setting name", "USB networking"),
.description = _("Enables connection by USB without ADB or developer mode.\nMake sure the server allows IPv6 link-local only connections."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.usb_network; },
.set_bool = [&config](bool v) { config.usb_network = v;config.save(); application::instance().set_usb_networking(v); },
.default_bool = default_config.usb_network,
});
#endif
list.push_back({
.id = "##extended",
.label = _C("setting name", "Extended configuration"),
.description = _("Allows unsafe configuration values, use at your own risk."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.extended_config; },
.set_bool = [&config](bool v) { config.extended_config = v; config.save(); },
.default_bool = default_config.extended_config,
});
if (ctx.instance.has_extension(XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME))
{
list.push_back({
.id = "##high_power",
.label = _("High power mode"),
.description = _("Increase power usage to allow higher resolution and refresh rate. Drains battery and runs hot."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.high_power_mode; },
.set_bool = [&config](bool v) { config.high_power_mode = v; config.save(); },
.default_bool = default_config.high_power_mode,
});
}
if (ctx.session.boundary_visibility_supported())
{
list.push_back({
.id = "##passthrough_boundary",
.label = _C("setting name", "Enable boundary in passthrough"),
.description = _("Shows the boundary while passthrough is on. Disable to walk freely outside of it. The boundary is always shown in VR."),
.ui = ui_kind::toggle,
.get_bool = [&config] { return config.passthrough_boundary_enabled; },
.set_bool = [&ctx, &config](bool v) { config.passthrough_boundary_enabled = v; config.save(); ctx.session.set_passthrough_boundary_enabled(v); },
.default_bool = default_config.passthrough_boundary_enabled,
});
}
bool disable_instream_gui = false;
bool disable_instream_gui_popup_open = ImGui::IsPopupOpen("confirm disable in stream gui");
list.push_back({
.id = "##stream_gui",
.label = _C("setting name", "In-stream window"),
.description = _("Enables the configuration window to be shown while the game is streaming. If enabled, the window is activated by pressing both thumbsticks."),
.ui = ui_kind::toggle,
.get_bool = [&config, &disable_instream_gui_popup_open] { return config.enable_stream_gui and not disable_instream_gui_popup_open; },
.set_bool = [&ctx, &config, &disable_instream_gui](bool v) {
if (ctx.in_game and not v)
{
disable_instream_gui = true;
}
else
{
config.enable_stream_gui = v;
config.save();
} },
.default_bool = default_config.enable_stream_gui,
});
ui::page_header(_cS("page header title", "System"), _cS("page header suibtitle", "Language and advanced options."));
render_settings(ctx, "##system", list);
if (disable_instream_gui)
ImGui::OpenPopup("confirm disable in stream gui");
}
void settings_theme(const settings_context & ctx)
{
ui::theme & theme = ui::current();
auto & config = ctx.config;
auto & default_config = ctx.default_config;
ui::page_header(_cS("page header title", "Theme"), _cS("page header subtitle", "Accent color, palette and sizing of the interface."));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ui::metrics::card_item_spacing);
const float control_w = ui::metrics::setting_control_width;
ui::begin_card("##theme");
{
// Accent
ImGui::TextUnformatted(_cS("setting name", "Accent color"));
ImGui::Dummy({0, 2});
for (const auto & swatch: ui::accent_swatches())
{
const bool selected = theme.accent.x == swatch.base.x and theme.accent.y == swatch.base.y and theme.accent.z == swatch.base.z;
const auto flags = ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoBorder | (selected ? 0 : ImGuiColorEditFlags_NoDragDrop);
if (ImGui::ColorButton(swatch.name, swatch.base, flags, {ImGui::GetFrameHeight() * 1.4f, ImGui::GetFrameHeight() * 1.4f}))
{
ui::set_accent(swatch);
config.theme_accent = swatch.name;
config.save();
}
ImGui::SameLine();
}
ImGui::NewLine();
ui::row_separator();
// Preset
const auto preset_list = ui::presets();
std::vector<ui::combo_item> preset_items;
for (const auto & p: preset_list)
preset_items.push_back({p.localized_name.c_str()});
// seed the selection from the saved preset so the box matches what is applied
auto f = [&](const configuration & cfg) {
for (int i = 0; i < int(preset_list.size()); ++i)
if (preset_list[i].name == cfg.theme_preset)
return i;
return 1; // dark_default
};
static int preset = f(config);
static const int preset_default = f(default_config);
ui::setting_label(_cS("setting name", "Preset"), _cS("setting description", "Surface and background palette"), control_w);
if (ui::combo("##preset", _("Theme preset"), preset_items, &preset, control_w, &preset_default))
{
// keep the accent across a preset change, only the surfaces swap
const ImVec4 keep_accent = theme.accent;
const ImVec4 keep_hover = theme.accent_hovered;
const ImVec4 keep_active = theme.accent_active;
ui::set_theme(preset_list[preset]);
theme.accent = keep_accent;
theme.accent_hovered = keep_hover;
theme.accent_active = keep_active;
config.theme_preset = preset_list[preset].name;
config.save();
}
ui::row_separator();
// Rounding
static const int rounding_default = default_config.theme_rounding;
int rounding = int(theme.rounding);
ui::setting_label(_cS("setting label", "Rounding"), _cS("setting description", "Corner radius of controls"), control_w);
if (ui::slider_int("##rounding", &rounding, 0, 20, "%d px", {control_w, 0}, &rounding_default))
{
theme.rounding = float(rounding);
config.theme_rounding = theme.rounding;
config.save();
}
ui::row_separator();
static const int card_rounding_default = 14;
int card_rounding = int(theme.card_rounding);
ui::setting_label(_cS("setting label", "Card rounding"), _cS("setting description", "Corner radius of panels"), control_w);
if (ui::slider_int("##card_rounding", &card_rounding, 0, 28, "%d px", {control_w, 0}, &card_rounding_default))
{
theme.card_rounding = float(card_rounding);
config.theme_card_rounding = theme.card_rounding;
config.save();
}
ui::row_separator();
// global font scale, 100% is the design default
static const int font_scale_default = 100;
int font_scale = int(theme.font_scale * 100);
ui::setting_label(_cS("setting name", "Text size"), _cS("setting description", "Global font scale"), control_w);
if (ui::slider_int("##font_scale", &font_scale, 60, 140, "%d%%", {control_w, 0}, &font_scale_default))
{
theme.font_scale = float(font_scale) / 100.f;
config.theme_font_scale = theme.font_scale;
config.save();
}
ui::row_separator();
// Panel transparency, independent of the selected preset
static const int opacity_default = int(default_config.theme_background_alpha * 100 + 0.5);
int opacity = int(ui::background_alpha() * 100 + 0.5);
ui::setting_label(_cS("setting name", "Panel opacity"), _cS("setting description", "Opacity of the panel and card backgrounds"), control_w);
if (ui::slider_int("##opacity", &opacity, 20, 100, "%d%%", {control_w, 0}, &opacity_default))
{
ui::background_alpha() = float(opacity) / 100.f;
config.theme_background_alpha = ui::background_alpha();
config.save();
}
ui::end_card();
}
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
}
} // namespace wivrn::gui