From 3b0af8d184babc21692e8d81e8291076ef5b090d Mon Sep 17 00:00:00 2001 From: Charlton Rodda Date: Sun, 13 Aug 2023 04:34:54 +0100 Subject: [PATCH] d/qwerty: Make controller support press-and-hold --- src/xrt/drivers/qwerty/qwerty_device.c | 17 ++++++----------- src/xrt/drivers/qwerty/qwerty_device.h | 22 ++++++++++++++++++---- src/xrt/drivers/qwerty/qwerty_sdl.c | 6 ++++-- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/xrt/drivers/qwerty/qwerty_device.c b/src/xrt/drivers/qwerty/qwerty_device.c index c7d346948..cdc09aade 100644 --- a/src/xrt/drivers/qwerty/qwerty_device.c +++ b/src/xrt/drivers/qwerty/qwerty_device.c @@ -113,17 +113,10 @@ qwerty_update_inputs(struct xrt_device *xd) struct qwerty_controller *qc = qwerty_controller(xd); struct qwerty_device *qd = &qc->base; - xd->inputs[QWERTY_SELECT].value.boolean = qc->select_clicked; - if (qc->select_clicked) { - QWERTY_INFO(qd, "[%s] Select click", xd->str); - qc->select_clicked = false; - } + QWERTY_TRACE(qd, "select: %u, menu: %u", qc->select_clicked, qc->menu_clicked); + xd->inputs[QWERTY_SELECT].value.boolean = qc->select_clicked; xd->inputs[QWERTY_MENU].value.boolean = qc->menu_clicked; - if (qc->menu_clicked) { - QWERTY_INFO(qd, "[%s] Menu click", xd->str); - qc->menu_clicked = false; - } } static void @@ -509,8 +502,10 @@ qwerty_release_all(struct qwerty_device *qd) // Controller methods // clang-format off -void qwerty_select_click(struct qwerty_controller *qc) { qc->select_clicked = true; } -void qwerty_menu_click(struct qwerty_controller *qc) { qc->menu_clicked = true; } +void qwerty_press_select(struct qwerty_controller *qc) { qc->select_clicked = true; } +void qwerty_release_select(struct qwerty_controller *qc) { qc->select_clicked = false; } +void qwerty_press_menu(struct qwerty_controller *qc) { qc->menu_clicked = true; } +void qwerty_release_menu(struct qwerty_controller *qc) { qc->menu_clicked = false; } // clang-format on void diff --git a/src/xrt/drivers/qwerty/qwerty_device.h b/src/xrt/drivers/qwerty/qwerty_device.h index ceb5e160a..0d714ac7c 100644 --- a/src/xrt/drivers/qwerty/qwerty_device.h +++ b/src/xrt/drivers/qwerty/qwerty_device.h @@ -254,18 +254,32 @@ struct qwerty_controller * qwerty_controller(struct xrt_device *xd); /*! - * Simulate input/select/click + * Simulate pressing input/select/click * @public @memberof qwerty_controller */ void -qwerty_select_click(struct qwerty_controller *qc); +qwerty_press_select(struct qwerty_controller *qc); /*! - * Simulate input/menu/click + * Simulate releasing input/select/click * @public @memberof qwerty_controller */ void -qwerty_menu_click(struct qwerty_controller *qc); +qwerty_release_select(struct qwerty_controller *qc); + +/*! + * Simulate pressing input/menu/click + * @public @memberof qwerty_controller + */ +void +qwerty_press_menu(struct qwerty_controller *qc); + +/*! + * Simulate releasing input/menu/click + * @public @memberof qwerty_controller + */ +void +qwerty_release_menu(struct qwerty_controller *qc); /*! * Attach/detach the pose of `qc` to its HMD. Only works when a qwerty_hmd is present. diff --git a/src/xrt/drivers/qwerty/qwerty_sdl.c b/src/xrt/drivers/qwerty/qwerty_sdl.c index 1db892c52..a2484c174 100644 --- a/src/xrt/drivers/qwerty/qwerty_sdl.c +++ b/src/xrt/drivers/qwerty/qwerty_sdl.c @@ -210,8 +210,10 @@ qwerty_process_event(struct xrt_device **xdevs, size_t xdev_count, SDL_Event eve } // Select and menu clicks only for controllers. - if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) qwerty_select_click(qctrl); - if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_MIDDLE) qwerty_menu_click(qctrl); + if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) qwerty_press_select(qctrl); + if (event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_LEFT) qwerty_release_select(qctrl); + if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_MIDDLE) qwerty_press_menu(qctrl); + if (event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_MIDDLE) qwerty_release_menu(qctrl); // clang-format on