5 ###--------------------------------------------------------------------------
8 ## Progress indicators.
11 case $info in yes) echo "- $*" >&2 ;; esac
19 case $what in bg*) bg=yes what=${what#bg} ;; esac
29 local when=$(date +%s) now
30 local fail=0 rc report
35 0) info "manage $1: successful exit"; break ;;
36 143) info "manage $1: terminated"; break ;;
40 if (( $now - $when > 5 )); then
43 report="$report, early failure"
45 if (( $fail >= 5 )); then
46 info "manage $1: exit ($report), giving up after $fail failures"
50 info "manage $1: exit ($report), restarting"
60 if type -t >/dev/null "$i"; then choice=$i; break; fi
62 info "pick $what = $choice"
66 ###--------------------------------------------------------------------------
90 tag=*) atomtag=/${opt#tag=} ;;
93 info | run | start | wait | vnc) eval "$opt=yes" ;;
94 noinfo | norun | nostart | nowait | novnc) eval "${opt#no}=no" ;;
96 *) echo "unknown option $opt" >&2; exit 1 ;;
100 ###--------------------------------------------------------------------------
101 ### Preliminary hook.
103 if [ -r $HOME/.xinitrc-prehook ]; then
104 . $HOME/.xinitrc-prehook
107 ###--------------------------------------------------------------------------
108 ### Iniitial settings.
110 ## Assume X sessions are secure.
111 export __mdw_sechost="`hostname`"
113 ## Obtain the screen dimensions.
114 case ",$XWIDTH,$XHEIGHT," in
115 *,,*) eval $(xscsize -bx; xscsize -bmx) ;;
119 XNSCR=1 XSCR0_X=0 XSCR0_Y=0 XSCR0_WIDTH=$XWIDTH XSCR0_HEIGHT=$XHEIGHT
122 i=0; while (( i < XNSCR )); do
123 eval "x=\$XSCR${i}_X y=\$XSCR${i}_Y
124 wd=\$XSCR${i}_WIDTH ht=\$XSCR${i}_HEIGHT"
125 info "screen #$i = ${wd}x${ht}+${x}+${y}"
130 ## Load the X resource database.
131 run init xrdb -override $HOME/.Xdefaults
134 run init xset b 5 2000 50
135 run init xset r rate 500 50
139 xmodmap $HOME/.xmodmap
140 if [ -r $HOME/.xmodmap-local ]; then
141 xmodmap $HOME/.xmodmap-local
145 ###--------------------------------------------------------------------------
146 ### Start a window manager.
148 wm=$(pick_program window-manager e16 compiz enlightenment e17 twm)
151 enlightenment,yes | e16,yes)
152 wmopts="$eopts -econfdir $HOME/.enlightenment-vnc"
157 run bginit manage $wm $wmopts
159 for i in $(seq 10); do
161 if eesh version >/dev/null 2>&1; then
168 info "$wm started ok"
169 run init xsetroot -cursor_name left_ptr
172 info "$wm failed to start!"
177 start-window-manager () {
178 case $(type -t start-$wm || echo "not-found") in
183 run bginit manage $wm $wmopts
188 ###--------------------------------------------------------------------------
189 ### Random useful clients.
191 start-clients-local () { :; }
196 case "$vnc,$(xfce4-session --version 2>&1),$(gnome-session --version 2>&1)"
199 run bginit xfce4-session
201 no,*,gnome-session\ 2.3[2-9].* | \
202 no,*,gnome-session\ 2.4[0-9].* | \
203 no,*,gnome-session\ 2.[1-9][0-9][0-9]*)
204 run bginit gnome-session --session mdw
207 run bginit gnome-session
215 ###--------------------------------------------------------------------------
216 ### Main screen layout.
218 ## Choose appropriate clients.
219 emacs=$(pick_program emacs \
220 emacs23-lucid emacs24-lucid emacs23 emacs24 emacs22 emacs21 emacs)
221 term=$(pick_program terminal pterm Eterm xterm)
223 ## Emacs window measurements.
225 ## e_colwd = basic width of a column in pixels
226 ## e_hextra = extra horizontal width in pixels
227 ## Width of an N-column Emacs frame in pixels will be
228 ## N*e_colwd + e_hextra
229 ## e_colchars = width of a column in Emacs `-geometry' units
230 ## e_cextra = extra horizontal width in Emacs `-geometry' units
231 ## So an N-column frame should be reported to Emacs as being
232 ## N*e_colchars + e_cextra geometry units wide
233 ## e_lineht = height of a character line in pixels
234 ## e_vextra = number of additional vertical cruft pixels
235 ## So an N-line Emacs frame takes N*e_lineht + e_vextra pixels
238 e_colwd=492 e_hextra=34
239 e_colchars=82 e_cextra=-2
240 e_lineht=13 e_vextra=52
243 e_colwd=492 e_hextra=8
244 e_colchars=82 e_cextra=-6
245 e_lineht=13 e_vextra=46
248 e_colwd=492 e_hextra=5
249 e_colchars=82 e_cextra=-6
250 e_lineht=13 e_vextra=42
253 e_colwd=492 e_hextra=7
254 e_colchars=82 e_cextra=-6
255 e_lineht=13 e_vextra=48
258 e_colwd=492 e_hextra=7
259 e_colchars=82 e_cextra=-5
260 e_lineht=13 e_vextra=48
264 ## Terminal window measurements.
266 ## t_wd = the window width, in pixels
267 ## t_lineht, t_vextra = height parameters: if the window is N lines high,
268 ## then it will be N*t_lineht + t_vextra pixels high
270 pterm) t_wd=504 t_lineht=13 t_vextra=23 geom=-geometry;;
271 Eterm) t_wd=504 t_lineht=13 t_vextra=23 geom=-g;;
272 xterm) t_wd=507 t_lineht=13 t_vextra=27 geom=-geometry;;
275 ## GNOME stuff measurements.
276 declare -i panelwd=64 xbound=$(( XWIDTH - panelwd ))
278 ## Choose a width for Emacs.
280 ## We're going to make a single frame of Emacs, which will be automatically
281 ## divvied into columns; the rest of the space will be tiled with xterms. If
282 ## we have multiple screens, then Emacs can have the first screen and we'll
283 ## fill the rest with terminals. Otherwise, we'll try to have N columns of
284 ## Emacs, and N - 1 columns of xterms; if that doesn't work, we'll make do
285 ## with N - 2 columns of xterms.
287 ## So, let W be the available width; let E and T be the widths of an Emacs
288 ## column (e_colwd) and terminal (t_wd), respectively, and let E0 be the
289 ## additive width of Emacs's existence (e_hextra). If we have more than one
290 ## screen, then instead, let T be zero. To start out, then, we let N = 1 +
291 ## floor((W - E - E0)/(E + T)). If W - E0 - (N + 1) E - (N - 1)*T >= 0, then
292 ## we increase N by one.
293 declare -i lim=XSCR0_WIDTH
294 if (( lim > xbound )); then lim=xbound; fi
295 declare -i twd=t_wd; if (( XNSCR > 1 )); then twd=0; fi
296 declare -i ecols=$(( (lim - e_colwd - e_hextra)/(e_colwd + twd) + 1 ))
297 if (( lim - e_hextra - (ecols + 1)*e_colwd - (ecols - 1)*twd >= 0 )); then
298 ecols=$(( ecols + 1 ))
302 emacsx=$(( ecols*e_colchars + e_cextra )) \
303 emacsy=$(( (XHEIGHT - e_vextra)/e_lineht ))
306 GDK_NATIVE_WINDOWS=1 run bgclients noip \
307 $emacs -bg black -geometry ${emacsx}x${emacsy}+${XSCR0_X}+${XSCR0_Y}
310 ## Now place some xterms.
312 ## A few smaller xterms are in general better than one great big one. 35
313 ## lines is a good height for most terminals. 25 lines is a minimum. The
314 ## strategy for doling out xterms into a column is to make as many 35-liners
315 ## as we can, until the remaining space would be too small for a 25-liner.
316 ## If we can get two 25s out of that then we do (largest first); otherwise
317 ## just make one big one. We stop at the end of a page, once we've made
322 ## Initialize some parameters.
323 declare -i x=$(( ecols*e_colwd + e_hextra + XSCR0_X )) xb=xbound
324 declare -i n=0 pgx=0 l h y ht scr=0 ll=lim
325 declare -i hstd=$(( 35*t_lineht + t_vextra ))
326 declare -i hmin=$(( 25*t_lineht + t_vextra ))
327 declare -i scrx scry scrwd scrht
329 eval "scrx=\$XSCR${scr}_X scry=\$XSCR${scr}_Y
330 scrwd=\$XSCR${scr}_WIDTH scrht=\$XSCR${scr}_HEIGHT"
335 ## Start a new iteration.
336 if (( x + t_wd > ll )); then
338 if (( scr >= XNSCR )); then
339 if (( n >= 3 )); then break; fi
340 pgx=$(( pgx + XWIDTH )) xb=$(( xb + XWIDTH ))
343 eval "scrx=\$XSCR${scr}_X scry=\$XSCR${scr}_Y
344 scrwd=\$XSCR${scr}_WIDTH scrht=\$XSCR${scr}_HEIGHT"
347 if (( ll > xb )); then ll=xb; fi
350 ## Make large xterms.
352 while (( ht - hstd >= hmin )); do
353 run bgclients $term $geom 80x35+$x+$y
354 y=$(( y + hstd )) ht=$(( ht - hstd )) n=$(( n + 1 ))
357 ## Fill the remaining space.
358 if (( ht >= 2*hmin )); then h=$(( ht - hmin )); else h=ht; fi
359 l=$(( (h - t_vextra)/t_lineht )) h=$(( l*t_lineht + t_vextra ))
360 run bgclients $term $geom 80x$l+$x+$y
361 y=$(( y + h )) ht=$(( ht - h )) n=$(( n + 1 ))
362 if ((ht >= hmin)); then
363 run bgclients $term $geom 80x25+$x+$y
370 ###--------------------------------------------------------------------------
374 declare title=$1 hist=$2; shift 2
375 cmd=$(xgetline -t "$title" -p "_Command:" -Hl "$HOME/$hist") &&
379 ###--------------------------------------------------------------------------
382 atom=XINIT_COMMAND$atomtag
387 info "waiting on $atom"
388 line=$(xatom wait $atom)
393 xmsg -I -t "xinitrc help" -d "xinitrc commands" - <<EOF &
395 :emacs :xterms :window-manager :clients
396 :ask-run :ask-command
403 :emacs | :xterms | :window-manager | :clients)
413 info "restarting xinitrc"
414 exec "$0" wait nostart
417 req "Shell command" .cmd.hist xcatch -F"Fixed 13" -- sh -c&
420 req "xinit command" .xinit.hist xatom set XINIT_COMMAND$atomtag&
423 xmsg -E -t "xinitrc error" "Unknown command \`$line'" &
436 ###--------------------------------------------------------------------------
437 ### Gnome session care and feeding.
439 session-running-p () {
440 dbus-send --session --print-reply --dest=org.freedesktop.DBus / \
441 org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager \
445 dbus-service-running-p () {
446 dbus-send >/dev/null 2>&1 --session --print-reply \
447 --dest=org.freedesktop.DBus / \
448 org.freedesktop.DBus.GetNameOwner string:$1
451 kill-gnome-session () {
453 while read service object logout; do
454 if dbus-service-running-p $service; then win=t; break; fi
456 org.xfce.SessionManager /org/xfce/SessionManager org.xfce.Session.Manager.Shutdown uint32:1 boolean:false
457 org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:2
459 case $win in nil) return ;; esac
460 info "killing session manager"
461 dbus-send --session --dest=$service $object $logout
462 for i in 1 2 3 4 5; do
464 if ! dbus-service-running-p $service; then break; fi
468 ###--------------------------------------------------------------------------
469 ### Actually start things up.
471 if [ -f $HOME/.xinitrc-local ]; then
472 . $HOME/.xinitrc-local
477 info "starting standard clients"
485 info "not starting standard clients"
495 info "not waiting before exit"
499 ###----- That's all, folks --------------------------------------------------