Repository: godotengine/godot
File: modules/webxr/webxr_interface_js.cpp (C++)

Code before:
			arvr_server->add_tracker(tracker);
		}

		InputDefault *input = (InputDefault *)Input::get_singleton();

		float *tracker_matrix = godot_webxr_get_controller_transform(p_controller_id);
		if (tracker_matrix) {
			Transform transform = _js_matrix_to_transform(tracker_matrix);
			tracker->set_position(transform.origin);
			tracker->set_orientation(transform.basis);
			free(tracker_matrix);
		}

		int *buttons = godot_webxr_get_controller_buttons(p_controller_id);
		if (buttons) {
			for (int i = 0; i < buttons[0]; i++) {
				input->joy_button(p_controller_id + 100, i, *((float *)buttons + (i + 1)));
			}
			free(buttons);
		}

		int *axes = godot_webxr_get_controller_axes(p_controller_id);
		if (axes) {
			for (int i = 0; i < axes[0]; i++) {
				InputDefault::JoyAxis joy_axis;
				joy_axis.min = -1;
				joy_axis.value = *((float *)axes + (i + 1));
				input->joy_axis(p_controller_id + 100, i, joy_axis);
			}
			free(axes);
		}
	} else if (tracker.is_valid()) {
		arvr_server->remove_tracker(tracker);
	}
}

void WebXRInterfaceJS::_on_controller_changed() {
	// Register "virtual" gamepads with Godot for the ones we get from WebXR.
	godot_webxr_sample_controller_data();
	for (int i = 0; i < 2; i++) {
		bool controller_connected = godot_webxr_is_controller_connected(i);
		if (controllers_state[i] != controller_connected) {
			Input::get_singleton()->joy_connection_changed(i + 100, controller_connected, i == 0 ? "Left" : "Right", "");
			controllers_state[i] = controller_connected;
		}
	}
}

void WebXRInterfaceJS::notification(int p_what) {
	// Nothing to do here.
}

Review comment (suggestion):
Worth noting that the code is different in the `master` branch (and thus not changed in #56238), I'm not sure if it means that either the `3.x` or `master` version might be missing a follow-up fix? @dsnopek @Faless 

In `master` it's:
```cpp
                int *axes = godot_webxr_get_controller_axes(p_controller_id);
                if (axes) {
                        // TODO again just a temporary fix, split these between proper float and vector2 inputs
                        for (int i = 0; i < axes[0]; i++) {
                                char name[1024];
                                sprintf(name, "axis_%i", i);

                                float value = *((float *)axes + (i + 1));
                                ;
                                tracker->set_input(name, value);
                        }
                        free(axes);
                }
```

Code after:
			arvr_server->add_tracker(tracker);
		}

		InputDefault *input = (InputDefault *)Input::get_singleton();

		float *tracker_matrix = godot_webxr_get_controller_transform(p_controller_id);
		if (tracker_matrix) {
			Transform transform = _js_matrix_to_transform(tracker_matrix);
			tracker->set_position(transform.origin);
			tracker->set_orientation(transform.basis);
			free(tracker_matrix);
		}

		int *buttons = godot_webxr_get_controller_buttons(p_controller_id);
		if (buttons) {
			for (int i = 0; i < buttons[0]; i++) {
				input->joy_button(p_controller_id + 100, i, *((float *)buttons + (i + 1)));
			}
			free(buttons);
		}

		int *axes = godot_webxr_get_controller_axes(p_controller_id);
		if (axes) {
			for (int i = 0; i < axes[0]; i++) {
				float value = *((float *)axes + (i + 1));
				input->joy_axis(p_controller_id + 100, i, value);
			}
			free(axes);
		}
	} else if (tracker.is_valid()) {
		arvr_server->remove_tracker(tracker);
	}
}

void WebXRInterfaceJS::_on_controller_changed() {
	// Register "virtual" gamepads with Godot for the ones we get from WebXR.
	godot_webxr_sample_controller_data();
	for (int i = 0; i < 2; i++) {
		bool controller_connected = godot_webxr_is_controller_connected(i);
		if (controllers_state[i] != controller_connected) {
			Input::get_singleton()->joy_connection_changed(i + 100, controller_connected, i == 0 ? "Left" : "Right", "");
			controllers_state[i] = controller_connected;
		}
	}
}

void WebXRInterfaceJS::notification(int p_what) {
	// Nothing to do here.
}

WebXRInterfaceJS::WebXRInterfaceJS() {