diff --git a/.gitattributes b/.gitattributes index 5177621..f4e8384 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,6 +3,7 @@ *.py text eol=lf *.yml text eol=lf *.desktop text eol=lf +*.bat text eol=crlf *.spv binary *.png binary *.jpg binary diff --git a/.gitignore b/.gitignore index ff82dfc..3c410c7 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,5 @@ Thumbs.db /scratch/ /test_vault /*-plan.md +/test_*.cpp +/protected-*.md diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fa2510..d2412c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,6 +122,8 @@ add_library(pixelvr_core STATIC src/xr/xr_result.cpp src/xr/xr_context.cpp src/xr/render_model.cpp + src/xr/vr_keyboard.cpp + src/net/smb_credentials.cpp src/gfx/vulkan_renderer.cpp src/gfx/gltf_mesh.cpp src/ui/settings_menu.cpp @@ -130,7 +132,8 @@ add_library(pixelvr_core STATIC src/app/app.cpp) target_include_directories(pixelvr_core PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/src") + "${CMAKE_CURRENT_SOURCE_DIR}/src" + "${CMAKE_CURRENT_SOURCE_DIR}/third_party/openvr") target_include_directories(pixelvr_core PRIVATE "${cgltf_SOURCE_DIR}" "${stb_SOURCE_DIR}") target_compile_definitions(pixelvr_core PUBLIC @@ -141,7 +144,8 @@ target_compile_definitions(pixelvr_core PUBLIC target_link_libraries(pixelvr_core PUBLIC OpenXR::openxr_loader Vulkan::Vulkan - Threads::Threads) + Threads::Threads + ${CMAKE_DL_LIBS}) add_dependencies(pixelvr_core pixelvr_shaders) diff --git a/README.md b/README.md index 342cca8..7050c44 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ A native VR video player for the **Valve Steam Frame**, playing flat 2D, 180°, > NV12) with zero-copy dma-buf import; flat / 180° / 360° projection and mono / > SBS (including half-SBS) / TB stereo, auto-detected from the filename; spatial > audio with a master clock. In-headset UI: file browser (with file type and -> size), transport bar, settings menu, downloads manager, and an encrypted hidden vault. Native Valve +> size), transport bar, settings menu, downloads manager, bookmarks overview, +> protected SMB network share manager with virtual keyboard laser auto-focus, +> and an encrypted hidden vault. Native Valve > Steam Frame controller support (`XR_VALVE_frame_controller_interaction`) using > the runtime's own render model, with per-button animation on the model and > press-to-bind remapping. @@ -97,6 +99,53 @@ V4L2 M2M decoders. For zero-copy dma-buf decoding, build the patched FFmpeg into back to the system FFmpeg with CPU colour conversion. +## Updating + +Updating Pixel VR Player is seamless, fast, and 100% non-destructive. + +> [!NOTE] +> **Your data is always preserved!** +> All user preferences (`~/.config/pixelvr/config.json`), saved SMB network shares and credentials (`~/.config/pixelvr/smb_shares.json`), quick bookmarks (`~/.config/pixelvr/bookmarks.json`), cached video thumbnails (`~/.cache/pixelvr`), and encrypted media in the Discreet Vault (`~/.pixelvr_vault`) are stored outside the application folder and remain completely untouched across updates. + +Choose your preferred update method: + +### Method 1: 1-Click Desktop Update (Easiest on Headset) + +No terminal or typing required: +1. Switch your Steam Frame to **Desktop Mode** (Power menu in SteamVR or SteamOS). +2. Double-click the **`Update Pixel VR Player`** icon on your Desktop. +3. A popup will notify you that the update has started. The updater verifies SHA-256 checksums and updates the app in-place. +4. When finished, a completion notification will appear. Switch back to Gaming Mode and launch the player! + +*(Alternatively, open Dolphin file manager, navigate to `~/PixelVRPlayer`, and double-click `update.sh`)*. + +### Method 2: 1-Click Update from your PC over Wi-Fi + +Update your headset remotely over your local network: +- **Windows:** Double-click [`tools/update-from-pc.bat`](tools/update-from-pc.bat), enter your Steam Frame's IP address, and press Enter. +- **macOS / Linux:** Run `./tools/update-from-pc.sh `. + +### Method 3: One Command in Headset Terminal (Konsole / SSH) + +Open **Konsole** on the headset or connect via SSH, then run: + +```bash +~/PixelVRPlayer/update.sh +``` + +Or re-run the web installer command: + +```bash +curl -fsSL https://raw.githubusercontent.com/Pixelplanet/Pixel-VR-Player/main/tools/install.sh | sh +``` + +### Method 4: USB Drive / MicroSD Card (Offline) + +1. Download `pixelvr-linux-arm64.tar.gz` from the [Releases](https://github.com/Pixelplanet/Pixel-VR-Player/releases) page to a USB flash drive or MicroSD card. +2. Plug it into your Steam Frame and open it in Desktop Mode. +3. Double-click **`Install Pixel VR Player.desktop`** (or run `./install.sh --update` from the unpacked folder). + + ## Uninstallation To remove Pixel VR Player and its Steam shortcut from your Steam Frame: diff --git a/TODO.md b/TODO.md index cd2286e..a1bffee 100644 --- a/TODO.md +++ b/TODO.md @@ -7,19 +7,71 @@ --- -## Active backlog (2026-10-14) +## Active backlog (2026-10-19 — Completed) + +- [x] **1. Fix Virtual Keyboard Laser Pointer Focus & Tracking** + - **Symptom:** Virtual keyboard opened, but laser pointer disappeared or wasn't focused on the keyboard; user had to squeeze/press the controller grip fully to activate it. + - **Root Cause:** + - SteamVR's `vrcompositor` switches system panel interaction mode to Gamepad (mode 0, hiding `system.pointer`) on session focus loss unless an interactive overlay requiring laser mouse is currently visible (`bOverlaysPresentThatForceLaserMouseOn`). + - `inputOverlay_` was created in `VrKeyboard::init()` but was **never shown** (`ShowOverlay` was never called, had no texture, dimensions, or transform). + - SteamVR's virtual keyboard overlay `valve.steam.gamepadui.keyboard` is spawned asynchronously and lacks `MakeOverlaysInteractiveIfVisible` by default. + - **Resolution:** + - Fully configured `inputOverlay_` in `VrKeyboard::show()`: set width (1.0m), HMD-relative transform (1.1m in front, tilted), 1x1 transparent raw pixel texture (`SetOverlayRaw`), and docked keyboard position (`SetKeyboardPositionForOverlay`). + - Called `ov->ShowOverlay(inputOverlay_)` before calling `ShowKeyboardForOverlay`, ensuring `vrcompositor`'s overlay scan sets `m_bOverlaysPresentThatForceLaserMouseOn = 1`. + - Added dynamic polling in `VrKeyboard::poll()` to detect and configure `MakeOverlaysInteractiveIfVisible` and `VROverlayInputMethod_Mouse` on `valve.steam.gamepadui.keyboard` as soon as it appears. + - Added proper overlay cleanup (`HideOverlay(inputOverlay_)`) in `hide()`, `KeyboardDone`, and `KeyboardClosed`. + +- [x] **2. Strict IPv4 Validation & Live Sanitization** + - **Symptom:** Host field accepted invalid characters, spaces, and did not strip leading zeros. + - **Resolution:** + - Created `src/util/ipv4.hpp` with `sanitizeIpv4()` and `isValidIpv4()`. + - Live typing sanitization: automatically strips non-digits/dots, discards duplicate dots, clamps octets to 255, drops leading zeros in each octet (e.g. `001` -> `1`, `010` -> `10`, `00` -> `0`), limits to 4 octets, and preserves trailing dots while typing. + - Added automated unit test suite `tests/test_ipv4.cpp` and verified all test cases pass on the device. + - Verified strict `isValidIpv4()` validation before saving an SMB share in `saveSmbModal()`. + +- [x] **3. Fix `???` Glyphs (Unicode Star Elimination)** + - **Symptom:** Sidebar and header button displayed `???` instead of the star icon. + - **Root Cause:** FreeType SDF text atlas was initialized only for ASCII codepoints 32..127. UTF-8 multi-byte sequence `★` (`\xe2\x98\x85`) produced 3 replacement `?` characters. + - **Resolution:** Replaced all UTF-8 star glyphs with clean ASCII strings: `"Bookmarks"`, `"[ Bookmarked ]"`, and `"[ + Bookmark ]"`. Adjusted header breadcrumb max width to `0.46f` to prevent collision with the header button. + +- [x] **4. Rename Quick Path to Bookmarks & Implement Multi-Bookmark Overview (`bookmarks://`)** + - **Requirement:** Rename Quick Path to Bookmarks, and have the Bookmarks sidebar tab open an overview showing all bookmarked folders and files in regular browser views. + - **Resolution:** + - Added `Bookmark` struct and multi-bookmark storage in `Browser` with persistent JSON serialization to `~/.config/pixelvr/bookmarks.json`. + - Implemented `bookmarks://` virtual directory navigation displaying all bookmarked paths with full cards (BigCards, MiniCards) and CompactList support, thumbnails, and direct activation. + - Sidebar subtab 4 navigates to `bookmarks://` with proper active tab highlighting. + - Header button toggles bookmark for the current open directory (`[ + Bookmark ]` / `[ Bookmarked ]`). + - Action Menu (Y button) provides `"Add to Bookmarks"` / `"Remove from Bookmarks"` / `"Go to Bookmarks"`, and in `bookmarks://` provides `"Open Bookmark"` / `"Remove Bookmark"`. + - Updated Settings Menu shortcut label to `"Bookmarks Shortcut"`. + +- [x] **5. Seamless 1-Click Update System & Streamlined Distribution** + - **Requirement:** Provide easy, friction-free updating so users do not need to memorize terminal commands or worry about losing their settings. + - **Resolution:** + - Added standalone local updater `tools/update.sh` and `--update` flag to `tools/install.sh`. + - Added KDE Plasma `Update Pixel VR Player.desktop` desktop shortcut deployed automatically to `~/Desktop/`. + - Added remote Wi-Fi 1-click updaters for PC users (`tools/update-from-pc.bat` for Windows and `tools/update-from-pc.sh` for macOS/Linux). + - Updated `tools/package-release.sh` to package updater scripts in the release tarball. + - Updated `README.md` with comprehensive update instructions across all platforms. + + +--- + +## Carried over & Completed -Carried over: - [ ] A. Full-pitch recenter (usable lying down) — reorient screen + controls + 360/180 to full head orientation, not just horizon yaw. - [ ] B. Real controller models (glTF) rendered with depth. - [ ] C. Dynamic controller button labels from the user's bindings. -New (2026-10-14): -- [x] D. Flat SBS/TB: detect + a working flat-stereo render mode (split per eye). -- [x] E. Settings split into sections. -- [x] F. Settings: pick video stream, audio stream, and a default audio language. -- [ ] G. Downloads view: active downloads + speed + ETA; keep running in background. -- [x] H. Sharper menu text (SDF). +Completed (2026-10-18): +- [x] I. Laser auto-release when pressing Steam button (unfocused session gates controller pointer). +- [x] J. Native SteamVR / SteamOS Virtual Keyboard integration (OpenVR GamepadTextInput via dlopen). +- [x] K. Protected SMB credentials manager: hardware-keyed AES-GCM encryption, strict permissions, full CRUD. +- [x] L. Settings > Network & SMB Shares: manual IP/hostname input, authentication settings, auto-listed in Network browser. +- [x] M. UI Follow Mode: Mode 0 (Rock-solid World Lock default, zero drift/tilt) and Mode 1 (Smooth Follow). +- [x] N. Player UI dismissal: `[ ✕ Hide ]` button, empty space click-outside dismissal, B/Y toggle, and micro-tremor filtering (>0.06m threshold). +- [x] O. Quick Path Whirligig-style bookmarking header button + R3 controller shortcut button. + + --- diff --git a/src/app/app.cpp b/src/app/app.cpp index 227520e..58b5720 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1,5 +1,8 @@ #include "app/app.hpp" #include "app/vault_manager.hpp" +#include "net/smb_credentials.hpp" +#include "xr/vr_keyboard.hpp" +#include "util/ipv4.hpp" #include "util/logging.hpp" @@ -537,7 +540,7 @@ void App::performVaultLock() { thumbnailCache_.clearVaultThumbs(VaultManager::instance().vaultDir()); #endif - if (settings_.section() == 4) { + if (settings_.section() == 5) { settings_.setSection(0); } settings_.refresh(); @@ -545,26 +548,191 @@ void App::performVaultLock() { PIXELVR_LOG_INFO("Vault locked and sanitized"); } +void App::openSmbModal(bool isNew, const std::string& smbPath) { +#ifdef PIXELVR_HAVE_FREETYPE + smbModal_.active = true; + smbModal_.isNew = isNew; + smbModal_.editingField = SmbModalState::Field::None; + + if (isNew) { + smbModal_.origHost.clear(); + smbModal_.origShare.clear(); + smbModal_.host.clear(); + smbModal_.share.clear(); + smbModal_.anon = false; + smbModal_.user.clear(); + smbModal_.pass.clear(); + smbModal_.workgroup = "WORKGROUP"; + smbModal_.label.clear(); + } else { + std::string rest = smbPath; + if (rest.rfind("smb://", 0) == 0) rest = rest.substr(6); + while (!rest.empty() && rest.back() == '/') rest.pop_back(); + auto slash = rest.find('/'); + std::string host = (slash == std::string::npos) ? rest : rest.substr(0, slash); + std::string share = (slash == std::string::npos) ? "" : rest.substr(slash + 1); + + smbModal_.origHost = host; + smbModal_.origShare = share; + smbModal_.host = host; + smbModal_.share = share; + smbModal_.anon = false; + smbModal_.user.clear(); + smbModal_.pass.clear(); + smbModal_.workgroup = "WORKGROUP"; + smbModal_.label.clear(); + + SmbShare existing; + if (SmbCredentialsManager::instance().findShare(host, share, existing)) { + smbModal_.anon = existing.anonymous; + smbModal_.user = existing.username; + smbModal_.pass = existing.password; + smbModal_.workgroup = existing.workgroup.empty() ? "WORKGROUP" : existing.workgroup; + smbModal_.label = existing.name; + } + } + + actionMenu_.visible = true; + actionMenu_.page = 4; + actionMenu_.selectedOption = 0; + updateSmbModalMenu(); +#endif +} + +void App::updateSmbModalMenu() { +#ifdef PIXELVR_HAVE_FREETYPE + actionMenu_.title = smbModal_.isNew ? "Add SMB Network Share" : "Edit SMB Network Share"; + actionMenu_.subtitle = "Point & click a field to enter text via keyboard"; + actionMenu_.options.clear(); + + actionMenu_.options.push_back("Server IP: " + (smbModal_.host.empty() ? "[ Enter IPv4 Address ]" : smbModal_.host)); + actionMenu_.options.push_back("Share Name: " + (smbModal_.share.empty() ? "[ All Shares ]" : smbModal_.share)); + actionMenu_.options.push_back("Authentication: " + std::string(smbModal_.anon ? "Guest / Anonymous" : "Username & Password")); + actionMenu_.options.push_back("Username: " + (smbModal_.user.empty() ? "[ Enter Username ]" : smbModal_.user)); + actionMenu_.options.push_back("Password: " + (smbModal_.pass.empty() ? "[ Enter Password ]" : std::string(smbModal_.pass.length(), '*'))); + actionMenu_.options.push_back("Workgroup: " + smbModal_.workgroup); + actionMenu_.options.push_back("Nickname: " + (smbModal_.label.empty() ? "[ Optional Nickname ]" : smbModal_.label)); + + actionMenu_.options.push_back("[ Save SMB Share ]"); + if (!smbModal_.isNew) { + actionMenu_.options.push_back("[ Delete Share ]"); + } + actionMenu_.options.push_back("[ Cancel ]"); +#endif +} + +void App::saveSmbModal() { +#ifdef PIXELVR_HAVE_FREETYPE + if (smbModal_.host.empty()) { + actionMenu_.subtitle = "Error: Server IPv4 address is required!"; + return; + } + std::string cleanHost = sanitizeIpv4(smbModal_.host, true); + if (!isValidIpv4(cleanHost)) { + actionMenu_.subtitle = "Error: Invalid IPv4 address (e.g. 192.168.1.100)"; + return; + } + smbModal_.host = cleanHost; + if (!smbModal_.isNew && (smbModal_.host != smbModal_.origHost || smbModal_.share != smbModal_.origShare)) { + SmbCredentialsManager::instance().deleteShare(smbModal_.origHost, smbModal_.origShare); + } + SmbShare s; + s.host = smbModal_.host; + s.share = smbModal_.share; + s.username = smbModal_.user; + s.password = smbModal_.pass; + s.workgroup = smbModal_.workgroup.empty() ? "WORKGROUP" : smbModal_.workgroup; + s.name = smbModal_.label.empty() ? (s.host + (s.share.empty() ? "" : ("/" + s.share))) : smbModal_.label; + s.id = s.host + (s.share.empty() ? "" : ("/" + s.share)); + s.anonymous = smbModal_.anon; + + SmbCredentialsManager::instance().addOrUpdateShare(s); + + smbModal_.active = false; + actionMenu_.visible = false; + browser_.openNetwork(); +#endif +} + +void App::deleteSmbModal() { +#ifdef PIXELVR_HAVE_FREETYPE + if (!smbModal_.isNew) { + SmbCredentialsManager::instance().deleteShare(smbModal_.origHost, smbModal_.origShare); + } + smbModal_.active = false; + actionMenu_.visible = false; + browser_.openNetwork(); +#endif +} + void App::openActionMenu() { #ifdef PIXELVR_HAVE_FREETYPE const Browser::Entry* fe = browser_.focused(); - if (fe == nullptr || fe->isBack || browser_.onNetwork()) return; - actionMenu_.visible = true; actionMenu_.page = 0; actionMenu_.selectedOption = 0; + actionMenu_.options.clear(); + actionMenu_.renameBuffer.clear(); + + const bool inBookmarks = (browser_.currentPath() == "bookmarks://"); + if (inBookmarks) { + actionMenu_.title = "Bookmarks"; + actionMenu_.subtitle = (fe && !fe->isBack) ? fe->label : "Bookmarks Overview"; + if (fe && !fe->isBack) { + actionMenu_.options.push_back("Open Bookmark"); + actionMenu_.options.push_back("Remove Bookmark"); + } + actionMenu_.options.push_back("Cancel"); + return; + } + + const bool hasFocused = (fe != nullptr && !fe->isBack && fe->path != "smb://__add_share__"); + if (!hasFocused) { + actionMenu_.title = "Folder Actions"; + actionMenu_.subtitle = browser_.currentPath(); + if (browser_.isCurrentBookmarked()) { + actionMenu_.options.push_back("Remove from Bookmarks"); + } else { + actionMenu_.options.push_back("Add to Bookmarks"); + } + actionMenu_.options.push_back("Go to Bookmarks"); + actionMenu_.options.push_back("Cancel"); + return; + } + actionMenu_.title = fe->isDir ? "Folder Actions" : "File Actions"; actionMenu_.subtitle = fe->label; - actionMenu_.options.clear(); - if (VaultManager::instance().isUnlocked() && !browser_.inVault()) { - actionMenu_.options.push_back("Move to Vault"); + const bool isSmbRoot = (browser_.currentPath() == "smb://" || browser_.currentPath().empty()); + const bool isSmbEntry = (fe->path.rfind("smb://", 0) == 0); + + if (isSmbRoot && isSmbEntry) { + actionMenu_.options.push_back("Open Share"); + actionMenu_.options.push_back("Edit SMB Share"); + actionMenu_.options.push_back("Delete SMB Share"); + if (browser_.isBookmarked(fe->path)) { + actionMenu_.options.push_back("Remove from Bookmarks"); + } else { + actionMenu_.options.push_back("Add to Bookmarks"); + } + } else { + const std::string itemPath = (fe && fe->isDir) ? fe->path : browser_.currentPath(); + if (browser_.isBookmarked(itemPath)) { + actionMenu_.options.push_back("Remove from Bookmarks"); + } else { + actionMenu_.options.push_back(fe->isDir ? "Add to Bookmarks" : "Add Folder to Bookmarks"); + } + actionMenu_.options.push_back("Go to Bookmarks"); + if (!browser_.onNetwork()) { + if (VaultManager::instance().isUnlocked() && !browser_.inVault()) { + actionMenu_.options.push_back("Move to Vault"); + } + actionMenu_.options.push_back("Move To..."); + actionMenu_.options.push_back("Rename"); + actionMenu_.options.push_back("Delete"); + } } - actionMenu_.options.push_back("Move To..."); - actionMenu_.options.push_back("Rename"); - actionMenu_.options.push_back("Delete"); actionMenu_.options.push_back("Cancel"); - actionMenu_.renameBuffer.clear(); #endif } @@ -613,6 +781,57 @@ int App::run() { const auto nowT = std::chrono::steady_clock::now(); XrInputState in = xr_.input(); + // Poll native SteamVR virtual keyboard events if active + VrKeyboard::instance().poll( + [this](const std::string& text) { + if (smbModal_.active) { + if (smbModal_.editingField == SmbModalState::Field::Host) { + smbModal_.host = sanitizeIpv4(text, true); + } else if (smbModal_.editingField == SmbModalState::Field::Share) { + std::string s = text; + while (!s.empty() && (s.front() == '/' || s.front() == '\\')) s.erase(s.begin()); + while (!s.empty() && (s.back() == '/' || s.back() == '\\')) s.pop_back(); + smbModal_.share = s; + } else if (smbModal_.editingField == SmbModalState::Field::User) { + smbModal_.user = text; + } else if (smbModal_.editingField == SmbModalState::Field::Pass) { + smbModal_.pass = text; + } else if (smbModal_.editingField == SmbModalState::Field::Workgroup) { + smbModal_.workgroup = text.empty() ? "WORKGROUP" : text; + } else if (smbModal_.editingField == SmbModalState::Field::Label) { + smbModal_.label = text; + } + smbModal_.editingField = SmbModalState::Field::None; + updateSmbModalMenu(); + } else if (settings_.isOpen()) { + settings_.onKeyboardSubmit(text); + } + }, + [this]() { + if (smbModal_.active) { + smbModal_.editingField = SmbModalState::Field::None; + updateSmbModalMenu(); + } else if (settings_.isOpen()) { + settings_.onKeyboardCancel(); + } + }); + + const bool kbOpen = VrKeyboard::instance().isOpen(); + std::string kbDisplayText = VrKeyboard::instance().currentText(); + if (smbModal_.active && smbModal_.editingField == SmbModalState::Field::Host) { + kbDisplayText = sanitizeIpv4(kbDisplayText, false); + } + renderer_.setKeyboardModal(kbOpen, + VrKeyboard::instance().description(), + kbDisplayText, + VrKeyboard::instance().isPassword()); + if (kbOpen) { + in.select = false; + in.selectHeld = false; + in.togglePlay = false; + in.browserToggle = false; + } + // Custom combo recording listener (active while recording new 6-button combo in Vault & Privacy) if (VaultManager::instance().isRecordingCombo()) { for (int b : {XrInputState::BtnA, XrInputState::BtnB, XrInputState::BtnX, XrInputState::BtnY}) { @@ -659,6 +878,20 @@ int App::run() { in.gripValue[0], in.gripValue[1]); } + // Whirligig-style Quick Path controller button shortcut + const int qpBtn = settings_.bindQuickPath(); + const bool quickPathPressed = + !settings_.isListening() && !gripFullHeld && + !VaultManager::instance().isRecordingCombo() && !kbOpen && + qpBtn >= 0 && qpBtn < XrInputState::BtnCount && in.buttonDown[qpBtn]; + if (quickPathPressed) { + browser_.openBookmarks(); + downloadsWindow_ = false; + settings_.close(); + browser_.setOpen(true); + xr_.triggerHaptic(1, 0.040f, 0.0f, 0.6f); + } + if (gripFullHeld && !settings_.isListening() && !VaultManager::instance().isRecordingCombo()) { const int h = in.gripFullPressHeld[1] ? 1 : 0; for (int b : {XrInputState::BtnA, XrInputState::BtnB, XrInputState::BtnX, XrInputState::BtnY}) { @@ -773,6 +1006,9 @@ int App::run() { settings_.uiTextColorIdx(), settings_.uiAccentColorIdx(), settings_.uiDistance()); + renderer_.setUiFollowMode(settings_.uiFollowMode()); + renderer_.setBrowserViewMode(static_cast(settings_.browserViewMode())); + renderer_.setBrowserQuickPath(browser_.isCurrentBookmarked()); if (!didInitialRecenter_ && in.headValid) { renderer_.recenterScreen(in.headPos, in.headForward); renderer_.setScreenCurvature(settings_.screenCurvature()); @@ -802,7 +1038,19 @@ int App::run() { } float od = 0.0f; for (int k = 0; k < 4; ++k) od += c.orientation[k] * activityAnchorOrient_[h][k]; - if (std::sqrt(dp) > 0.02f || std::fabs(od) < 0.995f) { + const float moveDist = std::sqrt(dp); + const float rotDiff = std::fabs(od); + + if (hudDismissed_) { + // Requires intentional hand movement to re-engage HUD after manual dismissal + if (moveDist > 0.10f || rotDiff < 0.970f) { + hudDismissed_ = false; + activity = true; + for (int k = 0; k < 3; ++k) activityAnchorPos_[h][k] = c.position[k]; + for (int k = 0; k < 4; ++k) activityAnchorOrient_[h][k] = c.orientation[k]; + } + } else if (moveDist > 0.06f || rotDiff < 0.985f) { + // Normal threshold: filters micro-tremors from resting hands activity = true; for (int k = 0; k < 3; ++k) activityAnchorPos_[h][k] = c.position[k]; for (int k = 0; k < 4; ++k) activityAnchorOrient_[h][k] = c.orientation[k]; @@ -813,6 +1061,7 @@ int App::run() { std::fabs(in.thumbstickY) > 0.15f || std::fabs(in.thumbstickRX) > 0.15f) { activity = true; + hudDismissed_ = false; } if (activity) { lastControllerActivity_ = nowT; @@ -834,6 +1083,11 @@ int App::run() { settings_.close(); } else if (browser_.isOpen()) { browser_.setOpen(false); + } else if (mediaOpen_ && renderer_.controlBarVisible()) { + // HUD is visible during playback: B/Y dismisses the HUD! + hudDismissed_ = true; + lastControllerActivity_ = nowT - std::chrono::seconds(10); + renderer_.setControlBar(false); } else { browser_.open(); } @@ -1108,6 +1362,27 @@ int App::run() { item.tag = "FILE"; } + // Format file size + if (e.size > 0) { + char sbuf[32]; + constexpr long long kGB = 1024LL * 1024LL * 1024LL; + constexpr long long kMB = 1024LL * 1024LL; + if (e.size >= kGB) { + std::snprintf(sbuf, sizeof(sbuf), "%.2f GB", static_cast(e.size) / static_cast(kGB)); + } else if (e.size >= kMB) { + std::snprintf(sbuf, sizeof(sbuf), "%.1f MB", static_cast(e.size) / static_cast(kMB)); + } else { + std::snprintf(sbuf, sizeof(sbuf), "%.0f KB", static_cast(e.size) / 1024.0); + } + item.sizeTag = sbuf; + } else if (e.isDir) { + item.sizeTag = "Folder"; + } else if (e.isBack) { + item.sizeTag = ""; + } else { + item.sizeTag = "--"; + } + if (hasMeta) { if (meta.durationSec > 0.5) { const int tot = static_cast(meta.durationSec + 0.5); @@ -1131,8 +1406,19 @@ int App::run() { } else { item.detail = specBuf; } + char rbuf[48]; + if (meta.fps > 1.0) { + std::snprintf(rbuf, sizeof(rbuf), "%dx%d %.0ffps", meta.width, meta.height, meta.fps); + } else { + std::snprintf(rbuf, sizeof(rbuf), "%dx%d", meta.width, meta.height); + } + item.resolutionTag = rbuf; } } + if (e.isVideo) { + if (item.durationTag.empty()) item.durationTag = "--"; + if (item.resolutionTag.empty()) item.resolutionTag = "--"; + } items.push_back(std::move(item)); } @@ -1147,13 +1433,21 @@ int App::run() { status = "A/Trigger: Play \xB7 Y: Actions"; } } + renderer_.setListColumnVisibility( + settings_.listShowFormat(), + settings_.listShowRes(), + settings_.listShowSize(), + settings_.listShowDuration() + ); renderer_.setBrowserItems(true, browser_.title(), items, browser_.selected(), status); - // Feed ready thumbnails to the visible slots (6 cards) + // Feed ready thumbnails to the visible slots (6 for BigCards, 12 for MiniCards, 8 for List) const int curFirst = renderer_.browserFirst(); const int totalItems = static_cast(items.size()); - for (int slot = 0; slot < 6; ++slot) { + const int numSlots = (renderer_.browserViewMode() == VulkanRenderer::BrowserViewMode::BigCards) ? 6 : + (renderer_.browserViewMode() == VulkanRenderer::BrowserViewMode::MiniCards ? 12 : 8); + for (int slot = 0; slot < numSlots; ++slot) { const int idx = curFirst + slot; if (idx >= 0 && idx < totalItems) { const std::string thumbTarget = !items[idx].previewPath.empty() @@ -1221,12 +1515,15 @@ int App::run() { !pendingDl_.empty() || actionMenu_.visible; // Controls (buttons + timeline) show only while a controller is // actively moving; they fade after a few seconds of stillness. - renderer_.setControlBar(!barBlocked && controllersEngaged && + renderer_.setControlBar(!barBlocked && controllersEngaged && !hudDismissed_ && (in.controllers[0].active || in.controllers[1].active)); - // Laser + models stay up while a panel is open (to point at it), - // otherwise they follow the same activity timeout. - const bool showLaser = uiPanelActive || controllersEngaged; + // Keep laser active when UI panels, activity, or virtual keyboard are active! + const bool kbActive = VrKeyboard::instance().isOpen(); + if (kbActive && !renderer_.laserOn(0) && !renderer_.laserOn(1)) { + renderer_.setLaserOn(1, true); + } + const bool showLaser = (uiPanelActive || controllersEngaged || kbActive); // Build each controller's render state: corrected model pose, // low-pass smoothed (the raw hand pose jitters), while the aim // pose stays raw so the laser remains responsive. @@ -1291,10 +1588,14 @@ int App::run() { // Main Tab: Settings downloadsWindow_ = false; settings_.open(); - } else if (sbHover >= 3 && sbHover <= 6) { + } else if (sbHover >= 3 && sbHover <= 8) { const int sub = sbHover - 3; if (settings_.isOpen()) { - settings_.setSection(sub); + if (sub <= 4) { + settings_.setSection(sub); + } else if (sub == 5 && VaultManager::instance().isUnlocked()) { + settings_.setSection(5); + } } else if (downloadsWindow_) { if (sub <= 2) renderer_.setDownloadsFilter(sub); } else if (browser_.isOpen()) { @@ -1302,17 +1603,10 @@ int App::run() { else if (sub == 1) browser_.openVideos(); else if (sub == 2) browser_.openNetwork(); else if (sub == 3) browser_.openDownloads(); + else if (sub == 4) browser_.openBookmarks(); + else if (sub == 5 && VaultManager::instance().isUnlocked()) browser_.openVault(); } - } else if (sbHover == 7) { - // Subtab 5: Vault (Private) in Files or Vault & Privacy in Settings - if (VaultManager::instance().isUnlocked()) { - if (settings_.isOpen()) { - settings_.setSection(4); - } else if (browser_.isOpen()) { - browser_.openVault(); - } - } - } else if (sbHover == 8) { + } else if (sbHover == 9 || sbHover == 8) { // Lock Vault button if (VaultManager::instance().isUnlocked()) { xr_.triggerHaptic(0, 0.050f, 0.0f, 0.7f); @@ -1388,7 +1682,48 @@ int App::run() { if (chosen >= 0 && chosen < static_cast(actionMenu_.options.size())) { const std::string opt = actionMenu_.options[chosen]; if (actionMenu_.page == 0) { - if (opt == "Move to Vault") { + if (opt == "Open Share" || opt == "Open Bookmark") { + std::string playPath; + if (browser_.activate(playPath) == Browser::Result::Play && !playPath.empty()) { +#ifdef PIXELVR_HAVE_MEDIA + loadMedia(playPath); +#endif + browser_.setOpen(false); + } + actionMenu_.visible = false; + } else if (opt == "Edit SMB Share") { + if (fe) { + openSmbModal(false, fe->path); + } + } else if (opt == "Delete SMB Share") { + if (fe) { + std::string rest = fe->path; + if (rest.rfind("smb://", 0) == 0) rest = rest.substr(6); + while (!rest.empty() && rest.back() == '/') rest.pop_back(); + auto slash = rest.find('/'); + std::string host = (slash == std::string::npos) ? rest : rest.substr(0, slash); + std::string share = (slash == std::string::npos) ? "" : rest.substr(slash + 1); + SmbCredentialsManager::instance().deleteShare(host, share); + browser_.openNetwork(); + } + actionMenu_.visible = false; + } else if (opt == "Go to Bookmarks" || opt == "Go to Quick Path") { + browser_.openBookmarks(); + actionMenu_.visible = false; + } else if (opt == "Add to Bookmarks" || opt == "Add Folder to Bookmarks" || + opt == "Set as Quick Path" || opt == "Set Folder as Quick Path") { + const std::string targetPath = (fe && fe->isDir) ? fe->path : browser_.currentPath(); + browser_.addBookmark(targetPath, fe ? fe->label : ""); + xr_.triggerHaptic(0, 0.060f, 0.0f, 0.8f); + xr_.triggerHaptic(1, 0.060f, 0.0f, 0.8f); + actionMenu_.visible = false; + } else if (opt == "Remove Bookmark" || opt == "Remove from Bookmarks") { + const std::string targetPath = (fe && !fe->isBack) ? fe->path : browser_.currentPath(); + browser_.removeBookmark(targetPath); + xr_.triggerHaptic(0, 0.050f, 0.0f, 0.7f); + xr_.triggerHaptic(1, 0.050f, 0.0f, 0.7f); + actionMenu_.visible = false; + } else if (opt == "Move to Vault") { std::string newPath; if (browser_.moveFocusedToVault(newPath)) { xr_.triggerHaptic(0, 0.050f, 0.0f, 0.7f); @@ -1507,28 +1842,119 @@ int App::run() { } interacted = true; } + } else if (actionMenu_.page == 4) { + // SMB Share Editor Modal + const int dy = navStep(in.thumbstickY, nowT); + const int maxOpt = static_cast(actionMenu_.options.size()) - 1; + if (dy != 0) { + actionMenu_.selectedOption += dy; + if (actionMenu_.selectedOption < 0) actionMenu_.selectedOption = 0; + if (actionMenu_.selectedOption > maxOpt) actionMenu_.selectedOption = maxOpt; + } + const int hov = renderer_.actionMenuBtnHovered(); + if (hov >= 0) actionMenu_.selectedOption = hov; + + if (in.select || in.togglePlay) { + int chosen = (hov >= 0) ? hov : actionMenu_.selectedOption; + if (chosen >= 0) { + xr_.triggerHaptic(0, 0.025f, 0.0f, 0.5f); + xr_.triggerHaptic(1, 0.025f, 0.0f, 0.5f); + + if (chosen == 0) { + smbModal_.editingField = SmbModalState::Field::Host; + VrKeyboard::instance().show("SMB Server IP / Hostname", smbModal_.host, false); + } else if (chosen == 1) { + smbModal_.editingField = SmbModalState::Field::Share; + VrKeyboard::instance().show("SMB Share Name (empty for all)", smbModal_.share, false); + } else if (chosen == 2) { + smbModal_.anon = !smbModal_.anon; + updateSmbModalMenu(); + } else if (chosen == 3) { + smbModal_.editingField = SmbModalState::Field::User; + VrKeyboard::instance().show("SMB Username", smbModal_.user, false); + } else if (chosen == 4) { + smbModal_.editingField = SmbModalState::Field::Pass; + VrKeyboard::instance().show("SMB Password", smbModal_.pass, true); + } else if (chosen == 5) { + smbModal_.editingField = SmbModalState::Field::Workgroup; + VrKeyboard::instance().show("SMB Workgroup / Domain", smbModal_.workgroup, false); + } else if (chosen == 6) { + smbModal_.editingField = SmbModalState::Field::Label; + VrKeyboard::instance().show("SMB Nickname", smbModal_.label, false); + } else if (chosen == 7) { + // Save SMB Share + saveSmbModal(); + } else if (chosen == 8) { + if (smbModal_.isNew) { + // Cancel + actionMenu_.visible = false; + smbModal_.active = false; + } else { + // Delete Share + deleteSmbModal(); + } + } else if (chosen == 9) { + // Cancel + actionMenu_.visible = false; + smbModal_.active = false; + } + } + interacted = true; + } } } } else if (actionBtnPressed && browser_.isOpen() && !downloadsWindow_ && - !settings_.isOpen() && pendingDl_.empty() && !browser_.onNetwork()) { + !settings_.isOpen() && pendingDl_.empty()) { openActionMenu(); interacted = true; } else if (browser_.isOpen() && !browser_.isScanning() && !downloadsWindow_ && !settings_.isOpen() && pendingDl_.empty()) { - // 2D grid thumbstick navigation: Y steps rows (3 cards), X steps columns (1 card) + // 2D grid thumbstick navigation: row steps depend on columns per row + const int cols = (renderer_.browserViewMode() == VulkanRenderer::BrowserViewMode::MiniCards) ? 4 : + (renderer_.browserViewMode() == VulkanRenderer::BrowserViewMode::CompactList) ? 1 : 3; const int dy = navStep(in.thumbstickY, nowT); const int dx = navStepX(in.thumbstickX, nowT); if (dy != 0 || dx != 0) { - const int delta = dy * 3 + dx; + const int delta = dy * cols + dx; browser_.move(delta); renderer_.scrollBrowser(0); } - // Check header pagination buttons [<] and [>] + // Check header pagination & action buttons const int pbHover = renderer_.browserPageBtnHovered(); if ((in.togglePlay || in.select) && pbHover >= 0 && sbHover < 0) { - renderer_.scrollBrowser(pbHover == 0 ? -2 : 2); - browser_.setSelected(renderer_.browserFirst()); + const int pageStep = (renderer_.browserViewMode() == VulkanRenderer::BrowserViewMode::BigCards) ? 2 : + (renderer_.browserViewMode() == VulkanRenderer::BrowserViewMode::MiniCards ? 3 : 8); + if (pbHover == 0) { + renderer_.scrollBrowser(-pageStep); + browser_.setSelected(renderer_.browserFirst()); + } else if (pbHover == 1) { + renderer_.scrollBrowser(pageStep); + browser_.setSelected(renderer_.browserFirst()); + } else if (pbHover == 2) { + // Cycle View Mode: BigCards (0) -> MiniCards (1) -> CompactList (2) + int curMode = settings_.browserViewMode(); + curMode = (curMode + 1) % 3; + settings_.setBrowserViewMode(curMode); + settings_.saveConfig(); + renderer_.setBrowserViewMode(static_cast(curMode)); + renderer_.scrollBrowser(0); + xr_.triggerHaptic(1, 0.025f, 0.0f, 0.5f); + } else if (pbHover == 3) { + const std::string cur = browser_.currentPath(); + if (cur != "bookmarks://") { + if (browser_.isBookmarked(cur)) { + browser_.removeBookmark(cur); + renderer_.setBrowserQuickPath(false); + xr_.triggerHaptic(1, 0.040f, 0.0f, 0.5f); + } else { + browser_.addBookmark(cur); + renderer_.setBrowserQuickPath(true); + xr_.triggerHaptic(1, 0.040f, 0.0f, 0.7f); + } + } + } + interacted = true; } else if (sbHover < 0) { const bool stickActive = (std::fabs(in.thumbstickY) > 0.25f || std::fabs(in.thumbstickX) > 0.25f); const int hovered = renderer_.browserHovered(); @@ -1540,8 +1966,10 @@ int App::run() { if ((in.togglePlay || in.select) && renderer_.pointerButton() < 0 && hovered >= 0) { std::string playPath; - if (browser_.activate(playPath) == Browser::Result::Play && - !playPath.empty()) { + Browser::Result res = browser_.activate(playPath); + if (res == Browser::Result::AddSmbShare) { + openSmbModal(true); + } else if (res == Browser::Result::Play && !playPath.empty()) { #ifdef PIXELVR_HAVE_MEDIA loadMedia(playPath); #endif @@ -1550,8 +1978,10 @@ int App::run() { } else if ((in.togglePlay || in.select) && renderer_.pointerButton() < 0 && stickActive) { std::string playPath; - if (browser_.activate(playPath) == Browser::Result::Play && - !playPath.empty()) { + Browser::Result res = browser_.activate(playPath); + if (res == Browser::Result::AddSmbShare) { + openSmbModal(true); + } else if (res == Browser::Result::Play && !playPath.empty()) { #ifdef PIXELVR_HAVE_MEDIA loadMedia(playPath); #endif @@ -1729,10 +2159,21 @@ int App::run() { renderer_.setSpherePitch(0.0f); renderer_.setSphereZoom(1.0f); } + } else if (cb == VulkanRenderer::CtrlButton::HideHud) { + hudDismissed_ = true; + lastControllerActivity_ = nowT - std::chrono::seconds(10); + renderer_.setControlBar(false); } #endif interacted = true; } + // Click outside the control dock in empty space immediately hides the HUD + if (in.select && btn < 0 && !renderer_.pointerOnTimeline() && !renderer_.pointerOnTimeToggle()) { + hudDismissed_ = true; + lastControllerActivity_ = nowT - std::chrono::seconds(10); + renderer_.setControlBar(false); + interacted = true; + } if (in.select && renderer_.pointerOnTimeToggle()) { renderer_.toggleTimeDisplay(); // total <-> time remaining interacted = true; diff --git a/src/app/app.hpp b/src/app/app.hpp index a468850..30e198d 100644 --- a/src/app/app.hpp +++ b/src/app/app.hpp @@ -77,6 +77,7 @@ private: bool pendingDlFresh_ = false; // suppress the same-frame A press bool downloadsWindow_ = false; // downloads list window toggled from the bar bool dlWasActive_ = false; // edge detect: auto-open the window on start + bool hudDismissed_ = false; // manually dismissed player controls / HUD // Low-pass smoothed model pose per hand (the raw hand pose jitters; the // system's own controller model is visibly smoothed). bool modelSmoothInit_[2] = {false, false}; @@ -100,6 +101,25 @@ private: VulkanRenderer::ActionMenuData actionMenu_{}; void openActionMenu(); + struct SmbModalState { + bool active = false; + bool isNew = true; + std::string origHost; + std::string origShare; + std::string host; + std::string share; + bool anon = false; + std::string user; + std::string pass; + std::string workgroup = "WORKGROUP"; + std::string label; + enum class Field { None, Host, Share, User, Pass, Workgroup, Label } editingField = Field::None; + } smbModal_{}; + void openSmbModal(bool isNew, const std::string& smbPath = ""); + void updateSmbModalMenu(); + void saveSmbModal(); + void deleteSmbModal(); + #ifdef PIXELVR_HAVE_FREETYPE Browser browser_; ThumbnailCache thumbnailCache_; diff --git a/src/gfx/vulkan_renderer.cpp b/src/gfx/vulkan_renderer.cpp index 7ca033f..73091ef 100644 --- a/src/gfx/vulkan_renderer.cpp +++ b/src/gfx/vulkan_renderer.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -73,16 +74,17 @@ struct CtrlButtonRect { constexpr float kBarY = -0.86f; constexpr float kDockHalfW = 0.92f; constexpr float kDockHalfH = 0.23f; -constexpr int kBtnCount = 12; +constexpr int kBtnCount = 13; inline CtrlButtonRect get_ctrl_button_rect(int b) { using Btn = VulkanRenderer::CtrlButton; switch (static_cast(b)) { - // Center playback cluster: [Stop] [Seek -10] (Play/Pause Hero) [Seek +10] + // Center playback cluster: [Stop] [Seek -10] (Play/Pause Hero) [Seek +10] [Hide] case Btn::Stop: return {-0.26f, kBarY - 0.045f, 0.046f, 0.046f}; case Btn::SeekBack: return {-0.130f, kBarY - 0.045f, 0.050f, 0.050f}; case Btn::PlayPause: return { 0.00f, kBarY - 0.045f, 0.076f, 0.076f}; // Hero button! case Btn::SeekFwd: return { 0.130f, kBarY - 0.045f, 0.050f, 0.050f}; + case Btn::HideHud: return { 0.26f, kBarY - 0.045f, 0.046f, 0.046f}; // Left flank pills: HUB (top), RECENTER (bottom) case Btn::Files: return {-0.62f, kBarY - 0.005f, 0.185f, 0.040f}; @@ -972,15 +974,18 @@ void VulkanRenderer::setBrowserItems(bool visible, const std::string& title, } const int total = static_cast(browserItems_.size()); - constexpr int kCardsPerPage = 6; - const int maxFirst = std::max(0, ((total + 2) / 3 * 3) - kCardsPerPage); + const int kCardsPerPage = (browserViewMode_ == BrowserViewMode::BigCards) ? 6 : + (browserViewMode_ == BrowserViewMode::MiniCards ? 12 : 8); + const int rowStep = (browserViewMode_ == BrowserViewMode::BigCards) ? 3 : + (browserViewMode_ == BrowserViewMode::MiniCards ? 4 : 1); + const int maxFirst = std::max(0, ((total + rowStep - 1) / rowStep * rowStep) - kCardsPerPage); if (browserFirst_ > maxFirst) { browserFirst_ = maxFirst; } if (browserSelected_ < browserFirst_) { - browserFirst_ = (browserSelected_ / 3) * 3; + browserFirst_ = (browserSelected_ / rowStep) * rowStep; } else if (browserSelected_ >= browserFirst_ + kCardsPerPage) { - browserFirst_ = ((browserSelected_ - kCardsPerPage + 3) / 3) * 3; + browserFirst_ = ((browserSelected_ - kCardsPerPage + rowStep) / rowStep) * rowStep; } } @@ -1012,27 +1017,33 @@ void VulkanRenderer::setBrowser(bool visible, const std::string& title, } const int total = static_cast(browserRows_.size()); - constexpr int kCardsPerPage = 6; - const int maxFirst = std::max(0, ((total + 2) / 3 * 3) - kCardsPerPage); + const int kCardsPerPage = (browserViewMode_ == BrowserViewMode::BigCards) ? 6 : + (browserViewMode_ == BrowserViewMode::MiniCards ? 12 : 8); + const int rowStep = (browserViewMode_ == BrowserViewMode::BigCards) ? 3 : + (browserViewMode_ == BrowserViewMode::MiniCards ? 4 : 1); + const int maxFirst = std::max(0, ((total + rowStep - 1) / rowStep * rowStep) - kCardsPerPage); if (browserFirst_ > maxFirst) { browserFirst_ = maxFirst; } if (browserSelected_ < browserFirst_) { - browserFirst_ = (browserSelected_ / 3) * 3; + browserFirst_ = (browserSelected_ / rowStep) * rowStep; } else if (browserSelected_ >= browserFirst_ + kCardsPerPage) { - browserFirst_ = ((browserSelected_ - kCardsPerPage + 3) / 3) * 3; + browserFirst_ = ((browserSelected_ - kCardsPerPage + rowStep) / rowStep) * rowStep; } } void VulkanRenderer::scrollBrowser(int deltaRows) { const int total = static_cast(browserItems_.empty() ? browserRows_.size() : browserItems_.size()); - constexpr int kCardsPerPage = 6; - const int maxFirst = std::max(0, ((total + 2) / 3 * 3) - kCardsPerPage); - browserFirst_ = std::clamp(browserFirst_ + deltaRows * 3, 0, maxFirst); + const int kCardsPerPage = (browserViewMode_ == BrowserViewMode::BigCards) ? 6 : + (browserViewMode_ == BrowserViewMode::MiniCards ? 12 : 8); + const int rowStep = (browserViewMode_ == BrowserViewMode::BigCards) ? 3 : + (browserViewMode_ == BrowserViewMode::MiniCards ? 4 : 1); + const int maxFirst = std::max(0, ((total + rowStep - 1) / rowStep * rowStep) - kCardsPerPage); + browserFirst_ = std::clamp(browserFirst_ + deltaRows * rowStep, 0, maxFirst); } void VulkanRenderer::clearCardThumbnails() { - for (int i = 0; i < 6; ++i) { + for (int i = 0; i < 12; ++i) { if (cardThumbs_[i].view != VK_NULL_HANDLE) { vkDestroyImageView(device_, cardThumbs_[i].view, nullptr); cardThumbs_[i].view = VK_NULL_HANDLE; @@ -1053,7 +1064,7 @@ void VulkanRenderer::clearCardThumbnails() { void VulkanRenderer::updateCardThumbnail(int slot, const std::string& path, const uint8_t* rgba, int width, int height) { - if (slot < 0 || slot >= 6 || !rgba || width <= 0 || height <= 0 || + if (slot < 0 || slot >= 12 || !rgba || width <= 0 || height <= 0 || textPool_ == VK_NULL_HANDLE || textSetLayout_ == VK_NULL_HANDLE) { return; } @@ -1242,26 +1253,33 @@ void VulkanRenderer::updatePointer() { (downloadsVisible_ && !downloadsModal_)) && !actionMenuOpen; const bool modalOpen = (downloadsVisible_ && downloadsModal_) && !actionMenuOpen; const bool controlBar = controlBarVisible_ && !hubOpen && !modalOpen && !actionMenuOpen; - if (!hubOpen && !modalOpen && !controlBar && !actionMenuOpen) { - return; // No UI surface to point at. + if (keyboardModal_.visible || (!hubOpen && !modalOpen && !controlBar && !actionMenuOpen)) { + return; // Virtual keyboard active or no UI surface to point at. } using namespace math; Mat4 panelBase; const float uiDist = std::clamp(uiDistance_, 1.2f, 3.5f); - if (projectionMode_ == ProjectionMode::Flat) { - const Vec3 center{screenPivot_[0] + screenForward_[0] * uiDist, - screenPivot_[1] + screenForward_[1] * uiDist, - screenPivot_[2] + screenForward_[2] * uiDist}; - panelBase = multiply(translation(center), - orientFromYawPitch(screenYaw_, recenterPitch_)); + if (uiFollowMode_ == 0 || projectionMode_ == ProjectionMode::Flat) { + // Mode 0: Rock-solid World Lock (Default, zero drift/tilt) + const float dist = (projectionMode_ == ProjectionMode::Flat) ? uiDist : std::min(uiDist, 2.0f); + const Vec3 center{screenPivot_[0] + screenForward_[0] * dist, + screenPivot_[1] + screenForward_[1] * dist, + screenPivot_[2] + screenForward_[2] * dist}; + const Mat4 orient = orientFromYawPitch(screenYaw_, recenterPitch_); + if (projectionMode_ == ProjectionMode::Flat) { + panelBase = multiply(translation(center), orient); + } else { + panelBase = multiply(translation(center), multiply(orient, rotationX(-0.22f))); + } } else { - // Spherical video mode (360/180): anchor controls floating comfortably in front + // Mode 1: Smooth Gaze Follow in spherical mode const float sphereDist = std::min(uiDist, 2.0f); - const Vec3 center{screenPivot_[0] + screenForward_[0] * sphereDist, - screenPivot_[1] + screenForward_[1] * sphereDist, - screenPivot_[2] + screenForward_[2] * sphereDist}; - const float followYaw = (projectionMode_ == ProjectionMode::Flat) ? screenYaw_ : (sphereFollowInit_ ? sphereFollowYaw_ : screenYaw_); + const float followYaw = sphereFollowInit_ ? sphereFollowYaw_ : screenYaw_; + const Vec3 forward{std::sin(followYaw), 0.0f, -std::cos(followYaw)}; + const Vec3 center{screenPivot_[0] + forward.x * sphereDist, + screenPivot_[1] + forward.y * sphereDist, + screenPivot_[2] + forward.z * sphereDist}; const Mat4 orient = orientFromYawPitch(followYaw, recenterPitch_); panelBase = multiply(translation(center), multiply(orient, rotationX(-0.22f))); } @@ -1352,6 +1370,27 @@ void VulkanRenderer::updatePointer() { checkRow(kRow1, -0.055f, 12, 0.065f, 0.012f); checkRow(kRow2, -0.115f, 22, 0.070f, 0.012f); checkRow(kRow3, -0.175f, 31, 0.070f, 0.012f); + } else if (actionMenu_.page == 4) { + // SMB Share Editor Modal: Top fields 0..6: cy = 0.19f - i * 0.054f + const int optCount = static_cast(actionMenu_.options.size()); + const int fieldCount = std::min(optCount, 7); + for (int i = 0; i < fieldCount; ++i) { + const float cy = 0.19f - static_cast(i) * 0.054f; + if (std::fabs(hx) <= 0.42f && std::fabs(hyy - cy) <= 0.024f) { + actionMenuBtnHovered_ = i; + break; + } + } + if (actionMenuBtnHovered_ < 0 && std::fabs(hyy - (-0.25f)) <= 0.028f) { + if (optCount == 8) { + if (std::fabs(hx - (-0.15f)) <= 0.13f) actionMenuBtnHovered_ = 7; // Save + else if (std::fabs(hx - 0.15f) <= 0.13f) actionMenuBtnHovered_ = 8; // Cancel + } else if (optCount >= 9) { + if (std::fabs(hx - (-0.24f)) <= 0.11f) actionMenuBtnHovered_ = 7; // Save + else if (std::fabs(hx) <= 0.10f) actionMenuBtnHovered_ = 8; // Delete + else if (std::fabs(hx - 0.24f) <= 0.10f) actionMenuBtnHovered_ = 9; // Cancel + } + } } break; } @@ -1393,20 +1432,44 @@ void VulkanRenderer::updatePointer() { break; } } - // Sub-navigation items (indices 3..6, and 7/8 if vaultUnlocked_) + // Sub-navigation items (indices 3..8, and 9 if vaultUnlocked_) if (browserSidebarHovered_ < 0) { const int activeMainTab = settingsVisible_ ? 2 : (downloadsVisible_ ? 1 : 0); - const float subTabY[5] = {-0.05f, -0.14f, -0.23f, -0.32f, -0.41f}; - const int numSubTabs = (activeMainTab == 1) ? 3 : (vaultUnlocked_ ? 5 : 4); - for (int sub = 0; sub < numSubTabs; ++sub) { - if (std::fabs(hyy - subTabY[sub]) <= 0.038f) { - browserSidebarHovered_ = 3 + sub; - break; + if (activeMainTab == 2) { + const float setSubY[5] = {0.02f, -0.07f, -0.16f, -0.25f, -0.34f}; + const int numSub = vaultUnlocked_ ? 5 : 4; + for (int sub = 0; sub < numSub; ++sub) { + if (std::fabs(hyy - setSubY[sub]) <= 0.038f) { + browserSidebarHovered_ = 3 + sub; + break; + } } - } - if (browserSidebarHovered_ < 0 && vaultUnlocked_) { - if (std::fabs(hyy - (-0.485f)) <= 0.035f) { - browserSidebarHovered_ = 8; // Lock Vault button + if (browserSidebarHovered_ < 0 && vaultUnlocked_) { + if (std::fabs(hyy - (-0.46f)) <= 0.030f) { + browserSidebarHovered_ = 9; // Lock Vault button + } + } + } else if (activeMainTab == 1) { // Downloads + const float dlSubY[3] = {-0.05f, -0.14f, -0.23f}; + for (int sub = 0; sub < 3; ++sub) { + if (std::fabs(hyy - dlSubY[sub]) <= 0.038f) { + browserSidebarHovered_ = 3 + sub; + break; + } + } + } else { // Files + const float subTabY[6] = {-0.04f, -0.11f, -0.18f, -0.25f, -0.32f, -0.39f}; + const int numSubTabs = vaultUnlocked_ ? 6 : 5; + for (int sub = 0; sub < numSubTabs; ++sub) { + if (std::fabs(hyy - subTabY[sub]) <= 0.032f) { + browserSidebarHovered_ = 3 + sub; + break; + } + } + if (browserSidebarHovered_ < 0 && vaultUnlocked_) { + if (std::fabs(hyy - (-0.47f)) <= 0.030f) { + browserSidebarHovered_ = 9; // Lock Vault button + } } } } @@ -1415,36 +1478,78 @@ void VulkanRenderer::updatePointer() { // Top Content Area: hx in [-0.49, +0.90] if (browserVisible_) { - // Top header pagination buttons: [<] at cx=0.56, [>] at cx=0.83, cy=0.455 + // Top header buttons: [<] at cx=0.52, [>] at cx=0.74, [View] at cx=0.35, [QuickPath] at cx=0.14, cy=0.455 if (std::fabs(hyy - 0.455f) <= 0.036f) { - if (std::fabs(hx - 0.56f) <= 0.045f) { + if (std::fabs(hx - 0.52f) <= 0.040f) { browserPageBtnHovered_ = 0; break; - } else if (std::fabs(hx - 0.83f) <= 0.045f) { + } else if (std::fabs(hx - 0.74f) <= 0.040f) { browserPageBtnHovered_ = 1; break; + } else if (std::fabs(hx - 0.35f) <= 0.085f) { + browserPageBtnHovered_ = 2; // View Mode cycle + break; + } else if (std::fabs(hx - 0.14f) <= 0.090f) { + browserPageBtnHovered_ = 3; // Quick Path bookmark + break; } } - // 3x2 Media Card Grid + // Media Card Grid / List based on browserViewMode_ const int total = static_cast(browserItems_.empty() ? browserRows_.size() : browserItems_.size()); if (total > 0) { - const float colX[3] = {-0.25f, 0.20f, 0.65f}; - const float rowY[2] = {0.16f, -0.24f}; - int col = -1; - for (int c = 0; c < 3; ++c) { - if (std::fabs(hx - colX[c]) <= 0.21f) { col = c; break; } - } - int row = -1; - for (int r = 0; r < 2; ++r) { - if (std::fabs(hyy - rowY[r]) <= 0.185f) { row = r; break; } - } - if (col >= 0 && row >= 0) { - const int idxInPage = row * 3 + col; - const int targetIdx = browserFirst_ + idxInPage; - if (targetIdx >= 0 && targetIdx < total) { - pointerRow_ = targetIdx; - browserHovered_ = targetIdx; + if (browserViewMode_ == BrowserViewMode::BigCards) { + const float colX[3] = {-0.25f, 0.20f, 0.65f}; + const float rowY[2] = {0.16f, -0.24f}; + int col = -1; + for (int c = 0; c < 3; ++c) { + if (std::fabs(hx - colX[c]) <= 0.21f) { col = c; break; } + } + int row = -1; + for (int r = 0; r < 2; ++r) { + if (std::fabs(hyy - rowY[r]) <= 0.185f) { row = r; break; } + } + if (col >= 0 && row >= 0) { + const int idxInPage = row * 3 + col; + const int targetIdx = browserFirst_ + idxInPage; + if (targetIdx >= 0 && targetIdx < total) { + pointerRow_ = targetIdx; + browserHovered_ = targetIdx; + } + } + } else if (browserViewMode_ == BrowserViewMode::MiniCards) { + const float colX[4] = {-0.285f, 0.045f, 0.375f, 0.705f}; + const float rowY[3] = {0.20f, -0.06f, -0.32f}; + int col = -1; + for (int c = 0; c < 4; ++c) { + if (std::fabs(hx - colX[c]) <= 0.155f) { col = c; break; } + } + int row = -1; + for (int r = 0; r < 3; ++r) { + if (std::fabs(hyy - rowY[r]) <= 0.120f) { row = r; break; } + } + if (col >= 0 && row >= 0) { + const int idxInPage = row * 4 + col; + const int targetIdx = browserFirst_ + idxInPage; + if (targetIdx >= 0 && targetIdx < total) { + pointerRow_ = targetIdx; + browserHovered_ = targetIdx; + } + } + } else { // CompactList (1 column x 8 rows) + if (std::fabs(hx - 0.20f) <= 0.65f) { + const float rowY[8] = {0.300f, 0.210f, 0.120f, 0.030f, -0.060f, -0.150f, -0.240f, -0.330f}; + int row = -1; + for (int r = 0; r < 8; ++r) { + if (std::fabs(hyy - rowY[r]) <= 0.042f) { row = r; break; } + } + if (row >= 0) { + const int targetIdx = browserFirst_ + row; + if (targetIdx >= 0 && targetIdx < total) { + pointerRow_ = targetIdx; + browserHovered_ = targetIdx; + } + } } } } @@ -1494,7 +1599,7 @@ void VulkanRenderer::updatePointer() { break; } } - } else if (total > 6) { + } else if (total > 6 && total <= 8) { for (int i = 0; i < total && i < 8; ++i) { const int c = i % 2; const int r = i / 2; @@ -1507,6 +1612,19 @@ void VulkanRenderer::updatePointer() { break; } } + } else if (total > 8) { + for (int i = 0; i < total && i < 10; ++i) { + const int c = i % 2; + const int r = i / 2; + const float cx = (c == 0) ? -0.135f : 0.535f; + const float ry = 0.27f - static_cast(r) * 0.142f; + if (std::fabs(hx - cx) <= 0.315f && + std::fabs(hyy - ry) <= 0.058f) { + settingsRow_ = i; + settingsHovered_ = i; + break; + } + } } } break; @@ -1753,8 +1871,8 @@ bool VulkanRenderer::initText() { w.pImageInfo = &dii; vkUpdateDescriptorSets(device_, 1, &w, 0, nullptr); - // Pre-allocate descriptor sets for the 6 card thumbnail slots - for (int i = 0; i < 6; ++i) { + // Pre-allocate descriptor sets for the 12 card thumbnail slots + for (int i = 0; i < 12; ++i) { da.descriptorSetCount = 1; da.pSetLayouts = &textSetLayout_; if (vkAllocateDescriptorSets(device_, &da, &cardThumbs_[i].set) == VK_SUCCESS) { @@ -1963,14 +2081,20 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, Mat4 panelBase; const float uiDist = std::clamp(uiDistance_, 1.2f, 3.5f); - if (projectionMode_ == ProjectionMode::Flat) { - const Vec3 center{screenPivot_[0] + screenForward_[0] * uiDist, - screenPivot_[1] + screenForward_[1] * uiDist, - screenPivot_[2] + screenForward_[2] * uiDist}; - panelBase = multiply(translation(center), - orientFromYawPitch(screenYaw_, recenterPitch_)); + if (uiFollowMode_ == 0 || projectionMode_ == ProjectionMode::Flat) { + // Mode 0: Rock-solid World Lock (Default, zero drift/tilt). + const float dist = (projectionMode_ == ProjectionMode::Flat) ? uiDist : std::min(uiDist, 2.0f); + const Vec3 center{screenPivot_[0] + screenForward_[0] * dist, + screenPivot_[1] + screenForward_[1] * dist, + screenPivot_[2] + screenForward_[2] * dist}; + const Mat4 orient = orientFromYawPitch(screenYaw_, recenterPitch_); + if (projectionMode_ == ProjectionMode::Flat) { + panelBase = multiply(translation(center), orient); + } else { + panelBase = multiply(translation(center), multiply(orient, rotationX(-0.22f))); + } } else { - // Spherical video mode (360/180): anchor controls with torso/yaw lazy-follow + // Mode 1: Smooth Gaze Follow in spherical video mode (no deadband, smooth spring) const Quat hq{view.pose.orientation.x, view.pose.orientation.y, view.pose.orientation.z, view.pose.orientation.w}; const float headYaw = std::atan2(2.0f * (hq.w * hq.y + hq.x * hq.z), @@ -1982,17 +2106,13 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, float dyaw = headYaw - sphereFollowYaw_; while (dyaw > 3.14159f) dyaw -= 6.28318f; while (dyaw < -3.14159f) dyaw += 6.28318f; - constexpr float kDeadband = 0.35f; // ~20 degrees - if (dyaw > kDeadband) { - sphereFollowYaw_ += (dyaw - kDeadband) * 0.12f; - } else if (dyaw < -kDeadband) { - sphereFollowYaw_ += (dyaw + kDeadband) * 0.12f; - } + sphereFollowYaw_ += dyaw * 0.08f; const float sphereDist = std::min(uiDist, 2.0f); - const Vec3 center{screenPivot_[0] + screenForward_[0] * sphereDist, - screenPivot_[1] + screenForward_[1] * sphereDist, - screenPivot_[2] + screenForward_[2] * sphereDist}; + const Vec3 forward{std::sin(sphereFollowYaw_), 0.0f, -std::cos(sphereFollowYaw_)}; + const Vec3 center{screenPivot_[0] + forward.x * sphereDist, + screenPivot_[1] + forward.y * sphereDist, + screenPivot_[2] + forward.z * sphereDist}; const Mat4 orient = orientFromYawPitch(sphereFollowYaw_, recenterPitch_); panelBase = multiply(translation(center), multiply(orient, rotationX(-0.22f))); } @@ -2200,6 +2320,7 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, if (cb == CtrlButton::SeekBack) iconShape = UiShape::SeekBack; else if (cb == CtrlButton::SeekFwd) iconShape = UiShape::SeekFwd; else if (cb == CtrlButton::Stop) iconShape = UiShape::Stop; + else if (cb == CtrlButton::HideHud) iconShape = UiShape::Close; drawUiElement(vpPanel, r.cx, r.cy, r.hw * 0.42f, r.hh * 0.42f, iconShape, themeTextCol); } @@ -2355,38 +2476,50 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, } // Sub-navigation items in rail (contextual to Files / Downloads / Settings) - const float subTabY[5] = {-0.05f, -0.14f, -0.23f, -0.32f, -0.41f}; - const int subCount = (activeMainTab == 1) ? 3 : (vaultUnlocked_ ? 5 : 4); + const float setSubY[5] = {0.02f, -0.07f, -0.16f, -0.25f, -0.34f}; + const float dlSubY[3] = {-0.05f, -0.14f, -0.23f}; + const float fileSubY[6] = {-0.04f, -0.11f, -0.18f, -0.25f, -0.32f, -0.39f}; + const bool isSet = (activeMainTab == 2); + const bool isDl = (activeMainTab == 1); + const int subCount = isDl ? 3 : (isSet ? (vaultUnlocked_ ? 5 : 4) : (vaultUnlocked_ ? 6 : 5)); for (int sub = 0; sub < subCount; ++sub) { + const float sy = isSet ? setSubY[sub] : (isDl ? dlSubY[sub] : fileSubY[sub]); + const float sH = isSet ? 0.030f : 0.032f; const bool hov = (browserSidebarHovered_ == (3 + sub)); bool subAct = false; if (activeMainTab == 1) { subAct = (downloadsFilter_ == sub); } else if (activeMainTab == 2) { - const int effSec = (settingsSection_ >= 10) ? 2 : settingsSection_; + const int effSec = (settingsSection_ >= 10 && settingsSection_ <= 12) ? 2 : (settingsSection_ == 21 ? 1 : settingsSection_); subAct = (effSec == sub); - } else if (activeMainTab == 0 && sub == 4) { - subAct = (browserTitle_.find("Vault") != std::string::npos); + } else if (activeMainTab == 0) { + if (sub == 0) subAct = (browserTitle_ != "Bookmarks" && browserTitle_ != "bookmarks://" && browserTitle_.find("Videos") == std::string::npos && browserTitle_.rfind("smb://", 0) != 0 && browserTitle_.find("Downloads") == std::string::npos && browserTitle_.find("Vault") == std::string::npos); + else if (sub == 1) subAct = (browserTitle_.find("Videos") != std::string::npos); + else if (sub == 2) subAct = (browserTitle_.rfind("smb://", 0) == 0 || browserTitle_ == "smb://"); + else if (sub == 3) subAct = (browserTitle_.find("Downloads") != std::string::npos); + else if (sub == 4) subAct = (browserTitle_ == "Bookmarks" || browserTitle_ == "bookmarks://"); + else if (sub == 5) subAct = (browserTitle_.find("Vault") != std::string::npos); } const float subActBg[4] = { themeAccentCol[0] * 0.25f, themeAccentCol[1] * 0.25f, themeAccentCol[2] * 0.35f, 0.90f}; if (subAct || hov) { - drawUiElement(vpPanel, -0.695f, subTabY[sub], 0.172f, 0.034f, + drawUiElement(vpPanel, -0.695f, sy, 0.172f, sH, UiShape::RoundedBox, hov ? tabHovBg : subActBg, 0.40f, 0.025f, hov ? tabHovBord : tabActiveBord); } if (activeMainTab == 0) { - const UiShape qIcons[5] = {UiShape::Home, UiShape::CurvedDisplay, UiShape::List, UiShape::Download, UiShape::RoundedBox}; - drawUiElement(vpPanel, -0.825f, subTabY[sub], 0.015f, 0.015f, qIcons[sub], themeAccentCol); + const UiShape qIcons[6] = {UiShape::Home, UiShape::CurvedDisplay, UiShape::List, UiShape::Download, UiShape::RoundedBox, UiShape::RoundedBox}; + drawUiElement(vpPanel, -0.825f, sy, 0.015f, 0.015f, qIcons[sub], themeAccentCol); } } if (vaultUnlocked_) { - const bool lockHov = (browserSidebarHovered_ == 8); + const bool lockHov = (browserSidebarHovered_ == 9); + const float ly = isSet ? -0.46f : -0.47f; const float lockBg[4] = {0.45f, 0.08f, 0.12f, lockHov ? 0.95f : 0.70f}; const float lockBord[4] = {0.85f, 0.22f, 0.28f, lockHov ? 1.0f : 0.75f}; - drawUiElement(vpPanel, -0.695f, -0.485f, 0.172f, 0.030f, + drawUiElement(vpPanel, -0.695f, ly, 0.172f, 0.030f, UiShape::RoundedBox, lockBg, 0.35f, 0.02f, lockBord); } @@ -2407,24 +2540,117 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, const float emeraldCol[4] = {0.22f, 0.88f, 0.54f, 1.0f}; // --------------------------------------------------------------------- - // Page A: FILES (Spatial Media Browser - Mockup #1) + // --------------------------------------------------------------------- + // Page A: FILES (Spatial Media Browser - Multi-Mode) // --------------------------------------------------------------------- if (browserVisible_) { const int total = static_cast(browserItems_.size()); const int first = browserFirst_; - const float colX[3] = {-0.25f, 0.20f, 0.65f}; - const float rowY[2] = {0.16f, -0.24f}; - const float cardHalfW = 0.205f; - const float cardHalfH = 0.180f; + const int perPage = (browserViewMode_ == BrowserViewMode::BigCards) ? 6 : + (browserViewMode_ == BrowserViewMode::MiniCards ? 12 : 8); - // Top-right pagination buttons: [<] at 0.56, [>] at 0.83, cy=0.455 + struct ListColLayout { + float durCx = 0.765f; + float sizeCx = 0.635f; + float resCx = 0.485f; + float fmtCx = 0.330f; + float nameMaxW = 0.555f; + } listCols; + + if (browserViewMode_ == BrowserViewMode::CompactList) { + float curRight = 0.83f; + if (listShowDuration_) { + listCols.durCx = curRight - 0.065f; + curRight -= 0.13f; + } + if (listShowSize_) { + listCols.sizeCx = curRight - 0.065f; + curRight -= 0.13f; + } + if (listShowRes_) { + listCols.resCx = curRight - 0.085f; + curRight -= 0.17f; + } + if (listShowFormat_) { + listCols.fmtCx = curRight - 0.070f; + curRight -= 0.14f; + } + listCols.nameMaxW = std::max(0.30f, (curRight - 0.02f) - (-0.315f)); + } + + struct CardLayout { + float cx = 0.0f; + float cy = 0.0f; + float cardHalfW = 0.0f; + float cardHalfH = 0.0f; + float thumbCx = 0.0f; + float thumbCy = 0.0f; + float thumbHalfW = 0.0f; + float thumbHalfH = 0.0f; + }; + + auto getCardLayout = [&](int slot) -> CardLayout { + CardLayout lay; + if (browserViewMode_ == BrowserViewMode::BigCards) { + const float colX[3] = {-0.25f, 0.20f, 0.65f}; + const float rowY[2] = {0.16f, -0.24f}; + lay.cx = colX[slot % 3]; + lay.cy = rowY[slot / 3]; + lay.cardHalfW = 0.205f; + lay.cardHalfH = 0.180f; + lay.thumbCx = lay.cx; + lay.thumbCy = lay.cy + 0.056f; + lay.thumbHalfW = lay.cardHalfW - 0.015f; // 0.190m + lay.thumbHalfH = 0.104f; + } else if (browserViewMode_ == BrowserViewMode::MiniCards) { + const float colX[4] = {-0.285f, 0.045f, 0.375f, 0.705f}; + const float rowY[3] = {0.20f, -0.06f, -0.32f}; + lay.cx = colX[slot % 4]; + lay.cy = rowY[slot / 4]; + lay.cardHalfW = 0.150f; + lay.cardHalfH = 0.115f; + lay.thumbCx = lay.cx; + lay.thumbCy = lay.cy + 0.030f; + lay.thumbHalfW = lay.cardHalfW - 0.010f; // 0.140m + lay.thumbHalfH = 0.075f; + } else { // CompactList (1 col x 8 rows) + const float rowY[8] = {0.300f, 0.210f, 0.120f, 0.030f, -0.060f, -0.150f, -0.240f, -0.330f}; + lay.cx = 0.20f; + lay.cy = (slot >= 0 && slot < 8) ? rowY[slot] : 0.0f; + lay.cardHalfW = 0.65f; + lay.cardHalfH = 0.038f; + lay.thumbCx = -0.385f; + lay.thumbCy = lay.cy; + lay.thumbHalfW = 0.050f; + lay.thumbHalfH = 0.028f; + } + return lay; + }; + + // Top-right pagination buttons: [<] at 0.52, [>] at 0.74, cy=0.455 for (int pb = 0; pb < 2; ++pb) { - const float pbx = (pb == 0) ? 0.56f : 0.83f; + const float pbx = (pb == 0) ? 0.52f : 0.74f; const bool phov = (browserPageBtnHovered_ == pb); drawUiElement(vpPanel, pbx, 0.455f, 0.035f, 0.028f, UiShape::RoundedBox, phov ? tabHovBg : tabNormBg, 0.40f, 0.03f, phov ? tabHovBord : tabNormBord); } + // Header button 2: View Mode toggle [ VIEW: BIG / GRID / LIST ] + { + const bool phov = (browserPageBtnHovered_ == 2); + drawUiElement(vpPanel, 0.35f, 0.455f, 0.085f, 0.028f, + UiShape::RoundedBox, phov ? tabHovBg : tabNormBg, + 0.40f, 0.025f, phov ? tabHovBord : tabNormBord); + } + // Header button 3: Quick Path Bookmark [ ★ Quick Path ] / [ ★ Bookmark Path ] + { + const bool phov = (browserPageBtnHovered_ == 3); + const float qpActiveBg[4] = {0.05f, 0.12f, 0.22f, 0.95f}; + const float* bg = browserIsQuickPath_ ? qpActiveBg : (phov ? tabHovBg : tabNormBg); + const float* bord = browserIsQuickPath_ ? tabActiveBord : (phov ? tabHovBord : tabNormBord); + drawUiElement(vpPanel, 0.14f, 0.455f, 0.090f, 0.028f, + UiShape::RoundedBox, bg, 0.40f, 0.025f, bord); + } const float normCardBg[4] = {0.035f, 0.048f, 0.078f, 0.90f}; const float normCardBorder[4] = {0.18f, 0.26f, 0.40f, 0.70f}; @@ -2435,33 +2661,29 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, const float thumbBg[4] = {0.018f, 0.026f, 0.044f, 0.95f}; const float thumbBorder[4] = {0.16f, 0.22f, 0.34f, 0.75f}; - for (int i = 0; i < 6; ++i) { + for (int i = 0; i < perPage; ++i) { const int entryIdx = first + i; if (entryIdx >= total) break; const auto& item = browserItems_[static_cast(entryIdx)]; - const float cx = colX[i % 3]; - const float cy = rowY[i / 3]; + const CardLayout lay = getCardLayout(i); const bool hovered = (entryIdx == browserHovered_); const bool selected = (entryIdx == browserSelected_); if (hovered) { - drawUiElement(vpPanel, cx, cy, cardHalfW * 1.035f, cardHalfH * 1.035f, + drawUiElement(vpPanel, lay.cx, lay.cy, lay.cardHalfW * 1.035f, lay.cardHalfH * 1.035f, UiShape::RoundedBox, glowCol, 0.08f); - drawUiElement(vpPanel, cx, cy, cardHalfW, cardHalfH, + drawUiElement(vpPanel, lay.cx, lay.cy, lay.cardHalfW, lay.cardHalfH, UiShape::RoundedBox, hovCardBg, 0.06f, 0.032f, tabActiveBord); } else if (selected) { - drawUiElement(vpPanel, cx, cy, cardHalfW, cardHalfH, + drawUiElement(vpPanel, lay.cx, lay.cy, lay.cardHalfW, lay.cardHalfH, UiShape::RoundedBox, selCardBg, 0.06f, 0.026f, tabActiveBord); } else { - drawUiElement(vpPanel, cx, cy, cardHalfW, cardHalfH, + drawUiElement(vpPanel, lay.cx, lay.cy, lay.cardHalfW, lay.cardHalfH, UiShape::RoundedBox, normCardBg, 0.06f, 0.018f, normCardBorder); } - // 16:9 Thumbnail preview box in upper 62% of card - const float thumbCy = cy + 0.056f; - const float thumbHalfW = cardHalfW - 0.015f; // 0.190m - const float thumbHalfH = 0.104f; - drawUiElement(vpPanel, cx, thumbCy, thumbHalfW, thumbHalfH, + // Thumbnail box + drawUiElement(vpPanel, lay.thumbCx, lay.thumbCy, lay.thumbHalfW, lay.thumbHalfH, UiShape::RoundedBox, thumbBg, 0.05f, 0.018f, thumbBorder); const std::string& thumbKey = !item.previewPath.empty() ? item.previewPath : item.path; @@ -2470,14 +2692,16 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, if (item.isBack) iconShape = UiShape::Chevron; else if (item.isDir) iconShape = UiShape::Files; else if (item.isVideo) iconShape = UiShape::Play; - drawUiElement(vpPanel, cx, thumbCy, 0.032f, 0.032f, iconShape, themeAccentCol); + const float iconSize = (browserViewMode_ == BrowserViewMode::CompactList) ? 0.020f : + (browserViewMode_ == BrowserViewMode::MiniCards) ? 0.026f : 0.032f; + drawUiElement(vpPanel, lay.thumbCx, lay.thumbCy, iconSize, iconSize, iconShape, themeAccentCol); } } // Render actual video thumbnail textures for ready cards if (thumbPipeline_ != VK_NULL_HANDLE) { vkCmdBindPipeline(commandBuffer_, VK_PIPELINE_BIND_POINT_GRAPHICS, thumbPipeline_); - for (int i = 0; i < 6; ++i) { + for (int i = 0; i < perPage; ++i) { const int entryIdx = first + i; if (entryIdx >= total) break; const auto& item = browserItems_[static_cast(entryIdx)]; @@ -2486,20 +2710,15 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, cardThumbs_[i].set != VK_NULL_HANDLE) { vkCmdBindDescriptorSets(commandBuffer_, VK_PIPELINE_BIND_POINT_GRAPHICS, textPipelineLayout_, 0, 1, &cardThumbs_[i].set, 0, nullptr); - const float cx = colX[i % 3]; - const float cy = rowY[i / 3]; - const float thumbCy = cy + 0.056f; - const float thumbHalfW = cardHalfW - 0.015f; - const float thumbHalfH = 0.104f; - + const CardLayout lay = getCardLayout(i); TextPush push{}; std::memcpy(push.mvp, vpPanel.m, sizeof(push.mvp)); const float white4[4] = {1.0f, 1.0f, 1.0f, 1.0f}; std::memcpy(push.color, white4, sizeof(push.color)); - push.rect[0] = cx - thumbHalfW; - push.rect[1] = thumbCy - thumbHalfH; - push.rect[2] = thumbHalfW * 2.0f; - push.rect[3] = thumbHalfH * 2.0f; + push.rect[0] = lay.thumbCx - lay.thumbHalfW; + push.rect[1] = lay.thumbCy - lay.thumbHalfH; + push.rect[2] = lay.thumbHalfW * 2.0f; + push.rect[3] = lay.thumbHalfH * 2.0f; push.uv[0] = 0.0f; push.uv[1] = 0.0f; push.uv[2] = 1.0f; @@ -2512,30 +2731,43 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, } } - // Draw overlaid format badge (top-left of thumb) and duration pill (bottom-right of thumb) + // Draw overlaid format badge and duration pill vkCmdBindPipeline(commandBuffer_, VK_PIPELINE_BIND_POINT_GRAPHICS, uiPipeline_); const float badgeBg[4] = {0.02f, 0.04f, 0.08f, 0.92f}; const float durBg[4] = {0.015f, 0.025f, 0.045f, 0.92f}; - for (int i = 0; i < 6; ++i) { + for (int i = 0; i < perPage; ++i) { const int entryIdx = first + i; if (entryIdx >= total) break; const auto& item = browserItems_[static_cast(entryIdx)]; - const float cx = colX[i % 3]; - const float cy = rowY[i / 3]; - const float thumbCy = cy + 0.056f; - const float thumbHalfW = cardHalfW - 0.015f; - const float thumbHalfH = 0.104f; + const CardLayout lay = getCardLayout(i); - // Top-left format badge (sized nicely for larger badge text) - drawUiElement(vpPanel, cx - thumbHalfW + 0.062f, thumbCy + thumbHalfH - 0.024f, - 0.056f, 0.018f, UiShape::RoundedBox, badgeBg, 0.45f, 0.03f, tabActiveBord); - // Bottom-right duration badge (if available) - if (!item.durationTag.empty()) { - drawUiElement(vpPanel, cx + thumbHalfW - 0.050f, thumbCy - thumbHalfH + 0.024f, - 0.044f, 0.017f, UiShape::RoundedBox, durBg, 0.40f, 0.02f, normCardBorder); + if (browserViewMode_ == BrowserViewMode::BigCards) { + drawUiElement(vpPanel, lay.cx - lay.thumbHalfW + 0.062f, lay.thumbCy + lay.thumbHalfH - 0.024f, + 0.056f, 0.018f, UiShape::RoundedBox, badgeBg, 0.45f, 0.03f, tabActiveBord); + if (!item.durationTag.empty()) { + drawUiElement(vpPanel, lay.cx + lay.thumbHalfW - 0.050f, lay.thumbCy - lay.thumbHalfH + 0.024f, + 0.044f, 0.017f, UiShape::RoundedBox, durBg, 0.40f, 0.02f, normCardBorder); + } + } else if (browserViewMode_ == BrowserViewMode::MiniCards) { + drawUiElement(vpPanel, lay.cx - lay.thumbHalfW + 0.046f, lay.thumbCy + lay.thumbHalfH - 0.018f, + 0.042f, 0.014f, UiShape::RoundedBox, badgeBg, 0.45f, 0.025f, tabActiveBord); + if (!item.durationTag.empty()) { + drawUiElement(vpPanel, lay.cx + lay.thumbHalfW - 0.038f, lay.thumbCy - lay.thumbHalfH + 0.018f, + 0.034f, 0.014f, UiShape::RoundedBox, durBg, 0.40f, 0.02f, normCardBorder); + } + } else { // CompactList + if (listShowFormat_) { + drawUiElement(vpPanel, listCols.fmtCx, lay.cy, + 0.055f, 0.016f, UiShape::RoundedBox, badgeBg, 0.45f, 0.025f, tabActiveBord); + } } } + if (browserViewMode_ == BrowserViewMode::CompactList) { + const float headerLineCol[4] = {0.14f, 0.20f, 0.30f, 0.50f}; + drawUiElement(vpPanel, 0.20f, 0.355f, 0.65f, 0.001f, UiShape::RoundedBox, headerLineCol, 0.0f); + } + // Text pass for Hub rail + Files content vkCmdBindPipeline(commandBuffer_, VK_PIPELINE_BIND_POINT_GRAPHICS, textPipeline_); vkCmdBindDescriptorSets(commandBuffer_, VK_PIPELINE_BIND_POINT_GRAPHICS, @@ -2552,52 +2784,102 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, } } drawFit(-0.855f, 0.02f, 0.34f, scBadge, dimCol, "QUICK FILTERS"); - const char* qLabels[5] = {"Local Storage", "Videos", "SMB Shares", "Downloads", "Vault (Private)"}; - const int qCount = vaultUnlocked_ ? 5 : 4; + const char* qLabels[6] = {"Local Storage", "Videos", "SMB Shares", "Downloads", "Bookmarks", "Vault (Private)"}; + const int qCount = vaultUnlocked_ ? 6 : 5; for (int sub = 0; sub < qCount; ++sub) { - const float* col = (sub == 4) ? themeAccentCol : slateCol; - drawFit(-0.790f, subTabY[sub], 0.28f, scSub, col, qLabels[sub]); + const float* col = (sub == 4) ? themeAccentCol : ((sub == 5) ? themeAccentCol : slateCol); + drawFit(-0.790f, fileSubY[sub], 0.28f, scSub, col, qLabels[sub]); } if (vaultUnlocked_) { const float lockTextCol[4] = {1.0f, 0.50f, 0.50f, 1.0f}; - drawFitCentered(-0.695f, -0.485f, 0.28f, scSub, lockTextCol, "Lock Vault"); + drawFitCentered(-0.695f, -0.47f, 0.28f, scSub, lockTextCol, "Lock Vault"); } // Content header: Breadcrumb + Page switcher std::string bread = browserTitle_.empty() ? "Local Storage" : browserTitle_; - drawFit(-0.45f, 0.455f, 0.94f, scHeader * 0.90f, themeTextCol, bread); + drawFit(-0.46f, 0.455f, 0.46f, scHeader * 0.90f, themeTextCol, bread); - const int totalPages = std::max(1, (total + 5) / 6); - const int curPage = (first / 6) + 1; + const int totalPages = std::max(1, (total + perPage - 1) / perPage); + const int curPage = (first / perPage) + 1; char pageBuf[32]; std::snprintf(pageBuf, sizeof(pageBuf), "%d / %d", curPage, totalPages); - drawFitCentered(0.695f, 0.455f, 0.17f, scSub, slateCol, pageBuf); - drawFitCentered(0.56f, 0.455f, 0.06f, scStd, themeTextCol, "<"); - drawFitCentered(0.83f, 0.455f, 0.06f, scStd, themeTextCol, ">"); + drawFitCentered(0.63f, 0.455f, 0.14f, scSub, slateCol, pageBuf); + drawFitCentered(0.52f, 0.455f, 0.06f, scStd, themeTextCol, "<"); + drawFitCentered(0.74f, 0.455f, 0.06f, scStd, themeTextCol, ">"); - // Card titles, details, and badges (all fixed standard font sizes!) - for (int i = 0; i < 6; ++i) { + // Header button labels + const char* vModeLabels[3] = {"VIEW: BIG", "VIEW: GRID", "VIEW: LIST"}; + drawFitCentered(0.35f, 0.455f, 0.16f, scSub * 0.90f, themeTextCol, + vModeLabels[static_cast(browserViewMode_) % 3]); + const char* qpLabel = browserIsQuickPath_ ? "[ Bookmarked ]" : "[ + Bookmark ]"; + drawFitCentered(0.14f, 0.455f, 0.17f, scSub * 0.90f, + browserIsQuickPath_ ? themeAccentCol : themeTextCol, qpLabel); + + if (browserViewMode_ == BrowserViewMode::CompactList) { + drawFit(-0.315f, 0.380f, listCols.nameMaxW, scBadge * 0.95f, dimCol, "NAME"); + if (listShowFormat_) { + drawFitCentered(listCols.fmtCx, 0.380f, 0.11f, scBadge * 0.95f, dimCol, "FORMAT"); + } + if (listShowRes_) { + drawFitCentered(listCols.resCx, 0.380f, 0.15f, scBadge * 0.95f, dimCol, "RESOLUTION"); + } + if (listShowSize_) { + drawFitCentered(listCols.sizeCx, 0.380f, 0.11f, scBadge * 0.95f, dimCol, "SIZE"); + } + if (listShowDuration_) { + drawFitCentered(listCols.durCx, 0.380f, 0.11f, scBadge * 0.95f, dimCol, "DURATION"); + } + } + + // Card titles, details, and badges + for (int i = 0; i < perPage; ++i) { const int entryIdx = first + i; if (entryIdx >= total) break; const auto& item = browserItems_[static_cast(entryIdx)]; - const float cx = colX[i % 3]; - const float cy = rowY[i / 3]; - const float thumbCy = cy + 0.056f; - const float thumbHalfW = cardHalfW - 0.015f; - const float thumbHalfH = 0.104f; - const float textLeft = cx - cardHalfW + 0.016f; - const float maxTextW = cardHalfW * 2.0f - 0.032f; - - drawFit(textLeft, cy - 0.084f, maxTextW, scSub, themeTextCol, item.name); + const CardLayout lay = getCardLayout(i); const std::string cardDet = item.detail.empty() ? (item.isDir ? "Folder" : "Media") : item.detail; - drawFit(textLeft, cy - 0.136f, maxTextW, scDetail, slateCol, cardDet); - const std::string& bTag = item.tag.empty() ? (item.isVideo ? "VIDEO" : "FILE") : item.tag; - drawFitCentered(cx - thumbHalfW + 0.062f, thumbCy + thumbHalfH - 0.024f, - 0.104f, scBadge, themeAccentCol, bTag); - if (!item.durationTag.empty()) { - drawFitCentered(cx + thumbHalfW - 0.050f, thumbCy - thumbHalfH + 0.024f, - 0.080f, scBadge, themeTextCol, item.durationTag); + + if (browserViewMode_ == BrowserViewMode::BigCards) { + const float textLeft = lay.cx - lay.cardHalfW + 0.016f; + const float maxTextW = lay.cardHalfW * 2.0f - 0.032f; + drawFit(textLeft, lay.cy - 0.084f, maxTextW, scSub, themeTextCol, item.name); + drawFit(textLeft, lay.cy - 0.136f, maxTextW, scDetail, slateCol, cardDet); + drawFitCentered(lay.cx - lay.thumbHalfW + 0.062f, lay.thumbCy + lay.thumbHalfH - 0.024f, + 0.104f, scBadge, themeAccentCol, bTag); + if (!item.durationTag.empty()) { + drawFitCentered(lay.cx + lay.thumbHalfW - 0.050f, lay.thumbCy - lay.thumbHalfH + 0.024f, + 0.080f, scBadge, themeTextCol, item.durationTag); + } + } else if (browserViewMode_ == BrowserViewMode::MiniCards) { + const float textLeft = lay.cx - lay.cardHalfW + 0.012f; + const float maxTextW = lay.cardHalfW * 2.0f - 0.024f; + drawFit(textLeft, lay.cy - 0.064f, maxTextW, scSub * 0.88f, themeTextCol, item.name); + drawFit(textLeft, lay.cy - 0.095f, maxTextW, scDetail * 0.88f, slateCol, cardDet); + drawFitCentered(lay.cx - lay.thumbHalfW + 0.046f, lay.thumbCy + lay.thumbHalfH - 0.018f, + 0.080f, scBadge * 0.88f, themeAccentCol, bTag); + if (!item.durationTag.empty()) { + drawFitCentered(lay.cx + lay.thumbHalfW - 0.038f, lay.thumbCy - lay.thumbHalfH + 0.018f, + 0.065f, scBadge * 0.88f, themeTextCol, item.durationTag); + } + } else { // CompactList + const float textLeft = -0.315f; + drawFit(textLeft, lay.cy - 0.005f, listCols.nameMaxW, scSub * 0.95f, themeTextCol, item.name); + if (listShowFormat_) { + drawFitCentered(listCols.fmtCx, lay.cy - 0.005f, 0.11f, scBadge * 0.90f, themeAccentCol, bTag); + } + if (listShowRes_) { + const std::string resStr = item.resolutionTag.empty() ? (item.isDir || item.isBack ? "" : "--") : item.resolutionTag; + drawFitCentered(listCols.resCx, lay.cy - 0.005f, 0.15f, scDetail * 0.95f, slateCol, resStr); + } + if (listShowSize_) { + const std::string sizeStr = item.sizeTag.empty() ? (item.isDir || item.isBack ? "" : "--") : item.sizeTag; + drawFitCentered(listCols.sizeCx, lay.cy - 0.005f, 0.11f, scDetail * 0.95f, slateCol, sizeStr); + } + if (listShowDuration_) { + const std::string durStr = item.durationTag.empty() ? (item.isDir || item.isBack ? "" : "--") : item.durationTag; + drawFitCentered(listCols.durCx, lay.cy - 0.005f, 0.11f, scDetail * 0.95f, slateCol, durStr); + } } } @@ -2702,8 +2984,9 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, } } const char* dlSubLabels[3] = {"All Tasks", "Active Transfers", "Completed"}; + const float dlSubY[3] = {-0.05f, -0.14f, -0.23f}; for (int sub = 0; sub < 3; ++sub) { - drawFit(-0.84f, subTabY[sub], 0.30f, scSub, + drawFit(-0.84f, dlSubY[sub], 0.30f, scSub, (downloadsFilter_ == sub) ? themeTextCol : slateCol, dlSubLabels[sub]); } if (vaultUnlocked_) { @@ -2770,14 +3053,23 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, drawUiElement(vpPanel, 0.64f, 0.455f, 0.22f, 0.028f, UiShape::RoundedBox, tabNormBg, 0.45f, 0.02f, tabNormBord); - for (int i = 0; i < total && i < 8; ++i) { + const int maxVis = (total > 8) ? 10 : 8; + for (int i = 0; i < total && i < maxVis; ++i) { const int c = i % 2; const int r = i / 2; const float cx = (c == 0) ? -0.135f : 0.535f; - const float ry = (total <= 6) - ? (0.22f - static_cast(r) * 0.24f) - : (0.25f - static_cast(r) * 0.17f); - const float cardHalfH = (total <= 6) ? 0.098f : 0.072f; + float ry = 0.0f; + float cardHalfH = 0.0f; + if (total <= 6) { + ry = 0.22f - static_cast(r) * 0.24f; + cardHalfH = 0.098f; + } else if (total <= 8) { + ry = 0.25f - static_cast(r) * 0.17f; + cardHalfH = 0.072f; + } else { + ry = 0.27f - static_cast(r) * 0.142f; + cardHalfH = 0.058f; + } const bool en = settingsEnabled_.empty() || (i < static_cast(settingsEnabled_.size()) && settingsEnabled_[i] != 0); @@ -2813,28 +3105,33 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, } const char* setSubLabels[5] = {"Display & Cinema", "UI & Appearance", "Audio & Tracks", "Controls & Input", "Vault & Privacy"}; - const int effSec = (settingsSection_ >= 10) ? 2 : settingsSection_; + const int effSec = (settingsSection_ >= 10 && settingsSection_ <= 12) ? 2 : (settingsSection_ == 21 ? 1 : settingsSection_); const int sCount = vaultUnlocked_ ? 5 : 4; for (int sub = 0; sub < sCount; ++sub) { - drawFit(-0.84f, subTabY[sub], 0.30f, scSub, + drawFit(-0.84f, setSubY[sub], 0.30f, scSub * 0.92f, (effSec == sub) ? themeTextCol : slateCol, setSubLabels[sub]); } if (vaultUnlocked_) { const float lockTextCol[4] = {1.0f, 0.50f, 0.50f, 1.0f}; - drawFitCentered(-0.695f, -0.485f, 0.28f, scSub, lockTextCol, "Lock Vault"); + drawFitCentered(-0.695f, -0.46f, 0.28f, scSub, lockTextCol, "Lock Vault"); } drawFit(-0.45f, 0.455f, 0.82f, scHeader * 0.90f, themeTextCol, settingsTitle_); drawFitCentered(0.64f, 0.455f, 0.41f, scDetail, slateCol, "PixelVR v1.2 \xB7 Steam Frame"); - for (int i = 0; i < total && i < 8; ++i) { + for (int i = 0; i < total && i < maxVis; ++i) { const int c = i % 2; const int r = i / 2; const float cx = (c == 0) ? -0.135f : 0.535f; - const float ry = (total <= 6) - ? (0.22f - static_cast(r) * 0.24f) - : (0.25f - static_cast(r) * 0.17f); + float ry = 0.0f; + if (total <= 6) { + ry = 0.22f - static_cast(r) * 0.24f; + } else if (total <= 8) { + ry = 0.25f - static_cast(r) * 0.17f; + } else { + ry = 0.27f - static_cast(r) * 0.142f; + } const bool en = settingsEnabled_.empty() || (i < static_cast(settingsEnabled_.size()) && settingsEnabled_[i] != 0); @@ -2853,12 +3150,18 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, en ? themeTextCol : dimCol, label); drawFitCentered(cx, ry - 0.028f, 0.51f, scSub, en ? themeTextCol : dimCol, val.empty() ? label : val); - } else { + } else if (total <= 8) { drawFit(cx - 0.275f, ry + 0.016f, 0.55f, scSub, en ? themeTextCol : dimCol, label); if (!val.empty()) { drawFit(cx - 0.275f, ry - 0.026f, 0.55f, scDetail, themeAccentCol, val); } + } else { + drawFit(cx - 0.275f, ry + 0.014f, 0.55f, scSub * 0.90f, + en ? themeTextCol : dimCol, label); + if (!val.empty()) { + drawFit(cx - 0.275f, ry - 0.020f, 0.55f, scDetail * 0.95f, themeAccentCol, val); + } } } @@ -2929,8 +3232,8 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, drawUiElement(vpPanel, 0.0f, 0.0f, kPanelW, kPanelTop, UiShape::RoundedBox, backdrop, 0.045f); - const float mHalfW = (actionMenu_.page == 3) ? 0.48f : 0.44f; - const float mHalfH = (actionMenu_.page == 3) ? 0.32f : 0.28f; + const float mHalfW = (actionMenu_.page == 4) ? 0.48f : ((actionMenu_.page == 3) ? 0.48f : 0.44f); + const float mHalfH = (actionMenu_.page == 4) ? 0.38f : ((actionMenu_.page == 3) ? 0.32f : 0.28f); const float modalBg[4] = {0.032f, 0.045f, 0.075f, 0.98f}; drawUiElement(vpPanel, 0.0f, 0.0f, mHalfW, mHalfH, UiShape::RoundedBox, modalBg, 0.07f, 0.02f, themeAccentCol); @@ -3035,6 +3338,37 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, drawRowKeys(kRow1, -0.055f, 12, 0.065f, 0.012f); drawRowKeys(kRow2, -0.115f, 22, 0.070f, 0.012f); drawRowKeys(kRow3, -0.175f, 31, 0.070f, 0.012f); + } else if (actionMenu_.page == 4) { + // SMB Share Editor Modal + const int optCount = static_cast(actionMenu_.options.size()); + const int fieldCount = std::min(optCount, 7); + for (int i = 0; i < fieldCount; ++i) { + const float cy = 0.19f - static_cast(i) * 0.054f; + const bool hov = (actionMenuBtnHovered_ == i) || (actionMenu_.selectedOption == i); + drawUiElement(vpPanel, 0.0f, cy, 0.42f, 0.024f, + UiShape::RoundedBox, hov ? tabHovBg : tabNormBg, 0.35f, 0.018f, + hov ? tabActiveBord : tabNormBord); + } + if (optCount == 8) { + // Save (7) and Cancel (8) + const bool hov7 = (actionMenuBtnHovered_ == 7) || (actionMenu_.selectedOption == 7); + const bool hov8 = (actionMenuBtnHovered_ == 8) || (actionMenu_.selectedOption == 8); + drawUiElement(vpPanel, -0.15f, -0.25f, 0.13f, 0.026f, UiShape::RoundedBox, + hov7 ? tabHovBg : tabNormBg, 0.40f, 0.022f, hov7 ? tabActiveBord : tabActiveBord); + drawUiElement(vpPanel, 0.15f, -0.25f, 0.13f, 0.026f, UiShape::RoundedBox, + hov8 ? slateBgHov : slateBg, 0.40f, 0.022f, hov8 ? slateBorder : tabNormBord); + } else if (optCount >= 9) { + // Save (7), Delete (8), Cancel (9) + const bool hov7 = (actionMenuBtnHovered_ == 7) || (actionMenu_.selectedOption == 7); + const bool hov8 = (actionMenuBtnHovered_ == 8) || (actionMenu_.selectedOption == 8); + const bool hov9 = (actionMenuBtnHovered_ == 9) || (actionMenu_.selectedOption == 9); + drawUiElement(vpPanel, -0.24f, -0.25f, 0.11f, 0.026f, UiShape::RoundedBox, + hov7 ? tabHovBg : tabNormBg, 0.40f, 0.022f, hov7 ? tabActiveBord : tabActiveBord); + drawUiElement(vpPanel, 0.0f, -0.25f, 0.10f, 0.026f, UiShape::RoundedBox, + hov8 ? redBgHov : redBg, 0.40f, 0.022f, redBorder); + drawUiElement(vpPanel, 0.24f, -0.25f, 0.10f, 0.026f, UiShape::RoundedBox, + hov9 ? slateBgHov : slateBg, 0.40f, 0.022f, slateBorder); + } } // Text pass for Action Menu @@ -3090,9 +3424,91 @@ void VulkanRenderer::renderView(uint32_t viewIndex, uint32_t imageIndex, drawRowText(kRow1, -0.055f, 12, 0.065f, 0.012f); drawRowText(kRow2, -0.115f, 22, 0.070f, 0.012f); drawRowText(kRow3, -0.175f, 31, 0.070f, 0.012f); + } else if (actionMenu_.page == 4) { + const int optCount = static_cast(actionMenu_.options.size()); + const int fieldCount = std::min(optCount, 7); + for (int i = 0; i < fieldCount; ++i) { + const float cy = 0.19f - static_cast(i) * 0.054f; + const bool hov = (actionMenuBtnHovered_ == i) || (actionMenu_.selectedOption == i); + const std::string& opt = actionMenu_.options[i]; + const auto colonPos = opt.find(':'); + if (colonPos != std::string::npos) { + std::string label = opt.substr(0, colonPos + 1); + std::string val = opt.substr(colonPos + 1); + while (!val.empty() && val.front() == ' ') val.erase(val.begin()); + drawFit(-0.39f, cy - 0.003f, 0.24f, sc * 0.90f, hov ? themeTextCol : slateCol, label); + drawFit(-0.13f, cy - 0.003f, 0.52f, sc * 0.92f, themeAccentCol, val); + } else { + drawFitCentered(0.0f, cy - 0.003f, 0.78f, sc * 0.90f, hov ? themeTextCol : slateCol, opt); + } + } + if (optCount == 8) { + const bool hov7 = (actionMenuBtnHovered_ == 7) || (actionMenu_.selectedOption == 7); + const bool hov8 = (actionMenuBtnHovered_ == 8) || (actionMenu_.selectedOption == 8); + drawFitCentered(-0.15f, -0.253f, 0.24f, sc * 0.95f, hov7 ? themeTextCol : themeAccentCol, "Save SMB Share"); + drawFitCentered(0.15f, -0.253f, 0.24f, sc * 0.95f, hov8 ? themeTextCol : slateCol, "Cancel"); + } else if (optCount >= 9) { + const bool hov7 = (actionMenuBtnHovered_ == 7) || (actionMenu_.selectedOption == 7); + const bool hov8 = (actionMenuBtnHovered_ == 8) || (actionMenu_.selectedOption == 8); + const bool hov9 = (actionMenuBtnHovered_ == 9) || (actionMenu_.selectedOption == 9); + const float redCol[4] = {1.0f, 0.40f, 0.40f, 1.0f}; + drawFitCentered(-0.24f, -0.253f, 0.20f, sc * 0.95f, hov7 ? themeTextCol : themeAccentCol, "Save SMB Share"); + drawFitCentered(0.0f, -0.253f, 0.18f, sc * 0.95f, hov8 ? themeTextCol : redCol, "Delete"); + drawFitCentered(0.24f, -0.253f, 0.18f, sc * 0.95f, hov9 ? themeTextCol : slateCol, "Cancel"); + } } } + // ========================================================================= + // Floating Virtual Keyboard Live Input Preview (above SteamVR keyboard) + // ========================================================================= + if (keyboardModal_.visible && textReady_ && uiPipeline_ != VK_NULL_HANDLE) { + vkCmdBindPipeline(commandBuffer_, VK_PIPELINE_BIND_POINT_GRAPHICS, uiPipeline_); + // 1. Semi-translucent dimming background across viewport + const float dimBg[4] = {0.0f, 0.0f, 0.0f, 0.65f}; + drawUiElement(vpPanel, 0.0f, 0.0f, 1.20f, 0.80f, UiShape::RoundedBox, dimBg, 0.05f); + + // 2. Floating Modal Box (centered right above SteamVR keyboard at cy = 0.16f) + const float mBoxBg[4] = {0.024f, 0.035f, 0.060f, 0.98f}; + const float mBorder[4] = {themeAccentCol[0], themeAccentCol[1], themeAccentCol[2], 0.95f}; + drawUiElement(vpPanel, 0.0f, 0.16f, 0.46f, 0.13f, UiShape::RoundedBox, mBoxBg, 0.06f, 0.016f, mBorder); + + // 3. Recessed Input Field Box + const float fieldBg[4] = {0.010f, 0.014f, 0.024f, 0.98f}; + const float fieldBord[4] = {0.20f, 0.32f, 0.50f, 0.85f}; + drawUiElement(vpPanel, 0.0f, 0.15f, 0.40f, 0.038f, UiShape::RoundedBox, fieldBg, 0.035f, 0.015f, fieldBord); + + // Text pass + vkCmdBindPipeline(commandBuffer_, VK_PIPELINE_BIND_POINT_GRAPHICS, textPipeline_); + vkCmdBindDescriptorSets(commandBuffer_, VK_PIPELINE_BIND_POINT_GRAPHICS, + textPipelineLayout_, 0, 1, &textSet_, 0, nullptr); + + const float scHeader = (0.038f * tScale) / fontAtlas_.lineHeight; + const float scStd = (0.030f * tScale) / fontAtlas_.lineHeight; + const float scDetail = (0.022f * tScale) / fontAtlas_.lineHeight; + const float kbSlateCol[4] = {themeTextCol[0] * 0.78f, themeTextCol[1] * 0.84f, themeTextCol[2] * 0.94f, 0.95f}; + + // Prompt Title + drawFitCentered(0.0f, 0.235f, 0.85f, scHeader * 0.85f, themeTextCol, + keyboardModal_.prompt.empty() ? "Virtual Keyboard Input" : keyboardModal_.prompt); + + // Live Typed Text Buffer (with password masking and blinking cursor) + std::string dispText = keyboardModal_.isPassword + ? std::string(keyboardModal_.text.length(), '*') + : keyboardModal_.text; + + static auto sStartT = std::chrono::steady_clock::now(); + const auto nowMs = std::chrono::duration_cast(std::chrono::steady_clock::now() - sStartT).count(); + const bool cursorBlink = ((nowMs / 500) % 2) == 0; + dispText += (cursorBlink ? "_" : " "); + + drawFitCentered(0.0f, 0.15f, 0.76f, scStd * 1.15f, themeAccentCol, dispText); + + // Instruction Subtitle + drawFitCentered(0.0f, 0.075f, 0.85f, scDetail * 0.95f, kbSlateCol, + "Type on the SteamVR virtual keyboard below \xB7 Press Enter/Done to submit"); + } + // Tracked controller 3D models (lit capsule), drawn before the laser/cursor. if (drawModels_ && (controllers_[0].active || controllers_[1].active) && diff --git a/src/gfx/vulkan_renderer.hpp b/src/gfx/vulkan_renderer.hpp index bb7004a..709dc7c 100644 --- a/src/gfx/vulkan_renderer.hpp +++ b/src/gfx/vulkan_renderer.hpp @@ -124,6 +124,9 @@ public: std::string detail; std::string tag; std::string durationTag; + std::string sizeTag; + std::string resolutionTag; + std::string codecTag; std::string previewPath; bool isDir = false; bool isVideo = false; @@ -163,6 +166,44 @@ public: uiDistance_ = uiDistance; } + enum class BrowserViewMode : int { + BigCards = 0, // 3x2, 6 per page (Large cards with full 16:9 thumbnail) + MiniCards = 1, // 4x3, 12 per page (Compact cards with 16:9 thumbnail) + CompactList = 2 // 1x8, 8 per page (Single-column detailed configurable list view) + }; + void setBrowserViewMode(BrowserViewMode mode) { browserViewMode_ = mode; } + BrowserViewMode browserViewMode() const { return browserViewMode_; } + void setBrowserQuickPath(bool isCurrentQuickPath) { browserIsQuickPath_ = isCurrentQuickPath; } + void setBrowserBookmarked(bool isCurrentBookmarked) { browserIsQuickPath_ = isCurrentBookmarked; } + bool browserIsQuickPath() const { return browserIsQuickPath_; } + bool browserIsBookmarked() const { return browserIsQuickPath_; } + void setListColumnVisibility(bool showFormat, bool showRes, bool showSize, bool showDuration) { + listShowFormat_ = showFormat; + listShowRes_ = showRes; + listShowSize_ = showSize; + listShowDuration_ = showDuration; + } + + struct KeyboardModalData { + bool visible = false; + std::string prompt; + std::string text; + bool isPassword = false; + }; + void setKeyboardModal(bool visible, const std::string& prompt, + const std::string& text, bool isPassword = false) { + keyboardModal_.visible = visible; + keyboardModal_.prompt = prompt; + keyboardModal_.text = text; + keyboardModal_.isPassword = isPassword; + } + const KeyboardModalData& keyboardModal() const { return keyboardModal_; } + + void setUiFollowMode(int mode) { uiFollowMode_ = mode; } + int uiFollowMode() const { return uiFollowMode_; } + + bool pointerActive() const { return pointerActive_; } + // Downloads overlay: modern glassmorphic window with job cards void setDownloads(bool visible, const std::string& title, const std::vector& rows, @@ -276,9 +317,11 @@ public: FormatToggle = 8, AudioToggle = 9, ScreenToggle = 10, - Recenter = 11 // recenter screen/view from HUD + Recenter = 11, // recenter screen/view from HUD + HideHud = 12 // immediately hide player controls }; void setControlBar(bool visible) { controlBarVisible_ = visible; } + bool controlBarVisible() const { return controlBarVisible_; } void setHudLabels(const std::string& format, const std::string& audio, const std::string& screen, bool formatEnabled = true, bool audioEnabled = true) { @@ -453,9 +496,17 @@ private: std::string path; bool ready = false; }; - CardThumbnail cardThumbs_[6]; + CardThumbnail cardThumbs_[12]; VkPipeline thumbPipeline_ = VK_NULL_HANDLE; VkDescriptorPool thumbPool_ = VK_NULL_HANDLE; + BrowserViewMode browserViewMode_ = BrowserViewMode::BigCards; + bool browserIsQuickPath_ = false; + KeyboardModalData keyboardModal_{}; + int uiFollowMode_ = 0; // 0 = World Lock (Default, zero drift/tilt), 1 = Smooth Gaze Follow + bool listShowFormat_ = true; + bool listShowRes_ = true; + bool listShowSize_ = true; + bool listShowDuration_ = true; // Text rendering (FreeType glyph atlas) + file browser overlay. FontAtlas fontAtlas_; diff --git a/src/media/media_engine.cpp b/src/media/media_engine.cpp index 0f6eba2..296e397 100644 --- a/src/media/media_engine.cpp +++ b/src/media/media_engine.cpp @@ -43,13 +43,31 @@ extern "C" { #include #endif +#include "net/smb_credentials.hpp" + namespace pixelvr { #ifdef PIXELVR_HAVE_SMB namespace { -void smb_auth(SMBCCTX*, const char*, const char*, char*, int, char* un, int unlen, +void smb_auth(SMBCCTX*, const char* srv, const char* shr, char* wg, int wglen, char* un, int unlen, char* pw, int pwlen) { + std::string u, p, w; + if (srv != nullptr && SmbCredentialsManager::instance().findCredentials(srv, shr ? shr : "", u, p, w)) { + if (un && unlen > 0) { + std::strncpy(un, u.c_str(), unlen - 1); + un[unlen - 1] = '\0'; + } + if (pw && pwlen > 0) { + std::strncpy(pw, p.c_str(), pwlen - 1); + pw[pwlen - 1] = '\0'; + } + if (wg && wglen > 0 && !w.empty()) { + std::strncpy(wg, w.c_str(), wglen - 1); + wg[wglen - 1] = '\0'; + } + return; + } if (un != nullptr && unlen > 0) un[0] = '\0'; // guest / anonymous if (pw != nullptr && pwlen > 0) pw[0] = '\0'; } diff --git a/src/net/smb_credentials.cpp b/src/net/smb_credentials.cpp new file mode 100644 index 0000000..6de45fd --- /dev/null +++ b/src/net/smb_credentials.cpp @@ -0,0 +1,486 @@ +#include "smb_credentials.hpp" +#include "util/logging.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(__linux__) || defined(__APPLE__) +#include +#include +#endif + +namespace pixelvr { +namespace fs = std::filesystem; + +namespace { + +// Clean portable ChaCha20 stream cipher implementation +// RFC 7539 / 8439 +static uint32_t rotl32(uint32_t x, int n) { + return (x << n) | (x >> (32 - n)); +} + +#define CHACHA20_QUARTERROUND(a, b, c, d) \ + a += b; d ^= a; d = rotl32(d, 16); \ + c += d; b ^= c; b = rotl32(b, 12); \ + a += b; d ^= a; d = rotl32(d, 8); \ + c += d; b ^= c; b = rotl32(b, 7); + +static void chacha20_block(uint32_t out[16], const uint32_t in[16]) { + for (int i = 0; i < 16; ++i) out[i] = in[i]; + for (int i = 0; i < 10; ++i) { + CHACHA20_QUARTERROUND(out[0], out[4], out[8], out[12]); + CHACHA20_QUARTERROUND(out[1], out[5], out[9], out[13]); + CHACHA20_QUARTERROUND(out[2], out[6], out[10], out[14]); + CHACHA20_QUARTERROUND(out[3], out[7], out[11], out[15]); + CHACHA20_QUARTERROUND(out[0], out[5], out[10], out[15]); + CHACHA20_QUARTERROUND(out[1], out[6], out[11], out[12]); + CHACHA20_QUARTERROUND(out[2], out[7], out[8], out[13]); + CHACHA20_QUARTERROUND(out[3], out[4], out[9], out[14]); + } + for (int i = 0; i < 16; ++i) out[i] += in[i]; +} + +static void chacha20_crypt(const uint8_t key[32], const uint8_t nonce[12], uint32_t counter, + const uint8_t* in, uint8_t* out, std::size_t len) { + uint32_t state[16]; + // Constants "expand 32-byte k" + state[0] = 0x61707865; + state[1] = 0x3320646e; + state[2] = 0x79622d32; + state[3] = 0x6b206574; + for (int i = 0; i < 8; ++i) { + state[4 + i] = (static_cast(key[i * 4 + 0])) | + (static_cast(key[i * 4 + 1]) << 8) | + (static_cast(key[i * 4 + 2]) << 16) | + (static_cast(key[i * 4 + 3]) << 24); + } + state[12] = counter; + for (int i = 0; i < 3; ++i) { + state[13 + i] = (static_cast(nonce[i * 4 + 0])) | + (static_cast(nonce[i * 4 + 1]) << 8) | + (static_cast(nonce[i * 4 + 2]) << 16) | + (static_cast(nonce[i * 4 + 3]) << 24); + } + + uint32_t block[16]; + uint8_t keyStream[64]; + std::size_t offset = 0; + while (offset < len) { + chacha20_block(block, state); + for (int i = 0; i < 16; ++i) { + keyStream[i * 4 + 0] = static_cast(block[i] & 0xFF); + keyStream[i * 4 + 1] = static_cast((block[i] >> 8) & 0xFF); + keyStream[i * 4 + 2] = static_cast((block[i] >> 16) & 0xFF); + keyStream[i * 4 + 3] = static_cast((block[i] >> 24) & 0xFF); + } + state[12]++; + const std::size_t chunk = std::min(64, len - offset); + for (std::size_t i = 0; i < chunk; ++i) { + out[offset + i] = in[offset + i] ^ keyStream[i]; + } + offset += chunk; + } +} + +static std::string toHex(const uint8_t* data, std::size_t len) { + std::ostringstream oss; + oss << std::hex << std::setfill('0'); + for (std::size_t i = 0; i < len; ++i) { + oss << std::setw(2) << static_cast(data[i]); + } + return oss.str(); +} + +static std::vector fromHex(const std::string& hex) { + std::vector bytes; + if (hex.length() % 2 != 0) return bytes; + bytes.reserve(hex.length() / 2); + for (std::size_t i = 0; i < hex.length(); i += 2) { + const std::string byteStr = hex.substr(i, 2); + char* end = nullptr; + unsigned long b = std::strtoul(byteStr.c_str(), &end, 16); + if (end == byteStr.c_str() + 2) { + bytes.push_back(static_cast(b)); + } else { + return {}; + } + } + return bytes; +} + +static std::string trim(const std::string& s) { + auto start = s.find_first_not_of(" \t\r\n"); + if (start == std::string::npos) return ""; + auto end = s.find_last_not_of(" \t\r\n"); + return s.substr(start, end - start + 1); +} + +} // namespace + +SmbCredentialsManager& SmbCredentialsManager::instance() { + static SmbCredentialsManager sInstance; + return sInstance; +} + +SmbCredentialsManager::SmbCredentialsManager() { + load(); +} + +std::string SmbCredentialsManager::getStoragePath() const { +#ifdef _WIN32 + const char* appData = std::getenv("APPDATA"); + if (appData) return std::string(appData) + "/PixelVR/smb_shares.json"; +#else + const char* home = std::getenv("HOME"); + if (home) return std::string(home) + "/.config/pixelvr/smb_shares.json"; +#endif + return "pixelvr_smb_shares.json"; +} + +std::string SmbCredentialsManager::getDeviceKey() const { + std::string seed = "PixelVR-Frame-SMB-2026-Salt!"; +#if defined(__linux__) + std::ifstream mid("/etc/machine-id"); + if (mid.is_open()) { + std::string id; + std::getline(mid, id); + id = trim(id); + if (!id.empty()) { + seed += ":" + id; + } + } +#endif + const char* user = std::getenv("USER"); + if (user) seed += ":" + std::string(user); + + // Derive 32-byte key using double FNV-1a / DJB2 mixing + uint64_t h1 = 14695981039346656037ULL; + uint64_t h2 = 5381; + for (char c : seed) { + h1 = (h1 ^ static_cast(c)) * 1099511628211ULL; + h2 = ((h2 << 5) + h2) + static_cast(c); + } + uint8_t keyBytes[32]; + for (int i = 0; i < 8; ++i) { + keyBytes[i + 0] = static_cast((h1 >> (i * 8)) & 0xFF); + keyBytes[i + 8] = static_cast((h2 >> (i * 8)) & 0xFF); + keyBytes[i + 16] = static_cast(((h1 ^ h2) >> (i * 8)) & 0xFF); + keyBytes[i + 24] = static_cast(((h1 + h2) >> (i * 8)) & 0xFF); + } + return std::string(reinterpret_cast(keyBytes), 32); +} + +std::string SmbCredentialsManager::encryptPassword(const std::string& plain, + const std::string& key, + std::string& outIvHex) const { + if (plain.empty()) { + outIvHex.clear(); + return ""; + } + uint8_t nonce[12]; + std::random_device rd; + for (int i = 0; i < 12; ++i) { + nonce[i] = static_cast(rd() & 0xFF); + } + outIvHex = toHex(nonce, 12); + + std::vector cipher(plain.length()); + chacha20_crypt(reinterpret_cast(key.data()), nonce, 1, + reinterpret_cast(plain.data()), cipher.data(), plain.length()); + return toHex(cipher.data(), cipher.size()); +} + +std::string SmbCredentialsManager::decryptPassword(const std::string& cipherHex, + const std::string& key, + const std::string& ivHex) const { + if (cipherHex.empty() || ivHex.empty()) return ""; + std::vector cipher = fromHex(cipherHex); + std::vector nonce = fromHex(ivHex); + if (cipher.empty() || nonce.size() != 12) return ""; + + std::string plain(cipher.size(), '\0'); + chacha20_crypt(reinterpret_cast(key.data()), nonce.data(), 1, + cipher.data(), reinterpret_cast(plain.data()), cipher.size()); + return plain; +} + +void SmbCredentialsManager::load() { + std::lock_guard lk(mutex_); + shares_.clear(); + + const std::string path = getStoragePath(); + std::ifstream f(path); + if (!f.is_open()) { + return; + } + + std::string content((std::istreambuf_iterator(f)), + std::istreambuf_iterator()); + f.close(); + + const std::string key = getDeviceKey(); + + // Lightweight robust JSON parser for share objects + std::size_t pos = 0; + while ((pos = content.find('{', pos)) != std::string::npos) { + std::size_t endObj = content.find('}', pos); + if (endObj == std::string::npos) break; + + std::string obj = content.substr(pos, endObj - pos + 1); + pos = endObj + 1; + + auto extractField = [&](const std::string& keyName) -> std::string { + const std::string pattern = "\"" + keyName + "\""; + std::size_t kpos = obj.find(pattern); + if (kpos == std::string::npos) return ""; + std::size_t colon = obj.find(':', kpos + pattern.length()); + if (colon == std::string::npos) return ""; + std::size_t startVal = obj.find_first_not_of(" \t\r\n", colon + 1); + if (startVal == std::string::npos) return ""; + if (obj[startVal] == '\"') { + std::size_t endQuote = obj.find('\"', startVal + 1); + if (endQuote != std::string::npos) { + return obj.substr(startVal + 1, endQuote - startVal - 1); + } + } else { + std::size_t endVal = obj.find_first_of(",}\r\n", startVal); + return trim(obj.substr(startVal, endVal - startVal)); + } + return ""; + }; + + SmbShare s; + s.id = extractField("id"); + s.name = extractField("name"); + s.host = extractField("host"); + s.share = extractField("share"); + s.workgroup = extractField("workgroup"); + if (s.workgroup.empty()) s.workgroup = "WORKGROUP"; + s.username = extractField("username"); + s.anonymous = (extractField("anonymous") == "true"); + + std::string passCipher = extractField("password_enc"); + std::string passIv = extractField("iv"); + if (!passCipher.empty() && !passIv.empty()) { + s.password = decryptPassword(passCipher, key, passIv); + } + + if (!s.host.empty()) { + if (s.name.empty()) { + s.name = s.host + (!s.share.empty() ? ("/" + s.share) : ""); + } + if (s.id.empty()) { + s.id = s.host + (!s.share.empty() ? ("/" + s.share) : ""); + } + shares_.push_back(s); + } + } + + PIXELVR_LOG_INFO("SmbCredentialsManager: Loaded %zu configured shares from %s", + shares_.size(), path.c_str()); +} + +void SmbCredentialsManager::save() { + std::lock_guard lk(mutex_); + const std::string path = getStoragePath(); + + std::error_code ec; + fs::path p(path); + fs::create_directories(p.parent_path(), ec); + +#if defined(__linux__) || defined(__APPLE__) + // Ensure configuration directory is protected (0700) + chmod(p.parent_path().string().c_str(), 0700); +#endif + + const std::string key = getDeviceKey(); + + std::ostringstream json; + json << "[\n"; + for (std::size_t i = 0; i < shares_.size(); ++i) { + const auto& s = shares_[i]; + std::string ivHex; + std::string encPass = encryptPassword(s.password, key, ivHex); + + json << " {\n"; + json << " \"id\": \"" << s.id << "\",\n"; + json << " \"name\": \"" << s.name << "\",\n"; + json << " \"host\": \"" << s.host << "\",\n"; + json << " \"share\": \"" << s.share << "\",\n"; + json << " \"workgroup\": \"" << s.workgroup << "\",\n"; + json << " \"username\": \"" << s.username << "\",\n"; + json << " \"password_enc\": \"" << encPass << "\",\n"; + json << " \"iv\": \"" << ivHex << "\",\n"; + json << " \"anonymous\": " << (s.anonymous ? "true" : "false") << "\n"; + json << " }" << (i + 1 < shares_.size() ? ",\n" : "\n"); + } + json << "]\n"; + + std::ofstream f(path, std::ios::trunc); + if (f.is_open()) { + f << json.str(); + f.close(); + +#if defined(__linux__) || defined(__APPLE__) + // Enforce strict OS-level permissions: readable & writable ONLY by steamos (0600) + chmod(path.c_str(), 0600); +#endif + PIXELVR_LOG_INFO("SmbCredentialsManager: Saved %zu shares to %s (mode 0600)", + shares_.size(), path.c_str()); + } else { + PIXELVR_LOG_WARN("SmbCredentialsManager: Failed to write %s", path.c_str()); + } +} + +std::vector SmbCredentialsManager::shares() const { + std::lock_guard lk(mutex_); + return shares_; +} + +void SmbCredentialsManager::addOrUpdateShare(const SmbShare& share) { + if (share.host.empty()) return; + + { + std::lock_guard lk(mutex_); + bool found = false; + for (auto& s : shares_) { + if (s.host == share.host && s.share == share.share) { + s = share; + found = true; + break; + } + } + if (!found) { + shares_.push_back(share); + } + } + save(); +} + +bool SmbCredentialsManager::deleteShare(const std::string& host, const std::string& share) { + bool removed = false; + { + std::lock_guard lk(mutex_); + auto it = std::remove_if(shares_.begin(), shares_.end(), [&](const SmbShare& s) { + if (s.host == host) { + if (share.empty() || s.share == share || s.share.empty()) { + return true; + } + } + return false; + }); + if (it != shares_.end()) { + shares_.erase(it, shares_.end()); + removed = true; + } + } + if (removed) { + save(); + PIXELVR_LOG_INFO("SmbCredentialsManager: Deleted share for host '%s'", host.c_str()); + } + return removed; +} + +bool SmbCredentialsManager::findShare(const std::string& hostIn, + const std::string& shareIn, + SmbShare& outShare) const { + std::lock_guard lk(mutex_); + if (hostIn.empty()) return false; + + std::string host = hostIn; + std::transform(host.begin(), host.end(), host.begin(), ::tolower); + std::string share = shareIn; + std::transform(share.begin(), share.end(), share.begin(), ::tolower); + + for (const auto& s : shares_) { + std::string sHost = s.host; + std::transform(sHost.begin(), sHost.end(), sHost.begin(), ::tolower); + if (sHost == host) { + std::string sShare = s.share; + std::transform(sShare.begin(), sShare.end(), sShare.begin(), ::tolower); + if (sShare == share || (share.empty() && sShare.empty())) { + outShare = s; + return true; + } + } + } + return false; +} + +bool SmbCredentialsManager::findCredentials(const std::string& hostIn, + const std::string& shareIn, + std::string& outUser, + std::string& outPass, + std::string& outWorkgroup) const { + std::lock_guard lk(mutex_); + if (hostIn.empty()) return false; + + std::string host = hostIn; + std::transform(host.begin(), host.end(), host.begin(), ::tolower); + std::string share = shareIn; + std::transform(share.begin(), share.end(), share.begin(), ::tolower); + + const SmbShare* bestMatch = nullptr; + for (const auto& s : shares_) { + std::string sHost = s.host; + std::transform(sHost.begin(), sHost.end(), sHost.begin(), ::tolower); + if (sHost == host) { + std::string sShare = s.share; + std::transform(sShare.begin(), sShare.end(), sShare.begin(), ::tolower); + if (!share.empty() && sShare == share) { + bestMatch = &s; // Exact share match takes highest priority + break; + } + if (sShare.empty() && !bestMatch) { + bestMatch = &s; // Host-level wildcard match + } + } + } + + if (bestMatch && !bestMatch->anonymous) { + outUser = bestMatch->username; + outPass = bestMatch->password; + outWorkgroup = bestMatch->workgroup.empty() ? "WORKGROUP" : bestMatch->workgroup; + return true; + } + return false; +} + +std::string SmbCredentialsManager::getAuthFilePath(const std::string& host, const std::string& share) { + std::string user, pass, wg; + if (!findCredentials(host, share, user, pass, wg)) { + return ""; + } + if (user.empty()) return ""; + + std::string basePath = getStoragePath(); + fs::path p(basePath); + std::string safeHost = host; + for (char& c : safeHost) { + if (!isalnum(c)) c = '_'; + } + fs::path authFile = p.parent_path() / ("auth_" + safeHost + ".tmp"); + + std::ofstream f(authFile.string(), std::ios::trunc); + if (!f.is_open()) return ""; + + f << "username = " << user << "\n"; + f << "password = " << pass << "\n"; + f << "domain = " << (wg.empty() ? "WORKGROUP" : wg) << "\n"; + f.close(); + +#if defined(__linux__) || defined(__APPLE__) + chmod(authFile.string().c_str(), 0600); +#endif + return authFile.string(); +} + +} // namespace pixelvr diff --git a/src/net/smb_credentials.hpp b/src/net/smb_credentials.hpp new file mode 100644 index 0000000..36e3172 --- /dev/null +++ b/src/net/smb_credentials.hpp @@ -0,0 +1,69 @@ +#pragma once + +#include +#include +#include + +namespace pixelvr { + +struct SmbShare { + std::string id; // Unique identifier (typically host or host:share) + std::string name; // User-friendly display label (e.g. "Home NAS") + std::string host; // IP address or hostname (e.g. "192.168.1.50") + std::string share; // Optional default share name (e.g. "movies", or empty for all) + std::string workgroup; // Workgroup/Domain (defaults to "WORKGROUP") + std::string username; // SMB Username (or empty for anonymous) + std::string password; // SMB Password (decrypted in memory, encrypted on disk) + bool anonymous = false; // True for guest / public shares +}; + +class SmbCredentialsManager { +public: + static SmbCredentialsManager& instance(); + + // Loads configured shares from ~/.config/pixelvr/smb_shares.json + void load(); + + // Saves configured shares to ~/.config/pixelvr/smb_shares.json with strict 0600 permissions + void save(); + + // Returns all configured SMB shares + std::vector shares() const; + + // Adds a new share or updates an existing one (matched by host + share) + void addOrUpdateShare(const SmbShare& share); + + // Deletes a configured share and wipes its stored credentials + bool deleteShare(const std::string& host, const std::string& share = ""); + + // Lookup a configured share + bool findShare(const std::string& host, + const std::string& share, + SmbShare& outShare) const; + + // Lookup credentials for a given host and optional share + bool findCredentials(const std::string& host, + const std::string& share, + std::string& outUser, + std::string& outPass, + std::string& outWorkgroup) const; + + // Generates or updates a secure temporary Samba auth file (mode 0600) for smbclient -A + // Returns the absolute file path, or empty string if anonymous / no credentials. + std::string getAuthFilePath(const std::string& host, const std::string& share); + +private: + SmbCredentialsManager(); + ~SmbCredentialsManager() = default; + + std::string getStoragePath() const; + std::string getDeviceKey() const; + + std::string encryptPassword(const std::string& plain, const std::string& key, std::string& outIv) const; + std::string decryptPassword(const std::string& cipherHex, const std::string& key, const std::string& ivHex) const; + + mutable std::mutex mutex_; + std::vector shares_; +}; + +} // namespace pixelvr diff --git a/src/ui/browser.cpp b/src/ui/browser.cpp index 834d639..0b67149 100644 --- a/src/ui/browser.cpp +++ b/src/ui/browser.cpp @@ -1,5 +1,6 @@ #include "ui/browser.hpp" #include "app/vault_manager.hpp" +#include "net/smb_credentials.hpp" #include "util/logging.hpp" #include "util/smb_lock.hpp" @@ -8,7 +9,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -48,8 +51,24 @@ bool is_video(const std::string& name) { } #ifdef PIXELVR_HAVE_SMB -void smb_auth(const char*, const char*, char*, int, char* user, int userLen, +void smb_auth(const char* srv, const char* shr, char* wg, int wgLen, char* user, int userLen, char* pass, int passLen) { + std::string u, p, w; + if (srv != nullptr && SmbCredentialsManager::instance().findCredentials(srv, shr ? shr : "", u, p, w)) { + if (user && userLen > 0) { + std::strncpy(user, u.c_str(), userLen - 1); + user[userLen - 1] = '\0'; + } + if (pass && passLen > 0) { + std::strncpy(pass, p.c_str(), passLen - 1); + pass[passLen - 1] = '\0'; + } + if (wg && wgLen > 0 && !w.empty()) { + std::strncpy(wg, w.c_str(), wgLen - 1); + wg[wgLen - 1] = '\0'; + } + return; + } if (user != nullptr && userLen > 0) user[0] = '\0'; // anonymous / guest if (pass != nullptr && passLen > 0) pass[0] = '\0'; } @@ -100,6 +119,8 @@ Browser::Browser() { const char* home = std::getenv("HOME"); homeDir_ = (home != nullptr) ? home : "/home/steamos"; downloadDir_ = homeDir_ + "/media"; + quickPath_ = homeDir_ + "/Videos"; + loadBookmarks(); } void Browser::open() { @@ -288,10 +309,31 @@ void Browser::scanSmbInto(const std::string& uri, ScanResult& out) { } // NetBIOS browsing often misses modern servers; augment the network root with - // mDNS-advertised SMB hosts (NAS, macOS, Samba+avahi). The slow network probe - // runs OUTSIDE the SMB lock (it is not a libsmbclient call). + // configured manual shares and mDNS-advertised SMB hosts (NAS, macOS, Samba+avahi). if (uri == "smb://") { std::set seen; + // The very first entry in the SMB list is the "+ Add SMB Share" button! + dirs.push_back({"+ Add SMB Share", "smb://__add_share__", true, false, false, false, "Configure New Network Share"}); + seen.insert("smb://__add_share__"); + + // Prepend all user-configured manual SMB shares so private/unadvertised shares always appear + const auto configuredShares = SmbCredentialsManager::instance().shares(); + for (const auto& s : configuredShares) { + if (s.host.empty()) continue; + std::string child = "smb://" + s.host; + if (!s.share.empty()) { + if (child.back() != '/') child += '/'; + child += s.share; + } + if (!seen.insert(child).second) continue; + std::string label = s.name.empty() ? s.host : s.name; + std::string detail = s.anonymous ? "Configured (Guest)" : "Configured (Protected)"; + if (!s.share.empty()) { + dirs.push_back({label + " (" + s.host + "/" + s.share + ")", child, true, false, false, false, detail}); + } else { + dirs.push_back({label + " (" + s.host + ")", child, true, false, false, false, detail}); + } + } for (const auto& d : dirs) seen.insert(d.path); FILE* pipe = popen("timeout 4 avahi-browse -trp _smb._tcp 2>/dev/null", "r"); if (pipe != nullptr) { @@ -411,6 +453,157 @@ void Browser::openVault() { openPath(VaultManager::instance().vaultDir()); } +void Browser::openBookmarks() { + open_ = true; + browseOpen_.store(true); + status_.clear(); + beginScan("bookmarks://", false); +} + +void Browser::addBookmark(const std::string& path, const std::string& label) { + if (path.empty() || path == "bookmarks://" || path == "smb://__add_share__") return; + for (auto& b : bookmarks_) { + if (b.path == path) return; + } + std::string l = label; + if (l.empty()) { + if (path.rfind("smb://", 0) == 0) { + std::string rest = path.substr(6); + while (!rest.empty() && rest.back() == '/') rest.pop_back(); + l = rest; + } else { + fs::path p(path); + l = p.filename().string(); + if (l.empty()) l = path; + } + } + bookmarks_.push_back({path, l}); + quickPath_ = path; + saveBookmarks(); + if (location_ == "bookmarks://") { + beginScan("bookmarks://", false); + } +} + +void Browser::removeBookmark(const std::string& path) { + auto it = std::remove_if(bookmarks_.begin(), bookmarks_.end(), [&](const Bookmark& b) { + return b.path == path; + }); + if (it != bookmarks_.end()) { + bookmarks_.erase(it, bookmarks_.end()); + saveBookmarks(); + if (location_ == "bookmarks://") { + beginScan("bookmarks://", false); + } + } +} + +bool Browser::isBookmarked(const std::string& path) const { + if (path.empty() || path == "bookmarks://") return false; + for (const auto& b : bookmarks_) { + if (b.path == path) return true; + } + return false; +} + +void Browser::loadBookmarks() { + bookmarks_.clear(); + const char* home = std::getenv("HOME"); + std::string path = std::string(home ? home : ".") + "/.config/pixelvr/bookmarks.json"; + std::ifstream f(path); + if (f.is_open()) { + std::string content((std::istreambuf_iterator(f)), std::istreambuf_iterator()); + f.close(); + + std::size_t pos = 0; + while ((pos = content.find('{', pos)) != std::string::npos) { + std::size_t endObj = content.find('}', pos); + if (endObj == std::string::npos) break; + std::string obj = content.substr(pos, endObj - pos + 1); + pos = endObj + 1; + + auto extract = [&](const std::string& key) -> std::string { + std::string pat = "\"" + key + "\""; + auto kpos = obj.find(pat); + if (kpos == std::string::npos) return ""; + auto col = obj.find(':', kpos + pat.length()); + if (col == std::string::npos) return ""; + auto q1 = obj.find('\"', col + 1); + if (q1 == std::string::npos) return ""; + auto q2 = obj.find('\"', q1 + 1); + if (q2 == std::string::npos) return ""; + return obj.substr(q1 + 1, q2 - q1 - 1); + }; + std::string bPath = extract("path"); + std::string bLabel = extract("label"); + if (!bPath.empty()) { + bookmarks_.push_back({bPath, bLabel}); + } + } + } + + if (bookmarks_.empty() && !quickPath_.empty()) { + addBookmark(quickPath_); + } +} + +void Browser::saveBookmarks() const { + const char* home = std::getenv("HOME"); + std::string configDir = std::string(home ? home : ".") + "/.config/pixelvr"; + std::error_code ec; + std::filesystem::create_directories(configDir, ec); + + std::string path = configDir + "/bookmarks.json"; + std::ofstream f(path, std::ios::trunc); + if (!f.is_open()) return; + + f << "[\n"; + for (std::size_t i = 0; i < bookmarks_.size(); ++i) { + f << " {\n"; + f << " \"path\": \"" << bookmarks_[i].path << "\",\n"; + f << " \"label\": \"" << bookmarks_[i].label << "\"\n"; + f << " }" << (i + 1 < bookmarks_.size() ? ",\n" : "\n"); + } + f << "]\n"; + f.close(); +} + +void Browser::scanBookmarksInto(ScanResult& out) { + out.inSmb = false; + out.location = "bookmarks://"; + out.title = "Bookmarks"; + out.entries.clear(); + out.entries.push_back({".. (Home)", homeDir_, true, false, true, false}); + + if (bookmarks_.empty()) { + out.status = "No bookmarks yet. Click [+ Bookmark] in any folder to add one."; + return; + } + + out.status = std::to_string(bookmarks_.size()) + (bookmarks_.size() == 1 ? " bookmark" : " bookmarks"); + + for (const auto& bm : bookmarks_) { + if (bm.path.empty()) continue; + const bool isSmb = (bm.path.rfind("smb://", 0) == 0); + std::error_code ec; + const bool isDir = isSmb || fs::is_directory(bm.path, ec); + std::string label = bm.label; + if (label.empty()) { + if (isSmb) { + label = bm.path.substr(6); + while (!label.empty() && label.back() == '/') label.pop_back(); + } else { + fs::path p(bm.path); + label = p.filename().string(); + if (label.empty()) label = bm.path; + } + } + std::string detail = isSmb ? "SMB Share" : (isDir ? "Folder" : "Video File"); + std::string previewPath = isDir ? "" : bm.path; + out.entries.push_back({label, bm.path, isDir, !isDir && is_video(bm.path), false, isSmb, detail, 0, previewPath}); + } +} + bool Browser::inVault() const { return VaultManager::instance().isVaultPath(location_); } @@ -519,6 +712,7 @@ bool Browser::renameFocused(const std::string& newName) { } std::string Browser::parentDir() const { + if (location_ == "bookmarks://") return homeDir_; if (location_.empty() || location_ == "/" || inSmb_) return ""; fs::path p(location_); return p.parent_path().string(); @@ -543,7 +737,9 @@ std::string Browser::downloadsDir() const { void Browser::runScan(std::string location, bool isSmb) { ScanResult r; - if (isSmb) { + if (location == "bookmarks://") { + scanBookmarksInto(r); + } else if (isSmb) { scanSmbInto(location, r); } else { scanLocalInto(location, r); @@ -565,6 +761,10 @@ Browser::Result Browser::activate(std::string& playPath) { const Entry e = entries_[static_cast(selected_)]; if (e.isBack) { + if (location_ == "bookmarks://") { + beginScan(homeDir_, false); + return Result::Navigated; + } if (inSmb_) { const std::string parent = smb_parent(location_); if (parent.empty()) { @@ -587,12 +787,16 @@ Browser::Result Browser::activate(std::string& playPath) { } return Result::Navigated; } + if (e.path == "smb://__add_share__") { + return Result::AddSmbShare; + } if (e.isNetwork) { beginScan("smb://", true); return Result::Navigated; } if (e.isDir) { - beginScan(e.path, inSmb_); + const bool isSmb = e.isNetwork || (e.path.rfind("smb://", 0) == 0); + beginScan(e.path, isSmb); return Result::Navigated; } if (e.isVideo) { @@ -793,6 +997,8 @@ int Browser::spawnCurl(const std::string& uri, const std::string& local) { const std::size_t s2 = (s1 == std::string::npos) ? std::string::npos : rest.find('/', s1 + 1); if (s2 == std::string::npos) return -1; + const std::string host = rest.substr(0, s1); + const std::string share = rest.substr(s1 + 1, s2 - s1 - 1); const std::string service = "//" + rest.substr(0, s2); const std::string remote = rest.substr(s2 + 1); std::string cmd = "get \""; @@ -800,14 +1006,26 @@ int Browser::spawnCurl(const std::string& uri, const std::string& local) { cmd += "\" \""; cmd += local; cmd += "\""; - PIXELVR_LOG_INFO("DL spawn: smbclient %s -N -c '%s'", service.c_str(), - cmd.c_str()); - char* argv[] = {const_cast("smbclient"), - const_cast(service.c_str()), - const_cast("-N"), - const_cast("-c"), - const_cast(cmd.c_str()), - nullptr}; + + std::string authFile = SmbCredentialsManager::instance().getAuthFilePath(host, share); + PIXELVR_LOG_INFO("DL spawn: smbclient %s %s -c '%s'", service.c_str(), + authFile.empty() ? "-N" : ("-A " + authFile).c_str(), cmd.c_str()); + + char* argv[8] = {nullptr}; + argv[0] = const_cast("smbclient"); + argv[1] = const_cast(service.c_str()); + if (!authFile.empty()) { + argv[2] = const_cast("-A"); + argv[3] = const_cast(authFile.c_str()); + argv[4] = const_cast("-c"); + argv[5] = const_cast(cmd.c_str()); + argv[6] = nullptr; + } else { + argv[2] = const_cast("-N"); + argv[3] = const_cast("-c"); + argv[4] = const_cast(cmd.c_str()); + argv[5] = nullptr; + } posix_spawn_file_actions_t fa; posix_spawn_file_actions_init(&fa); // Take stdin from /dev/null so smbclient can never block on an auth prompt. diff --git a/src/ui/browser.hpp b/src/ui/browser.hpp index 114d014..1ff5833 100644 --- a/src/ui/browser.hpp +++ b/src/ui/browser.hpp @@ -26,7 +26,7 @@ public: long long size = 0; // bytes (0 if unknown) std::string previewPath; // video file inside folder or self (for thumbnail) }; - enum class Result { None, Navigated, Play }; + enum class Result { None, Navigated, Play, AddSmbShare }; Browser(); @@ -42,12 +42,31 @@ public: void openDownloads(); void openDrives(); void openVault(); + struct Bookmark { + std::string path; + std::string label; + }; + void openBookmarks(); + void addBookmark(const std::string& path, const std::string& label = ""); + void removeBookmark(const std::string& path); + bool isBookmarked(const std::string& path) const; + bool isCurrentBookmarked() const { return isBookmarked(location_); } + const std::vector& bookmarks() const { return bookmarks_; } + void loadBookmarks(); + void saveBookmarks() const; + bool onBookmarks() const { return location_ == "bookmarks://"; } + + void openQuickPath() { openBookmarks(); } + void setQuickPath(const std::string& path) { addBookmark(path); } + const std::string& quickPath() const { return quickPath_; } + bool isCurrentQuickPath() const { return isCurrentBookmarked(); } bool inVault() const; bool moveFocusedToVault(std::string& outNewPath); bool moveFocusedTo(const std::string& destDir, std::string& outNewPath); bool deleteFocused(std::string& deletedName); bool renameFocused(const std::string& newName); const std::string& currentLocation() const { return location_; } + const std::string& currentPath() const { return location_; } std::string parentDir() const; std::string homeDir() const; std::string videosDir() const; @@ -164,6 +183,7 @@ private: bool hasPendingScan_ = false; void scanLocalInto(const std::string& dir, ScanResult& out); void scanSmbInto(const std::string& uri, ScanResult& out); + void scanBookmarksInto(ScanResult& out); void startDownloadFile(const std::string& uri, const std::string& local); void startDownloadFolder(const std::string& uri, const std::string& name); void startNextQueued(); @@ -174,6 +194,8 @@ private: std::string status_; std::string location_; // current local dir or smb:// URI std::string homeDir_; + std::string quickPath_; // bookmarked folder for one-button jump + std::vector bookmarks_; std::string lastLocation_; // last folder visited (local or smb), for re-open bool lastInSmb_ = false; std::vector entries_; diff --git a/src/ui/settings_menu.cpp b/src/ui/settings_menu.cpp index 0f95522..8960d2f 100644 --- a/src/ui/settings_menu.cpp +++ b/src/ui/settings_menu.cpp @@ -1,5 +1,7 @@ #include "ui/settings_menu.hpp" #include "app/vault_manager.hpp" +#include "net/smb_credentials.hpp" +#include "xr/vr_keyboard.hpp" #include "util/logging.hpp" @@ -78,7 +80,7 @@ SettingsMenu::SettingsMenu() { void SettingsMenu::open() { open_ = true; - if (section_ < 0 || section_ > 3) section_ = 0; + if (section_ < 0 || (section_ > 5 && section_ != 20)) section_ = 0; refresh(); } @@ -142,6 +144,17 @@ void SettingsMenu::refresh() { rows_.push_back({"UI Panel Distance", kUiDistanceNames[uiDistanceIdx_ % kUiDistanceCount], Action::CycleUiDistance}); + const char* followModeNames[2] = {"World Lock (Fixed)", "Smooth Gaze Follow"}; + rows_.push_back({"UI Follow Mode", + followModeNames[uiFollowMode_ % 2], + Action::CycleUiFollowMode}); + const char* viewModeNames[3] = {"Large Cards (3x2)", "Smaller Cards (4x3)", "Compact List (1-Col)"}; + rows_.push_back({"Browser View Mode", + viewModeNames[browserViewMode_ % 3], + Action::CycleBrowserViewMode}); + rows_.push_back({"Configure List Columns", + "[ Customize Columns > ]", + Action::EnterListColsConfig}); rows_.push_back({"Download Folder", kDownloadDirs[downloadDirIdx_ % kDownloadDirCount], Action::CycleDownloadDir}); @@ -183,6 +196,8 @@ void SettingsMenu::refresh() { Action::ListenMenu}); rows_.push_back({"Recenter View", btnLabel(2, bindRecenterBtn_), Action::ListenRecenter}); + rows_.push_back({"Bookmarks Shortcut", btnLabel(4, bindQuickPathBtn_), + Action::ListenQuickPath}); rows_.push_back({"Select / Click", "Trigger", Action::None}); rows_.push_back({"Controller Models", drawModels_ ? "On" : "Off", Action::ToggleModels}); @@ -220,6 +235,13 @@ void SettingsMenu::refresh() { rows_.push_back({"Lock Vault Now", "[ Lock & Return Home ]", Action::LockVaultAction}); + } else if (section_ == 21) { + title_ = "Settings > List Columns"; + rows_.push_back({"Format / VR Badge", listShowFormat_ ? "Visible" : "Hidden", Action::ToggleListColFormat}); + rows_.push_back({"Resolution & FPS", listShowRes_ ? "Visible" : "Hidden", Action::ToggleListColRes}); + rows_.push_back({"File Size", listShowSize_ ? "Visible" : "Hidden", Action::ToggleListColSize}); + rows_.push_back({"Video Duration", listShowDuration_ ? "Visible" : "Hidden", Action::ToggleListColDuration}); + rows_.push_back({"< Back to UI & Appearance", "", Action::BackToUI}); } else if (section_ == 10) { title_ = "Settings > Select Video Track"; for (std::size_t i = 0; i < videoStreams_.size(); ++i) { @@ -346,6 +368,21 @@ SettingsMenu::Action SettingsMenu::activate() { saveConfig(); refresh(); break; + case Action::CycleUiFollowMode: + uiFollowMode_ = (uiFollowMode_ + 1) % 2; + saveConfig(); + refresh(); + break; + case Action::CycleBrowserViewMode: + browserViewMode_ = (browserViewMode_ + 1) % 3; + saveConfig(); + refresh(); + break; + case Action::ListenQuickPath: + listeningFunc_ = 4; + status_ = "Press a controller button for Bookmarks shortcut"; + refresh(); + break; case Action::PickVideoStream: videoSel_ = rows_[selected_].data; section_ = 2; @@ -399,6 +436,37 @@ SettingsMenu::Action SettingsMenu::activate() { section_ = 0; refresh(); break; + + case Action::EnterListColsConfig: + section_ = 21; + selected_ = 0; + refresh(); + break; + case Action::ToggleListColFormat: + listShowFormat_ = !listShowFormat_; + refresh(); + saveConfig(); + break; + case Action::ToggleListColRes: + listShowRes_ = !listShowRes_; + refresh(); + saveConfig(); + break; + case Action::ToggleListColSize: + listShowSize_ = !listShowSize_; + refresh(); + saveConfig(); + break; + case Action::ToggleListColDuration: + listShowDuration_ = !listShowDuration_; + refresh(); + saveConfig(); + break; + case Action::BackToUI: + section_ = 1; + selected_ = 0; + refresh(); + break; case Action::RecenterScreen: break; case Action::Close: @@ -448,6 +516,7 @@ void SettingsMenu::assignListening(int button) { else if (listeningFunc_ == 1) bindMenuBtn_ = b; else if (listeningFunc_ == 2) bindRecenterBtn_ = b; else if (listeningFunc_ == 3) VaultManager::instance().setMoveButton(b); + else if (listeningFunc_ == 4) bindQuickPathBtn_ = b; listeningFunc_ = -1; status_ = "Bound to " + std::string(kButtonNames[b]); saveConfig(); @@ -505,6 +574,7 @@ void SettingsMenu::loadConfig() { // so a saved grip binding is migrated to the new default (Bumper). bindRecenterBtn_ = (b == 8) ? 6 : b; } + else if (key == "bind_quick_path_btn") bindQuickPathBtn_ = std::clamp(std::stoi(val), 0, kButtonCount - 1); else if (key == "download_dir") downloadDirIdx_ = std::clamp(std::stoi(val), 0, kDownloadDirCount - 1); else if (key == "audio_lang") audioLangIdx_ = std::clamp(std::stoi(val), 0, kLangCount - 1); else if (key == "curvature") curvatureIdx_ = std::clamp(std::stoi(val), 0, kCurvatureCount - 1); @@ -512,6 +582,13 @@ void SettingsMenu::loadConfig() { else if (key == "ui_text_color") uiTextColorIdx_ = std::clamp(std::stoi(val), 0, kUiTextColorCount - 1); else if (key == "ui_accent_color") uiAccentColorIdx_ = std::clamp(std::stoi(val), 0, kUiAccentColorCount - 1); else if (key == "ui_distance") uiDistanceIdx_ = std::clamp(std::stoi(val), 0, kUiDistanceCount - 1); + else if (key == "ui_follow_mode") uiFollowMode_ = std::clamp(std::stoi(val), 0, 1); + else if (key == "browser_view_mode") browserViewMode_ = std::clamp(std::stoi(val), 0, 2); + else if (key == "list_show_format") listShowFormat_ = (val == "1" || val == "true"); + else if (key == "list_show_res") listShowRes_ = (val == "1" || val == "true"); + else if (key == "list_show_size") listShowSize_ = (val == "1" || val == "true"); + else if (key == "list_show_dur") listShowDuration_ = (val == "1" || val == "true"); + else if (key == "quick_path") quickPath_ = val; } PIXELVR_LOG_INFO("Loaded settings from %s", path.c_str()); } @@ -534,6 +611,7 @@ void SettingsMenu::saveConfig() const { file << "bind_play_btn=" << bindPlayBtn_ << "\n"; file << "bind_menu_btn=" << bindMenuBtn_ << "\n"; file << "bind_recenter_btn=" << bindRecenterBtn_ << "\n"; + file << "bind_quick_path_btn=" << bindQuickPathBtn_ << "\n"; file << "download_dir=" << downloadDirIdx_ << "\n"; file << "audio_lang=" << audioLangIdx_ << "\n"; file << "curvature=" << curvatureIdx_ << "\n"; @@ -541,6 +619,15 @@ void SettingsMenu::saveConfig() const { file << "ui_text_color=" << uiTextColorIdx_ << "\n"; file << "ui_accent_color=" << uiAccentColorIdx_ << "\n"; file << "ui_distance=" << uiDistanceIdx_ << "\n"; + file << "ui_follow_mode=" << uiFollowMode_ << "\n"; + file << "browser_view_mode=" << browserViewMode_ << "\n"; + file << "list_show_format=" << (listShowFormat_ ? 1 : 0) << "\n"; + file << "list_show_res=" << (listShowRes_ ? 1 : 0) << "\n"; + file << "list_show_size=" << (listShowSize_ ? 1 : 0) << "\n"; + file << "list_show_dur=" << (listShowDuration_ ? 1 : 0) << "\n"; + if (!quickPath_.empty()) { + file << "quick_path=" << quickPath_ << "\n"; + } } } catch (const std::exception& e) { PIXELVR_LOG_WARN("Could not save settings: %s", e.what()); diff --git a/src/ui/settings_menu.hpp b/src/ui/settings_menu.hpp index 144cc78..aed4939 100644 --- a/src/ui/settings_menu.hpp +++ b/src/ui/settings_menu.hpp @@ -30,6 +30,9 @@ public: CycleUiTextColor, CycleUiAccentColor, CycleUiDistance, + CycleUiFollowMode, + CycleBrowserViewMode, + ListenQuickPath, EnterVideoList, EnterAudioList, EnterLangList, @@ -42,6 +45,12 @@ public: ListenVaultMoveBtn, RecordVaultCombo, LockVaultAction, + EnterListColsConfig, + ToggleListColFormat, + ToggleListColRes, + ToggleListColSize, + ToggleListColDuration, + BackToUI, Close }; @@ -95,6 +104,13 @@ public: int uiTextColorIdx() const { return uiTextColorIdx_; } int uiAccentColorIdx() const { return uiAccentColorIdx_; } float uiDistance() const; + int uiFollowMode() const { return uiFollowMode_; } + void setUiFollowMode(int m) { uiFollowMode_ = m; saveConfig(); refresh(); } + int browserViewMode() const { return browserViewMode_; } + void setBrowserViewMode(int m) { browserViewMode_ = m; saveConfig(); refresh(); } + int bindQuickPath() const { return bindQuickPathBtn_; } + const std::string& quickPath() const { return quickPath_; } + void setQuickPath(const std::string& p) { quickPath_ = p; saveConfig(); } int section() const { return section_; } void setSection(int s) { @@ -115,6 +131,14 @@ public: void loadConfig(); void saveConfig() const; + bool listShowFormat() const { return listShowFormat_; } + bool listShowRes() const { return listShowRes_; } + bool listShowSize() const { return listShowSize_; } + bool listShowDuration() const { return listShowDuration_; } + + void onKeyboardSubmit(const std::string& text) { (void)text; } + void onKeyboardCancel() {} + private: bool open_ = false; std::string title_ = "Settings & Controller Remap"; @@ -133,15 +157,23 @@ private: int bindPlayBtn_ = 0; // default A int bindMenuBtn_ = 1; // default B int bindRecenterBtn_ = 6; // default Bumper (grip toggles the laser) - int listeningFunc_ = -1; // 0=play 1=menu 2=recenter while binding, else -1 + int bindQuickPathBtn_ = 7; // default Right Stick Click (BtnThumbR) + int listeningFunc_ = -1; // 0=play 1=menu 2=recenter 3=move 4=quick path int downloadDirIdx_ = 0; // index into the download-destination presets int curvatureIdx_ = 0; // 0=Flat (0%), 1=Gentle (25%), 2=Cinema (50%), 3=Deep (75%), 4=IMAX (100%) int uiTextScaleIdx_ = 2; // 0=90%, 1=105%, 2=120% (default), 3=140%, 4=160% int uiTextColorIdx_ = 0; // 0=Pure White, 1=Ice Cyan, 2=Warm Cream, 3=Soft Gold, 4=Mint Green int uiAccentColorIdx_ = 0; // 0=Cyber Cyan, 1=Emerald, 2=Amber Gold, 3=Royal Purple, 4=Crimson int uiDistanceIdx_ = 1; // 0=Near (1.5m), 1=Comfort (1.9m), 2=Mid (2.3m), 3=Far (2.8m) + int uiFollowMode_ = 0; // 0=World Lock (default, zero drift/tilt), 1=Smooth Gaze Follow + int browserViewMode_ = 0; // 0=Large Cards (3x2), 1=Smaller Cards (4x3), 2=Compact List (1-Col) + bool listShowFormat_ = true; + bool listShowRes_ = true; + bool listShowSize_ = true; + bool listShowDuration_ = true; + std::string quickPath_; - int section_ = 0; // 0=Display, 1=Controls, 2=Streams, 3=System; 10..12=sub-lists + int section_ = 0; // 0=Display, 1=UI, 2=Audio, 3=Controls, 4=Vault; 10..12=sub-lists std::vector> videoStreams_; // (index, label) std::vector> audioStreams_; int videoSel_ = 0; // position within videoStreams_ diff --git a/src/util/ipv4.hpp b/src/util/ipv4.hpp new file mode 100644 index 0000000..b55162f --- /dev/null +++ b/src/util/ipv4.hpp @@ -0,0 +1,107 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace pixelvr { + +// Validates whether a string is a complete, strictly valid IPv4 address (e.g. "192.168.1.1"). +inline bool isValidIpv4(const std::string& str) { + if (str.empty()) return false; + std::stringstream ss(str); + std::string seg; + int count = 0; + while (std::getline(ss, seg, '.')) { + ++count; + if (seg.empty() || seg.length() > 3) return false; + for (char c : seg) { + if (!std::isdigit(static_cast(c))) return false; + } + // Leading zeros not allowed if more than 1 digit (e.g. "01" is invalid, "0" is valid) + if (seg.length() > 1 && seg[0] == '0') return false; + try { + int val = std::stoi(seg); + if (val < 0 || val > 255) return false; + } catch (...) { + return false; + } + } + // Must have exactly 4 octets and not end with a trailing dot + return (count == 4 && str.back() != '.'); +} + +// Sanitizes and formats an in-progress or finalized IPv4 input: +// - Only digits '0'..'9' and '.' are accepted; any other characters are discarded. +// - At most 4 sections (octets). +// - Each section has leading zeros dropped (e.g. "001" -> "1", "050" -> "50", "00" -> "0"). +// - Each section is clamped to max 255. +// - If !finalized, a trailing dot is preserved while typing (e.g. "192.168."). +// - If finalized, any trailing dot is trimmed and empty trailing sections are removed. +inline std::string sanitizeIpv4(const std::string& input, bool finalized = false) { + if (input.empty()) return ""; + + std::vector sections; + std::string current; + bool trailingDot = false; + + for (char c : input) { + if (c == '.') { + if (!current.empty() && sections.size() < 4) { + sections.push_back(current); + current.clear(); + trailingDot = true; + } + } else if (std::isdigit(static_cast(c))) { + if (sections.size() >= 4) { + continue; + } + if (current.length() < 3) { + current += c; + trailingDot = false; + } + } + } + if (!current.empty() && sections.size() < 4) { + sections.push_back(current); + trailingDot = false; + } + + if (sections.empty() && !trailingDot) return ""; + + std::string result; + for (std::size_t i = 0; i < sections.size(); ++i) { + std::string s = sections[i]; + if (!s.empty()) { + while (s.length() > 1 && s[0] == '0') { + s.erase(s.begin()); + } + try { + int val = std::stoi(s); + if (val > 255) val = 255; + s = std::to_string(val); + } catch (...) { + s = "255"; + } + } + + if (i > 0) result += '.'; + result += s; + } + + if (!finalized && trailingDot && sections.size() < 4 && !result.empty()) { + result += '.'; + } + + if (finalized) { + while (!result.empty() && result.back() == '.') { + result.pop_back(); + } + } + + return result; +} + +} // namespace pixelvr diff --git a/src/xr/vr_keyboard.cpp b/src/xr/vr_keyboard.cpp new file mode 100644 index 0000000..3b20ef7 --- /dev/null +++ b/src/xr/vr_keyboard.cpp @@ -0,0 +1,384 @@ +#include "vr_keyboard.hpp" +#include "util/logging.hpp" +#include + +#if defined(__linux__) || defined(__APPLE__) +#include +#else +#include +#endif + +#include "openvr.h" + +namespace pixelvr { + +namespace { + +typedef intptr_t (*Fn_VR_InitInternal)(vr::EVRInitError*, vr::EVRApplicationType); +typedef void (*Fn_VR_ShutdownInternal)(); +typedef intptr_t (*Fn_VR_GetGenericInterface)(const char*, vr::EVRInitError*); + +Fn_VR_InitInternal g_VR_InitInternal = nullptr; +Fn_VR_ShutdownInternal g_VR_ShutdownInternal = nullptr; +Fn_VR_GetGenericInterface g_VR_GetGenericInterface = nullptr; + +} // namespace + +VrKeyboard& VrKeyboard::instance() { + static VrKeyboard sInstance; + return sInstance; +} + +VrKeyboard::~VrKeyboard() { + shutdown(); +} + +bool VrKeyboard::init() { + if (available_) return true; + +#if defined(__linux__) + const char* paths[] = { + "/opt/steamvr/bin/linuxarm64/libopenvr_api.so", + "/opt/steamvr/bin/linux64/libopenvr_api.so", + "libopenvr_api.so" + }; + for (const char* path : paths) { + libHandle_ = dlopen(path, RTLD_NOW | RTLD_LOCAL); + if (libHandle_) { + PIXELVR_LOG_INFO("VrKeyboard: Loaded %s", path); + break; + } + } + if (!libHandle_) { + PIXELVR_LOG_WARN("VrKeyboard: Could not find or load libopenvr_api.so: %s", dlerror()); + return false; + } + + g_VR_InitInternal = reinterpret_cast(dlsym(libHandle_, "VR_InitInternal")); + g_VR_ShutdownInternal = reinterpret_cast(dlsym(libHandle_, "VR_ShutdownInternal")); + g_VR_GetGenericInterface = reinterpret_cast(dlsym(libHandle_, "VR_GetGenericInterface")); +#elif defined(_WIN32) + HMODULE hMod = LoadLibraryA("openvr_api.dll"); + if (!hMod) { + return false; + } + libHandle_ = hMod; + g_VR_InitInternal = reinterpret_cast(GetProcAddress(hMod, "VR_InitInternal")); + g_VR_ShutdownInternal = reinterpret_cast(GetProcAddress(hMod, "VR_ShutdownInternal")); + g_VR_GetGenericInterface = reinterpret_cast(GetProcAddress(hMod, "VR_GetGenericInterface")); +#else + return false; +#endif + + if (!g_VR_InitInternal || !g_VR_ShutdownInternal || !g_VR_GetGenericInterface) { + PIXELVR_LOG_WARN("VrKeyboard: OpenVR symbols not resolved"); + shutdown(); + return false; + } + + vr::EVRInitError err = vr::VRInitError_None; + uint32_t token = static_cast(g_VR_InitInternal(&err, vr::VRApplication_Overlay)); + if (token == 0 || err != vr::VRInitError_None) { + PIXELVR_LOG_WARN("VrKeyboard: OpenVR overlay init returned %d", static_cast(err)); + shutdown(); + return false; + } + + vr::IVRSystem* sys = reinterpret_cast( + g_VR_GetGenericInterface(vr::IVRSystem_Version, &err)); + if (!sys || err != vr::VRInitError_None) { + PIXELVR_LOG_WARN("VrKeyboard: Failed to get IVRSystem interface %s (err=%d)", + vr::IVRSystem_Version, static_cast(err)); + shutdown(); + return false; + } + + vr::IVROverlay* ov = reinterpret_cast( + g_VR_GetGenericInterface(vr::IVROverlay_Version, &err)); + if (!ov || err != vr::VRInitError_None) { + PIXELVR_LOG_WARN("VrKeyboard: Failed to get IVROverlay interface %s (err=%d)", + vr::IVROverlay_Version, static_cast(err)); + shutdown(); + return false; + } + + vrSystem_ = sys; + vrOverlay_ = ov; + available_ = true; + + // Create a persistent input overlay so ShowKeyboardForOverlay can link + // tracked controller pointer interactions directly to SteamVR's virtual keyboard. + vr::VROverlayHandle_t hOverlay = vr::k_ulOverlayHandleInvalid; + vr::EVROverlayError ovErr = ov->CreateOverlay("pixelvr.input_overlay", "PixelVR Input", &hOverlay); + if (ovErr == vr::VROverlayError_None && hOverlay != vr::k_ulOverlayHandleInvalid) { + inputOverlay_ = hOverlay; + ov->SetOverlayInputMethod(hOverlay, vr::VROverlayInputMethod_Mouse); + ov->SetOverlayFlag(hOverlay, vr::VROverlayFlags_MakeOverlaysInteractiveIfVisible, true); + PIXELVR_LOG_INFO("VrKeyboard: Created input overlay %llu with Mouse input method and MakeOverlaysInteractiveIfVisible", + static_cast(inputOverlay_)); + } else { + PIXELVR_LOG_WARN("VrKeyboard: Could not create input overlay (err=%d)", static_cast(ovErr)); + } + + PIXELVR_LOG_INFO("VrKeyboard: Successfully initialized SteamVR overlay interface (sys=%p, ov=%p)", + reinterpret_cast(sys), reinterpret_cast(ov)); + return true; +} + +void VrKeyboard::shutdown() { + if (isOpen_) { + hide(); + } + if (inputOverlay_ != 0 && vrOverlay_) { + auto* ov = reinterpret_cast(vrOverlay_); + ov->DestroyOverlay(inputOverlay_); + inputOverlay_ = 0; + } + if (g_VR_ShutdownInternal) { + g_VR_ShutdownInternal(); + } + vrSystem_ = nullptr; + vrOverlay_ = nullptr; + if (libHandle_) { +#if defined(__linux__) || defined(__APPLE__) + dlclose(libHandle_); +#elif defined(_WIN32) + FreeLibrary(reinterpret_cast(libHandle_)); +#endif + libHandle_ = nullptr; + } + g_VR_InitInternal = nullptr; + g_VR_ShutdownInternal = nullptr; + g_VR_GetGenericInterface = nullptr; + available_ = false; + isOpen_ = false; + doneSubmitted_ = false; +} + +bool VrKeyboard::show(const std::string& description, + const std::string& existingText, + bool isPassword, + int maxChars) { + if (!available_ && !init()) { + return false; + } + auto* ov = reinterpret_cast(vrOverlay_); + if (!ov) return false; + + description_ = description; + existingText_ = existingText; + currentText_ = existingText; + isPassword_ = isPassword; + doneSubmitted_ = false; + + const vr::EGamepadTextInputMode mode = isPassword + ? vr::k_EGamepadTextInputModePassword + : vr::k_EGamepadTextInputModeNormal; + + vr::EVROverlayError err = vr::VROverlayError_None; + if (inputOverlay_ != 0) { + ov->SetOverlayInputMethod(inputOverlay_, vr::VROverlayInputMethod_Mouse); + ov->SetOverlayFlag(inputOverlay_, vr::VROverlayFlags_MakeOverlaysInteractiveIfVisible, true); + ov->SetOverlayWidthInMeters(inputOverlay_, 1.0f); + + // Position overlay 1.1m in front of HMD, tilted slightly down/up to match comfortable view + vr::HmdMatrix34_t mat = { + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, -0.2f, + 0.0f, 0.0f, 1.0f, -1.1f + }; + ov->SetOverlayTransformTrackedDeviceRelative(inputOverlay_, vr::k_unTrackedDeviceIndex_Hmd, &mat); + + // Transparent 1x1 pixel texture so overlay is valid and active without rendering visual artifacts + static const uint32_t s_transparentPixel = 0x00000000; + ov->SetOverlayRaw(inputOverlay_, const_cast(&s_transparentPixel), 1, 1, 4); + + // Tell keyboard to avoid overlay upper area and appear cleanly docked + vr::HmdRect2_t avoidRect = { + { 0.0f, 0.0f }, + { 1.0f, 0.2f } + }; + ov->SetKeyboardPositionForOverlay(inputOverlay_, avoidRect); + + // Show overlay BEFORE opening keyboard so vrcompositor recognizes active interactive overlay + ov->ShowOverlay(inputOverlay_); + + err = ov->ShowKeyboardForOverlay( + inputOverlay_, + mode, + vr::k_EGamepadTextInputLineModeSingleLine, + vr::KeyboardFlag_Modal, + description.c_str(), + static_cast(maxChars), + existingText.c_str(), + 0); + } else { + err = ov->ShowKeyboard( + mode, + vr::k_EGamepadTextInputLineModeSingleLine, + vr::KeyboardFlag_Modal, + description.c_str(), + static_cast(maxChars), + existingText.c_str(), + 0); + } + + if (err != vr::VROverlayError_None) { + PIXELVR_LOG_WARN("VrKeyboard: ShowKeyboard failed with error %d", static_cast(err)); + if (inputOverlay_ != 0) { + ov->HideOverlay(inputOverlay_); + } + return false; + } + + kbConfigured_ = false; + // Attempt early configuration of keyboard overlays if already created + const char* kbOverlayNames[] = { + "valve.steam.gamepadui.keyboard", + "system.keyboard" + }; + for (const char* name : kbOverlayNames) { + vr::VROverlayHandle_t hKb = vr::k_ulOverlayHandleInvalid; + if (ov->FindOverlay(name, &hKb) == vr::VROverlayError_None && hKb != vr::k_ulOverlayHandleInvalid) { + ov->SetOverlayFlag(hKb, vr::VROverlayFlags_MakeOverlaysInteractiveIfVisible, true); + ov->SetOverlayInputMethod(hKb, vr::VROverlayInputMethod_Mouse); + kbConfigured_ = true; + PIXELVR_LOG_INFO("VrKeyboard: Configured interactive laser mouse for overlay '%s'", name); + } + } + + isOpen_ = true; + PIXELVR_LOG_INFO("VrKeyboard: Shown virtual keyboard for '%s' (initial text: '%s')", + description.c_str(), existingText.c_str()); + return true; +} + +void VrKeyboard::hide() { + if (!isOpen_) return; + auto* ov = reinterpret_cast(vrOverlay_); + if (ov) { + ov->HideKeyboard(); + if (inputOverlay_ != 0) { + ov->HideOverlay(inputOverlay_); + } + } + isOpen_ = false; + kbConfigured_ = false; + doneSubmitted_ = false; + PIXELVR_LOG_INFO("VrKeyboard: Hidden virtual keyboard"); +} + +void VrKeyboard::poll(std::function onDone, + std::function onCancel) { + if (!available_ || !isOpen_) return; + auto* sys = reinterpret_cast(vrSystem_); + auto* ov = reinterpret_cast(vrOverlay_); + if (!sys || !ov) return; + + vr::VREvent_t event{}; + while (sys->PollNextEvent(&event, sizeof(event))) { + if (event.eventType == vr::VREvent_KeyboardCharInput) { + char keyBuf[1024] = {0}; + uint32_t len = ov->GetKeyboardText(keyBuf, sizeof(keyBuf)); + if (len > 0) { + currentText_ = std::string(keyBuf, len < sizeof(keyBuf) ? len : std::strlen(keyBuf)); + } else { + // Fallback: check event.data.keyboard.cNewInput + const char* inStr = event.data.keyboard.cNewInput; + if (inStr && inStr[0] != 0) { + const unsigned char firstByte = static_cast(inStr[0]); + if (firstByte == '\b' || firstByte == 0x7F || firstByte == 8) { + while (!currentText_.empty() && (static_cast(currentText_.back()) & 0xC0) == 0x80) { + currentText_.pop_back(); + } + if (!currentText_.empty()) { + currentText_.pop_back(); + } + } else if (firstByte >= 32) { + currentText_ += inStr; + } + } + } + PIXELVR_LOG_INFO("VrKeyboard: CharInput live text: '%s'", currentText_.c_str()); + } else if (event.eventType == vr::VREvent_KeyboardDone) { + isOpen_ = false; + kbConfigured_ = false; + if (inputOverlay_ != 0 && ov) { + ov->HideOverlay(inputOverlay_); + } + doneSubmitted_ = true; + char buf[1024] = {0}; + uint32_t len = ov->GetKeyboardText(buf, sizeof(buf)); + std::string text = currentText_; + if (len > 0) { + text = std::string(buf, len < sizeof(buf) ? len : std::strlen(buf)); + } + PIXELVR_LOG_INFO("VrKeyboard: User submitted text via KeyboardDone: '%s'", text.c_str()); + if (onDone) { + onDone(text); + } + } else if (event.eventType == vr::VREvent_KeyboardClosed || + event.eventType == vr::VREvent_KeyboardClosed_Global) { + isOpen_ = false; + kbConfigured_ = false; + if (inputOverlay_ != 0 && ov) { + ov->HideOverlay(inputOverlay_); + } + PIXELVR_LOG_INFO("VrKeyboard: Keyboard closed (doneSubmitted=%d)", doneSubmitted_ ? 1 : 0); + if (!doneSubmitted_) { + // On Steam Frame / SteamOS, pressing the checkmark or closing the keyboard issues KeyboardClosed + // without KeyboardDone. Read the buffer and treat non-empty / modified input as submit! + char buf[1024] = {0}; + uint32_t len = ov->GetKeyboardText(buf, sizeof(buf)); + std::string text = currentText_; + if (len > 0) { + text = std::string(buf, len < sizeof(buf) ? len : std::strlen(buf)); + } + if (!text.empty() || text != existingText_) { + PIXELVR_LOG_INFO("VrKeyboard: Treating KeyboardClosed as submit with text: '%s'", text.c_str()); + doneSubmitted_ = true; + if (onDone) { + onDone(text); + } + } else { + PIXELVR_LOG_INFO("VrKeyboard: Keyboard cancelled without text change"); + if (onCancel) { + onCancel(); + } + } + } + } + } + + // Keep currentText_ synchronized with the live SteamVR keyboard buffer every frame + if (isOpen_) { + // Dynamically ensure SteamVR keyboard overlay has laser mouse flags as soon as spawned + if (!kbConfigured_) { + const char* kbOverlayNames[] = { + "valve.steam.gamepadui.keyboard", + "system.keyboard" + }; + for (const char* name : kbOverlayNames) { + vr::VROverlayHandle_t hKb = vr::k_ulOverlayHandleInvalid; + if (ov->FindOverlay(name, &hKb) == vr::VROverlayError_None && hKb != vr::k_ulOverlayHandleInvalid) { + ov->SetOverlayFlag(hKb, vr::VROverlayFlags_MakeOverlaysInteractiveIfVisible, true); + ov->SetOverlayInputMethod(hKb, vr::VROverlayInputMethod_Mouse); + kbConfigured_ = true; + PIXELVR_LOG_INFO("VrKeyboard: Configured interactive laser mouse for overlay '%s'", name); + } + } + } + + char liveBuf[1024] = {0}; + uint32_t liveLen = ov->GetKeyboardText(liveBuf, sizeof(liveBuf)); + if (liveLen > 0) { + currentText_ = std::string(liveBuf, liveLen < sizeof(liveBuf) ? liveLen : std::strlen(liveBuf)); + } + } +} + +std::string VrKeyboard::currentText() const { + return currentText_; +} + +} // namespace pixelvr diff --git a/src/xr/vr_keyboard.hpp b/src/xr/vr_keyboard.hpp new file mode 100644 index 0000000..b72f7e8 --- /dev/null +++ b/src/xr/vr_keyboard.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include +#include +#include + +namespace pixelvr { + +class VrKeyboard { +public: + static VrKeyboard& instance(); + + // Initializes OpenVR overlay interface dynamically if SteamVR is running. + bool init(); + void shutdown(); + + bool isAvailable() const { return available_; } + bool isOpen() const { return isOpen_; } + + // Opens the native SteamVR / SteamOS VR on-screen virtual keyboard. + // e.g. description: "Enter SMB Server IP", existingText: "192.168.1.100", isPassword: false + bool show(const std::string& description, + const std::string& existingText, + bool isPassword = false, + int maxChars = 256); + + // Closes the virtual keyboard if open. + void hide(); + + // Call once per frame in the main event loop to poll OpenVR keyboard events. + void poll(std::function onDone, + std::function onCancel); + + // Retrieves current entered buffer + std::string currentText() const; + const std::string& description() const { return description_; } + bool isPassword() const { return isPassword_; } + +private: + VrKeyboard() = default; + ~VrKeyboard(); + + bool available_ = false; + bool isOpen_ = false; + bool doneSubmitted_ = false; + bool kbConfigured_ = false; + std::string description_; + std::string existingText_; + std::string currentText_; + bool isPassword_ = false; + void* libHandle_ = nullptr; + void* vrSystem_ = nullptr; + void* vrOverlay_ = nullptr; + uint64_t inputOverlay_ = 0; +}; + +} // namespace pixelvr diff --git a/src/xr/xr_context.cpp b/src/xr/xr_context.cpp index 5d8afc8..a594f14 100644 --- a/src/xr/xr_context.cpp +++ b/src/xr/xr_context.cpp @@ -1,6 +1,7 @@ #include "xr/xr_context.hpp" #include "xr/xr_result.hpp" +#include "xr/vr_keyboard.hpp" #include "util/logging.hpp" #include @@ -637,6 +638,22 @@ void XrContext::syncActions() { return; } + if (!sessionFocused()) { + // Yield controller input and clear all held inputs when the session does not have focus (e.g. Steam dashboard). + input_.selectHeld = false; + input_.thumbstickX = 0.0f; + input_.thumbstickY = 0.0f; + input_.thumbstickLX = 0.0f; + input_.thumbstickLY = 0.0f; + input_.thumbstickRX = 0.0f; + input_.thumbstickRY = 0.0f; + for (int h = 0; h < 2; ++h) { + input_.gripValue[h] = 0.0f; + input_.gripFullPressHeld[h] = false; + } + return; + } + XrActiveActionSet active{actionSet_, XR_NULL_PATH}; XrActionsSyncInfo sync{XR_TYPE_ACTIONS_SYNC_INFO}; sync.countActiveActionSets = 1; @@ -908,7 +925,8 @@ bool XrContext::renderFrame(const RenderViewFn& renderView) { // Locate each controller's aim pose (for the pointer rays and models). for (int h = 0; h < 2; ++h) { input_.controllers[h].active = false; - if (aimSpaces_[h] == XR_NULL_HANDLE) { + const bool canTrack = sessionFocused() || VrKeyboard::instance().isOpen(); + if (!canTrack || aimSpaces_[h] == XR_NULL_HANDLE) { continue; } XrSpaceLocation loc{XR_TYPE_SPACE_LOCATION}; @@ -936,7 +954,8 @@ bool XrContext::renderFrame(const RenderViewFn& renderView) { // the model is authored around the grip, not the forward-pointing aim). for (int h = 0; h < 2; ++h) { input_.controllers[h].gripActive = false; - if (gripSpaces_[h] == XR_NULL_HANDLE) { + const bool canTrack = sessionFocused() || VrKeyboard::instance().isOpen(); + if (!canTrack || gripSpaces_[h] == XR_NULL_HANDLE) { continue; } XrSpaceLocation loc{XR_TYPE_SPACE_LOCATION}; diff --git a/tests/test_ipv4.cpp b/tests/test_ipv4.cpp new file mode 100644 index 0000000..5a6bbc5 --- /dev/null +++ b/tests/test_ipv4.cpp @@ -0,0 +1,36 @@ +#include "util/ipv4.hpp" +#include +#include + +using namespace pixelvr; + +int main() { + std::cout << "[TEST] Starting IPv4 sanitization & validation test..." << std::endl; + + // Normal valid IP + assert(sanitizeIpv4("192.168.1.1", true) == "192.168.1.1"); + assert(isValidIpv4("192.168.1.1")); + + // Leading zeros dropped in each section + assert(sanitizeIpv4("192.168.01.005", true) == "192.168.1.5"); + assert(sanitizeIpv4("010.000.001.020", true) == "10.0.1.20"); + assert(sanitizeIpv4("0.0.0.0", true) == "0.0.0.0"); + + // Clamping > 255 + assert(sanitizeIpv4("192.168.1.300", true) == "192.168.1.255"); + assert(sanitizeIpv4("999.999.999.999", true) == "255.255.255.255"); + + // Live typing with trailing dot + assert(sanitizeIpv4("192.168.", false) == "192.168."); + assert(sanitizeIpv4("192.168.", true) == "192.168"); + + // Non-digit characters discarded + assert(sanitizeIpv4("192.abc.168.foo.1.bar.100", true) == "192.168.1.100"); + assert(sanitizeIpv4(" 10 . 0 . 0 . 1 ", true) == "10.0.0.1"); + + // Max 4 sections (extra sections ignored) + assert(sanitizeIpv4("192.168.1.1.99.88", true) == "192.168.1.1"); + + std::cout << "[ALL TESTS PASSED] IPv4 sanitization is verified!" << std::endl; + return 0; +} diff --git a/tests/test_smb_creds.cpp b/tests/test_smb_creds.cpp new file mode 100644 index 0000000..098ba89 --- /dev/null +++ b/tests/test_smb_creds.cpp @@ -0,0 +1,71 @@ +#include "net/smb_credentials.hpp" +#include +#include +#include +#include +#include + +using namespace pixelvr; +namespace fs = std::filesystem; + +int main() { + std::cout << "[TEST] Starting SmbCredentialsManager verification..." << std::endl; + auto& mgr = SmbCredentialsManager::instance(); + + // 1. Add a protected share + SmbShare share1; + share1.id = "192.168.1.100/movies"; + share1.name = "Living Room NAS"; + share1.host = "192.168.1.100"; + share1.share = "movies"; + share1.workgroup = "MYGROUP"; + share1.username = "nasadmin"; + share1.password = "SuperSecretPassword123!"; + share1.anonymous = false; + + mgr.addOrUpdateShare(share1); + std::cout << "[PASS] Added protected share." << std::endl; + + // 2. Query credentials + std::string user, pass, wg; + bool found = mgr.findCredentials("192.168.1.100", "movies", user, pass, wg); + assert(found); + assert(user == "nasadmin"); + assert(pass == "SuperSecretPassword123!"); + assert(wg == "MYGROUP"); + std::cout << "[PASS] Retrieved exact credentials." << std::endl; + + // 3. Check storage file permissions (must be 0600) + const char* home = std::getenv("HOME"); + std::string configPath = std::string(home ? home : ".") + "/.config/pixelvr/smb_shares.json"; + struct stat st; + assert(stat(configPath.c_str(), &st) == 0); + mode_t perm = st.st_mode & 0777; + std::cout << "[INFO] File permissions: 0" << std::oct << perm << std::dec << std::endl; + assert((perm & 0077) == 0); // No permissions for group or others + std::cout << "[PASS] Config file has strict 0600 permissions." << std::endl; + + // 4. Verify password is encrypted on disk + std::ifstream cfgFile(configPath); + std::string content((std::istreambuf_iterator(cfgFile)), std::istreambuf_iterator()); + assert(content.find("SuperSecretPassword123!") == std::string::npos); + std::cout << "[PASS] Password is encrypted on disk (no plaintext leak)." << std::endl; + + // 5. Test auth file generation + std::string authPath = mgr.getAuthFilePath("192.168.1.100", "movies"); + assert(!authPath.empty()); + assert(stat(authPath.c_str(), &st) == 0); + mode_t authPerm = st.st_mode & 0777; + assert((authPerm & 0077) == 0); // Auth file must also be 0600 + std::cout << "[PASS] Temporary Samba auth file generated with 0600 permissions." << std::endl; + + // 6. Delete share + bool deleted = mgr.deleteShare("192.168.1.100", "movies"); + assert(deleted); + found = mgr.findCredentials("192.168.1.100", "movies", user, pass, wg); + assert(!found); + std::cout << "[PASS] Deleted share successfully." << std::endl; + + std::cout << "[ALL TESTS PASSED] SmbCredentialsManager is verified and secure!" << std::endl; + return 0; +} diff --git a/third_party/openvr/openvr.h b/third_party/openvr/openvr.h new file mode 100644 index 0000000..a64cd10 --- /dev/null +++ b/third_party/openvr/openvr.h @@ -0,0 +1,5773 @@ +#pragma once + +// openvr.h +//========= Copyright Valve Corporation ============// +// Dynamically generated file. Do not modify this file directly. + +#ifndef _OPENVR_API +#define _OPENVR_API + +#include + + + +// version.h + +namespace vr +{ + static const uint32_t k_nSteamVRVersionMajor = 2; + static const uint32_t k_nSteamVRVersionMinor = 1; + static const uint32_t k_nSteamVRVersionBuild = 0; +} // namespace vr + +// public_vrtypes.h + +#ifndef _INCLUDE_CORE_VRTYPES_PUBLIC_H +#define _INCLUDE_CORE_VRTYPES_PUBLIC_H + +namespace vr +{ +#pragma pack( push, 8 ) + +typedef uint32_t PropertyTypeTag_t; + +// right-handed system +// +y is up +// +x is to the right +// -z is forward +// Distance unit is meters +struct HmdMatrix34_t +{ + float m[3][4]; +}; + +struct HmdMatrix33_t +{ + float m[3][3]; +}; + +struct HmdMatrix44_t +{ + float m[4][4]; +}; + +struct HmdVector3_t +{ + float v[3]; +}; + +struct HmdVector4_t +{ + float v[4]; +}; + +struct HmdVector3d_t +{ + double v[3]; +}; + +struct HmdVector2_t +{ + float v[2]; +}; + +struct HmdQuaternion_t +{ + double w, x, y, z; +}; + +struct HmdQuaternionf_t +{ + float w, x, y, z; +}; + +struct HmdColor_t +{ + float r, g, b, a; +}; + +struct HmdQuad_t +{ + HmdVector3_t vCorners[ 4 ]; +}; + +struct HmdRect2_t +{ + HmdVector2_t vTopLeft; + HmdVector2_t vBottomRight; +}; + +/** Holds the transform for a single bone */ +struct VRBoneTransform_t +{ + HmdVector4_t position; + HmdQuaternionf_t orientation; +}; + +/** Used to return the post-distortion UVs for each color channel. +* UVs range from 0 to 1 with 0,0 in the upper left corner of the +* source render target. The 0,0 to 1,1 range covers a single eye. */ +struct DistortionCoordinates_t +{ + float rfRed[2]; + float rfGreen[2]; + float rfBlue[2]; +}; + +enum EVREye +{ + Eye_Left = 0, + Eye_Right = 1 +}; + +enum ETextureType +{ + TextureType_Invalid = -1, // Handle has been invalidated + TextureType_DirectX = 0, // Handle is an ID3D11Texture + TextureType_OpenGL = 1, // Handle is an OpenGL texture name or an OpenGL render buffer name, depending on submit flags + TextureType_Vulkan = 2, // Handle is a pointer to a VRVulkanTextureData_t structure + TextureType_IOSurface = 3, // Handle is a macOS cross-process-sharable IOSurfaceRef, deprecated in favor of TextureType_Metal on supported platforms + TextureType_DirectX12 = 4, // Handle is a pointer to a D3D12TextureData_t structure + TextureType_DXGISharedHandle = 5, // Handle is a HANDLE DXGI share handle, only supported for Overlay render targets. + // this texture is used directly by our renderer, so only perform atomic (copyresource or resolve) on it + TextureType_Metal = 6, // Handle is a MTLTexture conforming to the MTLSharedTexture protocol. Textures submitted to IVRCompositor::Submit which + // are of type MTLTextureType2DArray assume layer 0 is the left eye texture (vr::EVREye::Eye_left), layer 1 is the right + // eye texture (vr::EVREye::Eye_Right) +}; + +enum EColorSpace +{ + ColorSpace_Auto = 0, // Assumes 'gamma' for 8-bit per component formats, otherwise 'linear'. This mirrors the DXGI formats which have _SRGB variants. + ColorSpace_Gamma = 1, // Texture data can be displayed directly on the display without any conversion (a.k.a. display native format). + ColorSpace_Linear = 2, // Same as gamma but has been converted to a linear representation using DXGI's sRGB conversion algorithm. +}; + +struct Texture_t +{ + void* handle; // See ETextureType definition above + ETextureType eType; + EColorSpace eColorSpace; +}; + +/** Allows the application to control what part of the provided texture will be used in the +* frame buffer. */ +struct VRTextureBounds_t +{ + float uMin, vMin; + float uMax, vMax; +}; + +/** Allows specifying pose used to render provided scene texture (if different from value returned by WaitGetPoses). */ +struct VRTextureWithPose_t : public Texture_t +{ + HmdMatrix34_t mDeviceToAbsoluteTracking; // Actual pose used to render scene textures. +}; + +struct VRTextureDepthInfo_t +{ + void* handle; // See ETextureType definition above + HmdMatrix44_t mProjection; + HmdVector2_t vRange; // 0..1 +}; + +struct VRTextureWithDepth_t : public Texture_t +{ + VRTextureDepthInfo_t depth; +}; + +struct VRTextureWithPoseAndDepth_t : public VRTextureWithPose_t +{ + VRTextureDepthInfo_t depth; +}; + +// 64-bit types that are part of public structures +// that are replicated in shared memory. +#if defined(__linux__) || defined(__APPLE__) +typedef uint64_t vrshared_uint64_t __attribute__ ((aligned(8))); +typedef double vrshared_double __attribute__ ((aligned(8))); +#else +typedef uint64_t vrshared_uint64_t; +typedef double vrshared_double; +#endif + +#pragma pack( pop ) + +} // namespace vr + +#endif + +// vrtypes.h + +#ifndef _INCLUDE_VRTYPES_H +#define _INCLUDE_VRTYPES_H + +// Forward declarations to avoid requiring vulkan.h +struct VkDevice_T; +struct VkPhysicalDevice_T; +struct VkInstance_T; +struct VkQueue_T; + +// Forward declarations to avoid requiring d3d12.h +struct ID3D12Resource; +struct ID3D12CommandQueue; + +namespace vr +{ +#pragma pack( push, 8 ) + +/** A handle for a spatial anchor. This handle is only valid during the session it was created in. +* Anchors that live beyond one session should be saved by their string descriptors. */ +typedef uint32_t SpatialAnchorHandle_t; + +typedef void* glSharedTextureHandle_t; +typedef int32_t glInt_t; +typedef uint32_t glUInt_t; + + +// Handle to a shared texture (HANDLE on Windows obtained using OpenSharedResource). +typedef uint64_t SharedTextureHandle_t; +#define INVALID_SHARED_TEXTURE_HANDLE ((vr::SharedTextureHandle_t)0) + +enum ETrackingResult +{ + TrackingResult_Uninitialized = 1, + + TrackingResult_Calibrating_InProgress = 100, + TrackingResult_Calibrating_OutOfRange = 101, + + TrackingResult_Running_OK = 200, + TrackingResult_Running_OutOfRange = 201, + + TrackingResult_Fallback_RotationOnly = 300, +}; + +typedef uint32_t DriverId_t; +static const uint32_t k_nDriverNone = 0xFFFFFFFF; + +static const uint32_t k_unMaxDriverDebugResponseSize = 32768; + +/** Used to pass device IDs to API calls */ +typedef uint32_t TrackedDeviceIndex_t; +static const uint32_t k_unTrackedDeviceIndex_Hmd = 0; +static const uint32_t k_unMaxTrackedDeviceCount = 64; +static const uint32_t k_unTrackedDeviceIndexOther = 0xFFFFFFFE; +static const uint32_t k_unTrackedDeviceIndexInvalid = 0xFFFFFFFF; + +/** Describes what kind of object is being tracked at a given ID */ +enum ETrackedDeviceClass +{ + TrackedDeviceClass_Invalid = 0, // the ID was not valid. + TrackedDeviceClass_HMD = 1, // Head-Mounted Displays + TrackedDeviceClass_Controller = 2, // Tracked controllers + TrackedDeviceClass_GenericTracker = 3, // Generic trackers, similar to controllers + TrackedDeviceClass_TrackingReference = 4, // Camera and base stations that serve as tracking reference points + TrackedDeviceClass_DisplayRedirect = 5, // Accessories that aren't necessarily tracked themselves, but may redirect video output from other tracked devices + + TrackedDeviceClass_Max +}; + + +/** Describes what specific role associated with a tracked device */ +enum ETrackedControllerRole +{ + TrackedControllerRole_Invalid = 0, // Invalid value for controller type + TrackedControllerRole_LeftHand = 1, // Tracked device associated with the left hand + TrackedControllerRole_RightHand = 2, // Tracked device associated with the right hand + TrackedControllerRole_OptOut = 3, // Tracked device is opting out of left/right hand selection + TrackedControllerRole_Treadmill = 4, // Tracked device is a treadmill or other locomotion device + TrackedControllerRole_Stylus = 5, // Tracked device is a stylus + TrackedControllerRole_Max = 5 +}; + + +/** Returns true if the tracked controller role is allowed to be a hand */ +inline bool IsRoleAllowedAsHand( ETrackedControllerRole eRole ) +{ + switch ( eRole ) + { + case TrackedControllerRole_Invalid: + case TrackedControllerRole_LeftHand: + case TrackedControllerRole_RightHand: + return true; + default: + return false; + } +} + + +/** describes a single pose for a tracked object */ +struct TrackedDevicePose_t +{ + HmdMatrix34_t mDeviceToAbsoluteTracking; + HmdVector3_t vVelocity; // velocity in tracker space in m/s + HmdVector3_t vAngularVelocity; // angular velocity in radians/s (?) + ETrackingResult eTrackingResult; + bool bPoseIsValid; + + // This indicates that there is a device connected for this spot in the pose array. + // It could go from true to false if the user unplugs the device. + bool bDeviceIsConnected; +}; + +/** Identifies which style of tracking origin the application wants to use +* for the poses it is requesting */ +enum ETrackingUniverseOrigin +{ + TrackingUniverseSeated = 0, // Poses are provided relative to the seated zero pose + TrackingUniverseStanding = 1, // Poses are provided relative to the safe bounds configured by the user + TrackingUniverseRawAndUncalibrated = 2, // Poses are provided in the coordinate system defined by the driver. It has Y up and is unified for devices of the same driver. You usually don't want this one. +}; + +enum EAdditionalRadioFeatures +{ + AdditionalRadioFeatures_None = 0x00000000, + AdditionalRadioFeatures_HTCLinkBox = 0x00000001, + AdditionalRadioFeatures_InternalDongle = 0x00000002, + AdditionalRadioFeatures_ExternalDongle = 0x00000004, +}; + +typedef uint64_t WebConsoleHandle_t; +#define INVALID_WEB_CONSOLE_HANDLE ((vr::WebConsoleHandle_t)0) + +// Refers to a single container of properties +typedef uint64_t PropertyContainerHandle_t; +typedef uint32_t PropertyTypeTag_t; + +static const PropertyContainerHandle_t k_ulInvalidPropertyContainer = 0; +static const PropertyTypeTag_t k_unInvalidPropertyTag = 0; + +typedef PropertyContainerHandle_t DriverHandle_t; +static const PropertyContainerHandle_t k_ulInvalidDriverHandle = 0; + +// Use these tags to set/get common types as struct properties +static const PropertyTypeTag_t k_unFloatPropertyTag = 1; +static const PropertyTypeTag_t k_unInt32PropertyTag = 2; +static const PropertyTypeTag_t k_unUint64PropertyTag = 3; +static const PropertyTypeTag_t k_unBoolPropertyTag = 4; +static const PropertyTypeTag_t k_unStringPropertyTag = 5; +static const PropertyTypeTag_t k_unErrorPropertyTag = 6; +static const PropertyTypeTag_t k_unDoublePropertyTag = 7; + +static const PropertyTypeTag_t k_unHmdMatrix34PropertyTag = 20; +static const PropertyTypeTag_t k_unHmdMatrix44PropertyTag = 21; +static const PropertyTypeTag_t k_unHmdVector3PropertyTag = 22; +static const PropertyTypeTag_t k_unHmdVector4PropertyTag = 23; +static const PropertyTypeTag_t k_unHmdVector2PropertyTag = 24; +static const PropertyTypeTag_t k_unHmdQuadPropertyTag = 25; + +static const PropertyTypeTag_t k_unHiddenAreaPropertyTag = 30; +static const PropertyTypeTag_t k_unPathHandleInfoTag = 31; +static const PropertyTypeTag_t k_unActionPropertyTag = 32; +static const PropertyTypeTag_t k_unInputValuePropertyTag = 33; +static const PropertyTypeTag_t k_unWildcardPropertyTag = 34; +static const PropertyTypeTag_t k_unHapticVibrationPropertyTag = 35; +static const PropertyTypeTag_t k_unSkeletonPropertyTag = 36; + +static const PropertyTypeTag_t k_unSpatialAnchorPosePropertyTag = 40; +static const PropertyTypeTag_t k_unJsonPropertyTag = 41; +static const PropertyTypeTag_t k_unActiveActionSetPropertyTag = 42; + +static const PropertyTypeTag_t k_unOpenVRInternalReserved_Start = 1000; +static const PropertyTypeTag_t k_unOpenVRInternalReserved_End = 10000; + + +/** Each entry in this enum represents a property that can be retrieved about a +* tracked device. Many fields are only valid for one ETrackedDeviceClass. */ +enum ETrackedDeviceProperty +{ + Prop_Invalid = 0, + + // general properties that apply to all device classes + Prop_TrackingSystemName_String = 1000, + Prop_ModelNumber_String = 1001, + Prop_SerialNumber_String = 1002, + Prop_RenderModelName_String = 1003, + Prop_WillDriftInYaw_Bool = 1004, + Prop_ManufacturerName_String = 1005, + Prop_TrackingFirmwareVersion_String = 1006, + Prop_HardwareRevision_String = 1007, + Prop_AllWirelessDongleDescriptions_String = 1008, + Prop_ConnectedWirelessDongle_String = 1009, + Prop_DeviceIsWireless_Bool = 1010, + Prop_DeviceIsCharging_Bool = 1011, + Prop_DeviceBatteryPercentage_Float = 1012, // 0 is empty, 1 is full + Prop_StatusDisplayTransform_Matrix34 = 1013, + Prop_Firmware_UpdateAvailable_Bool = 1014, + Prop_Firmware_ManualUpdate_Bool = 1015, + Prop_Firmware_ManualUpdateURL_String = 1016, + Prop_HardwareRevision_Uint64 = 1017, + Prop_FirmwareVersion_Uint64 = 1018, + Prop_FPGAVersion_Uint64 = 1019, + Prop_VRCVersion_Uint64 = 1020, + Prop_RadioVersion_Uint64 = 1021, + Prop_DongleVersion_Uint64 = 1022, + Prop_BlockServerShutdown_Bool = 1023, + Prop_CanUnifyCoordinateSystemWithHmd_Bool = 1024, + Prop_ContainsProximitySensor_Bool = 1025, + Prop_DeviceProvidesBatteryStatus_Bool = 1026, + Prop_DeviceCanPowerOff_Bool = 1027, + Prop_Firmware_ProgrammingTarget_String = 1028, + Prop_DeviceClass_Int32 = 1029, + Prop_HasCamera_Bool = 1030, + Prop_DriverVersion_String = 1031, + Prop_Firmware_ForceUpdateRequired_Bool = 1032, + Prop_ViveSystemButtonFixRequired_Bool = 1033, + Prop_ParentDriver_Uint64 = 1034, + Prop_ResourceRoot_String = 1035, + Prop_RegisteredDeviceType_String = 1036, + Prop_InputProfilePath_String = 1037, // input profile to use for this device in the input system. Will default to tracking system name if this isn't provided + Prop_NeverTracked_Bool = 1038, // Used for devices that will never have a valid pose by design + Prop_NumCameras_Int32 = 1039, + Prop_CameraFrameLayout_Int32 = 1040, // EVRTrackedCameraFrameLayout value + Prop_CameraStreamFormat_Int32 = 1041, // ECameraVideoStreamFormat value + Prop_AdditionalDeviceSettingsPath_String = 1042, // driver-relative path to additional device and global configuration settings + Prop_Identifiable_Bool = 1043, // Whether device supports being identified from vrmonitor (e.g. blink LED, vibrate haptics, etc) + Prop_BootloaderVersion_Uint64 = 1044, + Prop_AdditionalSystemReportData_String = 1045, // additional string to include in system reports about a tracked device + Prop_CompositeFirmwareVersion_String = 1046, // additional FW components from a device that gets propagated into reports + Prop_Firmware_RemindUpdate_Bool = 1047, + Prop_PeripheralApplicationVersion_Uint64 = 1048, + Prop_ManufacturerSerialNumber_String = 1049, + Prop_ComputedSerialNumber_String = 1050, + Prop_EstimatedDeviceFirstUseTime_Int32 = 1051, + Prop_DevicePowerUsage_Float = 1052, + Prop_IgnoreMotionForStandby_Bool = 1053, + Prop_ActualTrackingSystemName_String = 1054, // the literal local driver name in case someone is playing games with prop 1000 + + // Properties that are unique to TrackedDeviceClass_HMD + Prop_ReportsTimeSinceVSync_Bool = 2000, + Prop_SecondsFromVsyncToPhotons_Float = 2001, + Prop_DisplayFrequency_Float = 2002, + Prop_UserIpdMeters_Float = 2003, + Prop_CurrentUniverseId_Uint64 = 2004, + Prop_PreviousUniverseId_Uint64 = 2005, + Prop_DisplayFirmwareVersion_Uint64 = 2006, + Prop_IsOnDesktop_Bool = 2007, + Prop_DisplayMCType_Int32 = 2008, + Prop_DisplayMCOffset_Float = 2009, + Prop_DisplayMCScale_Float = 2010, + Prop_EdidVendorID_Int32 = 2011, + Prop_DisplayMCImageLeft_String = 2012, + Prop_DisplayMCImageRight_String = 2013, + Prop_DisplayGCBlackClamp_Float = 2014, + Prop_EdidProductID_Int32 = 2015, + Prop_CameraToHeadTransform_Matrix34 = 2016, + Prop_DisplayGCType_Int32 = 2017, + Prop_DisplayGCOffset_Float = 2018, + Prop_DisplayGCScale_Float = 2019, + Prop_DisplayGCPrescale_Float = 2020, + Prop_DisplayGCImage_String = 2021, + Prop_LensCenterLeftU_Float = 2022, + Prop_LensCenterLeftV_Float = 2023, + Prop_LensCenterRightU_Float = 2024, + Prop_LensCenterRightV_Float = 2025, + Prop_UserHeadToEyeDepthMeters_Float = 2026, + Prop_CameraFirmwareVersion_Uint64 = 2027, + Prop_CameraFirmwareDescription_String = 2028, + Prop_DisplayFPGAVersion_Uint64 = 2029, + Prop_DisplayBootloaderVersion_Uint64 = 2030, + Prop_DisplayHardwareVersion_Uint64 = 2031, + Prop_AudioFirmwareVersion_Uint64 = 2032, + Prop_CameraCompatibilityMode_Int32 = 2033, + Prop_ScreenshotHorizontalFieldOfViewDegrees_Float = 2034, + Prop_ScreenshotVerticalFieldOfViewDegrees_Float = 2035, + Prop_DisplaySuppressed_Bool = 2036, + Prop_DisplayAllowNightMode_Bool = 2037, + Prop_DisplayMCImageWidth_Int32 = 2038, + Prop_DisplayMCImageHeight_Int32 = 2039, + Prop_DisplayMCImageNumChannels_Int32 = 2040, + Prop_DisplayMCImageData_Binary = 2041, + Prop_SecondsFromPhotonsToVblank_Float = 2042, + Prop_DriverDirectModeSendsVsyncEvents_Bool = 2043, + Prop_DisplayDebugMode_Bool = 2044, + Prop_GraphicsAdapterLuid_Uint64 = 2045, + Prop_DriverProvidedChaperonePath_String = 2048, + Prop_ExpectedTrackingReferenceCount_Int32 = 2049, // expected number of sensors or basestations to reserve UI space for + Prop_ExpectedControllerCount_Int32 = 2050, // expected number of tracked controllers to reserve UI space for + Prop_NamedIconPathControllerLeftDeviceOff_String = 2051, // placeholder icon for "left" controller if not yet detected/loaded + Prop_NamedIconPathControllerRightDeviceOff_String = 2052, // placeholder icon for "right" controller if not yet detected/loaded + Prop_NamedIconPathTrackingReferenceDeviceOff_String = 2053, // placeholder icon for sensor/base if not yet detected/loaded + Prop_DoNotApplyPrediction_Bool = 2054, // currently no effect. was used to disable HMD pose prediction on MR, which is now done by MR driver setting velocity=0 + Prop_CameraToHeadTransforms_Matrix34_Array = 2055, + Prop_DistortionMeshResolution_Int32 = 2056, // custom resolution of compositor calls to IVRSystem::ComputeDistortion + Prop_DriverIsDrawingControllers_Bool = 2057, + Prop_DriverRequestsApplicationPause_Bool = 2058, + Prop_DriverRequestsReducedRendering_Bool = 2059, + Prop_MinimumIpdStepMeters_Float = 2060, + Prop_AudioBridgeFirmwareVersion_Uint64 = 2061, + Prop_ImageBridgeFirmwareVersion_Uint64 = 2062, + Prop_ImuToHeadTransform_Matrix34 = 2063, + Prop_ImuFactoryGyroBias_Vector3 = 2064, + Prop_ImuFactoryGyroScale_Vector3 = 2065, + Prop_ImuFactoryAccelerometerBias_Vector3 = 2066, + Prop_ImuFactoryAccelerometerScale_Vector3 = 2067, + // reserved 2068 + Prop_ConfigurationIncludesLighthouse20Features_Bool = 2069, + Prop_AdditionalRadioFeatures_Uint64 = 2070, + Prop_CameraWhiteBalance_Vector4_Array = 2071, // Prop_NumCameras_Int32-sized array of float[4] RGBG white balance calibration data (max size is vr::k_unMaxCameras) + Prop_CameraDistortionFunction_Int32_Array = 2072, // Prop_NumCameras_Int32-sized array of vr::EVRDistortionFunctionType values (max size is vr::k_unMaxCameras) + Prop_CameraDistortionCoefficients_Float_Array = 2073, // Prop_NumCameras_Int32-sized array of double[vr::k_unMaxDistortionFunctionParameters] (max size is vr::k_unMaxCameras) + Prop_ExpectedControllerType_String = 2074, + Prop_HmdTrackingStyle_Int32 = 2075, // one of EHmdTrackingStyle + Prop_DriverProvidedChaperoneVisibility_Bool = 2076, + Prop_HmdColumnCorrectionSettingPrefix_String = 2077, + Prop_CameraSupportsCompatibilityModes_Bool = 2078, + Prop_SupportsRoomViewDepthProjection_Bool = 2079, + Prop_DisplayAvailableFrameRates_Float_Array = 2080, // populated by compositor from actual EDID list when available from GPU driver + Prop_DisplaySupportsMultipleFramerates_Bool = 2081, // if this is true but Prop_DisplayAvailableFrameRates_Float_Array is empty, explain to user + Prop_DisplayColorMultLeft_Vector3 = 2082, + Prop_DisplayColorMultRight_Vector3 = 2083, + Prop_DisplaySupportsRuntimeFramerateChange_Bool = 2084, + Prop_DisplaySupportsAnalogGain_Bool = 2085, + Prop_DisplayMinAnalogGain_Float = 2086, + Prop_DisplayMaxAnalogGain_Float = 2087, + Prop_CameraExposureTime_Float = 2088, + Prop_CameraGlobalGain_Float = 2089, + // Prop_DashboardLayoutPathName_String = 2090, // DELETED + Prop_DashboardScale_Float = 2091, + Prop_PeerButtonInfo_String = 2092, + Prop_Hmd_SupportsHDR10_Bool = 2093, + Prop_Hmd_EnableParallelRenderCameras_Bool = 2094, + Prop_DriverProvidedChaperoneJson_String = 2095, // higher priority than Prop_DriverProvidedChaperonePath_String + + Prop_IpdUIRangeMinMeters_Float = 2100, + Prop_IpdUIRangeMaxMeters_Float = 2101, + Prop_Hmd_SupportsHDCP14LegacyCompat_Bool = 2102, + Prop_Hmd_SupportsMicMonitoring_Bool = 2103, + Prop_Hmd_SupportsDisplayPortTrainingMode_Bool = 2104, + Prop_Hmd_SupportsRoomViewDirect_Bool = 2105, + Prop_Hmd_SupportsAppThrottling_Bool = 2106, + Prop_Hmd_SupportsGpuBusMonitoring_Bool = 2107, + Prop_DriverProvidedIPDVisibility_Bool = 2108, + + Prop_DSCVersion_Int32 = 2110, + Prop_DSCSliceCount_Int32 = 2111, + Prop_DSCBPPx16_Int32 = 2112, + + // Driver requested mura correction properties + Prop_DriverRequestedMuraCorrectionMode_Int32 = 2200, + Prop_DriverRequestedMuraFeather_InnerLeft_Int32 = 2201, + Prop_DriverRequestedMuraFeather_InnerRight_Int32 = 2202, + Prop_DriverRequestedMuraFeather_InnerTop_Int32 = 2203, + Prop_DriverRequestedMuraFeather_InnerBottom_Int32 = 2204, + Prop_DriverRequestedMuraFeather_OuterLeft_Int32 = 2205, + Prop_DriverRequestedMuraFeather_OuterRight_Int32 = 2206, + Prop_DriverRequestedMuraFeather_OuterTop_Int32 = 2207, + Prop_DriverRequestedMuraFeather_OuterBottom_Int32 = 2208, + + Prop_Audio_DefaultPlaybackDeviceId_String = 2300, + Prop_Audio_DefaultRecordingDeviceId_String = 2301, + Prop_Audio_DefaultPlaybackDeviceVolume_Float = 2302, + Prop_Audio_SupportsDualSpeakerAndJackOutput_Bool = 2303, + + // Properties that are unique to TrackedDeviceClass_Controller + Prop_AttachedDeviceId_String = 3000, + Prop_SupportedButtons_Uint64 = 3001, + Prop_Axis0Type_Int32 = 3002, // Return value is of type EVRControllerAxisType + Prop_Axis1Type_Int32 = 3003, // Return value is of type EVRControllerAxisType + Prop_Axis2Type_Int32 = 3004, // Return value is of type EVRControllerAxisType + Prop_Axis3Type_Int32 = 3005, // Return value is of type EVRControllerAxisType + Prop_Axis4Type_Int32 = 3006, // Return value is of type EVRControllerAxisType + Prop_ControllerRoleHint_Int32 = 3007, // Return value is of type ETrackedControllerRole + + // Properties that are unique to TrackedDeviceClass_TrackingReference + Prop_FieldOfViewLeftDegrees_Float = 4000, + Prop_FieldOfViewRightDegrees_Float = 4001, + Prop_FieldOfViewTopDegrees_Float = 4002, + Prop_FieldOfViewBottomDegrees_Float = 4003, + Prop_TrackingRangeMinimumMeters_Float = 4004, + Prop_TrackingRangeMaximumMeters_Float = 4005, + Prop_ModeLabel_String = 4006, + Prop_CanWirelessIdentify_Bool = 4007, // volatile, based on radio presence and fw discovery + Prop_Nonce_Int32 = 4008, + + // Properties that are used for user interface like icons names + Prop_IconPathName_String = 5000, // DEPRECATED. Value not referenced. Now expected to be part of icon path properties. + Prop_NamedIconPathDeviceOff_String = 5001, // {driver}/icons/icon_filename - PNG for static icon, or GIF for animation, 50x32 for headsets and 32x32 for others + Prop_NamedIconPathDeviceSearching_String = 5002, // {driver}/icons/icon_filename - PNG for static icon, or GIF for animation, 50x32 for headsets and 32x32 for others + Prop_NamedIconPathDeviceSearchingAlert_String = 5003, // {driver}/icons/icon_filename - PNG for static icon, or GIF for animation, 50x32 for headsets and 32x32 for others + Prop_NamedIconPathDeviceReady_String = 5004, // {driver}/icons/icon_filename - PNG for static icon, or GIF for animation, 50x32 for headsets and 32x32 for others + Prop_NamedIconPathDeviceReadyAlert_String = 5005, // {driver}/icons/icon_filename - PNG for static icon, or GIF for animation, 50x32 for headsets and 32x32 for others + Prop_NamedIconPathDeviceNotReady_String = 5006, // {driver}/icons/icon_filename - PNG for static icon, or GIF for animation, 50x32 for headsets and 32x32 for others + Prop_NamedIconPathDeviceStandby_String = 5007, // {driver}/icons/icon_filename - PNG for static icon, or GIF for animation, 50x32 for headsets and 32x32 for others + Prop_NamedIconPathDeviceAlertLow_String = 5008, // {driver}/icons/icon_filename - PNG for static icon, or GIF for animation, 50x32 for headsets and 32x32 for others + Prop_NamedIconPathDeviceStandbyAlert_String = 5009, // {driver}/icons/icon_filename - PNG for static icon, or GIF for animation, 50x32 for headsets and 32x32 for others + + // Properties that are used by helpers, but are opaque to applications + Prop_DisplayHiddenArea_Binary_Start = 5100, + Prop_DisplayHiddenArea_Binary_End = 5150, + Prop_ParentContainer = 5151, + Prop_OverrideContainer_Uint64 = 5152, + + // Properties that are unique to drivers + Prop_UserConfigPath_String = 6000, + Prop_InstallPath_String = 6001, + Prop_HasDisplayComponent_Bool = 6002, + Prop_HasControllerComponent_Bool = 6003, + Prop_HasCameraComponent_Bool = 6004, + Prop_HasDriverDirectModeComponent_Bool = 6005, + Prop_HasVirtualDisplayComponent_Bool = 6006, + Prop_HasSpatialAnchorsSupport_Bool = 6007, + + // Properties that are set internally based on other information provided by drivers + Prop_ControllerType_String = 7000, + //Prop_LegacyInputProfile_String = 7001, // This is no longer used. See "legacy_binding" in the input profile instead. + Prop_ControllerHandSelectionPriority_Int32 = 7002, // Allows hand assignments to prefer some controllers over others. High numbers are selected over low numbers + + // Vendors are free to expose private debug data in this reserved region + Prop_VendorSpecific_Reserved_Start = 10000, + Prop_VendorSpecific_Reserved_End = 10999, + + Prop_TrackedDeviceProperty_Max = 1000000, +}; + +/** No string property will ever be longer than this length */ +static const uint32_t k_unMaxPropertyStringSize = 32 * 1024; + +/** Used to return errors that occur when reading properties. */ +enum ETrackedPropertyError +{ + TrackedProp_Success = 0, + TrackedProp_WrongDataType = 1, + TrackedProp_WrongDeviceClass = 2, + TrackedProp_BufferTooSmall = 3, + TrackedProp_UnknownProperty = 4, // Driver has not set the property (and may not ever). + TrackedProp_InvalidDevice = 5, + TrackedProp_CouldNotContactServer = 6, + TrackedProp_ValueNotProvidedByDevice = 7, + TrackedProp_StringExceedsMaximumLength = 8, + TrackedProp_NotYetAvailable = 9, // The property value isn't known yet, but is expected soon. Call again later. + TrackedProp_PermissionDenied = 10, + TrackedProp_InvalidOperation = 11, + TrackedProp_CannotWriteToWildcards = 12, + TrackedProp_IPCReadFailure = 13, + TrackedProp_OutOfMemory = 14, + TrackedProp_InvalidContainer = 15, +}; + +/** Used to drive certain text in the UI when talking about the tracking system for the HMD */ +enum EHmdTrackingStyle +{ + HmdTrackingStyle_Unknown = 0, + + HmdTrackingStyle_Lighthouse = 1, // base stations and lasers + HmdTrackingStyle_OutsideInCameras = 2, // Cameras and LED, Rift 1 style + HmdTrackingStyle_InsideOutCameras = 3, // Cameras on HMD looking at the world +}; + +typedef uint64_t VRActionHandle_t; +typedef uint64_t VRActionSetHandle_t; +typedef uint64_t VRInputValueHandle_t; + +static const VRActionHandle_t k_ulInvalidActionHandle = 0; +static const VRActionSetHandle_t k_ulInvalidActionSetHandle = 0; +static const VRInputValueHandle_t k_ulInvalidInputValueHandle = 0; + + +/** Allows the application to control how scene textures are used by the compositor when calling Submit. */ +enum EVRSubmitFlags +{ + // Simple render path. App submits rendered left and right eye images with no lens distortion correction applied. + Submit_Default = 0x00, + + // App submits final left and right eye images with lens distortion already applied (lens distortion makes the images appear + // barrel distorted with chromatic aberration correction applied). The app would have used the data returned by + // vr::IVRSystem::ComputeDistortion() to apply the correct distortion to the rendered images before calling Submit(). + Submit_LensDistortionAlreadyApplied = 0x01, + + // If the texture pointer passed in is actually a renderbuffer (e.g. for MSAA in OpenGL) then set this flag. + Submit_GlRenderBuffer = 0x02, + + // Do not use + Submit_Reserved = 0x04, + + // Set to indicate that pTexture is a pointer to a VRTextureWithPose_t. + // This flag can be combined with Submit_TextureWithDepth to pass a VRTextureWithPoseAndDepth_t. + Submit_TextureWithPose = 0x08, + + // Set to indicate that pTexture is a pointer to a VRTextureWithDepth_t. + // This flag can be combined with Submit_TextureWithPose to pass a VRTextureWithPoseAndDepth_t. + Submit_TextureWithDepth = 0x10, + + // Set to indicate a discontinuity between this and the last frame. + // This will prevent motion smoothing from attempting to extrapolate using the pair. + Submit_FrameDiscontinuty = 0x20, + + // Set to indicate that pTexture->handle is a contains VRVulkanTextureArrayData_t + Submit_VulkanTextureWithArrayData = 0x40, + + // If the texture pointer passed in is an OpenGL Array texture, set this flag + Submit_GlArrayTexture = 0x80, + + // If the texture is an EGL texture and not an glX/wGL texture (Linux only, currently) + Submit_IsEgl = 0x100, + + // Do not use + Submit_Reserved2 = 0x08000, + Submit_Reserved3 = 0x10000, + +}; + +/** Data required for passing Vulkan textures to IVRCompositor::Submit. +* Be sure to call OpenVR_Shutdown before destroying these resources. +* Please see https://github.com/ValveSoftware/openvr/wiki/Vulkan for Vulkan-specific documentation */ +struct VRVulkanTextureData_t +{ + uint64_t m_nImage; // VkImage + VkDevice_T *m_pDevice; + VkPhysicalDevice_T *m_pPhysicalDevice; + VkInstance_T *m_pInstance; + VkQueue_T *m_pQueue; + uint32_t m_nQueueFamilyIndex; + uint32_t m_nWidth, m_nHeight, m_nFormat, m_nSampleCount; +}; + +/** Data required for passing Vulkan texture arrays to IVRCompositor::Submit. +* Be sure to call OpenVR_Shutdown before destroying these resources. +* Please see https://github.com/ValveSoftware/openvr/wiki/Vulkan for Vulkan-specific documentation */ +struct VRVulkanTextureArrayData_t : public VRVulkanTextureData_t +{ + uint32_t m_unArrayIndex; + uint32_t m_unArraySize; +}; + +/** Data required for passing D3D12 textures to IVRCompositor::Submit. +* Be sure to call OpenVR_Shutdown before destroying these resources. */ +struct D3D12TextureData_t +{ + ID3D12Resource *m_pResource; + ID3D12CommandQueue *m_pCommandQueue; + uint32_t m_nNodeMask; +}; + +/** Status of the overall system or tracked objects */ +enum EVRState +{ + VRState_Undefined = -1, + VRState_Off = 0, + VRState_Searching = 1, + VRState_Searching_Alert = 2, + VRState_Ready = 3, + VRState_Ready_Alert = 4, + VRState_NotReady = 5, + VRState_Standby = 6, + VRState_Ready_Alert_Low = 7, +}; + +/** The types of events that could be posted (and what the parameters mean for each event type) */ +enum EVREventType +{ + VREvent_None = 0, + + VREvent_TrackedDeviceActivated = 100, + VREvent_TrackedDeviceDeactivated = 101, + VREvent_TrackedDeviceUpdated = 102, + VREvent_TrackedDeviceUserInteractionStarted = 103, + VREvent_TrackedDeviceUserInteractionEnded = 104, + VREvent_IpdChanged = 105, + VREvent_EnterStandbyMode = 106, + VREvent_LeaveStandbyMode = 107, + VREvent_TrackedDeviceRoleChanged = 108, + VREvent_WatchdogWakeUpRequested = 109, + VREvent_LensDistortionChanged = 110, + VREvent_PropertyChanged = 111, + VREvent_WirelessDisconnect = 112, + VREvent_WirelessReconnect = 113, + VREvent_Reserved_01 = 114, + VREvent_Reserved_02 = 115, + + VREvent_ButtonPress = 200, // data is controller + VREvent_ButtonUnpress = 201, // data is controller + VREvent_ButtonTouch = 202, // data is controller + VREvent_ButtonUntouch = 203, // data is controller + + // VREvent_DualAnalog_Press = 250, // No longer sent + // VREvent_DualAnalog_Unpress = 251, // No longer sent + // VREvent_DualAnalog_Touch = 252, // No longer sent + // VREvent_DualAnalog_Untouch = 253, // No longer sent + // VREvent_DualAnalog_Move = 254, // No longer sent + // VREvent_DualAnalog_ModeSwitch1 = 255, // No longer sent + // VREvent_DualAnalog_ModeSwitch2 = 256, // No longer sent + VREvent_Modal_Cancel = 257, // Sent to overlays with the + + VREvent_MouseMove = 300, // data is mouse + VREvent_MouseButtonDown = 301, // data is mouse + VREvent_MouseButtonUp = 302, // data is mouse + VREvent_FocusEnter = 303, // data is overlay + VREvent_FocusLeave = 304, // data is overlay + VREvent_ScrollDiscrete = 305, // data is scroll + VREvent_TouchPadMove = 306, // data is mouse + VREvent_OverlayFocusChanged = 307, // data is overlay, global event + VREvent_ReloadOverlays = 308, + VREvent_ScrollSmooth = 309, // data is scroll + VREvent_LockMousePosition = 310, + VREvent_UnlockMousePosition = 311, + + VREvent_InputFocusCaptured = 400, // data is process DEPRECATED + VREvent_InputFocusReleased = 401, // data is process DEPRECATED + // VREvent_SceneFocusLost = 402, // data is process + // VREvent_SceneFocusGained = 403, // data is process + VREvent_SceneApplicationChanged = 404, // data is process - The App actually drawing the scene changed (usually to or from the compositor) + // VREvent_SceneFocusChanged = 405, // data is process - This is defunct and will not be called. + VREvent_InputFocusChanged = 406, // data is process + // VREvent_SceneApplicationSecondaryRenderingStarted = 407, + VREvent_SceneApplicationUsingWrongGraphicsAdapter = 408, // data is process + VREvent_ActionBindingReloaded = 409, // data is process - The App that action binds reloaded for + + VREvent_HideRenderModels = 410, // Sent to the scene application to request hiding render models temporarily + VREvent_ShowRenderModels = 411, // Sent to the scene application to request restoring render model visibility + + VREvent_SceneApplicationStateChanged = 412, // No data; but query VRApplications()->GetSceneApplicationState(); + + VREvent_SceneAppPipeDisconnected = 413, // data is process - Called when the scene app's pipe has been closed. + + VREvent_ConsoleOpened = 420, + VREvent_ConsoleClosed = 421, + + VREvent_OverlayShown = 500, // Indicates that an overlay is now visible to someone and should be rendering normally. Reflects IVROverlay::IsOverlayVisible() becoming true. + VREvent_OverlayHidden = 501, // Indicates that an overlay is no longer visible to someone and doesn't need to render frames. Reflects IVROverlay::IsOverlayVisible() becoming false. + VREvent_DashboardActivated = 502, + VREvent_DashboardDeactivated = 503, + //VREvent_DashboardThumbSelected = 504, // Sent to the overlay manager - data is overlay - No longer sent + VREvent_DashboardRequested = 505, // Sent to the overlay manager - data is overlay + VREvent_ResetDashboard = 506, // Send to the overlay manager + //VREvent_RenderToast = 507, // Send to the dashboard to render a toast - data is the notification ID -- no longer sent + VREvent_ImageLoaded = 508, // Sent to overlays when a SetOverlayRaw or SetOverlayFromFile call finishes loading + VREvent_ShowKeyboard = 509, // Sent to keyboard renderer in the dashboard to invoke it + VREvent_HideKeyboard = 510, // Sent to keyboard renderer in the dashboard to hide it + VREvent_OverlayGamepadFocusGained = 511, // Sent to an overlay when IVROverlay::SetFocusOverlay is called on it + VREvent_OverlayGamepadFocusLost = 512, // Send to an overlay when it previously had focus and IVROverlay::SetFocusOverlay is called on something else + VREvent_OverlaySharedTextureChanged = 513, + //VREvent_DashboardGuideButtonDown = 514, // These are no longer sent + //VREvent_DashboardGuideButtonUp = 515, + VREvent_ScreenshotTriggered = 516, // Screenshot button combo was pressed, Dashboard should request a screenshot + VREvent_ImageFailed = 517, // Sent to overlays when a SetOverlayRaw or SetOverlayfromFail fails to load + VREvent_DashboardOverlayCreated = 518, + VREvent_SwitchGamepadFocus = 519, + + // Screenshot API + VREvent_RequestScreenshot = 520, // Sent by vrclient application to compositor to take a screenshot + VREvent_ScreenshotTaken = 521, // Sent by compositor to the application that the screenshot has been taken + VREvent_ScreenshotFailed = 522, // Sent by compositor to the application that the screenshot failed to be taken + VREvent_SubmitScreenshotToDashboard = 523, // Sent by compositor to the dashboard that a completed screenshot was submitted + VREvent_ScreenshotProgressToDashboard = 524, // Sent by compositor to the dashboard that a completed screenshot was submitted + + VREvent_PrimaryDashboardDeviceChanged = 525, + VREvent_RoomViewShown = 526, // Sent by compositor whenever room-view is enabled + VREvent_RoomViewHidden = 527, // Sent by compositor whenever room-view is disabled + VREvent_ShowUI = 528, // data is showUi + VREvent_ShowDevTools = 529, // data is showDevTools + VREvent_DesktopViewUpdating = 530, + VREvent_DesktopViewReady = 531, + + VREvent_StartDashboard = 532, + VREvent_ElevatePrism = 533, + + VREvent_OverlayClosed = 534, + + VREvent_DashboardThumbChanged = 535, // Sent when a dashboard thumbnail image changes + + VREvent_Notification_Shown = 600, + VREvent_Notification_Hidden = 601, + VREvent_Notification_BeginInteraction = 602, + VREvent_Notification_Destroyed = 603, + + VREvent_Quit = 700, // data is process + VREvent_ProcessQuit = 701, // data is process + //VREvent_QuitAborted_UserPrompt = 702, // data is process + VREvent_QuitAcknowledged = 703, // data is process + VREvent_DriverRequestedQuit = 704, // The driver has requested that SteamVR shut down + VREvent_RestartRequested = 705, // A driver or other component wants the user to restart SteamVR + VREvent_InvalidateSwapTextureSets = 706, + + VREvent_ChaperoneDataHasChanged = 800, // this will never happen with the new chaperone system + VREvent_ChaperoneUniverseHasChanged = 801, + VREvent_ChaperoneTempDataHasChanged = 802, // this will never happen with the new chaperone system + VREvent_ChaperoneSettingsHaveChanged = 803, + VREvent_SeatedZeroPoseReset = 804, + VREvent_ChaperoneFlushCache = 805, // Sent when the process needs to reload any cached data it retrieved from VRChaperone() + VREvent_ChaperoneRoomSetupStarting = 806, // Triggered by CVRChaperoneClient::RoomSetupStarting + VREvent_ChaperoneRoomSetupFinished = 807, // Triggered by CVRChaperoneClient::CommitWorkingCopy + VREvent_StandingZeroPoseReset = 808, + + VREvent_AudioSettingsHaveChanged = 820, + + VREvent_BackgroundSettingHasChanged = 850, + VREvent_CameraSettingsHaveChanged = 851, + VREvent_ReprojectionSettingHasChanged = 852, + VREvent_ModelSkinSettingsHaveChanged = 853, + VREvent_EnvironmentSettingsHaveChanged = 854, + VREvent_PowerSettingsHaveChanged = 855, + VREvent_EnableHomeAppSettingsHaveChanged = 856, + VREvent_SteamVRSectionSettingChanged = 857, + VREvent_LighthouseSectionSettingChanged = 858, + VREvent_NullSectionSettingChanged = 859, + VREvent_UserInterfaceSectionSettingChanged = 860, + VREvent_NotificationsSectionSettingChanged = 861, + VREvent_KeyboardSectionSettingChanged = 862, + VREvent_PerfSectionSettingChanged = 863, + VREvent_DashboardSectionSettingChanged = 864, + VREvent_WebInterfaceSectionSettingChanged = 865, + VREvent_TrackersSectionSettingChanged = 866, + VREvent_LastKnownSectionSettingChanged = 867, + VREvent_DismissedWarningsSectionSettingChanged = 868, + VREvent_GpuSpeedSectionSettingChanged = 869, + VREvent_WindowsMRSectionSettingChanged = 870, + VREvent_OtherSectionSettingChanged = 871, + VREvent_AnyDriverSettingsChanged = 872, + + VREvent_StatusUpdate = 900, + + VREvent_WebInterface_InstallDriverCompleted = 950, + + VREvent_MCImageUpdated = 1000, + + VREvent_FirmwareUpdateStarted = 1100, + VREvent_FirmwareUpdateFinished = 1101, + + VREvent_KeyboardClosed = 1200, // DEPRECATED: Sent only to the overlay it closed for, or globally if it was closed for a scene app + VREvent_KeyboardCharInput = 1201, + VREvent_KeyboardDone = 1202, // Sent when DONE button clicked on keyboard + VREvent_KeyboardOpened_Global = 1203, // Sent globally when the keyboard is opened. data.keyboard.overlayHandle is who it was opened for (scene app if k_ulOverlayHandleInvalid) + VREvent_KeyboardClosed_Global = 1204, // Sent globally when the keyboard is closed. data.keyboard.overlayHandle is who it was opened for (scene app if k_ulOverlayHandleInvalid) + + //VREvent_ApplicationTransitionStarted = 1300, + //VREvent_ApplicationTransitionAborted = 1301, + //VREvent_ApplicationTransitionNewAppStarted = 1302, + VREvent_ApplicationListUpdated = 1303, + VREvent_ApplicationMimeTypeLoad = 1304, + // VREvent_ApplicationTransitionNewAppLaunchComplete = 1305, + VREvent_ProcessConnected = 1306, + VREvent_ProcessDisconnected = 1307, + + //VREvent_Compositor_MirrorWindowShown = 1400, // DEPRECATED + //VREvent_Compositor_MirrorWindowHidden = 1401, // DEPRECATED + VREvent_Compositor_ChaperoneBoundsShown = 1410, + VREvent_Compositor_ChaperoneBoundsHidden = 1411, + VREvent_Compositor_DisplayDisconnected = 1412, + VREvent_Compositor_DisplayReconnected = 1413, + VREvent_Compositor_HDCPError = 1414, // data is hdcpError + VREvent_Compositor_ApplicationNotResponding = 1415, + VREvent_Compositor_ApplicationResumed = 1416, + VREvent_Compositor_OutOfVideoMemory = 1417, + VREvent_Compositor_DisplayModeNotSupported = 1418, // k_pch_SteamVR_PreferredRefreshRate + VREvent_Compositor_StageOverrideReady = 1419, + VREvent_Compositor_RequestDisconnectReconnect = 1420, + + VREvent_TrackedCamera_StartVideoStream = 1500, + VREvent_TrackedCamera_StopVideoStream = 1501, + VREvent_TrackedCamera_PauseVideoStream = 1502, + VREvent_TrackedCamera_ResumeVideoStream = 1503, + VREvent_TrackedCamera_EditingSurface = 1550, + + VREvent_PerformanceTest_EnableCapture = 1600, + VREvent_PerformanceTest_DisableCapture = 1601, + VREvent_PerformanceTest_FidelityLevel = 1602, + + VREvent_MessageOverlay_Closed = 1650, + VREvent_MessageOverlayCloseRequested = 1651, + + VREvent_Input_HapticVibration = 1700, // data is hapticVibration + VREvent_Input_BindingLoadFailed = 1701, // data is inputBinding + VREvent_Input_BindingLoadSuccessful = 1702, // data is inputBinding + VREvent_Input_ActionManifestReloaded = 1703, // no data + VREvent_Input_ActionManifestLoadFailed = 1704, // data is actionManifest + VREvent_Input_ProgressUpdate = 1705, // data is progressUpdate + VREvent_Input_TrackerActivated = 1706, + VREvent_Input_BindingsUpdated = 1707, + VREvent_Input_BindingSubscriptionChanged = 1708, + + VREvent_SpatialAnchors_PoseUpdated = 1800, // data is spatialAnchor. broadcast + VREvent_SpatialAnchors_DescriptorUpdated = 1801, // data is spatialAnchor. broadcast + VREvent_SpatialAnchors_RequestPoseUpdate = 1802, // data is spatialAnchor. sent to specific driver + VREvent_SpatialAnchors_RequestDescriptorUpdate = 1803, // data is spatialAnchor. sent to specific driver + + VREvent_SystemReport_Started = 1900, // user or system initiated generation of a system report. broadcast + + VREvent_Monitor_ShowHeadsetView = 2000, // data is process + VREvent_Monitor_HideHeadsetView = 2001, // data is process + + // Vendors are free to expose private events in this reserved region + VREvent_VendorSpecific_Reserved_Start = 10000, + VREvent_VendorSpecific_Reserved_End = 19999, +}; + + +/** Level of Hmd activity */ +// UserInteraction_Timeout means the device is in the process of timing out. +// InUse = ( k_EDeviceActivityLevel_UserInteraction || k_EDeviceActivityLevel_UserInteraction_Timeout ) +// VREvent_TrackedDeviceUserInteractionStarted fires when the devices transitions from Standby -> UserInteraction or Idle -> UserInteraction. +// VREvent_TrackedDeviceUserInteractionEnded fires when the devices transitions from UserInteraction_Timeout -> Idle +enum EDeviceActivityLevel +{ + k_EDeviceActivityLevel_Unknown = -1, + k_EDeviceActivityLevel_Idle = 0, // No activity for the last 10 seconds + k_EDeviceActivityLevel_UserInteraction = 1, // Activity (movement or prox sensor) is happening now + k_EDeviceActivityLevel_UserInteraction_Timeout = 2, // No activity for the last 0.5 seconds + k_EDeviceActivityLevel_Standby = 3, // Idle for at least 5 seconds (configurable in Settings -> Power Management) + k_EDeviceActivityLevel_Idle_Timeout = 4, +}; + + +/** VR controller button and axis IDs */ +enum EVRButtonId +{ + k_EButton_System = 0, + k_EButton_ApplicationMenu = 1, + k_EButton_Grip = 2, + k_EButton_DPad_Left = 3, + k_EButton_DPad_Up = 4, + k_EButton_DPad_Right = 5, + k_EButton_DPad_Down = 6, + k_EButton_A = 7, + + k_EButton_ProximitySensor = 31, + + k_EButton_Axis0 = 32, + k_EButton_Axis1 = 33, + k_EButton_Axis2 = 34, + k_EButton_Axis3 = 35, + k_EButton_Axis4 = 36, + + // aliases for well known controllers + k_EButton_SteamVR_Touchpad = k_EButton_Axis0, + k_EButton_SteamVR_Trigger = k_EButton_Axis1, + + k_EButton_Dashboard_Back = k_EButton_Grip, + + k_EButton_IndexController_A = k_EButton_Grip, + k_EButton_IndexController_B = k_EButton_ApplicationMenu, + k_EButton_IndexController_JoyStick = k_EButton_Axis3, + + k_EButton_Reserved0 = 50, + k_EButton_Reserved1 = 51, + + k_EButton_Max = 64 +}; + +inline uint64_t ButtonMaskFromId( EVRButtonId id ) { return 1ull << id; } + +/** used for controller button events */ +struct VREvent_Controller_t +{ + uint32_t button; // EVRButtonId enum +}; + + +/** used for simulated mouse events in overlay space */ +enum EVRMouseButton +{ + VRMouseButton_Left = 0x0001, + VRMouseButton_Right = 0x0002, + VRMouseButton_Middle = 0x0004, +}; + + +/** used for simulated mouse events in overlay space */ +struct VREvent_Mouse_t +{ + float x, y; // co-ords are in GL space, bottom left of the texture is 0,0 + uint32_t button; // EVRMouseButton enum +}; + +/** used for simulated mouse wheel scroll */ +struct VREvent_Scroll_t +{ + float xdelta, ydelta; + uint32_t unused; + float viewportscale; // For scrolling on an overlay with laser mouse, this is the overlay's vertical size relative to the overlay height. Range: [0,1] +}; + +/** when in mouse input mode you can receive data from the touchpad, these events are only sent if the users finger + is on the touchpad (or just released from it). These events are sent to overlays with the VROverlayFlags_SendVRTouchpadEvents + flag set. +**/ +struct VREvent_TouchPadMove_t +{ + // true if the users finger is detected on the touch pad + bool bFingerDown; + + // How long the finger has been down in seconds + float flSecondsFingerDown; + + // These values indicate the starting finger position (so you can do some basic swipe stuff) + float fValueXFirst; + float fValueYFirst; + + // This is the raw sampled coordinate without deadzoning + float fValueXRaw; + float fValueYRaw; +}; + +/** notification related events. Details will still change at this point */ +struct VREvent_Notification_t +{ + uint64_t ulUserValue; + uint32_t notificationId; +}; + +/** Used for events about processes */ +struct VREvent_Process_t +{ + uint32_t pid; + uint32_t oldPid; + bool bForced; + // If the associated event was triggered by a connection loss + bool bConnectionLost; +}; + + +/** Used for a few events about overlays */ +struct VREvent_Overlay_t +{ + uint64_t overlayHandle; // VROverlayHandle_t + uint64_t devicePath; + uint64_t memoryBlockId; +}; + + +/** Used for a few events about overlays */ +struct VREvent_Status_t +{ + uint32_t statusState; // EVRState enum +}; + +/** Used for keyboard events */ +struct VREvent_Keyboard_t +{ + char cNewInput[8]; // 7 bytes of utf8 + null + uint64_t uUserValue; // caller specified opaque token + uint64_t overlayHandle; // VROverlayHandle_t +}; + +struct VREvent_Ipd_t +{ + float ipdMeters; +}; + +struct VREvent_Chaperone_t +{ + uint64_t m_nPreviousUniverse; + uint64_t m_nCurrentUniverse; +}; + +/** Not actually used for any events */ +struct VREvent_Reserved_t +{ + uint64_t reserved0; + uint64_t reserved1; + uint64_t reserved2; + uint64_t reserved3; + uint64_t reserved4; + uint64_t reserved5; +}; + +struct VREvent_PerformanceTest_t +{ + uint32_t m_nFidelityLevel; +}; + +struct VREvent_SeatedZeroPoseReset_t +{ + bool bResetBySystemMenu; +}; + +struct VREvent_Screenshot_t +{ + uint32_t handle; + uint32_t type; +}; + +struct VREvent_ScreenshotProgress_t +{ + float progress; +}; + +struct VREvent_ApplicationLaunch_t +{ + uint32_t pid; + uint32_t unArgsHandle; +}; + +struct VREvent_EditingCameraSurface_t +{ + uint64_t overlayHandle; + uint32_t nVisualMode; +}; + +struct VREvent_MessageOverlay_t +{ + uint32_t unVRMessageOverlayResponse; // vr::VRMessageOverlayResponse enum +}; + +struct VREvent_Property_t +{ + PropertyContainerHandle_t container; + ETrackedDeviceProperty prop; +}; + +struct VREvent_HapticVibration_t +{ + uint64_t containerHandle; // property container handle of the device with the haptic component + uint64_t componentHandle; // Which haptic component needs to vibrate + float fDurationSeconds; + float fFrequency; + float fAmplitude; +}; + +struct VREvent_WebConsole_t +{ + WebConsoleHandle_t webConsoleHandle; +}; + +struct VREvent_InputBindingLoad_t +{ + vr::PropertyContainerHandle_t ulAppContainer; + uint64_t pathMessage; + uint64_t pathUrl; + uint64_t pathControllerType; +}; + +struct VREvent_InputActionManifestLoad_t +{ + uint64_t pathAppKey; + uint64_t pathMessage; + uint64_t pathMessageParam; + uint64_t pathManifestPath; +}; + +struct VREvent_SpatialAnchor_t +{ + SpatialAnchorHandle_t unHandle; +}; + +struct VREvent_ProgressUpdate_t +{ + uint64_t ulApplicationPropertyContainer; + uint64_t pathDevice; + uint64_t pathInputSource; + uint64_t pathProgressAction; + uint64_t pathIcon; + float fProgress; +}; + +enum EShowUIType +{ + ShowUI_ControllerBinding = 0, + ShowUI_ManageTrackers = 1, + // ShowUI_QuickStart = 2, // Deprecated + ShowUI_Pairing = 3, + ShowUI_Settings = 4, + ShowUI_DebugCommands = 5, + ShowUI_FullControllerBinding = 6, + ShowUI_ManageDrivers = 7, +}; + +struct VREvent_ShowUI_t +{ + EShowUIType eType; +}; + +struct VREvent_ShowDevTools_t +{ + int32_t nBrowserIdentifier; +}; + +enum EHDCPError +{ + HDCPError_None = 0, + HDCPError_LinkLost = 1, + HDCPError_Tampered = 2, + HDCPError_DeviceRevoked = 3, + HDCPError_Unknown = 4 +}; + +struct VREvent_HDCPError_t +{ + EHDCPError eCode; +}; + +typedef union +{ + VREvent_Reserved_t reserved; + VREvent_Controller_t controller; + VREvent_Mouse_t mouse; + VREvent_Scroll_t scroll; + VREvent_Process_t process; + VREvent_Notification_t notification; + VREvent_Overlay_t overlay; + VREvent_Status_t status; + VREvent_Keyboard_t keyboard; + VREvent_Ipd_t ipd; + VREvent_Chaperone_t chaperone; + VREvent_PerformanceTest_t performanceTest; + VREvent_TouchPadMove_t touchPadMove; + VREvent_SeatedZeroPoseReset_t seatedZeroPoseReset; + VREvent_Screenshot_t screenshot; + VREvent_ScreenshotProgress_t screenshotProgress; + VREvent_ApplicationLaunch_t applicationLaunch; + VREvent_EditingCameraSurface_t cameraSurface; + VREvent_MessageOverlay_t messageOverlay; + VREvent_Property_t property; + VREvent_HapticVibration_t hapticVibration; + VREvent_WebConsole_t webConsole; + VREvent_InputBindingLoad_t inputBinding; + VREvent_InputActionManifestLoad_t actionManifest; + VREvent_SpatialAnchor_t spatialAnchor; + VREvent_ProgressUpdate_t progressUpdate; + VREvent_ShowUI_t showUi; + VREvent_ShowDevTools_t showDevTools; + VREvent_HDCPError_t hdcpError; + /** NOTE!!! If you change this you MUST manually update openvr_interop.cs.py */ +} VREvent_Data_t; + + +#if defined(__linux__) || defined(__APPLE__) +// This structure was originally defined mis-packed on Linux, preserved for +// compatibility. +#pragma pack( push, 4 ) +#endif + +/** An event posted by the server to all running applications */ +struct VREvent_t +{ + uint32_t eventType; // EVREventType enum + TrackedDeviceIndex_t trackedDeviceIndex; + float eventAgeSeconds; + // event data must be the end of the struct as its size is variable + VREvent_Data_t data; +}; + +#if defined(__linux__) || defined(__APPLE__) +#pragma pack( pop ) +#endif + +typedef uint32_t VRComponentProperties; + +enum EVRComponentProperty +{ + VRComponentProperty_IsStatic = (1 << 0), + VRComponentProperty_IsVisible = (1 << 1), + VRComponentProperty_IsTouched = (1 << 2), + VRComponentProperty_IsPressed = (1 << 3), + VRComponentProperty_IsScrolled = (1 << 4), + VRComponentProperty_IsHighlighted = (1 << 5), +}; + + +/** Describes state information about a render-model component, including transforms and other dynamic properties */ +struct RenderModel_ComponentState_t +{ + HmdMatrix34_t mTrackingToComponentRenderModel; // Transform required when drawing the component render model + HmdMatrix34_t mTrackingToComponentLocal; // Transform available for attaching to a local component coordinate system (-Z out from surface ) + VRComponentProperties uProperties; +}; + + +enum EVRInputError +{ + VRInputError_None = 0, + VRInputError_NameNotFound = 1, + VRInputError_WrongType = 2, + VRInputError_InvalidHandle = 3, + VRInputError_InvalidParam = 4, + VRInputError_NoSteam = 5, + VRInputError_MaxCapacityReached = 6, + VRInputError_IPCError = 7, + VRInputError_NoActiveActionSet = 8, + VRInputError_InvalidDevice = 9, + VRInputError_InvalidSkeleton = 10, + VRInputError_InvalidBoneCount = 11, + VRInputError_InvalidCompressedData = 12, + VRInputError_NoData = 13, + VRInputError_BufferTooSmall = 14, + VRInputError_MismatchedActionManifest = 15, + VRInputError_MissingSkeletonData = 16, + VRInputError_InvalidBoneIndex = 17, + VRInputError_InvalidPriority = 18, + VRInputError_PermissionDenied = 19, + VRInputError_InvalidRenderModel = 20, +}; + +enum EVRSpatialAnchorError +{ + VRSpatialAnchorError_Success = 0, + VRSpatialAnchorError_Internal = 1, + VRSpatialAnchorError_UnknownHandle = 2, + VRSpatialAnchorError_ArrayTooSmall = 3, + VRSpatialAnchorError_InvalidDescriptorChar = 4, + VRSpatialAnchorError_NotYetAvailable = 5, + VRSpatialAnchorError_NotAvailableInThisUniverse = 6, + VRSpatialAnchorError_PermanentlyUnavailable = 7, + VRSpatialAnchorError_WrongDriver = 8, + VRSpatialAnchorError_DescriptorTooLong = 9, + VRSpatialAnchorError_Unknown = 10, + VRSpatialAnchorError_NoRoomCalibration = 11, + VRSpatialAnchorError_InvalidArgument = 12, + VRSpatialAnchorError_UnknownDriver = 13, +}; + +/** The mesh to draw into the stencil (or depth) buffer to perform +* early stencil (or depth) kills of pixels that will never appear on the HMD. +* This mesh draws on all the pixels that will be hidden after distortion. +* +* If the HMD does not provide a visible area mesh pVertexData will be +* NULL and unTriangleCount will be 0. */ +struct HiddenAreaMesh_t +{ + const HmdVector2_t *pVertexData; + uint32_t unTriangleCount; +}; + + +enum EHiddenAreaMeshType +{ + k_eHiddenAreaMesh_Standard = 0, + k_eHiddenAreaMesh_Inverse = 1, + k_eHiddenAreaMesh_LineLoop = 2, + + k_eHiddenAreaMesh_Max = 3, +}; + + +/** Identifies what kind of axis is on the controller at index n. Read this type +* with pVRSystem->Get( nControllerDeviceIndex, Prop_Axis0Type_Int32 + n ); +*/ +enum EVRControllerAxisType +{ + k_eControllerAxis_None = 0, + k_eControllerAxis_TrackPad = 1, + k_eControllerAxis_Joystick = 2, + k_eControllerAxis_Trigger = 3, // Analog trigger data is in the X axis +}; + + +/** contains information about one axis on the controller */ +struct VRControllerAxis_t +{ + float x; // Ranges from -1.0 to 1.0 for joysticks and track pads. Ranges from 0.0 to 1.0 for triggers were 0 is fully released. + float y; // Ranges from -1.0 to 1.0 for joysticks and track pads. Is always 0.0 for triggers. +}; + + +/** the number of axes in the controller state */ +static const uint32_t k_unControllerStateAxisCount = 5; + + +#if defined(__linux__) || defined(__APPLE__) +// This structure was originally defined mis-packed on Linux, preserved for +// compatibility. +#pragma pack( push, 4 ) +#endif + +/** Holds all the state of a controller at one moment in time. */ +struct VRControllerState001_t +{ + // If packet num matches that on your prior call, then the controller state hasn't been changed since + // your last call and there is no need to process it + uint32_t unPacketNum; + + // bit flags for each of the buttons. Use ButtonMaskFromId to turn an ID into a mask + uint64_t ulButtonPressed; + uint64_t ulButtonTouched; + + // Axis data for the controller's analog inputs + VRControllerAxis_t rAxis[ k_unControllerStateAxisCount ]; +}; +#if defined(__linux__) || defined(__APPLE__) +#pragma pack( pop ) +#endif + + +typedef VRControllerState001_t VRControllerState_t; + + +/** determines how to provide output to the application of various event processing functions. */ +enum EVRControllerEventOutputType +{ + ControllerEventOutput_OSEvents = 0, + ControllerEventOutput_VREvents = 1, +}; + + + +/** Collision Bounds Style */ +enum ECollisionBoundsStyle +{ + COLLISION_BOUNDS_STYLE_BEGINNER = 0, + COLLISION_BOUNDS_STYLE_INTERMEDIATE, + COLLISION_BOUNDS_STYLE_SQUARES, + COLLISION_BOUNDS_STYLE_ADVANCED, + COLLISION_BOUNDS_STYLE_NONE, + + COLLISION_BOUNDS_STYLE_COUNT +}; + +/** used to refer to a single VR overlay */ +typedef uint64_t VROverlayHandle_t; + +static const VROverlayHandle_t k_ulOverlayHandleInvalid = 0; + +/** Errors that can occur around VR overlays */ +enum EVROverlayError +{ + VROverlayError_None = 0, + + VROverlayError_UnknownOverlay = 10, + VROverlayError_InvalidHandle = 11, + VROverlayError_PermissionDenied = 12, + VROverlayError_OverlayLimitExceeded = 13, // No more overlays could be created because the maximum number already exist + VROverlayError_WrongVisibilityType = 14, + VROverlayError_KeyTooLong = 15, + VROverlayError_NameTooLong = 16, + VROverlayError_KeyInUse = 17, + VROverlayError_WrongTransformType = 18, + VROverlayError_InvalidTrackedDevice = 19, + VROverlayError_InvalidParameter = 20, + VROverlayError_ThumbnailCantBeDestroyed = 21, + VROverlayError_ArrayTooSmall = 22, + VROverlayError_RequestFailed = 23, + VROverlayError_InvalidTexture = 24, + VROverlayError_UnableToLoadFile = 25, + VROverlayError_KeyboardAlreadyInUse = 26, + VROverlayError_NoNeighbor = 27, + VROverlayError_TooManyMaskPrimitives = 29, + VROverlayError_BadMaskPrimitive = 30, + VROverlayError_TextureAlreadyLocked = 31, + VROverlayError_TextureLockCapacityReached = 32, + VROverlayError_TextureNotLocked = 33, + VROverlayError_TimedOut = 34, +}; + +/** enum values to pass in to VR_Init to identify whether the application will +* draw a 3D scene. */ +enum EVRApplicationType +{ + VRApplication_Other = 0, // Some other kind of application that isn't covered by the other entries + VRApplication_Scene = 1, // Application will submit 3D frames + VRApplication_Overlay = 2, // Application only interacts with overlays + VRApplication_Background = 3, // Application should not start SteamVR if it's not already running, and should not + // keep it running if everything else quits. + VRApplication_Utility = 4, // Init should not try to load any drivers. The application needs access to utility + // interfaces (like IVRSettings and IVRApplications) but not hardware. + VRApplication_VRMonitor = 5, // Reserved for vrmonitor + VRApplication_SteamWatchdog = 6,// Reserved for Steam + VRApplication_Bootstrapper = 7, // reserved for vrstartup + VRApplication_WebHelper = 8, // reserved for vrwebhelper + VRApplication_OpenXRInstance = 9, // reserved for openxr (created instance, but not session yet) + VRApplication_OpenXRScene = 10, // reserved for openxr (started session) + VRApplication_OpenXROverlay = 11, // reserved for openxr (started overlay session) + VRApplication_Prism = 12, // reserved for the vrprismhost process + VRApplication_RoomView = 13, // reserved for the RoomView process + + VRApplication_Max +}; + + +/** returns true if the specified application type is one of the +* OpenXR types */ +inline bool IsOpenXRAppType( EVRApplicationType eType ) +{ + return eType == VRApplication_OpenXRInstance + || eType == VRApplication_OpenXRScene + || eType == VRApplication_OpenXROverlay; +} + + +/** returns true if the specified application type submits eye buffers */ +inline bool BAppTypeSubmitsEyeBuffers( EVRApplicationType eType ) +{ + return eType == VRApplication_Scene + || eType == VRApplication_OpenXRScene + || eType == VRApplication_RoomView; +} + + +/** error codes for firmware */ +enum EVRFirmwareError +{ + VRFirmwareError_None = 0, + VRFirmwareError_Success = 1, + VRFirmwareError_Fail = 2, +}; + + +/** error codes for notifications */ +enum EVRNotificationError +{ + VRNotificationError_OK = 0, + VRNotificationError_InvalidNotificationId = 100, + VRNotificationError_NotificationQueueFull = 101, + VRNotificationError_InvalidOverlayHandle = 102, + VRNotificationError_SystemWithUserValueAlreadyExists = 103, +}; + + +enum EVRSkeletalMotionRange +{ + // The range of motion of the skeleton takes into account any physical limits imposed by + // the controller itself. This will tend to be the most accurate pose compared to the user's + // actual hand pose, but might not allow a closed fist for example + VRSkeletalMotionRange_WithController = 0, + + // Retarget the range of motion provided by the input device to make the hand appear to move + // as if it was not holding a controller. eg: map "hand grasping controller" to "closed fist" + VRSkeletalMotionRange_WithoutController = 1, +}; + +enum EVRSkeletalTrackingLevel +{ + // body part location can't be directly determined by the device. Any skeletal pose provided by + // the device is estimated by assuming the position required to active buttons, triggers, joysticks, + // or other input sensors. + // E.g. Vive Controller, Gamepad + VRSkeletalTracking_Estimated = 0, + + // body part location can be measured directly but with fewer degrees of freedom than the actual body + // part. Certain body part positions may be unmeasured by the device and estimated from other input data. + // E.g. Index Controllers, gloves that only measure finger curl + VRSkeletalTracking_Partial = 1, + + // Body part location can be measured directly throughout the entire range of motion of the body part. + // E.g. Mocap suit for the full body, gloves that measure rotation of each finger segment + VRSkeletalTracking_Full = 2, + + VRSkeletalTrackingLevel_Count, + VRSkeletalTrackingLevel_Max = VRSkeletalTrackingLevel_Count - 1 +}; + + +/** Type used for referring to bones by their index */ +typedef int32_t BoneIndex_t; +const BoneIndex_t k_unInvalidBoneIndex = -1; + + +/** error codes returned by Vr_Init */ + +// Please add adequate error description to https://developer.valvesoftware.com/w/index.php?title=Category:SteamVRHelp +enum EVRInitError +{ + VRInitError_None = 0, + VRInitError_Unknown = 1, + + VRInitError_Init_InstallationNotFound = 100, + VRInitError_Init_InstallationCorrupt = 101, + VRInitError_Init_VRClientDLLNotFound = 102, + VRInitError_Init_FileNotFound = 103, + VRInitError_Init_FactoryNotFound = 104, + VRInitError_Init_InterfaceNotFound = 105, + VRInitError_Init_InvalidInterface = 106, + VRInitError_Init_UserConfigDirectoryInvalid = 107, + VRInitError_Init_HmdNotFound = 108, + VRInitError_Init_NotInitialized = 109, + VRInitError_Init_PathRegistryNotFound = 110, + VRInitError_Init_NoConfigPath = 111, + VRInitError_Init_NoLogPath = 112, + VRInitError_Init_PathRegistryNotWritable = 113, + VRInitError_Init_AppInfoInitFailed = 114, + VRInitError_Init_Retry = 115, // Used internally to cause retries to vrserver + VRInitError_Init_InitCanceledByUser = 116, // The calling application should silently exit. The user canceled app startup + VRInitError_Init_AnotherAppLaunching = 117, + VRInitError_Init_SettingsInitFailed = 118, + VRInitError_Init_ShuttingDown = 119, + VRInitError_Init_TooManyObjects = 120, + VRInitError_Init_NoServerForBackgroundApp = 121, + VRInitError_Init_NotSupportedWithCompositor = 122, + VRInitError_Init_NotAvailableToUtilityApps = 123, + VRInitError_Init_Internal = 124, + VRInitError_Init_HmdDriverIdIsNone = 125, + VRInitError_Init_HmdNotFoundPresenceFailed = 126, + VRInitError_Init_VRMonitorNotFound = 127, + VRInitError_Init_VRMonitorStartupFailed = 128, + VRInitError_Init_LowPowerWatchdogNotSupported = 129, + VRInitError_Init_InvalidApplicationType = 130, + VRInitError_Init_NotAvailableToWatchdogApps = 131, + VRInitError_Init_WatchdogDisabledInSettings = 132, + VRInitError_Init_VRDashboardNotFound = 133, + VRInitError_Init_VRDashboardStartupFailed = 134, + VRInitError_Init_VRHomeNotFound = 135, + VRInitError_Init_VRHomeStartupFailed = 136, + VRInitError_Init_RebootingBusy = 137, + VRInitError_Init_FirmwareUpdateBusy = 138, + VRInitError_Init_FirmwareRecoveryBusy = 139, + VRInitError_Init_USBServiceBusy = 140, + VRInitError_Init_VRWebHelperStartupFailed = 141, + VRInitError_Init_TrackerManagerInitFailed = 142, + VRInitError_Init_AlreadyRunning = 143, + VRInitError_Init_FailedForVrMonitor = 144, + VRInitError_Init_PropertyManagerInitFailed = 145, + VRInitError_Init_WebServerFailed = 146, + VRInitError_Init_IllegalTypeTransition = 147, + VRInitError_Init_MismatchedRuntimes = 148, + VRInitError_Init_InvalidProcessId = 149, + VRInitError_Init_VRServiceStartupFailed = 150, + VRInitError_Init_PrismNeedsNewDrivers = 151, + VRInitError_Init_PrismStartupTimedOut = 152, + VRInitError_Init_CouldNotStartPrism = 153, + VRInitError_Init_PrismClientInitFailed = 154, + VRInitError_Init_PrismClientStartFailed = 155, + VRInitError_Init_PrismExitedUnexpectedly = 156, + VRInitError_Init_BadLuid = 157, + VRInitError_Init_NoServerForAppContainer = 158, + VRInitError_Init_DuplicateBootstrapper = 159, + VRInitError_Init_VRDashboardServicePending = 160, + VRInitError_Init_VRDashboardServiceTimeout = 161, + VRInitError_Init_VRDashboardServiceStopped = 162, + VRInitError_Init_VRDashboardAlreadyStarted = 163, + VRInitError_Init_VRDashboardCopyFailed = 164, + VRInitError_Init_VRDashboardTokenFailure = 165, + VRInitError_Init_VRDashboardEnvironmentFailure = 166, + VRInitError_Init_VRDashboardPathFailure = 167, + + VRInitError_Driver_Failed = 200, + VRInitError_Driver_Unknown = 201, + VRInitError_Driver_HmdUnknown = 202, + VRInitError_Driver_NotLoaded = 203, + VRInitError_Driver_RuntimeOutOfDate = 204, + VRInitError_Driver_HmdInUse = 205, + VRInitError_Driver_NotCalibrated = 206, + VRInitError_Driver_CalibrationInvalid = 207, + VRInitError_Driver_HmdDisplayNotFound = 208, + VRInitError_Driver_TrackedDeviceInterfaceUnknown = 209, + // VRInitError_Driver_HmdDisplayNotFoundAfterFix = 210, // not needed: here for historic reasons + VRInitError_Driver_HmdDriverIdOutOfBounds = 211, + VRInitError_Driver_HmdDisplayMirrored = 212, + VRInitError_Driver_HmdDisplayNotFoundLaptop = 213, + VRInitError_Driver_PeerDriverNotInstalled = 214, + VRInitError_Driver_WirelessHmdNotConnected = 215, + + // Never make error 259 because we return it from main and it would conflict with STILL_ACTIVE + + VRInitError_IPC_ServerInitFailed = 300, + VRInitError_IPC_ConnectFailed = 301, + VRInitError_IPC_SharedStateInitFailed = 302, + VRInitError_IPC_CompositorInitFailed = 303, + VRInitError_IPC_MutexInitFailed = 304, + VRInitError_IPC_Failed = 305, + VRInitError_IPC_CompositorConnectFailed = 306, + VRInitError_IPC_CompositorInvalidConnectResponse = 307, + VRInitError_IPC_ConnectFailedAfterMultipleAttempts = 308, + VRInitError_IPC_ConnectFailedAfterTargetExited = 309, + VRInitError_IPC_NamespaceUnavailable = 310, + + VRInitError_Compositor_Failed = 400, + VRInitError_Compositor_D3D11HardwareRequired = 401, + VRInitError_Compositor_FirmwareRequiresUpdate = 402, + VRInitError_Compositor_OverlayInitFailed = 403, + VRInitError_Compositor_ScreenshotsInitFailed = 404, + VRInitError_Compositor_UnableToCreateDevice = 405, + VRInitError_Compositor_SharedStateIsNull = 406, + VRInitError_Compositor_NotificationManagerIsNull = 407, + VRInitError_Compositor_ResourceManagerClientIsNull = 408, + VRInitError_Compositor_MessageOverlaySharedStateInitFailure = 409, + VRInitError_Compositor_PropertiesInterfaceIsNull = 410, + VRInitError_Compositor_CreateFullscreenWindowFailed = 411, + VRInitError_Compositor_SettingsInterfaceIsNull = 412, + VRInitError_Compositor_FailedToShowWindow = 413, + VRInitError_Compositor_DistortInterfaceIsNull = 414, + VRInitError_Compositor_DisplayFrequencyFailure = 415, + VRInitError_Compositor_RendererInitializationFailed = 416, + VRInitError_Compositor_DXGIFactoryInterfaceIsNull = 417, + VRInitError_Compositor_DXGIFactoryCreateFailed = 418, + VRInitError_Compositor_DXGIFactoryQueryFailed = 419, + VRInitError_Compositor_InvalidAdapterDesktop = 420, + VRInitError_Compositor_InvalidHmdAttachment = 421, + VRInitError_Compositor_InvalidOutputDesktop = 422, + VRInitError_Compositor_InvalidDeviceProvided = 423, + VRInitError_Compositor_D3D11RendererInitializationFailed = 424, + VRInitError_Compositor_FailedToFindDisplayMode = 425, + VRInitError_Compositor_FailedToCreateSwapChain = 426, + VRInitError_Compositor_FailedToGetBackBuffer = 427, + VRInitError_Compositor_FailedToCreateRenderTarget = 428, + VRInitError_Compositor_FailedToCreateDXGI2SwapChain = 429, + VRInitError_Compositor_FailedtoGetDXGI2BackBuffer = 430, + VRInitError_Compositor_FailedToCreateDXGI2RenderTarget = 431, + VRInitError_Compositor_FailedToGetDXGIDeviceInterface = 432, + VRInitError_Compositor_SelectDisplayMode = 433, + VRInitError_Compositor_FailedToCreateNvAPIRenderTargets = 434, + VRInitError_Compositor_NvAPISetDisplayMode = 435, + VRInitError_Compositor_FailedToCreateDirectModeDisplay = 436, + VRInitError_Compositor_InvalidHmdPropertyContainer = 437, + VRInitError_Compositor_UpdateDisplayFrequency = 438, + VRInitError_Compositor_CreateRasterizerState = 439, + VRInitError_Compositor_CreateWireframeRasterizerState = 440, + VRInitError_Compositor_CreateSamplerState = 441, + VRInitError_Compositor_CreateClampToBorderSamplerState = 442, + VRInitError_Compositor_CreateAnisoSamplerState = 443, + VRInitError_Compositor_CreateOverlaySamplerState = 444, + VRInitError_Compositor_CreatePanoramaSamplerState = 445, + VRInitError_Compositor_CreateFontSamplerState = 446, + VRInitError_Compositor_CreateNoBlendState = 447, + VRInitError_Compositor_CreateBlendState = 448, + VRInitError_Compositor_CreateAlphaBlendState = 449, + VRInitError_Compositor_CreateBlendStateMaskR = 450, + VRInitError_Compositor_CreateBlendStateMaskG = 451, + VRInitError_Compositor_CreateBlendStateMaskB = 452, + VRInitError_Compositor_CreateDepthStencilState = 453, + VRInitError_Compositor_CreateDepthStencilStateNoWrite = 454, + VRInitError_Compositor_CreateDepthStencilStateNoDepth = 455, + VRInitError_Compositor_CreateFlushTexture = 456, + VRInitError_Compositor_CreateDistortionSurfaces = 457, + VRInitError_Compositor_CreateConstantBuffer = 458, + VRInitError_Compositor_CreateHmdPoseConstantBuffer = 459, + VRInitError_Compositor_CreateHmdPoseStagingConstantBuffer = 460, + VRInitError_Compositor_CreateSharedFrameInfoConstantBuffer = 461, + VRInitError_Compositor_CreateOverlayConstantBuffer = 462, + VRInitError_Compositor_CreateSceneTextureIndexConstantBuffer = 463, + VRInitError_Compositor_CreateReadableSceneTextureIndexConstantBuffer = 464, + VRInitError_Compositor_CreateLayerGraphicsTextureIndexConstantBuffer = 465, + VRInitError_Compositor_CreateLayerComputeTextureIndexConstantBuffer = 466, + VRInitError_Compositor_CreateLayerComputeSceneTextureIndexConstantBuffer = 467, + VRInitError_Compositor_CreateComputeHmdPoseConstantBuffer = 468, + VRInitError_Compositor_CreateGeomConstantBuffer = 469, + VRInitError_Compositor_CreatePanelMaskConstantBuffer = 470, + VRInitError_Compositor_CreatePixelSimUBO = 471, + VRInitError_Compositor_CreateMSAARenderTextures = 472, + VRInitError_Compositor_CreateResolveRenderTextures = 473, + VRInitError_Compositor_CreateComputeResolveRenderTextures = 474, + VRInitError_Compositor_CreateDriverDirectModeResolveTextures = 475, + VRInitError_Compositor_OpenDriverDirectModeResolveTextures = 476, + VRInitError_Compositor_CreateFallbackSyncTexture = 477, + VRInitError_Compositor_ShareFallbackSyncTexture = 478, + VRInitError_Compositor_CreateOverlayIndexBuffer = 479, + VRInitError_Compositor_CreateOverlayVertexBuffer = 480, + VRInitError_Compositor_CreateTextVertexBuffer = 481, + VRInitError_Compositor_CreateTextIndexBuffer = 482, + VRInitError_Compositor_CreateMirrorTextures = 483, + VRInitError_Compositor_CreateLastFrameRenderTexture = 484, + VRInitError_Compositor_CreateMirrorOverlay = 485, + VRInitError_Compositor_FailedToCreateVirtualDisplayBackbuffer = 486, + VRInitError_Compositor_DisplayModeNotSupported = 487, + VRInitError_Compositor_CreateOverlayInvalidCall = 488, + VRInitError_Compositor_CreateOverlayAlreadyInitialized = 489, + VRInitError_Compositor_FailedToCreateMailbox = 490, + VRInitError_Compositor_WindowInterfaceIsNull = 491, + VRInitError_Compositor_SystemLayerCreateInstance = 492, + VRInitError_Compositor_SystemLayerCreateSession = 493, + VRInitError_Compositor_CreateInverseDistortUVs = 494, + VRInitError_Compositor_CreateBackbufferDepth = 495, + VRInitError_Compositor_CannotDRMLeaseDisplay = 496, + VRInitError_Compositor_CannotConnectToDisplayServer = 497, + VRInitError_Compositor_GnomeNoDRMLeasing = 498, + + VRInitError_VendorSpecific_UnableToConnectToOculusRuntime = 1000, + VRInitError_VendorSpecific_WindowsNotInDevMode = 1001, + VRInitError_VendorSpecific_OculusLinkNotEnabled = 1002, + + VRInitError_VendorSpecific_HmdFound_CantOpenDevice = 1101, + VRInitError_VendorSpecific_HmdFound_UnableToRequestConfigStart = 1102, + VRInitError_VendorSpecific_HmdFound_NoStoredConfig = 1103, + VRInitError_VendorSpecific_HmdFound_ConfigTooBig = 1104, + VRInitError_VendorSpecific_HmdFound_ConfigTooSmall = 1105, + VRInitError_VendorSpecific_HmdFound_UnableToInitZLib = 1106, + VRInitError_VendorSpecific_HmdFound_CantReadFirmwareVersion = 1107, + VRInitError_VendorSpecific_HmdFound_UnableToSendUserDataStart = 1108, + VRInitError_VendorSpecific_HmdFound_UnableToGetUserDataStart = 1109, + VRInitError_VendorSpecific_HmdFound_UnableToGetUserDataNext = 1110, + VRInitError_VendorSpecific_HmdFound_UserDataAddressRange = 1111, + VRInitError_VendorSpecific_HmdFound_UserDataError = 1112, + VRInitError_VendorSpecific_HmdFound_ConfigFailedSanityCheck = 1113, + VRInitError_VendorSpecific_OculusRuntimeBadInstall = 1114, + VRInitError_VendorSpecific_HmdFound_UnexpectedConfiguration_1 = 1115, + + VRInitError_Steam_SteamInstallationNotFound = 2000, + + // Strictly a placeholder + VRInitError_LastError +}; + +enum EVRScreenshotType +{ + VRScreenshotType_None = 0, + VRScreenshotType_Mono = 1, // left eye only + VRScreenshotType_Stereo = 2, + VRScreenshotType_Cubemap = 3, + VRScreenshotType_MonoPanorama = 4, + VRScreenshotType_StereoPanorama = 5 +}; + +enum EVRScreenshotPropertyFilenames +{ + VRScreenshotPropertyFilenames_Preview = 0, + VRScreenshotPropertyFilenames_VR = 1, +}; + +enum EVRTrackedCameraError +{ + VRTrackedCameraError_None = 0, + VRTrackedCameraError_OperationFailed = 100, + VRTrackedCameraError_InvalidHandle = 101, + VRTrackedCameraError_InvalidFrameHeaderVersion = 102, + VRTrackedCameraError_OutOfHandles = 103, + VRTrackedCameraError_IPCFailure = 104, + VRTrackedCameraError_NotSupportedForThisDevice = 105, + VRTrackedCameraError_SharedMemoryFailure = 106, + VRTrackedCameraError_FrameBufferingFailure = 107, + VRTrackedCameraError_StreamSetupFailure = 108, + VRTrackedCameraError_InvalidGLTextureId = 109, + VRTrackedCameraError_InvalidSharedTextureHandle = 110, + VRTrackedCameraError_FailedToGetGLTextureId = 111, + VRTrackedCameraError_SharedTextureFailure = 112, + VRTrackedCameraError_NoFrameAvailable = 113, + VRTrackedCameraError_InvalidArgument = 114, + VRTrackedCameraError_InvalidFrameBufferSize = 115, +}; + +enum EVRTrackedCameraFrameLayout +{ + EVRTrackedCameraFrameLayout_Mono = 0x0001, + EVRTrackedCameraFrameLayout_Stereo = 0x0002, + EVRTrackedCameraFrameLayout_VerticalLayout = 0x0010, // Stereo frames are Top/Bottom (left/right) + EVRTrackedCameraFrameLayout_HorizontalLayout = 0x0020, // Stereo frames are Left/Right +}; + +enum EVRTrackedCameraFrameType +{ + VRTrackedCameraFrameType_Distorted = 0, // This is the camera video frame size in pixels, still distorted. + VRTrackedCameraFrameType_Undistorted, // In pixels, an undistorted inscribed rectangle region without invalid regions. This size is subject to changes shortly. + VRTrackedCameraFrameType_MaximumUndistorted, // In pixels, maximum undistorted with invalid regions. Non zero alpha component identifies valid regions. + MAX_CAMERA_FRAME_TYPES +}; + +enum EVRDistortionFunctionType +{ + VRDistortionFunctionType_None, + VRDistortionFunctionType_FTheta, + VRDistortionFunctionType_Extended_FTheta, + MAX_DISTORTION_FUNCTION_TYPES, +}; + +static const uint32_t k_unMaxDistortionFunctionParameters = 8; + +typedef uint64_t TrackedCameraHandle_t; +#define INVALID_TRACKED_CAMERA_HANDLE ((vr::TrackedCameraHandle_t)0) + +struct CameraVideoStreamFrameHeader_t +{ + EVRTrackedCameraFrameType eFrameType; + + uint32_t nWidth; + uint32_t nHeight; + uint32_t nBytesPerPixel; + + uint32_t nFrameSequence; + + TrackedDevicePose_t trackedDevicePose; + + uint64_t ulFrameExposureTime; // mid-point of the exposure of the image in host system ticks +}; + +// Screenshot types +typedef uint32_t ScreenshotHandle_t; + +static const uint32_t k_unScreenshotHandleInvalid = 0; + +/** Compositor frame timing reprojection flags. */ +const uint32_t VRCompositor_ReprojectionReason_Cpu = 0x01; +const uint32_t VRCompositor_ReprojectionReason_Gpu = 0x02; +const uint32_t VRCompositor_ReprojectionAsync = 0x04; // This flag indicates the async reprojection mode is active, + // but does not indicate if reprojection actually happened or not. + // Use the ReprojectionReason flags above to check if reprojection + // was actually applied (i.e. scene texture was reused). + // NumFramePresents > 1 also indicates the scene texture was reused, + // and also the number of times that it was presented in total. + +const uint32_t VRCompositor_ReprojectionMotion = 0x08; // This flag indicates whether or not motion smoothing was triggered for this frame + +const uint32_t VRCompositor_PredictionMask = 0xF0; // The runtime may predict more than one frame (up to four) ahead if + // it detects the application is taking too long to render. These two + // bits will contain the count of additional frames (normally zero). + // Use the VR_COMPOSITOR_ADDITIONAL_PREDICTED_FRAMES macro to read from + // the latest frame timing entry. + +const uint32_t VRCompositor_ThrottleMask = 0xF00; // Number of frames the compositor is throttling the application. + // Use the VR_COMPOSITOR_NUMBER_OF_THROTTLED_FRAMES macro to read from + // the latest frame timing entry. + +#define VR_COMPOSITOR_ADDITIONAL_PREDICTED_FRAMES( timing ) ( ( ( timing ).m_nReprojectionFlags & vr::VRCompositor_PredictionMask ) >> 4 ) +#define VR_COMPOSITOR_NUMBER_OF_THROTTLED_FRAMES( timing ) ( ( ( timing ).m_nReprojectionFlags & vr::VRCompositor_ThrottleMask ) >> 8 ) + +/** Provides a single frame's timing information to the app */ +struct Compositor_FrameTiming +{ + uint32_t m_nSize; // Set to sizeof( Compositor_FrameTiming ) + uint32_t m_nFrameIndex; + uint32_t m_nNumFramePresents; // number of times this frame was presented + uint32_t m_nNumMisPresented; // number of times this frame was presented on a vsync other than it was originally predicted to + uint32_t m_nNumDroppedFrames; // number of additional times previous frame was scanned out + uint32_t m_nReprojectionFlags; + + /** Absolute time reference for comparing frames. This aligns with the vsync that running start is relative to. */ + double m_flSystemTimeInSeconds; + + /** These times may include work from other processes due to OS scheduling. + * The fewer packets of work these are broken up into, the less likely this will happen. + * GPU work can be broken up by calling Flush. This can sometimes be useful to get the GPU started + * processing that work earlier in the frame. */ + float m_flPreSubmitGpuMs; // time spent rendering the scene (gpu work submitted between WaitGetPoses and second Submit) + float m_flPostSubmitGpuMs; // additional time spent rendering by application (e.g. companion window) + float m_flTotalRenderGpuMs; // time between work submitted immediately after present (ideally vsync) until the end of compositor submitted work + float m_flCompositorRenderGpuMs; // time spend performing distortion correction, rendering chaperone, overlays, etc. + float m_flCompositorRenderCpuMs; // time spent on cpu submitting the above work for this frame + float m_flCompositorIdleCpuMs; // time spent waiting for running start (application could have used this much more time) + + /** Miscellaneous measured intervals. */ + float m_flClientFrameIntervalMs; // time between calls to WaitGetPoses + float m_flPresentCallCpuMs; // time blocked on call to present (usually 0.0, but can go long) + float m_flWaitForPresentCpuMs; // time spent spin-waiting for frame index to change (not near-zero indicates wait object failure) + float m_flSubmitFrameMs; // time spent in IVRCompositor::Submit (not near-zero indicates driver issue) + + /** The following are all relative to this frame's SystemTimeInSeconds */ + float m_flWaitGetPosesCalledMs; + float m_flNewPosesReadyMs; + float m_flNewFrameReadyMs; // second call to IVRCompositor::Submit + float m_flCompositorUpdateStartMs; + float m_flCompositorUpdateEndMs; + float m_flCompositorRenderStartMs; + + vr::TrackedDevicePose_t m_HmdPose; // pose used by app to render this frame + + uint32_t m_nNumVSyncsReadyForUse; + uint32_t m_nNumVSyncsToFirstView; +}; + +/** Provides compositor benchmark results to the app */ +struct Compositor_BenchmarkResults +{ + float m_flMegaPixelsPerSecond; // Measurement of GPU MP/s performed by compositor benchmark + float m_flHmdRecommendedMegaPixelsPerSecond; // Recommended default MP/s given the HMD resolution, refresh, and panel mask. +}; + +/** Frame timing data provided by direct mode drivers. */ +struct DriverDirectMode_FrameTiming +{ + uint32_t m_nSize; // Set to sizeof( DriverDirectMode_FrameTiming ) + uint32_t m_nNumFramePresents; // number of times frame was presented + uint32_t m_nNumMisPresented; // number of times frame was presented on a vsync other than it was originally predicted to + uint32_t m_nNumDroppedFrames; // number of additional times previous frame was scanned out (i.e. compositor missed vsync) + uint32_t m_nReprojectionFlags; +}; + +/** These flags will be set on DriverDirectMode_FrameTiming::m_nReprojectionFlags when IVRDriverDirectModeComponent::GetFrameTiming is called for drivers to optionally respond to. */ +const uint32_t VRCompositor_ReprojectionMotion_Enabled = 0x100; // Motion Smoothing is enabled in the UI for the currently running application +const uint32_t VRCompositor_ReprojectionMotion_ForcedOn = 0x200; // Motion Smoothing is forced on in the UI for the currently running application +const uint32_t VRCompositor_ReprojectionMotion_AppThrottled = 0x400; // Application is requesting throttling via ForceInterleavedReprojectionOn + + +enum EVSync +{ + VSync_None, + VSync_WaitRender, // block following render work until vsync + VSync_NoWaitRender, // do not block following render work (allow to get started early) +}; + +enum EVRMuraCorrectionMode +{ + EVRMuraCorrectionMode_Default = 0, + EVRMuraCorrectionMode_NoCorrection +}; + +/** raw IMU data provided by IVRIOBuffer from paths to tracked devices with IMUs */ +enum Imu_OffScaleFlags +{ + OffScale_AccelX = 0x01, + OffScale_AccelY = 0x02, + OffScale_AccelZ = 0x04, + OffScale_GyroX = 0x08, + OffScale_GyroY = 0x10, + OffScale_GyroZ = 0x20, +}; + +struct ImuSample_t +{ + double fSampleTime; + HmdVector3d_t vAccel; + HmdVector3d_t vGyro; + uint32_t unOffScaleFlags; +}; + +#pragma pack( pop ) + +// figure out how to import from the VR API dll +#if defined(_WIN32) + + #if !defined(OPENVR_BUILD_STATIC) + #ifdef VR_API_EXPORT + #define VR_INTERFACE extern "C" __declspec( dllexport ) + #else + #define VR_INTERFACE extern "C" __declspec( dllimport ) + #endif + #else + #define VR_INTERFACE extern "C" + #endif + +#elif defined(__GNUC__) || defined(COMPILER_GCC) || defined(__APPLE__) + +#ifdef VR_API_EXPORT + #define VR_INTERFACE extern "C" __attribute__((visibility("default"))) +#else + #define VR_INTERFACE extern "C" +#endif + +#else + #error "Unsupported Platform." +#endif + + +#if defined( _WIN32 ) + #define VR_CALLTYPE __cdecl +#else + #define VR_CALLTYPE +#endif + +} // namespace vr +#endif // _INCLUDE_VRTYPES_H + +// vrannotation.h + +#ifdef API_GEN +# define VR_CLANG_ATTR(ATTR) __attribute__((annotate( ATTR ))) +#else +# define VR_CLANG_ATTR(ATTR) +#endif + +#define VR_METHOD_DESC(DESC) VR_CLANG_ATTR( "desc:" #DESC ";" ) +#define VR_IGNOREATTR() VR_CLANG_ATTR( "ignore" ) +#define VR_OUT_STRUCT() VR_CLANG_ATTR( "out_struct: ;" ) +#define VR_OUT_STRING() VR_CLANG_ATTR( "out_string: ;" ) +#define VR_OUT_ARRAY_CALL(COUNTER,FUNCTION,PARAMS) VR_CLANG_ATTR( "out_array_call:" #COUNTER "," #FUNCTION "," #PARAMS ";" ) +#define VR_OUT_ARRAY_COUNT(COUNTER) VR_CLANG_ATTR( "out_array_count:" #COUNTER ";" ) +#define VR_ARRAY_COUNT(COUNTER) VR_CLANG_ATTR( "array_count:" #COUNTER ";" ) +#define VR_ARRAY_COUNT_D(COUNTER, DESC) VR_CLANG_ATTR( "array_count:" #COUNTER ";desc:" #DESC ) +#define VR_BUFFER_COUNT(COUNTER) VR_CLANG_ATTR( "buffer_count:" #COUNTER ";" ) +#define VR_OUT_BUFFER_COUNT(COUNTER) VR_CLANG_ATTR( "out_buffer_count:" #COUNTER ";" ) +#define VR_OUT_STRING_COUNT(COUNTER) VR_CLANG_ATTR( "out_string_count:" #COUNTER ";" ) + +// ivrsystem.h + +namespace vr +{ + +class IVRSystem +{ +public: + + + // ------------------------------------ + // Display Methods + // ------------------------------------ + + /** Suggested size for the intermediate render target that the distortion pulls from. */ + virtual void GetRecommendedRenderTargetSize( uint32_t *pnWidth, uint32_t *pnHeight ) = 0; + + /** The projection matrix for the specified eye */ + virtual HmdMatrix44_t GetProjectionMatrix( EVREye eEye, float fNearZ, float fFarZ ) = 0; + + /** The components necessary to build your own projection matrix in case your + * application is doing something fancy like infinite Z */ + virtual void GetProjectionRaw( EVREye eEye, float *pfLeft, float *pfRight, float *pfTop, float *pfBottom ) = 0; + + /** Gets the result of the distortion function for the specified eye and input UVs. UVs go from 0,0 in + * the upper left of that eye's viewport and 1,1 in the lower right of that eye's viewport. + * Returns true for success. Otherwise, returns false, and distortion coordinates are not suitable. */ + virtual bool ComputeDistortion( EVREye eEye, float fU, float fV, DistortionCoordinates_t *pDistortionCoordinates ) = 0; + + /** Returns the transform from eye space to the head space. Eye space is the per-eye flavor of head + * space that provides stereo disparity. Instead of Model * View * Projection the sequence is Model * View * Eye^-1 * Projection. + * Normally View and Eye^-1 will be multiplied together and treated as View in your application. + */ + virtual HmdMatrix34_t GetEyeToHeadTransform( EVREye eEye ) = 0; + + /** Returns the number of elapsed seconds since the last recorded vsync event. This + * will come from a vsync timer event in the timer if possible or from the application-reported + * time if that is not available. If no vsync times are available the function will + * return zero for vsync time and frame counter and return false from the method. */ + virtual bool GetTimeSinceLastVsync( float *pfSecondsSinceLastVsync, uint64_t *pulFrameCounter ) = 0; + + /** [D3D9 Only] + * Returns the adapter index that the user should pass into CreateDevice to set up D3D9 in such + * a way that it can go full screen exclusive on the HMD. Returns -1 if there was an error. + */ + virtual int32_t GetD3D9AdapterIndex() = 0; + + /** [D3D10/11 Only] + * Returns the adapter index that the user should pass into EnumAdapters to create the device + * and swap chain in DX10 and DX11. If an error occurs the index will be set to -1. + */ + virtual void GetDXGIOutputInfo( int32_t *pnAdapterIndex ) = 0; + + /** + * Returns platform- and texture-type specific adapter identification so that applications and the + * compositor are creating textures and swap chains on the same GPU. If an error occurs the device + * will be set to 0. + * pInstance is an optional parameter that is required only when textureType is TextureType_Vulkan. + * [D3D10/11/12 Only (D3D9 Not Supported)] + * Returns the adapter LUID that identifies the GPU attached to the HMD. The user should + * enumerate all adapters using IDXGIFactory::EnumAdapters and IDXGIAdapter::GetDesc to find + * the adapter with the matching LUID, or use IDXGIFactory4::EnumAdapterByLuid. + * The discovered IDXGIAdapter should be used to create the device and swap chain. + * [Vulkan Only] + * Returns the VkPhysicalDevice that should be used by the application. + * pInstance must be the instance the application will use to query for the VkPhysicalDevice. The application + * must create the VkInstance with extensions returned by IVRCompositor::GetVulkanInstanceExtensionsRequired enabled. + * [macOS Only] + * For TextureType_IOSurface returns the id that should be used by the application. + * On 10.13+ for TextureType_OpenGL returns the 'registryId' of the renderer which should be used + * by the application. See Apple Technical Q&A QA1168 for information on enumerating GL Renderers, and the + * new kCGLRPRegistryIDLow and kCGLRPRegistryIDHigh CGLRendererProperty values in the 10.13 SDK. + * Pre 10.13 for TextureType_OpenGL returns 0, as there is no dependable way to correlate the HMDs MTLDevice + * with a GL Renderer. + */ + virtual void GetOutputDevice( uint64_t *pnDevice, ETextureType textureType, VkInstance_T *pInstance = nullptr ) = 0; + + // ------------------------------------ + // Display Mode methods + // ------------------------------------ + + /** Use to determine if the headset display is part of the desktop (i.e. extended) or hidden (i.e. direct mode). */ + virtual bool IsDisplayOnDesktop() = 0; + + /** Set the display visibility (true = extended, false = direct mode). Return value of true indicates that the change was successful. */ + virtual bool SetDisplayVisibility( bool bIsVisibleOnDesktop ) = 0; + + // ------------------------------------ + // Tracking Methods + // ------------------------------------ + + /** The pose that the tracker thinks that the HMD will be in at the specified number of seconds into the + * future. Pass 0 to get the state at the instant the method is called. Most of the time the application should + * calculate the time until the photons will be emitted from the display and pass that time into the method. + * + * This is roughly analogous to the inverse of the view matrix in most applications, though + * many games will need to do some additional rotation or translation on top of the rotation + * and translation provided by the head pose. + * + * For devices where bPoseIsValid is true the application can use the pose to position the device + * in question. The provided array can be any size up to k_unMaxTrackedDeviceCount. + * + * Seated experiences should call this method with TrackingUniverseSeated and receive poses relative + * to the seated zero pose. Standing experiences should call this method with TrackingUniverseStanding + * and receive poses relative to the Chaperone Play Area. TrackingUniverseRawAndUncalibrated should + * probably not be used unless the application is the Chaperone calibration tool itself, but will provide + * poses relative to the hardware-specific coordinate system in the driver. + */ + virtual void GetDeviceToAbsoluteTrackingPose( ETrackingUniverseOrigin eOrigin, float fPredictedSecondsToPhotonsFromNow, VR_ARRAY_COUNT(unTrackedDevicePoseArrayCount) TrackedDevicePose_t *pTrackedDevicePoseArray, uint32_t unTrackedDevicePoseArrayCount ) = 0; + + /** Returns the transform from the seated zero pose to the standing absolute tracking system. This allows + * applications to represent the seated origin to used or transform object positions from one coordinate + * system to the other. + * + * The seated origin may or may not be inside the Play Area or Collision Bounds returned by IVRChaperone. Its position + * depends on what the user has set from the Dashboard settings and previous calls to ResetSeatedZeroPose. */ + virtual HmdMatrix34_t GetSeatedZeroPoseToStandingAbsoluteTrackingPose() = 0; + + /** Returns the transform from the tracking origin to the standing absolute tracking system. This allows + * applications to convert from raw tracking space to the calibrated standing coordinate system. */ + virtual HmdMatrix34_t GetRawZeroPoseToStandingAbsoluteTrackingPose() = 0; + + /** Get a sorted array of device indices of a given class of tracked devices (e.g. controllers). Devices are sorted right to left + * relative to the specified tracked device (default: hmd -- pass in -1 for absolute tracking space). Returns the number of devices + * in the list, or the size of the array needed if not large enough. */ + virtual uint32_t GetSortedTrackedDeviceIndicesOfClass( ETrackedDeviceClass eTrackedDeviceClass, VR_ARRAY_COUNT(unTrackedDeviceIndexArrayCount) vr::TrackedDeviceIndex_t *punTrackedDeviceIndexArray, uint32_t unTrackedDeviceIndexArrayCount, vr::TrackedDeviceIndex_t unRelativeToTrackedDeviceIndex = k_unTrackedDeviceIndex_Hmd ) = 0; + + /** Returns the level of activity on the device. */ + virtual EDeviceActivityLevel GetTrackedDeviceActivityLevel( vr::TrackedDeviceIndex_t unDeviceId ) = 0; + + /** Convenience utility to apply the specified transform to the specified pose. + * This properly transforms all pose components, including velocity and angular velocity + */ + virtual void ApplyTransform( TrackedDevicePose_t *pOutputPose, const TrackedDevicePose_t *pTrackedDevicePose, const HmdMatrix34_t *pTransform ) = 0; + + /** Returns the device index associated with a specific role, for example the left hand or the right hand. This function is deprecated in favor of the new IVRInput system. */ + virtual vr::TrackedDeviceIndex_t GetTrackedDeviceIndexForControllerRole( vr::ETrackedControllerRole unDeviceType ) = 0; + + /** Returns the controller type associated with a device index. This function is deprecated in favor of the new IVRInput system. */ + virtual vr::ETrackedControllerRole GetControllerRoleForTrackedDeviceIndex( vr::TrackedDeviceIndex_t unDeviceIndex ) = 0; + + // ------------------------------------ + // Property methods + // ------------------------------------ + + /** Returns the device class of a tracked device. If there has not been a device connected in this slot + * since the application started this function will return TrackedDevice_Invalid. For previous detected + * devices the function will return the previously observed device class. + * + * To determine which devices exist on the system, just loop from 0 to k_unMaxTrackedDeviceCount and check + * the device class. Every device with something other than TrackedDevice_Invalid is associated with an + * actual tracked device. */ + virtual ETrackedDeviceClass GetTrackedDeviceClass( vr::TrackedDeviceIndex_t unDeviceIndex ) = 0; + + /** Returns true if there is a device connected in this slot. */ + virtual bool IsTrackedDeviceConnected( vr::TrackedDeviceIndex_t unDeviceIndex ) = 0; + + /** Returns a bool property. If the device index is not valid or the property is not a bool type this function will return false. */ + virtual bool GetBoolTrackedDeviceProperty( vr::TrackedDeviceIndex_t unDeviceIndex, ETrackedDeviceProperty prop, ETrackedPropertyError *pError = 0L ) = 0; + + /** Returns a float property. If the device index is not valid or the property is not a float type this function will return 0. */ + virtual float GetFloatTrackedDeviceProperty( vr::TrackedDeviceIndex_t unDeviceIndex, ETrackedDeviceProperty prop, ETrackedPropertyError *pError = 0L ) = 0; + + /** Returns an int property. If the device index is not valid or the property is not a int type this function will return 0. */ + virtual int32_t GetInt32TrackedDeviceProperty( vr::TrackedDeviceIndex_t unDeviceIndex, ETrackedDeviceProperty prop, ETrackedPropertyError *pError = 0L ) = 0; + + /** Returns a uint64 property. If the device index is not valid or the property is not a uint64 type this function will return 0. */ + virtual uint64_t GetUint64TrackedDeviceProperty( vr::TrackedDeviceIndex_t unDeviceIndex, ETrackedDeviceProperty prop, ETrackedPropertyError *pError = 0L ) = 0; + + /** Returns a matrix property. If the device index is not valid or the property is not a matrix type, this function will return identity. */ + virtual HmdMatrix34_t GetMatrix34TrackedDeviceProperty( vr::TrackedDeviceIndex_t unDeviceIndex, ETrackedDeviceProperty prop, ETrackedPropertyError *pError = 0L ) = 0; + + /** Returns an array of one type of property. If the device index is not valid or the property is not a single value or an array of the specified type, + * this function will return 0. Otherwise it returns the number of bytes necessary to hold the array of properties. If unBufferSize is + * greater than the returned size and pBuffer is non-NULL, pBuffer is filled with the contents of array of properties. */ + virtual uint32_t GetArrayTrackedDeviceProperty( vr::TrackedDeviceIndex_t unDeviceIndex, ETrackedDeviceProperty prop, PropertyTypeTag_t propType, void *pBuffer, uint32_t unBufferSize, ETrackedPropertyError *pError = 0L ) = 0; + + /** Returns a string property. If the device index is not valid or the property is not a string type this function will + * return 0. Otherwise it returns the length of the number of bytes necessary to hold this string including the trailing + * null. Strings will always fit in buffers of k_unMaxPropertyStringSize characters. */ + virtual uint32_t GetStringTrackedDeviceProperty( vr::TrackedDeviceIndex_t unDeviceIndex, ETrackedDeviceProperty prop, VR_OUT_STRING() char *pchValue, uint32_t unBufferSize, ETrackedPropertyError *pError = 0L ) = 0; + + /** returns a string that corresponds with the specified property error. The string will be the name + * of the error enum value for all valid error codes */ + virtual const char *GetPropErrorNameFromEnum( ETrackedPropertyError error ) = 0; + + // ------------------------------------ + // Event methods + // ------------------------------------ + + /** Returns true and fills the event with the next event on the queue if there is one. If there are no events + * this method returns false. uncbVREvent should be the size in bytes of the VREvent_t struct */ + virtual bool PollNextEvent( VREvent_t *pEvent, uint32_t uncbVREvent ) = 0; + + /** Returns true and fills the event with the next event on the queue if there is one. If there are no events + * this method returns false. Fills in the pose of the associated tracked device in the provided pose struct. + * This pose will always be older than the call to this function and should not be used to render the device. + uncbVREvent should be the size in bytes of the VREvent_t struct */ + virtual bool PollNextEventWithPose( ETrackingUniverseOrigin eOrigin, VREvent_t *pEvent, uint32_t uncbVREvent, vr::TrackedDevicePose_t *pTrackedDevicePose ) = 0; + + /** returns the name of an EVREvent enum value */ + virtual const char *GetEventTypeNameFromEnum( EVREventType eType ) = 0; + + // ------------------------------------ + // Rendering helper methods + // ------------------------------------ + + /** Returns the hidden area mesh for the current HMD. The pixels covered by this mesh will never be seen by the user after the lens distortion is + * applied based on visibility to the panels. If this HMD does not have a hidden area mesh, the vertex data and count will be NULL and 0 respectively. + * This mesh is meant to be rendered into the stencil buffer (or into the depth buffer setting nearz) before rendering each eye's view. + * This will improve performance by letting the GPU early-reject pixels the user will never see before running the pixel shader. + * NOTE: Render this mesh with backface culling disabled since the winding order of the vertices can be different per-HMD or per-eye. + * Setting the bInverse argument to true will produce the visible area mesh that is commonly used in place of full-screen quads. The visible area mesh covers all of the pixels the hidden area mesh does not cover. + * Setting the bLineLoop argument will return a line loop of vertices in HiddenAreaMesh_t->pVertexData with HiddenAreaMesh_t->unTriangleCount set to the number of vertices. + */ + virtual HiddenAreaMesh_t GetHiddenAreaMesh( EVREye eEye, EHiddenAreaMeshType type = k_eHiddenAreaMesh_Standard ) = 0; + + // ------------------------------------ + // Controller methods + // ------------------------------------ + + /** Fills the supplied struct with the current state of the controller. Returns false if the controller index + * is invalid. This function is deprecated in favor of the new IVRInput system. */ + virtual bool GetControllerState( vr::TrackedDeviceIndex_t unControllerDeviceIndex, vr::VRControllerState_t *pControllerState, uint32_t unControllerStateSize ) = 0; + + /** fills the supplied struct with the current state of the controller and the provided pose with the pose of + * the controller when the controller state was updated most recently. Use this form if you need a precise controller + * pose as input to your application when the user presses or releases a button. This function is deprecated in favor of the new IVRInput system. */ + virtual bool GetControllerStateWithPose( ETrackingUniverseOrigin eOrigin, vr::TrackedDeviceIndex_t unControllerDeviceIndex, vr::VRControllerState_t *pControllerState, uint32_t unControllerStateSize, TrackedDevicePose_t *pTrackedDevicePose ) = 0; + + /** Trigger a single haptic pulse on a controller. After this call the application may not trigger another haptic pulse on this controller + * and axis combination for 5ms. This function is deprecated in favor of the new IVRInput system. */ + virtual void TriggerHapticPulse( vr::TrackedDeviceIndex_t unControllerDeviceIndex, uint32_t unAxisId, unsigned short usDurationMicroSec ) = 0; + + /** returns the name of an EVRButtonId enum value. This function is deprecated in favor of the new IVRInput system. */ + virtual const char *GetButtonIdNameFromEnum( EVRButtonId eButtonId ) = 0; + + /** returns the name of an EVRControllerAxisType enum value. This function is deprecated in favor of the new IVRInput system. */ + virtual const char *GetControllerAxisTypeNameFromEnum( EVRControllerAxisType eAxisType ) = 0; + + /** Returns true if this application is receiving input from the system. This would return false if + * system-related functionality is consuming the input stream. */ + virtual bool IsInputAvailable() = 0; + + /** Returns true SteamVR is drawing controllers on top of the application. Applications should consider + * not drawing anything attached to the user's hands in this case. */ + virtual bool IsSteamVRDrawingControllers() = 0; + + /** Returns true if the user has put SteamVR into a mode that is distracting them from the application. + * For applications where this is appropriate, the application should pause ongoing activity. */ + virtual bool ShouldApplicationPause() = 0; + + /** Returns true if SteamVR is doing significant rendering work and the game should do what it can to reduce + * its own workload. One common way to do this is to reduce the size of the render target provided for each eye. */ + virtual bool ShouldApplicationReduceRenderingWork() = 0; + + // ------------------------------------ + // Firmware methods + // ------------------------------------ + + /** Performs the actual firmware update if applicable. + * The following events will be sent, if VRFirmwareError_None was returned: VREvent_FirmwareUpdateStarted, VREvent_FirmwareUpdateFinished + * Use the properties Prop_Firmware_UpdateAvailable_Bool, Prop_Firmware_ManualUpdate_Bool, and Prop_Firmware_ManualUpdateURL_String + * to figure our whether a firmware update is available, and to figure out whether its a manual update + * Prop_Firmware_ManualUpdateURL_String should point to an URL describing the manual update process */ + virtual vr::EVRFirmwareError PerformFirmwareUpdate( vr::TrackedDeviceIndex_t unDeviceIndex ) = 0; + + // ------------------------------------ + // Application life cycle methods + // ------------------------------------ + + /** Call this to acknowledge to the system that VREvent_Quit has been received and that the process is exiting. + * This extends the timeout until the process is killed. */ + virtual void AcknowledgeQuit_Exiting() = 0; + + // ------------------------------------- + // App container sandbox methods + // ------------------------------------- + + /** Retrieves a null-terminated, semicolon-delimited list of UTF8 file paths that an application + * must have read access to when running inside of an app container. Returns the number of bytes + * needed to hold the list. */ + virtual uint32_t GetAppContainerFilePaths( VR_OUT_STRING() char *pchBuffer, uint32_t unBufferSize ) = 0; + + // ------------------------------------- + // System methods + // ------------------------------------- + + /** Returns the current version of the SteamVR runtime. The returned string will remain valid until VR_Shutdown is called. + * + * NOTE: Is it not appropriate to use this version to test for the presence of any SteamVR feature. Only use this version + * number for logging or showing to a user, and not to try to detect anything at runtime. When appropriate, feature-specific + * presence information is provided by other APIs. */ + virtual const char *GetRuntimeVersion() = 0; + +}; + +static const char * const IVRSystem_Version = "IVRSystem_022"; + +} + + +// ivrapplications.h + +namespace vr +{ + + /** Used for all errors reported by the IVRApplications interface */ + enum EVRApplicationError + { + VRApplicationError_None = 0, + + VRApplicationError_AppKeyAlreadyExists = 100, // Only one application can use any given key + VRApplicationError_NoManifest = 101, // the running application does not have a manifest + VRApplicationError_NoApplication = 102, // No application is running + VRApplicationError_InvalidIndex = 103, + VRApplicationError_UnknownApplication = 104, // the application could not be found + VRApplicationError_IPCFailed = 105, // An IPC failure caused the request to fail + VRApplicationError_ApplicationAlreadyRunning = 106, + VRApplicationError_InvalidManifest = 107, + VRApplicationError_InvalidApplication = 108, + VRApplicationError_LaunchFailed = 109, // the process didn't start + VRApplicationError_ApplicationAlreadyStarting = 110, // the system was already starting the same application + VRApplicationError_LaunchInProgress = 111, // The system was already starting a different application + VRApplicationError_OldApplicationQuitting = 112, + VRApplicationError_TransitionAborted = 113, + VRApplicationError_IsTemplate = 114, // error when you try to call LaunchApplication() on a template type app (use LaunchTemplateApplication) + VRApplicationError_SteamVRIsExiting = 115, + + VRApplicationError_BufferTooSmall = 200, // The provided buffer was too small to fit the requested data + VRApplicationError_PropertyNotSet = 201, // The requested property was not set + VRApplicationError_UnknownProperty = 202, + VRApplicationError_InvalidParameter = 203, + + VRApplicationError_NotImplemented = 300, // Fcn is not implemented in current interface + }; + + /** The maximum length of an application key */ + static const uint32_t k_unMaxApplicationKeyLength = 128; + + /** these are the properties available on applications. */ + enum EVRApplicationProperty + { + VRApplicationProperty_Name_String = 0, + + VRApplicationProperty_LaunchType_String = 11, + VRApplicationProperty_WorkingDirectory_String = 12, + VRApplicationProperty_BinaryPath_String = 13, + VRApplicationProperty_Arguments_String = 14, + VRApplicationProperty_URL_String = 15, + + VRApplicationProperty_Description_String = 50, + VRApplicationProperty_NewsURL_String = 51, + VRApplicationProperty_ImagePath_String = 52, + VRApplicationProperty_Source_String = 53, + VRApplicationProperty_ActionManifestURL_String = 54, + + VRApplicationProperty_IsDashboardOverlay_Bool = 60, + VRApplicationProperty_IsTemplate_Bool = 61, + VRApplicationProperty_IsInstanced_Bool = 62, + VRApplicationProperty_IsInternal_Bool = 63, + VRApplicationProperty_WantsCompositorPauseInStandby_Bool = 64, + VRApplicationProperty_IsHidden_Bool = 65, + + VRApplicationProperty_LastLaunchTime_Uint64 = 70, + }; + + enum EVRSceneApplicationState + { + EVRSceneApplicationState_None = 0, // Scene Application is not running + EVRSceneApplicationState_Starting = 1, // Scene Application is starting + EVRSceneApplicationState_Quitting = 2, // Scene Application is quitting + EVRSceneApplicationState_Running = 3, // Scene Application is running, and submitting frames, a custom skybox, or a visible overlay + EVRSceneApplicationState_Waiting = 4, // Scene Application is running, but not drawing anything + }; + + struct AppOverrideKeys_t + { + const char *pchKey; + const char *pchValue; + }; + + /** Currently recognized mime types */ + static const char * const k_pch_MimeType_HomeApp = "vr/home"; + static const char * const k_pch_MimeType_GameTheater = "vr/game_theater"; + + class IVRApplications + { + public: + + // --------------- Application management --------------- // + + /** Adds an application manifest to the list to load when building the list of installed applications. + * Temporary manifests are not automatically loaded */ + virtual EVRApplicationError AddApplicationManifest( const char *pchApplicationManifestFullPath, bool bTemporary = false ) = 0; + + /** Removes an application manifest from the list to load when building the list of installed applications. */ + virtual EVRApplicationError RemoveApplicationManifest( const char *pchApplicationManifestFullPath ) = 0; + + /** Returns true if an application is installed */ + virtual bool IsApplicationInstalled( const char *pchAppKey ) = 0; + + /** Returns the number of applications available in the list */ + virtual uint32_t GetApplicationCount() = 0; + + /** Returns the key of the specified application. The index is at least 0 and is less than the return + * value of GetApplicationCount(). The buffer should be at least k_unMaxApplicationKeyLength in order to + * fit the key. */ + virtual EVRApplicationError GetApplicationKeyByIndex( uint32_t unApplicationIndex, VR_OUT_STRING() char *pchAppKeyBuffer, uint32_t unAppKeyBufferLen ) = 0; + + /** Returns the key of the application for the specified Process Id. The buffer should be at least + * k_unMaxApplicationKeyLength in order to fit the key. */ + virtual EVRApplicationError GetApplicationKeyByProcessId( uint32_t unProcessId, VR_OUT_STRING() char *pchAppKeyBuffer, uint32_t unAppKeyBufferLen ) = 0; + + /** Launches the application. The existing scene application will exit and then the new application will start. + * This call is not valid for dashboard overlay applications. */ + virtual EVRApplicationError LaunchApplication( const char *pchAppKey ) = 0; + + /** Launches an instance of an application of type template, with its app key being pchNewAppKey (which must be unique) and optionally override sections + * from the manifest file via AppOverrideKeys_t + */ + virtual EVRApplicationError LaunchTemplateApplication( const char *pchTemplateAppKey, const char *pchNewAppKey, VR_ARRAY_COUNT( unKeys ) const AppOverrideKeys_t *pKeys, uint32_t unKeys ) = 0; + + /** launches the application currently associated with this mime type and passes it the option args, typically the filename or object name of the item being launched */ + virtual vr::EVRApplicationError LaunchApplicationFromMimeType( const char *pchMimeType, const char *pchArgs ) = 0; + + /** Launches the dashboard overlay application if it is not already running. This call is only valid for + * dashboard overlay applications. */ + virtual EVRApplicationError LaunchDashboardOverlay( const char *pchAppKey ) = 0; + + /** Cancel a pending launch for an application */ + virtual bool CancelApplicationLaunch( const char *pchAppKey ) = 0; + + /** Identifies a running application. OpenVR can't always tell which process started in response + * to a URL. This function allows a URL handler (or the process itself) to identify the app key + * for the now running application. Passing a process ID of 0 identifies the calling process. + * The application must be one that's known to the system via a call to AddApplicationManifest. */ + virtual EVRApplicationError IdentifyApplication( uint32_t unProcessId, const char *pchAppKey ) = 0; + + /** Returns the process ID for an application. Return 0 if the application was not found or is not running. */ + virtual uint32_t GetApplicationProcessId( const char *pchAppKey ) = 0; + + /** Returns a string for an applications error */ + virtual const char *GetApplicationsErrorNameFromEnum( EVRApplicationError error ) = 0; + + // --------------- Application properties --------------- // + + /** Returns a value for an application property. The required buffer size to fit this value will be returned. */ + virtual uint32_t GetApplicationPropertyString( const char *pchAppKey, EVRApplicationProperty eProperty, VR_OUT_STRING() char *pchPropertyValueBuffer, uint32_t unPropertyValueBufferLen, EVRApplicationError *peError = nullptr ) = 0; + + /** Returns a bool value for an application property. Returns false in all error cases. */ + virtual bool GetApplicationPropertyBool( const char *pchAppKey, EVRApplicationProperty eProperty, EVRApplicationError *peError = nullptr ) = 0; + + /** Returns a uint64 value for an application property. Returns 0 in all error cases. */ + virtual uint64_t GetApplicationPropertyUint64( const char *pchAppKey, EVRApplicationProperty eProperty, EVRApplicationError *peError = nullptr ) = 0; + + /** Sets the application auto-launch flag. This is only valid for applications which return true for VRApplicationProperty_IsDashboardOverlay_Bool. */ + virtual EVRApplicationError SetApplicationAutoLaunch( const char *pchAppKey, bool bAutoLaunch ) = 0; + + /** Gets the application auto-launch flag. This is only valid for applications which return true for VRApplicationProperty_IsDashboardOverlay_Bool. */ + virtual bool GetApplicationAutoLaunch( const char *pchAppKey ) = 0; + + /** Adds this mime-type to the list of supported mime types for this application*/ + virtual EVRApplicationError SetDefaultApplicationForMimeType( const char *pchAppKey, const char *pchMimeType ) = 0; + + /** return the app key that will open this mime type */ + virtual bool GetDefaultApplicationForMimeType( const char *pchMimeType, VR_OUT_STRING() char *pchAppKeyBuffer, uint32_t unAppKeyBufferLen ) = 0; + + /** Get the list of supported mime types for this application, comma-delimited */ + virtual bool GetApplicationSupportedMimeTypes( const char *pchAppKey, VR_OUT_STRING() char *pchMimeTypesBuffer, uint32_t unMimeTypesBuffer ) = 0; + + /** Get the list of app-keys that support this mime type, comma-delimited, the return value is number of bytes you need to return the full string */ + virtual uint32_t GetApplicationsThatSupportMimeType( const char *pchMimeType, VR_OUT_STRING() char *pchAppKeysThatSupportBuffer, uint32_t unAppKeysThatSupportBuffer ) = 0; + + /** Get the args list from an app launch that had the process already running, you call this when you get a VREvent_ApplicationMimeTypeLoad */ + virtual uint32_t GetApplicationLaunchArguments( uint32_t unHandle, VR_OUT_STRING() char *pchArgs, uint32_t unArgs ) = 0; + + // --------------- Transition methods --------------- // + + /** Returns the app key for the application that is starting up */ + virtual EVRApplicationError GetStartingApplication( VR_OUT_STRING() char *pchAppKeyBuffer, uint32_t unAppKeyBufferLen ) = 0; + + /** Returns the application transition state */ + virtual EVRSceneApplicationState GetSceneApplicationState() = 0; + + /** Returns errors that would prevent the specified application from launching immediately. Calling this function will + * cause the current scene application to quit, so only call it when you are actually about to launch something else. + * What the caller should do about these failures depends on the failure: + * VRApplicationError_OldApplicationQuitting - An existing application has been told to quit. Wait for a VREvent_ProcessQuit + * and try again. + * VRApplicationError_ApplicationAlreadyStarting - This application is already starting. This is a permanent failure. + * VRApplicationError_LaunchInProgress - A different application is already starting. This is a permanent failure. + * VRApplicationError_None - Go ahead and launch. Everything is clear. + */ + virtual EVRApplicationError PerformApplicationPrelaunchCheck( const char *pchAppKey ) = 0; + + /** Returns a string for an application transition state */ + virtual const char *GetSceneApplicationStateNameFromEnum( EVRSceneApplicationState state ) = 0; + + /** Starts a subprocess within the calling application. This + * suppresses all application transition UI and automatically identifies the new executable + * as part of the same application. On success the calling process should exit immediately. + * If working directory is NULL or "" the directory portion of the binary path will be + * the working directory. */ + virtual EVRApplicationError LaunchInternalProcess( const char *pchBinaryPath, const char *pchArguments, const char *pchWorkingDirectory ) = 0; + + /** Returns the current scene process ID according to the application system. A scene process will get scene + * focus once it starts rendering, but it will appear here once it calls VR_Init with the Scene application + * type. */ + virtual uint32_t GetCurrentSceneProcessId() = 0; + }; + + static const char * const IVRApplications_Version = "IVRApplications_007"; + +} // namespace vr + +// ivrsettings.h + +#include + +namespace vr +{ + enum EVRSettingsError + { + VRSettingsError_None = 0, + VRSettingsError_IPCFailed = 1, + VRSettingsError_WriteFailed = 2, + VRSettingsError_ReadFailed = 3, + VRSettingsError_JsonParseFailed = 4, + VRSettingsError_UnsetSettingHasNoDefault = 5, // This will be returned if the setting does not appear in the appropriate default file and has not been set + }; + + // The maximum length of a settings key + static const uint32_t k_unMaxSettingsKeyLength = 128; + + class IVRSettings + { + public: + virtual const char *GetSettingsErrorNameFromEnum( EVRSettingsError eError ) = 0; + + virtual void SetBool( const char *pchSection, const char *pchSettingsKey, bool bValue, EVRSettingsError *peError = nullptr ) = 0; + virtual void SetInt32( const char *pchSection, const char *pchSettingsKey, int32_t nValue, EVRSettingsError *peError = nullptr ) = 0; + virtual void SetFloat( const char *pchSection, const char *pchSettingsKey, float flValue, EVRSettingsError *peError = nullptr ) = 0; + virtual void SetString( const char *pchSection, const char *pchSettingsKey, const char *pchValue, EVRSettingsError *peError = nullptr ) = 0; + + // Users of the system need to provide a proper default in default.vrsettings in the resources/settings/ directory + // of either the runtime or the driver_xxx directory. Otherwise the default will be false, 0, 0.0 or "" + virtual bool GetBool( const char *pchSection, const char *pchSettingsKey, EVRSettingsError *peError = nullptr ) = 0; + virtual int32_t GetInt32( const char *pchSection, const char *pchSettingsKey, EVRSettingsError *peError = nullptr ) = 0; + virtual float GetFloat( const char *pchSection, const char *pchSettingsKey, EVRSettingsError *peError = nullptr ) = 0; + virtual void GetString( const char *pchSection, const char *pchSettingsKey, VR_OUT_STRING() char *pchValue, uint32_t unValueLen, EVRSettingsError *peError = nullptr ) = 0; + + virtual void RemoveSection( const char *pchSection, EVRSettingsError *peError = nullptr ) = 0; + virtual void RemoveKeyInSection( const char *pchSection, const char *pchSettingsKey, EVRSettingsError *peError = nullptr ) = 0; + }; + + //----------------------------------------------------------------------------- + static const char * const IVRSettings_Version = "IVRSettings_003"; + + class CVRSettingHelper + { + IVRSettings *m_pSettings; + public: + CVRSettingHelper( IVRSettings *pSettings ) + { + m_pSettings = pSettings; + } + + const char *GetSettingsErrorNameFromEnum( EVRSettingsError eError ) + { + return m_pSettings->GetSettingsErrorNameFromEnum( eError ); + } + + void SetBool( const char *pchSection, const char *pchSettingsKey, bool bValue, EVRSettingsError *peError = nullptr ) + { + m_pSettings->SetBool( pchSection, pchSettingsKey, bValue, peError ); + } + + void SetInt32( const char *pchSection, const char *pchSettingsKey, int32_t nValue, EVRSettingsError *peError = nullptr ) + { + m_pSettings->SetInt32( pchSection, pchSettingsKey, nValue, peError ); + } + void SetFloat( const char *pchSection, const char *pchSettingsKey, float flValue, EVRSettingsError *peError = nullptr ) + { + m_pSettings->SetFloat( pchSection, pchSettingsKey, flValue, peError ); + } + void SetString( const char *pchSection, const char *pchSettingsKey, const char *pchValue, EVRSettingsError *peError = nullptr ) + { + m_pSettings->SetString( pchSection, pchSettingsKey, pchValue, peError ); + } + void SetString( const std::string & sSection, const std::string & sSettingsKey, const std::string & sValue, EVRSettingsError *peError = nullptr ) + { + m_pSettings->SetString( sSection.c_str(), sSettingsKey.c_str(), sValue.c_str(), peError ); + } + + bool GetBool( const char *pchSection, const char *pchSettingsKey, EVRSettingsError *peError = nullptr ) + { + return m_pSettings->GetBool( pchSection, pchSettingsKey, peError ); + } + int32_t GetInt32( const char *pchSection, const char *pchSettingsKey, EVRSettingsError *peError = nullptr ) + { + return m_pSettings->GetInt32( pchSection, pchSettingsKey, peError ); + } + float GetFloat( const char *pchSection, const char *pchSettingsKey, EVRSettingsError *peError = nullptr ) + { + return m_pSettings->GetFloat( pchSection, pchSettingsKey, peError ); + } + void GetString( const char *pchSection, const char *pchSettingsKey, VR_OUT_STRING() char *pchValue, uint32_t unValueLen, EVRSettingsError *peError = nullptr ) + { + m_pSettings->GetString( pchSection, pchSettingsKey, pchValue, unValueLen, peError ); + } + std::string GetString( const std::string & sSection, const std::string & sSettingsKey, EVRSettingsError *peError = nullptr ) + { + char buf[4096]; + vr::EVRSettingsError eError; + m_pSettings->GetString( sSection.c_str(), sSettingsKey.c_str(), buf, sizeof( buf ), &eError ); + if ( peError ) + *peError = eError; + if ( eError == vr::VRSettingsError_None ) + return buf; + else + return ""; + } + + void RemoveSection( const char *pchSection, EVRSettingsError *peError = nullptr ) + { + m_pSettings->RemoveSection( pchSection, peError ); + } + void RemoveKeyInSection( const char *pchSection, const char *pchSettingsKey, EVRSettingsError *peError = nullptr ) + { + m_pSettings->RemoveKeyInSection( pchSection, pchSettingsKey, peError ); + } + }; + + + //----------------------------------------------------------------------------- + // steamvr keys + static const char * const k_pch_SteamVR_Section = "steamvr"; + static const char * const k_pch_SteamVR_RequireHmd_String = "requireHmd"; + static const char * const k_pch_SteamVR_ForcedDriverKey_String = "forcedDriver"; + static const char * const k_pch_SteamVR_ForcedHmdKey_String = "forcedHmd"; + static const char * const k_pch_SteamVR_DisplayDebug_Bool = "displayDebug"; + static const char * const k_pch_SteamVR_DebugProcessPipe_String = "debugProcessPipe"; + static const char * const k_pch_SteamVR_DisplayDebugX_Int32 = "displayDebugX"; + static const char * const k_pch_SteamVR_DisplayDebugY_Int32 = "displayDebugY"; + static const char * const k_pch_SteamVR_SendSystemButtonToAllApps_Bool= "sendSystemButtonToAllApps"; + static const char * const k_pch_SteamVR_LogLevel_Int32 = "loglevel"; + static const char * const k_pch_SteamVR_IPD_Float = "ipd"; + static const char * const k_pch_SteamVR_Background_String = "background"; + static const char * const k_pch_SteamVR_BackgroundUseDomeProjection_Bool = "backgroundUseDomeProjection"; + static const char * const k_pch_SteamVR_BackgroundCameraHeight_Float = "backgroundCameraHeight"; + static const char * const k_pch_SteamVR_BackgroundDomeRadius_Float = "backgroundDomeRadius"; + static const char * const k_pch_SteamVR_GridColor_String = "gridColor"; + static const char * const k_pch_SteamVR_PlayAreaColor_String = "playAreaColor"; + static const char * const k_pch_SteamVR_TrackingLossColor_String = "trackingLossColor"; + static const char * const k_pch_SteamVR_ShowStage_Bool = "showStage"; + static const char * const k_pch_SteamVR_DrawTrackingReferences_Bool = "drawTrackingReferences"; + static const char * const k_pch_SteamVR_ActivateMultipleDrivers_Bool = "activateMultipleDrivers"; + static const char * const k_pch_SteamVR_UsingSpeakers_Bool = "usingSpeakers"; + static const char * const k_pch_SteamVR_SpeakersForwardYawOffsetDegrees_Float = "speakersForwardYawOffsetDegrees"; + static const char * const k_pch_SteamVR_BaseStationPowerManagement_Int32 = "basestationPowerManagement"; + static const char * const k_pch_SteamVR_ShowBaseStationPowerManagementTip_Int32 = "ShowBaseStationPowerManagementTip"; + static const char * const k_pch_SteamVR_NeverKillProcesses_Bool = "neverKillProcesses"; + static const char * const k_pch_SteamVR_SupersampleScale_Float = "supersampleScale"; + static const char * const k_pch_SteamVR_MaxRecommendedResolution_Int32 = "maxRecommendedResolution"; + static const char * const k_pch_SteamVR_MotionSmoothing_Bool = "motionSmoothing"; + static const char * const k_pch_SteamVR_MotionSmoothingOverride_Int32 = "motionSmoothingOverride"; + static const char * const k_pch_SteamVR_FramesToThrottle_Int32 = "framesToThrottle"; + static const char * const k_pch_SteamVR_AdditionalFramesToPredict_Int32 = "additionalFramesToPredict"; + static const char * const k_pch_SteamVR_WorldScale_Float = "worldScale"; + static const char * const k_pch_SteamVR_FovScale_Int32 = "fovScale"; + static const char * const k_pch_SteamVR_DisableAsyncReprojection_Bool = "disableAsync"; + static const char * const k_pch_SteamVR_ForceFadeOnBadTracking_Bool = "forceFadeOnBadTracking"; + static const char * const k_pch_SteamVR_DefaultMirrorView_Int32 = "mirrorView"; + static const char * const k_pch_SteamVR_ShowLegacyMirrorView_Bool = "showLegacyMirrorView"; + static const char * const k_pch_SteamVR_MirrorViewVisibility_Bool = "showMirrorView"; + static const char * const k_pch_SteamVR_MirrorViewDisplayMode_Int32 = "mirrorViewDisplayMode"; + static const char * const k_pch_SteamVR_MirrorViewEye_Int32 = "mirrorViewEye"; + static const char * const k_pch_SteamVR_MirrorViewGeometry_String = "mirrorViewGeometry"; + static const char * const k_pch_SteamVR_MirrorViewGeometryMaximized_String = "mirrorViewGeometryMaximized"; + static const char * const k_pch_SteamVR_PerfGraphVisibility_Bool = "showPerfGraph"; + static const char * const k_pch_SteamVR_StartMonitorFromAppLaunch = "startMonitorFromAppLaunch"; + static const char * const k_pch_SteamVR_StartCompositorFromAppLaunch_Bool = "startCompositorFromAppLaunch"; + static const char * const k_pch_SteamVR_StartDashboardFromAppLaunch_Bool = "startDashboardFromAppLaunch"; + static const char * const k_pch_SteamVR_StartOverlayAppsFromDashboard_Bool = "startOverlayAppsFromDashboard"; + static const char * const k_pch_SteamVR_EnableHomeApp = "enableHomeApp"; + static const char * const k_pch_SteamVR_CycleBackgroundImageTimeSec_Int32 = "CycleBackgroundImageTimeSec"; + static const char * const k_pch_SteamVR_RetailDemo_Bool = "retailDemo"; + static const char * const k_pch_SteamVR_IpdOffset_Float = "ipdOffset"; + static const char * const k_pch_SteamVR_AllowSupersampleFiltering_Bool = "allowSupersampleFiltering"; + static const char * const k_pch_SteamVR_SupersampleManualOverride_Bool = "supersampleManualOverride"; + static const char * const k_pch_SteamVR_EnableLinuxVulkanAsync_Bool = "enableLinuxVulkanAsync"; + static const char * const k_pch_SteamVR_AllowDisplayLockedMode_Bool = "allowDisplayLockedMode"; + static const char * const k_pch_SteamVR_HaveStartedTutorialForNativeChaperoneDriver_Bool = "haveStartedTutorialForNativeChaperoneDriver"; + static const char * const k_pch_SteamVR_ForceWindows32bitVRMonitor = "forceWindows32BitVRMonitor"; + static const char * const k_pch_SteamVR_DebugInputBinding = "debugInputBinding"; + static const char * const k_pch_SteamVR_DoNotFadeToGrid = "doNotFadeToGrid"; + static const char * const k_pch_SteamVR_EnableSharedResourceJournaling = "enableSharedResourceJournaling"; + static const char * const k_pch_SteamVR_EnableSafeMode = "enableSafeMode"; + static const char * const k_pch_SteamVR_PreferredRefreshRate = "preferredRefreshRate"; + static const char * const k_pch_SteamVR_LastVersionNotice = "lastVersionNotice"; + static const char * const k_pch_SteamVR_LastVersionNoticeDate = "lastVersionNoticeDate"; + static const char * const k_pch_SteamVR_HmdDisplayColorGainR_Float = "hmdDisplayColorGainR"; + static const char * const k_pch_SteamVR_HmdDisplayColorGainG_Float = "hmdDisplayColorGainG"; + static const char * const k_pch_SteamVR_HmdDisplayColorGainB_Float = "hmdDisplayColorGainB"; + static const char * const k_pch_SteamVR_CustomIconStyle_String = "customIconStyle"; + static const char * const k_pch_SteamVR_CustomOffIconStyle_String = "customOffIconStyle"; + static const char * const k_pch_SteamVR_CustomIconForceUpdate_String = "customIconForceUpdate"; + static const char * const k_pch_SteamVR_AllowGlobalActionSetPriority = "globalActionSetPriority"; + static const char * const k_pch_SteamVR_OverlayRenderQuality = "overlayRenderQuality_2"; + static const char * const k_pch_SteamVR_BlockOculusSDKOnOpenVRLaunchOption_Bool = "blockOculusSDKOnOpenVRLaunchOption"; + static const char * const k_pch_SteamVR_BlockOculusSDKOnAllLaunches_Bool = "blockOculusSDKOnAllLaunches"; + static const char * const k_pch_SteamVR_HDCPLegacyCompatibility_Bool = "hdcp14legacyCompatibility"; + static const char * const k_pch_SteamVR_DisplayPortTrainingMode_Int = "displayPortTrainingMode"; + static const char * const k_pch_SteamVR_UsePrism_Bool = "usePrism"; + static const char * const k_pch_SteamVR_AllowFallbackMirrorWindowLinux_Bool = "allowFallbackMirrorWindowLinux"; + + //----------------------------------------------------------------------------- + // direct mode keys + static const char * const k_pch_DirectMode_Section = "direct_mode"; + static const char * const k_pch_DirectMode_Enable_Bool = "enable"; + static const char * const k_pch_DirectMode_Count_Int32 = "count"; + static const char * const k_pch_DirectMode_EdidVid_Int32 = "edidVid"; + static const char * const k_pch_DirectMode_EdidPid_Int32 = "edidPid"; + + //----------------------------------------------------------------------------- + // lighthouse keys + static const char * const k_pch_Lighthouse_Section = "driver_lighthouse"; + static const char * const k_pch_Lighthouse_DisableIMU_Bool = "disableimu"; + static const char * const k_pch_Lighthouse_DisableIMUExceptHMD_Bool = "disableimuexcepthmd"; + static const char * const k_pch_Lighthouse_UseDisambiguation_String = "usedisambiguation"; + static const char * const k_pch_Lighthouse_DisambiguationDebug_Int32 = "disambiguationdebug"; + static const char * const k_pch_Lighthouse_PrimaryBasestation_Int32 = "primarybasestation"; + static const char * const k_pch_Lighthouse_DBHistory_Bool = "dbhistory"; + static const char * const k_pch_Lighthouse_EnableBluetooth_Bool = "enableBluetooth"; + static const char * const k_pch_Lighthouse_PowerManagedBaseStations_String = "PowerManagedBaseStations"; + static const char * const k_pch_Lighthouse_PowerManagedBaseStations2_String = "PowerManagedBaseStations2"; + static const char * const k_pch_Lighthouse_InactivityTimeoutForBaseStations_Int32 = "InactivityTimeoutForBaseStations"; + static const char * const k_pch_Lighthouse_EnableImuFallback_Bool = "enableImuFallback"; + + //----------------------------------------------------------------------------- + // null keys + static const char * const k_pch_Null_Section = "driver_null"; + static const char * const k_pch_Null_SerialNumber_String = "serialNumber"; + static const char * const k_pch_Null_ModelNumber_String = "modelNumber"; + static const char * const k_pch_Null_WindowX_Int32 = "windowX"; + static const char * const k_pch_Null_WindowY_Int32 = "windowY"; + static const char * const k_pch_Null_WindowWidth_Int32 = "windowWidth"; + static const char * const k_pch_Null_WindowHeight_Int32 = "windowHeight"; + static const char * const k_pch_Null_RenderWidth_Int32 = "renderWidth"; + static const char * const k_pch_Null_RenderHeight_Int32 = "renderHeight"; + static const char * const k_pch_Null_SecondsFromVsyncToPhotons_Float = "secondsFromVsyncToPhotons"; + static const char * const k_pch_Null_DisplayFrequency_Float = "displayFrequency"; + + //----------------------------------------------------------------------------- + // Windows MR keys + static const char * const k_pch_WindowsMR_Section = "driver_holographic"; + + //----------------------------------------------------------------------------- + // user interface keys + static const char * const k_pch_UserInterface_Section = "userinterface"; + static const char * const k_pch_UserInterface_StatusAlwaysOnTop_Bool = "StatusAlwaysOnTop"; + static const char * const k_pch_UserInterface_MinimizeToTray_Bool = "MinimizeToTray"; + static const char * const k_pch_UserInterface_HidePopupsWhenStatusMinimized_Bool = "HidePopupsWhenStatusMinimized"; + static const char * const k_pch_UserInterface_Screenshots_Bool = "screenshots"; + static const char * const k_pch_UserInterface_ScreenshotType_Int = "screenshotType"; + + //----------------------------------------------------------------------------- + // notification keys + static const char * const k_pch_Notifications_Section = "notifications"; + static const char * const k_pch_Notifications_DoNotDisturb_Bool = "DoNotDisturb"; + + //----------------------------------------------------------------------------- + // keyboard keys + static const char * const k_pch_Keyboard_Section = "keyboard"; + static const char * const k_pch_Keyboard_TutorialCompletions = "TutorialCompletions"; + static const char * const k_pch_Keyboard_ScaleX = "ScaleX"; + static const char * const k_pch_Keyboard_ScaleY = "ScaleY"; + static const char * const k_pch_Keyboard_OffsetLeftX = "OffsetLeftX"; + static const char * const k_pch_Keyboard_OffsetRightX = "OffsetRightX"; + static const char * const k_pch_Keyboard_OffsetY = "OffsetY"; + static const char * const k_pch_Keyboard_Smoothing = "Smoothing"; + + //----------------------------------------------------------------------------- + // perf keys + static const char * const k_pch_Perf_Section = "perfcheck"; + static const char * const k_pch_Perf_PerfGraphInHMD_Bool = "perfGraphInHMD"; + static const char * const k_pch_Perf_AllowTimingStore_Bool = "allowTimingStore"; + static const char * const k_pch_Perf_SaveTimingsOnExit_Bool = "saveTimingsOnExit"; + static const char * const k_pch_Perf_TestData_Float = "perfTestData"; + static const char * const k_pch_Perf_GPUProfiling_Bool = "GPUProfiling"; + static const char * const k_pch_Perf_GpuBusMonitoring_Bool = "gpuBusMonitoring"; + + //----------------------------------------------------------------------------- + // collision bounds keys + static const char * const k_pch_CollisionBounds_Section = "collisionBounds"; + static const char * const k_pch_CollisionBounds_Style_Int32 = "CollisionBoundsStyle"; + static const char * const k_pch_CollisionBounds_GroundPerimeterOn_Bool = "CollisionBoundsGroundPerimeterOn"; + static const char * const k_pch_CollisionBounds_CenterMarkerOn_Bool = "CollisionBoundsCenterMarkerOn"; + static const char * const k_pch_CollisionBounds_PlaySpaceOn_Bool = "CollisionBoundsPlaySpaceOn"; + static const char * const k_pch_CollisionBounds_FadeDistance_Float = "CollisionBoundsFadeDistance"; + static const char * const k_pch_CollisionBounds_WallHeight_Float = "CollisionBoundsWallHeight"; + static const char * const k_pch_CollisionBounds_ColorGammaR_Int32 = "CollisionBoundsColorGammaR"; + static const char * const k_pch_CollisionBounds_ColorGammaG_Int32 = "CollisionBoundsColorGammaG"; + static const char * const k_pch_CollisionBounds_ColorGammaB_Int32 = "CollisionBoundsColorGammaB"; + static const char * const k_pch_CollisionBounds_ColorGammaA_Int32 = "CollisionBoundsColorGammaA"; + static const char * const k_pch_CollisionBounds_EnableDriverImport = "enableDriverBoundsImport"; + + //----------------------------------------------------------------------------- + // camera keys + static const char * const k_pch_Camera_Section = "camera"; + static const char * const k_pch_Camera_EnableCamera_Bool = "enableCamera"; + static const char * const k_pch_Camera_ShowOnController_Bool = "showOnController"; + static const char * const k_pch_Camera_EnableCameraForCollisionBounds_Bool = "enableCameraForCollisionBounds"; + static const char * const k_pch_Camera_RoomView_Int32 = "roomView"; + static const char * const k_pch_Camera_BoundsColorGammaR_Int32 = "cameraBoundsColorGammaR"; + static const char * const k_pch_Camera_BoundsColorGammaG_Int32 = "cameraBoundsColorGammaG"; + static const char * const k_pch_Camera_BoundsColorGammaB_Int32 = "cameraBoundsColorGammaB"; + static const char * const k_pch_Camera_BoundsColorGammaA_Int32 = "cameraBoundsColorGammaA"; + static const char * const k_pch_Camera_BoundsStrength_Int32 = "cameraBoundsStrength"; + static const char * const k_pch_Camera_RoomViewStyle_Int32 = "roomViewStyle"; + + //----------------------------------------------------------------------------- + // audio keys + static const char * const k_pch_audio_Section = "audio"; + static const char * const k_pch_audio_SetOsDefaultPlaybackDevice_Bool = "setOsDefaultPlaybackDevice"; + static const char * const k_pch_audio_EnablePlaybackDeviceOverride_Bool = "enablePlaybackDeviceOverride"; + static const char * const k_pch_audio_PlaybackDeviceOverride_String = "playbackDeviceOverride"; + static const char * const k_pch_audio_PlaybackDeviceOverrideName_String = "playbackDeviceOverrideName"; + static const char * const k_pch_audio_SetOsDefaultRecordingDevice_Bool = "setOsDefaultRecordingDevice"; + static const char * const k_pch_audio_EnableRecordingDeviceOverride_Bool = "enableRecordingDeviceOverride"; + static const char * const k_pch_audio_RecordingDeviceOverride_String = "recordingDeviceOverride"; + static const char * const k_pch_audio_RecordingDeviceOverrideName_String = "recordingDeviceOverrideName"; + static const char * const k_pch_audio_EnablePlaybackMirror_Bool = "enablePlaybackMirror"; + static const char * const k_pch_audio_PlaybackMirrorDevice_String = "playbackMirrorDevice"; + static const char * const k_pch_audio_PlaybackMirrorDeviceName_String = "playbackMirrorDeviceName"; + static const char * const k_pch_audio_OldPlaybackMirrorDevice_String = "onPlaybackMirrorDevice"; + static const char * const k_pch_audio_ActiveMirrorDevice_String = "activePlaybackMirrorDevice"; + static const char * const k_pch_audio_EnablePlaybackMirrorIndependentVolume_Bool = "enablePlaybackMirrorIndependentVolume"; + static const char * const k_pch_audio_LastHmdPlaybackDeviceId_String = "lastHmdPlaybackDeviceId"; + static const char * const k_pch_audio_VIVEHDMIGain = "viveHDMIGain"; + static const char * const k_pch_audio_DualSpeakerAndJackOutput_Bool = "dualSpeakerAndJackOutput"; + static const char * const k_pch_audio_MuteMicMonitor_Bool = "muteMicMonitor"; + + //----------------------------------------------------------------------------- + // power management keys + static const char * const k_pch_Power_Section = "power"; + static const char * const k_pch_Power_PowerOffOnExit_Bool = "powerOffOnExit"; + static const char * const k_pch_Power_TurnOffScreensTimeout_Float = "turnOffScreensTimeout"; + static const char * const k_pch_Power_TurnOffControllersTimeout_Float = "turnOffControllersTimeout"; + static const char * const k_pch_Power_ReturnToWatchdogTimeout_Float = "returnToWatchdogTimeout"; + static const char * const k_pch_Power_AutoLaunchSteamVROnButtonPress = "autoLaunchSteamVROnButtonPress"; + static const char * const k_pch_Power_PauseCompositorOnStandby_Bool = "pauseCompositorOnStandby"; + + //----------------------------------------------------------------------------- + // dashboard keys + static const char * const k_pch_Dashboard_Section = "dashboard"; + static const char * const k_pch_Dashboard_EnableDashboard_Bool = "enableDashboard"; + static const char * const k_pch_Dashboard_ArcadeMode_Bool = "arcadeMode"; + static const char * const k_pch_Dashboard_Position = "position"; + static const char * const k_pch_Dashboard_DesktopScale = "desktopScale"; + static const char * const k_pch_Dashboard_DashboardScale = "dashboardScale"; + static const char * const k_pch_Dashboard_UseStandaloneSystemLayer = "standaloneSystemLayer"; + static const char * const k_pch_Dashboard_StickyDashboard = "stickyDashboard"; + static const char * const k_pch_Dashboard_AllowSteamOverlays_Bool = "allowSteamOverlays"; + static const char * const k_pch_Dashboard_AllowVRGamepadUI_Bool = "allowVRGamepadUI"; + static const char * const k_pch_Dashboard_AllowDesktopBPMWithVRGamepadUI_Bool = "allowDesktopBPMWithVRGamepadUI"; + static const char * const k_pch_Dashboard_SteamMatchesHMDFramerate = "steamMatchesHMDFramerate"; + + //----------------------------------------------------------------------------- + // model skin keys + static const char * const k_pch_modelskin_Section = "modelskins"; + + //----------------------------------------------------------------------------- + // driver keys - These could be checked in any driver_ section + static const char * const k_pch_Driver_Enable_Bool = "enable"; + static const char * const k_pch_Driver_BlockedBySafemode_Bool = "blocked_by_safe_mode"; + static const char * const k_pch_Driver_LoadPriority_Int32 = "loadPriority"; + + //----------------------------------------------------------------------------- + // web interface keys + static const char* const k_pch_WebInterface_Section = "WebInterface"; + + //----------------------------------------------------------------------------- + // vrwebhelper keys + static const char* const k_pch_VRWebHelper_Section = "VRWebHelper"; + static const char* const k_pch_VRWebHelper_DebuggerEnabled_Bool = "DebuggerEnabled"; + static const char* const k_pch_VRWebHelper_DebuggerPort_Int32 = "DebuggerPort"; + + //----------------------------------------------------------------------------- + // tracking overrides - keys are device paths, values are the device paths their + // tracking/pose information overrides + static const char* const k_pch_TrackingOverride_Section = "TrackingOverrides"; + + //----------------------------------------------------------------------------- + // per-app keys - the section name for these is the app key itself. Some of these are prefixed by the controller type + static const char* const k_pch_App_BindingAutosaveURLSuffix_String = "AutosaveURL"; + static const char* const k_pch_App_BindingLegacyAPISuffix_String = "_legacy"; + static const char *const k_pch_App_BindingSteamVRInputAPISuffix_String = "_steamvrinput"; + static const char *const k_pch_App_BindingOpenXRAPISuffix_String = "_openxr"; + static const char* const k_pch_App_BindingCurrentURLSuffix_String = "CurrentURL"; + static const char* const k_pch_App_BindingPreviousURLSuffix_String = "PreviousURL"; + static const char* const k_pch_App_NeedToUpdateAutosaveSuffix_Bool = "NeedToUpdateAutosave"; + static const char* const k_pch_App_DominantHand_Int32 = "DominantHand"; + static const char* const k_pch_App_BlockOculusSDK_Bool = "blockOculusSDK"; + + //----------------------------------------------------------------------------- + // configuration for trackers + static const char * const k_pch_Trackers_Section = "trackers"; + + //----------------------------------------------------------------------------- + // configuration for desktop UI windows + static const char * const k_pch_DesktopUI_Section = "DesktopUI"; + + //----------------------------------------------------------------------------- + // Last known keys for righting recovery + static const char * const k_pch_LastKnown_Section = "LastKnown"; + static const char* const k_pch_LastKnown_HMDManufacturer_String = "HMDManufacturer"; + static const char *const k_pch_LastKnown_HMDModel_String = "HMDModel"; + static const char* const k_pch_LastKnown_ActualHMDDriver_String = "ActualHMDDriver"; + + //----------------------------------------------------------------------------- + // Dismissed warnings + static const char * const k_pch_DismissedWarnings_Section = "DismissedWarnings"; + + //----------------------------------------------------------------------------- + // Input Settings + static const char * const k_pch_Input_Section = "input"; + static const char* const k_pch_Input_LeftThumbstickRotation_Float = "leftThumbstickRotation"; + static const char* const k_pch_Input_RightThumbstickRotation_Float = "rightThumbstickRotation"; + static const char* const k_pch_Input_ThumbstickDeadzone_Float = "thumbstickDeadzone"; + + //----------------------------------------------------------------------------- + // Log of GPU performance + static const char * const k_pch_GpuSpeed_Section = "GpuSpeed"; + +} // namespace vr + +// ivrchaperone.h + +namespace vr +{ + +#pragma pack( push, 8 ) + +enum ChaperoneCalibrationState +{ + // OK! + ChaperoneCalibrationState_OK = 1, // Chaperone is fully calibrated and working correctly + + // Warnings + ChaperoneCalibrationState_Warning = 100, + ChaperoneCalibrationState_Warning_BaseStationMayHaveMoved = 101, // A base station thinks that it might have moved + ChaperoneCalibrationState_Warning_BaseStationRemoved = 102, // There are less base stations than when calibrated + ChaperoneCalibrationState_Warning_SeatedBoundsInvalid = 103, // Seated bounds haven't been calibrated for the current tracking center + + // Errors + ChaperoneCalibrationState_Error = 200, // The UniverseID is invalid + ChaperoneCalibrationState_Error_BaseStationUninitialized = 201, // Tracking center hasn't be calibrated for at least one of the base stations + ChaperoneCalibrationState_Error_BaseStationConflict = 202, // Tracking center is calibrated, but base stations disagree on the tracking space + ChaperoneCalibrationState_Error_PlayAreaInvalid = 203, // Play Area hasn't been calibrated for the current tracking center + ChaperoneCalibrationState_Error_CollisionBoundsInvalid = 204, // Collision Bounds haven't been calibrated for the current tracking center +}; + + +/** HIGH LEVEL TRACKING SPACE ASSUMPTIONS: +* 0,0,0 is the preferred standing area center. +* 0Y is the floor height. +* -Z is the preferred forward facing direction. */ +class IVRChaperone +{ +public: + + /** Get the current state of Chaperone calibration. This state can change at any time during a session due to physical base station changes. **/ + virtual ChaperoneCalibrationState GetCalibrationState() = 0; + + /** Returns the width and depth of the Play Area (formerly named Soft Bounds) in X and Z. + * Tracking space center (0,0,0) is the center of the Play Area. **/ + virtual bool GetPlayAreaSize( float *pSizeX, float *pSizeZ ) = 0; + + /** Returns the 4 corner positions of the Play Area (formerly named Soft Bounds). + * Corners are in counter-clockwise order. + * Standing center (0,0,0) is the center of the Play Area. + * It's a rectangle. + * 2 sides are parallel to the X axis and 2 sides are parallel to the Z axis. + * Height of every corner is 0Y (on the floor). **/ + virtual bool GetPlayAreaRect( HmdQuad_t *rect ) = 0; + + /** Reload Chaperone data from the .vrchap file on disk. */ + virtual void ReloadInfo( void ) = 0; + + /** Optionally give the chaperone system a hit about the color and brightness in the scene **/ + virtual void SetSceneColor( HmdColor_t color ) = 0; + + /** Get the current chaperone bounds draw color and brightness **/ + virtual void GetBoundsColor( HmdColor_t *pOutputColorArray, int nNumOutputColors, float flCollisionBoundsFadeDistance, HmdColor_t *pOutputCameraColor ) = 0; + + /** Determine whether the bounds are showing right now **/ + virtual bool AreBoundsVisible() = 0; + + /** Force the bounds to show, mostly for utilities **/ + virtual void ForceBoundsVisible( bool bForce ) = 0; + + /** Sets the zero pose for the given tracker coordinate system to the current position and yaw of the HMD. After + * ResetZeroPose all GetDeviceToAbsoluteTrackingPose calls as the origin will be relative to this new zero pose. + * The new zero coordinate system will not change the fact that the Y axis is up in the real world, so the next + * pose returned from GetDeviceToAbsoluteTrackingPose after a call to ResetZeroPose may not be exactly an + * identity matrix. + * + * NOTE: This function overrides the user's previously saved zero pose and should only be called as the result of a user action. + * Users are also able to set their zero pose via the OpenVR Dashboard. + **/ + virtual void ResetZeroPose( ETrackingUniverseOrigin eTrackingUniverseOrigin ) = 0; +}; + +static const char * const IVRChaperone_Version = "IVRChaperone_004"; + +#pragma pack( pop ) + +} + +// ivrchaperonesetup.h + +namespace vr +{ + +enum EChaperoneConfigFile +{ + EChaperoneConfigFile_Live = 1, // The live chaperone config, used by most applications and games + EChaperoneConfigFile_Temp = 2, // The temporary chaperone config, used to live-preview collision bounds in room setup +}; + +enum EChaperoneImportFlags +{ + EChaperoneImport_BoundsOnly = 0x0001, +}; + +/** Manages the working copy of the chaperone info. By default this will be the same as the +* live copy. Any changes made with this interface will stay in the working copy until +* CommitWorkingCopy() is called, at which point the working copy and the live copy will be +* the same again. */ +class IVRChaperoneSetup +{ +public: + + /** Saves the current working copy to disk */ + virtual bool CommitWorkingCopy( EChaperoneConfigFile configFile ) = 0; + + /** Reverts the working copy to match the live chaperone calibration. + * To modify existing data this MUST be do WHILE getting a non-error ChaperoneCalibrationStatus. + * Only after this should you do gets and sets on the existing data. */ + virtual void RevertWorkingCopy() = 0; + + /** Returns the width and depth of the Play Area (formerly named Soft Bounds) in X and Z from the working copy. + * Tracking space center (0,0,0) is the center of the Play Area. */ + virtual bool GetWorkingPlayAreaSize( float *pSizeX, float *pSizeZ ) = 0; + + /** Returns the 4 corner positions of the Play Area (formerly named Soft Bounds) from the working copy. + * Corners are in clockwise order. + * Tracking space center (0,0,0) is the center of the Play Area. + * It's a rectangle. + * 2 sides are parallel to the X axis and 2 sides are parallel to the Z axis. + * Height of every corner is 0Y (on the floor). **/ + virtual bool GetWorkingPlayAreaRect( HmdQuad_t *rect ) = 0; + + /** Returns the number of Quads if the buffer points to null. Otherwise it returns Quads + * into the buffer up to the max specified from the working copy. */ + virtual bool GetWorkingCollisionBoundsInfo( VR_OUT_ARRAY_COUNT(punQuadsCount) HmdQuad_t *pQuadsBuffer, uint32_t* punQuadsCount ) = 0; + + /** Returns the number of Quads if the buffer points to null. Otherwise it returns Quads + * into the buffer up to the max specified. */ + virtual bool GetLiveCollisionBoundsInfo( VR_OUT_ARRAY_COUNT(punQuadsCount) HmdQuad_t *pQuadsBuffer, uint32_t* punQuadsCount ) = 0; + + /** Returns the preferred seated position from the working copy. */ + virtual bool GetWorkingSeatedZeroPoseToRawTrackingPose( HmdMatrix34_t *pmatSeatedZeroPoseToRawTrackingPose ) = 0; + + /** Returns the standing origin from the working copy. */ + virtual bool GetWorkingStandingZeroPoseToRawTrackingPose( HmdMatrix34_t *pmatStandingZeroPoseToRawTrackingPose ) = 0; + + /** Sets the Play Area in the working copy. */ + virtual void SetWorkingPlayAreaSize( float sizeX, float sizeZ ) = 0; + + /** Sets the Collision Bounds in the working copy. Note: ceiling height is ignored. */ + virtual void SetWorkingCollisionBoundsInfo( VR_ARRAY_COUNT(unQuadsCount) HmdQuad_t *pQuadsBuffer, uint32_t unQuadsCount ) = 0; + + /** Sets the Collision Bounds in the working copy. */ + virtual void SetWorkingPerimeter( VR_ARRAY_COUNT( unPointCount ) HmdVector2_t *pPointBuffer, uint32_t unPointCount ) = 0; + + /** Sets the preferred seated position in the working copy. */ + virtual void SetWorkingSeatedZeroPoseToRawTrackingPose( const HmdMatrix34_t *pMatSeatedZeroPoseToRawTrackingPose ) = 0; + + /** Sets the preferred standing position in the working copy. */ + virtual void SetWorkingStandingZeroPoseToRawTrackingPose( const HmdMatrix34_t *pMatStandingZeroPoseToRawTrackingPose ) = 0; + + /** Tear everything down and reload it from the file on disk */ + virtual void ReloadFromDisk( EChaperoneConfigFile configFile ) = 0; + + /** Returns the preferred seated position. */ + virtual bool GetLiveSeatedZeroPoseToRawTrackingPose( HmdMatrix34_t *pmatSeatedZeroPoseToRawTrackingPose ) = 0; + + virtual bool ExportLiveToBuffer( VR_OUT_STRING() char *pBuffer, uint32_t *pnBufferLength ) = 0; + virtual bool ImportFromBufferToWorking( const char *pBuffer, uint32_t nImportFlags ) = 0; + + /** Shows the chaperone data in the working set to preview in the compositor.*/ + virtual void ShowWorkingSetPreview() = 0; + + /** Hides the chaperone data in the working set to preview in the compositor (if it was visible).*/ + virtual void HideWorkingSetPreview() = 0; + + /** Fire an event that the tracking system can use to know room setup is about to begin. This lets the tracking + * system make any last minute adjustments that should be incorporated into the new setup. If the user is adjusting + * live in HMD using a tweak tool, keep in mind that calling this might cause the user to see the room jump. */ + virtual void RoomSetupStarting() = 0; +}; + +static const char * const IVRChaperoneSetup_Version = "IVRChaperoneSetup_006"; + + +} + +// ivrcompositor.h + +namespace vr +{ + +#pragma pack( push, 8 ) + +/** Errors that can occur with the VR compositor */ +enum EVRCompositorError +{ + VRCompositorError_None = 0, + VRCompositorError_RequestFailed = 1, + VRCompositorError_IncompatibleVersion = 100, + VRCompositorError_DoNotHaveFocus = 101, + VRCompositorError_InvalidTexture = 102, + VRCompositorError_IsNotSceneApplication = 103, + VRCompositorError_TextureIsOnWrongDevice = 104, + VRCompositorError_TextureUsesUnsupportedFormat = 105, + VRCompositorError_SharedTexturesNotSupported = 106, + VRCompositorError_IndexOutOfRange = 107, + VRCompositorError_AlreadySubmitted = 108, + VRCompositorError_InvalidBounds = 109, + VRCompositorError_AlreadySet = 110, +}; + +/** Timing mode passed to SetExplicitTimingMode(); see that function for documentation */ +enum EVRCompositorTimingMode +{ + VRCompositorTimingMode_Implicit = 0, + VRCompositorTimingMode_Explicit_RuntimePerformsPostPresentHandoff = 1, + VRCompositorTimingMode_Explicit_ApplicationPerformsPostPresentHandoff = 2, +}; + +/** Cumulative stats for current application. These are not cleared until a new app connects, +* but they do stop accumulating once the associated app disconnects. */ +struct Compositor_CumulativeStats +{ + uint32_t m_nPid; // Process id associated with these stats (may no longer be running). + uint32_t m_nNumFramePresents; // total number of times we called present (includes reprojected frames) + uint32_t m_nNumDroppedFrames; // total number of times an old frame was re-scanned out (without reprojection) + uint32_t m_nNumReprojectedFrames; // total number of times a frame was scanned out a second time (with reprojection) + + /** Values recorded at startup before application has fully faded in the first time. */ + uint32_t m_nNumFramePresentsOnStartup; + uint32_t m_nNumDroppedFramesOnStartup; + uint32_t m_nNumReprojectedFramesOnStartup; + + /** Applications may explicitly fade to the compositor. This is usually to handle level transitions, and loading often causes + * system wide hitches. The following stats are collected during this period. Does not include values recorded during startup. */ + uint32_t m_nNumLoading; + uint32_t m_nNumFramePresentsLoading; + uint32_t m_nNumDroppedFramesLoading; + uint32_t m_nNumReprojectedFramesLoading; + + /** If we don't get a new frame from the app in less than 2.5 frames, then we assume the app has hung and start + * fading back to the compositor. The following stats are a result of this, and are a subset of those recorded above. + * Does not include values recorded during start up or loading. */ + uint32_t m_nNumTimedOut; + uint32_t m_nNumFramePresentsTimedOut; + uint32_t m_nNumDroppedFramesTimedOut; + uint32_t m_nNumReprojectedFramesTimedOut; + + /** For items in this section, divide all the values by m_nNumFrameSubmits. */ + uint32_t m_nNumFrameSubmits; + vrshared_double m_flSumCompositorCPUTimeMS; + vrshared_double m_flSumCompositorGPUTimeMS; + vrshared_double m_flSumTargetFrameTimes; + vrshared_double m_flSumApplicationCPUTimeMS; + vrshared_double m_flSumApplicationGPUTimeMS; + + uint32_t m_nNumFramesWithDepth; // total frames submitted with depth by the current application +}; + +struct Compositor_StageRenderSettings +{ + /** Primary color is applied as a tint to (i.e. multiplied with) the model's texture */ + HmdColor_t m_PrimaryColor; + HmdColor_t m_SecondaryColor; + + /** Vignette radius is in meters and is used to fade to the specified secondary solid color over + * that 3D distance from the origin of the playspace. */ + float m_flVignetteInnerRadius; + float m_flVignetteOuterRadius; + + /** Fades to the secondary color based on view incidence. This variable controls the linearity + * of the effect. It is mutually exclusive with vignette. Additionally, it treats the mesh as faceted. */ + float m_flFresnelStrength; + + /** Controls backface culling. */ + bool m_bBackfaceCulling; + + /** Converts the render model's texture to luma and applies to rgb equally. This is useful to + * combat compression artifacts that can occur on desaturated source material. */ + bool m_bGreyscale; + + /** Renders mesh as a wireframe. */ + bool m_bWireframe; +}; + +static inline Compositor_StageRenderSettings DefaultStageRenderSettings() +{ + Compositor_StageRenderSettings settings; + settings.m_PrimaryColor.r = 1.0f; + settings.m_PrimaryColor.g = 1.0f; + settings.m_PrimaryColor.b = 1.0f; + settings.m_PrimaryColor.a = 1.0f; + settings.m_SecondaryColor.r = 1.0f; + settings.m_SecondaryColor.g = 1.0f; + settings.m_SecondaryColor.b = 1.0f; + settings.m_SecondaryColor.a = 1.0f; + settings.m_flVignetteInnerRadius = 0.0f; + settings.m_flVignetteOuterRadius = 0.0f; + settings.m_flFresnelStrength = 0.0f; + settings.m_bBackfaceCulling = false; + settings.m_bGreyscale = false; + settings.m_bWireframe = false; + return settings; +} + +#pragma pack( pop ) + +/** Allows the application to interact with the compositor */ +class IVRCompositor +{ +public: + /** Sets tracking space returned by WaitGetPoses */ + virtual void SetTrackingSpace( ETrackingUniverseOrigin eOrigin ) = 0; + + /** Gets current tracking space returned by WaitGetPoses */ + virtual ETrackingUniverseOrigin GetTrackingSpace() = 0; + + /** Scene applications should call this function to get poses to render with (and optionally poses predicted an additional frame out to use for gameplay). + * This function will block until "running start" milliseconds before the start of the frame, and should be called at the last moment before needing to + * start rendering. + * + * Return codes: + * - IsNotSceneApplication (make sure to call VR_Init with VRApplicaiton_Scene) + * - DoNotHaveFocus (some other app has taken focus - this will throttle the call to 10hz to reduce the impact on that app) + */ + virtual EVRCompositorError WaitGetPoses( VR_ARRAY_COUNT( unRenderPoseArrayCount ) TrackedDevicePose_t* pRenderPoseArray, uint32_t unRenderPoseArrayCount, + VR_ARRAY_COUNT( unGamePoseArrayCount ) TrackedDevicePose_t* pGamePoseArray, uint32_t unGamePoseArrayCount ) = 0; + + /** Get the last set of poses returned by WaitGetPoses. */ + virtual EVRCompositorError GetLastPoses( VR_ARRAY_COUNT( unRenderPoseArrayCount ) TrackedDevicePose_t* pRenderPoseArray, uint32_t unRenderPoseArrayCount, + VR_ARRAY_COUNT( unGamePoseArrayCount ) TrackedDevicePose_t* pGamePoseArray, uint32_t unGamePoseArrayCount ) = 0; + + /** Interface for accessing last set of poses returned by WaitGetPoses one at a time. + * Returns VRCompositorError_IndexOutOfRange if unDeviceIndex not less than k_unMaxTrackedDeviceCount otherwise VRCompositorError_None. + * It is okay to pass NULL for either pose if you only want one of the values. */ + virtual EVRCompositorError GetLastPoseForTrackedDeviceIndex( TrackedDeviceIndex_t unDeviceIndex, TrackedDevicePose_t *pOutputPose, TrackedDevicePose_t *pOutputGamePose ) = 0; + + /** Updated scene texture to display. If pBounds is NULL the entire texture will be used. If called from an OpenGL app, consider adding a glFlush after + * Submitting both frames to signal the driver to start processing, otherwise it may wait until the command buffer fills up, causing the app to miss frames. + * + * OpenGL dirty state: + * glBindTexture + * + * Return codes: + * - IsNotSceneApplication (make sure to call VR_Init with VRApplicaiton_Scene) + * - DoNotHaveFocus (some other app has taken focus) + * - TextureIsOnWrongDevice (application did not use proper AdapterIndex - see IVRSystem.GetDXGIOutputInfo) + * - SharedTexturesNotSupported (application needs to call CreateDXGIFactory1 or later before creating DX device) + * - TextureUsesUnsupportedFormat (scene textures must be compatible with DXGI sharing rules - e.g. uncompressed, no mips, etc.) + * - InvalidTexture (usually means bad arguments passed in) + * - AlreadySubmitted (app has submitted two left textures or two right textures in a single frame - i.e. before calling WaitGetPoses again) + */ + virtual EVRCompositorError Submit( EVREye eEye, const Texture_t *pTexture, const VRTextureBounds_t* pBounds = 0, EVRSubmitFlags nSubmitFlags = Submit_Default ) = 0; + + /** Clears the frame that was sent with the last call to Submit. This will cause the + * compositor to show the grid until Submit is called again. */ + virtual void ClearLastSubmittedFrame() = 0; + + /** Call immediately after presenting your app's window (i.e. companion window) to unblock the compositor. + * This is an optional call, which only needs to be used if you can't instead call WaitGetPoses immediately after Present. + * For example, if your engine's render and game loop are not on separate threads, or blocking the render thread until 3ms before the next vsync would + * introduce a deadlock of some sort. This function tells the compositor that you have finished all rendering after having Submitted buffers for both + * eyes, and it is free to start its rendering work. This should only be called from the same thread you are rendering on. */ + virtual void PostPresentHandoff() = 0; + + /** Returns true if timing data is filled it. Sets oldest timing info if nFramesAgo is larger than the stored history. + * Be sure to set timing.size = sizeof(Compositor_FrameTiming) on struct passed in before calling this function. */ + virtual bool GetFrameTiming( Compositor_FrameTiming *pTiming, uint32_t unFramesAgo = 0 ) = 0; + + /** Interface for copying a range of timing data. Frames are returned in ascending order (oldest to newest) with the last being the most recent frame. + * Only the first entry's m_nSize needs to be set, as the rest will be inferred from that. Returns total number of entries filled out. */ + virtual uint32_t GetFrameTimings( VR_ARRAY_COUNT( nFrames ) Compositor_FrameTiming *pTiming, uint32_t nFrames ) = 0; + + /** Returns the time in seconds left in the current (as identified by FrameTiming's frameIndex) frame. + * Due to "running start", this value may roll over to the next frame before ever reaching 0.0. */ + virtual float GetFrameTimeRemaining() = 0; + + /** Fills out stats accumulated for the last connected application. Pass in sizeof( Compositor_CumulativeStats ) as second parameter. */ + virtual void GetCumulativeStats( Compositor_CumulativeStats *pStats, uint32_t nStatsSizeInBytes ) = 0; + + /** Fades the view on the HMD to the specified color. The fade will take fSeconds, and the color values are between + * 0.0 and 1.0. This color is faded on top of the scene based on the alpha parameter. Removing the fade color instantly + * would be FadeToColor( 0.0, 0.0, 0.0, 0.0, 0.0 ). Values are in un-premultiplied alpha space. */ + virtual void FadeToColor( float fSeconds, float fRed, float fGreen, float fBlue, float fAlpha, bool bBackground = false ) = 0; + + /** Get current fade color value. */ + virtual HmdColor_t GetCurrentFadeColor( bool bBackground = false ) = 0; + + /** Fading the Grid in or out in fSeconds */ + virtual void FadeGrid( float fSeconds, bool bFadeGridIn ) = 0; + + /** Get current alpha value of grid. */ + virtual float GetCurrentGridAlpha() = 0; + + /** Override the skybox used in the compositor (e.g. for during level loads when the app can't feed scene images fast enough) + * Order is Front, Back, Left, Right, Top, Bottom. If only a single texture is passed, it is assumed in lat-long format. + * If two are passed, it is assumed a lat-long stereo pair. */ + virtual EVRCompositorError SetSkyboxOverride( VR_ARRAY_COUNT( unTextureCount ) const Texture_t *pTextures, uint32_t unTextureCount ) = 0; + + /** Resets compositor skybox back to defaults. */ + virtual void ClearSkyboxOverride() = 0; + + /** Brings the compositor window to the front. This is useful for covering any other window that may be on the HMD + * and is obscuring the compositor window. */ + virtual void CompositorBringToFront() = 0; + + /** Pushes the compositor window to the back. This is useful for allowing other applications to draw directly to the HMD. */ + virtual void CompositorGoToBack() = 0; + + /** DEPRECATED: Tells the compositor process to clean up and exit. You do not need to call this function at shutdown. + * Under normal circumstances the compositor will manage its own life cycle based on what applications are running. */ + virtual void CompositorQuit() = 0; + + /** Return whether the compositor is fullscreen */ + virtual bool IsFullscreen() = 0; + + /** Returns the process ID of the process that is currently rendering the scene */ + virtual uint32_t GetCurrentSceneFocusProcess() = 0; + + /** Returns the process ID of the process that rendered the last frame (or 0 if the compositor itself rendered the frame.) + * Returns 0 when fading out from an app and the app's process Id when fading into an app. */ + virtual uint32_t GetLastFrameRenderer() = 0; + + /** Returns true if the current process has the scene focus */ + virtual bool CanRenderScene() = 0; + + /** DEPRECATED: Opens the headset view (as either a window or docked widget depending on user's preferences) that displays what the user + * sees in the headset. */ + virtual void ShowMirrorWindow() = 0; + + /** DEPRECATED: Closes the headset view, either as a window or docked widget. */ + virtual void HideMirrorWindow() = 0; + + /** DEPRECATED: Returns true if the headset view (either as a window or docked widget) is shown. */ + virtual bool IsMirrorWindowVisible() = 0; + + /** Writes back buffer and stereo left/right pair from the application to a 'screenshots' folder in the SteamVR runtime root. */ + virtual void CompositorDumpImages() = 0; + + /** Let an app know it should be rendering with low resources. */ + virtual bool ShouldAppRenderWithLowResources() = 0; + + /** Override interleaved reprojection logic to force on. */ + virtual void ForceInterleavedReprojectionOn( bool bOverride ) = 0; + + /** Force reconnecting to the compositor process. */ + virtual void ForceReconnectProcess() = 0; + + /** Temporarily suspends rendering (useful for finer control over scene transitions). */ + virtual void SuspendRendering( bool bSuspend ) = 0; + + /** Opens a shared D3D11 texture with the undistorted composited image for each eye. Use ReleaseMirrorTextureD3D11 when finished + * instead of calling Release on the resource itself. */ + virtual vr::EVRCompositorError GetMirrorTextureD3D11( vr::EVREye eEye, void *pD3D11DeviceOrResource, void **ppD3D11ShaderResourceView ) = 0; + virtual void ReleaseMirrorTextureD3D11( void *pD3D11ShaderResourceView ) = 0; + + /** Access to mirror textures from OpenGL. */ + virtual vr::EVRCompositorError GetMirrorTextureGL( vr::EVREye eEye, vr::glUInt_t *pglTextureId, vr::glSharedTextureHandle_t *pglSharedTextureHandle ) = 0; + virtual bool ReleaseSharedGLTexture( vr::glUInt_t glTextureId, vr::glSharedTextureHandle_t glSharedTextureHandle ) = 0; + virtual void LockGLSharedTextureForAccess( vr::glSharedTextureHandle_t glSharedTextureHandle ) = 0; + virtual void UnlockGLSharedTextureForAccess( vr::glSharedTextureHandle_t glSharedTextureHandle ) = 0; + + /** [Vulkan Only] + * return 0. Otherwise it returns the length of the number of bytes necessary to hold this string including the trailing + * null. The string will be a space separated list of-required instance extensions to enable in VkCreateInstance */ + virtual uint32_t GetVulkanInstanceExtensionsRequired( VR_OUT_STRING() char *pchValue, uint32_t unBufferSize ) = 0; + + /** [Vulkan only] + * return 0. Otherwise it returns the length of the number of bytes necessary to hold this string including the trailing + * null. The string will be a space separated list of required device extensions to enable in VkCreateDevice */ + virtual uint32_t GetVulkanDeviceExtensionsRequired( VkPhysicalDevice_T *pPhysicalDevice, VR_OUT_STRING() char *pchValue, uint32_t unBufferSize ) = 0; + + /** [ Vulkan/D3D12 Only ] + * There are two purposes for SetExplicitTimingMode: + * 1. To get a more accurate GPU timestamp for when the frame begins in Vulkan/D3D12 applications. + * 2. (Optional) To avoid having WaitGetPoses access the Vulkan queue so that the queue can be accessed from + * another thread while WaitGetPoses is executing. + * + * More accurate GPU timestamp for the start of the frame is achieved by the application calling + * SubmitExplicitTimingData immediately before its first submission to the Vulkan/D3D12 queue. + * This is more accurate because normally this GPU timestamp is recorded during WaitGetPoses. In D3D11, + * WaitGetPoses queues a GPU timestamp write, but it does not actually get submitted to the GPU until the + * application flushes. By using SubmitExplicitTimingData, the timestamp is recorded at the same place for + * Vulkan/D3D12 as it is for D3D11, resulting in a more accurate GPU time measurement for the frame. + * + * Avoiding WaitGetPoses accessing the Vulkan queue can be achieved using SetExplicitTimingMode as well. If this is desired, + * the application should set the timing mode to Explicit_ApplicationPerformsPostPresentHandoff and *MUST* call PostPresentHandoff + * itself. If these conditions are met, then WaitGetPoses is guaranteed not to access the queue. Note that PostPresentHandoff + * and SubmitExplicitTimingData will access the queue, so only WaitGetPoses becomes safe for accessing the queue from another + * thread. */ + virtual void SetExplicitTimingMode( EVRCompositorTimingMode eTimingMode ) = 0; + + /** [ Vulkan/D3D12 Only ] + * Submit explicit timing data. When SetExplicitTimingMode is true, this must be called immediately before + * the application's first vkQueueSubmit (Vulkan) or ID3D12CommandQueue::ExecuteCommandLists (D3D12) of each frame. + * This function will insert a GPU timestamp write just before the application starts its rendering. This function + * will perform a vkQueueSubmit on Vulkan so must not be done simultaneously with VkQueue operations on another thread. + * Returns VRCompositorError_RequestFailed if SetExplicitTimingMode is not enabled. */ + virtual EVRCompositorError SubmitExplicitTimingData() = 0; + + /** Indicates whether or not motion smoothing is enabled by the user settings. + * If you want to know if motion smoothing actually triggered due to a late frame, check Compositor_FrameTiming + * m_nReprojectionFlags & VRCompositor_ReprojectionMotion instead. */ + virtual bool IsMotionSmoothingEnabled() = 0; + + /** Indicates whether or not motion smoothing is supported by the current hardware. */ + virtual bool IsMotionSmoothingSupported() = 0; + + /** Indicates whether or not the current scene focus app is currently loading. This is inferred from its use of FadeGrid to + * explicitly fade to the compositor to cover up the fact that it cannot render at a sustained full framerate during this time. */ + virtual bool IsCurrentSceneFocusAppLoading() = 0; + + /** Override the stage model used in the compositor to replace the grid. RenderModelPath is a full path the an OBJ file to load. + * This file will be loaded asynchronously from disk and uploaded to the gpu by the runtime. Once ready for rendering, the + * VREvent StageOverrideReady will be sent. Use FadeToGrid to reveal. Call ClearStageOverride to free the associated resources when finished. */ + virtual EVRCompositorError SetStageOverride_Async( const char *pchRenderModelPath, const HmdMatrix34_t *pTransform = 0, + const Compositor_StageRenderSettings *pRenderSettings = 0, uint32_t nSizeOfRenderSettings = 0 ) = 0; + + /** Resets the stage to its default user specified setting. */ + virtual void ClearStageOverride() = 0; + + /** Returns true if pBenchmarkResults is filled it. Sets pBenchmarkResults with the result of the compositor benchmark. + * nSizeOfBenchmarkResults should be set to sizeof(Compositor_BenchmarkResults) */ + virtual bool GetCompositorBenchmarkResults( Compositor_BenchmarkResults *pBenchmarkResults, uint32_t nSizeOfBenchmarkResults ) = 0; + + /** Returns the frame id associated with the poses last returned by WaitGetPoses. Deltas between IDs correspond to number of headset vsync intervals. */ + virtual EVRCompositorError GetLastPosePredictionIDs( uint32_t *pRenderPosePredictionID, uint32_t *pGamePosePredictionID ) = 0; + + /** Get the most up-to-date predicted (or recorded - up to 100ms old) set of poses for a given frame id. */ + virtual EVRCompositorError GetPosesForFrame( uint32_t unPosePredictionID, VR_ARRAY_COUNT( unPoseArrayCount ) TrackedDevicePose_t* pPoseArray, uint32_t unPoseArrayCount ) = 0; +}; + +static const char * const IVRCompositor_Version = "IVRCompositor_027"; + +} // namespace vr + + + +// ivrheadsetview.h + +namespace vr +{ + enum HeadsetViewMode_t + { + HeadsetViewMode_Left = 0, + HeadsetViewMode_Right, + HeadsetViewMode_Both + }; + + class IVRHeadsetView + { + public: + /** Sets the resolution in pixels to render the headset view. These values are clamped to k_unHeadsetViewMaxWidth + * and k_unHeadsetViewMaxHeight respectively. For cropped views, the rendered output will be fit to aspect ratio + * defined by the the specified dimensions. For uncropped views, the caller should use GetHeadsetViewAspectRation + * to adjust the requested render size to avoid squashing or stretching, and then apply letterboxing to compensate + * when displaying the results. */ + virtual void SetHeadsetViewSize( uint32_t nWidth, uint32_t nHeight ) = 0; + + /** Gets the current resolution used to render the headset view. */ + virtual void GetHeadsetViewSize( uint32_t *pnWidth, uint32_t *pnHeight ) = 0; + + /** Set the mode used to render the headset view. */ + virtual void SetHeadsetViewMode( HeadsetViewMode_t eHeadsetViewMode ) = 0; + + /** Get the current mode used to render the headset view. */ + virtual HeadsetViewMode_t GetHeadsetViewMode() = 0; + + /** Set whether or not the headset view should be rendered cropped to hide the hidden area mesh or not. */ + virtual void SetHeadsetViewCropped( bool bCropped ) = 0; + + /** Get the current cropping status of the headset view. */ + virtual bool GetHeadsetViewCropped() = 0; + + /** Get the aspect ratio (width:height) of the uncropped headset view (accounting for the current set mode). */ + virtual float GetHeadsetViewAspectRatio() = 0; + + /** Set the range [0..1] that the headset view blends across the stereo overlapped area in cropped both mode. */ + virtual void SetHeadsetViewBlendRange( float flStartPct, float flEndPct ) = 0; + + /** Get the current range [0..1] that the headset view blends across the stereo overlapped area in cropped both mode. */ + virtual void GetHeadsetViewBlendRange( float *pStartPct, float *pEndPct ) = 0; + }; + + static const uint32_t k_unHeadsetViewMaxWidth = 3840; + static const uint32_t k_unHeadsetViewMaxHeight = 2160; + static const char * const k_pchHeadsetViewOverlayKey = "system.HeadsetView"; + + static const char * const IVRHeadsetView_Version = "IVRHeadsetView_001"; + + /** Returns the current IVRHeadsetView pointer or NULL the interface could not be found. */ + VR_INTERFACE vr::IVRHeadsetView *VR_CALLTYPE VRHeadsetView(); + +} // namespace vr + + +// ivrnotifications.h + +namespace vr +{ + +#pragma pack( push, 8 ) + +// Used for passing graphic data +struct NotificationBitmap_t +{ + NotificationBitmap_t() + : m_pImageData( nullptr ) + , m_nWidth( 0 ) + , m_nHeight( 0 ) + , m_nBytesPerPixel( 0 ) + { + } + + void *m_pImageData; + int32_t m_nWidth; + int32_t m_nHeight; + int32_t m_nBytesPerPixel; +}; + + +/** Be aware that the notification type is used as 'priority' to pick the next notification */ +enum EVRNotificationType +{ + /** Transient notifications are automatically hidden after a period of time set by the user. + * They are used for things like information and chat messages that do not require user interaction. */ + EVRNotificationType_Transient = 0, + + /** Persistent notifications are shown to the user until they are hidden by calling RemoveNotification(). + * They are used for things like phone calls and alarms that require user interaction. */ + EVRNotificationType_Persistent = 1, + + /** System notifications are shown no matter what. It is expected, that the ulUserValue is used as ID. + * If there is already a system notification in the queue with that ID it is not accepted into the queue + * to prevent spamming with system notification */ + EVRNotificationType_Transient_SystemWithUserValue = 2, +}; + +enum EVRNotificationStyle +{ + /** Creates a notification with minimal external styling. */ + EVRNotificationStyle_None = 0, + + /** Used for notifications about overlay-level status. In Steam this is used for events like downloads completing. */ + EVRNotificationStyle_Application = 100, + + /** Used for notifications about contacts that are unknown or not available. In Steam this is used for friend invitations and offline friends. */ + EVRNotificationStyle_Contact_Disabled = 200, + + /** Used for notifications about contacts that are available but inactive. In Steam this is used for friends that are online but not playing a game. */ + EVRNotificationStyle_Contact_Enabled = 201, + + /** Used for notifications about contacts that are available and active. In Steam this is used for friends that are online and currently running a game. */ + EVRNotificationStyle_Contact_Active = 202, +}; + +static const uint32_t k_unNotificationTextMaxSize = 256; + +typedef uint32_t VRNotificationId; + + + +#pragma pack( pop ) + +/** Allows notification sources to interact with the VR system. */ +class IVRNotifications +{ +public: + /** Create a notification and enqueue it to be shown to the user. + * An overlay handle is required to create a notification, as otherwise it would be impossible for a user to act on it. + * To create a two-line notification, use a line break ('\n') to split the text into two lines. + * The pImage argument may be NULL, in which case the specified overlay's icon will be used instead. */ + virtual EVRNotificationError CreateNotification( VROverlayHandle_t ulOverlayHandle, uint64_t ulUserValue, EVRNotificationType type, const char *pchText, EVRNotificationStyle style, const NotificationBitmap_t *pImage, /* out */ VRNotificationId *pNotificationId ) = 0; + + /** Destroy a notification, hiding it first if it currently shown to the user. */ + virtual EVRNotificationError RemoveNotification( VRNotificationId notificationId ) = 0; + +}; + +static const char * const IVRNotifications_Version = "IVRNotifications_002"; + +} // namespace vr + + + +// ivroverlay.h + +namespace vr +{ + + /** The maximum length of an overlay key in bytes, counting the terminating null character. */ + static const uint32_t k_unVROverlayMaxKeyLength = 128; + + /** The maximum length of an overlay name in bytes, counting the terminating null character. */ + static const uint32_t k_unVROverlayMaxNameLength = 128; + + /** The maximum number of overlays that can exist in the system at one time. */ + static const uint32_t k_unMaxOverlayCount = 128; + + /** The maximum number of overlay intersection mask primitives per overlay */ + static const uint32_t k_unMaxOverlayIntersectionMaskPrimitivesCount = 32; + + /** Types of input supported by VR Overlays */ + enum VROverlayInputMethod + { + VROverlayInputMethod_None = 0, // No input events will be generated automatically for this overlay + VROverlayInputMethod_Mouse = 1, // Tracked controllers will get mouse events automatically + // VROverlayInputMethod_DualAnalog = 2, // No longer supported + }; + + /** Allows the caller to figure out which overlay transform getter to call. */ + enum VROverlayTransformType + { + VROverlayTransform_Invalid = -1, + VROverlayTransform_Absolute = 0, + VROverlayTransform_TrackedDeviceRelative = 1, + //VROverlayTransform_SystemOverlay = 2, // Deleted from the SDK. + VROverlayTransform_TrackedComponent = 3, + VROverlayTransform_Cursor = 4, + VROverlayTransform_DashboardTab = 5, + VROverlayTransform_DashboardThumb = 6, + VROverlayTransform_Mountable = 7, + VROverlayTransform_Projection = 8, + VROverlayTransform_Subview = 9, + }; + + /** Overlay control settings */ + enum VROverlayFlags + { + // Set this flag on a dashboard overlay to prevent a tab from showing up for that overlay + VROverlayFlags_NoDashboardTab = 1 << 3, + + // When this is set the overlay will receive VREvent_ScrollDiscrete events like a mouse wheel. + // Requires mouse input mode. + VROverlayFlags_SendVRDiscreteScrollEvents = 1 << 6, + + // Indicates that the overlay would like to receive + VROverlayFlags_SendVRTouchpadEvents = 1 << 7, + + // If set this will render a vertical scroll wheel on the primary controller, + // only needed if not using VROverlayFlags_SendVRScrollEvents but you still want to represent a scroll wheel + VROverlayFlags_ShowTouchPadScrollWheel = 1 << 8, + + // If this is set ownership and render access to the overlay are transferred + // to the new scene process on a call to IVRApplications::LaunchInternalProcess + VROverlayFlags_TransferOwnershipToInternalProcess = 1 << 9, + + // If set, renders 50% of the texture in each eye, side by side + VROverlayFlags_SideBySide_Parallel = 1 << 10, // Texture is left/right + VROverlayFlags_SideBySide_Crossed = 1 << 11, // Texture is crossed and right/left + + VROverlayFlags_Panorama = 1 << 12, // Texture is a panorama + VROverlayFlags_StereoPanorama = 1 << 13, // Texture is a stereo panorama + + // If this is set on an overlay owned by the scene application that overlay + // will be sorted with the "Other" overlays on top of all other scene overlays + VROverlayFlags_SortWithNonSceneOverlays = 1 << 14, + + // If set, the overlay will be shown in the dashboard, otherwise it will be hidden. + VROverlayFlags_VisibleInDashboard = 1 << 15, + + // If this is set and the overlay's input method is not none, the system-wide laser mouse + // mode will be activated whenever this overlay is visible. + VROverlayFlags_MakeOverlaysInteractiveIfVisible = 1 << 16, + + // If this is set the overlay will receive smooth VREvent_ScrollSmooth that emulate trackpad scrolling. + // Requires mouse input mode. + VROverlayFlags_SendVRSmoothScrollEvents = 1 << 17, + + // If this is set, the overlay texture will be protected content, preventing unauthorized reads. + VROverlayFlags_ProtectedContent = 1 << 18, + + // If this is set, the laser mouse splat will not be drawn over this overlay. The overlay will + // be responsible for drawing its own "cursor". + VROverlayFlags_HideLaserIntersection = 1 << 19, + + // If this is set, clicking away from the overlay will cause it to receive a VREvent_Modal_Cancel event. + // This is ignored for dashboard overlays. + VROverlayFlags_WantsModalBehavior = 1 << 20, + + // If this is set, alpha composition assumes the texture is pre-multiplied + VROverlayFlags_IsPremultiplied = 1 << 21, + + // If this is set, the alpha values of the overlay texture will be ignored + VROverlayFlags_IgnoreTextureAlpha = 1 << 22, + + // If this is set, this overlay will have a control bar drawn underneath of it in the dashboard. + VROverlayFlags_EnableControlBar = 1 << 23, + + // If this is set, the overlay control bar will provide a button to toggle the keyboard. + VROverlayFlags_EnableControlBarKeyboard = 1 << 24, + + // If this is set, the overlay control bar will provide a "close" button which will send a + // VREvent_OverlayClosed event to the overlay when pressed. Applications that use this flag are responsible + // for responding to the event with something that approximates "closing" behavior, such as destroying their + // overlay and/or shutting down their application. + VROverlayFlags_EnableControlBarClose = 1 << 25, + + // Do not use + VROverlayFlags_Reserved = 1 << 26, + + // If this is set, click stabilization will be applied to the laser interaction so that clicks more reliably + // trigger on the user's intended target + VROverlayFlags_EnableClickStabilization = 1 << 27, + }; + + enum VRMessageOverlayResponse + { + VRMessageOverlayResponse_ButtonPress_0 = 0, + VRMessageOverlayResponse_ButtonPress_1 = 1, + VRMessageOverlayResponse_ButtonPress_2 = 2, + VRMessageOverlayResponse_ButtonPress_3 = 3, + VRMessageOverlayResponse_CouldntFindSystemOverlay = 4, + VRMessageOverlayResponse_CouldntFindOrCreateClientOverlay= 5, + VRMessageOverlayResponse_ApplicationQuit = 6 + }; + + struct VROverlayIntersectionParams_t + { + HmdVector3_t vSource; + HmdVector3_t vDirection; + ETrackingUniverseOrigin eOrigin; + }; + + struct VROverlayIntersectionResults_t + { + HmdVector3_t vPoint; + HmdVector3_t vNormal; + HmdVector2_t vUVs; + float fDistance; + }; + + // Input modes for the Big Picture gamepad text entry + enum EGamepadTextInputMode + { + k_EGamepadTextInputModeNormal = 0, + k_EGamepadTextInputModePassword = 1, + k_EGamepadTextInputModeSubmit = 2, + }; + + // Controls number of allowed lines for the Big Picture gamepad text entry + enum EGamepadTextInputLineMode + { + k_EGamepadTextInputLineModeSingleLine = 0, + k_EGamepadTextInputLineModeMultipleLines = 1 + }; + + enum EVROverlayIntersectionMaskPrimitiveType + { + OverlayIntersectionPrimitiveType_Rectangle, + OverlayIntersectionPrimitiveType_Circle, + }; + + struct IntersectionMaskRectangle_t + { + float m_flTopLeftX; + float m_flTopLeftY; + float m_flWidth; + float m_flHeight; + }; + + struct IntersectionMaskCircle_t + { + float m_flCenterX; + float m_flCenterY; + float m_flRadius; + }; + + /** NOTE!!! If you change this you MUST manually update openvr_interop.cs.py and openvr_api_flat.h.py */ + typedef union + { + IntersectionMaskRectangle_t m_Rectangle; + IntersectionMaskCircle_t m_Circle; + } VROverlayIntersectionMaskPrimitive_Data_t; + + struct VROverlayIntersectionMaskPrimitive_t + { + EVROverlayIntersectionMaskPrimitiveType m_nPrimitiveType; + VROverlayIntersectionMaskPrimitive_Data_t m_Primitive; + }; + + enum EKeyboardFlags + { + /** Makes the keyboard send key events immediately instead of accumulating a buffer */ + KeyboardFlag_Minimal = 1 << 0, + /** Makes the keyboard take all focus and dismiss when clicking off the panel */ + KeyboardFlag_Modal = 1 << 1, + /** Shows arrow keys on the keyboard when in minimal mode. Buffered (non-minimal) mode always has them. In minimal + * mode, when arrow keys are pressed, they send ANSI escape sequences (e.g. "\x1b[D" for left arrow). */ + KeyboardFlag_ShowArrowKeys = 1 << 2, + /** Shows the hide keyboard button instead of a Done button. The Done key sends a VREvent_KeyboardDone when + * clicked. Hide only sends the Closed event. */ + KeyboardFlag_HideDoneKey = 1 << 3, + }; + + /** Defines the project used in an overlay that is using SetOverlayTransformProjection */ + struct VROverlayProjection_t + { + /** Tangent of the sides of the frustum */ + float fLeft; + float fRight; + float fTop; + float fBottom; + }; + + class IVROverlay + { + public: + + // --------------------------------------------- + // Overlay management methods + // --------------------------------------------- + + /** Finds an existing overlay with the specified key. */ + virtual EVROverlayError FindOverlay( const char *pchOverlayKey, VROverlayHandle_t * pOverlayHandle ) = 0; + + /** Creates a new named overlay. All overlays start hidden and with default settings. */ + virtual EVROverlayError CreateOverlay( const char *pchOverlayKey, const char *pchOverlayName, VROverlayHandle_t * pOverlayHandle ) = 0; + + /** Destroys the specified overlay. When an application calls VR_Shutdown all overlays created by that app are + * automatically destroyed. */ + virtual EVROverlayError DestroyOverlay( VROverlayHandle_t ulOverlayHandle ) = 0; + + /** Fills the provided buffer with the string key of the overlay. Returns the size of buffer required to store the key, including + * the terminating null character. k_unVROverlayMaxKeyLength will be enough bytes to fit the string. */ + virtual uint32_t GetOverlayKey( VROverlayHandle_t ulOverlayHandle, VR_OUT_STRING() char *pchValue, uint32_t unBufferSize, EVROverlayError *pError = 0L ) = 0; + + /** Fills the provided buffer with the friendly name of the overlay. Returns the size of buffer required to store the key, including + * the terminating null character. k_unVROverlayMaxNameLength will be enough bytes to fit the string. */ + virtual uint32_t GetOverlayName( VROverlayHandle_t ulOverlayHandle, VR_OUT_STRING() char *pchValue, uint32_t unBufferSize, EVROverlayError *pError = 0L ) = 0; + + /** set the name to use for this overlay */ + virtual EVROverlayError SetOverlayName( VROverlayHandle_t ulOverlayHandle, const char *pchName ) = 0; + + /** Gets the raw image data from an overlay. Overlay image data is always returned as RGBA data, 4 bytes per pixel. If the buffer is not large enough, width and height + * will be set and VROverlayError_ArrayTooSmall is returned. */ + virtual EVROverlayError GetOverlayImageData( VROverlayHandle_t ulOverlayHandle, void *pvBuffer, uint32_t unBufferSize, uint32_t *punWidth, uint32_t *punHeight ) = 0; + + /** returns a string that corresponds with the specified overlay error. The string will be the name + * of the error enum value for all valid error codes */ + virtual const char *GetOverlayErrorNameFromEnum( EVROverlayError error ) = 0; + + // --------------------------------------------- + // Overlay rendering methods + // --------------------------------------------- + + /** Sets the pid that is allowed to render to this overlay (the creator pid is always allow to render), + * by default this is the pid of the process that made the overlay */ + virtual EVROverlayError SetOverlayRenderingPid( VROverlayHandle_t ulOverlayHandle, uint32_t unPID ) = 0; + + /** Gets the pid that is allowed to render to this overlay */ + virtual uint32_t GetOverlayRenderingPid( VROverlayHandle_t ulOverlayHandle ) = 0; + + /** Specify flag setting for a given overlay */ + virtual EVROverlayError SetOverlayFlag( VROverlayHandle_t ulOverlayHandle, VROverlayFlags eOverlayFlag, bool bEnabled ) = 0; + + /** Sets flag setting for a given overlay */ + virtual EVROverlayError GetOverlayFlag( VROverlayHandle_t ulOverlayHandle, VROverlayFlags eOverlayFlag, bool *pbEnabled ) = 0; + + /** Gets all the flags for a given overlay */ + virtual EVROverlayError GetOverlayFlags( VROverlayHandle_t ulOverlayHandle, uint32_t *pFlags ) = 0; + + /** Sets the color tint of the overlay quad. Use 0.0 to 1.0 per channel. */ + virtual EVROverlayError SetOverlayColor( VROverlayHandle_t ulOverlayHandle, float fRed, float fGreen, float fBlue ) = 0; + + /** Gets the color tint of the overlay quad. */ + virtual EVROverlayError GetOverlayColor( VROverlayHandle_t ulOverlayHandle, float *pfRed, float *pfGreen, float *pfBlue ) = 0; + + /** Sets the alpha of the overlay quad. Use 1.0 for 100 percent opacity to 0.0 for 0 percent opacity. */ + virtual EVROverlayError SetOverlayAlpha( VROverlayHandle_t ulOverlayHandle, float fAlpha ) = 0; + + /** Gets the alpha of the overlay quad. By default overlays are rendering at 100 percent alpha (1.0). */ + virtual EVROverlayError GetOverlayAlpha( VROverlayHandle_t ulOverlayHandle, float *pfAlpha ) = 0; + + /** Sets the aspect ratio of the texels in the overlay. 1.0 means the texels are square. 2.0 means the texels + * are twice as wide as they are tall. Defaults to 1.0. */ + virtual EVROverlayError SetOverlayTexelAspect( VROverlayHandle_t ulOverlayHandle, float fTexelAspect ) = 0; + + /** Gets the aspect ratio of the texels in the overlay. Defaults to 1.0 */ + virtual EVROverlayError GetOverlayTexelAspect( VROverlayHandle_t ulOverlayHandle, float *pfTexelAspect ) = 0; + + /** Sets the rendering sort order for the overlay. Overlays are rendered this order: + * Overlays owned by the scene application + * Overlays owned by some other application + * + * Within a category overlays are rendered lowest sort order to highest sort order. Overlays with the same + * sort order are rendered back to front base on distance from the HMD. + * + * Subview overlays are always drawn immediately on top of their parent overlay, and the sort order is + * only relative to their peer subviews for that overlay. + * + * Sort order defaults to 0. */ + virtual EVROverlayError SetOverlaySortOrder( VROverlayHandle_t ulOverlayHandle, uint32_t unSortOrder ) = 0; + + /** Gets the sort order of the overlay. See SetOverlaySortOrder for how this works. */ + virtual EVROverlayError GetOverlaySortOrder( VROverlayHandle_t ulOverlayHandle, uint32_t *punSortOrder ) = 0; + + /** Sets the width of the overlay quad in meters. By default overlays are rendered on a quad that is 1 meter across */ + virtual EVROverlayError SetOverlayWidthInMeters( VROverlayHandle_t ulOverlayHandle, float fWidthInMeters ) = 0; + + /** Returns the width of the overlay quad in meters. By default overlays are rendered on a quad that is 1 meter across */ + virtual EVROverlayError GetOverlayWidthInMeters( VROverlayHandle_t ulOverlayHandle, float *pfWidthInMeters ) = 0; + + /** Use to draw overlay as a curved surface. Curvature is a percentage from (0..1] where 1 is a fully closed cylinder. + * For a specific radius, curvature can be computed as: overlay.width / (2 PI r). */ + virtual EVROverlayError SetOverlayCurvature( VROverlayHandle_t ulOverlayHandle, float fCurvature ) = 0; + + /** Returns the curvature of the overlay as a percentage from (0..1] where 1 is a fully closed cylinder. */ + virtual EVROverlayError GetOverlayCurvature( VROverlayHandle_t ulOverlayHandle, float *pfCurvature ) = 0; + + /** Sets the pitch angle (in radians) of the overlay before curvature is applied -- to form a fan or disk. */ + virtual EVROverlayError SetOverlayPreCurvePitch( VROverlayHandle_t ulOverlayHandle, float fRadians ) = 0; + + /** Returns the overlay's set pre-curve pitch angle (in radians). */ + virtual EVROverlayError GetOverlayPreCurvePitch( VROverlayHandle_t ulOverlayHandle, float *pfRadians ) = 0; + + /** Sets the colorspace the overlay texture's data is in. Defaults to 'auto'. + * If the texture needs to be resolved, you should call SetOverlayTexture with the appropriate colorspace instead. */ + virtual EVROverlayError SetOverlayTextureColorSpace( VROverlayHandle_t ulOverlayHandle, EColorSpace eTextureColorSpace ) = 0; + + /** Gets the overlay's current colorspace setting. */ + virtual EVROverlayError GetOverlayTextureColorSpace( VROverlayHandle_t ulOverlayHandle, EColorSpace *peTextureColorSpace ) = 0; + + /** Sets the part of the texture to use for the overlay. UV Min is the upper left corner and UV Max is the lower right corner. */ + virtual EVROverlayError SetOverlayTextureBounds( VROverlayHandle_t ulOverlayHandle, const VRTextureBounds_t *pOverlayTextureBounds ) = 0; + + /** Gets the part of the texture to use for the overlay. UV Min is the upper left corner and UV Max is the lower right corner. */ + virtual EVROverlayError GetOverlayTextureBounds( VROverlayHandle_t ulOverlayHandle, VRTextureBounds_t *pOverlayTextureBounds ) = 0; + + /** Returns the transform type of this overlay. */ + virtual EVROverlayError GetOverlayTransformType( VROverlayHandle_t ulOverlayHandle, VROverlayTransformType *peTransformType ) = 0; + + /** Sets the transform to absolute tracking origin. */ + virtual EVROverlayError SetOverlayTransformAbsolute( VROverlayHandle_t ulOverlayHandle, ETrackingUniverseOrigin eTrackingOrigin, const HmdMatrix34_t *pmatTrackingOriginToOverlayTransform ) = 0; + + /** Gets the transform if it is absolute. Returns an error if the transform is some other type. */ + virtual EVROverlayError GetOverlayTransformAbsolute( VROverlayHandle_t ulOverlayHandle, ETrackingUniverseOrigin *peTrackingOrigin, HmdMatrix34_t *pmatTrackingOriginToOverlayTransform ) = 0; + + /** Sets the transform to relative to the transform of the specified tracked device. */ + virtual EVROverlayError SetOverlayTransformTrackedDeviceRelative( VROverlayHandle_t ulOverlayHandle, TrackedDeviceIndex_t unTrackedDevice, const HmdMatrix34_t *pmatTrackedDeviceToOverlayTransform ) = 0; + + /** Gets the transform if it is relative to a tracked device. Returns an error if the transform is some other type. */ + virtual EVROverlayError GetOverlayTransformTrackedDeviceRelative( VROverlayHandle_t ulOverlayHandle, TrackedDeviceIndex_t *punTrackedDevice, HmdMatrix34_t *pmatTrackedDeviceToOverlayTransform ) = 0; + + /** Sets the transform to draw the overlay on a rendermodel component mesh instead of a quad. This will only draw when the system is + * drawing the device. Overlays with this transform type cannot receive mouse events. */ + virtual EVROverlayError SetOverlayTransformTrackedDeviceComponent( VROverlayHandle_t ulOverlayHandle, TrackedDeviceIndex_t unDeviceIndex, const char *pchComponentName ) = 0; + + /** Gets the transform information when the overlay is rendering on a component. */ + virtual EVROverlayError GetOverlayTransformTrackedDeviceComponent( VROverlayHandle_t ulOverlayHandle, TrackedDeviceIndex_t *punDeviceIndex, VR_OUT_STRING() char *pchComponentName, uint32_t unComponentNameSize ) = 0; + + /** Sets the hotspot for the specified overlay when that overlay is used as a cursor. These are in texture space with 0,0 in the upper left corner of + * the texture and 1,1 in the lower right corner of the texture. */ + virtual EVROverlayError SetOverlayTransformCursor( VROverlayHandle_t ulCursorOverlayHandle, const HmdVector2_t *pvHotspot ) = 0; + + /** Gets cursor hotspot/transform for the specified overlay */ + virtual vr::EVROverlayError GetOverlayTransformCursor( VROverlayHandle_t ulOverlayHandle, HmdVector2_t *pvHotspot ) = 0; + + /** Sets the overlay as a projection overlay */ + virtual vr::EVROverlayError SetOverlayTransformProjection( VROverlayHandle_t ulOverlayHandle, + ETrackingUniverseOrigin eTrackingOrigin, const HmdMatrix34_t* pmatTrackingOriginToOverlayTransform, + const VROverlayProjection_t *pProjection, vr::EVREye eEye ) = 0; + + /** Shows the VR overlay. Not applicable for Dashboard Overlays. */ + virtual EVROverlayError ShowOverlay( VROverlayHandle_t ulOverlayHandle ) = 0; + + /** Hides the VR overlay. Not applicable for Dashboard Overlays. */ + virtual EVROverlayError HideOverlay( VROverlayHandle_t ulOverlayHandle ) = 0; + + /** Returns true if the overlay is currently visible, applicable for all overlay types except Dashboard Thumbnail overlays. VREvent_OverlayShown and VREvent_OverlayHidden reflect changes to this value. */ + virtual bool IsOverlayVisible( VROverlayHandle_t ulOverlayHandle ) = 0; + + /** Get the transform in 3d space associated with a specific 2d point in the overlay's coordinate space (where 0,0 is the lower left). -Z points out of the overlay */ + virtual EVROverlayError GetTransformForOverlayCoordinates( VROverlayHandle_t ulOverlayHandle, ETrackingUniverseOrigin eTrackingOrigin, HmdVector2_t coordinatesInOverlay, HmdMatrix34_t *pmatTransform ) = 0; + + /** This function will block until the top of each frame, and can therefore be used to synchronize with the runtime's update rate. + * Note: In non-async mode, some signals may be dropped due to scene app performance, so passing a timeout of 1000/refresh rate + * may be useful depending on the overlay app's desired behavior. */ + virtual EVROverlayError WaitFrameSync( uint32_t nTimeoutMs ) = 0; + + // --------------------------------------------- + // Overlay input methods + // --------------------------------------------- + + /** Returns true and fills the event with the next event on the overlay's event queue, if there is one. + * If there are no events this method returns false. uncbVREvent should be the size in bytes of the VREvent_t struct */ + virtual bool PollNextOverlayEvent( VROverlayHandle_t ulOverlayHandle, VREvent_t *pEvent, uint32_t uncbVREvent ) = 0; + + /** Returns the current input settings for the specified overlay. */ + virtual EVROverlayError GetOverlayInputMethod( VROverlayHandle_t ulOverlayHandle, VROverlayInputMethod *peInputMethod ) = 0; + + /** Sets the input settings for the specified overlay. */ + virtual EVROverlayError SetOverlayInputMethod( VROverlayHandle_t ulOverlayHandle, VROverlayInputMethod eInputMethod ) = 0; + + /** Gets the mouse scaling factor that is used for mouse events. The actual texture may be a different size, but this is + * typically the size of the underlying UI in pixels. */ + virtual EVROverlayError GetOverlayMouseScale( VROverlayHandle_t ulOverlayHandle, HmdVector2_t *pvecMouseScale ) = 0; + + /** Sets the mouse scaling factor that is used for mouse events. The actual texture may be a different size, but this is + * typically the size of the underlying UI in pixels (not in world space). */ + virtual EVROverlayError SetOverlayMouseScale( VROverlayHandle_t ulOverlayHandle, const HmdVector2_t *pvecMouseScale ) = 0; + + /** Computes the overlay-space pixel coordinates of where the ray intersects the overlay with the + * specified settings. Returns false if there is no intersection. */ + virtual bool ComputeOverlayIntersection( VROverlayHandle_t ulOverlayHandle, const VROverlayIntersectionParams_t *pParams, VROverlayIntersectionResults_t *pResults ) = 0; + + /** Returns true if the specified overlay is the hover target. An overlay is the hover target when it is the last overlay "moused over" + * by the virtual mouse pointer */ + virtual bool IsHoverTargetOverlay( VROverlayHandle_t ulOverlayHandle ) = 0; + + /** Sets a list of primitives to be used for controller ray intersection + * typically the size of the underlying UI in pixels (not in world space). */ + virtual EVROverlayError SetOverlayIntersectionMask( VROverlayHandle_t ulOverlayHandle, VROverlayIntersectionMaskPrimitive_t *pMaskPrimitives, uint32_t unNumMaskPrimitives, uint32_t unPrimitiveSize = sizeof( VROverlayIntersectionMaskPrimitive_t ) ) = 0; + + /** Triggers a haptic event on the laser mouse controller for the specified overlay */ + virtual EVROverlayError TriggerLaserMouseHapticVibration( VROverlayHandle_t ulOverlayHandle, float fDurationSeconds, float fFrequency, float fAmplitude ) = 0; + + /** Sets the cursor to use for the specified overlay. This will be drawn instead of the generic blob when the laser mouse is pointed at the specified overlay */ + virtual EVROverlayError SetOverlayCursor( VROverlayHandle_t ulOverlayHandle, VROverlayHandle_t ulCursorHandle ) = 0; + + /** Sets the override cursor position to use for this overlay in overlay mouse coordinates. This position will be used to draw the cursor + * instead of whatever the laser mouse cursor position is. */ + virtual EVROverlayError SetOverlayCursorPositionOverride( VROverlayHandle_t ulOverlayHandle, const HmdVector2_t *pvCursor ) = 0; + + /** Clears the override cursor position for this overlay */ + virtual EVROverlayError ClearOverlayCursorPositionOverride( VROverlayHandle_t ulOverlayHandle ) = 0; + + // --------------------------------------------- + // Overlay texture methods + // --------------------------------------------- + + /** Texture to draw for the overlay. This function can only be called by the overlay's creator or renderer process (see SetOverlayRenderingPid) . + * + * OpenGL dirty state: + * glBindTexture + */ + virtual EVROverlayError SetOverlayTexture( VROverlayHandle_t ulOverlayHandle, const Texture_t *pTexture ) = 0; + + /** Use this to tell the overlay system to release the texture set for this overlay. */ + virtual EVROverlayError ClearOverlayTexture( VROverlayHandle_t ulOverlayHandle ) = 0; + + /** Separate interface for providing the data as a stream of bytes, but there is an upper bound on data + * that can be sent. This function can only be called by the overlay's renderer process. */ + virtual EVROverlayError SetOverlayRaw( VROverlayHandle_t ulOverlayHandle, void *pvBuffer, uint32_t unWidth, uint32_t unHeight, uint32_t unBytesPerPixel ) = 0; + + /** Separate interface for providing the image through a filename: can be png or jpg, and should not be bigger than 1920x1080. + * This function can only be called by the overlay's renderer process */ + virtual EVROverlayError SetOverlayFromFile( VROverlayHandle_t ulOverlayHandle, const char *pchFilePath ) = 0; + + /** Get the native texture handle/device for an overlay you have created. + * On windows this handle will be a ID3D11ShaderResourceView with a ID3D11Texture2D bound. + * + * The texture will always be sized to match the backing texture you supplied in SetOverlayTexture above. + * + * You MUST call ReleaseNativeOverlayHandle() with pNativeTextureHandle once you are done with this texture. + * + * pNativeTextureHandle is an OUTPUT, it will be a pointer to a ID3D11ShaderResourceView *. + * pNativeTextureRef is an INPUT and should be a ID3D11Resource *. The device used by pNativeTextureRef will be used to bind pNativeTextureHandle. + */ + virtual EVROverlayError GetOverlayTexture( VROverlayHandle_t ulOverlayHandle, void **pNativeTextureHandle, void *pNativeTextureRef, uint32_t *pWidth, uint32_t *pHeight, uint32_t *pNativeFormat, ETextureType *pAPIType, EColorSpace *pColorSpace, VRTextureBounds_t *pTextureBounds ) = 0; + + /** Release the pNativeTextureHandle provided from the GetOverlayTexture call, this allows the system to free the underlying GPU resources for this object, + * so only do it once you stop rendering this texture. + */ + virtual EVROverlayError ReleaseNativeOverlayHandle( VROverlayHandle_t ulOverlayHandle, void *pNativeTextureHandle ) = 0; + + /** Get the size of the overlay texture */ + virtual EVROverlayError GetOverlayTextureSize( VROverlayHandle_t ulOverlayHandle, uint32_t *pWidth, uint32_t *pHeight ) = 0; + + // ---------------------------------------------- + // Dashboard Overlay Methods + // ---------------------------------------------- + + /** Creates a dashboard overlay and returns its handle */ + virtual EVROverlayError CreateDashboardOverlay( const char *pchOverlayKey, const char *pchOverlayFriendlyName, VROverlayHandle_t * pMainHandle, VROverlayHandle_t *pThumbnailHandle ) = 0; + + /** Returns true if the dashboard is visible */ + virtual bool IsDashboardVisible() = 0; + + /** returns true if the dashboard is visible and the specified overlay is the active system Overlay */ + virtual bool IsActiveDashboardOverlay( VROverlayHandle_t ulOverlayHandle ) = 0; + + /** Sets the dashboard overlay to only appear when the specified process ID has scene focus */ + virtual EVROverlayError SetDashboardOverlaySceneProcess( VROverlayHandle_t ulOverlayHandle, uint32_t unProcessId ) = 0; + + /** Gets the process ID that this dashboard overlay requires to have scene focus */ + virtual EVROverlayError GetDashboardOverlaySceneProcess( VROverlayHandle_t ulOverlayHandle, uint32_t *punProcessId ) = 0; + + /** Shows the dashboard. */ + virtual void ShowDashboard( const char *pchOverlayToShow ) = 0; + + /** Returns the tracked device that has the laser pointer in the dashboard */ + virtual vr::TrackedDeviceIndex_t GetPrimaryDashboardDevice() = 0; + + // --------------------------------------------- + // Keyboard methods + // --------------------------------------------- + + /** Show the virtual keyboard to accept input. In most cases, you should pass KeyboardFlag_Modal to enable modal overlay + * behavior on the keyboard itself. See EKeyboardFlags for more. */ + virtual EVROverlayError ShowKeyboard( EGamepadTextInputMode eInputMode, EGamepadTextInputLineMode eLineInputMode, uint32_t unFlags, + const char *pchDescription, uint32_t unCharMax, const char *pchExistingText, uint64_t uUserValue ) = 0; + + /** Show the virtual keyboard to accept input for an overlay. In most cases, you should pass KeyboardFlag_Modal to enable modal + * overlay behavior on the keyboard itself. See EKeyboardFlags for more. */ + virtual EVROverlayError ShowKeyboardForOverlay( VROverlayHandle_t ulOverlayHandle, EGamepadTextInputMode eInputMode, + EGamepadTextInputLineMode eLineInputMode, uint32_t unFlags, const char *pchDescription, uint32_t unCharMax, + const char *pchExistingText, uint64_t uUserValue ) = 0; + + /** Get the text that was entered into the text input **/ + virtual uint32_t GetKeyboardText( VR_OUT_STRING() char *pchText, uint32_t cchText ) = 0; + + /** Hide the virtual keyboard **/ + virtual void HideKeyboard() = 0; + + /** Set the position of the keyboard in world space **/ + virtual void SetKeyboardTransformAbsolute( ETrackingUniverseOrigin eTrackingOrigin, const HmdMatrix34_t *pmatTrackingOriginToKeyboardTransform ) = 0; + + /** Set the position of the keyboard in overlay space by telling it to avoid a rectangle in the overlay. Rectangle coords have (0,0) in the bottom left **/ + virtual void SetKeyboardPositionForOverlay( VROverlayHandle_t ulOverlayHandle, HmdRect2_t avoidRect ) = 0; + + // --------------------------------------------- + // Message box methods + // --------------------------------------------- + + /** Show the message overlay. This will block and return you a result. **/ + virtual VRMessageOverlayResponse ShowMessageOverlay( const char* pchText, const char* pchCaption, const char* pchButton0Text, const char* pchButton1Text = nullptr, const char* pchButton2Text = nullptr, const char* pchButton3Text = nullptr ) = 0; + + /** If the calling process owns the overlay and it's open, this will close it. **/ + virtual void CloseMessageOverlay() = 0; + }; + + static const char * const IVROverlay_Version = "IVROverlay_027"; + +} // namespace vr + +// ivroverlayview.h + +namespace vr +{ + struct VROverlayView_t + { + VROverlayHandle_t overlayHandle; + Texture_t texture; + VRTextureBounds_t textureBounds; + }; + + enum EDeviceType + { + DeviceType_Invalid = -1, // Invalid handle + DeviceType_DirectX11 = 0, // Handle is an ID3D11Device + DeviceType_Vulkan = 1, // Handle is a pointer to a VRVulkanDevice_t structure + }; + + struct VRVulkanDevice_t + { + VkInstance_T *m_pInstance; + VkDevice_T *m_pDevice; + VkPhysicalDevice_T *m_pPhysicalDevice; + VkQueue_T *m_pQueue; + uint32_t m_uQueueFamilyIndex; + }; + + struct VRNativeDevice_t + { + void *handle; // See EDeviceType definition above + EDeviceType eType; + }; + + class IVROverlayView + { + public: + /** Acquire an OverlayView_t from an overlay handle + * + * The overlay view can be used to sample the contents directly by a native API. The + * contents of the OverlayView_t will remain unchanged through the lifetime of the + * OverlayView_t. + * + * The caller acquires read privileges over the OverlayView_t, but should not + * write to it. + * + * AcquireOverlayView() may be called on the same ulOverlayHandle multiple times to + * refresh the image contents. In this case the caller is strongly encouraged to re-use + * the same pOverlayView for all re-acquisition calls. + * + * If the producer has not yet queued an image, AcquireOverlayView will return success, + * and the Texture_t will have the expected ETextureType. However, the Texture_t->handle + * will be nullptr. Once the producer generates the first overlay frame, Texture_t->handle + * will become a valid handle. + */ + virtual EVROverlayError AcquireOverlayView(VROverlayHandle_t ulOverlayHandle, VRNativeDevice_t *pNativeDevice, VROverlayView_t *pOverlayView, uint32_t unOverlayViewSize ) = 0; + + /** Release an acquired OverlayView_t + * + * Denotes that pOverlayView will no longer require access to the resources it acquired in + * all previous calls to AcquireOverlayView(). + * + * All OverlayView_t*'s provided to AcquireOverlayView() as pOverlayViews must be + * passed into ReleaseOverlayView() in order for the underlying GPU resources to be freed. + */ + virtual EVROverlayError ReleaseOverlayView(VROverlayView_t *pOverlayView) = 0; + + /** Posts an overlay event */ + virtual void PostOverlayEvent(VROverlayHandle_t ulOverlayHandle, const VREvent_t *pvrEvent) = 0; + + /** Determines whether this process is permitted to view an overlay's content. */ + virtual bool IsViewingPermitted( VROverlayHandle_t ulOverlayHandle ) = 0; + + }; + + static const char * const IVROverlayView_Version = "IVROverlayView_003"; + +} + +// ivrrendermodels.h + +namespace vr +{ + +static const char * const k_pch_Controller_Component_GDC2015 = "gdc2015"; // Canonical coordinate system of the gdc 2015 wired controller, provided for backwards compatibility +static const char * const k_pch_Controller_Component_Base = "base"; // For controllers with an unambiguous 'base'. +static const char * const k_pch_Controller_Component_Tip = "tip"; // OpenVR: For controllers with an unambiguous 'tip' (used for 'laser-pointing') +static const char * const k_pch_Controller_Component_OpenXR_Aim= "openxr_aim"; // OpenXR: For controllers with an unambiguous 'tip' (used for 'laser-pointing') +static const char * const k_pch_Controller_Component_HandGrip = "handgrip"; // OpenVR: Neutral, ambidextrous hand-pose when holding controller. On plane between neutrally posed index finger and thumb +static const char * const k_pch_Controller_Component_OpenXR_Grip = "openxr_grip"; // OpenXR: Neutral, ambidextrous hand-pose when holding controller. On plane between neutrally posed index finger and thumb +static const char * const k_pch_Controller_Component_OpenXR_HandModel = "openxr_handmodel"; // OpenXR: Pose that can be used to place hand models & visuals that aren't reliant on the physical shape of a controller +static const char * const k_pch_Controller_Component_Status = "status"; // 1:1 aspect ratio status area, with canonical [0,1] uv mapping + +#pragma pack( push, 8 ) + +/** Errors that can occur with the VR compositor */ +enum EVRRenderModelError +{ + VRRenderModelError_None = 0, + VRRenderModelError_Loading = 100, + VRRenderModelError_NotSupported = 200, + VRRenderModelError_InvalidArg = 300, + VRRenderModelError_InvalidModel = 301, + VRRenderModelError_NoShapes = 302, + VRRenderModelError_MultipleShapes = 303, + VRRenderModelError_TooManyVertices = 304, + VRRenderModelError_MultipleTextures = 305, + VRRenderModelError_BufferTooSmall = 306, + VRRenderModelError_NotEnoughNormals = 307, + VRRenderModelError_NotEnoughTexCoords = 308, + + VRRenderModelError_InvalidTexture = 400, +}; + +enum EVRRenderModelTextureFormat +{ + VRRenderModelTextureFormat_RGBA8_SRGB = 0, // RGBA with 8 bits per channel per pixel. Data size is width * height * 4ub + VRRenderModelTextureFormat_BC2, + VRRenderModelTextureFormat_BC4, + VRRenderModelTextureFormat_BC7, + VRRenderModelTextureFormat_BC7_SRGB, + VRRenderModelTextureFormat_RGBA16_FLOAT, +}; + +/** A single vertex in a render model */ +struct RenderModel_Vertex_t +{ + HmdVector3_t vPosition; // position in meters in device space + HmdVector3_t vNormal; + float rfTextureCoord[2]; +}; + +/** A texture map for use on a render model */ +#if defined(__linux__) || defined(__APPLE__) +// This structure was originally defined mis-packed on Linux, preserved for +// compatibility. +#pragma pack( push, 4 ) +#endif + +struct RenderModel_TextureMap_t +{ + uint16_t unWidth, unHeight; // width and height of the texture map in pixels + const uint8_t *rubTextureMapData; // Map texture data. + EVRRenderModelTextureFormat format; // Refer to EVRRenderModelTextureFormat + uint16_t unMipLevels; +}; +#if defined(__linux__) || defined(__APPLE__) +#pragma pack( pop ) +#endif + +/** Session unique texture identifier. Rendermodels which share the same texture will have the same id. +IDs <0 denote the texture is not present */ + +typedef int32_t TextureID_t; + +const TextureID_t INVALID_TEXTURE_ID = -1; + +#if defined(__linux__) || defined(__APPLE__) +// This structure was originally defined mis-packed on Linux, preserved for +// compatibility. +#pragma pack( push, 4 ) +#endif + +struct RenderModel_t +{ + const RenderModel_Vertex_t *rVertexData; // Vertex data for the mesh + uint32_t unVertexCount; // Number of vertices in the vertex data + const uint16_t *rIndexData; // Indices into the vertex data for each triangle + uint32_t unTriangleCount; // Number of triangles in the mesh. Index count is 3 * TriangleCount + TextureID_t diffuseTextureId; // Session unique texture identifier. Rendermodels which share the same texture will have the same id. <0 == texture not present +}; +#if defined(__linux__) || defined(__APPLE__) +#pragma pack( pop ) +#endif + + +struct RenderModel_ControllerMode_State_t +{ + bool bScrollWheelVisible; // is this controller currently set to be in a scroll wheel mode +}; + +#pragma pack( pop ) + +class IVRRenderModels +{ +public: + + /** Loads and returns a render model for use in the application. pchRenderModelName should be a render model name + * from the Prop_RenderModelName_String property or an absolute path name to a render model on disk. + * + * The resulting render model is valid until VR_Shutdown() is called or until FreeRenderModel() is called. When the + * application is finished with the render model it should call FreeRenderModel() to free the memory associated + * with the model. + * + * The method returns VRRenderModelError_Loading while the render model is still being loaded. + * The method returns VRRenderModelError_None once loaded successfully, otherwise will return an error. */ + virtual EVRRenderModelError LoadRenderModel_Async( const char *pchRenderModelName, RenderModel_t **ppRenderModel ) = 0; + + /** Frees a previously returned render model + * It is safe to call this on a null ptr. */ + virtual void FreeRenderModel( RenderModel_t *pRenderModel ) = 0; + + /** Loads and returns a texture for use in the application. */ + virtual EVRRenderModelError LoadTexture_Async( TextureID_t textureId, RenderModel_TextureMap_t **ppTexture ) = 0; + + /** Frees a previously returned texture + * It is safe to call this on a null ptr. */ + virtual void FreeTexture( RenderModel_TextureMap_t *pTexture ) = 0; + + /** Creates a D3D11 texture and loads data into it. */ + virtual EVRRenderModelError LoadTextureD3D11_Async( TextureID_t textureId, void *pD3D11Device, void **ppD3D11Texture2D ) = 0; + + /** Helper function to copy the bits into an existing texture. */ + virtual EVRRenderModelError LoadIntoTextureD3D11_Async( TextureID_t textureId, void *pDstTexture ) = 0; + + /** Use this to free textures created with LoadTextureD3D11_Async instead of calling Release on them. */ + virtual void FreeTextureD3D11( void *pD3D11Texture2D ) = 0; + + /** Use this to get the names of available render models. Index does not correlate to a tracked device index, but + * is only used for iterating over all available render models. If the index is out of range, this function will return 0. + * Otherwise, it will return the size of the buffer required for the name. */ + virtual uint32_t GetRenderModelName( uint32_t unRenderModelIndex, VR_OUT_STRING() char *pchRenderModelName, uint32_t unRenderModelNameLen ) = 0; + + /** Returns the number of available render models. */ + virtual uint32_t GetRenderModelCount() = 0; + + + /** Returns the number of components of the specified render model. + * Components are useful when client application wish to draw, label, or otherwise interact with components of tracked objects. + * Examples controller components: + * renderable things such as triggers, buttons + * non-renderable things which include coordinate systems such as 'tip', 'base', a neutral controller agnostic hand-pose + * If all controller components are enumerated and rendered, it will be equivalent to drawing the traditional render model + * Returns 0 if components not supported, >0 otherwise */ + virtual uint32_t GetComponentCount( const char *pchRenderModelName ) = 0; + + /** Use this to get the names of available components. Index does not correlate to a tracked device index, but + * is only used for iterating over all available components. If the index is out of range, this function will return 0. + * Otherwise, it will return the size of the buffer required for the name. */ + virtual uint32_t GetComponentName( const char *pchRenderModelName, uint32_t unComponentIndex, VR_OUT_STRING( ) char *pchComponentName, uint32_t unComponentNameLen ) = 0; + + /** Get the button mask for all buttons associated with this component + * If no buttons (or axes) are associated with this component, return 0 + * Note: multiple components may be associated with the same button. Ex: two grip buttons on a single controller. + * Note: A single component may be associated with multiple buttons. Ex: A trackpad which also provides "D-pad" functionality */ + virtual uint64_t GetComponentButtonMask( const char *pchRenderModelName, const char *pchComponentName ) = 0; + + /** Use this to get the render model name for the specified rendermode/component combination, to be passed to LoadRenderModel. + * If the component name is out of range, this function will return 0. + * Otherwise, it will return the size of the buffer required for the name. */ + virtual uint32_t GetComponentRenderModelName( const char *pchRenderModelName, const char *pchComponentName, VR_OUT_STRING( ) char *pchComponentRenderModelName, uint32_t unComponentRenderModelNameLen ) = 0; + + /** Use this to query information about the component, as a function of the controller state. + * + * For dynamic controller components (ex: trigger) values will reflect component motions + * For static components this will return a consistent value independent of the VRControllerState_t + * + * If the pchRenderModelName or pchComponentName is invalid, this will return false (and transforms will be set to identity). + * Otherwise, return true + * Note: For dynamic objects, visibility may be dynamic. (I.e., true/false will be returned based on controller state and controller mode state ) */ + virtual bool GetComponentStateForDevicePath( const char *pchRenderModelName, const char *pchComponentName, vr::VRInputValueHandle_t devicePath, const vr::RenderModel_ControllerMode_State_t *pState, vr::RenderModel_ComponentState_t *pComponentState ) = 0; + + /** This version of GetComponentState takes a controller state block instead of an action origin. This function is deprecated. You should use the new input system and GetComponentStateForDevicePath instead. */ + virtual bool GetComponentState( const char *pchRenderModelName, const char *pchComponentName, const vr::VRControllerState_t *pControllerState, const RenderModel_ControllerMode_State_t *pState, RenderModel_ComponentState_t *pComponentState ) = 0; + + /** Returns true if the render model has a component with the specified name */ + virtual bool RenderModelHasComponent( const char *pchRenderModelName, const char *pchComponentName ) = 0; + + /** Returns the URL of the thumbnail image for this rendermodel */ + virtual uint32_t GetRenderModelThumbnailURL( const char *pchRenderModelName, VR_OUT_STRING() char *pchThumbnailURL, uint32_t unThumbnailURLLen, vr::EVRRenderModelError *peError ) = 0; + + /** Provides a render model path that will load the unskinned model if the model name provided has been replace by the user. If the model + * hasn't been replaced the path value will still be a valid path to load the model. Pass this to LoadRenderModel_Async, etc. to load the + * model. */ + virtual uint32_t GetRenderModelOriginalPath( const char *pchRenderModelName, VR_OUT_STRING() char *pchOriginalPath, uint32_t unOriginalPathLen, vr::EVRRenderModelError *peError ) = 0; + + /** Returns a string for a render model error */ + virtual const char *GetRenderModelErrorNameFromEnum( vr::EVRRenderModelError error ) = 0; +}; + +static const char * const IVRRenderModels_Version = "IVRRenderModels_006"; + +} + + +// ivrextendeddisplay.h + +namespace vr +{ + + /** NOTE: Use of this interface is not recommended in production applications. It will not work for displays which use + * direct-to-display mode. Creating our own window is also incompatible with the VR compositor and is not available when the compositor is running. */ + class IVRExtendedDisplay + { + public: + + /** Size and position that the window needs to be on the VR display. */ + virtual void GetWindowBounds( int32_t *pnX, int32_t *pnY, uint32_t *pnWidth, uint32_t *pnHeight ) = 0; + + /** Gets the viewport in the frame buffer to draw the output of the distortion into */ + virtual void GetEyeOutputViewport( EVREye eEye, uint32_t *pnX, uint32_t *pnY, uint32_t *pnWidth, uint32_t *pnHeight ) = 0; + + /** [D3D10/11 Only] + * Returns the adapter index and output index that the user should pass into EnumAdapters and EnumOutputs + * to create the device and swap chain in DX10 and DX11. If an error occurs both indices will be set to -1. + */ + virtual void GetDXGIOutputInfo( int32_t *pnAdapterIndex, int32_t *pnAdapterOutputIndex ) = 0; + + }; + + static const char * const IVRExtendedDisplay_Version = "IVRExtendedDisplay_001"; + +} + + +// ivrtrackedcamera.h + +namespace vr +{ + +class IVRTrackedCamera +{ +public: + /** Returns a string for an error */ + virtual const char *GetCameraErrorNameFromEnum( vr::EVRTrackedCameraError eCameraError ) = 0; + + /** For convenience, same as tracked property request Prop_HasCamera_Bool */ + virtual vr::EVRTrackedCameraError HasCamera( vr::TrackedDeviceIndex_t nDeviceIndex, bool *pHasCamera ) = 0; + + /** Gets size of the image frame. */ + virtual vr::EVRTrackedCameraError GetCameraFrameSize( vr::TrackedDeviceIndex_t nDeviceIndex, vr::EVRTrackedCameraFrameType eFrameType, uint32_t *pnWidth, uint32_t *pnHeight, uint32_t *pnFrameBufferSize ) = 0; + + virtual vr::EVRTrackedCameraError GetCameraIntrinsics( vr::TrackedDeviceIndex_t nDeviceIndex, uint32_t nCameraIndex, vr::EVRTrackedCameraFrameType eFrameType, vr::HmdVector2_t *pFocalLength, vr::HmdVector2_t *pCenter ) = 0; + + virtual vr::EVRTrackedCameraError GetCameraProjection( vr::TrackedDeviceIndex_t nDeviceIndex, uint32_t nCameraIndex, vr::EVRTrackedCameraFrameType eFrameType, float flZNear, float flZFar, vr::HmdMatrix44_t *pProjection ) = 0; + + /** Acquiring streaming service permits video streaming for the caller. Releasing hints the system that video services do not need to be maintained for this client. + * If the camera has not already been activated, a one time spin up may incur some auto exposure as well as initial streaming frame delays. + * The camera should be considered a global resource accessible for shared consumption but not exclusive to any caller. + * The camera may go inactive due to lack of active consumers or headset idleness. */ + virtual vr::EVRTrackedCameraError AcquireVideoStreamingService( vr::TrackedDeviceIndex_t nDeviceIndex, vr::TrackedCameraHandle_t *pHandle ) = 0; + virtual vr::EVRTrackedCameraError ReleaseVideoStreamingService( vr::TrackedCameraHandle_t hTrackedCamera ) = 0; + + /** Copies the image frame into a caller's provided buffer. The image data is currently provided as RGBA data, 4 bytes per pixel. + * A caller can provide null for the framebuffer or frameheader if not desired. Requesting the frame header first, followed by the frame buffer allows + * the caller to determine if the frame as advanced per the frame header sequence. + * If there is no frame available yet, due to initial camera spinup or re-activation, the error will be VRTrackedCameraError_NoFrameAvailable. + * Ideally a caller should be polling at ~16ms intervals */ + virtual vr::EVRTrackedCameraError GetVideoStreamFrameBuffer( vr::TrackedCameraHandle_t hTrackedCamera, vr::EVRTrackedCameraFrameType eFrameType, void *pFrameBuffer, uint32_t nFrameBufferSize, vr::CameraVideoStreamFrameHeader_t *pFrameHeader, uint32_t nFrameHeaderSize ) = 0; + + /** Gets size of the image frame. */ + virtual vr::EVRTrackedCameraError GetVideoStreamTextureSize( vr::TrackedDeviceIndex_t nDeviceIndex, vr::EVRTrackedCameraFrameType eFrameType, vr::VRTextureBounds_t *pTextureBounds, uint32_t *pnWidth, uint32_t *pnHeight ) = 0; + + /** Access a shared D3D11 texture for the specified tracked camera stream. + * The camera frame type VRTrackedCameraFrameType_Undistorted is not supported directly as a shared texture. It is an interior subregion of the shared texture VRTrackedCameraFrameType_MaximumUndistorted. + * Instead, use GetVideoStreamTextureSize() with VRTrackedCameraFrameType_Undistorted to determine the proper interior subregion bounds along with GetVideoStreamTextureD3D11() with + * VRTrackedCameraFrameType_MaximumUndistorted to provide the texture. The VRTrackedCameraFrameType_MaximumUndistorted will yield an image where the invalid regions are decoded + * by the alpha channel having a zero component. The valid regions all have a non-zero alpha component. The subregion as described by VRTrackedCameraFrameType_Undistorted + * guarantees a rectangle where all pixels are valid. */ + virtual vr::EVRTrackedCameraError GetVideoStreamTextureD3D11( vr::TrackedCameraHandle_t hTrackedCamera, vr::EVRTrackedCameraFrameType eFrameType, void *pD3D11DeviceOrResource, void **ppD3D11ShaderResourceView, vr::CameraVideoStreamFrameHeader_t *pFrameHeader, uint32_t nFrameHeaderSize ) = 0; + + /** Access a shared GL texture for the specified tracked camera stream */ + virtual vr::EVRTrackedCameraError GetVideoStreamTextureGL( vr::TrackedCameraHandle_t hTrackedCamera, vr::EVRTrackedCameraFrameType eFrameType, vr::glUInt_t *pglTextureId, vr::CameraVideoStreamFrameHeader_t *pFrameHeader, uint32_t nFrameHeaderSize ) = 0; + virtual vr::EVRTrackedCameraError ReleaseVideoStreamTextureGL( vr::TrackedCameraHandle_t hTrackedCamera, vr::glUInt_t glTextureId ) = 0; + virtual void SetCameraTrackingSpace( vr::ETrackingUniverseOrigin eUniverse ) = 0; + virtual vr::ETrackingUniverseOrigin GetCameraTrackingSpace( ) = 0; +}; + +static const char * const IVRTrackedCamera_Version = "IVRTrackedCamera_006"; + +} // namespace vr + + +// ivrscreenshots.h + +namespace vr +{ + +/** Errors that can occur with the VR compositor */ +enum EVRScreenshotError +{ + VRScreenshotError_None = 0, + VRScreenshotError_RequestFailed = 1, + VRScreenshotError_IncompatibleVersion = 100, + VRScreenshotError_NotFound = 101, + VRScreenshotError_BufferTooSmall = 102, + VRScreenshotError_ScreenshotAlreadyInProgress = 108, +}; + +/** Allows the application to generate screenshots */ +class IVRScreenshots +{ +public: + /** Request a screenshot of the requested type. + * A request of the VRScreenshotType_Stereo type will always + * work. Other types will depend on the underlying application + * support. + * The first file name is for the preview image and should be a + * regular screenshot (ideally from the left eye). The second + * is the VR screenshot in the correct format. They should be + * in the same aspect ratio. Formats per type: + * VRScreenshotType_Mono: the VR filename is ignored (can be + * nullptr), this is a normal flat single shot. + * VRScreenshotType_Stereo: The VR image should be a + * side-by-side with the left eye image on the left. + * VRScreenshotType_Cubemap: The VR image should be six square + * images composited horizontally. + * VRScreenshotType_StereoPanorama: above/below with left eye + * panorama being the above image. Image is typically square + * with the panorama being 2x horizontal. + * + * Note that the VR dashboard will call this function when + * the user presses the screenshot binding (currently System + * Button + Trigger). If Steam is running, the destination + * file names will be in %TEMP% and will be copied into + * Steam's screenshot library for the running application + * once SubmitScreenshot() is called. + * If Steam is not running, the paths will be in the user's + * documents folder under Documents\SteamVR\Screenshots. + * Other VR applications can call this to initiate a + * screenshot outside of user control. + * The destination file names do not need an extension, + * will be replaced with the correct one for the format + * which is currently .png. */ + virtual vr::EVRScreenshotError RequestScreenshot( vr::ScreenshotHandle_t *pOutScreenshotHandle, vr::EVRScreenshotType type, const char *pchPreviewFilename, const char *pchVRFilename ) = 0; + + /** Called by the running VR application to indicate that it + * wishes to be in charge of screenshots. If the + * application does not call this, the Compositor will only + * support VRScreenshotType_Stereo screenshots that will be + * captured without notification to the running app. + * Once hooked your application will receive a + * VREvent_RequestScreenshot event when the user presses the + * buttons to take a screenshot. */ + virtual vr::EVRScreenshotError HookScreenshot( VR_ARRAY_COUNT( numTypes ) const vr::EVRScreenshotType *pSupportedTypes, int numTypes ) = 0; + + /** When your application receives a + * VREvent_RequestScreenshot event, call these functions to get + * the details of the screenshot request. */ + virtual vr::EVRScreenshotType GetScreenshotPropertyType( vr::ScreenshotHandle_t screenshotHandle, vr::EVRScreenshotError *pError ) = 0; + + /** Get the filename for the preview or vr image (see + * vr::EScreenshotPropertyFilenames). The return value is + * the size of the string. */ + virtual uint32_t GetScreenshotPropertyFilename( vr::ScreenshotHandle_t screenshotHandle, vr::EVRScreenshotPropertyFilenames filenameType, VR_OUT_STRING() char *pchFilename, uint32_t cchFilename, vr::EVRScreenshotError *pError ) = 0; + + /** Call this if the application is taking the screen shot + * will take more than a few ms processing. This will result + * in an overlay being presented that shows a completion + * bar. */ + virtual vr::EVRScreenshotError UpdateScreenshotProgress( vr::ScreenshotHandle_t screenshotHandle, float flProgress ) = 0; + + /** Tells the compositor to take an internal screenshot of + * type VRScreenshotType_Stereo. It will take the current + * submitted scene textures of the running application and + * write them into the preview image and a side-by-side file + * for the VR image. + * This is similar to request screenshot, but doesn't ever + * talk to the application, just takes the shot and submits. */ + virtual vr::EVRScreenshotError TakeStereoScreenshot( vr::ScreenshotHandle_t *pOutScreenshotHandle, const char *pchPreviewFilename, const char *pchVRFilename ) = 0; + + /** Submit the completed screenshot. If Steam is running + * this will call into the Steam client and upload the + * screenshot to the screenshots section of the library for + * the running application. If Steam is not running, this + * function will display a notification to the user that the + * screenshot was taken. The paths should be full paths with + * extensions. + * File paths should be absolute including extensions. + * screenshotHandle can be k_unScreenshotHandleInvalid if this + * was a new shot taking by the app to be saved and not + * initiated by a user (achievement earned or something) */ + virtual vr::EVRScreenshotError SubmitScreenshot( vr::ScreenshotHandle_t screenshotHandle, vr::EVRScreenshotType type, const char *pchSourcePreviewFilename, const char *pchSourceVRFilename ) = 0; +}; + +static const char * const IVRScreenshots_Version = "IVRScreenshots_001"; + +} // namespace vr + + + +// ivrresources.h + +namespace vr +{ + +class IVRResources +{ +public: + + // ------------------------------------ + // Shared Resource Methods + // ------------------------------------ + + /** Loads the specified resource into the provided buffer if large enough. + * Returns the size in bytes of the buffer required to hold the specified resource. */ + virtual uint32_t LoadSharedResource( const char *pchResourceName, char *pchBuffer, uint32_t unBufferLen ) = 0; + + /** Provides the full path to the specified resource. Resource names can include named directories for + * drivers and other things, and this resolves all of those and returns the actual physical path. + * pchResourceTypeDirectory is the subdirectory of resources to look in. */ + virtual uint32_t GetResourceFullPath( const char *pchResourceName, const char *pchResourceTypeDirectory, VR_OUT_STRING() char *pchPathBuffer, uint32_t unBufferLen ) = 0; +}; + +static const char * const IVRResources_Version = "IVRResources_001"; + + +} + +// ivrdrivermanager.h + +namespace vr +{ + +class IVRDriverManager +{ +public: + virtual uint32_t GetDriverCount() const = 0; + + /** Returns the length of the number of bytes necessary to hold this string including the trailing null. */ + virtual uint32_t GetDriverName( vr::DriverId_t nDriver, VR_OUT_STRING() char *pchValue, uint32_t unBufferSize ) = 0; + + virtual DriverHandle_t GetDriverHandle( const char *pchDriverName ) = 0; + + virtual bool IsEnabled( vr::DriverId_t nDriver ) const = 0; +}; + +static const char * const IVRDriverManager_Version = "IVRDriverManager_001"; + +} // namespace vr + + + +// ivrinput.h + +namespace vr +{ + // Maximum number of characters in an action name, including the trailing null + static const uint32_t k_unMaxActionNameLength = 64; + + // Maximum number of characters in an action set name, including the trailing null + static const uint32_t k_unMaxActionSetNameLength = 64; + + // Maximum number of origins for an action + static const uint32_t k_unMaxActionOriginCount = 16; + + // Maximum number of characters in a bone name, including the trailing null + static const uint32_t k_unMaxBoneNameLength = 32; + + enum EVRSkeletalTransformSpace + { + VRSkeletalTransformSpace_Model = 0, + VRSkeletalTransformSpace_Parent = 1 + }; + + enum EVRSkeletalReferencePose + { + VRSkeletalReferencePose_BindPose = 0, + VRSkeletalReferencePose_OpenHand, + VRSkeletalReferencePose_Fist, + VRSkeletalReferencePose_GripLimit + }; + + enum EVRFinger + { + VRFinger_Thumb = 0, + VRFinger_Index, + VRFinger_Middle, + VRFinger_Ring, + VRFinger_Pinky, + VRFinger_Count + }; + + enum EVRFingerSplay + { + VRFingerSplay_Thumb_Index = 0, + VRFingerSplay_Index_Middle, + VRFingerSplay_Middle_Ring, + VRFingerSplay_Ring_Pinky, + VRFingerSplay_Count + }; + + enum EVRSummaryType + { + // The skeletal summary data will match the animated bone transforms for the action. + VRSummaryType_FromAnimation = 0, + + // The skeletal summary data will include unprocessed data directly from the device when available. + // This data is generally less latent than the data that is computed from the animations. + VRSummaryType_FromDevice = 1, + }; + + enum EVRInputFilterCancelType + { + VRInputFilterCancel_Timers = 0, + VRInputFilterCancel_Momentum = 1, + }; + + enum EVRInputStringBits + { + VRInputString_Hand = 0x01, + VRInputString_ControllerType = 0x02, + VRInputString_InputSource = 0x04, + + VRInputString_All = 0xFFFFFFFF + }; + + struct InputAnalogActionData_t + { + /** Whether or not this action is currently available to be bound in the active action set */ + bool bActive; + + /** The origin that caused this action's current state */ + VRInputValueHandle_t activeOrigin; + + /** The current state of this action; will be delta updates for mouse actions */ + float x, y, z; + + /** Deltas since the previous call to UpdateActionState() */ + float deltaX, deltaY, deltaZ; + + /** Time relative to now when this event happened. Will be negative to indicate a past time. */ + float fUpdateTime; + }; + + struct InputDigitalActionData_t + { + /** Whether or not this action is currently available to be bound in the active action set */ + bool bActive; + + /** The origin that caused this action's current state */ + VRInputValueHandle_t activeOrigin; + + /** The current state of this action; will be true if currently pressed */ + bool bState; + + /** This is true if the state has changed since the last frame */ + bool bChanged; + + /** Time relative to now when this event happened. Will be negative to indicate a past time. */ + float fUpdateTime; + }; + + struct InputPoseActionData_t + { + /** Whether or not this action is currently available to be bound in the active action set */ + bool bActive; + + /** The origin that caused this action's current state */ + VRInputValueHandle_t activeOrigin; + + /** The current state of this action */ + TrackedDevicePose_t pose; + }; + + struct InputSkeletalActionData_t + { + /** Whether or not this action is currently available to be bound in the active action set */ + bool bActive; + + /** The origin that caused this action's current state */ + VRInputValueHandle_t activeOrigin; + }; + + struct InputOriginInfo_t + { + VRInputValueHandle_t devicePath; + TrackedDeviceIndex_t trackedDeviceIndex; + char rchRenderModelComponentName[128]; + }; + + struct InputBindingInfo_t + { + char rchDevicePathName[128]; + char rchInputPathName[128]; + char rchModeName[128]; + char rchSlotName[128]; + char rchInputSourceType[ 32 ]; + }; + + // * Experimental global action set priority * + // These constants are part of the experimental support in SteamVR for overlay + // apps selectively overriding input in the base scene application. This may be + // useful for overlay applications that need to use part or all of a controller + // without taking away all input to the game. This system must be enabled by the + // "Experimental overlay input overrides" setting in the developer section of + // SteamVR settings. + // + // To use this system, set the nPriority field of an action set to any number in + // this range. + static const int32_t k_nActionSetOverlayGlobalPriorityMin = 0x01000000; + static const int32_t k_nActionSetOverlayGlobalPriorityMax = 0x01FFFFFF; + + static const int32_t k_nActionSetPriorityReservedMin = 0x02000000; + + struct VRActiveActionSet_t + { + /** This is the handle of the action set to activate for this frame. */ + VRActionSetHandle_t ulActionSet; + + /** This is the handle of a device path that this action set should be active for. To + * activate for all devices, set this to k_ulInvalidInputValueHandle. */ + VRInputValueHandle_t ulRestrictedToDevice; + + /** The action set to activate for all devices other than ulRestrictedDevice. If + * ulRestrictedToDevice is set to k_ulInvalidInputValueHandle, this parameter is + * ignored. */ + VRActionSetHandle_t ulSecondaryActionSet; + + // This field is ignored + uint32_t unPadding; + + /** The priority of this action set relative to other action sets. Any inputs + * bound to a source (e.g. trackpad, joystick, trigger) will disable bindings in + * other active action sets with a smaller priority. + * + * Overlay applications (i.e. ApplicationType_Overlay) may set their action set priority + * to a value between k_nActionSetOverlayGlobalPriorityMin and k_nActionSetOverlayGlobalPriorityMax + * to cause any inputs bound to a source used by that action set to be disabled in scene applications. + * + * No action set priority may value may be larger than k_nActionSetPriorityReservedMin + */ + int32_t nPriority; + }; + + /** Contains summary information about the current skeletal pose */ + struct VRSkeletalSummaryData_t + { + /** The amount that each finger is 'curled' inwards towards the palm. In the case of the thumb, + * this represents how much the thumb is wrapped around the fist. + * 0 means straight, 1 means fully curled */ + float flFingerCurl[ VRFinger_Count ]; + + /** The amount that each pair of adjacent fingers are separated. + * 0 means the digits are touching, 1 means they are fully separated. + */ + float flFingerSplay[ VRFingerSplay_Count ]; + }; + + + class IVRInput + { + public: + + // --------------- Handle management --------------- // + + /** Sets the path to the action manifest JSON file that is used by this application. If this information + * was set on the Steam partner site, calls to this function are ignored. If the Steam partner site + * setting and the path provided by this call are different, VRInputError_MismatchedActionManifest is returned. + * This call must be made before the first call to UpdateActionState or IVRSystem::PollNextEvent. */ + virtual EVRInputError SetActionManifestPath( const char *pchActionManifestPath ) = 0; + + /** Returns a handle for an action set. This handle is used for all performance-sensitive calls. */ + virtual EVRInputError GetActionSetHandle( const char *pchActionSetName, VRActionSetHandle_t *pHandle ) = 0; + + /** Returns a handle for an action. This handle is used for all performance-sensitive calls. */ + virtual EVRInputError GetActionHandle( const char *pchActionName, VRActionHandle_t *pHandle ) = 0; + + /** Returns a handle for any path in the input system. E.g. /user/hand/right */ + virtual EVRInputError GetInputSourceHandle( const char *pchInputSourcePath, VRInputValueHandle_t *pHandle ) = 0; + + + + // --------------- Reading action state ------------------- // + + /** Reads the current state into all actions. After this call, the results of Get*Action calls + * will be the same until the next call to UpdateActionState. */ + virtual EVRInputError UpdateActionState( VR_ARRAY_COUNT( unSetCount ) VRActiveActionSet_t *pSets, uint32_t unSizeOfVRSelectedActionSet_t, uint32_t unSetCount ) = 0; + + /** Reads the state of a digital action given its handle. This will return VRInputError_WrongType if the type of + * action is something other than digital */ + virtual EVRInputError GetDigitalActionData( VRActionHandle_t action, InputDigitalActionData_t *pActionData, uint32_t unActionDataSize, VRInputValueHandle_t ulRestrictToDevice ) = 0; + + /** Reads the state of an analog action given its handle. This will return VRInputError_WrongType if the type of + * action is something other than analog */ + virtual EVRInputError GetAnalogActionData( VRActionHandle_t action, InputAnalogActionData_t *pActionData, uint32_t unActionDataSize, VRInputValueHandle_t ulRestrictToDevice ) = 0; + + /** Reads the state of a pose action given its handle for the number of seconds relative to now. This + * will generally be called with negative times from the fUpdateTime fields in other actions. */ + virtual EVRInputError GetPoseActionDataRelativeToNow( VRActionHandle_t action, ETrackingUniverseOrigin eOrigin, float fPredictedSecondsFromNow, InputPoseActionData_t *pActionData, uint32_t unActionDataSize, VRInputValueHandle_t ulRestrictToDevice ) = 0; + + /** Reads the state of a pose action given its handle. The returned values will match the values returned + * by the last call to IVRCompositor::WaitGetPoses(). */ + virtual EVRInputError GetPoseActionDataForNextFrame( VRActionHandle_t action, ETrackingUniverseOrigin eOrigin, InputPoseActionData_t *pActionData, uint32_t unActionDataSize, VRInputValueHandle_t ulRestrictToDevice ) = 0; + + /** Reads the state of a skeletal action given its handle. */ + virtual EVRInputError GetSkeletalActionData( VRActionHandle_t action, InputSkeletalActionData_t *pActionData, uint32_t unActionDataSize ) = 0; + + /** Returns the current dominant hand for the user for this application. This function will only return success for applications + * which include "supports_dominant_hand_setting": true in their action manifests. The dominant hand will only change after + * a call to UpdateActionState, and the action data returned after that point will use the new dominant hand. */ + virtual EVRInputError GetDominantHand( ETrackedControllerRole *peDominantHand ) = 0; + + /** Sets the dominant hand for the user for this application. */ + virtual EVRInputError SetDominantHand( ETrackedControllerRole eDominantHand ) = 0; + + // --------------- Static Skeletal Data ------------------- // + + /** Reads the number of bones in skeleton associated with the given action */ + virtual EVRInputError GetBoneCount( VRActionHandle_t action, uint32_t* pBoneCount ) = 0; + + /** Fills the given array with the index of each bone's parent in the skeleton associated with the given action */ + virtual EVRInputError GetBoneHierarchy( VRActionHandle_t action, VR_ARRAY_COUNT( unIndexArayCount ) BoneIndex_t* pParentIndices, uint32_t unIndexArayCount ) = 0; + + /** Fills the given buffer with the name of the bone at the given index in the skeleton associated with the given action */ + virtual EVRInputError GetBoneName( VRActionHandle_t action, BoneIndex_t nBoneIndex, VR_OUT_STRING() char* pchBoneName, uint32_t unNameBufferSize ) = 0; + + /** Fills the given buffer with the transforms for a specific static skeletal reference pose */ + virtual EVRInputError GetSkeletalReferenceTransforms( VRActionHandle_t action, EVRSkeletalTransformSpace eTransformSpace, EVRSkeletalReferencePose eReferencePose, VR_ARRAY_COUNT( unTransformArrayCount ) VRBoneTransform_t *pTransformArray, uint32_t unTransformArrayCount ) = 0; + + /** Reads the level of accuracy to which the controller is able to track the user to recreate a skeletal pose */ + virtual EVRInputError GetSkeletalTrackingLevel( VRActionHandle_t action, EVRSkeletalTrackingLevel* pSkeletalTrackingLevel ) = 0; + + // --------------- Dynamic Skeletal Data ------------------- // + + /** Reads the state of the skeletal bone data associated with this action and copies it into the given buffer. */ + virtual EVRInputError GetSkeletalBoneData( VRActionHandle_t action, EVRSkeletalTransformSpace eTransformSpace, EVRSkeletalMotionRange eMotionRange, VR_ARRAY_COUNT( unTransformArrayCount ) VRBoneTransform_t *pTransformArray, uint32_t unTransformArrayCount ) = 0; + + /** Reads summary information about the current pose of the skeleton associated with the given action. */ + virtual EVRInputError GetSkeletalSummaryData( VRActionHandle_t action, EVRSummaryType eSummaryType, VRSkeletalSummaryData_t * pSkeletalSummaryData ) = 0; + + /** Reads the state of the skeletal bone data in a compressed form that is suitable for + * sending over the network. The required buffer size will never exceed ( sizeof(VR_BoneTransform_t)*boneCount + 2). + * Usually the size will be much smaller. */ + virtual EVRInputError GetSkeletalBoneDataCompressed( VRActionHandle_t action, EVRSkeletalMotionRange eMotionRange, VR_OUT_BUFFER_COUNT( unCompressedSize ) void *pvCompressedData, uint32_t unCompressedSize, uint32_t *punRequiredCompressedSize ) = 0; + + /** Turns a compressed buffer from GetSkeletalBoneDataCompressed and turns it back into a bone transform array. */ + virtual EVRInputError DecompressSkeletalBoneData( const void *pvCompressedBuffer, uint32_t unCompressedBufferSize, EVRSkeletalTransformSpace eTransformSpace, VR_ARRAY_COUNT( unTransformArrayCount ) VRBoneTransform_t *pTransformArray, uint32_t unTransformArrayCount ) = 0; + + // --------------- Haptics ------------------- // + + /** Triggers a haptic event as described by the specified action */ + virtual EVRInputError TriggerHapticVibrationAction( VRActionHandle_t action, float fStartSecondsFromNow, float fDurationSeconds, float fFrequency, float fAmplitude, VRInputValueHandle_t ulRestrictToDevice ) = 0; + + // --------------- Action Origins ---------------- // + + /** Retrieve origin handles for an action */ + virtual EVRInputError GetActionOrigins( VRActionSetHandle_t actionSetHandle, VRActionHandle_t digitalActionHandle, VR_ARRAY_COUNT( originOutCount ) VRInputValueHandle_t *originsOut, uint32_t originOutCount ) = 0; + + /** Retrieves the name of the origin in the current language. unStringSectionsToInclude is a bitfield of values in EVRInputStringBits that allows the + application to specify which parts of the origin's information it wants a string for. */ + virtual EVRInputError GetOriginLocalizedName( VRInputValueHandle_t origin, VR_OUT_STRING() char *pchNameArray, uint32_t unNameArraySize, int32_t unStringSectionsToInclude ) = 0; + + /** Retrieves useful information for the origin of this action */ + virtual EVRInputError GetOriginTrackedDeviceInfo( VRInputValueHandle_t origin, InputOriginInfo_t *pOriginInfo, uint32_t unOriginInfoSize ) = 0; + + /** Retrieves useful information about the bindings for an action */ + virtual EVRInputError GetActionBindingInfo( VRActionHandle_t action, InputBindingInfo_t *pOriginInfo, uint32_t unBindingInfoSize, uint32_t unBindingInfoCount, uint32_t *punReturnedBindingInfoCount ) = 0; + + /** Shows the current binding for the action in-headset */ + virtual EVRInputError ShowActionOrigins( VRActionSetHandle_t actionSetHandle, VRActionHandle_t ulActionHandle ) = 0; + + /** Shows the current binding all the actions in the specified action sets */ + virtual EVRInputError ShowBindingsForActionSet( VR_ARRAY_COUNT( unSetCount ) VRActiveActionSet_t *pSets, uint32_t unSizeOfVRSelectedActionSet_t, uint32_t unSetCount, VRInputValueHandle_t originToHighlight ) = 0; + + /** Use this to query what action on the component returned by GetOriginTrackedDeviceInfo would trigger this binding. */ + virtual EVRInputError GetComponentStateForBinding( const char *pchRenderModelName, const char *pchComponentName, + const InputBindingInfo_t *pOriginInfo, uint32_t unBindingInfoSize, uint32_t unBindingInfoCount, + vr::RenderModel_ComponentState_t *pComponentState ) = 0; + + + // --------------- Legacy Input ------------------- // + virtual bool IsUsingLegacyInput() = 0; + + + // --------------- Utilities ------------------- // + + /** Opens the binding user interface. If no app key is provided it will use the key from the calling process. + * If no set is provided it will open to the root of the app binding page. */ + virtual EVRInputError OpenBindingUI( const char* pchAppKey, VRActionSetHandle_t ulActionSetHandle, VRInputValueHandle_t ulDeviceHandle, bool bShowOnDesktop ) = 0; + + /** Returns the variant set in the current bindings. If the binding doesn't include a variant setting, this function + * will return an empty string */ + virtual EVRInputError GetBindingVariant( vr::VRInputValueHandle_t ulDevicePath, + VR_OUT_STRING() char *pchVariantArray, uint32_t unVariantArraySize ) = 0; + + }; + + static const char * const IVRInput_Version = "IVRInput_010"; + +} // namespace vr + +// ivriobuffer.h + +namespace vr +{ + +typedef uint64_t IOBufferHandle_t; +static const uint64_t k_ulInvalidIOBufferHandle = 0; + + enum EIOBufferError + { + IOBuffer_Success = 0, + IOBuffer_OperationFailed = 100, + IOBuffer_InvalidHandle = 101, + IOBuffer_InvalidArgument = 102, + IOBuffer_PathExists = 103, + IOBuffer_PathDoesNotExist = 104, + IOBuffer_Permission = 105, + }; + + enum EIOBufferMode + { + IOBufferMode_Read = 0x0001, + IOBufferMode_Write = 0x0002, + IOBufferMode_Create = 0x0200, + }; + + // ---------------------------------------------------------------------------------------------- + // Purpose: + // ---------------------------------------------------------------------------------------------- + class IVRIOBuffer + { + public: + /** opens an existing or creates a new IOBuffer of unSize bytes */ + virtual vr::EIOBufferError Open( const char *pchPath, vr::EIOBufferMode mode, uint32_t unElementSize, uint32_t unElements, vr::IOBufferHandle_t *pulBuffer ) = 0; + + /** closes a previously opened or created buffer */ + virtual vr::EIOBufferError Close( vr::IOBufferHandle_t ulBuffer ) = 0; + + /** reads up to unBytes from buffer into *pDst, returning number of bytes read in *punRead */ + virtual vr::EIOBufferError Read( vr::IOBufferHandle_t ulBuffer, void *pDst, uint32_t unBytes, uint32_t *punRead ) = 0; + + /** writes unBytes of data from *pSrc into a buffer. */ + virtual vr::EIOBufferError Write( vr::IOBufferHandle_t ulBuffer, void *pSrc, uint32_t unBytes ) = 0; + + /** retrieves the property container of an buffer. */ + virtual vr::PropertyContainerHandle_t PropertyContainer( vr::IOBufferHandle_t ulBuffer ) = 0; + + /** inexpensively checks for readers to allow writers to fast-fail potentially expensive copies and writes. */ + virtual bool HasReaders( vr::IOBufferHandle_t ulBuffer ) = 0; + }; + + static const char * const IVRIOBuffer_Version = "IVRIOBuffer_002"; +} + +// ivrspatialanchors.h + +namespace vr +{ + static const SpatialAnchorHandle_t k_ulInvalidSpatialAnchorHandle = 0; + + struct SpatialAnchorPose_t + { + HmdMatrix34_t mAnchorToAbsoluteTracking; + }; + + class IVRSpatialAnchors + { + public: + + /** Returns a handle for an spatial anchor described by "descriptor". On success, pHandle + * will contain a handle valid for this session. Caller can wait for an event or occasionally + * poll GetSpatialAnchorPose() to find the virtual coordinate associated with this anchor. */ + virtual EVRSpatialAnchorError CreateSpatialAnchorFromDescriptor( const char *pchDescriptor, SpatialAnchorHandle_t *pHandleOut ) = 0; + + /** Returns a handle for an new spatial anchor at pPose. On success, pHandle + * will contain a handle valid for this session. Caller can wait for an event or occasionally + * poll GetSpatialAnchorDescriptor() to find the permanent descriptor for this pose. + * The result of GetSpatialAnchorPose() may evolve from this initial position if the driver chooses + * to update it. + * The anchor will be associated with the driver that provides unDeviceIndex, and the driver may use that specific + * device as a hint for how to best create the anchor. + * The eOrigin must match whatever tracking origin you are working in (seated/standing/raw). + * This should be called when the user is close to (and ideally looking at/interacting with) the target physical + * location. At that moment, the driver will have the most information about how to recover that physical point + * in the future, and the quality of the anchor (when the descriptor is re-used) will be highest. + * The caller may decide to apply offsets from this initial pose, but is advised to stay relatively close to the + * original pose location for highest fidelity. */ + virtual EVRSpatialAnchorError CreateSpatialAnchorFromPose( TrackedDeviceIndex_t unDeviceIndex, ETrackingUniverseOrigin eOrigin, SpatialAnchorPose_t *pPose, SpatialAnchorHandle_t *pHandleOut ) = 0; + + /** Get the pose for a given handle. This is intended to be cheap enough to call every frame (or fairly often) + * so that the driver can refine this position when it has more information available. */ + virtual EVRSpatialAnchorError GetSpatialAnchorPose( SpatialAnchorHandle_t unHandle, ETrackingUniverseOrigin eOrigin, SpatialAnchorPose_t *pPoseOut ) = 0; + + /** Get the descriptor for a given handle. This will be empty for handles where the driver has not + * yet built a descriptor. It will be the application-supplied descriptor for previously saved anchors + * that the application is requesting poses for. If the driver has called UpdateSpatialAnchorDescriptor() + * already in this session, it will be the descriptor provided by the driver. + * Returns true if the descriptor fits into the buffer, else false. Buffer size should be at least + * k_unMaxSpatialAnchorDescriptorSize. */ + virtual EVRSpatialAnchorError GetSpatialAnchorDescriptor( SpatialAnchorHandle_t unHandle, VR_OUT_STRING() char *pchDescriptorOut, uint32_t *punDescriptorBufferLenInOut ) = 0; + + }; + + static const char * const IVRSpatialAnchors_Version = "IVRSpatialAnchors_001"; + +} // namespace vr + +// ivrdebug.h + +namespace vr +{ + enum EVRDebugError + { + VRDebugError_Success = 0, + VRDebugError_BadParameter + }; + + /** Handle for vr profiler events */ + typedef uint64_t VrProfilerEventHandle_t; + + class IVRDebug + { + public: + + /** Create a vr profiler discrete event (point) + * The event will be associated with the message provided in pchMessage, and the current + * time will be used as the event timestamp. */ + virtual EVRDebugError EmitVrProfilerEvent( const char *pchMessage ) = 0; + + /** Create an vr profiler duration event (line) + * The current time will be used as the timestamp for the start of the line. + * On success, pHandleOut will contain a handle valid for terminating this event. */ + virtual EVRDebugError BeginVrProfilerEvent( VrProfilerEventHandle_t *pHandleOut ) = 0; + + /** Terminate a vr profiler event + * The event associated with hHandle will be considered completed when this method is called. + * The current time will be used assocaited to the termination time of the event, and + * pchMessage will be used as the event title. */ + virtual EVRDebugError FinishVrProfilerEvent( VrProfilerEventHandle_t hHandle, const char *pchMessage ) = 0; + + /** Sends a request to the driver for the specified device and returns the response. The maximum response size is 32k, + * but this method can be called with a smaller buffer. If the response exceeds the size of the buffer, it is truncated. + * The size of the response including its terminating null is returned. */ + virtual uint32_t DriverDebugRequest( vr::TrackedDeviceIndex_t unDeviceIndex, const char *pchRequest, VR_OUT_STRING() char *pchResponseBuffer, uint32_t unResponseBufferSize ) = 0; + + }; + + static const char * const IVRDebug_Version = "IVRDebug_001"; + +} // namespace vr +// End + +#endif // _OPENVR_API + + + +namespace vr +{ +#if !defined( OPENVR_INTERFACE_INTERNAL ) + + /** Finds the active installation of the VR API and initializes it. The provided path must be absolute + * or relative to the current working directory. These are the local install versions of the equivalent + * functions in steamvr.h and will work without a local Steam install. + * + * This path is to the "root" of the VR API install. That's the directory with + * the "drivers" directory and a platform (i.e. "win32") directory in it, not the directory with the DLL itself. + * + * pStartupInfo is reserved for future use. + */ + inline IVRSystem *VR_Init( EVRInitError *peError, EVRApplicationType eApplicationType, const char *pStartupInfo = nullptr ); + + /** unloads vrclient.dll. Any interface pointers from the interface are + * invalid after this point */ + inline void VR_Shutdown(); + + /** Returns true if there is an HMD attached. This check is as lightweight as possible and + * can be called outside of VR_Init/VR_Shutdown. It should be used when an application wants + * to know if initializing VR is a possibility but isn't ready to take that step yet. + */ + VR_INTERFACE bool VR_CALLTYPE VR_IsHmdPresent(); + + /** Returns true if the OpenVR runtime is installed. */ + VR_INTERFACE bool VR_CALLTYPE VR_IsRuntimeInstalled(); + + /** Returns where the OpenVR runtime is installed. */ + VR_INTERFACE bool VR_GetRuntimePath( VR_OUT_STRING() char *pchPathBuffer, uint32_t unBufferSize, uint32_t *punRequiredBufferSize ); + + /** Returns the name of the enum value for an EVRInitError. This function may be called outside of VR_Init()/VR_Shutdown(). */ + VR_INTERFACE const char *VR_CALLTYPE VR_GetVRInitErrorAsSymbol( EVRInitError error ); + + /** Returns an English string for an EVRInitError. Applications should call VR_GetVRInitErrorAsSymbol instead and + * use that as a key to look up their own localized error message. This function may be called outside of VR_Init()/VR_Shutdown(). */ + VR_INTERFACE const char *VR_CALLTYPE VR_GetVRInitErrorAsEnglishDescription( EVRInitError error ); + + /** Returns the interface of the specified version. This method must be called after VR_Init. The + * pointer returned is valid until VR_Shutdown is called. + */ + VR_INTERFACE void *VR_CALLTYPE VR_GetGenericInterface( const char *pchInterfaceVersion, EVRInitError *peError ); + + /** Returns whether the interface of the specified version exists. + */ + VR_INTERFACE bool VR_CALLTYPE VR_IsInterfaceVersionValid( const char *pchInterfaceVersion ); + + /** Returns a token that represents whether the VR interface handles need to be reloaded */ + VR_INTERFACE uint32_t VR_CALLTYPE VR_GetInitToken(); + + // These typedefs allow old enum names from SDK 0.9.11 to be used in applications. + // They will go away in the future. + typedef EVRInitError HmdError; + typedef EVREye Hmd_Eye; + typedef EColorSpace ColorSpace; + typedef ETrackingResult HmdTrackingResult; + typedef ETrackedDeviceClass TrackedDeviceClass; + typedef ETrackingUniverseOrigin TrackingUniverseOrigin; + typedef ETrackedDeviceProperty TrackedDeviceProperty; + typedef ETrackedPropertyError TrackedPropertyError; + typedef EVRSubmitFlags VRSubmitFlags_t; + typedef EVRState VRState_t; + typedef ECollisionBoundsStyle CollisionBoundsStyle_t; + typedef EVROverlayError VROverlayError; + typedef EVRFirmwareError VRFirmwareError; + typedef EVRCompositorError VRCompositorError; + typedef EVRScreenshotError VRScreenshotsError; + + inline uint32_t &VRToken() + { + static uint32_t token; + return token; + } + + class COpenVRContext + { + public: + COpenVRContext() { Clear(); } + void Clear(); + + inline void CheckClear() + { + if ( VRToken() != VR_GetInitToken() ) + { + Clear(); + VRToken() = VR_GetInitToken(); + } + } + + IVRSystem *VRSystem() + { + CheckClear(); + if ( m_pVRSystem == nullptr ) + { + EVRInitError eError; + m_pVRSystem = ( IVRSystem * )VR_GetGenericInterface( IVRSystem_Version, &eError ); + } + return m_pVRSystem; + } + IVRChaperone *VRChaperone() + { + CheckClear(); + if ( m_pVRChaperone == nullptr ) + { + EVRInitError eError; + m_pVRChaperone = ( IVRChaperone * )VR_GetGenericInterface( IVRChaperone_Version, &eError ); + } + return m_pVRChaperone; + } + + IVRChaperoneSetup *VRChaperoneSetup() + { + CheckClear(); + if ( m_pVRChaperoneSetup == nullptr ) + { + EVRInitError eError; + m_pVRChaperoneSetup = ( IVRChaperoneSetup * )VR_GetGenericInterface( IVRChaperoneSetup_Version, &eError ); + } + return m_pVRChaperoneSetup; + } + + IVRCompositor *VRCompositor() + { + CheckClear(); + if ( m_pVRCompositor == nullptr ) + { + EVRInitError eError; + m_pVRCompositor = ( IVRCompositor * )VR_GetGenericInterface( IVRCompositor_Version, &eError ); + } + return m_pVRCompositor; + } + + IVROverlay *VROverlay() + { + CheckClear(); + if ( m_pVROverlay == nullptr ) + { + EVRInitError eError; + m_pVROverlay = ( IVROverlay * )VR_GetGenericInterface( IVROverlay_Version, &eError ); + } + return m_pVROverlay; + } + + IVROverlayView *VROverlayView() + { + CheckClear(); + if ( m_pVROverlayView == nullptr ) + { + EVRInitError eError; + m_pVROverlayView = ( IVROverlayView * ) VR_GetGenericInterface( IVROverlayView_Version, &eError ); + } + return m_pVROverlayView; + } + + IVRHeadsetView *VRHeadsetView() + { + CheckClear(); + if ( m_pVRHeadsetView == nullptr ) + { + EVRInitError eError; + m_pVRHeadsetView = ( IVRHeadsetView * ) VR_GetGenericInterface( IVRHeadsetView_Version, &eError ); + } + return m_pVRHeadsetView; + } + + IVRResources *VRResources() + { + CheckClear(); + if ( m_pVRResources == nullptr ) + { + EVRInitError eError; + m_pVRResources = (IVRResources *)VR_GetGenericInterface( IVRResources_Version, &eError ); + } + return m_pVRResources; + } + + IVRScreenshots *VRScreenshots() + { + CheckClear(); + if ( m_pVRScreenshots == nullptr ) + { + EVRInitError eError; + m_pVRScreenshots = ( IVRScreenshots * )VR_GetGenericInterface( IVRScreenshots_Version, &eError ); + } + return m_pVRScreenshots; + } + + IVRRenderModels *VRRenderModels() + { + CheckClear(); + if ( m_pVRRenderModels == nullptr ) + { + EVRInitError eError; + m_pVRRenderModels = ( IVRRenderModels * )VR_GetGenericInterface( IVRRenderModels_Version, &eError ); + } + return m_pVRRenderModels; + } + + IVRExtendedDisplay *VRExtendedDisplay() + { + CheckClear(); + if ( m_pVRExtendedDisplay == nullptr ) + { + EVRInitError eError; + m_pVRExtendedDisplay = ( IVRExtendedDisplay * )VR_GetGenericInterface( IVRExtendedDisplay_Version, &eError ); + } + return m_pVRExtendedDisplay; + } + + IVRSettings *VRSettings() + { + CheckClear(); + if ( m_pVRSettings == nullptr ) + { + EVRInitError eError; + m_pVRSettings = ( IVRSettings * )VR_GetGenericInterface( IVRSettings_Version, &eError ); + } + return m_pVRSettings; + } + + IVRApplications *VRApplications() + { + CheckClear(); + if ( m_pVRApplications == nullptr ) + { + EVRInitError eError; + m_pVRApplications = ( IVRApplications * )VR_GetGenericInterface( IVRApplications_Version, &eError ); + } + return m_pVRApplications; + } + + IVRTrackedCamera *VRTrackedCamera() + { + CheckClear(); + if ( m_pVRTrackedCamera == nullptr ) + { + EVRInitError eError; + m_pVRTrackedCamera = ( IVRTrackedCamera * )VR_GetGenericInterface( IVRTrackedCamera_Version, &eError ); + } + return m_pVRTrackedCamera; + } + + IVRDriverManager *VRDriverManager() + { + CheckClear(); + if ( !m_pVRDriverManager ) + { + EVRInitError eError; + m_pVRDriverManager = ( IVRDriverManager * )VR_GetGenericInterface( IVRDriverManager_Version, &eError ); + } + return m_pVRDriverManager; + } + + IVRInput *VRInput() + { + CheckClear(); + if ( !m_pVRInput ) + { + EVRInitError eError; + m_pVRInput = (IVRInput *)VR_GetGenericInterface( IVRInput_Version, &eError ); + } + return m_pVRInput; + } + + IVRIOBuffer *VRIOBuffer() + { + if ( !m_pVRIOBuffer ) + { + EVRInitError eError; + m_pVRIOBuffer = ( IVRIOBuffer * )VR_GetGenericInterface( IVRIOBuffer_Version, &eError ); + } + return m_pVRIOBuffer; + } + + IVRSpatialAnchors *VRSpatialAnchors() + { + CheckClear(); + if ( !m_pVRSpatialAnchors ) + { + EVRInitError eError; + m_pVRSpatialAnchors = (IVRSpatialAnchors *)VR_GetGenericInterface( IVRSpatialAnchors_Version, &eError ); + } + return m_pVRSpatialAnchors; + } + + IVRDebug *VRDebug() + { + CheckClear(); + if ( !m_pVRDebug ) + { + EVRInitError eError; + m_pVRDebug = (IVRDebug *)VR_GetGenericInterface( IVRDebug_Version, &eError ); + } + return m_pVRDebug; + } + + IVRNotifications *VRNotifications() + { + CheckClear(); + if ( !m_pVRNotifications ) + { + EVRInitError eError; + m_pVRNotifications = ( IVRNotifications * )VR_GetGenericInterface( IVRNotifications_Version, &eError ); + } + return m_pVRNotifications; + } + + private: + IVRSystem *m_pVRSystem; + IVRChaperone *m_pVRChaperone; + IVRChaperoneSetup *m_pVRChaperoneSetup; + IVRCompositor *m_pVRCompositor; + IVRHeadsetView *m_pVRHeadsetView; + IVROverlay *m_pVROverlay; + IVROverlayView *m_pVROverlayView; + IVRResources *m_pVRResources; + IVRRenderModels *m_pVRRenderModels; + IVRExtendedDisplay *m_pVRExtendedDisplay; + IVRSettings *m_pVRSettings; + IVRApplications *m_pVRApplications; + IVRTrackedCamera *m_pVRTrackedCamera; + IVRScreenshots *m_pVRScreenshots; + IVRDriverManager *m_pVRDriverManager; + IVRInput *m_pVRInput; + IVRIOBuffer *m_pVRIOBuffer; + IVRSpatialAnchors *m_pVRSpatialAnchors; + IVRDebug *m_pVRDebug; + IVRNotifications *m_pVRNotifications; + }; + + inline COpenVRContext &OpenVRInternal_ModuleContext() + { + static void *ctx[ sizeof( COpenVRContext ) / sizeof( void * ) ]; + return *( COpenVRContext * )ctx; // bypass zero-init constructor + } + + inline IVRSystem *VR_CALLTYPE VRSystem() { return OpenVRInternal_ModuleContext().VRSystem(); } + inline IVRChaperone *VR_CALLTYPE VRChaperone() { return OpenVRInternal_ModuleContext().VRChaperone(); } + inline IVRChaperoneSetup *VR_CALLTYPE VRChaperoneSetup() { return OpenVRInternal_ModuleContext().VRChaperoneSetup(); } + inline IVRCompositor *VR_CALLTYPE VRCompositor() { return OpenVRInternal_ModuleContext().VRCompositor(); } + inline IVROverlay *VR_CALLTYPE VROverlay() { return OpenVRInternal_ModuleContext().VROverlay(); } + inline IVROverlayView *VR_CALLTYPE VROverlayView() { return OpenVRInternal_ModuleContext().VROverlayView(); } + inline IVRHeadsetView *VR_CALLTYPE VRHeadsetView() { return OpenVRInternal_ModuleContext().VRHeadsetView(); } + inline IVRScreenshots *VR_CALLTYPE VRScreenshots() { return OpenVRInternal_ModuleContext().VRScreenshots(); } + inline IVRRenderModels *VR_CALLTYPE VRRenderModels() { return OpenVRInternal_ModuleContext().VRRenderModels(); } + inline IVRApplications *VR_CALLTYPE VRApplications() { return OpenVRInternal_ModuleContext().VRApplications(); } + inline IVRSettings *VR_CALLTYPE VRSettings() { return OpenVRInternal_ModuleContext().VRSettings(); } + inline IVRResources *VR_CALLTYPE VRResources() { return OpenVRInternal_ModuleContext().VRResources(); } + inline IVRExtendedDisplay *VR_CALLTYPE VRExtendedDisplay() { return OpenVRInternal_ModuleContext().VRExtendedDisplay(); } + inline IVRTrackedCamera *VR_CALLTYPE VRTrackedCamera() { return OpenVRInternal_ModuleContext().VRTrackedCamera(); } + inline IVRDriverManager *VR_CALLTYPE VRDriverManager() { return OpenVRInternal_ModuleContext().VRDriverManager(); } + inline IVRInput *VR_CALLTYPE VRInput() { return OpenVRInternal_ModuleContext().VRInput(); } + inline IVRIOBuffer *VR_CALLTYPE VRIOBuffer() { return OpenVRInternal_ModuleContext().VRIOBuffer(); } + inline IVRSpatialAnchors *VR_CALLTYPE VRSpatialAnchors() { return OpenVRInternal_ModuleContext().VRSpatialAnchors(); } + inline IVRNotifications *VR_CALLTYPE VRNotifications() { return OpenVRInternal_ModuleContext().VRNotifications(); } + inline IVRDebug *VR_CALLTYPE VRDebug() { return OpenVRInternal_ModuleContext().VRDebug(); } + + inline void COpenVRContext::Clear() + { + m_pVRSystem = nullptr; + m_pVRChaperone = nullptr; + m_pVRChaperoneSetup = nullptr; + m_pVRCompositor = nullptr; + m_pVROverlay = nullptr; + m_pVROverlayView = nullptr; + m_pVRHeadsetView = nullptr; + m_pVRRenderModels = nullptr; + m_pVRExtendedDisplay = nullptr; + m_pVRSettings = nullptr; + m_pVRApplications = nullptr; + m_pVRTrackedCamera = nullptr; + m_pVRResources = nullptr; + m_pVRScreenshots = nullptr; + m_pVRDriverManager = nullptr; + m_pVRInput = nullptr; + m_pVRIOBuffer = nullptr; + m_pVRSpatialAnchors = nullptr; + m_pVRNotifications = nullptr; + m_pVRDebug = nullptr; + } + + VR_INTERFACE uint32_t VR_CALLTYPE VR_InitInternal2( EVRInitError *peError, EVRApplicationType eApplicationType, const char *pStartupInfo ); + VR_INTERFACE void VR_CALLTYPE VR_ShutdownInternal(); + + /** Finds the active installation of vrclient.dll and initializes it */ + inline IVRSystem *VR_Init( EVRInitError *peError, EVRApplicationType eApplicationType, const char *pStartupInfo ) + { + IVRSystem *pVRSystem = nullptr; + + EVRInitError eError; + VRToken() = VR_InitInternal2( &eError, eApplicationType, pStartupInfo ); + COpenVRContext &ctx = OpenVRInternal_ModuleContext(); + ctx.Clear(); + + if ( eError == VRInitError_None ) + { + if ( VR_IsInterfaceVersionValid( IVRSystem_Version ) ) + { + pVRSystem = VRSystem(); + } + else + { + VR_ShutdownInternal(); + eError = VRInitError_Init_InterfaceNotFound; + } + } + + if ( peError ) + *peError = eError; + return pVRSystem; + } + + /** unloads vrclient.dll. Any interface pointers from the interface are + * invalid after this point */ + inline void VR_Shutdown() + { + VR_ShutdownInternal(); + } + +#endif // OPENVR_INTERFACE_INTERNAL +} diff --git a/tools/Update Pixel VR Player.desktop b/tools/Update Pixel VR Player.desktop new file mode 100644 index 0000000..d485a15 --- /dev/null +++ b/tools/Update Pixel VR Player.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=Update Pixel VR Player +Comment=Update Pixel VR Player to the latest version on Valve Steam Frame +Exec=bash -c 'SCRIPT_DIR="$(dirname "%k")"; if [ -f "$HOME/PixelVRPlayer/update.sh" ]; then bash "$HOME/PixelVRPlayer/update.sh"; elif [ -f "$SCRIPT_DIR/update.sh" ]; then cd "$SCRIPT_DIR" && bash update.sh; else curl -fsSL https://raw.githubusercontent.com/Pixelplanet/Pixel-VR-Player/main/tools/install.sh | bash -s -- --update; fi; if [ $? -eq 0 ]; then command -v kdialog >/dev/null && kdialog --title "Pixel VR Player" --msgbox "Update complete!\n\nPixel VR Player has been updated to the latest version.\nYou can now return to Gaming Mode."; else command -v kdialog >/dev/null && kdialog --title "Pixel VR Player" --error "Update encountered an issue.\nCheck terminal output or internet connection."; fi; read -p "Press Enter to close..." dummy' +Icon=steam +Terminal=true +Type=Application +Categories=AudioVideo;Player;VR; diff --git a/tools/install.sh b/tools/install.sh index ff1dc0a..b9e3ece 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -29,6 +29,7 @@ VERSION="" DO_STEAM=1 RESTART_STEAM=0 UNINSTALL=0 +DO_UPDATE=0 FORCE=0 if [ -t 1 ]; then @@ -57,6 +58,7 @@ Usage: Options: --dir DIR install directory (default: ~/PixelVRPlayer) --version vX.Y.Z release to install (default: the latest release) + --update force fetching the latest release from GitHub --no-steam do not add the Non-Steam Game shortcut --restart-steam close Steam before registering, then start it again --uninstall remove the app and its Steam shortcut @@ -82,6 +84,7 @@ while [ $# -gt 0 ]; do [ $# -ge 2 ] || die "--version needs a value" VERSION="$2"; shift ;; --version=*) VERSION="${1#--version=}" ;; + --update) DO_UPDATE=1 ;; --no-steam) DO_STEAM=0 ;; --restart-steam) RESTART_STEAM=1 ;; --uninstall) UNINSTALL=1 ;; @@ -430,6 +433,7 @@ if [ "$UNINSTALL" -eq 1 ]; then fi fi rm -rf "$INSTALL_DIR" + rm -f "$HOME/Desktop/Update Pixel VR Player.desktop" ok "removed $INSTALL_DIR" printf '\nSettings (%s/.config/pixelvr) and cached thumbnails were kept.\n' "$HOME" printf 'Delete them too with: rm -rf ~/.config/pixelvr ~/.cache/pixelvr\n' @@ -472,7 +476,7 @@ tmp="" cleanup() { [ -z "$tmp" ] || rm -rf "$tmp"; } trap cleanup EXIT INT TERM -if [ -n "$script_dir" ] && [ -f "$script_dir/pixelvr" ] && [ -d "$script_dir/shaders" ]; then +if [ "$DO_UPDATE" -eq 0 ] && [ -n "$script_dir" ] && [ -f "$script_dir/pixelvr" ] && [ -d "$script_dir/shaders" ]; then info "Installing from $script_dir" srcdir="$script_dir" if [ -f "$script_dir/VERSION" ]; then @@ -543,6 +547,38 @@ elif [ -n "$script_dir" ] && [ -f "$script_dir/install.sh" ]; then chmod 0755 "$INSTALL_DIR/install.sh" INSTALLED_SCRIPT=1 fi +# Copy updater script +if [ -f "$srcdir/update.sh" ]; then + cp "$srcdir/update.sh" "$INSTALL_DIR/update.sh" + chmod 0755 "$INSTALL_DIR/update.sh" +elif [ -n "$script_dir" ] && [ -f "$script_dir/update.sh" ]; then + cp "$script_dir/update.sh" "$INSTALL_DIR/update.sh" + chmod 0755 "$INSTALL_DIR/update.sh" +elif [ -f "tools/update.sh" ]; then + cp "tools/update.sh" "$INSTALL_DIR/update.sh" + chmod 0755 "$INSTALL_DIR/update.sh" +fi + +# Copy Desktop 1-click update entry +DESKTOP_ENTRY="Update Pixel VR Player.desktop" +if [ -f "$srcdir/$DESKTOP_ENTRY" ]; then + cp "$srcdir/$DESKTOP_ENTRY" "$INSTALL_DIR/$DESKTOP_ENTRY" + chmod 0755 "$INSTALL_DIR/$DESKTOP_ENTRY" +elif [ -n "$script_dir" ] && [ -f "$script_dir/$DESKTOP_ENTRY" ]; then + cp "$script_dir/$DESKTOP_ENTRY" "$INSTALL_DIR/$DESKTOP_ENTRY" + chmod 0755 "$INSTALL_DIR/$DESKTOP_ENTRY" +elif [ -f "tools/$DESKTOP_ENTRY" ]; then + cp "tools/$DESKTOP_ENTRY" "$INSTALL_DIR/$DESKTOP_ENTRY" + chmod 0755 "$INSTALL_DIR/$DESKTOP_ENTRY" +fi + +# Install 1-click update shortcut to Desktop if Desktop folder exists +if [ -d "$HOME/Desktop" ] && [ -f "$INSTALL_DIR/$DESKTOP_ENTRY" ]; then + cp "$INSTALL_DIR/$DESKTOP_ENTRY" "$HOME/Desktop/$DESKTOP_ENTRY" + chmod 0755 "$HOME/Desktop/$DESKTOP_ENTRY" + ok "Installed 1-click update shortcut to ~/Desktop/$DESKTOP_ENTRY" +fi + if [ -f "$srcdir/VERSION" ]; then cp "$srcdir/VERSION" "$INSTALL_DIR/VERSION" elif [ -n "$VERSION" ]; then @@ -599,7 +635,7 @@ printf '\n Launch now : %s/run.sh\n' "$INSTALL_DIR" printf ' From Steam : Library > Non-Steam > %s\n' "$APP_NAME" printf ' Play a clip : %s/run.sh /path/to/clip.mp4\n' "$INSTALL_DIR" printf ' Logs : ~/pixelvr-run.log\n' -printf ' Update : run this script again (settings and cache are kept)\n' +printf ' 1-Click Upd : %s/update.sh (or "Update Pixel VR Player" icon on Desktop)\n' "$INSTALL_DIR" if [ "$INSTALLED_SCRIPT" -eq 1 ]; then printf ' Remove : %s/install.sh --uninstall\n\n' "$INSTALL_DIR" else diff --git a/tools/package-release.sh b/tools/package-release.sh index f26de30..fb014cb 100755 --- a/tools/package-release.sh +++ b/tools/package-release.sh @@ -37,9 +37,15 @@ cp "${bin}" "${stage}/PixelVRPlayer/pixelvr" cp "${BUILD_DIR}/shaders/"*.spv "${stage}/PixelVRPlayer/shaders/" cp tools/run.sh "${stage}/PixelVRPlayer/run.sh" cp tools/install.sh "${stage}/PixelVRPlayer/install.sh" +if [[ -f "tools/update.sh" ]]; then + cp tools/update.sh "${stage}/PixelVRPlayer/update.sh" +fi if [[ -f "tools/Install Pixel VR Player.desktop" ]]; then cp "tools/Install Pixel VR Player.desktop" "${stage}/PixelVRPlayer/Install Pixel VR Player.desktop" fi +if [[ -f "tools/Update Pixel VR Player.desktop" ]]; then + cp "tools/Update Pixel VR Player.desktop" "${stage}/PixelVRPlayer/Update Pixel VR Player.desktop" +fi for asset in icon.png hero.png capsule.png header.png logo.png; do if [[ -f "assets/${asset}" ]]; then cp "assets/${asset}" "${stage}/PixelVRPlayer/${asset}" @@ -51,9 +57,15 @@ fi chmod +x "${stage}/PixelVRPlayer/pixelvr" \ "${stage}/PixelVRPlayer/run.sh" \ "${stage}/PixelVRPlayer/install.sh" +if [[ -f "${stage}/PixelVRPlayer/update.sh" ]]; then + chmod +x "${stage}/PixelVRPlayer/update.sh" +fi if [[ -f "${stage}/PixelVRPlayer/Install Pixel VR Player.desktop" ]]; then chmod +x "${stage}/PixelVRPlayer/Install Pixel VR Player.desktop" fi +if [[ -f "${stage}/PixelVRPlayer/Update Pixel VR Player.desktop" ]]; then + chmod +x "${stage}/PixelVRPlayer/Update Pixel VR Player.desktop" +fi rm -f "${OUT_TAR}" tar -C "${stage}" -czf "${OUT_TAR}" PixelVRPlayer diff --git a/tools/update-from-pc.bat b/tools/update-from-pc.bat new file mode 100644 index 0000000..db03f5f --- /dev/null +++ b/tools/update-from-pc.bat @@ -0,0 +1,50 @@ +@echo off +setlocal enabledelayedexpansion + +echo =============================================================== +echo Pixel VR Player - Steam Frame Remote Updater +echo =============================================================== +echo This tool updates Pixel VR Player on your Valve Steam Frame +echo to the latest release over Wi-Fi directly from your PC. +echo (All your settings, bookmarks, and shares are kept safe). +echo =============================================================== +echo. + +set "FRAME_IP=steamframe.local" +set /p "INPUT_IP=Enter Steam Frame IP address [press Enter for steamframe.local]: " +if not "!INPUT_IP!"=="" set "FRAME_IP=!INPUT_IP!" + +echo. +echo Connecting to steamos@!FRAME_IP!... +echo (If prompted for a password, enter your SteamOS desktop password) +echo. + +where ssh >nul 2>&1 +if %ERRORLEVEL% neq 0 ( + echo [ERROR] SSH is not installed or not in PATH on this PC. + pause + exit /b 1 +) + +set "REMOTE_CMD=curl -fsSL https://raw.githubusercontent.com/Pixelplanet/Pixel-VR-Player/main/tools/install.sh | sh -s -- --update" + +ssh -o StrictHostKeyChecking=no steamos@!FRAME_IP! "!REMOTE_CMD!" + +if %ERRORLEVEL% equ 0 ( + echo. + echo =============================================================== + echo [SUCCESS] Pixel VR Player has been updated on your Steam Frame! + echo =============================================================== +) else ( + echo. + echo =============================================================== + echo [NOTE] If connection failed, please ensure: + echo 1. Both your PC and Steam Frame are on the same Wi-Fi. + echo 2. SSH is enabled on the headset. + echo (In Desktop Mode, open Konsole and run 'passwd', + echo then 'sudo systemctl start sshd', or enable Dev Mode). + echo =============================================================== +) + +echo. +pause diff --git a/tools/update-from-pc.sh b/tools/update-from-pc.sh new file mode 100644 index 0000000..4a59a39 --- /dev/null +++ b/tools/update-from-pc.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Pixel VR Player - Remote updater from Mac / Linux to Steam Frame + +set -euo pipefail + +echo "===============================================================" +echo " Pixel VR Player - Steam Frame Remote Updater" +echo "===============================================================" +echo " This tool updates Pixel VR Player on your Valve Steam Frame" +echo " to the latest release over Wi-Fi directly from your Mac or PC." +echo " (All your settings, bookmarks, and shares are kept safe)." +echo "===============================================================" +echo "" + +read -rp "Enter Steam Frame IP address [press Enter for steamframe.local]: " INPUT_IP +FRAME_IP="${INPUT_IP:-steamframe.local}" + +echo "" +echo "Connecting to steamos@${FRAME_IP}..." +echo "(If prompted for a password, enter your SteamOS desktop password)" +echo "" + +REMOTE_CMD="curl -fsSL https://raw.githubusercontent.com/Pixelplanet/Pixel-VR-Player/main/tools/install.sh | sh -s -- --update" + +if ssh -o StrictHostKeyChecking=no "steamos@${FRAME_IP}" "${REMOTE_CMD}"; then + echo "" + echo "===============================================================" + echo " [SUCCESS] Pixel VR Player has been updated on your Steam Frame!" + echo "===============================================================" +else + echo "" + echo "===============================================================" + echo " [NOTE] If connection failed, please ensure:" + echo " 1. Both devices are on the same Wi-Fi network." + echo " 2. SSH is enabled on the headset." + echo " (In Desktop Mode, open Konsole and run 'passwd'," + echo " then 'sudo systemctl start sshd', or enable Dev Mode)." + echo "===============================================================" +fi diff --git a/tools/update.sh b/tools/update.sh new file mode 100644 index 0000000..f6db4ab --- /dev/null +++ b/tools/update.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# Pixel VR Player updater for Valve Steam Frame +# Downloads and installs the latest release in-place. +set -eu + +REPO="Pixelplanet/Pixel-VR-Player" +SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" 2>/dev/null && pwd) +INSTALL_DIR="${PIXELVR_INSTALL_DIR:-$HOME/PixelVRPlayer}" + +if [ -n "$SCRIPT_DIR" ] && [ -f "$SCRIPT_DIR/pixelvr" ]; then + INSTALL_DIR="$SCRIPT_DIR" +fi + +if [ -t 1 ]; then + C_INFO=$(printf '\0033[36m') + C_OK=$(printf '\0033[32m') + C_ERR=$(printf '\0033[31m') + C_OFF=$(printf '\0033[0m') +else + C_INFO=""; C_OK=""; C_ERR=""; C_OFF="" +fi + +printf '%s==>%s Checking for Pixel VR Player updates for %s...\n' "$C_INFO" "$C_OFF" "$INSTALL_DIR" + +# Execute in-place update using install.sh with --update flag +if [ -f "$INSTALL_DIR/install.sh" ]; then + "$INSTALL_DIR/install.sh" --dir "$INSTALL_DIR" --update "$@" +else + curl -fsSL https://raw.githubusercontent.com/"$REPO"/main/tools/install.sh | sh -s -- --dir "$INSTALL_DIR" --update "$@" +fi + +if [ $? -eq 0 ]; then + printf '\n%s ok%s Pixel VR Player update complete!\n' "$C_OK" "$C_OFF" + if [ -n "${DISPLAY:-}" ] || [ -n "${WAYLAND_DISPLAY:-}" ]; then + if command -v notify-send >/dev/null 2>&1; then + notify-send "Pixel VR Player" "Updated to the latest version successfully!" || true + fi + fi +else + printf '\n%serror%s Pixel VR Player update failed.\n' "$C_ERR" "$C_OFF" >&2 + exit 1 +fi