putty-defaults: Revert bogus change to Putty terminal height.
[profile] / xinitrc
1 #! /bin/bash
2
3 xx= tt=:; if [ "$XINIT_TEST" != "" ]; then xx=: tt=echo; set -x; fi
4 $xx xrdb -override $HOME/.Xdefaults
5 : ${VNCSESSION=false}
6 export __mdw_sechost="`hostname`"
7
8 # --- Do some fiddling ---
9
10 cleanup=":"
11 xset b 10 2000 50
12 xset r rate 500 50
13 xset m 1 1
14 $xx gnome-settings-daemon&
15 $xx mail-notification&
16 $xx $VNCSESSION || $xx gkrellm&
17 if [ "$XINIT_TEST" = "" ] || [ "$XWIDTH" = "" ] || [ "$XHEIGHT" = "" ]; then
18 eval `xscsize -bx`
19 fi
20
21 # --- Crank up ESD ---
22
23 if ! $xx [ -r /tmp/.esd/socket ]; then
24 esd -nobeeps -as 10&
25 cleanup="$cleanup; kill $!"
26 fi
27
28 # --- Picking appropriate programs ---
29
30 pick_program () {
31 for i in "$@"; do
32 if type -t >/dev/null "$i"; then echo "$i"; return; fi
33 done
34 echo false
35 }
36
37 # --- Start a nice window manager ---
38
39 : ${wm=$(pick_program enlightenment e16)}
40 $tt Window manager is $wm.
41 $xx $wm $EOPTS&
42
43 # --- Crank up a screenlock program ---
44
45 if ! $xx $VNCSESSION; then
46 xscreensaver-command -exit
47 xscreensaver -no-splash&
48 fi
49 $xx gnome-panel&
50
51 # --- Emacs window measurements ---
52 #
53 # Horizontal column pixel width = 492; window manager overhead = 34
54 # Column character width = 82; Emacs magic overhead = -2
55 # Vertical line pixel height = 13; misc overhead = 52
56
57 : ${emacs=$(pick_program emacs22 emacs21)}
58 $tt Using editor $emacs.
59 case "$emacs" in
60 emacs21)
61 e_colwd=492 e_hextra=34
62 e_colchars=82 e_cextra=-2
63 e_lineht=13 e_vextra=52
64 ;;
65 emacs22)
66 e_colwd=492 e_hextra=8
67 e_colchars=82 e_cextra=-6
68 e_lineht=13 e_vextra=46
69 ;;
70 esac
71
72 # --- Xterm window measurements ---
73 #
74 # Window width is 503 (fixed).
75 # Vertical line pixel height = 13; misc overhead = 23
76
77 : ${term=$(pick_program pterm Eterm xterm)}
78 $tt Using terminal $tt
79 case "$term" in
80 pterm) t_wd=503 t_lineht=13 t_vextra=23 geom=-geometry;;
81 Eterm) t_wd=504 t_lineht=13 t_vextra=23 geom=-g;;
82 xterm) t_wd=507 t_lineht=13 t_vextra=27 geom=-geometry;;
83 esac
84
85 # --- GNOME stuff measurements ---
86 #
87 # GNOME panel width = 113
88
89 declare -i xbound="XWIDTH - 113"
90
91 # --- Choose a width for Emacs ---
92 #
93 # We'd like it to be as wide as possible, allowing for a column of xterms
94 # down the right hand side. However, I'd prefer a double-width Emacs to a
95 # single-width Emacs and xterms. If it's not going to work at all, a single
96 # Emacs column will have to do. Also, there's a strange thing with Emacs21
97 # and the toolbar, so we add on some rows which are later mysteriously
98 # subtracted.
99
100 declare -i ecols="(xbound - t_wd - e_hextra)/e_colwd"
101 if (( ecols < 2 && xbound > e_colwd * 2 + e_hextra )); then
102 ecols=2
103 elif (( ecols < 1 )); then
104 ecols=1
105 fi
106
107 declare -i x="ecols * e_colwd + e_hextra"
108 noip $emacs -geometry $((ecols * e_colchars + e_cextra))x$(((XHEIGHT - e_vextra)/e_lineht))+0+0&
109
110 # --- Now place some xterms ---
111 #
112 # A few smaller xterms are in general better than one great big one. 35
113 # lines is a good height for most terminals. 25 lines is a minimum. The
114 # strategy for doling out xterms into a column is to make as many 35-liners
115 # as we can, until the remaining space would be too small for a 25-liner. If
116 # we can get two 25s out of that then we do (largest first); otherwise just
117 # make one big one. We stop at the end of a page, once we've made three
118 # xterms.
119
120 declare -i n=0 pgx=0 l h y ht
121 declare -i hstd="35 * t_lineht + t_vextra" hmin="25 * t_lineht + t_vextra"
122 while true; do
123 if ((x + t_wd > xbound)); then
124 if ((n >= 3)); then break; fi
125 x="pgx + XWIDTH" pgx="pgx + XWIDTH" xbound="xbound + XWIDTH"
126 fi
127 y=0 ht=XHEIGHT
128 while ((ht - hstd >= hmin)); do
129 $term $geom 80x35+$x+$y&
130 y="y + hstd" ht="ht - hstd" n="n + 1"
131 done
132 if ((ht >= 2 * hmin)); then h="ht - hmin"; else h=ht; fi
133 l="(h - t_vextra)/t_lineht" h="l * t_lineht + t_vextra"
134 $term $geom 80x$l+$x+$y&
135 y="y + h" ht="ht - h" n="n + 1"
136 if ((ht >= hmin)); then
137 $term $geom 80x25+$x+$y&
138 n="n + 1"
139 fi
140 x="x + t_wd"
141 done
142
143 # --- Wait for the world to end ---
144
145 $xx xwait XWAIT_DIE:XWAIT_DIE_NOW
146 $xx eval "$cleanup"