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
) ;;
117 info
"screen size = $XWIDTH x $XHEIGHT"
120 ## Load the X resource database.
121 run init xrdb
-override
$HOME/.Xdefaults
124 run init xset b
5 2000 50
125 run init xset r rate
500 50
129 xmodmap
$HOME/.xmodmap
130 if [ -r
$HOME/.xmodmap-local
]; then
131 xmodmap
$HOME/.xmodmap-local
135 ###--------------------------------------------------------------------------
136 ### Start a window manager.
138 wm
=$
(pick_program window-manager e16 compiz enlightenment e17 twm
)
141 enlightenment
,yes | e16
,yes)
142 wmopts
="$eopts -econfdir $HOME/.enlightenment-vnc"
147 run bginit manage
$wm $wmopts
149 for i
in $
(seq 10); do
151 if eesh version
>/dev
/null
2>&1; then
158 info
"$wm started ok"
159 run init xsetroot
-cursor_name left_ptr
162 info
"$wm failed to start!"
167 start-window-manager
() {
168 case $
(type -t start-
$wm ||
echo "not-found") in
173 run bginit manage
$wm $wmopts
178 ###--------------------------------------------------------------------------
179 ### Random useful clients.
181 start-clients-local
() { :; }
186 case "$vnc,$(xfce4-session --version 2>&1),$(gnome-session --version 2>&1)"
189 run bginit xfce4-session
191 no
,*,gnome-session\
2.3[2-9].
* | \
192 no
,*,gnome-session\
2.4[0-9].
* | \
193 no
,*,gnome-session\
2.
[1-9][0-9][0-9]*)
194 run bginit gnome-session
--session mdw
197 run bginit gnome-session
205 ###--------------------------------------------------------------------------
206 ### Main screen layout.
208 ## Choose appropriate clients.
209 emacs
=$
(pick_program emacs emacs23 emacs24 emacs22 emacs21 emacs
)
210 term
=$
(pick_program terminal pterm Eterm xterm
)
212 ## Emacs window measurements.
214 ## e_colwd = basic width of a column in pixels
215 ## e_hextra = extra horizontal width in pixels
216 ## Width of an N-column Emacs frame in pixels will be
217 ## N*e_colwd + e_hextra
218 ## e_colchars = width of a column in Emacs `-geometry' units
219 ## e_cextra = extra horizontal width in Emacs `-geometry' units
220 ## So an N-column frame should be reported to Emacs as being
221 ## N*e_colchars + e_cextra geometry units wide
222 ## e_lineht = height of a character line in pixels
223 ## e_vextra = number of additional vertical cruft pixels
224 ## So an N-line Emacs frame takes N*e_lineht + e_vextra pixels
227 e_colwd
=492 e_hextra
=34
228 e_colchars
=82 e_cextra
=-2
229 e_lineht
=13 e_vextra
=52
232 e_colwd
=492 e_hextra
=8
233 e_colchars
=82 e_cextra
=-6
234 e_lineht
=13 e_vextra
=46
237 e_colwd
=492 e_hextra
=5
238 e_colchars
=82 e_cextra
=-6
239 e_lineht
=13 e_vextra
=42
243 ## Terminal window measurements.
245 ## t_wd = the window width, in pixels
246 ## t_lineht, t_vextra = height parameters: if the window is N lines high,
247 ## then it will be N*t_lineht + t_vextra pixels high
249 pterm
) t_wd
=504 t_lineht
=13 t_vextra
=23 geom
=-geometry
;;
250 Eterm
) t_wd
=504 t_lineht
=13 t_vextra
=23 geom
=-g
;;
251 xterm
) t_wd
=507 t_lineht
=13 t_vextra
=27 geom
=-geometry
;;
254 ## GNOME stuff measurements.
255 declare -i xbound
="XWIDTH - 113"
257 ## Choose a width for Emacs.
259 ## We'd like it to be as wide as possible, allowing for a column of xterms
260 ## down the right hand side. However, I'd prefer a double-width Emacs to a
261 ## single-width Emacs and xterms. If it's not going to work at all, a single
262 ## Emacs column will have to do. Also, there's a strange thing with Emacs21
263 ## and the toolbar, so we add on some rows which are later mysteriously
266 declare -i ecols
="(xbound - t_wd - e_hextra)/e_colwd"
267 if (( ecols
< 2 && xbound
> e_colwd
* 2 + e_hextra
)); then
269 elif (( ecols
< 1 )); then
274 emacsx
="ecols * e_colchars + e_cextra" \
275 emacsy
="(XHEIGHT - e_vextra)/e_lineht"
278 GDK_NATIVE_WINDOWS
=1 run bgclients noip \
279 $emacs -bg black
-geometry
${emacsx}x
${emacsy}+0+0
282 ## Now place some xterms.
284 ## A few smaller xterms are in general better than one great big one. 35
285 ## lines is a good height for most terminals. 25 lines is a minimum. The
286 ## strategy for doling out xterms into a column is to make as many 35-liners
287 ## as we can, until the remaining space would be too small for a 25-liner.
288 ## If we can get two 25s out of that then we do (largest first); otherwise
289 ## just make one big one. We stop at the end of a page, once we've made
294 ## Initialize some parameters.
295 declare -i x
="ecols * e_colwd + e_hextra" xb
=xbound
296 declare -i n
=0 pgx
=0 l h y ht
297 declare -i hstd
="35 * t_lineht + t_vextra" hmin
="25 * t_lineht + t_vextra"
302 ## Start a new iteration.
303 if ((x
+ t_wd
> xb
)); then
304 if ((n
>= 3)); then break; fi
305 x
="pgx + XWIDTH" pgx
="pgx + XWIDTH" xb
="xb + XWIDTH"
308 ## Make large xterms.
310 while ((ht
- hstd
>= hmin
)); do
311 run bgclients
$term $geom 80x35
+$x+$y
312 y
="y + hstd" ht
="ht - hstd" n
="n + 1"
315 ## Fill the remaining space.
316 if ((ht
>= 2 * hmin
)); then h
="ht - hmin"; else h
=ht
; fi
317 l
="(h - t_vextra)/t_lineht" h
="l * t_lineht + t_vextra"
318 run bgclients
$term $geom 80x
$l+$x+$y
319 y
="y + h" ht
="ht - h" n
="n + 1"
320 if ((ht
>= hmin
)); then
321 run bgclients
$term $geom 80x25
+$x+$y
328 ###--------------------------------------------------------------------------
332 declare title
=$1 hist
=$2; shift 2
333 cmd
=$
(xgetline
-t
"$title" -p
"_Command:" -Hl
"$HOME/$hist") &&
337 ###--------------------------------------------------------------------------
340 atom
=XINIT_COMMAND
$atomtag
345 info
"waiting on $atom"
346 line
=$
(xatom
wait $atom)
351 xmsg
-I
-t
"xinitrc help" -d
"xinitrc commands" - <<EOF &
353 :emacs :xterms :window-manager :clients
354 :ask-run :ask-command
361 :emacs |
:xterms |
:window-manager |
:clients
)
371 info
"restarting xinitrc"
372 exec "$0" wait nostart
375 req
"Shell command" .cmd.hist xcatch
-F
"Fixed 13" -- sh
-c
&
378 req
"xinit command" .xinit.hist xatom
set XINIT_COMMAND
$atomtag&
381 xmsg
-E
-t
"xinitrc error" "Unknown command \`$line'" &
394 ###--------------------------------------------------------------------------
395 ### Gnome session care and feeding.
397 session-running-p
() {
398 dbus-send
--session
--print-reply
--dest
=org.freedesktop.DBus
/ \
399 org.freedesktop.DBus.GetNameOwner string
:org.gnome.SessionManager \
403 dbus-service-running-p
() {
404 dbus-send
>/dev
/null
2>&1 --session
--print-reply \
405 --dest
=org.freedesktop.DBus
/ \
406 org.freedesktop.DBus.GetNameOwner string
:$1
409 kill-gnome-session
() {
411 while read service object
logout; do
412 if dbus-service-running-p
$service; then win
=t
; break; fi
414 org.xfce.SessionManager /org/xfce/SessionManager org.xfce.Session.Manager.Shutdown uint32:1 boolean:false
415 org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:2
417 case $win in nil
) return ;; esac
418 info
"killing session manager"
419 dbus-send
--session
--dest
=$service $object $logout
420 for i
in 1 2 3 4 5; do
422 if ! dbus-service-running-p
$service; then break; fi
426 ###--------------------------------------------------------------------------
427 ### Actually start things up.
429 if [ -f
$HOME/.xinitrc-local
]; then
430 .
$HOME/.xinitrc-local
435 info
"starting standard clients"
443 info
"not starting standard clients"
453 info
"not waiting before exit"
457 ###----- That's all, folks --------------------------------------------------