# <Solved> Set mouse acceleration on hotplug via hal/udev

## jw5801

Under xorg-server-1.5.3-r5 I'm attempting to adjust acceleration on my usb mouse whenever it's plugged in.

Running the following manually in a terminal has the desired effect:

```
xset m 1 1
```

I can't seem to find any way to tell the evdev driver the same things, if there is one, let me know, it would be much simpler. My input device configuration (using hal) can be seen below

/etc/hal/fdi/policy/10-input-policy.fdi:

```

<?xml version="1.0" encoding="UTF-8"?>

<deviceinfo version="0.2">

  <device>

    <match key="info.capabilities" contains="input">

      ...

      <match key="info.capabilities" contains="input.mouse">

        <match key="info.product" contain="MX610 Laser Cordless Mouse">

          <merge key="input.x11_driver" type="string">evdev</merge>

          <merge key="input.x11_options.RelHWHEELOptions" type="string">invert</merge>

        </match>

      </match>

      ...

    </match>

  </device>

</deviceinfo>

```

Since I can't seem to set the acceleration using hal, I've attempted to use udev to run the command when the mouse is plugged in. The following file sets up a command to be run whenever a mouse is added to the system.

/etc/udev/rules.d/92-mouse-noaccel.rules:

```
ACTION=="add", SUBSYSTEM=="input", ENV{ID_CLASS}="mouse", RUN+="xset m 1 1"
```

The command "xset m 1 1" is run (for debug I've put other commands that can more obviously be seen to have run, and they do), but seems to be overruled by hal, or something else, immediately after. Getting it to run a script in the background, with a "sleep 5" before the "xset m 1 1" also appears to have no effect.

I'm somewhat at a loss as to how I can automate this, anyone have any ideas?Last edited by jw5801 on Fri May 01, 2009 5:32 pm; edited 1 time in total

----------

## jw5801

Bump? Still can't figure this one out. Hoping for some inspiration!

----------

## dob

Your udev xset command probably fails because of some DISPLAY issue.

It might work if you specified the display and resolved the access control complexities involved.

Did you try to pass the sensitivity or resolution options from xorg.conf in the fdi?

Resolution http://ftp.x.org/pub/X11R6.9.0/doc/html/mouse5.html#24

Sensitivity http://blog.khax.net/2009/02/08/adjusting-mouse-and-touchpad-speed-in-xorgconf/

----------

## jw5801

Neither the resolution nor sensitivity options do anything as far as I can tell; they're for the `mouse' driver, rather than `evdev'. Can't use them to adjust the acceleration, anyhow.

I think you might be onto something with the DISPLAY issue, as I can't get it to run an xterm or any other X app. Can't fix it just by telling it about the DISPLAY though. Is there anything else I should be telling it?

```
ACTION=="add", SUBSYSTEM=="input", ENV{ID_CLASS}="mouse", RUN+="DISPLAY=:0.0 /usr/bin/xterm"
```

----------

## dob

 *jw5801 wrote:*   

> Neither the resolution nor sensitivity options do anything as far as I can tell; they're for the `mouse' driver, rather than `evdev'. Can't use them to adjust the acceleration, anyhow.

 Then one solution could be to get hal/xorg to use the mouse driver instead of evdev  :Very Happy:  (If you know how to do that, then I'm interested, see https://forums.gentoo.org/viewtopic-t-760265.html )

 *Quote:*   

> I think you might be onto something with the DISPLAY issue, as I can't get it to run an xterm or any other X app. Can't fix it just by telling it about the DISPLAY though. Is there anything else I should be telling it?
> 
> ```
> ACTION=="add", SUBSYSTEM=="input", ENV{ID_CLASS}="mouse", RUN+="DISPLAY=:0.0 /usr/bin/xterm"
> ```
> ...

 I'd try running 'xhost +' in the Xsession beforehand (it's not secure but it's just for the sake of seeing if that helps)

----------

## truc

I don't know how udev try to run that command, but it may try to execute DISPLAY=:0, which is not what you want. Did you try try to put this command into a shell script and see if that helps?

(or may be even something like RUN+="/bin/bash -c 'DISPLAY=:0.0 /usr/bin/xterm'" might work? )

----------

## jw5801

 *dob wrote:*   

>  *jw5801 wrote:*   I think you might be onto something with the DISPLAY issue, as I can't get it to run an xterm or any other X app. Can't fix it just by telling it about the DISPLAY though. Is there anything else I should be telling it?
> 
> ```
> ACTION=="add", SUBSYSTEM=="input", ENV{ID_CLASS}="mouse", RUN+="DISPLAY=:0.0 /usr/bin/xterm"
> ```
> ...

 

 *truc wrote:*   

> I don't know how udev try to run that command, but it may try to execute DISPLAY=:0, which is not what you want. Did you try try to put this command into a shell script and see if that helps?
> 
> (or may be even something like RUN+="/bin/bash -c 'DISPLAY=:0.0 /usr/bin/xterm'" might work? )

 

I realised that I can't talk to the display server as root (not without running `xhost +' anyway), so I'm trying to run the command as my user account for now (single user machine, so doesn't really matter that this isn't the most graceful way to do it). Didn't really help though.

No, wait, scratch that, I forgot that udev can't find `su' on it's own. We have success! The command which is successfully executed is:

```
ACTION=="add", SUBSYSTEM=="input", ENV{ID_CLASS}="mouse", RUN+="/bin/su jw -l -c 'DISPLAY=:0.0 /usr/bin/xset m 1 1'"
```

Awesome, thanks for the assistance!

 *dob wrote:*   

>  *jw5801 wrote:*   Neither the resolution nor sensitivity options do anything as far as I can tell; they're for the `mouse' driver, rather than `evdev'. Can't use them to adjust the acceleration, anyhow. Then one solution could be to get hal/xorg to use the mouse driver instead of evdev  (If you know how to do that, then I'm interested, see https://forums.gentoo.org/viewtopic-t-760265.html )

 

I'm using `evdev' because it correctly configures most of the buttons on my mouse (back and forwards buttons, horizontal scroll wheel, volume buttons), so I'd rather not use `mouse'. Shouldn't be too difficult to change though, set it in your hal policy?

```
<match key="info.capabilities" contains="input.mouse">

    <merge key="input.x11_driver" type="string">mouse</merge>

</match>
```

If that's not working, then I have no idea.

----------

