Use `Control_Type' to handle different segment directions.
[ttfautohint.git] / doc / make-snapshot.sh
blob8057937c12cf1fc4e171edd1ef93fb2c2668ec66
1 #! /bin/sh
3 # Copyright (C) 2013-2014 by Werner Lemberg.
5 # This file is part of the ttfautohint library, and may only be used,
6 # modified, and distributed under the terms given in `COPYING'. By
7 # continuing to use, modify, or distribute this file you indicate that you
8 # have read `COPYING' and understand and accept it fully.
10 # The file `COPYING' mentioned in the previous paragraph is distributed
11 # with the ttfautohint library.
14 # make-snapshot.sh <application> <filename>
16 # Make a snapshot from an application's start window and save it to a file.
17 # This needs X11 and ImageMagick's `import' tool.
19 # This script is very simple. Some possible problems:
21 # o In case the program doesn't create a visible X11 window, you have to
22 # abort the script with ^C.
24 # o It fails for intelligent applications like `firefox' in case they are
25 # already run, since firefox replaces the process with a new window of the
26 # already running instance.
28 # o It loops forever for programs like `k3b' that spawns itself, thus
29 # having a different process ID for the visible window.
32 # This script uses ideas from
33 # http://blog.chewearn.com/2010/01/18/find-window-id-of-a-process-id-in-bash-script/.
35 if [ $# -ne 2 ]; then
36 echo "Usage: $0 application imagename"
37 exit 1
41 find_WID()
43 # Get all windows with the name $APP (ignoring case).
44 xwininfo -root -tree 2>/dev/null \
45 | grep -i $1 \
46 | while read DATA; do
47 # Extract Window ID.
48 WID=`echo $DATA | awk '{print $1}'`
50 # Check whether the window's PID is matching the application's PID.
51 if [ `xprop -id $WID _NET_WM_PID | awk '{print $3}'` -eq $PID ]; then
52 # Check whether window is displayed actually.
53 if [ "`xwininfo -id $WID | grep 'IsViewable'`" != '' ]; then
54 echo $WID
55 return
58 done
62 # Start program in background and get its process ID.
63 $1 &
64 PID=$!
66 sleep 1
68 # Get application name.
69 APP=`ps --no-header -o comm -p $PID`
70 if [ "$APP" == "" ]; then
71 echo "Couldn't start application \`$1'"
72 exit 1
75 # Loop until program has displayed a window
76 # so that we can actually get the Windows ID.
77 while [ "$WID" == "" ]; do
78 WID=`find_WID $APP`
79 sleep 1
80 done
82 # Make snapshot.
83 import -silent -window $WID $2
85 kill $PID
87 # eof