mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
Land taps and the pointer on what is drawn under them (#389)
The compositor takes touch and pointer positions over its whole output and removes the letterbox bars itself, but the session sent them already measured from the picture's edge, so the bars were taken off twice. Any session whose output is a different shape from the panel (16:9 on a 16:10 tablet or a foldable, a fixed resolution on a wide phone) had taps and the touchpad pointer pulled away from the centre, by up to a bar's height at the edges: on a 2400x1504 panel showing 1280x720, a tap near the top reached the first row and one near the bottom landed 32 rows low. Stretch to panel hid it because that output has no bars. Direct touch, the touchpad and mouse pointer, and the second-screen pointer now send positions over the whole view, so the compositor's own mapping puts them on the pixel under the finger.
This commit is contained in:
1 parent
f39dc2b97a
commit
39220c8fd5
3 files changed
+71
-19
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class InputSpaceTest {
|
||||
private fun sceneUnder(viewX: Float, viewY: Float, view: Pair<Int, Int>, scene: Pair<Int, Int>): Pair<Double, Double> {
|
||||
val k = minOf(view.first.toDouble() / scene.first, view.second.toDouble() / scene.second)
|
||||
val offX = (view.first - scene.first * k) / 2
|
||||
val offY = (view.second - scene.second * k) / 2
|
||||
val ox = InputSpace.x(viewX, view.first).toDouble() * view.first / InputSpace.WIDTH
|
||||
val oy = InputSpace.y(viewY, view.second).toDouble() * view.second / InputSpace.HEIGHT
|
||||
return ((ox - offX) / k).coerceIn(0.0, scene.first - 1.0) to ((oy - offY) / k).coerceIn(0.0, scene.second - 1.0)
|
||||
}
|
||||
|
||||
private fun assertLandsUnderFinger(view: Pair<Int, Int>, scene: Pair<Int, Int>) {
|
||||
val k = minOf(view.first.toFloat() / scene.first, view.second.toFloat() / scene.second)
|
||||
val offX = (view.first - scene.first * k) / 2
|
||||
val offY = (view.second - scene.second * k) / 2
|
||||
val stepX = view.first.toDouble() / InputSpace.WIDTH / k
|
||||
val stepY = view.second.toDouble() / InputSpace.HEIGHT / k
|
||||
for (sx in listOf(10, scene.first / 4, scene.first / 2, scene.first - 10))
|
||||
for (sy in listOf(10, scene.second / 4, scene.second / 2, scene.second - 10)) {
|
||||
val (x, y) = sceneUnder(offX + sx * k, offY + sy * k, view, scene)
|
||||
assertEquals("x at $sx,$sy on $view showing $scene", sx.toDouble(), x, stepX + 0.01)
|
||||
assertEquals("y at $sx,$sy on $view showing $scene", sy.toDouble(), y, stepY + 0.01)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aTouchReachesTheScenePixelUnderTheFinger() {
|
||||
assertLandsUnderFinger(2400 to 1504, 1280 to 720)
|
||||
assertLandsUnderFinger(2400 to 1080, 1280 to 720)
|
||||
assertLandsUnderFinger(2400 to 1504, 1148 to 720)
|
||||
assertLandsUnderFinger(1080 to 2400, 1280 to 720)
|
||||
}
|
||||
|
||||
@Test fun positionsOutsideTheViewStayInRange() {
|
||||
assertEquals(0, InputSpace.x(-50f, 2400))
|
||||
assertEquals(InputSpace.WIDTH - 1, InputSpace.x(2400f, 2400))
|
||||
assertEquals(InputSpace.HEIGHT - 1, InputSpace.y(5000f, 1504))
|
||||
assertEquals(0, InputSpace.y(10f, 0))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user