An initial implementation of trackball auto-layering that does not rely on host-side software. State is communicated via scroll and num locks -- num lock for trackball-to-keyboard, and scroll lock for keyboard-to-trackball.
- Add
TB_LOFF,TB_TOGG, andSCROLLto your custom keycodes. - Add a layer
_TRACKBALLwith your mousekeys on it. - Add a
process_trackballcall to the housekeeping task function. - Add a
process_trackball_keyscall to the record processing function.
TB_LOFFdisables the auto-layer as a fallback if it gets stuck;TB_TOGGdisables the use of the locking states as communication;- and
SCROLLis a drag scroll key, but on the keyboard side.
KB_M is an example of a key that acts as a tap-hold drag scroll key that you can put on your base layer so that you can hold the scroll key before moving the trackball and the auto-layer activates.
The Scroll Lock and Num Lock keys don't set the locking states while control is held since these combinations are interpreted as Pause and Break. This is bypassable on the keyboard side by temporarily releasing control while toggling the lock states, but if you hold control on the keyboard first, there is no way to release it on the trackball side.
However, the caps lock state is unaffected by control, so we can replace the send signal with caps lock. Since we aren't typing while using the trackball, this should be safe, but this will mean that any other caps lock usage in your keyboard keymap will have to add additional logic to disable the auto-layering while caps lock is being used for its normal purpose.
See my corne keymap for an example of this. I've since moved to a raw HID setup since I don't move my trackball around, so I don't need it to be portable, and so that I can implement more control signals, like a volume control mode.
Also, if anyone wants to implement a hilarious time-division multiplexing scheme to encode all the signals into a single lock key, please let me know.