dot/xinitrc: Wait for e16 to start, and tweak cursor after it does.
[profile] / dot / xinitrc
CommitLineData
f617db13 1#! /bin/bash
8e08f814
MW
2###
3### X startup script
f617db13 4
8e08f814
MW
5###--------------------------------------------------------------------------
6### Utility functions.
f617db13 7
8e08f814
MW
8## Progress indicators.
9info=yes
10info () {
11 case $info in yes) echo "- $*" >&2 ;; esac
12}
f617db13 13
8e08f814
MW
14run=yes
15run () {
16 local what=$1; shift
17 local bg=no
f617db13 18
8e08f814
MW
19 case $what in bg*) bg=yes what=${what#bg} ;; esac
20 info "run $what: $*"
f617db13 21
8e08f814
MW
22 case "$run,$bg" in
23 yes,no) "$@" ;;
24 yes,yes) "$@" & ;;
25 esac
26}
eebca092 27
8e08f814 28## Program choice
eebca092 29pick_program () {
8e08f814
MW
30 local what=$1; shift
31 local choice=false
eebca092 32 for i in "$@"; do
8e08f814 33 if type -t >/dev/null "$i"; then choice=$i; break; fi
eebca092 34 done
8e08f814
MW
35 info "pick $what = $choice"
36 echo "$choice"
eebca092
MW
37}
38
8e08f814
MW
39###--------------------------------------------------------------------------
40### Parse arguments.
f617db13 41
8e08f814
MW
42vnc=no
43atomtag=
44start=yes
45wait=yes
f617db13 46
8e08f814
MW
47for opt; do
48 case "$opt" in
49 help)
50 cat <<EOF
51Options:
52 tag=TAG
53 [no]trace
54 [no]info
55 [no]run
56 [no]start
57 [no]wait
58 [no]vnc
59EOF
60 exit
61 ;;
f617db13 62
8e08f814
MW
63 tag=*) atomtag=/${opt#tag=} ;;
64 trace) set -x ;;
65 notrace) set +x ;;
66 info | run | start | wait | vnc) eval "$opt=yes" ;;
67 noinfo | norun | nostart | nowait | novnc) eval "${opt#no}=no" ;;
68
69 *) echo "unknown option $opt" >&2; exit 1 ;;
70 esac
71done
72
73###--------------------------------------------------------------------------
74### Iniitial settings.
75
76## Assume X sessions are secure.
77export __mdw_sechost="`hostname`"
78
79## Obtain the screen dimensions.
80case ",$XWIDTH,$XHEIGHT," in
81 *,,*) eval $(xscsize -bx) ;;
82esac
83info "screen size = $XWIDTH x $XHEIGHT"
84
85initialize () {
86 ## Load the X resource database.
87 run init xrdb -override $HOME/.Xdefaults
88
89 ## Random xsettery.
90 run init xset b 10 2000 50
91 run init xset r rate 500 50
92 run init xset m 2 1
93
f4450ac9
MW
94 ## Key mappings.
95 xmodmap -e 'keysym BackSpace = BackSpace BackSpace'
96
8e08f814
MW
97 ## Gnome settings.
98 case $vnc in no) run bginit gnome-settings-daemon ;; esac
99}
100
101###--------------------------------------------------------------------------
102### Start a window manager.
103
104wm=$(pick_program window-manager enlightenment e16 twm)
105wmopts=""
106case "$wm,$vnc" in
107 enlightenment,yes | e16,yes)
108 wmopts="$eopts -econfdir $HOME/.enlightenment-vnc"
109 ;;
110esac
111
16ee7a8c 112start-e16 () {
8e08f814 113 run bginit $wm $wmopts
16ee7a8c
MW
114 win=nil
115 for i in $(seq 10); do
116 if eesh version >/dev/null 2>&1; then
117 win=t
118 break
119 fi
120 sleep 1
121 done
122 case $win in
123 t)
124 info "$wm started ok"
125 run init xsetroot -cursor_name left_ptr
126 ;;
127 nil)
128 info "$wm failed to start!"
129 ;;
130 esac
131}
132
133start-window-manager () {
134 case $(type -t start-$wm || echo "not-found") in
135 function)
136 start-$wm $wmopts
137 ;;
138 *)
139 run bginit $wm $wmopts
140 ;;
141 esac
8e08f814
MW
142}
143
144###--------------------------------------------------------------------------
145### Random useful clients.
146
54951353
MW
147start-clients-local () { :; }
148
8e08f814
MW
149start-clients () {
150 ## Mail notification.
151 run bginit mail-notification
152
59a62625 153 ## Policykit authentication agent.
4906574e 154 agent=/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1
59a62625
MW
155 if [ -x $agent ]; then run bginit $agent; fi
156
8e08f814
MW
157 ## System monitor.
158 case $vnc in no) run bginit gkrellm ;; esac
159
c02999e8
MW
160 ## Screensaver.
161 case $vnc in
162 no)
163 run init xscreensaver-command -exit
164 run bginit xscreensaver -no-splash
165 ;;
166 esac
167
8e08f814
MW
168 ## Panel.
169 case $vnc in no) run bginit gnome-panel ;; esac
54951353 170
e517857c 171 ## System tray.
079b6c2b 172 ## run bginit stalonetray
e517857c 173
54951353
MW
174 ## Local clients.
175 start-clients-local
8e08f814
MW
176}
177
178###--------------------------------------------------------------------------
179### Main screen layout.
f617db13 180
8e08f814 181## Choose appropriate clients.
0c47c911 182emacs=$(pick_program emacs emacs23 emacs22 emacs21 emacs)
8e08f814 183term=$(pick_program terminal pterm Eterm xterm)
f617db13 184
8e08f814 185## Emacs window measurements.
85bbf8d3 186case "$emacs" in
8e08f814 187 emacs21 | emacs)
85bbf8d3
MW
188 e_colwd=492 e_hextra=34
189 e_colchars=82 e_cextra=-2
190 e_lineht=13 e_vextra=52
191 ;;
0c47c911 192 emacs22 | emacs23)
85bbf8d3
MW
193 e_colwd=492 e_hextra=8
194 e_colchars=82 e_cextra=-6
195 e_lineht=13 e_vextra=46
196 ;;
197esac
f617db13 198
8e08f814 199## Terminal window measurements.
85bbf8d3 200case "$term" in
e2b44bd9 201 pterm) t_wd=504 t_lineht=13 t_vextra=23 geom=-geometry;;
85bbf8d3
MW
202 Eterm) t_wd=504 t_lineht=13 t_vextra=23 geom=-g;;
203 xterm) t_wd=507 t_lineht=13 t_vextra=27 geom=-geometry;;
204esac
f617db13 205
8e08f814 206## GNOME stuff measurements.
f617db13
MW
207declare -i xbound="XWIDTH - 113"
208
8e08f814
MW
209## Choose a width for Emacs.
210##
211## We'd like it to be as wide as possible, allowing for a column of xterms
212## down the right hand side. However, I'd prefer a double-width Emacs to a
213## single-width Emacs and xterms. If it's not going to work at all, a single
214## Emacs column will have to do. Also, there's a strange thing with Emacs21
215## and the toolbar, so we add on some rows which are later mysteriously
216## subtracted.
f617db13 217
85bbf8d3
MW
218declare -i ecols="(xbound - t_wd - e_hextra)/e_colwd"
219if (( ecols < 2 && xbound > e_colwd * 2 + e_hextra )); then
f617db13
MW
220 ecols=2
221elif (( ecols < 1 )); then
222 ecols=1
223fi
224
8e08f814
MW
225declare -i \
226 emacsx="ecols * e_colchars + e_cextra" \
227 emacsy="(XHEIGHT - e_vextra)/e_lineht"
228
229start-emacs () {
bf057abe
MW
230 GDK_NATIVE_WINDOWS=1 run bgclients noip \
231 $emacs -geometry ${emacsx}x${emacsy}+0+0
8e08f814
MW
232}
233
234## Now place some xterms.
235##
236## A few smaller xterms are in general better than one great big one. 35
237## lines is a good height for most terminals. 25 lines is a minimum. The
238## strategy for doling out xterms into a column is to make as many 35-liners
239## as we can, until the remaining space would be too small for a 25-liner.
240## If we can get two 25s out of that then we do (largest first); otherwise
241## just make one big one. We stop at the end of a page, once we've made
242## three xterms.
243
244start-xterms () {
245
246 ## Initialize some parameters.
6b4faba6 247 declare -i x="ecols * e_colwd + e_hextra" xb=xbound
8e08f814
MW
248 declare -i n=0 pgx=0 l h y ht
249 declare -i hstd="35 * t_lineht + t_vextra" hmin="25 * t_lineht + t_vextra"
250
251 ## Do the placement.
252 while :; do
253
254 ## Start a new iteration.
6b4faba6 255 if ((x + t_wd > xb)); then
8e08f814 256 if ((n >= 3)); then break; fi
6b4faba6 257 x="pgx + XWIDTH" pgx="pgx + XWIDTH" xb="xb + XWIDTH"
8e08f814
MW
258 fi
259
260 ## Make large xterms.
261 y=0 ht=XHEIGHT
262 while ((ht - hstd >= hmin)); do
263 run bgclients $term $geom 80x35+$x+$y
264 y="y + hstd" ht="ht - hstd" n="n + 1"
265 done
266
267 ## Fill the remaining space.
268 if ((ht >= 2 * hmin)); then h="ht - hmin"; else h=ht; fi
269 l="(h - t_vextra)/t_lineht" h="l * t_lineht + t_vextra"
270 run bgclients $term $geom 80x$l+$x+$y
271 y="y + h" ht="ht - h" n="n + 1"
272 if ((ht >= hmin)); then
273 run bgclients $term $geom 80x25+$x+$y
274 n="n + 1"
275 fi
276 x="x + t_wd"
f617db13 277 done
8e08f814 278}
f617db13 279
8e08f814 280###--------------------------------------------------------------------------
3bdada49
MW
281### Requesters.
282
283req () {
284 declare title=$1 hist=$2; shift 2
3f88bd1f 285 cmd=$(xgetline -t "$title" -p "_Command:" -Hl "$HOME/$hist") &&
3bdada49
MW
286 exec "$@" "$cmd"
287}
288
289###--------------------------------------------------------------------------
8e08f814
MW
290### Final waiting.
291
292atom=XINIT_COMMAND$atomtag
293
294xwait () {
295 while :; do
296 xatom delete $atom
297 info "waiting on $atom"
298 line=$(xatom wait $atom)
299 info "xatom: $line"
300
301 case "$line" in
302 :help)
303 xmsg -I -t "xinitrc help" -d "xinitrc commands" - <<EOF &
304:help
305:emacs :xterms :window-manager :clients
3bdada49 306:ask-run :ask-command
8e08f814
MW
307:init
308:terminal
309! SHELL-COMMAND
310CLIENT
311EOF
312 ;;
313 :emacs | :xterms | :window-manager | :clients)
314 start-${line#:}
315 ;;
316 :terminal)
317 run bgclients $term
318 ;;
319 :init)
320 initialize
321 ;;
322 :exec)
323 info "restarting xinitrc"
324 exec "$0" wait nostart
325 ;;
3bdada49
MW
326 :ask-run)
327 req "Shell command" .cmd.hist xcatch -FMiscFixed6x13 -- sh -c&
328 ;;
329 :ask-command)
330 req "xinit command" .xinit.hist xatom set XINIT_COMMAND$atomtag&
331 ;;
8e08f814
MW
332 :*)
333 xmsg -E -t "xinitrc error" "Unknown command \`$line'" &
334 ;;
335 !*)
336 eval "${line#!}"
337 ;;
338 *)
339 set -- $line
340 run bgclients "$@"
341 ;;
342 esac
343 done
344}
345
346###--------------------------------------------------------------------------
347### Actually start things up.
348
54951353
MW
349if [ -f $HOME/.xinitrc-local ]; then
350 . $HOME/.xinitrc-local
351fi
352
8e08f814
MW
353case "$start" in
354 yes)
355 info "starting standard clients"
356 initialize
357 start-window-manager
358 start-clients
359 start-emacs
360 start-xterms
361 ;;
362 no)
363 info "not starting standard clients"
364 ;;
365esac
366
367case "$wait" in
368 yes)
369 xwait
370 ;;
371 no)
372 info "not waiting before exit"
373 ;;
374esac
f617db13 375
8e08f814 376###----- That's all, folks --------------------------------------------------