Remote Control

03 Sep, 2005

I recently bought a Shuttle PN31 Infrared USB Remote Control to use with my computer, specifically to use when I watch movies using the TV output. I used to have an old gamepad for this, but as I have moved and don't have the TV as close to the computer the cord isn't long enough. Besides, it wasn't a solution I was entierly pleased with as the gamepad didn't have enough buttons.

My setup is perhaps a little bit unusual. I have an ATI Radeon 9100 as my main card (on of the cards with free 3D drivers) and an old GeForce2 MX as a secondary card since this card has TV-output with support for free drivers. (The GeForce is supported by nvtv. Work is being done to support the Radeon natively in Xorg, until then I need to cards.) I have these setup as two displays in X (no Xinerama).

The PN31 works like a simple USB keyboard/mouse, sadly it seems to use some bastardize version of the USB protocol for the mouse part that Windows XP accepts, but real operating systems don't, so I haven't been able to use that part. (There is a patch I haven't tried yet.) The remote seems to be a little bit more Windows centric than I first imagined. I hoped that all buttons were special ones I could bind however I liked, but it seems to have been custom made to support Windows Media Player, and quite a few buttons are normal ones, such as Enter, or even Control-Alt-f.

Even so, It wasn't very hard to make a sufficent Xmodmap to bind keyboard settings for the special buttons, and make MPlayer and Totem keybindings work with the rest. (I was pleased to find out that GNOME asked me if I wanted to load my Xmodmap when I logged in!)

The last problem with the remote, was this (wich I solved yesterday night). If I sit by the TV watching a movie, pause, go and use the computer for something, return to the tv and try to unpause, nothing happens. The movie player have of course lost focus, this was never a problem with the gamepad. So I simply wrote a short script that checks for running movie players on the second display and gives them focus:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh

# BUGS: Defaults to the one started first if both are running
#       Not much of a problem as they normally don't run at the
#       same time

export DISPLAY=:0.1
PIDS=("`pidof mplayer totem`")

if [ -z "$PIDS" ]
then
    totem --fullscreen dvd://
fi

for pid in $PIDS
do
ACTIVEPLAYER=`wmctrl -l -p | grep "$pid" | awk '{print $5}'`
if [ -z $ACTIVEPLAYER ]
then
    true      # if we find a non matching pid (one of my scripts) do nothing for this one
elif [ $ACTIVEPLAYER == "MPlayer" ]
then
    wmctrl -a MPlayer
else
    wmctrl -a $ACTIVEPLAYER
 fi
done

exit 0

This is bind to a button on the remote, no more going up from the comfy sofa when I forget to give the player focus back! As an added bonus, If no program is running, it starts Totem as a DVD player.

Now all I need to do is get the mouse running so I can navigate those pesky DVD menus.