Monado OpenXR Runtime
Loading...
Searching...
No Matches
oxr_subaction.h
Go to the documentation of this file.
1// Copyright 2020, Collabora, Ltd.
2// Copyright 2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Provides a utility macro for dealing with subaction paths
7 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
8 * @ingroup oxr_input
9 */
10
11#pragma once
12
14#include "oxr_extension_support.h"
15
16
17/*!
18 * Expansion macro (x-macro) that calls the macro you pass with the shorthand
19 * name of each valid subaction path.
20 *
21 * Use to generate code that checks each subaction path in sequence, etc.
22 *
23 * If you also want the bogus subaction path of just plain `/user`, then see
24 * OXR_FOR_EACH_SUBACTION_PATH()
25 *
26 * @note Keep this synchronized with OXR_ACTION_GET_FILLER!
27 */
28#define OXR_FOR_EACH_VALID_SUBACTION_PATH(_) \
29 _(left) \
30 _(right) \
31 _(head) \
32 _(gamepad) \
33 _(eyes)
34
35
36/*!
37 * Expansion macro (x-macro) that calls the macro you pass with the shorthand
38 * name of each subaction path, including just bare `user`.
39 *
40 * Use to generate code that checks each subaction path in sequence, etc.
41 *
42 * @note Keep this synchronized with OXR_ACTION_GET_FILLER!
43 */
44#define OXR_FOR_EACH_SUBACTION_PATH(_) \
45 OXR_FOR_EACH_VALID_SUBACTION_PATH(_) \
46 _(user)
47
48/*!
49 * Expansion macro (x-macro) that calls the macro you pass for each valid
50 * subaction path, with the shorthand name of each subaction path, the same
51 * name capitalized, and the corresponding path string.
52 *
53 * If you also want the bogus subaction path of just plain `/user`, then see
54 * OXR_FOR_EACH_SUBACTION_PATH_DETAILED()
55 *
56 * Use to generate code that checks each subaction path in sequence, etc.
57 *
58 * Most of the time you can just use OXR_FOR_EACH_VALID_SUBACTION_PATH() or
59 * OXR_FOR_EACH_SUBACTION_PATH()
60 */
61#define OXR_FOR_EACH_VALID_SUBACTION_PATH_DETAILED(_) \
62 _(left, LEFT, "/user/hand/left") \
63 _(right, RIGHT, "/user/hand/right") \
64 _(head, HEAD, "/user/head") \
65 _(gamepad, GAMEPAD, "/user/gamepad") \
66 _(eyes, EYES, "/user/eyes_ext")
67
68/*!
69 * Expansion macro (x-macro) that calls the macro you pass for each subaction
70 * path (including the bare `/user`), with the shorthand name of each subaction
71 * path, the same name capitalized, and the corresponding path string.
72 *
73 * Use to generate code that checks each subaction path in sequence, etc.
74 *
75 * Most of the time you can just use OXR_FOR_EACH_VALID_SUBACTION_PATH() or
76 * OXR_FOR_EACH_SUBACTION_PATH()
77 */
78#define OXR_FOR_EACH_SUBACTION_PATH_DETAILED(_) \
79 OXR_FOR_EACH_VALID_SUBACTION_PATH_DETAILED(_) \
80 _(user, USER, "/user")
81
82
83#ifdef __cplusplus
84extern "C" {
85#endif
86
87
88/*!
89 * A parsed equivalent of a list of sub-action paths.
90 *
91 * If @p any is true, then no paths were provided, which typically means any
92 * input is acceptable.
93 *
94 * @ingroup oxr_main
95 * @ingroup oxr_input
96 */
98{
99 bool any;
100#define OXR_SUBPATH_MEMBER(X) bool X;
101 OXR_FOR_EACH_SUBACTION_PATH(OXR_SUBPATH_MEMBER)
102#undef OXR_SUBPATH_MEMBER
103};
104
105/*!
106 * Helper function to determine if the set of paths in @p a is a subset of the
107 * paths in @p b.
108 *
109 * @public @memberof oxr_subaction_paths
110 */
111static inline bool
113{
114#define OXR_CHECK_SUBACTION_PATHS(X) \
115 if (a->X && !b->X) { \
116 return false; \
117 }
118 OXR_FOR_EACH_SUBACTION_PATH(OXR_CHECK_SUBACTION_PATHS)
119#undef OXR_CHECK_SUBACTION_PATHS
120 return true;
121}
122
123/*!
124 * Classify an array of subaction paths into a parsed @ref oxr_subaction_paths
125 * bitfield. The caller must do any error printing or reporting.
126 *
127 * Zeroes @p out_subaction_paths, then for each path in @p subaction_paths:
128 * - If @p subaction_path_count is 0, sets @p out_subaction_paths->any to true
129 * and returns true.
130 * - If the path is XR_NULL_PATH, sets @p out_subaction_paths->any to true.
131 * - Otherwise matches the path against the instance's known subaction paths
132 * (e.g. /user/hand/left, /user/hand/right, /user/head) via @p cache and sets
133 * the corresponding flag in @p out_subaction_paths.
134 *
135 * @param[in] cache Instance path cache containing resolved subaction path
136 * values
137 * @param[in] subaction_path_count Number of paths in @p subaction_paths
138 * @param[in] subaction_paths Array of XrPath subaction path handles to classify
139 * @param[out] out_subaction_paths Filled with the classified path flags; set
140 * @ref oxr_subaction_paths::any if no paths or XR_NULL_PATH seen
141 * @return true if all paths were recognized and classified
142 * @return false if any path was not a known subaction path; the caller must
143 * report an error or warning
144 * @public @memberof oxr_subaction_paths
145 */
146bool
147oxr_classify_subaction_paths(const struct oxr_instance_path_cache *cache,
148 uint32_t subaction_path_count,
149 const XrPath *subaction_paths,
150 struct oxr_subaction_paths *out_subaction_paths);
151
152/*!
153 * Convenience wrapper around oxr_classify_subaction_paths() for the
154 * single-path case, see @ref oxr_classify_subaction_paths().
155 *
156 * @public @memberof oxr_subaction_paths
157 */
158static inline bool
160 XrPath subaction_path,
161 struct oxr_subaction_paths *out_subaction_paths)
162{
163 return oxr_classify_subaction_paths(cache, 1, &subaction_path, out_subaction_paths);
164}
165
166
167#ifdef __cplusplus
168}
169#endif
Forward declarations for OpenXR state tracker structs.
#define OXR_FOR_EACH_SUBACTION_PATH(_)
Expansion macro (x-macro) that calls the macro you pass with the shorthand name of each subaction pat...
Definition oxr_subaction.h:44
This holds cached paths for subaction paths.
Definition oxr_instance_path_cache.h:27
A parsed equivalent of a list of sub-action paths.
Definition oxr_subaction.h:98
static bool oxr_subaction_paths_is_subset_of(const struct oxr_subaction_paths *a, const struct oxr_subaction_paths *b)
Helper function to determine if the set of paths in a is a subset of the paths in b.
Definition oxr_subaction.h:112
static bool oxr_classify_subaction_path(const struct oxr_instance_path_cache *cache, XrPath subaction_path, struct oxr_subaction_paths *out_subaction_paths)
Convenience wrapper around oxr_classify_subaction_paths() for the single-path case,...
Definition oxr_subaction.h:159