Skip to content

android: dpi_scale from DisplayMetrics (413218d) makes touches and screen size use different units #704

Open

Description

@indicozy

Commit 413218d ("android: populate dpi_scale from DisplayMetrics.density via JNI") is on master but not in a release yet (0.4.11 still reports dpi_scale() == 1.0 on Android). With it, an app that uses high_dpi: true gets two different units for input on Android:

  • dpi_scale() becomes the display density (3.5 on a OnePlus 13).
  • macroquad divides the screen size and the mouse by it (window.rs screen_width()/screen_height(), input.rs mouse_position()), so these are now in dp: about 411 × 905 on a 1440 × 3168 screen.
  • Touch positions are still raw pixels. touch_event passes the window's pixel coordinates through, and macroquad's touches() returns them unchanged.

So touches() and screen_width()/mouse_position() no longer agree on Android. A game that reads touches() and hit-tests against the screen size gets every tap 3.5× too far right and down.

That's what we hit in Razdor, a macroquad 0.4.16 game. It turns off simulate_mouse_with_touch on phones and reads touches(). Built against master, it drew correctly but ignored every tap on a OnePlus 13 (Android 16). With 413218d reverted, and nothing else changed, taps work again.

A real density on Android makes sense, and iOS already reports one. What would help before it ships:

  1. Make the units consistent, e.g. scale touch positions by dpi_scale the same way the mouse is (here in touch_event, or in macroquad's touches()), or document clearly which API is in pixels and which in points.
  2. Mention it in the release notes as a breaking change for Android apps with high_dpi: true: screen size, mouse and anything derived from them change by the density factor.

I haven't checked how iOS behaves here, i.e. whether its touches arrive in points or pixels. If iOS already scales touches, Android could follow the same path.

(Investigated on the device by me, written up with Claude Code.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions