Custom actions with mouse/trackball buttons on Linux

amospalla
let's go

04 Jul 2015, 13:56

Hi guys,

I've used xbindkeys on Linux to chain button actions of my trackball to do actions, something similar to layers on keyboard. To explain it, let me put an example:

= Press button 8: enter layer 2.
==== Press button 1 in layer 2: "Backward" (ie useful on browser)
==== Press button 3 in layer 2: "Forward" (ie useful on browser)
==== Press button 2 in layer 2: lock screen
and so on.

You can chain buttons ad infinitum like this.

The way to do this is not quite elegant, but just works:

$HOME/.xbindkeysrc

Code: Select all

"/home/user/mouse.sh enter_layer2"
b:8
$HOME/mouse.sh

Code: Select all

#!/bin/bash

case "$1" in
    enter_layer2)
        # kill main xbindkeys and call xbindkeys with layer2
        killall xbindkeys
        xbindkeys -f $HOME/.xbindkeysrc_layer2
        # at this moment a button press will do something, and go back to main xbindkeys
        ;;
    layer2_button1)
        # Left Button
        xdotool key XF86Back
        killall xbindkeys
        xbindkeys
        ;;
    layer2_button2)
        # Middle button
        xdotool key XF86Forward
        killall xbindkeys
        xbindkeys
        ;;

        ... and son on with as many buttons as wanted
esac
$HOME/.xbindkeys_layer2

Code: Select all

"/home/user/mouse.sh layer2_button1"
Release + b:1

"/home/user/mouse.sh layer2_button2"
Release + b:2

... and so on 
One could setup as many layers as needed, like:
press button 8: enter layer 2
press button 8 on layer 2: enter layer 3
press button 8 on layer 3: enter layer 4 ...

Some example commands to bind to:
xdotool key XF86Back
xdotool key XF86Forward
xdotool key Control+Home (on button 4 which is wheel up, goes to the start of a browser page)
xdotool key Control+End (on button 5 which is wheel down, goes to the end of a browser page)
lock screen with something like alock, i3lock... or put monitor in standby mode

I hope it may be useful for somebody.
Last edited by amospalla on 05 Jul 2015, 14:11, edited 1 time in total.

SilentNeutrino

05 Jul 2015, 11:27

This is very clever, thank you for sharing.
I'll try it.

I'd like to mention easystroke, a mouse/trackball gesture recognition (gui) software for linux.
It can map trackball/mouse buttons to keyboard keypresses or shell scripts.
I use it for simple remappings.

Code: Select all

sudo aptitude install easystroke
My quick an dirty M570 acceleration settings:

Code: Select all

/usr/bin/xinput --set-ptr-feedback "Logitech Unifying Device. Wireless PID:1028" 0 4 2

amospalla
let's go

05 Jul 2015, 15:59

Thank you SilentNeutrino.

If anyone has any doubt about this please ask, I'll be glad to help.

Another setting I highly recommend to use on any trackball/mouse is the Wheel emulation. On my slimblade I set it up with:

Code: Select all

xinput set-prop "Kensington Kensington Slimblade Trackball" "Evdev Wheel Emulation" 1
xinput set-prop "Kensington Kensington Slimblade Trackball" "Evdev Wheel Emulation Button" 8
xinput set-prop "Kensington Kensington Slimblade Trackball" "Evdev Wheel Emulation Timeout" 300
The only reason I don't move to a L-TRAC trackball is it not having an extra button which I can easily use with Evdev Wheel Emulation.

Post Reply

Return to “Mice & other input devices”