#! /bin/bash -eu 

IMG_FILE="$1"; shift
TAG="$1"; shift

# Displays {IMG_FILE} in a certain position of the screen that
# is presumably adequate for checking the transcription of hat page.
# The {TAG} must be a string that is certain to occur in the 
# windos'ws title as set by gimp.

echo "displaying the image ${IMG_FILE} ..." 1>&2
gimp --no-splash ${IMG_FILE} 

echo "Waiting for window '*${TAG}*' to show up ..." 1>&2
SEARCH_STR="${TAG}"
for i in {1..15}; do
    printf "." 1>&2
    if wmctrl -l | grep -F "${SEARCH_STR}" > /dev/null; then
        echo " found it!" 1>&2
        break
    fi
    sleep 1
done
    
echo "positioning the image ..." 1>&2
wmctrl -v -r "${SEARCH_STR}" -e 0,100,600,2200,400 || ( echo "wmctrl failed" 1>&2 )
wmctrl -v -r "${SEARCH_STR}" -b add,above || ( echo "wmctrl failed" 1>&2 )
echo "positioned." 1>&2

#     --batch "
#       (let* 
#         ( ( image-list 
#             (gimp-file-load RUN-NONINTERACTIVE \"${IMG_FILE}\" \"${IMG_FILE}\")
#           )
#           ( img (car image-list) )
#           ( disp (car (gimp-display-new img)))
#         )
#         (display disp) (newline)
#         (display img) (newline)
#         (gimp-zoom-set 0.85)
#         (gimp-display-set-zoom disp 0.85 0.85)
#       )
#     "
# 
