openvr_sys2/
lib.rs

1use std::mem::ManuallyDrop;
2autocxx::include_cpp! {
3    #include "../third-party/openvr/headers/openvr.h"
4    generate!("vr::IVRSystem")
5    generate!("vr::IVROverlay")
6    generate!("vr::IVRCompositor")
7    generate!("vr::IVRInput")
8    generate_pod!("vr::VRActiveActionSet_t")
9    generate_pod!("vr::VREvent_Reserved_t")
10    generate_pod!("vr::VREvent_Controller_t")
11    generate_pod!("vr::VREvent_Mouse_t")
12    generate_pod!("vr::VREvent_Scroll_t")
13    generate_pod!("vr::VREvent_Process_t")
14    generate_pod!("vr::VREvent_Notification_t")
15    generate_pod!("vr::VREvent_Overlay_t")
16    generate_pod!("vr::VREvent_Status_t")
17    generate_pod!("vr::VREvent_Keyboard_t")
18    generate_pod!("vr::VREvent_Ipd_t")
19    generate_pod!("vr::VREvent_Chaperone_t")
20    generate_pod!("vr::VREvent_PerformanceTest_t")
21    generate_pod!("vr::VREvent_TouchPadMove_t")
22    generate_pod!("vr::VREvent_SeatedZeroPoseReset_t")
23    generate_pod!("vr::VREvent_Screenshot_t")
24    generate_pod!("vr::VREvent_ScreenshotProgress_t")
25    generate_pod!("vr::VREvent_ApplicationLaunch_t")
26    generate_pod!("vr::VREvent_EditingCameraSurface_t")
27    generate_pod!("vr::VREvent_MessageOverlay_t")
28    generate_pod!("vr::VREvent_Property_t")
29    generate_pod!("vr::VREvent_HapticVibration_t")
30    generate_pod!("vr::VREvent_WebConsole_t")
31    generate_pod!("vr::VREvent_InputBindingLoad_t")
32    generate_pod!("vr::VREvent_InputActionManifestLoad_t")
33    generate_pod!("vr::VREvent_SpatialAnchor_t")
34    generate_pod!("vr::VREvent_ProgressUpdate_t")
35    generate_pod!("vr::VREvent_ShowUI_t")
36    generate_pod!("vr::VREvent_ShowDevTools_t")
37    generate_pod!("vr::VREvent_HDCPError_t")
38    generate_pod!("vr::TrackedDeviceIndex_t")
39    generate_pod!("vr::TrackedDevicePose_t")
40    generate_pod!("vr::VRTextureBounds_t")
41    generate_pod!("vr::VRVulkanTextureData_t")
42    generate_pod!("vr::Texture_t")
43    generate_pod!("vr::ETextureType")
44    generate_pod!("vr::EVRInputError")
45    generate_pod!("vr::HmdMatrix34_t")
46    generate_pod!("vr::InputDigitalActionData_t")
47    generate!("vr::k_ulInvalidInputValueHandle")
48    generate!("vr::VR_Init")
49    generate!("vr::VR_Shutdown")
50    generate!("vr::VR_IsHmdPresent")
51    generate!("vr::VROverlay")
52    generate!("vr::VRCompositor")
53    generate!("vr::VRInput")
54    safety!(unsafe)
55}
56
57#[allow(non_camel_case_types, non_snake_case)]
58#[repr(C)]
59pub union VREvent_Data_t {
60    pub reserved: ManuallyDrop<ffi::vr::VREvent_Reserved_t>,
61    pub controller: ManuallyDrop<ffi::vr::VREvent_Controller_t>,
62    pub mouse: ManuallyDrop<ffi::vr::VREvent_Mouse_t>,
63    pub scroll: ManuallyDrop<ffi::vr::VREvent_Scroll_t>,
64    pub process: ManuallyDrop<ffi::vr::VREvent_Process_t>,
65    pub notification: ManuallyDrop<ffi::vr::VREvent_Notification_t>,
66    pub overlay: ManuallyDrop<ffi::vr::VREvent_Overlay_t>,
67    pub status: ManuallyDrop<ffi::vr::VREvent_Status_t>,
68    pub keyboard: ManuallyDrop<ffi::vr::VREvent_Keyboard_t>,
69    pub ipd: ManuallyDrop<ffi::vr::VREvent_Ipd_t>,
70    pub chaperone: ManuallyDrop<ffi::vr::VREvent_Chaperone_t>,
71    pub performanceTest: ManuallyDrop<ffi::vr::VREvent_PerformanceTest_t>,
72    pub touchPadMove: ManuallyDrop<ffi::vr::VREvent_TouchPadMove_t>,
73    pub seatedZeroPoseReset: ManuallyDrop<ffi::vr::VREvent_SeatedZeroPoseReset_t>,
74    pub screenshot: ManuallyDrop<ffi::vr::VREvent_Screenshot_t>,
75    pub screenshotProgress: ManuallyDrop<ffi::vr::VREvent_ScreenshotProgress_t>,
76    pub applicationLaunch: ManuallyDrop<ffi::vr::VREvent_ApplicationLaunch_t>,
77    pub cameraSurface: ManuallyDrop<ffi::vr::VREvent_EditingCameraSurface_t>,
78    pub messageOverlay: ManuallyDrop<ffi::vr::VREvent_MessageOverlay_t>,
79    pub property: ManuallyDrop<ffi::vr::VREvent_Property_t>,
80    pub hapticVibration: ManuallyDrop<ffi::vr::VREvent_HapticVibration_t>,
81    pub webConsole: ManuallyDrop<ffi::vr::VREvent_WebConsole_t>,
82    pub inputBinding: ManuallyDrop<ffi::vr::VREvent_InputBindingLoad_t>,
83    pub actionManifest: ManuallyDrop<ffi::vr::VREvent_InputActionManifestLoad_t>,
84    pub spatialAnchor: ManuallyDrop<ffi::vr::VREvent_SpatialAnchor_t>,
85    pub progressUpdate: ManuallyDrop<ffi::vr::VREvent_ProgressUpdate_t>,
86    pub showUi: ManuallyDrop<ffi::vr::VREvent_ShowUI_t>,
87    pub showDevTools: ManuallyDrop<ffi::vr::VREvent_ShowDevTools_t>,
88    pub hdcpError: ManuallyDrop<ffi::vr::VREvent_HDCPError_t>,
89}
90
91#[allow(non_camel_case_types, non_snake_case)]
92#[repr(C, packed(4))]
93pub struct VREvent_t {
94    pub eventType: u32,
95    pub trackedDeviceIndex: ffi::vr::TrackedDeviceIndex_t,
96    pub eventAgeSeconds: f32,
97    pub data: VREvent_Data_t,
98}
99
100pub use ffi::vr::*;
101pub use ffi::*;
102
103impl TryFrom<u32> for EVREventType {
104    type Error = ();
105    fn try_from(value: u32) -> Result<Self, Self::Error> {
106        Ok(match value {
107            0 => EVREventType::VREvent_None,
108
109            100 => EVREventType::VREvent_TrackedDeviceActivated,
110            101 => EVREventType::VREvent_TrackedDeviceDeactivated,
111            102 => EVREventType::VREvent_TrackedDeviceUpdated,
112            103 => EVREventType::VREvent_TrackedDeviceUserInteractionStarted,
113            104 => EVREventType::VREvent_TrackedDeviceUserInteractionEnded,
114            105 => EVREventType::VREvent_IpdChanged,
115            106 => EVREventType::VREvent_EnterStandbyMode,
116            107 => EVREventType::VREvent_LeaveStandbyMode,
117            108 => EVREventType::VREvent_TrackedDeviceRoleChanged,
118            109 => EVREventType::VREvent_WatchdogWakeUpRequested,
119            110 => EVREventType::VREvent_LensDistortionChanged,
120            111 => EVREventType::VREvent_PropertyChanged,
121            112 => EVREventType::VREvent_WirelessDisconnect,
122            113 => EVREventType::VREvent_WirelessReconnect,
123
124            200 => EVREventType::VREvent_ButtonPress, // data is controller
125            201 => EVREventType::VREvent_ButtonUnpress, // data is controller
126            202 => EVREventType::VREvent_ButtonTouch, // data is controller
127            203 => EVREventType::VREvent_ButtonUntouch, // data is controller
128
129            //  250 => EVREventType::VREvent_DualAnalog_Press			 // No longer sent
130            //  251 => EVREventType::VREvent_DualAnalog_Unpress		 // No longer sent
131            //  252 => EVREventType::VREvent_DualAnalog_Touch			 // No longer sent
132            //  253 => EVREventType::VREvent_DualAnalog_Untouch		 // No longer sent
133            //  254 => EVREventType::VREvent_DualAnalog_Move			 // No longer sent
134            //  255 => EVREventType::VREvent_DualAnalog_ModeSwitch1	 // No longer sent
135            //  256 => EVREventType::VREvent_DualAnalog_ModeSwitch2	 // No longer sent
136            257 => EVREventType::VREvent_Modal_Cancel, // Sent to overlays with the
137
138            300 => EVREventType::VREvent_MouseMove, // data is mouse
139            301 => EVREventType::VREvent_MouseButtonDown, // data is mouse
140            302 => EVREventType::VREvent_MouseButtonUp, // data is mouse
141            303 => EVREventType::VREvent_FocusEnter, // data is overlay
142            304 => EVREventType::VREvent_FocusLeave, // data is overlay
143            305 => EVREventType::VREvent_ScrollDiscrete, // data is scroll
144            306 => EVREventType::VREvent_TouchPadMove, // data is mouse
145            307 => EVREventType::VREvent_OverlayFocusChanged, // data is overlay, global event
146            308 => EVREventType::VREvent_ReloadOverlays,
147            309 => EVREventType::VREvent_ScrollSmooth, // data is scroll
148            310 => EVREventType::VREvent_LockMousePosition,
149            311 => EVREventType::VREvent_UnlockMousePosition,
150
151            400 => EVREventType::VREvent_InputFocusCaptured, // data is process DEPRECATED
152            401 => EVREventType::VREvent_InputFocusReleased, // data is process DEPRECATED
153            //  402 => EVREventType::VREvent_SceneFocusLost			, // data is process
154            //  403 => EVREventType::VREvent_SceneFocusGained			, // data is process
155            404 => EVREventType::VREvent_SceneApplicationChanged, // data is process - The App actually drawing the scene changed (usually to or from the compositor)
156            405 => EVREventType::VREvent_SceneFocusChanged, // data is process - New app got access to draw the scene
157            406 => EVREventType::VREvent_InputFocusChanged, // data is process
158            //  407 => EVREventType::VREvent_SceneApplicationSecondaryRenderingStarted ,
159            408 => EVREventType::VREvent_SceneApplicationUsingWrongGraphicsAdapter, // data is process
160            409 => EVREventType::VREvent_ActionBindingReloaded, // data is process - The App that action binds reloaded for
161
162            410 => EVREventType::VREvent_HideRenderModels, // Sent to the scene application to request hiding render models temporarily
163            411 => EVREventType::VREvent_ShowRenderModels, // Sent to the scene application to request restoring render model visibility
164
165            412 => EVREventType::VREvent_SceneApplicationStateChanged, // No data; but query VRApplications()->GetSceneApplicationState();
166
167            420 => EVREventType::VREvent_ConsoleOpened,
168            421 => EVREventType::VREvent_ConsoleClosed,
169
170            500 => EVREventType::VREvent_OverlayShown,
171            501 => EVREventType::VREvent_OverlayHidden,
172            502 => EVREventType::VREvent_DashboardActivated,
173            503 => EVREventType::VREvent_DashboardDeactivated,
174            // 504 => EVREventType::VREvent_DashboardThumbSelected		, // Sent to the overlay manager - data is overlay - No longer sent
175            505 => EVREventType::VREvent_DashboardRequested, // Sent to the overlay manager - data is overlay
176            506 => EVREventType::VREvent_ResetDashboard,     // Send to the overlay manager
177            // 507 => EVREventType::VREvent_RenderToast					, // Send to the dashboard to render a toast - data is the notification ID -- no longer sent
178            508 => EVREventType::VREvent_ImageLoaded, // Sent to overlays when a SetOverlayRaw or SetOverlayFromFile call finishes loading
179            509 => EVREventType::VREvent_ShowKeyboard, // Sent to keyboard renderer in the dashboard to invoke it
180            510 => EVREventType::VREvent_HideKeyboard, // Sent to keyboard renderer in the dashboard to hide it
181            511 => EVREventType::VREvent_OverlayGamepadFocusGained, // Sent to an overlay when IVROverlay::SetFocusOverlay is called on it
182            512 => EVREventType::VREvent_OverlayGamepadFocusLost, // Send to an overlay when it previously had focus and IVROverlay::SetFocusOverlay is called on something else
183            513 => EVREventType::VREvent_OverlaySharedTextureChanged,
184            // 514 => EVREventType::VREvent_DashboardGuideButtonDown	, // These are no longer sent
185            // 515 => EVREventType::VREvent_DashboardGuideButtonUp		,
186            516 => EVREventType::VREvent_ScreenshotTriggered, // Screenshot button combo was pressed, Dashboard should request a screenshot
187            517 => EVREventType::VREvent_ImageFailed, // Sent to overlays when a SetOverlayRaw or SetOverlayfromFail fails to load
188            518 => EVREventType::VREvent_DashboardOverlayCreated,
189            519 => EVREventType::VREvent_SwitchGamepadFocus,
190
191            // Screenshot API
192            520 => EVREventType::VREvent_RequestScreenshot, // Sent by vrclient application to compositor to take a screenshot
193            521 => EVREventType::VREvent_ScreenshotTaken, // Sent by compositor to the application that the screenshot has been taken
194            522 => EVREventType::VREvent_ScreenshotFailed, // Sent by compositor to the application that the screenshot failed to be taken
195            523 => EVREventType::VREvent_SubmitScreenshotToDashboard, // Sent by compositor to the dashboard that a completed screenshot was submitted
196            524 => EVREventType::VREvent_ScreenshotProgressToDashboard, // Sent by compositor to the dashboard that a completed screenshot was submitted
197
198            525 => EVREventType::VREvent_PrimaryDashboardDeviceChanged,
199            526 => EVREventType::VREvent_RoomViewShown, // Sent by compositor whenever room-view is enabled
200            527 => EVREventType::VREvent_RoomViewHidden, // Sent by compositor whenever room-view is disabled
201            528 => EVREventType::VREvent_ShowUI,         // data is showUi
202            529 => EVREventType::VREvent_ShowDevTools,   // data is showDevTools
203            530 => EVREventType::VREvent_DesktopViewUpdating,
204            531 => EVREventType::VREvent_DesktopViewReady,
205
206            532 => EVREventType::VREvent_StartDashboard,
207            533 => EVREventType::VREvent_ElevatePrism,
208
209            534 => EVREventType::VREvent_OverlayClosed,
210
211            600 => EVREventType::VREvent_Notification_Shown,
212            601 => EVREventType::VREvent_Notification_Hidden,
213            602 => EVREventType::VREvent_Notification_BeginInteraction,
214            603 => EVREventType::VREvent_Notification_Destroyed,
215
216            700 => EVREventType::VREvent_Quit, // data is process
217            701 => EVREventType::VREvent_ProcessQuit, // data is process
218            // 702 => EVREventType::VREvent_QuitAborted_UserPrompt			, // data is process
219            703 => EVREventType::VREvent_QuitAcknowledged, // data is process
220            704 => EVREventType::VREvent_DriverRequestedQuit, // The driver has requested that SteamVR shut down
221            705 => EVREventType::VREvent_RestartRequested, // A driver or other component wants the user to restart SteamVR
222            706 => EVREventType::VREvent_InvalidateSwapTextureSets,
223
224            800 => EVREventType::VREvent_ChaperoneDataHasChanged, // this will never happen with the new chaperone system
225            801 => EVREventType::VREvent_ChaperoneUniverseHasChanged,
226            802 => EVREventType::VREvent_ChaperoneTempDataHasChanged, // this will never happen with the new chaperone system
227            803 => EVREventType::VREvent_ChaperoneSettingsHaveChanged,
228            804 => EVREventType::VREvent_SeatedZeroPoseReset,
229            805 => EVREventType::VREvent_ChaperoneFlushCache, // Sent when the process needs to reload any cached data it retrieved from VRChaperone()
230            806 => EVREventType::VREvent_ChaperoneRoomSetupStarting, // Triggered by CVRChaperoneClient::RoomSetupStarting
231            807 => EVREventType::VREvent_ChaperoneRoomSetupFinished, // Triggered by CVRChaperoneClient::CommitWorkingCopy
232            808 => EVREventType::VREvent_StandingZeroPoseReset,
233
234            820 => EVREventType::VREvent_AudioSettingsHaveChanged,
235
236            850 => EVREventType::VREvent_BackgroundSettingHasChanged,
237            851 => EVREventType::VREvent_CameraSettingsHaveChanged,
238            852 => EVREventType::VREvent_ReprojectionSettingHasChanged,
239            853 => EVREventType::VREvent_ModelSkinSettingsHaveChanged,
240            854 => EVREventType::VREvent_EnvironmentSettingsHaveChanged,
241            855 => EVREventType::VREvent_PowerSettingsHaveChanged,
242            856 => EVREventType::VREvent_EnableHomeAppSettingsHaveChanged,
243            857 => EVREventType::VREvent_SteamVRSectionSettingChanged,
244            858 => EVREventType::VREvent_LighthouseSectionSettingChanged,
245            859 => EVREventType::VREvent_NullSectionSettingChanged,
246            860 => EVREventType::VREvent_UserInterfaceSectionSettingChanged,
247            861 => EVREventType::VREvent_NotificationsSectionSettingChanged,
248            862 => EVREventType::VREvent_KeyboardSectionSettingChanged,
249            863 => EVREventType::VREvent_PerfSectionSettingChanged,
250            864 => EVREventType::VREvent_DashboardSectionSettingChanged,
251            865 => EVREventType::VREvent_WebInterfaceSectionSettingChanged,
252            866 => EVREventType::VREvent_TrackersSectionSettingChanged,
253            867 => EVREventType::VREvent_LastKnownSectionSettingChanged,
254            868 => EVREventType::VREvent_DismissedWarningsSectionSettingChanged,
255            869 => EVREventType::VREvent_GpuSpeedSectionSettingChanged,
256            870 => EVREventType::VREvent_WindowsMRSectionSettingChanged,
257            871 => EVREventType::VREvent_OtherSectionSettingChanged,
258
259            900 => EVREventType::VREvent_StatusUpdate,
260
261            950 => EVREventType::VREvent_WebInterface_InstallDriverCompleted,
262
263            1000 => EVREventType::VREvent_MCImageUpdated,
264
265            1100 => EVREventType::VREvent_FirmwareUpdateStarted,
266            1101 => EVREventType::VREvent_FirmwareUpdateFinished,
267
268            1200 => EVREventType::VREvent_KeyboardClosed,
269            1201 => EVREventType::VREvent_KeyboardCharInput,
270            1202 => EVREventType::VREvent_KeyboardDone, // Sent when DONE button clicked on keyboard
271
272            // 1300 => EVREventType::VREvent_ApplicationTransitionStarted		,
273            // 1301 => EVREventType::VREvent_ApplicationTransitionAborted		,
274            // 1302 => EVREventType::VREvent_ApplicationTransitionNewAppStarted	,
275            1303 => EVREventType::VREvent_ApplicationListUpdated,
276            1304 => EVREventType::VREvent_ApplicationMimeTypeLoad,
277            //  1305 => EVREventType::VREvent_ApplicationTransitionNewAppLaunchComplete ,
278            1306 => EVREventType::VREvent_ProcessConnected,
279            1307 => EVREventType::VREvent_ProcessDisconnected,
280
281            // 1400 => EVREventType::VREvent_Compositor_MirrorWindowShown		, // DEPRECATED
282            // 1401 => EVREventType::VREvent_Compositor_MirrorWindowHidden		, // DEPRECATED
283            1410 => EVREventType::VREvent_Compositor_ChaperoneBoundsShown,
284            1411 => EVREventType::VREvent_Compositor_ChaperoneBoundsHidden,
285            1412 => EVREventType::VREvent_Compositor_DisplayDisconnected,
286            1413 => EVREventType::VREvent_Compositor_DisplayReconnected,
287            1414 => EVREventType::VREvent_Compositor_HDCPError, // data is hdcpError
288            1415 => EVREventType::VREvent_Compositor_ApplicationNotResponding,
289            1416 => EVREventType::VREvent_Compositor_ApplicationResumed,
290            1417 => EVREventType::VREvent_Compositor_OutOfVideoMemory,
291            1418 => EVREventType::VREvent_Compositor_DisplayModeNotSupported, // k_pch_SteamVR_PreferredRefreshRate
292            1419 => EVREventType::VREvent_Compositor_StageOverrideReady,
293            1420 => EVREventType::VREvent_Compositor_RequestDisconnectReconnect,
294
295            1500 => EVREventType::VREvent_TrackedCamera_StartVideoStream,
296            1501 => EVREventType::VREvent_TrackedCamera_StopVideoStream,
297            1502 => EVREventType::VREvent_TrackedCamera_PauseVideoStream,
298            1503 => EVREventType::VREvent_TrackedCamera_ResumeVideoStream,
299            1550 => EVREventType::VREvent_TrackedCamera_EditingSurface,
300
301            1600 => EVREventType::VREvent_PerformanceTest_EnableCapture,
302            1601 => EVREventType::VREvent_PerformanceTest_DisableCapture,
303            1602 => EVREventType::VREvent_PerformanceTest_FidelityLevel,
304
305            1650 => EVREventType::VREvent_MessageOverlay_Closed,
306            1651 => EVREventType::VREvent_MessageOverlayCloseRequested,
307
308            1700 => EVREventType::VREvent_Input_HapticVibration, // data is hapticVibration
309            1701 => EVREventType::VREvent_Input_BindingLoadFailed, // data is inputBinding
310            1702 => EVREventType::VREvent_Input_BindingLoadSuccessful, // data is inputBinding
311            1703 => EVREventType::VREvent_Input_ActionManifestReloaded, // no data
312            1704 => EVREventType::VREvent_Input_ActionManifestLoadFailed, // data is actionManifest
313            1705 => EVREventType::VREvent_Input_ProgressUpdate,  // data is progressUpdate
314            1706 => EVREventType::VREvent_Input_TrackerActivated,
315            1707 => EVREventType::VREvent_Input_BindingsUpdated,
316            1708 => EVREventType::VREvent_Input_BindingSubscriptionChanged,
317
318            1800 => EVREventType::VREvent_SpatialAnchors_PoseUpdated, // data is spatialAnchor. broadcast
319            1801 => EVREventType::VREvent_SpatialAnchors_DescriptorUpdated, // data is spatialAnchor. broadcast
320            1802 => EVREventType::VREvent_SpatialAnchors_RequestPoseUpdate, // data is spatialAnchor. sent to specific driver
321            1803 => EVREventType::VREvent_SpatialAnchors_RequestDescriptorUpdate, // data is spatialAnchor. sent to specific driver
322
323            1900 => EVREventType::VREvent_SystemReport_Started, // user or system initiated generation of a system report. broadcast
324
325            2000 => EVREventType::VREvent_Monitor_ShowHeadsetView, // data is process
326            2001 => EVREventType::VREvent_Monitor_HideHeadsetView, // data is process
327
328            // Vendors are free to expose private events in this reserved region
329            10000 => EVREventType::VREvent_VendorSpecific_Reserved_Start,
330            19999 => EVREventType::VREvent_VendorSpecific_Reserved_End,
331            _ => return Err(()),
332        })
333    }
334}
335
336impl EVROverlayError {
337    pub fn into_result(self) -> Result<(), Self> {
338        if self == EVROverlayError::VROverlayError_None {
339            Ok(())
340        } else {
341            Err(self)
342        }
343    }
344}
345
346impl std::fmt::Debug for EVROverlayError {
347    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
348        match self {
349            Self::VROverlayError_None => write!(f, "VROverlayError_None"),
350            Self::VROverlayError_UnknownOverlay => write!(f, "VROverlayError_UnknownOverlay"),
351            Self::VROverlayError_InvalidHandle => write!(f, "VROverlayError_InvalidHandle"),
352            Self::VROverlayError_PermissionDenied => write!(f, "VROverlayError_PermissionDenied"),
353            Self::VROverlayError_OverlayLimitExceeded => {
354                write!(f, "VROverlayError_OverlayLimitExceeded")
355            }
356            Self::VROverlayError_WrongVisibilityType => {
357                write!(f, "VROverlayError_WrongVisibilityType")
358            }
359            Self::VROverlayError_KeyTooLong => write!(f, "VROverlayError_KeyTooLong"),
360            Self::VROverlayError_NameTooLong => write!(f, "VROverlayError_NameTooLong"),
361            Self::VROverlayError_KeyInUse => write!(f, "VROverlayError_KeyInUse"),
362            Self::VROverlayError_WrongTransformType => {
363                write!(f, "VROverlayError_WrongTransformType")
364            }
365            Self::VROverlayError_InvalidTrackedDevice => {
366                write!(f, "VROverlayError_InvalidTrackedDevice")
367            }
368            Self::VROverlayError_InvalidParameter => write!(f, "VROverlayError_InvalidParameter"),
369            Self::VROverlayError_ThumbnailCantBeDestroyed => {
370                write!(f, "VROverlayError_ThumbnailCantBeDestroyed")
371            }
372            Self::VROverlayError_ArrayTooSmall => write!(f, "VROverlayError_ArrayTooSmall"),
373            Self::VROverlayError_RequestFailed => write!(f, "VROverlayError_RequestFailed"),
374            Self::VROverlayError_InvalidTexture => write!(f, "VROverlayError_InvalidTexture"),
375            Self::VROverlayError_UnableToLoadFile => write!(f, "VROverlayError_UnableToLoadFile"),
376            Self::VROverlayError_KeyboardAlreadyInUse => {
377                write!(f, "VROverlayError_KeyboardAlreadyInUse")
378            }
379            Self::VROverlayError_NoNeighbor => write!(f, "VROverlayError_NoNeighbor"),
380            Self::VROverlayError_TooManyMaskPrimitives => {
381                write!(f, "VROverlayError_TooManyMaskPrimitives")
382            }
383            Self::VROverlayError_BadMaskPrimitive => write!(f, "VROverlayError_BadMaskPrimitive"),
384            Self::VROverlayError_TextureAlreadyLocked => {
385                write!(f, "VROverlayError_TextureAlreadyLocked")
386            }
387            Self::VROverlayError_TextureLockCapacityReached => {
388                write!(f, "VROverlayError_TextureLockCapacityReached")
389            }
390            Self::VROverlayError_TextureNotLocked => write!(f, "VROverlayError_TextureNotLocked"),
391            Self::VROverlayError_TimedOut => write!(f, "VROverlayError_TimedOut"),
392        }
393    }
394}
395
396impl std::fmt::Display for EVROverlayError {
397    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
398        <Self as std::fmt::Debug>::fmt(self, f)
399    }
400}
401
402impl std::error::Error for EVROverlayError {}
403
404impl std::fmt::Debug for ETrackedPropertyError {
405    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
406        use ETrackedPropertyError::*;
407        match self {
408            TrackedProp_Success => write!(f, "TrackedProp_Success"),
409            TrackedProp_WrongDataType => write!(f, "TrackedProp_WrongDataType"),
410            TrackedProp_WrongDeviceClass => write!(f, "TrackedProp_WrongDeviceClass"),
411            TrackedProp_BufferTooSmall => write!(f, "TrackedProp_BufferTooSmall"),
412            TrackedProp_UnknownProperty => write!(f, "TrackedProp_UnknownProperty"),
413            TrackedProp_InvalidDevice => write!(f, "TrackedProp_InvalidDevice"),
414            TrackedProp_CouldNotContactServer => write!(f, "TrackedProp_CouldNotContactServer"),
415            TrackedProp_ValueNotProvidedByDevice => {
416                write!(f, "TrackedProp_ValueNotProvidedByDevice")
417            }
418            TrackedProp_StringExceedsMaximumLength => {
419                write!(f, "TrackedProp_StringExceedsMaximumLength")
420            }
421            TrackedProp_NotYetAvailable => write!(f, "TrackedProp_NotYetAvailable"),
422            TrackedProp_PermissionDenied => write!(f, "TrackedProp_PermissionDenied"),
423            TrackedProp_InvalidOperation => write!(f, "TrackedProp_InvalidOperation"),
424            TrackedProp_CannotWriteToWildcards => write!(f, "TrackedProp_CannotWriteToWildcards"),
425            TrackedProp_IPCReadFailure => write!(f, "TrackedProp_IPCReadFailure"),
426            TrackedProp_OutOfMemory => write!(f, "TrackedProp_OutOfMemory"),
427            TrackedProp_InvalidContainer => write!(f, "TrackedProp_InvalidContainer"),
428        }
429    }
430}
431
432impl std::fmt::Display for ETrackedPropertyError {
433    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
434        <Self as std::fmt::Debug>::fmt(self, f)
435    }
436}
437
438impl ETrackedPropertyError {
439    pub fn into_result(self) -> Result<(), Self> {
440        if self == ETrackedPropertyError::TrackedProp_Success {
441            Ok(())
442        } else {
443            Err(self)
444        }
445    }
446}
447
448impl std::error::Error for ETrackedPropertyError {}
449
450impl std::fmt::Debug for EVRInputError {
451    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
452        use EVRInputError::*;
453        match self {
454            VRInputError_None => write!(f, "VRInputError_None"),
455            VRInputError_NameNotFound => write!(f, "VRInputError_NameNotFound"),
456            VRInputError_WrongType => write!(f, "VRInputError_WrongType"),
457            VRInputError_InvalidHandle => write!(f, "VRInputError_InvalidHandle"),
458            VRInputError_InvalidParam => write!(f, "VRInputError_InvalidParam"),
459            VRInputError_NoSteam => write!(f, "VRInputError_NoSteam"),
460            VRInputError_MaxCapacityReached => write!(f, "VRInputError_MaxCapacityReached"),
461            VRInputError_IPCError => write!(f, "VRInputError_IPCError"),
462            VRInputError_NoActiveActionSet => write!(f, "VRInputError_NoActiveActionSet"),
463            VRInputError_InvalidDevice => write!(f, "VRInputError_InvalidDevice"),
464            VRInputError_InvalidSkeleton => write!(f, "VRInputError_InvalidSkeleton"),
465            VRInputError_InvalidBoneCount => write!(f, "VRInputError_InvalidBoneCount"),
466            VRInputError_InvalidCompressedData => write!(f, "VRInputError_InvalidCompressedData"),
467            VRInputError_NoData => write!(f, "VRInputError_NoData"),
468            VRInputError_BufferTooSmall => write!(f, "VRInputError_BufferTooSmall"),
469            VRInputError_MismatchedActionManifest => {
470                write!(f, "VRInputError_MismatchedActionManifest")
471            }
472            VRInputError_MissingSkeletonData => write!(f, "VRInputError_MissingSkeletonData"),
473            VRInputError_InvalidBoneIndex => write!(f, "VRInputError_InvalidBoneIndex"),
474            VRInputError_InvalidPriority => write!(f, "VRInputError_InvalidPriority"),
475            VRInputError_PermissionDenied => write!(f, "VRInputError_PermissionDenied"),
476            VRInputError_InvalidRenderModel => write!(f, "VRInputError_InvalidRenderModel"),
477        }
478    }
479}
480
481impl std::fmt::Display for EVRInputError {
482    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
483        <Self as std::fmt::Debug>::fmt(self, f)
484    }
485}
486
487impl std::error::Error for EVRInputError {}
488
489impl EVRInputError {
490    pub fn into_result(self) -> Result<(), Self> {
491        if self == EVRInputError::VRInputError_None {
492            Ok(())
493        } else {
494            Err(self)
495        }
496    }
497}
498
499impl EVRInitError {
500    pub fn into_result(self) -> Result<(), Self> {
501        if self == EVRInitError::VRInitError_None {
502            Ok(())
503        } else {
504            Err(self)
505        }
506    }
507}
508
509impl std::fmt::Debug for EVRInitError {
510    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
511        match self {
512            _ => write!(f, "VRInitError_Unknown"),
513        }
514    }
515}
516
517impl std::fmt::Display for EVRInitError {
518    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
519        <Self as std::fmt::Debug>::fmt(self, f)
520    }
521}
522
523impl std::error::Error for EVRInitError {}
524
525impl<T: num::NumCast + num::Float + num::Zero + num::One + nalgebra::Scalar> From<&'_ HmdMatrix34_t>
526    for nalgebra::Matrix4<T>
527{
528    fn from(m: &HmdMatrix34_t) -> nalgebra::Matrix4<T> {
529        // Note: [[float; 4]; 4] -> Matrix is column major
530        let mut tmp = [[T::nan(); 4]; 4];
531        for i in 0..3 {
532            for j in 0..4 {
533                tmp[j][i] = T::from(m.m[i][j]).unwrap();
534            }
535        }
536        for i in 0..3 {
537            tmp[i][3] = T::zero();
538        }
539        tmp[3][3] = T::one();
540        tmp.into()
541    }
542}
543
544impl<T: num::NumCast + num::Float + num::Zero + num::One + nalgebra::Scalar> From<HmdMatrix34_t>
545    for nalgebra::Matrix4<T>
546{
547    fn from(m: HmdMatrix34_t) -> nalgebra::Matrix4<T> {
548        Self::from(&m)
549    }
550}
551
552impl<T: num::ToPrimitive> From<&'_ nalgebra::Matrix4<T>> for HmdMatrix34_t {
553    fn from(m: &nalgebra::Matrix4<T>) -> Self {
554        let mut ret = unsafe { std::mem::MaybeUninit::<Self>::zeroed().assume_init() };
555        for i in 0..3 {
556            for j in 0..4 {
557                ret.m[i][j] = m[(i, j)].to_f32().unwrap();
558            }
559        }
560        ret
561    }
562}