Combine xf86-input-evdev middle button + wheel emulation, Kensington Orbit Trackball

This “mouse” is the best thing since sliced bread. No more wrist bending carpal tunnel syndrome inducing table mice for me. Witness the awesomeness for yourself:

In the interest of keeping price low and functions simple, this thing only has two buttons. I now happened to run into a situation where Xorg’s standard wheel and middle button emulation configuration didn’t cut it, because evdev (as of 2.7.3) doesn’t support wheel emulation on top of middle button emulation.

My previous configuration consisted of having the right button do wheel emulation: holding it down and moving the trackball would scroll the document up and down. Single click gives the regular context menu popup etc. Apparently this works for about 99% of the time because I didn’t have a problem until I needed the right button held down for a Tcl/Tk application context menu (hi git gui!).

After finding out I can’t just hold both buttons down (middle button emulation) and scroll with it (wheel emulation on top of middle button emulation) — see above –, doing plenty of remapping logic exercises finally resulted in a configuration that works. Enter third button emulation into the picture, which will replace middle button emulation.

Here’s the final configuration (replace 11 with your device id from “xinput list”):

$ xinput list-props 11
Device 'Kensington      Kensington USB/PS2 Orbit':
	Device Enabled (134):	1
	Coordinate Transformation Matrix (136):	1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
	Device Accel Profile (261):	0
	Device Accel Constant Deceleration (262):	1.000000
	Device Accel Adaptive Deceleration (263):	1.000000
	Device Accel Velocity Scaling (264):	10.000000
	Device Product ID (252):	1149, 4130
	Device Node (253):	"/dev/input/event6"
	Evdev Axis Inversion (560):	0, 0
	Evdev Axes Swap (562):	0
	Axis Labels (563):	"Rel X" (144), "Rel Y" (145)
	Button Labels (564):	"Button Left" (137), "Button Unknown" (559), "Button Right" (139), "Button Wheel Up" (140), "Button Wheel Down" (141)

We disable middle button emulation, because when enabling third button emulation there is no more use for it.

	Evdev Middle Button Emulation (565):	0
	Evdev Middle Button Timeout (566):	50

Hello third button emulation. Because right mouse button will be occupied for wheel emulation, which requires a real non-emulated button, this will be our new right-click that can be held down. Thing to watch out here for is the timeout. I’m finding 400ms delay is about right. Default of 1000ms was definitely annoyingly long. 200ms is too short, you will have trouble selecting text without getting a right-click.

Notice I’m setting the emulated button to “2″. This is for getting apps to keep functioning in a regular expected way.

	Evdev Third Button Emulation (567):	1
	Evdev Third Button Emulation Timeout (568):	400
	Evdev Third Button Emulation Button (569):	2
	Evdev Third Button Emulation Threshold (570):	20

Wheel emulation is all regular stuff, except for setting the emulated button to “3″.

	Evdev Wheel Emulation (571):	1
	Evdev Wheel Emulation Axes (572):	0, 0, 4, 5
	Evdev Wheel Emulation Inertia (573):	10
	Evdev Wheel Emulation Timeout (574):	200
	Evdev Wheel Emulation Button (575):	3
	Evdev Drag Lock Buttons (576):	0

And here’s the final piece of the puzzle, reversing buttons “2″ and “3″ mapping. This makes sure the wheel emulation ends up on the real, non-emulated button.

leho@s9 ~ $ xinput get-button-map 11
1 3 2 4 5

To sum it all up, problem solved here is getting a right-click that can be held, while still maintaining wheel emulation, with a 2-button mouse.

Everything in terms of /etc/X11/xorg.conf.d:

leho@s9 ~ $ cat /etc/X11/xorg.conf.d/51-kensington.conf
Section "InputClass"
    Identifier "My Kensington Orbit Trackball"
    Driver "evdev"
    Option "ButtonMapping" "1 3 2 4 5"
    Option "EmulateMiddleButton" "False"
    Option "EmulateThirdButton" "True"
    Option "EmulateThirdButtonButton" "2"
    Option "EmulateThirdButtonMoveThreshold" "0"
    Option "EmulateThirdButtonTimeout" "400"
    Option "EmulateWheel" "True"
    Option "EmulateWheelButton" "3"
    MatchProduct "Kensington USB/PS2 Orbit"
EndSection

EDIT
One more parameter needs to be tuned. Default setting of EmulateThirdButtonMoveThreshold 20 disturbs selecting text and drag-n-dropping stuff with the left. You can safely set the threshold to 0, since with a trackball there is pretty much no involuntary movement of the cursor after clicking, like there can be with the regular mouse connected to the whole palm of your hand. 51-kensington.conf has been updated accordingly.

Using interactive commands during emerge ebuild phases

Gentoo Portage’s primary tool emerge is largely meant to run as a non-interactive process. Meaning aside from the –ask flag making it get user confirmation before beginning operations, rest of the process is supposed to finish without any further user input.

This mostly makes sense, because compiling software can be a lengthy process. Even more so when you’re possibly emerging tens of packages at a time. It makes no sense for the user to guard the terminal and stare at the Matrix, waiting to answer the occasional, usually trivial Yes/No prompt.

But in this particular use case I have, I’ve discovered I’d like to run an interactive command etc-update after every package finishes installing (ebuild postinst phase). My goal is to have a firm grip on a vserver bootstrap template configuration with the help of git. Portage’s configuration protection litters /etc with ._cfg* files and I would rather not spread the litter to the git repo by just blindly committing everything in postinst. Also, maintaining the bootstrap template is usually a rare and short operation (few packages at a time) where I can monitor the build and act on request.

Your ${ROOT}/etc/portage/bashrc could have something like this:

echo Phase: $EBUILD_PHASE
ETC="${ROOT}etc"
GITCMD="GIT_DIR=$ETC/.git GIT_WORK_TREE=$ETC git"

case "$EBUILD_PHASE" in
    "setup")
        STATUS=$(eval $GITCMD status -uno -s)
        [ -n "${STATUS}" ] && die "Error: $ETC is not clean"
    ;;
    "postinst")
        etc-update
        eval $GITCMD add $ETC
        eval $GITCMD commit -q -a -m \"emerge $CATEGORY/$P\"
    ;;
esac

Problem is that emerge pipes everything to its logfiles and won’t let etc-update get any input from you. Some googling revealed a solution by redirecting stdin and stdout. /dev/tty is magic that always has the right answer, google it yourself for details.

${ROOT}/etc/portage/bashrc:

...
    "postinst")
        etc-update 0</dev/tty 1>/dev/tty
...

Alternative fix for Linux Skype “Another instance may exist” login error

Ran into this error today, running Skype 2.2.0.25. Most of top Google hits suggest removing lockfiles and killing your profile, but that seemed like an overkill. After some consulting with the developers, it turned out Skype locking mechanisms are also possibly influenced by browser processes that are launched by clicking URLs or in my case, clicking “Open Downloads folder” button. This fired up an “xdg-open” which in turn fired up “links2″ somewhere in the non-visible process space, beacuse I probably don’t have XDG fully configured for firefox in my fresh awesome-based setup.

One command to reveal such Skype lockfile-hogging processes is:

$ lsof .Skype/your-username-here/main.lock

If there is no way to cleanly shut them down, kill them and Skype should be able to login again.

Version control for Gentoo make.conf, USE flags

Introduction

I have recently implemented etckeeper and metastore to keep my Gentoo server:/etc directory under version control. Object of interest today is how to make a good git commit message regarding Gentoo’s /etc/make.conf and the long long USE flags (possibly multi-)line in there. Usually these USE flag changes happen in the process of reconfiguring some packages. I often don’t commit make.conf changes immediately and then after a few days can’t remember anymore what USE flags have changed and why to make a meaningful commit message.
(more…)

less is also tail, who knew?

Can’t believe I hadn’t come across this one before anywhere. You know the scenario when you’re debugging some wack crash or non-functionality in your Linux box and doing this over and over again:

less /var/log/messages

for reviewing what happened, then CTRL+C and:

tail -f /var/log/messages

to monitor what happens when you changed something.

Well how about just staying in less and pressing F. Discovered from less’ very own help page.

F Forward forever; like "tail -f"