3

I've built a custom keyboard with a trackball under my thumb and I want to map a scroll behavior in such way that when I press a shortcut (like left alt) and rotate the ball, it should behave like a scroll. I'm using Xorg here, but I'd be very interested in seing solutions for both X and Wayland (if the solution would involve display server).

  • As there are no answers: What exactly do you want to scroll? You can configure your window manager to scroll the virtual viewport, for example. If you want your trackball to emulate a mousewheel when used together with a key, you'll likely have to fiddle with some driver (either on the hardware level, or on the X resp. Wayland level). But as you built the keyboard yourself, maybe you are already using a custom driver. – dirkt Oct 15 '16 at 6:28
  • I'm not using a custom driver. In fact the trackball is just embedded Logitech M570 trackball's ball into Kinesis Advantage. I want to use it as a scroll for all the content of my applications - like scrolling the code text area or pages in a web browser. I want it to behave just like mouse wheel when rotating vertical and like horizontal wheel when rotating horizontally. The idea is to have just one input device - keyboard with a trackball and being able to just scroll content using the ball while holding some modifier key. Is it clear now? :) – Wojciech Danilo Oct 15 '16 at 21:06
3

Emulate vertical and horizontal scrolling using libinput

The evdev driver from dirkt's answer only supports vertical scrolling emulation. If you (like me) also want to scroll horizontally, the libinput driver can be used to do that:

  1. The details are in the manpage for libinput(4):

    Option "ScrollButton" "int"

    Designates a button as scroll button. If the ScrollMethod is button and the button is logically held down, x/y axis movement is converted into scroll events.

    Option "ScrollMethod" "string"

    Enables a scroll method. Permitted values are none, twofinger, edge, button. Not all devices support all options, if an option is unsupported, the default scroll option for this device is used

  2. For example:

    Section "InputClass"
      Identifier "Some Trackball"
      # ... Stuff to match your trackball, see xorg.conf(5)
      Driver "libinput"
      Option "ScrollMethod" "button"
      Option "ScrollButton" "4" # Or whatever button suits your needs
    EndSection
    
0

Simulate mouse wheel with trackball

You can either use existing configuration options of drivers that do something similar to what you want, or write your own driver.

The Logitech M570 is a wireless trackball with an USB-receiver. That means it will show up as a HID device, and mouse events will be made available via the input layer in the kernel, and can read from the corresponding /dev/event device.

The X driver in turn uses the evdev driver to read events from this layer, and turns them into X events. I'm not familiar with Wayland, but I assume it will work similarly there.

1) The evdev driver already contains options to emulate a mousewheel on a trackball, see man evdev. The most important ones are

Option "EmulateWheel" "boolean"

Enable/disable "wheel" emulation. Wheel emulation means emulating button press/release events when the mouse is moved while a specific real button is pressed. Wheel button events (typically buttons 4 and 5) are usually used for scrolling. Wheel emulation is useful for getting wheel-like behaviour with trackballs.

Option "EmulateWheelButton" "integer"

Specifies which button must be held down to enable wheel emulation mode. While this button is down, X and/or Y pointer movement will generate button press/release events as specified for the XAxisMapping and YAxisMapping settings. If the button is 0 and EmulateWheel is on, any motion of the device is converted into wheel events. Default: 4.

So this works using a trackball button instead of keyboard shortcut (because the driver only sees events from the mouse, not from the keyboard), and will convert movement into wheel events, and not rotation.

2) Write your own driver by modifying several existing ones. You will need to combine the drivers for the keyboard and the mouse, so wheel emulation can be triggered by keypresses.

The source code for the kernel input layer is in drivers/input in the kernel tree.

The source code for the evdev X driver is in xorg/driver/xf86-input-evdev/tree/src/evdev.c.

The keyboard driver depends on what type of keyboard you used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.