convert abs mouse from screen to viewport coordinates; fix relative m… (#13258)

* convert abs mouse from screen to viewport coordinates; fix relative mouse code to work in screen mode

* C89 compatibility

* revert accidental include
This commit is contained in:
arpruss 2021-12-18 10:52:27 -06:00 committed by GitHub
parent 698ab4729a
commit e5e6f343ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -385,19 +385,29 @@ static int16_t udev_mouse_get_pointer_x(const udev_input_mouse_t *mouse, bool sc
if (mouse->abs) /* mouse coords are absolute */ if (mouse->abs) /* mouse coords are absolute */
{ {
/* mouse coordinates are relative to the screen; convert them
* to be relative to the viewport */
double scaled_x;
src_min = mouse->x_min; src_min = mouse->x_min;
src_width = mouse->x_max - mouse->x_min + 1; src_width = mouse->x_max - mouse->x_min + 1;
scaled_x = vp.full_width * (mouse->x_abs - src_min) / src_width;
x = -32767.0 + 65535.0 / vp.width * (scaled_x - vp.x);
} }
else /* mouse coords are viewport relative */ else /* mouse coords are viewport relative */
{ {
src_min = vp.x; if (screen)
if (screen) {
src_min = 0.0;
src_width = vp.full_width; src_width = vp.full_width;
else }
else
{
src_min = vp.x;
src_width = vp.width; src_width = vp.width;
}
x = -32767.0 + 65535.0 / src_width * (mouse->x_abs - src_min);
} }
x = -32767.0 + 65535.0 / src_width * (mouse->x_abs - src_min);
x += (x < 0 ? -0.5 : 0.5); x += (x < 0 ? -0.5 : 0.5);
if (x < -0x7fff) if (x < -0x7fff)
@ -420,16 +430,26 @@ static int16_t udev_mouse_get_pointer_y(const udev_input_mouse_t *mouse, bool sc
if (mouse->abs) /* mouse coords are absolute */ if (mouse->abs) /* mouse coords are absolute */
{ {
double scaled_y;
/* mouse coordinates are relative to the screen; convert them
* to be relative to the viewport */
src_min = mouse->y_min; src_min = mouse->y_min;
src_height = mouse->y_max - mouse->y_min + 1; src_height = mouse->y_max - mouse->y_min + 1;
scaled_y = vp.full_height * (mouse->y_abs - src_min) / src_height;
y = -32767.0 + 65535.0 / vp.height * (scaled_y - vp.y);
} }
else /* mouse coords are viewport relative */ else /* mouse coords are viewport relative */
{ {
src_min = vp.y;
if (screen) if (screen)
{
src_min = 0.0;
src_height = vp.full_height; src_height = vp.full_height;
}
else else
{
src_min = vp.y;
src_height = vp.height; src_height = vp.height;
}
} }
y = -32767.0 + 65535.0 / src_height * (mouse->y_abs - src_min); y = -32767.0 + 65535.0 / src_height * (mouse->y_abs - src_min);