Michael Toomim <[EMAIL PROTECTED]> writes:
> Proposal: Add a boolean option to XF86Config called
> "UseSmoothMouseAccel" that changes the behavior of xset. If this
> variable is set to true, the command `xset m [A] [B]' will mean "set the
> cursor movement function to `[A] * raw_mouse_speed^[B]'".
Back in May this year I sent the mail below to [EMAIL PROTECTED], but
I never got any response.
S�ren
From: Soeren Sandmann <[EMAIL PROTECTED]>
Subject: Smoother mouse acceleration
To: [EMAIL PROTECTED]
The current mouse acceleration algorithm when the user defined
threshold is non-zero is essentially this:
if (d > t)
d' = A * d
else
d' = d;
where d' is the new traveled distance, and d the distqance reported by
the mouse. The constant t is the user defined threshold, and A
(= num/den) is the user defined amount of acceleration.
There are some problems with this:
- if you set the threshold high, the mouse cursor feels
sticky. If you move the mouse at just the right speed, you
will se jerky cursor movements as the traveled distance
oscillates around the threshold.
- if you set the threshold low and the acceleration high, you
lose precision as the cursor moves too fast even on small
movements.
- if you set the acceleration low, it gets difficult to reach
to corners of the screen.
So, while this isn't terribly bad, it not really good either
Here is a patch that modifies the mouse acceleration code to use the
formula
d' = c * d^alpha + d
where d' is the new distance and d is the distance reported by the
mouse. The constants c and alpha are based on the acceleration
settings, specifically
c = 1 / (threshold / 4) ^alpha
which ensures that when the travelled distance is less then
threshold/4, the distance is not modified by more than 1. This ensures
that the threshold set by the user still corresponds to the precision
of the device.
The constant alpha is just a linear function of the user set
acceleration.
The patch also changes the default acceleration to 8/3 3, which in my
opinion is a more useful setting than 2/1 4, which is the current
default.
S�ren
--- ../../../xcoriginal/programs/Xserver/hw/xfree86/common/xf86Xinput.c Tue May 21 01:50:43 2002
+++ ./hw/xfree86/common/xf86Xinput.c Tue May 21 01:49:00 2002
@@ -905,15 +905,42 @@
/*
* Accelerate
*/
- if (device->ptrfeed && device->ptrfeed->ctrl.num) {
- /* modeled from xf86Events.c */
- if (device->ptrfeed->ctrl.threshold) {
- if ((abs(dx) + abs(dy)) >= device->ptrfeed->ctrl.threshold) {
- valuator[0] = (dx * device->ptrfeed->ctrl.num) /
- device->ptrfeed->ctrl.den;
- valuator[1] = (dy * device->ptrfeed->ctrl.num) /
- device->ptrfeed->ctrl.den;
+ if (device->ptrfeed && device->ptrfeed->ctrl.num && device->ptrfeed->ctrl.den) {
+ if (device->ptrfeed->ctrl.num <= device->ptrfeed->ctrl.den) {
+ valuator[0] = (dx * device->ptrfeed->ctrl.num) / device->ptrfeed->ctrl.den;
+ valuator[1] = (dy * device->ptrfeed->ctrl.num) / device->ptrfeed->ctrl.den;
+ }
+ else if (device->ptrfeed->ctrl.threshold) {
+ static int cached_num = -1;
+ static int cached_den = -1;
+ static int cached_threshold = -1;
+
+ static double c = -1;
+ static double alpha = -1;
+
+ double k;
+
+ if (cached_num != device->ptrfeed->ctrl.num ||
+ cached_den != device->ptrfeed->ctrl.den ||
+ cached_threshold != device->ptrfeed->ctrl.threshold) {
+
+ double A, t;
+
+ cached_num = device->ptrfeed->ctrl.num;
+ cached_den = device->ptrfeed->ctrl.den;
+ cached_threshold = device->ptrfeed->ctrl.threshold;
+
+ A = (double)cached_num / cached_den;
+ t = (double)cached_threshold;
+
+ alpha = A/3.0 + 2.0/3.0;
+ c = 1 / pow (t/4.0, alpha);
}
+
+ k = c * pow (dx*dx + dy*dy, 0.5 * (alpha - 1)) + 1;
+
+ valuator[0] = k * dx;
+ valuator[1] = k * dy;
}
else if (dx || dy) {
mult = pow((float)(dx*dx+dy*dy),
--- ../../../xcoriginal/programs/Xserver/include/site.h Tue May 21 01:50:43 2002
+++ ./include/site.h Tue May 21 01:17:48 2002
@@ -113,9 +113,9 @@
#define DEFAULT_INT_MAX_VALUE 100
#define DEFAULT_INT_DISPLAYED 0
-#define DEFAULT_PTR_NUMERATOR 2
-#define DEFAULT_PTR_DENOMINATOR 1
-#define DEFAULT_PTR_THRESHOLD 4
+#define DEFAULT_PTR_NUMERATOR 8
+#define DEFAULT_PTR_DENOMINATOR 3
+#define DEFAULT_PTR_THRESHOLD 3
#define DEFAULT_SCREEN_SAVER_TIME (10 * (60 * 1000))
#define DEFAULT_SCREEN_SAVER_INTERVAL (10 * (60 * 1000))