diff options
| author | Javier <dev.git@javispedro.com> | 2026-10-11 01:38:53 +0200 |
|---|---|---|
| committer | Javier <dev.git@javispedro.com> | 2026-10-11 01:38:53 +0200 |
| commit | 041bd26ca840f5efd477b6d80dc264c6cd09a7e0 (patch) | |
| tree | 8ea1db799cf91f245f017fa5f02a8e00e4eb24e5 | |
| parent | 9ec2bc913cd57f6f09f79cd673b0327d9cc2fcbf (diff) | |
| download | vbados-041bd26ca840f5efd477b6d80dc264c6cd09a7e0.tar.gz vbados-041bd26ca840f5efd477b6d80dc264c6cd09a7e0.zip | |
also store the remainder of the sensitivity division, as it smooths movement for low sensitivity values
| -rw-r--r-- | mousetsr.c | 38 | ||||
| -rw-r--r-- | mousetsr.h | 5 |
2 files changed, 23 insertions, 20 deletions
@@ -71,17 +71,11 @@ static void bound_position_to_window(void) * I am going with f(x) = x(x+32)/4096 since it looks round and fits decently, * even with integer math (we don't divide by 4096 until after multiplying by delta). * @see INT33_SET_MOUSE_SENSITIVITY for what the factor should look like. */ -int16_t apply_sensitivity(int16_t x, uint8_t sens) +int16_t apply_sensitivity(int16_t x, uint8_t sens, int16_t *rem) { uint16_t factor = (sens * (sens + 32)); -#if 1 - // use shift by 12 rather than divide by 4096 - // unsigned math, otherwise negative values would round down when shifted - uint16_t scaled = scaleu_shift(abs(x), 12 /*4096*/, factor); - return x < 0 ? -scaled : scaled; -#else - return scalei(x, 4096, factor); -#endif + // TODO Actually use a shift instead of division + return scalei_rem(x, 4096, factor, rem); } /** Constraints coordinate value to the desired granularity, @@ -648,8 +642,10 @@ static void handle_mouse_event(uint16_t buttons, bool absolute, int x, int y, ch // Set the new absolute position data.pos.x = x; data.pos.y = y; - data.pos_frac.x = 0; - data.pos_frac.y = 0; + data.pos_pixel_frac.x = 0; + data.pos_pixel_frac.y = 0; + data.pos_sens_frac.x = 0; + data.pos_sens_frac.y = 0; } } else if (x || y) { // Relative movement: x,y are in mickeys @@ -671,8 +667,8 @@ static void handle_mouse_event(uint16_t buttons, bool absolute, int x, int y, ch data.total_motion += ax * ax + ay * ay; // Apply sensitivity now, since unlike acceleration/speed, it affects the raw mickey counters - x = apply_sensitivity(x, data.sensitivity_x); - y = apply_sensitivity(y, data.sensitivity_y); + x = apply_sensitivity(x, data.sensitivity_x, &data.pos_sens_frac.x); + y = apply_sensitivity(y, data.sensitivity_y, &data.pos_sens_frac.y); // Update the raw mickey counters data.delta.x += x; @@ -692,8 +688,8 @@ static void handle_mouse_event(uint16_t buttons, bool absolute, int x, int y, ch } // Apply mickeysPerLine. Keep the fractional part for the next movement! - data.pos.x += scalei_rem(x, data.mickeysPerLine.x, 8, &data.pos_frac.x); - data.pos.y += scalei_rem(y, data.mickeysPerLine.y, 8, &data.pos_frac.y); + data.pos.x += scalei_rem(x, data.mickeysPerLine.x, 8, &data.pos_pixel_frac.x); + data.pos.y += scalei_rem(y, data.mickeysPerLine.y, 8, &data.pos_pixel_frac.y); } bound_position_to_window(); @@ -1226,8 +1222,10 @@ static void reset_mouse_state() int i; data.pos.x = data.min.x + (data.max.x - data.min.x) / 2; data.pos.y = data.min.y + (data.max.y - data.min.y) / 2; - data.pos_frac.x = 0; - data.pos_frac.y = 0; + data.pos_pixel_frac.x = 0; + data.pos_pixel_frac.y = 0; + data.pos_sens_frac.x = 0; + data.pos_sens_frac.y = 0; data.delta.x = 0; data.delta.y = 0; data.abs_pos.x = -1; @@ -1348,8 +1346,10 @@ static void int33_handler(union INTPACK r) #endif data.pos.x = r.w.cx; data.pos.y = r.w.dx; - data.pos_frac.x = 0; - data.pos_frac.y = 0; + data.pos_pixel_frac.x = 0; + data.pos_pixel_frac.y = 0; + data.pos_sens_frac.x = 0; + data.pos_sens_frac.y = 0; data.delta.x = 0; data.delta.y = 0; bound_position_to_window(); @@ -192,7 +192,10 @@ typedef struct tsrdata { struct point pos; /** Current remainder of movement that does not yet translate to an entire pixel * (8ths of pixel). */ - struct point pos_frac; + struct point pos_pixel_frac; + /** Current remainder of movement that does not yet translate to one sensitivity unit (4096) + * @see apply_sensitivity */ + struct point pos_sens_frac; /** Current delta movement (in mickeys) since the last report. */ struct point delta; /** Last absolute position (to compute a delta for relative motion emulation). Using -1 for "none". */ |
