Using the Gimp in Ratpoison

[The Gimp in Ratpoison]

The Gimp is an application notorious for its many windows and dialog boxes, which seems just made to conflict with Ratpoison’s window handling. It turns out that the Gimp, starting with version 2.2, actually works quite well with Ratpoison. This is because the Gimp has stopped using gazillions of windows, but restricts itself to a few instead.

The trick is to set up frames in a convenient way for the windows which are typically open—that would be a big frame for the current image, and two small frames for the tools and layer dialogs—and store this setup in a frame dump. This way, when starting the Gimp, the frames can be set up for a comfortable work environment again. When the Gimp does indeed use another window—the brightness/contrast dialog, for example—one can split the main frame horizontally.

Once you set up the screen in a way you want, use ratpoison -c fdump > ~/.rpframe_gimp to store your frame setup the way you want.

The following script is run by my Ratpoison on C-t G. It first sets up the frames as needed, and then either starts the Gimp if it’s not running yet, or puts windows into the appropriate frames. Currently, it is not possible to run a script after an application has displayed all of its windows, so when the Gimp started up, I just hit C-t G again and find myself in a good work environment.

#!/bin/sh
FRAMEDUMP="$HOME/.rpframe_gimp"

if [ -f "$FRAMEDUMP" ]
then
    ratpoison -c "frestore `cat "$FRAMEDUMP"`"
fi

if ! ps -C gimp >/dev/null
then
    exec gimp "$@"
else
    WGIMP=$(ratpoison -c "windows %n %t" \
            | sed -ne 's/^\([0-9]\+\) The GIMP/\1/p')
    WLAYERS=$(ratpoison -c "windows %n %t" \
              | sed -ne 's/^\([0-9]\+\) Layers/\1/p')
    ratpoison -c focus
    ratpoison -c "select $WGIMP"
    ratpoison -c focus
    ratpoison -c "select $WLAYERS"
    ratpoison -c focus
    ratpoison -c other
    ratpoison -c "echo The Gimp is already running."
fi