work on docs
[pspp] / doc / screengrab
1 #!/bin/bash
2 ## PSPP - a program for statistical analysis.
3 ## Copyright (C) 2020 Free Software Foundation, Inc.
4 ##
5 ## This program is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
9 ##
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 fail ()
19 {
20     kill $pid;
21     echo FAILED to grab image for $payload
22     cat $errfile
23     rm -f $errfile
24     exit 1;
25 }
26
27 pass ()
28 {
29     kill $pid;
30     rm -f $errfile
31     exit 0;
32 }
33
34 # Types the argument, with a pause after the first character.
35 hard_type ()
36 {
37     xdotool type "${1:0:1}"
38     xdotool sleep 0.5
39     xdotool type "${1:1}"
40 }
41
42 theme=Aidwaita
43
44 while test $# -gt 0; do
45     case "$1" in
46         --topsrcdir=*)
47             topsrcdir=${1/--topsrcdir=/}
48         ;;
49         --application=*)
50             application=${1/--application=/}
51             ;;
52         --x-server=*)
53             xserver=${1/--x-server=/}
54             ;;
55         --payload=*)
56             payload=${1/--payload=/}
57         ;;
58         --theme=*)
59             theme=${1/--theme=/}
60         ;;
61         *)
62             output=$1;
63         ;;
64     esac
65     shift 1;
66 done
67
68 rm -f $output
69 export LC_ALL=C
70
71 width=1440
72 height=900
73
74 temp=`mktemp -d`
75 export HOME=$temp
76
77 mkdir -p $HOME/.config
78 cat > $HOME/.config/psppirerc <<EOF
79 [PsppireOutputWindow]
80 maximize=true
81
82 [PsppireDataWindow]
83 maximize=true
84 height=$height
85 width=$width
86
87 [PsppireSyntaxWindow]
88 maximize=true
89 EOF
90
91
92 # xserver=xephyr
93
94 case "$xserver" in
95     xvfb)
96         display=:$RANDOM
97         Xvfb +extension XTEST \
98              -screen 0 "$width"x"$height"x24 \
99              $display &
100         ;;
101     xephyr)
102         display=:$RANDOM
103         Xephyr -screen "$width"x"$height" \
104                +extension XTEST \
105                -noxv \
106                -dumb $display &
107         ;;
108     native)
109         display=$DISPLAY
110         ;;
111     *)
112         printf "Unknown X server type\n";
113         exit 1;
114         ;;
115 esac
116 pid=$!
117 export DISPLAY=$display
118 export GTK_THEME=$theme
119
120 sleep 1
121
122 errfile=`mktemp`
123 $application -q -n 2> $errfile &
124 if test "$xserver"x = "native"x; then pid=$!; fi
125
126 xdotool sleep 0.5
127 if test $? -ne 0 ; then fail; fi
128
129 trap fail ERR
130 . $payload
131
132 mv $output,tmp $output
133 pass;