From 55c004fb6534e480d7139ef3bd8b884787f8eac3 Mon Sep 17 00:00:00 2001 From: Ada Date: Thu, 3 Jul 2025 00:47:11 +1000 Subject: [PATCH] Fix virtual trigger buttons from sending real click events --- libraries/entities/src/EntityScriptingInterface.cpp | 4 ++++ libraries/pointers/src/Pointer.cpp | 9 +++++++-- scripts/system/controllers/controllerDispatcher.js | 4 ---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 6bb0c0b69f..a8aa10f5b9 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -222,6 +222,8 @@ void EntityScriptingInterface::attachDefaultEventHandlers(ScriptManager* manager * {@link Entities.hoverOverEntity} * "hoverLeaveEntity"{@link Script~pointerEventCallback|pointerEventCallback} * {@link Entities.hoverLeaveEntity} + * "scrollOnEntity"{@link Script~pointerEventCallback|pointerEventCallback} + * {@link Entities.scrollOnEntity} * "collisionWithEntity"{@link Script~collisionEventCallback|collisionEventCallback} * {@link Entities.collisionWithEntity} * @@ -243,6 +245,8 @@ void EntityScriptingInterface::attachDefaultEventHandlers(ScriptManager* manager connect(this, &EntityScriptingInterface::hoverOverEntity, manager, makePointerHandler("hoverOverEntity")); connect(this, &EntityScriptingInterface::hoverLeaveEntity, manager, makePointerHandler("hoverLeaveEntity")); + connect(this, &EntityScriptingInterface::scrollOnEntity, manager, makePointerHandler("scrollOnEntity")); + connect(this, &EntityScriptingInterface::collisionWithEntity, manager, makeCollisionHandler("collisionWithEntity")); } diff --git a/libraries/pointers/src/Pointer.cpp b/libraries/pointers/src/Pointer.cpp index 9cb136b59c..ac09fcf4f8 100644 --- a/libraries/pointers/src/Pointer.cpp +++ b/libraries/pointers/src/Pointer.cpp @@ -113,6 +113,12 @@ void Pointer::generatePointerEvents(unsigned int pointerID, const PickResultPoin if (_enabled && shouldTrigger(pickResult)) { buttons = getPressedButtons(pickResult); for (const std::string& button : buttons) { + auto buttonType = chooseButton(button); + if (buttonType == PointerEvent::NoButtons) { + // don't issue trigger events for virtual triggers + continue; + } + if (_prevButtons.find(button) == _prevButtons.end()) { newButtons.insert(button); } else { @@ -225,11 +231,10 @@ void Pointer::generatePointerEvents(unsigned int pointerID, const PickResultPoin } // Trigger begin - const std::string SHOULD_FOCUS_BUTTON = "Focus"; for (const std::string& button : newButtons) { hoveredEvent.setType(PointerEvent::Press); hoveredEvent.setButton(chooseButton(button)); - hoveredEvent.setShouldFocus(button == SHOULD_FOCUS_BUTTON); + hoveredEvent.setShouldFocus(true); if (hoveredObject.type == ENTITY) { emit pointerManager->triggerBeginEntity(hoveredObject.objectID, hoveredEvent); } else if (hoveredObject.type == LOCAL_ENTITY) { diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 05684f77d6..49976b3248 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -580,7 +580,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); joint: "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND", filter: Picks.PICK_OVERLAYS | Picks.PICK_ENTITIES | Picks.PICK_INCLUDE_NONCOLLIDABLE, triggers: [ - {action: controllerStandard.LTClick, button: "Focus"}, {action: controllerStandard.LTClick, button: "Primary"}, {action: controllerStandard.LT, button: "ScrollActive"}, {action: controllerStandard.LX, button: "ScrollX"}, @@ -598,7 +597,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); joint: "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND", filter: Picks.PICK_OVERLAYS | Picks.PICK_ENTITIES | Picks.PICK_INCLUDE_NONCOLLIDABLE, triggers: [ - {action: controllerStandard.RTClick, button: "Focus"}, {action: controllerStandard.RTClick, button: "Primary"}, {action: controllerStandard.RT, button: "ScrollActive"}, {action: controllerStandard.RX, button: "ScrollX"}, @@ -618,7 +616,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); maxDistance: DEFAULT_SEARCH_SPHERE_DISTANCE, posOffset: getGrabPointSphereOffset(controllerStandard.LeftHand, true), triggers: [ - {action: controllerStandard.LTClick, button: "Focus"}, {action: controllerStandard.LTClick, button: "Primary"}, {action: controllerStandard.LT, button: "ScrollActive"}, {action: controllerStandard.LX, button: "ScrollX"}, @@ -636,7 +633,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); maxDistance: DEFAULT_SEARCH_SPHERE_DISTANCE, posOffset: getGrabPointSphereOffset(controllerStandard.RightHand, true), triggers: [ - {action: controllerStandard.RTClick, button: "Focus"}, {action: controllerStandard.RTClick, button: "Primary"}, {action: controllerStandard.RT, button: "ScrollActive"}, {action: controllerStandard.RX, button: "ScrollX"},