Index | Thread | Search

From:
Crystal Kolipe <kolipe.c@exoticsilicon.com>
Subject:
Obscure X11 bug with PS/2 keyboard and mousekeys
To:
tech@openbsd.org
Date:
Tue, 03 Jun 2025 03:27:55 -0300

Download raw body.

Thread
This is a difficult bug to encounter, but nevertheless...


Background info:

X11 has a 'mousekeys' feature, which allows the user to control the mouse
pointer using, (by default), the numeric keypad.  It's configured with a line
such as this in .Xmodmap:

keycode 108 = Pointer_EnableKeys Pointer_Accelerate

Pointer_EnableKeys toggles the function on and off, and Pointer_Accelerate
toggles between two modes, accelerated, where the pointer moves faster the
longer a key is held down, and unaccelerated where it always moves one pixel
at a time.


Bug:

When using a USB keyboard, it all works as expected.

When using a PS/2 keyboard, the pointer movement is erratic:

Holding down a directional key, the pointer moves and accelerates for about a
second, then stops, and starts again for about half a second, then repeats
this sequence endlessly.  Note that the initial 'jump' is longer than any
subsequent 'jumps'.

Visually, the pointer speeds looks like this:

0 1 2 3 4 5 6 7 0 0 1 2 3 4 0 0 1 2 3 4 0 0 1 2 3 4 ....

Whereas it should look like this:

0 1 2 3 4 5 6 7 8 9 9 ....


Reason:

The regular auto-repeat functionality of the input layer is causing spurious
keypress events to be sent to the mousekeys code.

Each repeat triggers the 'initial press' code in _XkbFilterPointerMove() in
xkbActions.c, and resets xkbi->mouseKeysCounter to zero, causing the pointer
movement to studder.


Workaround:

Disabling typematic repeat for the keypad keys 'fixes' the issue with the
'mousekeys' feature:

$ for i in 79 80 81 83 85 87 88 89 ; do xset -r $i ; done

But this seems like the wrong fix, because it's only necessary with PS/2
connected keyboards, and this functionality should really be
hardware-independent.

Thoughts?