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 5
29//! Patch version of the API.
30#define MND_API_VERSION_PATCH 1
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.
49 //! Supported in version 1.5 and above.
52
53/*!
54 * Bitflags for client application state.
55 */
56typedef enum mnd_client_flags
57{
58 MND_CLIENT_PRIMARY_APP = (1u << 0u),
59 MND_CLIENT_SESSION_ACTIVE = (1u << 1u),
60 MND_CLIENT_SESSION_VISIBLE = (1u << 2u),
61 MND_CLIENT_SESSION_FOCUSED = (1u << 3u),
62 MND_CLIENT_SESSION_OVERLAY = (1u << 4u),
63 MND_CLIENT_IO_ACTIVE = (1u << 5u),
65
66/*!
67 * A property to get from a thing (currently only devices).
68 *
69 * Supported in version 1.2 and above.
70 */
71typedef enum mnd_property
72{
73 //! Supported in version 1.2 and above.
75 //! Supported in version 1.2 and above.
77 //! Supported in version 1.4.0 and above.
79 //! Supported in version 1.4.0 and above.
81 //! Supported in version 1.4.0 and above.
83 //! Supported in version 1.5.0 and above.
86
87/*!
88 * Opaque type for libmonado state
89 */
90typedef struct mnd_root mnd_root_t;
91
92/*!
93 * A pose composed of a position and orientation.
94 */
95typedef struct mnd_pose
96{
97 struct
98 {
99 float x, y, z, w;
100 } orientation;
101 struct
102 {
103 float x, y, z;
104 } position;
106
107/*!
108 * Types of reference space.
109 */
111{
112 MND_SPACE_REFERENCE_TYPE_VIEW,
113 MND_SPACE_REFERENCE_TYPE_LOCAL,
114 MND_SPACE_REFERENCE_TYPE_LOCAL_FLOOR,
115 MND_SPACE_REFERENCE_TYPE_STAGE,
116 MND_SPACE_REFERENCE_TYPE_UNBOUNDED,
118
119/*
120 *
121 * Functions
122 *
123 */
124
125/*!
126 * Returns the version of the API (not Monado itself), follows the versioning
127 * semantics of https://semver.org/ standard. In short if the major version
128 * mismatch then the interface is incompatible.
129 *
130 * @param[out] out_major Major version number, must be valid pointer.
131 * @param[out] out_minor Minor version number, must be valid pointer.
132 * @param[out] out_patch Patch version number, must be valid pointer.
133 *
134 * Always succeeds, or crashes if any pointer isn't valid.
135 */
136void
137mnd_api_get_version(uint32_t *out_major, uint32_t *out_minor, uint32_t *out_patch);
138
139/*!
140 * Create libmonado state and connect to service
141 *
142 * @param[out] out_root Address to populate with the opaque state type.
143 * @return MND_SUCCESS on success
144 */
146mnd_root_create(mnd_root_t **out_root);
147
148/*!
149 * Destroy libmonado state, disconnecting from the service, and zeroing the
150 * pointer.
151 *
152 * @param root_ptr Pointer to your libmonado state. Null-checked, will be set to null.
153 */
154void
155mnd_root_destroy(mnd_root_t **root_ptr);
156
157/*!
158 * Update our local cached copy of the client list
159 *
160 * @param root The libmonado state.
161 * @return MND_SUCCESS on success
162 */
165
166/*!
167 * Get the number of active clients
168 *
169 * This value only changes on calls to @ref mnd_root_update_client_list
170 *
171 * @param root The libmonado state.
172 * @param[out] out_num Pointer to value to populate with the number of clients.
173 *
174 * @pre Called @ref mnd_root_update_client_list at least once
175 *
176 * @return MND_SUCCESS on success
177 */
179mnd_root_get_number_clients(mnd_root_t *root, uint32_t *out_num);
180
181/*!
182 * Get the id from the current client list.
183 *
184 * @param root The libmonado state.
185 * @param index Index to retrieve id for.
186 * @param[out] out_client_id Pointer to value to populate with the id at the given index.
187 */
189mnd_root_get_client_id_at_index(mnd_root_t *root, uint32_t index, uint32_t *out_client_id);
190
191/*!
192 * Get the name of the client at the given index.
193 *
194 * The string returned is only valid until the next call into libmonado.
195 *
196 * @param root The libmonado state.
197 * @param client_id ID of client to retrieve name from.
198 * @param[out] out_name Pointer to populate with the client name.
199 *
200 * @pre Called @ref mnd_root_update_client_list at least once
201 *
202 * @return MND_SUCCESS on success
203 */
205mnd_root_get_client_name(mnd_root_t *root, uint32_t client_id, const char **out_name);
206
207/*!
208 * Get the state flags of the client at the given index.
209 *
210 * This result only changes on calls to @ref mnd_root_update_client_list
211 *
212 * @param root The libmonado state.
213 * @param client_id ID of client to retrieve flags from.
214 * @param[out] out_flags Pointer to populate with the flags, a bitwise combination of @ref mnd_client_flags.
215 *
216 * @pre Called @ref mnd_root_update_client_list at least once
217 *
218 * @return MND_SUCCESS on success
219 */
221mnd_root_get_client_state(mnd_root_t *root, uint32_t client_id, uint32_t *out_flags);
222
223/*!
224 * Set the client at the given index as "primary".
225 *
226 * @param root The libmonado state.
227 * @param client_id ID of the client set as primary.
228 *
229 * @pre Called @ref mnd_root_update_client_list at least once
230 *
231 * @return MND_SUCCESS on success
232 */
234mnd_root_set_client_primary(mnd_root_t *root, uint32_t client_id);
235
236/*!
237 * Set the client at the given index as "focused".
238 *
239 * @param root The libmonado state.
240 * @param client_id ID of the client set as focused.
241 *
242 * @pre Called @ref mnd_root_update_client_list at least once
243 *
244 * @return MND_SUCCESS on success
245 */
247mnd_root_set_client_focused(mnd_root_t *root, uint32_t client_id);
248
249/*!
250 * Toggle io activity for the client at the given index.
251 *
252 * @param root The libmonado state.
253 * @param client_id ID of the client to toggle IO for.
254 *
255 * @pre Called @ref mnd_root_update_client_list at least once
256 *
257 * @return MND_SUCCESS on success
258 */
260mnd_root_toggle_client_io_active(mnd_root_t *root, uint32_t client_id);
261
262/*!
263 * Get the number of devices
264 *
265 * @param root The libmonado state.
266 * @param[out] out_device_count Pointer to value to populate with the number of devices.
267 *
268 * @return MND_SUCCESS on success
269 */
271mnd_root_get_device_count(mnd_root_t *root, uint32_t *out_device_count);
272
273/*!
274 * Get boolean property for the device at the given index.
275 *
276 * Supported in version 1.2 and above.
277 *
278 * @param root The libmonado state.
279 * @param device_index Index of device to retrieve name from.
280 * @param prop A boolean property enum.
281 * @param[out] out_bool Pointer to populate with the boolean.
282 *
283 * @return MND_SUCCESS on success
284 */
286mnd_root_get_device_info_bool(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, bool *out_bool);
287
288/*!
289 * Get int32_t property for the device at the given index.
290 *
291 * Supported in version 1.2 and above.
292 *
293 * @param root The libmonado state.
294 * @param device_index Index of device to retrieve name from.
295 * @param prop A int32_t property enum.
296 * @param[out] out_i32 Pointer to populate with the int32_t.
297 *
298 * @return MND_SUCCESS on success
299 */
301mnd_root_get_device_info_i32(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, uint32_t *out_i32);
302
303/*!
304 * Get uint32_t property for the device at the given index.
305 *
306 * Supported in version 1.2 and above.
307 *
308 * @param root The libmonado state.
309 * @param device_index Index of device to retrieve name from.
310 * @param prop A uint32_t property enum.
311 * @param[out] out_u32 Pointer to populate with the uint32_t.
312 *
313 * @return MND_SUCCESS on success
314 */
316mnd_root_get_device_info_u32(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, uint32_t *out_u32);
317
318/*!
319 * Get float property for the device at the given index.
320 *
321 * Supported in version 1.2 and above.
322 *
323 * @param root The libmonado state.
324 * @param device_index Index of device to retrieve name from.
325 * @param prop A float property enum.
326 * @param[out] out_float Pointer to populate with the float.
327 *
328 * @return MND_SUCCESS on success
329 */
331mnd_root_get_device_info_float(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, float *out_float);
332
333/*!
334 * Get string property for the device at the given index.
335 *
336 * Supported in version 1.2 and above.
337 *
338 * @param root The libmonado state.
339 * @param device_index Index of device to retrieve name from.
340 * @param prop A string property enum.
341 * @param[out] out_string Pointer to populate with the string.
342 *
343 * @return MND_SUCCESS on success
344 */
346mnd_root_get_device_info_string(mnd_root_t *root, uint32_t device_index, mnd_property_t prop, const char **out_string);
347
348/*!
349 * Get device info at the given index.
350 *
351 * @deprecated Deprecated in version 1.2, scheduled for removal in version 2.0.0 currently.
352 *
353 * @param root The libmonado state.
354 * @param device_index Index of device to retrieve name from.
355 * @param[out] out_device_id Pointer to value to populate with the device id at the given index.
356 * @param[out] out_dev_name Pointer to populate with the device name.
357 *
358 * @return MND_SUCCESS on success
359 */
361mnd_root_get_device_info(mnd_root_t *root, uint32_t device_index, uint32_t *out_device_id, const char **out_dev_name);
362
363/*!
364 * Get the device index associated for a given role name.
365 *
366 *
367 * @param root The libmonado state.
368 * @param role_name Name of the role. Possible values are:
369 * - "head"
370 * - "left"
371 * - "right"
372 * - "gamepad"
373 * - "eyes"
374 * - "hand-tracking-unobstructed-[left|right]"
375 * - "hand-tracking-conforming-[left|right]"
376 *
377 * **DEPRECATED**: The role names "hand-tracking-[left|right]"
378 * are deprecated as of v1.5. They now map to
379 * "hand-tracking-unobstructed-[left|right]" and are
380 * scheduled for removal in v2.0.
381 *
382 * @param[out] out_index Pointer to value to populate with the device index
383 * associated with given role name, -1 if not role is set.
384 *
385 * @return MND_SUCCESS on success
386 */
388mnd_root_get_device_from_role(mnd_root_t *root, const char *role_name, int32_t *out_index);
389
390/*!
391 * Trigger a recenter of the local spaces.
392 *
393 * Supported in version 1.1 and above.
394 *
395 * @param root The libmonado state.
396 *
397 * @return MND_SUCCESS on success
398 */
401
402/*!
403 * Get the current offset value of the specified reference space.
404 *
405 * Supported in version 1.3 and above.
406 *
407 * @param root The libmonado state.
408 * @param type The reference space.
409 * @param offset A pointer to where the offset should be written.
410 *
411 * @return MND_SUCCESS on success
412 */
415
416/*!
417 * Apply an offset to the specified reference space.
418 *
419 * Supported in version 1.3 and above.
420 *
421 * @param root The libmonado state.
422 * @param type The reference space.
423 * @param offset A pointer to valid xrt_pose.
424 *
425 * @return MND_SUCCESS on success
426 */
429
430/*!
431 * Read the current offset of a tracking origin.
432 *
433 * Supported in version 1.3 and above.
434 *
435 * @param root The libmonado state.
436 * @param origin_id The ID of the tracking origin.
437 * @param offset A pointer to where the offset should be written.
438 *
439 * @return MND_SUCCESS on success
440 */
442mnd_root_get_tracking_origin_offset(mnd_root_t *root, uint32_t origin_id, mnd_pose_t *out_offset);
443
444/*!
445 * Apply an offset to the specified tracking origin.
446 *
447 * Supported in version 1.3 and above.
448 *
449 * @param root The libmonado state.
450 * @param origin_id The ID of the tracking origin.
451 * @param offset A pointer to valid xrt_pose.
452 *
453 * @return MND_SUCCESS on success
454 */
456mnd_root_set_tracking_origin_offset(mnd_root_t *root, uint32_t origin_id, const mnd_pose_t *offset);
457
458/*!
459 * Retrieve the number of tracking origins available.
460 *
461 * Supported in version 1.3 and above.
462 *
463 * @param root The libmonado state.
464 * @param out_track_count Pointer to where the count should be written.
465 *
466 * @return MND_SUCCESS on success
467 */
469mnd_root_get_tracking_origin_count(mnd_root_t *root, uint32_t *out_track_count);
470
471/*!
472 * Retrieve the name of the indicated tracking origin.
473 *
474 * Supported in version 1.3 and above.
475 *
476 * @param root The libmonado state.
477 * @param origin_id The ID of a tracking origin.
478 * @param out_string The pointer to write the name's pointer to.
479 *
480 * @return MND_SUCCESS on success
481 */
483mnd_root_get_tracking_origin_name(mnd_root_t *root, uint32_t origin_id, const char **out_string);
484
485/*!
486 * Get battery status of a device.
487 *
488 * @param root The libmonado state.
489 * @param device_index Index of device to retrieve battery info from.
490 * @param[out] out_present Pointer to value to populate with whether the device provides battery status info.
491 * @param[out] out_charging Pointer to value to populate with whether the device is currently being charged.
492 * @param[out] out_charge Pointer to value to populate with the battery charge as a value between 0 and 1.
493 *
494 * @return MND_SUCCESS on success
495 */
498 mnd_root_t *root, uint32_t device_index, bool *out_present, bool *out_charging, float *out_charge);
499
500/*!
501 * Get current brightness of a display device.
502 *
503 * @param root The libmonado state.
504 * @param device_index Index of device to retrieve brightness from.
505 * @param[out] out_brightness Pointer to value to populate with the current device brightness, where 0 is 0%, and 1 is
506 * 100%.
507 *
508 * @return MND_SUCCESS on success
509 */
511mnd_root_get_device_brightness(mnd_root_t *root, uint32_t device_index, float *out_brightness);
512
513/*!
514 * @brief Set the display brightness.
515 *
516 * @param root The libmonado state.
517 * @param device_index Index of device to retrieve battery info from.
518 * @param[in] brightness Desired display brightness, usually between 0 and 1. Some devices may
519 * allow exceeding 1 if the supported range exceeds 100%, but it will be clamped to
520 * the supported range.
521 * @param[in] relative Whether to add \a brightness to the current brightness, instead of overwriting
522 * the current brightness.
523 *
524 * @return MND_SUCCESS on success
525 */
527mnd_root_set_device_brightness(mnd_root_t *root, uint32_t device_index, float brightness, bool relative);
528
529#ifdef __cplusplus
530}
531#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:543
mnd_result_t mnd_root_create(mnd_root_t **out_root)
Create libmonado state and connect to service.
Definition: monado.c:134
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:309
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:385
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_UNSUPPORTED_OPERATION
Supported in version 1.5 and above.
Definition: monado.h:50
@ 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:530
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:119
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:229
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:503
mnd_property
A property to get from a thing (currently only devices).
Definition: monado.h:72
@ MND_PROPERTY_SUPPORTS_POSITION_BOOL
Supported in version 1.4.0 and above.
Definition: monado.h:80
@ MND_PROPERTY_SUPPORTS_BRIGHTNESS_BOOL
Supported in version 1.5.0 and above.
Definition: monado.h:84
@ MND_PROPERTY_NAME_STRING
Supported in version 1.2 and above.
Definition: monado.h:74
@ MND_PROPERTY_SUPPORTS_ORIENTATION_BOOL
Supported in version 1.4.0 and above.
Definition: monado.h:82
@ MND_PROPERTY_TRACKING_ORIGIN_U32
Supported in version 1.4.0 and above.
Definition: monado.h:78
@ MND_PROPERTY_SERIAL_STRING
Supported in version 1.2 and above.
Definition: monado.h:76
void mnd_root_destroy(mnd_root_t **root_ptr)
Destroy libmonado state, disconnecting from the service, and zeroing the pointer.
Definition: monado.c:156
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:212
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:585
mnd_result_t mnd_root_recenter_local_spaces(mnd_root_t *root)
Trigger a recenter of the local spaces.
Definition: monado.c:491
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:426
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:111
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:332
mnd_result_t mnd_root_update_client_list(mnd_root_t *root)
Update our local cached copy of the client list.
Definition: monado.c:176
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:516
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:567
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:201
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:268
enum mnd_client_flags mnd_client_flags_t
Bitflags for client application state.
mnd_result_t mnd_root_set_device_brightness(mnd_root_t *root, uint32_t device_index, float brightness, bool relative)
Set the display brightness.
Definition: monado.c:636
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:283
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:57
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:298
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:407
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:253
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:348
mnd_result_t mnd_root_get_device_brightness(mnd_root_t *root, uint32_t device_index, float *out_brightness)
Get current brightness of a display device.
Definition: monado.c:614
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:190
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:369
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:556
A pose composed of a position and orientation.
Definition: monado.h:96
Definition: monado.c:32