Re: [AD] set_mouse_speed for X

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Fri, 2006-12-22 at 13:54 +0100, Elias Pschernig wrote:
> I'm not so sure it won't change existing programs. There's apparently a
> call to set_mouse_speed(2, 2) in install_mouse(), so..
> 
>    speed = MAX(0, (xspeed + yspeed) / 2);
> 
>    tenths = (mouse_mult / mouse_div * 10) + (mouse_mult % mouse_div);
>    tenths -= (speed-2) * 5;
>    tenths = MIN(100, MAX(0, tenths));

Oops. That second line should be:
tenths = (mouse_mult * 10 / mouse_div);

> E.g. assume, the speed initially is 5/2 (that's what I actually do get).
> Now, by the above code:
> speed = (2+2)/2 = 2
> tenths = (5/2*10) + (5%2) = 21

Fixed.

> Also, I don't understand why 5/2 isn't converted to 25/10, and what the
> MIN/MAX is for.

The MIN keeps the speed from going too high. The mouse becomes useless
if you go above 10x acceleration. The MAX keeps the acceleration from
going below zero.. actually that may not be desired.

New patch attached.
--- xmouse.c	2005-03-15 11:37:18.000000000 -0700
+++ /home/trent/allegro-4.2.1/src/x/xmouse.c	2006-12-13 09:53:46.000000000 -0700
@@ -40,7 +40,9 @@
 static int mymickey_x = 0;
 static int mymickey_y = 0;
 
-
+static int mouse_mult = -1;       /* mouse acceleration multiplier */
+static int mouse_div = -1;        /* mouse acceleration divisor */
+static int mouse_threshold = -1;  /* mouse acceleration threshold */
 
 static int _xwin_mousedrv_init(void);
 static void _xwin_mousedrv_exit(void);
@@ -132,6 +134,10 @@
  */
 static void _xwin_mousedrv_exit(void)
 {
+   if (mouse_mult >= 0)
+      XChangePointerControl(_xwin.display, 1, 1, mouse_mult,
+         mouse_div, mouse_threshold);
+
    XLOCK();
 
    _xwin_mouse_interrupt = 0;
@@ -190,10 +196,24 @@
 
 /* _xwin_mousedrv_set_speed:
  *  Sets the speed of the mickey-mode mouse.
+ *  Each step slows down or speeds the mouse up by 0.5x.
  */
 static void _xwin_mousedrv_set_speed(int xspeed, int yspeed)
 {
-   /* Use xset utility with "m" option.  */
+   int speed;
+   int tenths;
+
+   if (mouse_mult<0)
+      XGetPointerControl(_xwin.display, &mouse_mult, &mouse_div, &mouse_threshold);
+
+   speed = MAX(0, (xspeed + yspeed) / 2);
+
+   if (mouse_div == 0)
+      tenths = mouse_mult * 10;
+   else
+      tenths = (mouse_mult * 10 / mouse_div);
+   tenths -= (speed-2) * 5;
+   tenths = MIN(100, tenths);
+
+   XChangePointerControl(_xwin.display, 1, 1, tenths,
+      10, mouse_threshold);
 }
 
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/