Monado OpenXR Runtime
monado.h
Go to the documentation of this file.
1// Copyright 2019-2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Interface of libmonado
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
8 */
9
10#include <stdint.h>
11#include <stdbool.h>
12
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18
19/*
20 *
21 * Enums, defines and objects.
22 *
23 */
24
25//! Major version of the API.
26#define MND_API_VERSION_MAJOR 1
27//! Minor version of the API.
28#define MND_API_VERSION_MINOR 4
29//! Patch version of the API.
30#define MND_API_VERSION_PATCH 0
31
32/*!
33 * Result codes for operations, negative are errors, zero or positives are
34 * success.
35 */
36typedef enum mnd_result
37{
38 MND_SUCCESS = 0,
39 MND_ERROR_INVALID_VERSION = -1,
40 MND_ERROR_INVALID_VALUE = -2,
41 MND_ERROR_CONNECTING_FAILED = -3,
42 MND_ERROR_OPERATION_FAILED = -4,
43 //! Supported in version 1.1 and above.
45 //! Supported in version 1.2 and above.
47 //! Supported in version 1.3 and above.
50
51/*!
52 * Bitflags for client application state.
53 */
54typedef enum mnd_client_flags
55{
56 MND_CLIENT_PRIMARY_APP = (1u << 0u),
57 MND_CLIENT_SESSION_ACTIVE = (1u << 1u),
58 MND_CLIENT_SESSION_VISIBLE = (1u << 2u),
59 MND_CLIENT_SESSION_FOCUSED = (1u << 3u),
60 MND_CLIENT_SESSION_OVERLAY = (1u << 4u),
61 MND_CLIENT_IO_ACTIVE = (1u << 5u),
63
64/*!
65 * A property to get from a thing (currently only devices).
66 *
67 * Supported in version 1.2 and above.
68 */
69typedef enum mnd_property
70{
71 //! Supported in version 1.2 and above.
73 //! Supported in version 1.2 and above.
75 //! Supported in version 1.4.0 and above.
77 //! Supported in version 1.4.0 and above.
79 //! Supported in version 1.4.0 and above.
82
83/*!
84 * Opaque type for libmonado state
85 */
86typedef struct mnd_root mnd_root_t;
87
88/*!
89 * A pose composed of a position and orientation.
90 */
91typedef struct mnd_pose
92{
93 struct
94 {
95 float x, y, z, w;
96 } orientation;
97 struct
98 {
99 float x, y, z;
100 } position;
102
103/*!
104 * Types of reference space.
105 */
107{
108 MND_SPACE_REFERENCE_TYPE_VIEW,
109 MND_SPACE_REFERENCE_TYPE_LOCAL,
110 MND_SPACE_REFERENCE_TYPE_LOCAL_FLOOR,
111 MND_SPACE_REFERENCE_TYPE_STAGE,
112 MND_SPACE_REFERENCE_TYPE_UNBOUNDED,
114
115/*
116 *
117 * Functions
118 *
119 */
120
121/*!
122 * Returns the version of the API (not Monado itself), follows the versioning
123 * semantics of https://semver.org/ standard. In short if the major version
124 * mismatch then the interface is incompatible.
125 *
126 * @param[out] out_major Major version number, must be valid pointer.
127 * @param[out] out_minor Minor version number, must be valid pointer.
128 * @param[out] out_patch Patch version number, must be valid pointer.
129 *
130 * Always succeeds, or crashes if any pointer isn't valid.
131 */
132void
133mnd_api_get_version(uint32_t *out_major, uint32_t *out_minor, uint32_t *out_patch);
134
135/*!
136 * Create libmonado state and connect to service
137 *
138 * @param[out] out_root Address to populate with the opaque state type.
139 * @return MND_SUCCESS on success
140 */
142mnd_root_create(mnd_root_t **out_root);
143
144/*!
145 * Destroy libmonado state, disconnecting from the service, and zeroing the
146 * pointer.
147 *
148 * @param root_ptr Pointer to your libmonado state. Null-checked, will be set to null.
149 */
150void
151mnd_root_destroy(mnd_root_t **root_ptr);
152
153/*!
154 * Update our local cached copy of the client list
155 *
156 * @param root The libmonado state.
157 * @return MND_SUCCESS on success
158 */
161
162/*!
163 * Get the number of active clients
164 *
165 * This value only changes on calls to @ref mnd_root_update_client_list
166 *
167 * @param root The libmonado state.
168 * @param[out] out_num Pointer to value to populate with the number of clients.
169 *
170 * @pre Called @ref mnd_root_update_client_list at least once
171 *
172 * @return MND_SUCCESS on success
173 */
175mnd_root_get_number_clients(mnd_root_t *root, uint32_t *out_num);
176
177/*!
178 * Get the id from the current client list.
179 *
180 * @param root The libmonado state.
181 * @param index Index to retrieve id for.
182 * @param[out] out_client_id Pointer to value to populate with the id at the given index.
183 */
185mnd_root_get_client_id_at_index(mnd_root_t *root, uint32_t index, uint32_t *out_client_id);
186
187/*!
188 * Get the name of the client at the given index.
189 *
190 * The string returned is only valid until the next call into libmonado.
191 *
192 * @param root The libmonado state.
193 * @param client_id ID of client to retrieve name from.
194 * @param[out] out_name Pointer to populate with the client name.
195 *
196 * @pre Called @ref mnd_root_update_client_list at least once
197 *
198 * @return MND_SUCCESS on success
199 */
201mnd_root_get_client_name(mnd_root_t *root, uint32_t client_id, const char **out_name);
202
203/*!
204 * Get the state flags of the client at the given index.
205 *
206 * This result only changes on calls to @ref mnd_root_update_client_list
207 *
208 * @param root The libmonado state.
209 * @param client_id ID of client to retrieve flags from.
210 * @param[out] out_flags Pointer to populate with the flags, a bitwise combination of @ref mnd_client_flags.
211 *
212 * @pre Called @ref mnd_root_update_client_list at least once
213 *
214 * @return MND_SUCCESS on success
215 */
217mnd_root_get_client_state(mnd_root_t *root, uint32_t client_id, uint32_t *out_flags);
218
219/*!
220 * Set the client at the given index as "primary".
221 *
222 * @param root The libmonado state.
223 * @param client_id ID of the client set as primary.
224 *
225 * @pre Called @ref mnd_root_update_client_list at least once
226 *
227 * @return MND_SUCCESS on success
228 */
230mnd_root_set_client_primary(mnd_root_t *root, uint32_t client_id);
231
232/*!
233 * Set the client at the given index as "focused".
234 *
235 * @param root The libmonado state.
236 * @param client_id ID of the client set as focused.
237 *
238 * @pre Called @ref mnd_root_update_client_list at least once
239 *
240 * @return MND_SUCCESS on success
241 */
243mnd_root_set_client_focused(mnd_root_t *root, uint32_t client_id);
244
245/*!
246 * Toggle io activity for the client at the given index.
247 *
248 * @param root The libmonado state.
249 * @param client_id ID of the client to toggle IO for.
250 *
251 * @pre Called @ref mnd_root_update_client_list at least once
252 *
253 * @return MND_SUCCESS on success
254 */
256mnd_root_toggle_client_io_active(mnd_root_t *root, uint32_t client_id);
257
258/*!
259 * Get the number of devices
260 *
261 * @param root The libmonado state.
262 * @param[out] out_device_count Pointer to value to populate with the number of devices.
263 *
264 * @return MND_SUCCESS on success
265 */
267mnd_root_get_device_count(mnd_root_t *root, uint32_t *out_device_count);
268
269/*!
270 * Get boolean property for the device at the given index.
271 *
272 * Supported in version 1.2 and above.
273 *
274 * @param root The libmonado state.
275 * @param device_index Index of device to retrieve name from.
276 * @param prop A boolean property enum.
277 * @param[out] out_bool Pointer to populate with the boolean.
278 *
279 * @return MND_SUCCESS on success
280 */
282mnd_root_get_device_info_bool(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, bool *out_bool);
283
284/*!
285 * Get int32_t property for the device at the given index.
286 *
287 * Supported in version 1.2 and above.
288 *
289 * @param root The libmonado state.
290 * @param device_index Index of device to retrieve name from.
291 * @param prop A int32_t property enum.
292 * @param[out] out_i32 Pointer to populate with the int32_t.
293 *
294 * @return MND_SUCCESS on success
295 */
297mnd_root_get_device_info_i32(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, uint32_t *out_i32);
298
299/*!
300 * Get uint32_t property for the device at the given index.
301 *
302 * Supported in version 1.2 and above.
303 *
304 * @param root The libmonado state.
305 * @param device_index Index of device to retrieve name from.
306 * @param prop A uint32_t property enum.
307 * @param[out] out_u32 Pointer to populate with the uint32_t.
308 *
309 * @return MND_SUCCESS on success
310 */
312mnd_root_get_device_info_u32(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, uint32_t *out_u32);
313
314/*!
315 * Get float property for the device at the given index.
316 *
317 * Supported in version 1.2 and above.
318 *
319 * @param root The libmonado state.
320 * @param device_index Index of device to retrieve name from.
321 * @param prop A float property enum.
322 * @param[out] out_float Pointer to populate with the float.
323 *
324 * @return MND_SUCCESS on success
325 */
327mnd_root_get_device_info_float(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, float *out_float);
328
329/*!
330 * Get string property for the device at the given index.
331 *
332 * Supported in version 1.2 and above.
333 *
334 * @param root The libmonado state.
335 * @param device_index Index of device to retrieve name from.
336 * @param prop A string property enum.
337 * @param[out] out_string Pointer to populate with the string.
338 *
339 * @return MND_SUCCESS on success
340 */
342mnd_root_get_device_info_string(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, const char **out_string);
343
344/*!
345 * Get device info at the given index.
346 *
347 * @deprecated Deprecated in version 1.2, scheduled for removal in version 2.0.0 currently.
348 *
349 * @param root The libmonado state.
350 * @param device_index Index of device to retrieve name from.
351 * @param[out] out_device_id Pointer to value to populate with the device id at the given index.
352 * @param[out] out_dev_name Pointer to populate with the device name.
353 *
354 * @return MND_SUCCESS on success
355 */
357mnd_root_get_device_info(mnd_root_t *root, uint32_t device_index, uint32_t *out_device_id, const char **out_dev_name);
358
359/*!
360 * Get the device index associated for a given role name.
361 *
362 * @param root The libmonado state.
363 * @param role_name Name of the role, one-of: "head", "left", "right",
364 * "gamepad", "eyes", "hand-tracking-left", and,
365 * "hand-tracking-right":
366 * @param[out] out_index Pointer to value to populate with the device index
367 * associated with given role name, -1 if not role is set.
368 *
369 * @return MND_SUCCESS on success
370 */
372mnd_root_get_device_from_role(mnd_root_t *root, const char *role_name, int32_t *out_index);
373
374/*!
375 * Trigger a recenter of the local spaces.
376 *
377 * Supported in version 1.1 and above.
378 *
379 * @param root The libmonado state.
380 *
381 * @return MND_SUCCESS on success
382 */
385
386/*!
387 * Get the current offset value of the specified reference space.
388 *
389 * Supported in version 1.3 and above.
390 *
391 * @param root The libmonado state.
392 * @param type The reference space.
393 * @param offset A pointer to where the offset should be written.
394 *
395 * @return MND_SUCCESS on success
396 */
399
400/*!
401 * Apply an offset to the specified reference space.
402 *
403 * Supported in version 1.3 and above.
404 *
405 * @param root The libmonado state.
406 * @param type The reference space.
407 * @param offset A pointer to valid xrt_pose.
408 *
409 * @return MND_SUCCESS on success
410 */
413
414/*!
415 * Read the current offset of a tracking origin.
416 *
417 * Supported in version 1.3 and above.
418 *
419 * @param root The libmonado state.
420 * @param origin_id The ID of the tracking origin.
421 * @param offset A pointer to where the offset should be written.
422 *
423 * @return MND_SUCCESS on success
424 */
426mnd_root_get_tracking_origin_offset(mnd_root_t *root, uint32_t origin_id, mnd_pose_t *out_offset);
427
428/*!
429 * Apply an offset to the specified tracking origin.
430 *
431 * Supported in version 1.3 and above.
432 *
433 * @param root The libmonado state.
434 * @param origin_id The ID of the tracking origin.
435 * @param offset A pointer to valid xrt_pose.
436 *
437 * @return MND_SUCCESS on success
438 */
440mnd_root_set_tracking_origin_offset(mnd_root_t *root, uint32_t origin_id, const mnd_pose_t *offset);
441
442/*!
443 * Retrieve the number of tracking origins available.
444 *
445 * Supported in version 1.3 and above.
446 *
447 * @param root The libmonado state.
448 * @param out_track_count Pointer to where the count should be written.
449 *
450 * @return MND_SUCCESS on success
451 */
453mnd_root_get_tracking_origin_count(mnd_root_t *root, uint32_t *out_track_count);
454
455/*!
456 * Retrieve the name of the indicated tracking origin.
457 *
458 * Supported in version 1.3 and above.
459 *
460 * @param root The libmonado state.
461 * @param origin_id The ID of a tracking origin.
462 * @param out_string The pointer to write the name's pointer to.
463 *
464 * @return MND_SUCCESS on success
465 */
467mnd_root_get_tracking_origin_name(mnd_root_t *root, uint32_t origin_id, const char **out_string);
468
469/*!
470 * Get battery status of a device.
471 *
472 * @param root The libmonado state.
473 * @param device_index Index of device to retrieve battery info from.
474 * @param[out] out_present Pointer to value to populate with whether the device provides battery status info.
475 * @param[out] out_charging Pointer to value to populate with whether the device is currently being charged.
476 * @param[out] out_charge Pointer to value to populate with the battery charge as a value between 0 and 1.
477 *
478 * @return MND_SUCCESS on success
479 */
482 mnd_root_t *root, uint32_t device_index, bool *out_present, bool *out_charging, float *out_charge);
483
484#ifdef __cplusplus
485}
486#endif
mnd_result_t mnd_root_set_tracking_origin_offset(mnd_root_t *root, uint32_t origin_id, const mnd_pose_t *offset)
Apply an offset to the specified tracking origin.
Definition: monado.c:520
mnd_result_t mnd_root_create(mnd_root_t **out_root)
Create libmonado state and connect to service.
Definition: monado.c:124
mnd_result_t mnd_root_get_device_info_bool(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, bool *out_bool)
Get boolean property for the device at the given index.
Definition: monado.c:299
mnd_result_t mnd_root_get_device_info_string(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, const char **out_string)
Get string property for the device at the given index.
Definition: monado.c:374
mnd_result
Result codes for operations, negative are errors, zero or positives are success.
Definition: monado.h:37
@ MND_ERROR_INVALID_PROPERTY
Supported in version 1.2 and above.
Definition: monado.h:46
@ MND_ERROR_INVALID_OPERATION
Supported in version 1.3 and above.
Definition: monado.h:48
@ MND_ERROR_RECENTERING_NOT_SUPPORTED
Supported in version 1.1 and above.
Definition: monado.h:44
mnd_result_t mnd_root_get_tracking_origin_offset(mnd_root_t *root, uint32_t origin_id, mnd_pose_t *out_offset)
Read the current offset of a tracking origin.
Definition: monado.c:507
void mnd_api_get_version(uint32_t *out_major, uint32_t *out_minor, uint32_t *out_patch)
Returns the version of the API (not Monado itself), follows the versioning semantics of https://semve...
Definition: monado.c:109
enum mnd_result mnd_result_t
Result codes for operations, negative are errors, zero or positives are success.
mnd_result_t mnd_root_get_client_state(mnd_root_t *root, uint32_t client_id, uint32_t *out_flags)
Get the state flags of the client at the given index.
Definition: monado.c:219
mnd_result_t mnd_root_get_reference_space_offset(mnd_root_t *root, mnd_reference_space_type_t type, mnd_pose_t *out_offset)
Get the current offset value of the specified reference space.
Definition: monado.c:480
mnd_property
A property to get from a thing (currently only devices).
Definition: monado.h:70
@ MND_PROPERTY_SUPPORTS_POSITION_BOOL
Supported in version 1.4.0 and above.
Definition: monado.h:78
@ MND_PROPERTY_NAME_STRING
Supported in version 1.2 and above.
Definition: monado.h:72
@ MND_PROPERTY_SUPPORTS_ORIENTATION_BOOL
Supported in version 1.4.0 and above.
Definition: monado.h:80
@ MND_PROPERTY_TRACKING_ORIGIN_U32
Supported in version 1.4.0 and above.
Definition: monado.h:76
@ MND_PROPERTY_SERIAL_STRING
Supported in version 1.2 and above.
Definition: monado.h:74
void mnd_root_destroy(mnd_root_t **root_ptr)
Destroy libmonado state, disconnecting from the service, and zeroing the pointer.
Definition: monado.c:146
mnd_result_t mnd_root_get_client_name(mnd_root_t *root, uint32_t client_id, const char **out_name)
Get the name of the client at the given index.
Definition: monado.c:202
mnd_result_t mnd_root_get_device_battery_status(mnd_root_t *root, uint32_t device_index, bool *out_present, bool *out_charging, float *out_charge)
Get battery status of a device.
Definition: monado.c:562
mnd_result_t mnd_root_recenter_local_spaces(mnd_root_t *root)
Trigger a recenter of the local spaces.
Definition: monado.c:468
mnd_result_t mnd_root_get_device_from_role(mnd_root_t *root, const char *role_name, int32_t *out_index)
Get the device index associated for a given role name.
Definition: monado.c:415
struct mnd_pose mnd_pose_t
A pose composed of a position and orientation.
mnd_reference_space_type
Types of reference space.
Definition: monado.h:107
mnd_result_t mnd_root_get_device_info_i32(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, uint32_t *out_i32)
Get int32_t property for the device at the given index.
Definition: monado.c:321
mnd_result_t mnd_root_update_client_list(mnd_root_t *root)
Update our local cached copy of the client list.
Definition: monado.c:166
mnd_result_t mnd_root_set_reference_space_offset(mnd_root_t *root, mnd_reference_space_type_t type, const mnd_pose_t *offset)
Apply an offset to the specified reference space.
Definition: monado.c:493
mnd_result_t mnd_root_get_tracking_origin_name(mnd_root_t *root, uint32_t origin_id, const char **out_string)
Retrieve the name of the indicated tracking origin.
Definition: monado.c:544
mnd_result_t mnd_root_get_client_id_at_index(mnd_root_t *root, uint32_t index, uint32_t *out_client_id)
Get the id from the current client list.
Definition: monado.c:191
mnd_result_t mnd_root_set_client_focused(mnd_root_t *root, uint32_t client_id)
Set the client at the given index as "focused".
Definition: monado.c:258
enum mnd_client_flags mnd_client_flags_t
Bitflags for client application state.
mnd_result_t mnd_root_toggle_client_io_active(mnd_root_t *root, uint32_t client_id)
Toggle io activity for the client at the given index.
Definition: monado.c:273
enum mnd_reference_space_type mnd_reference_space_type_t
Types of reference space.
mnd_client_flags
Bitflags for client application state.
Definition: monado.h:55
mnd_result_t mnd_root_get_device_count(mnd_root_t *root, uint32_t *out_device_count)
Get the number of devices.
Definition: monado.c:288
mnd_result_t mnd_root_get_device_info(mnd_root_t *root, uint32_t device_index, uint32_t *out_device_id, const char **out_dev_name)
Get device info at the given index.
Definition: monado.c:396
mnd_result_t mnd_root_set_client_primary(mnd_root_t *root, uint32_t client_id)
Set the client at the given index as "primary".
Definition: monado.c:243
enum mnd_property mnd_property_t
A property to get from a thing (currently only devices).
mnd_result_t mnd_root_get_device_info_u32(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, uint32_t *out_u32)
Get uint32_t property for the device at the given index.
Definition: monado.c:337
mnd_result_t mnd_root_get_number_clients(mnd_root_t *root, uint32_t *out_num)
Get the number of active clients.
Definition: monado.c:180
mnd_result_t mnd_root_get_device_info_float(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, float *out_float)
Get float property for the device at the given index.
Definition: monado.c:358
mnd_result_t mnd_root_get_tracking_origin_count(mnd_root_t *root, uint32_t *out_track_count)
Retrieve the number of tracking origins available.
Definition: monado.c:533
A pose composed of a position and orientation.
Definition: monado.h:92
Definition: monado.c:32