Optimising mouse control in Xorg

I decided to make a quick write up of one of FreeBSD's jewels — moused(8). I stand to be corrected, but I don't think the other BSDs nor linux have anything like it, and it makes mousing under X a lot more pleasant.

If you're a X user you should already be familiar with its builtin mouse acceleration support. Most desktop environments have control panels to configure it, but here's the bad news — it sucks! It's a feature that runs your mouse at a low sensitivity when it's moving slowly, but increases the sensitivity when it accelerates beyond a set threshold to make the pointer move quicker. So it only has only two levels: slow and fast.

FreeBSD's mouse daemon
FreeBSD's mouse daemon has a couple of very neat features:
  • Multiplexes multiple mice into one mouse device (useful for notebooks).
  • Provides mouse support for syscons(4)
  • Emulates 3 buttons on a 2 button mouse (same as X's implementation)
  • Provides fine grained mouse sensitivity control
  • Provides exponential (or dynamic) acceleration
  • Provides virtual scrolling
I'm going to be speaking about the last 3 points here. Now before I continue you need to make sure your X is setup correctly so that it uses moused and doesn't interfere with moused's acceleration features. I'm going to assume you're using a USB mouse.

Preparing...
When you plug your mouse in, FreeBSD should automatically spawn a mouse daemon process and attach it to your ums device:

Code:
$ ps -wwp $(pgrep moused)
  PID  TT  STAT      TIME COMMAND
98163  ??  Ss     3:27.46 /usr/sbin/moused -F 200 -A 1.5,2.0 -a 0.7 -r high -V -p /dev/ums0 -t auto -I /var/run/moused.ums0.pid

That's how mine looks after my customising. To change the defaults you need to edit rc.conf:

Code:
$ grep moused /etc/rc.conf
moused_ums0_flags="-F 200 -A 1.5,2.0 -a 0.7 -r high -V"

I'll come back to exactly what settings you'll be playing with in a second. For now you just need to make sure the mouse daemon is running. Next you need to make sure your X configuration is using it:

Code:
Section "InputDevice"
        Identifier      "Configured Mouse"
        Driver          "mouse"
        Option          "CorePointer"
        Option          "Device" "/dev/sysmouse"
        Option          "Protocol" "auto"
        Option          "Emulate3Buttons" "false"
EndSection

That should be the only pointing device in xorg.conf (unless you know what you're doing). You'll notice /dev/sysmouse in your dev filesystem — moused creates this. It is a virtual mouse device where the daemon sends all mousey data for X to use.

So moused is running and Xorg is using it. Now you need to disable X's own mouse acceleration. If you're running a desktop environment like GNOME, KDE, or Xfce there is a mouse configuration GUI where you should do this. Set the mouse acceleration and threshold all the way to minimum.

If you don't have a mouse configuration GUI then open a terminal and run
Code:
xset m 1/1 1
and add that to your startup script.

In a terminal run the following to check that your mouse acceleration is set correctly:

Code:
$ xset q |grep -A 1 ^Pointer
Pointer Control:
  acceleration:  1/1    threshold:  1

Play time!

Base mouse sensitivity
How does your mouse feel now? Too slow? Too fast? You're going to set the base sensitivity first. The mouse should feel slow at this stage. Too slow to use X, but fast enough to, say, touch up a few pixels of a graphic. To adjust the sensitivity you need to add the -a parameter to rc.conf. Values below 1.0 desensitize your mouse. Values above 1.0 increase sensitivity. Take another look at my -a setting above — I had to desensitize my mouse, hence 0.7. Edit rc.conf as shown above and then run /etc/rc.d/moused restart ums0 (assuming your mouse device is ums0). Your mouse daemon should be running with the new setting and things should be feeling better. If not, try another setting until you're happy. Remember, the mouse must feel slow at this stage.

Mouse acceleration
This is the best part: the -A parameter. It takes two values separated by a comma as seen in my config. The first value is the magnitude of acceleration, the second value is the movement threshold required to activate acceleration. Try my settings (1.5,2.0) to start with and experiment with the values until you're happy. As you're experimenting you should already be thinking, "Damn, how did I live without this for so long??"

Virtual scrolling
And now, the cherry on the top. Virtual scrolling! No more having to motor your mouse wheel like a wheelchair racing gold medallist. Virtual scrolling is enabled with the -V parameter. If you've setup your mouse acceleration and sensitivity nicely, the virtual scrolling defaults should be satisfactory. Now that you've enabled it, click and hold your middle mouse button in your web browser and move the mouse up and down. Awesome huh?

There are a few other useful features you might want to experiment with. Go ahead and browse through the moused(8) manual to find out more. Don't forget to ensure that Xorg's builtin mouse acceleration remains disabled. Enjoy!

(this post is a copy of my blog post)
 
200Hz is the maximum sample rate for PS/2 mice, so I'd use it with psm0. PS/2 mice are normally sampled with 80Hz, changing it to 200Hz makes a huge difference.

The default sample rate for USB is 125Hz. A decent value is 500Hz or 1000Hz for gaming mice like a Razer.

These are the rc.conf settings for my notebook:
Code:
# Activate moused for the touchpad.
moused_enable="YES"
# Touchpad tracking from 80Hz to 200Hz.
moused_flags="-3 -F 200"
# USB mouse tracking from 125Hz to 1kHz.
moused_ums0_flags="-F 1000 -r 2000"

Now, to make use of the higher sample rates, you should also adjust them in your xorg.conf file.
Code:
Section "InputDevice"
	Identifier	"SysMouse"
	Driver		"mouse"
	Option		"Protocol" "auto"
	Option		"Device" "/dev/sysmouse"
	Option		"ZAxisMapping" "4 5 6 7"
	Option		"SampleRate"	"1000"
	Option		"Resolution"	"2000"
EndSection
 
I always thought/assumed moused was just for getting the mouse work with syscons, and I hadn't looked at the manpage ever since started with FreeBSD yeeaaars ago.

I never knew it's full potential! Thanks for showing it to me!
 
aragon said:
If the latter, usually it's one of ~/.xinit or ~/.xsession.

Hello,

Does anyone know which of these two file I need to edit? I am using KDE. Also, where in the file do I issue this command?

It seems to me that people are cagey about the answer to these questions. If possible, answer my question with definitive and clear answers, like the kind I get from the FreeBSD manual.

Thank you again for helping a novice. I want to do things the right way.

Chris
 
chrisstankevitz said:
Does anyone know which of these two file I need to edit? I am using KDE. Also, where in the file do I issue this command?

It seems to me that people are cagey about the answer to these questions. If possible, answer my question with definitive and clear answers, like the kind I get from the FreeBSD manual.
Actually people are only able to provide information in the same context a question is asked. A manual too can only answer questions if the readers extract information from it in the same context the manual was written, eg. you wouldn't expect to find a linux installation guide in the FreeBSD manual. How was I to know you run KDE? You never mentioned it. My answer was the most generic answer possible given the ambiguous, generic information you provided.

Editing either of those files will probably not work with KDE because the setting will get overridden when it starts up. I don't know what file you can edit for KDE to apply the same setting, but if its mouse configuration GUI tool (whatever it's called) indicates "acceleration" and "threshold" values, you need to adjust them until acceleration is 1.0. (or the equivalent ratio)
 
Interesting topic I just dug out.

I decided to make a quick write up of one of FreeBSD's jewels — moused(8). I stand to be corrected, but I don't think the other BSDs nor linux have anything like it, and it makes mousing under X a lot more pleasant.

Things have progressed somewhat since 2008, but the OP was totally right. The other BSDs at the time were miles away, and linux didn't even come close :\. I'm still a bit of a perfectionist and am not 100% satisfied with mousing under X, but then again I'm never 100% satisfied with anything :)


chrisstankevitz said:
Hello,

Does anyone know which of these two file I need to edit? I am using KDE. Also, where in the file do I issue this command?

It seems to me that people are cagey about the answer to these questions. If possible, answer my question with definitive and clear answers, :) like the kind I get from the FreeBSD manual.

Thank you again for helping a novice. I want to do things the right way.

Chris
 
...very helpful. One problem I have encountered is when enabling virtual scrolling some (default) key bindings in fluxbox seem to break. For example, I'm unable to manipulate tabs with Mouse2. I could be wrong. I just noticed this stopped working a few days after enabling virtual scrolling, but I could have messed something else up. Has anyone else come across this problem?
 
It was the virtual scrolling that screwed up the tabbing, so I just ended up using an alternative key binding.

Code:
OnTitlebar Control Mouse1 :StartTabbing
 
If find yourself moving your mouse cursor out of the way because it's blocking text or anything else on the screen, you can have it disappear after a certain idle time with a nice simple program in the ports tree: misc/unclutter. Just put something like unclutter -idle 1 in ~/.xinitrc and your all set.

unclutter man page
 
Back
Top