From 57a269a1ac47c8d92927e2c349a842fb3adaa4d7 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 19 Nov 2025 13:09:46 +0000 Subject: [PATCH] a/bindings: Remove xrt_[input|output]_name_string functions These were buggy anyways as inputs and outputs not referred to by the json wouldn't be listed, for instance all the PS Sense inputs. Replace usage with u_str_xrt_input_name instead. Part-of: --- .../b_generated_bindings_helpers.c.template | 17 ----------------- .../bindings/b_generated_bindings_helpers.h | 6 ------ src/xrt/auxiliary/bindings/bindings.py | 12 ------------ src/xrt/auxiliary/util/u_config_json.c | 3 ++- .../gui/gui_scene_tracking_overrides.c | 4 ++-- src/xrt/state_trackers/oxr/oxr_input.c | 7 +++---- 6 files changed, 7 insertions(+), 42 deletions(-) diff --git a/src/xrt/auxiliary/bindings/b_generated_bindings_helpers.c.template b/src/xrt/auxiliary/bindings/b_generated_bindings_helpers.c.template index 568de92cd..86469a83a 100644 --- a/src/xrt/auxiliary/bindings/b_generated_bindings_helpers.c.template +++ b/src/xrt/auxiliary/bindings/b_generated_bindings_helpers.c.template @@ -14,29 +14,12 @@ // clang-format off -const char * -xrt_input_name_string(enum xrt_input_name input) { - switch(input) - { -$xrt_input_name_string_switch - } -} - enum xrt_input_name xrt_input_name_enum(const char *input) { $xrt_input_name_enum_content } -const char * -xrt_output_name_string(enum xrt_output_name output) -{ - switch(output) - { -$xrt_output_name_string_switch - } -} - enum xrt_output_name xrt_output_name_enum(const char *output) { diff --git a/src/xrt/auxiliary/bindings/b_generated_bindings_helpers.h b/src/xrt/auxiliary/bindings/b_generated_bindings_helpers.h index 4207c41e2..255232263 100644 --- a/src/xrt/auxiliary/bindings/b_generated_bindings_helpers.h +++ b/src/xrt/auxiliary/bindings/b_generated_bindings_helpers.h @@ -17,15 +17,9 @@ extern "C" { #endif -const char * -xrt_input_name_string(enum xrt_input_name input); - enum xrt_input_name xrt_input_name_enum(const char *input); -const char * -xrt_output_name_string(enum xrt_output_name output); - enum xrt_output_name xrt_output_name_enum(const char *output); diff --git a/src/xrt/auxiliary/bindings/bindings.py b/src/xrt/auxiliary/bindings/bindings.py index b99c0445b..377305216 100755 --- a/src/xrt/auxiliary/bindings/bindings.py +++ b/src/xrt/auxiliary/bindings/bindings.py @@ -588,21 +588,11 @@ def generate_bindings_helpers_c(template, file, b): inputs.add("XRT_INPUT_HT_CONFORMING_RIGHT") inputs.add("XRT_INPUT_GENERIC_TRACKER_POSE") - xrt_input_name_string_switch = '\n'.join( - [(f'\tcase {input}: return "{input}";') for input in sorted(inputs)] - ) - xrt_input_name_string_switch += (f'\n\tdefault: return "UNKNOWN";') - xrt_input_name_enum_content = '\n'.join( [f'\tif(strcmp("{input}", input) == 0) return {input};' for input in sorted(inputs)] ) xrt_input_name_enum_content += f'\n\treturn XRT_INPUT_GENERIC_TRACKER_POSE;' - xrt_output_name_string_switch = '\n'.join( - [(f'\tcase {output}: return "{output}";') for output in sorted(outputs)] - ) - xrt_output_name_string_switch+= f'\n\tdefault: return "UNKNOWN";' - xrt_output_name_enum_content = '\n'.join( [f'\tif(strcmp("{output}", output) == 0) return {output};' for output in sorted(outputs)] ) @@ -614,9 +604,7 @@ def generate_bindings_helpers_c(template, file, b): with open(file, "w") as f: filled = src.substitute( - xrt_input_name_string_switch=xrt_input_name_string_switch, xrt_input_name_enum_content=xrt_input_name_enum_content, - xrt_output_name_string_switch=xrt_output_name_string_switch, xrt_output_name_enum_content=xrt_output_name_enum_content ) f.write(filled) diff --git a/src/xrt/auxiliary/util/u_config_json.c b/src/xrt/auxiliary/util/u_config_json.c index f59e7c7c9..34ea24d8b 100644 --- a/src/xrt/auxiliary/util/u_config_json.c +++ b/src/xrt/auxiliary/util/u_config_json.c @@ -14,6 +14,7 @@ #include "util/u_file.h" #include "util/u_json.h" #include "util/u_debug.h" +#include "util/u_pretty_print.h" #include "u_config_json.h" @@ -504,7 +505,7 @@ u_config_json_save_overrides(struct u_config_json *json, struct xrt_tracking_ove cJSON_AddItemToObject(entry, "offset", make_pose(&overrides[i].offset)); - const char *input_name_string = xrt_input_name_string(overrides[i].input_name); + const char *input_name_string = u_str_xrt_input_name(overrides[i].input_name); cJSON_AddStringToObject(entry, "xrt_input_name", input_name_string); cJSON_AddItemToArray(o, entry); diff --git a/src/xrt/state_trackers/gui/gui_scene_tracking_overrides.c b/src/xrt/state_trackers/gui/gui_scene_tracking_overrides.c index 504639f73..265e75097 100644 --- a/src/xrt/state_trackers/gui/gui_scene_tracking_overrides.c +++ b/src/xrt/state_trackers/gui/gui_scene_tracking_overrides.c @@ -11,6 +11,7 @@ #include "util/u_misc.h" #include "util/u_format.h" #include "util/u_logging.h" +#include "util/u_pretty_print.h" #include "util/u_config_json.h" @@ -23,7 +24,6 @@ #include "gui_common.h" #include "gui_imgui.h" -#include "bindings/b_generated_bindings_helpers.h" struct gui_tracking_overrides { @@ -243,7 +243,7 @@ scene_render(struct gui_scene *scene, struct gui_program *p) continue; } - const char *name_str = xrt_input_name_string(input_name); + const char *name_str = u_str_xrt_input_name(input_name); bool selected = o->input_name == input_name; if (igCheckbox(name_str, &selected)) { o->input_name = input_name; diff --git a/src/xrt/state_trackers/oxr/oxr_input.c b/src/xrt/state_trackers/oxr/oxr_input.c index f55957d16..91a3b75f6 100644 --- a/src/xrt/state_trackers/oxr/oxr_input.c +++ b/src/xrt/state_trackers/oxr/oxr_input.c @@ -9,7 +9,6 @@ * @ingroup oxr_main */ -#include "b_generated_bindings_helpers.h" #include "oxr_bindings/b_oxr_generated_bindings.h" #include "util/u_debug.h" #include "util/u_time.h" @@ -771,7 +770,7 @@ get_binding(struct oxr_logger *log, if (found) { if (xbp == NULL) { oxr_slog(slog, "\t\t\t\tBound (xdev '%s'): %s!\n", xdev->str, - xrt_input_name_string(binding_points[i]->input)); + u_str_xrt_input_name(binding_points[i]->input)); } else { oxr_slog(slog, "\t\t\t\tBound (xbp)!\n"); } @@ -1626,7 +1625,7 @@ oxr_action_bind_io(struct oxr_logger *log, // Only add the input if we can find a transform. oxr_slog(slog, "\t\tFinding transforms for '%s' to action '%s' of type '%s'\n", - xrt_input_name_string(inputs[i].input->name), act_ref->name, + u_str_xrt_input_name(inputs[i].input->name), act_ref->name, xr_action_type_to_str(act_ref->action_type)); enum oxr_dpad_region dpad_region; @@ -1667,7 +1666,7 @@ oxr_action_bind_io(struct oxr_logger *log, struct xrt_input *input = cache->inputs[i].input; enum xrt_input_type t = XRT_GET_INPUT_TYPE(input->name); bool active = input->active; - oxr_slog(slog, "\t\t\t'%s' ('%s') on '%s' (%s)\n", xrt_input_name_string(input->name), + oxr_slog(slog, "\t\t\t'%s' ('%s') on '%s' (%s)\n", u_str_xrt_input_name(input->name), xrt_input_type_to_str(t), cache->inputs[i].xdev->str, active ? "active" : "inactive"); } -- 2.51.2