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 ## Tell things that XFCE is in charge. This is the most desktoppy thing that
114 ## I run, so it's not entirely wrong.
115 : ${XDG_CURRENT_DESKTOP=XFCE}; export XDG_CURRENT_DESKTOP
117 ## Obtain the screen dimensions.
118 case ",$XWIDTH,$XHEIGHT," in
119 *,,*) eval $
(xscsize
-bx
; xscsize
-bmx
) ;;
123 XNSCR
=1 XSCR0_X
=0 XSCR0_Y
=0 XSCR0_WIDTH
=$XWIDTH XSCR0_HEIGHT
=$XHEIGHT
126 i
=0; while (( i
< XNSCR
)); do
127 eval "x=\$XSCR${i}_X y=\$XSCR${i}_Y
128 wd=\$XSCR${i}_WIDTH ht=\$XSCR${i}_HEIGHT"
129 info
"screen #$i = ${wd}x${ht}+${x}+${y}"
134 ## Load the X resource database.
135 run init xrdb
-override
$HOME/.Xdefaults
138 run init xset b
5 2000 50
139 run init xset r rate
500 50
143 xmodmap
$HOME/.xmodmap
144 if [ -r
$HOME/.xmodmap-local
]; then
145 xmodmap
$HOME/.xmodmap-local
149 ###--------------------------------------------------------------------------
150 ### Start a window manager.
152 wm
=$
(pick_program window-manager e16 compiz enlightenment e17 twm
)
155 enlightenment
,yes | e16
,yes)
156 wmopts
="$eopts -econfdir $HOME/.enlightenment-vnc"
161 run bginit manage
$wm $wmopts
163 for i
in $
(seq 10); do
165 if eesh version
>/dev
/null
2>&1; then
172 info
"$wm started ok"
173 run init xsetroot
-cursor_name left_ptr
176 info
"$wm failed to start!"
181 start-window-manager
() {
182 case $
(type -t start-
$wm ||
echo "not-found") in
187 run bginit manage
$wm $wmopts
192 ###--------------------------------------------------------------------------
193 ### Random useful clients.
195 start-clients-local
() { :; }
200 case "$vnc,$(xfce4-session --version 2>&1),$(gnome-session --version 2>&1)"
203 run bginit xfce4-session
205 no
,*,gnome-session\
2.3[2-9].
* | \
206 no
,*,gnome-session\
2.4[0-9].
* | \
207 no
,*,gnome-session\
2.
[1-9][0-9][0-9]*)
208 run bginit gnome-session
--session mdw
211 run bginit gnome-session
219 ###--------------------------------------------------------------------------
220 ### Main screen layout.
222 ## Choose appropriate clients.
223 emacs
=$
(pick_program emacs \
224 emacs24-lucid emacs23-lucid emacs24 emacs23 emacs22 emacs21 \
226 term
=$
(pick_program terminal pterm Eterm xterm
)
228 ## If we fell back to an unversioned Emacs binary, then figure out what
229 ## version it actually is.
232 set -- $
($emacs --version |
head -n1
)
233 e_ver
=emacs
${3%%.*}${emacs#emacs}
239 info emacs-version
= $e_ver
241 ## Emacs window measurements.
243 ## e_colsz = width of a column in characters (from `emacs-width' metaconfig)
244 ## e_charwd = width of a character in pixels (assume `6x13')
245 ## e_colextra = additional per-column overhead in pixels
246 ## e_colextrachars = additional per-column overhead in character units
247 ## e_colwd = basic width of a column in pixels
248 ## e_hextra = extra horizontal width in pixels
249 ## Width of an N-column Emacs frame in pixels will be
250 ## N*e_colwd + e_hextra
251 ## e_colchars = width of a column in Emacs `-geometry' units
252 ## e_cextra = extra horizontal width in Emacs `-geometry' units
253 ## So an N-column frame should be reported to Emacs as being
254 ## N*e_colchars + e_cextra geometry units wide
255 ## e_lineht = height of a character line in pixels
256 ## e_vextra = number of additional vertical cruft pixels
257 ## So an N-line Emacs frame takes N*e_lineht + e_vextra pixels
258 e_colsz
=$
(mdw-conf emacs-width
77) e_charwd
=6
259 e_colextra
=30 e_colextrachars
=5 e_lineht
=13
261 emacs21 | emacs
) e_hextra
=34 e_cextra
=-2 e_vextra
=52 ;;
262 emacs22 | emacs23
) e_hextra
=8 e_cextra
=-6 e_vextra
=46 ;;
263 emacs24
) e_hextra
=5 e_cextra
=-6 e_vextra
=42 ;;
264 emacs23-lucid
) e_hextra
=7 e_cextra
=-6 e_vextra
=48 ;;
265 emacs24-lucid
) e_hextra
=7 e_cextra
=-5 e_vextra
=48 ;;
266 emacs26-lucid
) e_hextra
=5 e_cextra
=-6 e_vextra
=51 ;;
268 e_colwd
=$
(( e_colsz
*e_charwd
+ e_colextra
))
269 e_colchars
=$
(( e_colsz
+ e_colextrachars
))
271 ## Terminal window measurements.
273 ## t_wd = the window width, in pixels
274 ## t_lineht, t_vextra = height parameters: if the window is N lines high,
275 ## then it will be N*t_lineht + t_vextra pixels high
278 ## The pterm width differs according to whether it's linked against Gtk 2
279 ## or 3. Let's find out...
280 case $
(ldd $
(command -v pterm
) |
grep libgtk
) in
281 libgtk-2
*) t_wd
=504 ;;
284 t_lineht
=13 t_vextra
=23 geom
=-geometry
;;
285 Eterm
) t_wd
=504 t_lineht
=13 t_vextra
=23 geom
=-g
;;
286 xterm
) t_wd
=507 t_lineht
=13 t_vextra
=27 geom
=-geometry
;;
289 ## GNOME stuff measurements.
290 declare -i panelwd
=64 xbound
=$
(( XWIDTH
- panelwd
))
292 ## Choose a width for Emacs.
294 ## We're going to make a single frame of Emacs, which will be automatically
295 ## divvied into columns; the rest of the space will be tiled with xterms. If
296 ## we have multiple screens, then Emacs can have the first screen and we'll
297 ## fill the rest with terminals. Otherwise, we'll try to have N columns of
298 ## Emacs, and N - 1 columns of xterms; if that doesn't work, we'll make do
299 ## with N - 2 columns of xterms.
301 ## So, let W be the available width; let E and T be the widths of an Emacs
302 ## column (e_colwd) and terminal (t_wd), respectively, and let E0 be the
303 ## additive width of Emacs's existence (e_hextra). If we have more than one
304 ## screen, then instead, let T be zero. To start out, then, we let N = 1 +
305 ## floor((W - E - E0)/(E + T)). If W - E0 - (N + 1) E - (N - 1)*T >= 0, then
306 ## we increase N by one.
307 declare -i lim
=XSCR0_WIDTH
308 if (( lim
> xbound
)); then lim
=xbound
; fi
309 declare -i twd
=t_wd
; if (( XNSCR
> 1 )); then twd
=0; fi
310 declare -i ecols
=$
(( (lim
- e_colwd
- e_hextra
)/(e_colwd
+ twd
) + 1 ))
311 if (( lim
- e_hextra
- (ecols
+ 1)*e_colwd
- (ecols
- 1)*twd
>= 0 )); then
312 ecols
=$
(( ecols
+ 1 ))
316 emacsx
=$
(( ecols
*e_colchars
+ e_cextra
)) \
317 emacsy
=$
(( (XHEIGHT
- e_vextra
)/e_lineht
))
320 GDK_NATIVE_WINDOWS
=1 run bgclients noip \
321 $emacs -bg black
-geometry
${emacsx}x
${emacsy}+${XSCR0_X}+${XSCR0_Y} \
322 --mdw-splashy-startup
325 ## Now place some xterms.
327 ## A few smaller xterms are in general better than one great big one. 35
328 ## lines is a good height for most terminals. 25 lines is a minimum. The
329 ## strategy for doling out xterms into a column is to make as many 35-liners
330 ## as we can, until the remaining space would be too small for a 25-liner.
331 ## If we can get two 25s out of that then we do (largest first); otherwise
332 ## just make one big one. We stop at the end of a page, once we've made
337 ## Initialize some parameters.
338 declare -i x
=$
(( ecols
*e_colwd
+ e_hextra
+ XSCR0_X
)) xb
=xbound
339 declare -i n
=0 pgx
=0 l h y ht scr
=0 ll
=lim
340 declare -i hstd
=$
(( 35*t_lineht
+ t_vextra
))
341 declare -i hmin
=$
(( 25*t_lineht
+ t_vextra
))
342 declare -i scrx scry scrwd scrht
344 eval "scrx=\$XSCR${scr}_X scry=\$XSCR${scr}_Y
345 scrwd=\$XSCR${scr}_WIDTH scrht=\$XSCR${scr}_HEIGHT"
350 ## Start a new iteration.
351 if (( x
+ t_wd
> ll
)); then
353 if (( scr
>= XNSCR
)); then
354 if (( n
>= 3 )); then break; fi
355 pgx
=$
(( pgx
+ XWIDTH
)) xb
=$
(( xb
+ XWIDTH
))
358 eval "scrx=\$XSCR${scr}_X scry=\$XSCR${scr}_Y
359 scrwd=\$XSCR${scr}_WIDTH scrht=\$XSCR${scr}_HEIGHT"
362 if (( ll
> xb
)); then ll
=xb
; fi
365 ## Make large xterms.
367 while (( ht
- hstd
>= hmin
)); do
368 run bgclients
$term $geom 80x35
+$x+$y
369 y
=$
(( y
+ hstd
)) ht
=$
(( ht
- hstd
)) n
=$
(( n
+ 1 ))
372 ## Fill the remaining space.
373 if (( ht
>= 2*hmin
)); then h
=$
(( ht
- hmin
)); else h
=ht
; fi
374 l
=$
(( (h
- t_vextra
)/t_lineht
)) h
=$
(( l
*t_lineht
+ t_vextra
))
375 run bgclients
$term $geom 80x
$l+$x+$y
376 y
=$
(( y
+ h
)) ht
=$
(( ht
- h
)) n
=$
(( n
+ 1 ))
377 if ((ht
>= hmin
)); then
378 run bgclients
$term $geom 80x25
+$x+$y
385 ###--------------------------------------------------------------------------
389 declare title
=$1 hist
=$2; shift 2
390 cmd
=$
(xgetline
-t
"$title" -p
"_Command:" -Hl
"$HOME/$hist") &&
394 ###--------------------------------------------------------------------------
397 atom
=XINIT_COMMAND
$atomtag
402 info
"waiting on $atom"
403 line
=$
(xatom
wait $atom)
408 xmsg
-I
-t
"xinitrc help" -d
"xinitrc commands" - <<EOF &
410 :emacs :xterms :window-manager :clients
411 :ask-run :ask-command
418 :emacs |
:xterms |
:window-manager |
:clients
)
428 info
"restarting xinitrc"
429 exec "$0" wait nostart
432 req
"Shell command" .cmd.hist xcatch
-F
"Fixed 13" -- sh
-c
&
435 req
"xinit command" .xinit.hist xatom
set XINIT_COMMAND
$atomtag&
438 xmsg
-E
-t
"xinitrc error" "Unknown command \`$line'" &
451 ###--------------------------------------------------------------------------
452 ### Gnome session care and feeding.
454 session-running-p
() {
455 dbus-send
--session
--print-reply
--dest
=org.freedesktop.DBus
/ \
456 org.freedesktop.DBus.GetNameOwner string
:org.gnome.SessionManager \
460 dbus-service-running-p
() {
461 dbus-send
>/dev
/null
2>&1 --session
--print-reply \
462 --dest
=org.freedesktop.DBus
/ \
463 org.freedesktop.DBus.GetNameOwner string
:$1
466 kill-gnome-session
() {
468 while read service object
logout; do
469 if dbus-service-running-p
$service; then win
=t
; break; fi
471 org.xfce.SessionManager /org/xfce/SessionManager org.xfce.Session.Manager.Shutdown uint32:1 boolean:false
472 org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:2
474 case $win in nil
) return ;; esac
475 info
"killing session manager"
476 dbus-send
--session
--dest
=$service $object $logout
477 for i
in 1 2 3 4 5; do
479 if ! dbus-service-running-p
$service; then break; fi
483 ###--------------------------------------------------------------------------
484 ### Actually start things up.
486 if [ -f
$HOME/.xinitrc-local
]; then
487 .
$HOME/.xinitrc-local
492 info
"starting standard clients"
500 info
"not starting standard clients"
510 info
"not waiting before exit"
514 ###----- That's all, folks --------------------------------------------------