The almost 10 year old mouse wheel bug in FreeBSD nobody cares about
When I first discovered this bug I first thought it was just a questionable key binding decision by GhostBSD author Eric Turgeon.
But as it turned out this is a real bug.
So what exactly is this bug? When you use your mouse wheel to scroll down it works perfectly fine but if you scroll up any program you are in just moves back and forth, e.g. up and down in directories in the file explorer or back and forward in your web browser.
I was not the first to discover this bug, it is at least known since September of 2016. Here are some links that I attribute to it:
- 09/2016: FreeBSD Forums: mouse wheel strange behavior with firefox
- 12/2016: VirtualBox Forums: FreeBSD/TrueOS mouse wheel issues browser back command
- 10/2018: FreeBSD Forums: Sudden mouse movement change page in Web browsers
- 07/2019: KDE Community: Mouse wheel *scroll up* always jumps to cursor
- 06/2021: reddit: Anyone else having weird behaviour with scrolling the mouse wheel causing other actions?
- 12/2021: Google Groups: Bizarro Problem With Libinput
In the maner of VirtualBox user Oclair I also used the X Event Viewer tool (xev) to see what's going on. Turns out when you scroll down only button 5 is sent but if you scroll up 3 buttons at once are sent, namely button 4, 8 and 9. I also made a video recording of it.
But why is it so rarely noticed by anyone? There are 2 reasons:
- Only PS/2 mice are affected
- Only FreeBSD in connection with X11/XLibre is affected
Fist reason is clear, nobody (except me with my ca. 22 year old mouse) uses a PS/2 mouse anymore. But what about VirtualBox and QEMU, isn't their default device a PS/2 mouse? Yes, but that leads to the second reason, very few people virtualize their FreeBSD under the VirtualBox hypervisor and the QEMU emulator, and when they do it's mostly a server without a desktop environment and therefore the mouse isn't even required. Maybe this isn't true for Proxmox which uses QEMU/KVM under the hood.
A fellow BSD user suggested that the problem could be in a commit from 2016 regarding support for Elantech trackpads.
One solution was to remove the xf86-input-libinput package which will break newer devices like touchscreens and tablets, but these are not really relevant in a virtual machine. Then supposedly the mouse falls back to the xf86-input-mouse driver which likely has a patch for the supposed bug in the FreeBSD psm(4) driver.
My personal solution was to switch to a USB mouse with this option added to the QEMU configuration:
-usbdevice mouseIf somebody can pin down the exact location where this bug originates, please write down in the comments.
Update 05/27/2026:
Yesterday FreeBSD user b-aaz proposed a workaround in psm.c by adding a sysctl kernel parameter. The Elantech commit wasn't the issue by the way, it must be somewhere in the virtual PS/2 mouse drivers.
This kernel parameter will turn off the side buttons of the virtual PS/2 device which emulates the Microsoft IntelliMouse Explorer. This mouse has two extra buttons on the left side which by default will navigate back and forward, e.g. in the browser.
When we look at the relevant psm.c code we can see how data which is sent by the IntelliMouse is interpreted.
switch (sc->hw.model) {
case MOUSE_MODEL_EXPLORER:
/*
* b7 b6 b5 b4 b3 b2 b1 b0
* byte 1: oy ox sy sx 1 M R L
* byte 2: x x x x x x x x
* byte 3: y y y y y y y y
* byte 4: * * S2 S1 s d2 d1 d0
*
* L, M, R, S1, S2: left, middle, right and side buttons
* s: wheel data sign bit
* d2-d0: wheel data
*/
So bit 4 and bit 5 in byte 4 represent the both side buttons on the mouse and somehow these bits are accidentally set when you scroll up or down. Why down now? Because today I also tested it in VirtualBox and there the effect is visible while scrolling up and down. I also tried to boot GhostBSD with a real PS/2 mouse but unfortunately the mouse was not responsive at all so I couldn't test the mouse wheel.
VirtualBox states in its FAQs that they use some device drivers from QEMU. But the PS/2 mouse driver doesn't seem to be shared because the code looks different. When you look at the code of both device drivers you can see that it was not really clear how to interpret the data that the original mouse is sending, probably because of the mouse wheel which could be tilted sideways for horizontal scrolling.
New Scroll Wheel With Tilt Wheel Technology
This year, Microsoft is reinventing the scroll wheel, the No. 1 feature users want in a mouse,* with proprietary Tilt Wheel Technology. Featuring a revolutionary design, the scroll wheel takes a turn for the better with these features:
- Unprecedented navigation capabilities, delivering vertical and now horizontal scrolling in a single wheel — useful for navigating long Web pages or spreadsheets
Maybe this was not the best mouse to choose as the standard mouse for virtualization. There are some interesting comments about the IntelliMouse Explorer in the QEMU and VirtualBox source code which could explain the wrong settings of the S1 and S2 bits.
Comments
Post a Comment