hrvach / deskhop

Fast Desktop Switching Device
GNU General Public License v3.0
6.14k stars 173 forks source link

Possible bug on mouse acceleration #80

Closed lvntbkdmr closed 6 months ago

lvntbkdmr commented 6 months ago

Hey, I found a possible bug on mouse acceleration function. As acceleration is enabled by default, I experienced a strange behavior when I moved my mouse right-left or up-down fast that it drifts to the right and down directions (positive movement). I first thought it was because of some hardware interference (a noise maybe idk). Than I decided to implement a low pass filter on the software-side. At that moment I realized that in accelerate function inside mouse.c it checks whether the given offset checks (lower than) one of the values inside the array, than it is multiplied by its associated factor. However that offset can also be negative (mouse up, or left movement). In that case it always get multiplied with 1 (which is the first element in array). That results in slow and not accelerated movement in negative directions.

I suggest to change the offset check condition by using its absolute value in that function

diff --git a/src/mouse.c b/src/mouse.c
index 2801b5f..2d1093e 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -52,7 +52,7 @@ int32_t accelerate(int32_t offset) {
         return offset;

     for (int i = 0; i < 7; i++) {
-        if (offset < acceleration[i].value) {
+        if (abs(offset) < acceleration[i].value) {
             return offset * acceleration[i].factor;
         }
     }
hrvach commented 6 months ago

Thank you, this is a great find! Will fix in the next release.