Where do I have to paste an "xinput" command so that it executes it when GNOME is started?

On my Thinkpad I need to execute something like this in the terminal:

xinput set-int-prop "TPPS/2 IBM TrackPoint" "Evdev Middle Button Emulation" 8 1

so that my the 2 buttons on my touchpad emulate the middle mouse click. Now I need this line to be executed each time I start GNOMe or X or whatever, so that it "just works".

I tried ~/.xsession or ~/.bashrc but to no avail. Should I put it in GNOME start scripts or in /etc/X somewhere?

I'm using Ubuntu 11.10.


Solution 1:

I'm using Enlightenment DM, but that's relevant to other DMs/desktops. I start my session using xsession so I initially put xinput commands in ~/.xsession which didn't change all settings I wanted to change. Only some of them. I was expecting either all or no changes, so I added a 10-interation loop to my .xsession with 1 second intervals, running xinput commands each time and checking if the settings were applied. To my surprise, all settings were applied after the first iteration.

This means that it's your DM that does something to override your xinput settings and since the command that launches your DM (E17 in my case) is the last one in your .xsession file, this file is no place for this.

I've added the following lines in my ~/.profile and this has solved the problem:

# don't run unless we're being invoked from an xwindows session
if [[ -n ${DISPLAY} ]]; then

  # set your devices names here
  pointer1="IBM TrackPoint"
  pointer2="Lite-On Technology Corp. ThinkPad USB Keyboard with TrackPoint"
  pointer3="Logitech USB Trackball"

  id1=$(xinput | awk -F= "/$pointer1.*pointer/ {print \$2}" | cut -f1)
  id2=$(xinput | awk -F= "/$pointer2.*pointer/ {print \$2}" | cut -f1)
  id3=$(xinput | awk -F= "/$pointer3.*pointer/ {print \$2}" | cut -f1)

  if [[ -n "${id1}" ]]; then
    xinput --set-button-map "${id1}" 1 2 3 4 5 6 7
    xinput set-prop "${id1}"  "Evdev Wheel Emulation Axes" 6 7 4 5
    xinput set-prop "${id1}"  "Evdev Wheel Emulation" 1
    xinput set-prop "${id1}"  "Evdev Wheel Emulation Button" 2
    xinput set-prop "${id1}"  "Evdev Middle Button Emulation" 0
  fi

  if [[ -n "${id2}" ]]; then
    xinput --set-button-map "${id2}" 1 2 3 4 5 6 7
    xinput set-prop "${id2}"  "Evdev Wheel Emulation Axes" 6 7 4 5
    xinput set-prop "${id2}"  "Evdev Wheel Emulation" 1
    xinput set-prop "${id2}"  "Evdev Wheel Emulation Button" 2
    xinput set-prop "${id2}"  "Evdev Middle Button Emulation" 0
  fi

  if [[ -n "${id3}" ]]; then
    xinput --set-button-map "${id3}" 1 2 3 4 5 6 7 8 9
    xinput set-prop "${id3}"  "Evdev Wheel Emulation Axes" 6 7 4 5
    xinput set-prop "${id3}"  "Evdev Wheel Emulation" 1
    xinput set-prop "${id3}"  "Evdev Wheel Emulation Button" 8
    xinput set-prop "${id3}"  "Evdev Middle Button Emulation" 1
  fi
fi

PS. set-int-prop has been deprecated in favour of set-prop (man xinput).

Hopefully this helps someone.

Solution 2:

Add the command directly to startup applications. In the command field.

or

make a simple script and add the script to startup applications.

Solution 3:

Create a file in /etc/X11/Xsession.d/ for it.