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