From 01e7394101fefce582ba6c863fd3a66aeb474c8f Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 12 Aug 2023 15:59:29 +0200 Subject: [PATCH] Moved mouse scaling back to the emulated side, should improve mouse movement. --- src/device/mouse.c | 81 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 24 deletions(-) diff --git a/src/device/mouse.c b/src/device/mouse.c index 4ca2d0a6f..5250e5125 100644 --- a/src/device/mouse.c +++ b/src/device/mouse.c @@ -165,6 +165,31 @@ mouse_clear_buttons(void) mouse_delta_b = 0x00; } +static double +mouse_scale_coord_x(double x, int mul) +{ + double ratio = (double) monitors[0].mon_unscaled_size_x / (double) monitors[0].mon_res_x; + + if (mul) + x *= ratio; + else + x /= ratio; + + return x; +} + +static double +mouse_scale_coord_y(double y, int mul) +{ + double ratio = (double) monitors[0].mon_efscrnsz_y / (double) monitors[0].mon_res_y; + + if (mul) + y *= ratio; + else + y /= ratio; + + return y; +} void mouse_subtract_x(int *delta_x, int *o_x, int min, int max, int abs) { @@ -173,14 +198,14 @@ mouse_subtract_x(int *delta_x, int *o_x, int min, int max, int abs) double rsmin_x; double smin_x; - rsmin_x = (double) min; + rsmin_x = mouse_scale_coord_x(min, 0); if (abs) { - smax_x = (double) max + ABS(rsmin_x); + smax_x = mouse_scale_coord_x(max, 0) + ABS(rsmin_x); max += ABS(min); real_x += rsmin_x; smin_x = 0; } else { - smax_x = (double) max; + smax_x = mouse_scale_coord_x(max, 0); smin_x = rsmin_x; } @@ -189,13 +214,22 @@ mouse_subtract_x(int *delta_x, int *o_x, int min, int max, int abs) *o_x = 1; if (real_x > smax_x) { - *delta_x = abs ? (int) real_x : max; + if (abs) + *delta_x = (int) mouse_scale_coord_x(real_x, 1); + else + *delta_x = max; real_x -= smax_x; } else if (real_x < smin_x) { - *delta_x = abs ? (int) real_x : min; + if (abs) + *delta_x = (int) mouse_scale_coord_x(real_x, 1); + else + *delta_x = min; real_x += ABS(smin_x); } else { - *delta_x = (int) real_x; + if (abs) + *delta_x = (int) mouse_scale_coord_x(real_x, 1); + else + *delta_x = (int) mouse_scale_coord_x(real_x, 1); real_x = 0.0; if (o_x != NULL) *o_x = 0; @@ -221,14 +255,14 @@ mouse_subtract_y(int *delta_y, int *o_y, int min, int max, int invert, int abs) if (invert) real_y = -real_y; - rsmin_y = (double) min; + rsmin_y = mouse_scale_coord_y(min, 0); if (abs) { - smax_y = (double) max + ABS(rsmin_y); + smax_y = mouse_scale_coord_y(max, 0) + ABS(rsmin_y); max += ABS(min); real_y += rsmin_y; smin_y = 0; } else { - smax_y = (double) max; + smax_y = mouse_scale_coord_y(max, 0); smin_y = rsmin_y; } @@ -237,13 +271,22 @@ mouse_subtract_y(int *delta_y, int *o_y, int min, int max, int invert, int abs) *o_y = 1; if (real_y > smax_y) { - *delta_y = abs ? (int) real_y : max; + if (abs) + *delta_y = (int) mouse_scale_coord_y(real_y, 1); + else + *delta_y = max; real_y -= smax_y; } else if (real_y < smin_y) { - *delta_y = abs ? (int) real_y : min; + if (abs) + *delta_y = (int) mouse_scale_coord_y(real_y, 1); + else + *delta_y = min; real_y += ABS(smin_y); } else { - *delta_y = (int) real_y; + if (abs) + *delta_y = (int) mouse_scale_coord_y(real_y, 1); + else + *delta_y = (int) mouse_scale_coord_y(real_y, 1); real_y = 0.0; if (o_y != NULL) *o_y = 0; @@ -331,23 +374,13 @@ atomic_double_add(_Atomic double *var, double val) void mouse_scale_x(int x) { - double ratio_x = ((double) monitors[0].mon_unscaled_size_x) / monitors[0].mon_res_x; - - if (mouse_raw) - ratio_x /= plat_get_dpi(); - - atomic_double_add(&mouse_x, (((double) x) * mouse_sensitivity * ratio_x)); + atomic_double_add(&mouse_x, ((double) x) * mouse_sensitivity); } void mouse_scale_y(int y) { - double ratio_y = ((double) monitors[0].mon_efscrnsz_y) / monitors[0].mon_res_y; - - if (mouse_raw) - ratio_y /= plat_get_dpi(); - - atomic_double_add(&mouse_y, (((double) y) * mouse_sensitivity * ratio_y)); + atomic_double_add(&mouse_y, ((double) y) * mouse_sensitivity); } void