Wednesday, September 10, 2014

Automatic GIMP dock window exporting


To my knowledge, GIMP is unlike other applications under X in one particular sense; it has the inbuilt functionality to export its windows to other X displays. Besides the bizarre, a more common application is to move GIMP windows onto different monitors (screens) in a multihead configuration (Zaphod mode, not Xinerama). This functionality is available on the window menus and in theory, these window locations should even be saved in the sessionrc data. ... But that's where everything breaks.
The export menu items

In my experience with GIMP 2.8.2 and a few earlier versions under xfwm4/Mint14, the sessionrc file normally contains all the correct geometries for a dock window which has been exported to another X display; however, when GIMP exports the window during launch, the window is initialized at a minimal size instead of the specified overall geometry. Resizing the window like this destroys any specific internal geometries (i.e. the relative widths of individual dock tabs). I'm not terribly sure, but i suspect that it's a window manager problem and that a simple delay during the export process would fix the problem.

The collapsed dock window.  Internal geometry is lost.

My workaround was to simply automate a manual window export routine. Since the two displays normally used for both the GIMP image window and the exported dock have the same dimensions, I simply configure both to be created on the same display. I then set GIMP preferences to save the window positions. Subsequently, i turn off session save features and even set sessionrc to read-only (just for good measure).

A short script using xdotool does all the work:

#!/bin/bash
# this script launches gimp and exports the tools/layers dock window
# this avoids the fact that gimp's session manager cannot accurately place the
# window if exported during launch
# may be due to laggy wm data during concurrent placement of other gimp windows
# click placement is dependent on screen dims, themes

gimp &

while [ "$(wmctrl -l | grep "Layers")" == "" ]; do
  sleep 0.1
done

DISPLAY=:0.2
wmctrl -s 1
sleep 0.5
DISPLAY=:0

keytime=0.005

xdotool search --screen 0 --name "Layers" windowfocus;
sleep 0.1; xdotool mousemove 1266 60
sleep 0.3; xdotool click 1

for i in `seq 1 12`; do
  sleep $keytime; xdotool key Down
done

sleep $keytime; xdotool key Right

for i in `seq 1 3`; do
  sleep $keytime; xdotool key Down
done

sleep $keytime; xdotool key Return

echo "window move attempted"

It's a cringe-worthy open-loop sort of approach, but it does work. This script launches GIMP with the unexported dock window on the same screen. It raises the dock window, clicks on the menu button, and uses key events to navigate to the desired menu entry.

Simply tailor the script to fit your application:
  • menu button location (1266 60)
  • $DISPLAY values for particular screens
  • dock window title string
  • number of key events to reach your menu item
  • adjust key delay if necessary

No comments:

Post a Comment