~bl4ckb0ne/wxrc

9644d99d240d85ba42ce87ab5ba3b682b5787b7c — Simon Zeni 1 year, 3 months ago e778d0c
wxrc/config: add hand-tracking option
4 files changed, 33 insertions(+), 21 deletions(-)

M config
M wxrc/config.c
M wxrc/config.h
M wxrc/input.c
M config => config +1 -0
@@ 1,4 1,5 @@
input {
	hand-tracking enable
	hands {
		left "assets/input/hands/valve/left.glb"
		right "assets/input/hands/valve/right.glb"

M wxrc/config.c => wxrc/config.c +24 -20
@@ 45,6 45,24 @@ parse_path(const char *path)
}

static bool
parse_bool(struct scfg_directive *data)
{
	if (data->params_len != 1) {
		wlr_log(WLR_ERROR, "expected 1 param got %zu (line %d)",
			data->params_len, data->lineno);
	} else if (strcmp(data->params[0], "enable") == 0) {
		return true;
	} else if (strcmp(data->params[0], "disable") == 0) {
		return false;
	} else {
		wlr_log(WLR_ERROR, "unknown value '%s' (line %d)", data->params[0],
			data->lineno);
	}

	return false;
}

static bool
parse_hands(struct scfg_directive *data)
{
	if (data->params_len != 0) {


@@ 149,25 167,6 @@ parse_profile(struct scfg_directive *data)
}

static bool
parse_haptic(struct scfg_directive *data)
{
	if (data->params_len != 1) {
		wlr_log(WLR_ERROR, "expected 1 param got %zu (line %d)",
			data->params_len, data->lineno);
	} else if (strcmp(data->params[0], "enable") == 0) {
		return true;
	} else if (strcmp(data->params[0], "disable") == 0) {
		return false;
	} else {
		wlr_log(WLR_ERROR, "unknown value '%s' (line %d)", data->params[0],
			data->lineno);
	}

	wlr_log(WLR_INFO, "haptic disabled");
	return false;
}

static bool
parse_controllers(struct scfg_directive *data)
{
	if (data->params_len != 0) {


@@ 196,7 195,7 @@ parse_controllers(struct scfg_directive *data)
				return false;
			}
		} else if (strcmp(d->name, "haptic") == 0) {
			c->haptic = parse_haptic(d);
			c->haptic = parse_bool(d);
		} else if (strcmp(d->name, "profile") == 0) {
			if (!parse_profile(d)) {
				return false;


@@ 220,6 219,9 @@ parse_input(struct scfg_directive *data)
		return false;
	}

	struct wxrc_config_input *input = &config.input;
	input->hand_tracking = true;

	for (size_t i = 0; i < data->children.directives_len; ++i) {
		struct scfg_directive *d = &data->children.directives[i];



@@ 231,6 233,8 @@ parse_input(struct scfg_directive *data)
			if (!parse_controllers(d)) {
				return false;
			}
		} else if (strcmp(d->name, "hand-tracking") == 0) {
			input->hand_tracking = parse_bool(d);
		} else {
			wlr_log(WLR_ERROR, "unknown directive '%s' (line %d)", d->name,
				d->lineno);

M wxrc/config.h => wxrc/config.h +2 -0
@@ 27,6 27,8 @@ struct wxrc_config_input {
		char *left, *right;
	} hands;

	bool hand_tracking;

	struct wxrc_config_controllers controllers;
};


M wxrc/input.c => wxrc/input.c +6 -1
@@ 320,9 320,14 @@ wxrc_input_init(struct wxrc_input *input)
	input->left.controller = wxrc_controller_create(input, XR_HAND_LEFT_EXT);
	input->right.controller = wxrc_controller_create(input, XR_HAND_RIGHT_EXT);

	if (wxrc_xr_has_hand_tracking(server->instance, server->system_id)) {
	const struct wxrc_config *cfg = wxrc_config_get();

	if (wxrc_xr_has_hand_tracking(server->instance, server->system_id)
			&& cfg->input.hand_tracking) {
		input->left.hand = wxrc_hand_tracking_create(input, XR_HAND_LEFT_EXT);
		input->right.hand = wxrc_hand_tracking_create(input, XR_HAND_RIGHT_EXT);
	} else {
		wlr_log(WLR_INFO, "hand-tracking disabled");
	}

	return true;