Skip to content

Adjust click event threshold for XR Device ray interaction from 1px to 5px #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 18, 2025

This PR increases the click event distance threshold from 1 pixel to 5 pixels to improve click detection reliability for XR device ray interactions.

Problem

In the current implementation, click events are only triggered when the distance between mousedown and mouseup hit points is less than 1 pixel. While this works well for traditional mouse interactions, XR device ray interactions often experience slight jitter that makes it difficult to trigger click events consistently.

Solution

The change increases the threshold from client_cssom::pixelToMeter(1) to client_cssom::pixelToMeter(5) in the DocumentEventDispatcher class:

// Before
static inline float click_distance_threshold_ = client_cssom::pixelToMeter(1);

// After  
static inline float click_distance_threshold_ = client_cssom::pixelToMeter(5);

Technical Details

  • Old threshold: 1px ≈ 0.276mm in world space
  • New threshold: 5px ≈ 1.38mm in world space
  • Impact: 5x increase provides better tolerance for XR ray jitter while maintaining click vs drag distinction
  • Scope: Single line change with no breaking changes to existing APIs

The threshold is used in the click detection logic to determine if a selectStart and selectEnd event pair should generate a click event based on spatial proximity of the hit points.

Fixes #86.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • registry.npmmirror.com
    • Triggering command: npm install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…raction

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] adjust click event threshold for XR Device ray interaction Adjust click event threshold for XR Device ray interaction from 1px to 5px Jul 18, 2025
@Copilot Copilot AI requested a review from yorkie July 18, 2025 11:10
Copilot finished work on behalf of yorkie July 18, 2025 11:10
Copy link
Collaborator

@yorkie yorkie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making this configurable?

…nvironment variable

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 18, 2025

How about making this configurable?

Made the click distance threshold configurable via Android property jsar.xr.click.distance.threshold and environment variable JSAR_XR_CLICK_DISTANCE_THRESHOLD. The implementation follows existing patterns in the codebase with proper validation and maintains the 5px default. See commit fafd4fa.

@Copilot Copilot AI requested a review from yorkie July 18, 2025 12:14
Copilot finished work on behalf of yorkie July 18, 2025 12:14
Copy link
Collaborator

@yorkie yorkie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://www.w3.org/TR/uievents/.

This threshold is not related to the XR-specific concepts, it's defined at Web UI Events spec, please rename the related configurations in this PR.

@@ -48,6 +48,7 @@ namespace dom
glm::vec3 current_scroll_end_point_;
bool is_scroll_in_progress_ = false;

static inline float click_distance_threshold_ = client_cssom::pixelToMeter(1);
static float getClickDistanceThreshold();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static members should use uppercase for first char.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed static member naming to use uppercase first character: click_distance_threshold_Click_distance_threshold_. See commit 0308c1b.

…aming and fix static member naming convention

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 18, 2025

See https://www.w3.org/TR/uievents/.

This threshold is not related to the XR-specific concepts, it's defined at Web UI Events spec, please rename the related configurations in this PR.

Renamed the configuration to follow Web UI Events spec naming. Changed Android property from jsar.xr.click.distance.threshold to jsar.click.distance.threshold and environment variable from JSAR_XR_CLICK_DISTANCE_THRESHOLD to JSAR_CLICK_DISTANCE_THRESHOLD. Updated documentation accordingly. See commit 0308c1b.

@Copilot Copilot AI requested a review from yorkie July 18, 2025 16:23
Copilot finished work on behalf of yorkie July 18, 2025 16:23
@@ -48,6 +48,7 @@ namespace dom
glm::vec3 current_scroll_end_point_;
bool is_scroll_in_progress_ = false;

static inline float click_distance_threshold_ = client_cssom::pixelToMeter(1);
static float getClickDistanceThreshold();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static float getClickDistanceThreshold();
static float GetClickDistanceThreshold();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated function name to GetClickDistanceThreshold with uppercase first character. See commit 959a984.

adb shell setprop jsar.click.distance.threshold 5
```

This controls the maximum distance (in pixels) between `mousedown` and `mouseup` hit points for triggering click events. The default value is 5 pixels, which provides good tolerance for ray jitter while maintaining distinction between click and drag gestures.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain the distance threshold at first, and add link to the related Web spec, and then provide the help to how to config it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restructured documentation to first explain the distance threshold concept with reference to Web UI Events specification, then provide configuration instructions. See commit 959a984.

To configure the click distance threshold for device ray interactions:

```sh
adb shell setprop jsar.click.distance.threshold 5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

Suggested change
adb shell setprop jsar.click.distance.threshold 5
adb shell setprop jsar.events.click_distance_threshold 5

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed Android property name to jsar.events.click_distance_threshold using events namespace and underscore separator. See commit 959a984.

…erty naming, and documentation structure

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
@Copilot Copilot AI requested a review from yorkie July 18, 2025 16:36
Copilot finished work on behalf of yorkie July 18, 2025 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

adjust click event threshold for XR Device ray interaction
2 participants