Re: [AD] set_mouse_speed for X

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


On Wed, 2006-12-13 at 13:42 +0100, Elias Pschernig wrote:
> Thanks. Seems to work, but can you explain how it works? E.g. why do you
> need a temporary file?
> 
> Also, it probably can't be applied directly like that, since we have a
> standard way to create a tempfile I think, but that should be easy to
> fix.
> 
> Another question is, why not use a direct X11 API call instead of xset?
> 
> And also, will this patch cause the mouse behavior of existing programs
> to change in any way?

I used xset because that's what was written in xmouse.c originally. It
said "use xset with m option" or something similar. It does not affect
existing Allegro programs. And I have attached a new patch that uses the
X11 API directly instead of xset. I know you may not use it as it does
affect all the other programs the user is running at the time too,
although it resets the mouse to the original speed at the end of the
program. Adjusting the speed for just one program has proven too
difficult for me as I'm not very familiar with the Allegro internals.
--- 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);
+
+   tenths = (mouse_mult / mouse_div * 10) + (mouse_mult % mouse_div);
+   tenths -= (speed-2) * 5;
+   tenths = MIN(100, MAX(0, tenths));
+
+   XChangePointerControl(_xwin.display, 1, 1, tenths,
+      10, mouse_threshold);
 }
 
 


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