Skip to content

Conversation

@sshwsfc
Copy link

@sshwsfc sshwsfc commented Oct 19, 2025

Description:​​
This PR fixes incorrect touch coordinate handling when the display is rotated in DRM/EGL mode. Currently, while the display content rotates correctly, touch input coordinates aren't properly transformed to match the rotated display orientation.
The Problem
When rotating the display using DRM/EGL (drmModeSetPlane), we observed:

  1. Touch coordinates remain in unrotated screen space
  2. Touch events don't align with displayed content
  3. Particularly noticeable at 90° and 270° rotations where X/Y axes should be swapped

Solution Approach
The fix implements proper coordinate transformation by:

  1. Adding rotation state tracking in input handling
  2. Applying appropriate coordinate transforms based on current rotation:
  • 90° rotation: (x,y) → (y, width-x)
  • 180° rotation: (x,y) → (width-x, height-y)
  • 270° rotation: (x,y) → (height-y, x)
  1. Maintaining original behavior for 0° rotation
  2. Adding coordinate clamping to ensure values stay within display bounds

Key Improvements
​​Correct Rotation Handling​​:

  1. Touch coordinates now properly match rotated display content
  2. Supports all standard rotation angles (0°, 90°, 180°, 270°)

​​Performance Optimizations​​:

  1. Minimizes redundant coordinate transformations
  2. Uses efficient integer math where possible
  3. Only applies transforms when rotation is active

​​Robustness​​:

  1. Includes boundary checking via CLAMP
  2. Handles edge cases and invalid rotations gracefully
  3. Maintains compatibility with existing touch handling

Testing Performed
Validated on:

  1. x86_64 and ARM platforms
  2. Various touchscreen devices
  3. All rotation angles (0°, 90°, 180°, 270°)
  4. Both single-touch and multi-touch scenarios

Test cases included:

  1. Corner touches (should remain in corners after rotation)
  2. Center touches (should remain centered)
  3. Edge swipes (should follow display orientation)
  4. Rapid successive touches
  5. Rotation changes during interaction

Impact
This change affects:

  1. All DRM/EGL backend users with touch input
  2. Particularly important for kiosk and embedded systems
  3. No impact on non-rotated displays or non-DRM backends

Added rotation handling for touch input coordinates based on the current display orientation.
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.

1 participant