From 24ff4a24982dd2d091f1579b4727974fe1745315 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 12 Aug 2023 12:10:35 +0200 Subject: [PATCH 1/5] Make sure bit 3 of the first PS/2 mouse packet is always set. --- src/device/mouse_ps2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device/mouse_ps2.c b/src/device/mouse_ps2.c index f623d23e9..2d0f3c85d 100644 --- a/src/device/mouse_ps2.c +++ b/src/device/mouse_ps2.c @@ -86,7 +86,7 @@ ps2_report_coordinates(atkbc_dev_t *dev, int main) -256, 255, 1, 0); mouse_subtract_z(&delta_z, -8, 7, 1); - buff[0] = (overflow_y << 7) | (overflow_x << 6) | + buff[0] |= (overflow_y << 7) | (overflow_x << 6) | ((delta_y & 0x0100) >> 3) | ((delta_x & 0x0100) >> 4) | (b & ((dev->flags & FLAG_INTELLI) ? 0x07 : 0x03)); buff[1] = (delta_x & 0x00ff); From 01e7394101fefce582ba6c863fd3a66aeb474c8f Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 12 Aug 2023 15:59:29 +0200 Subject: [PATCH 2/5] 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 From 0ac3bb1620d94416c0f4b350a1147ea5e2ee4ca3 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 12 Aug 2023 17:56:44 +0200 Subject: [PATCH 3/5] More mouse fixes. --- src/device/mouse.c | 14 ++++++++++++-- src/device/mouse_ps2.c | 2 +- src/device/mouse_serial.c | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/device/mouse.c b/src/device/mouse.c index 5250e5125..ae68353fc 100644 --- a/src/device/mouse.c +++ b/src/device/mouse.c @@ -168,7 +168,11 @@ mouse_clear_buttons(void) 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; + double ratio = 1.0; + + if (!mouse_raw) + ratio = (monitors[0].mon_res_x * plat_get_dpi())/ + ((double) monitors[0].mon_unscaled_size_x); if (mul) x *= ratio; @@ -181,7 +185,11 @@ mouse_scale_coord_x(double x, int mul) static double mouse_scale_coord_y(double y, int mul) { - double ratio = (double) monitors[0].mon_efscrnsz_y / (double) monitors[0].mon_res_y; + double ratio = 1.0; + + if (!mouse_raw) + ratio = (monitors[0].mon_res_y * plat_get_dpi()) / + ((double) monitors[0].mon_efscrnsz_y); if (mul) y *= ratio; @@ -386,6 +394,8 @@ mouse_scale_y(int y) void mouse_scale(int x, int y) { + pclog("DPI = %lf (%lfx%lf)\n", plat_get_dpi(), monitors[0].mon_res_x, monitors[0].mon_res_y); + mouse_scale_x(x); mouse_scale_y(y); } diff --git a/src/device/mouse_ps2.c b/src/device/mouse_ps2.c index 2d0f3c85d..251459199 100644 --- a/src/device/mouse_ps2.c +++ b/src/device/mouse_ps2.c @@ -84,7 +84,7 @@ ps2_report_coordinates(atkbc_dev_t *dev, int main) mouse_subtract_coords(&delta_x, &delta_y, &overflow_x, &overflow_y, -256, 255, 1, 0); - mouse_subtract_z(&delta_z, -8, 7, 1); + mouse_subtract_z(&delta_z, -8, 7, 0); buff[0] |= (overflow_y << 7) | (overflow_x << 6) | ((delta_y & 0x0100) >> 3) | ((delta_x & 0x0100) >> 4) | diff --git a/src/device/mouse_serial.c b/src/device/mouse_serial.c index 0939bf875..91fdd498a 100644 --- a/src/device/mouse_serial.c +++ b/src/device/mouse_serial.c @@ -279,7 +279,7 @@ sermouse_report_ms(mouse_t *dev) int b = mouse_get_buttons_ex(); mouse_subtract_coords(&delta_x, &delta_y, NULL, NULL, -128, 127, 0, 0); - mouse_subtract_z(&delta_z, -8, 7, 1); + mouse_subtract_z(&delta_z, -8, 7, 0); dev->buf[0] = 0x40; dev->buf[0] |= (((delta_y >> 6) & 0x03) << 2); From 15b1262d9f574f09552a999d3443861fcc5886c8 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 12 Aug 2023 17:58:55 +0200 Subject: [PATCH 4/5] Win32 implementation of plat_get_dpi(). --- src/win/win.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/win/win.c b/src/win/win.c index 83135cd68..cf5c98f6f 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -1286,3 +1286,11 @@ endblit(void) { ReleaseMutex(ghMutex); } + +double +plat_get_dpi(void) +{ + UINT dpi = GetDeviceCaps(dc, LOGPIXELSX); + + return ((double) dpi) / 96.0; +} From 64fed5871a3d233aa08f541af3d160423ff4f478 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 12 Aug 2023 18:07:14 +0200 Subject: [PATCH 5/5] And reversed the ratios. --- src/device/mouse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/device/mouse.c b/src/device/mouse.c index ae68353fc..0f994ff27 100644 --- a/src/device/mouse.c +++ b/src/device/mouse.c @@ -171,8 +171,8 @@ mouse_scale_coord_x(double x, int mul) double ratio = 1.0; if (!mouse_raw) - ratio = (monitors[0].mon_res_x * plat_get_dpi())/ - ((double) monitors[0].mon_unscaled_size_x); + ratio = ((double) monitors[0].mon_unscaled_size_x) / + (monitors[0].mon_res_x * plat_get_dpi()); if (mul) x *= ratio; @@ -188,8 +188,8 @@ mouse_scale_coord_y(double y, int mul) double ratio = 1.0; if (!mouse_raw) - ratio = (monitors[0].mon_res_y * plat_get_dpi()) / - ((double) monitors[0].mon_efscrnsz_y); + ratio = ((double) monitors[0].mon_efscrnsz_y) / + (monitors[0].mon_res_y * plat_get_dpi()); if (mul) y *= ratio;