fix(input): align Windows absolute moves with picture pixels

The Viewer sends a continuous picture fraction. Select that source pixel, translate the virtual desktop origin with widened arithmetic, and target the centre of its Win32 absolute-input interval. Preserve the actual producer rounding at pixel boundaries.

Production Go input tests pass, including a wire value from the real Viewer and a negative-origin monitor. Independent review compared the published Microsoft mapping. This fixes positioning precision; it does not explain the separate minimized-Chrome button rejection in issue 502.
This commit is contained in:
AAA committed 2026-11-26 13:20:33 -05:00
1 parent 2fc1081d1b
commit 5dbc6fee54
2 files changed
+35 -3

No files matched your search

+15 -3
View File
@@ -250,6 +250,18 @@ func buttonInput(button int, down bool) (winInput, error) {
return input, nil
}
// The Viewer sends a fraction of the picture's continuous extent. Select its
// physical pixel, then the midpoint of the integer Win32 codes for that pixel.
func absoluteMouseCoordinate(position float64, start, extent, origin, size int32) int32 {
const rounding = 0x1p-52 // Viewer division and rotation can round an exact pixel boundary down.
local := min(int64((position+rounding)*float64(extent)), int64(extent)-1)
pixel := max(int64(0), min(int64(size)-1, int64(start)-int64(origin)+local))
width := int64(size)
first := (pixel*65536 + width - 1) / width
last := ((pixel+1)*65536 - 1) / width
return int32((first + last) / 2)
}
func (s *windowsSink) Apply(b bounds, e inputEvent) error {
switch e.Type {
case "move":
@@ -263,9 +275,9 @@ func (s *windowsSink) Apply(b bounds, e inputEvent) error {
if int32(w) < 2 || int32(h) < 2 {
return errors.New("desktop is unavailable")
}
px := float64(b.left) + e.X*float64(b.width-1) - float64(int32(x))
py := float64(b.top) + e.Y*float64(b.height-1) - float64(int32(y))
return s.inject(winInput{Mouse: mouseInput{X: int32(px * 65535 / float64(int32(w)-1)), Y: int32(py * 65535 / float64(int32(h)-1)), Flags: 0xc001}})
dx := absoluteMouseCoordinate(e.X, b.left, b.width, int32(x), int32(w))
dy := absoluteMouseCoordinate(e.Y, b.top, b.height, int32(y), int32(h))
return s.inject(winInput{Mouse: mouseInput{X: dx, Y: dy, Flags: 0xc001}})
case "relative":
if e.DX < -32767 || e.DX > 32767 || e.DY < -32767 || e.DY > 32767 {
return errors.New("invalid relative pointer")
@@ -229,3 +229,23 @@ func TestWindowsPartialUnicodeRelease(t *testing.T) {
t.Fatalf("release recovery did not deliver only the unmatched KEYUP: %v", calls)
}
}
func TestAbsoluteMousePicturePixel(t *testing.T) {
// A 1024-pixel source at -1600 lies 320 pixels from the virtual origin.
for _, sample := range []struct {
position float64
extent int32
pixel int32
}{
{0, 1024, 0}, {.99 / 1024, 1024, 0}, {1 / 1024., 1024, 1}, {1.01 / 1024, 1024, 1},
{511.99 / 1024, 1024, 511}, {1, 1024, 1023},
// Actual picturePoint output for source pixel 2 on a 1920-wide image.
{0.001041666666666663, 1920, 2},
} {
code := absoluteMouseCoordinate(sample.position, -1600, sample.extent, -1920, 4480)
got := int32(int64(code)*4480/65536) - 320
if got != sample.pixel {
t.Fatalf("position %g reached %d, want %d", sample.position, got, sample.pixel)
}
}
}