chiark / gitweb /
doc/xinitrc: Handle Emacs and terminal placement on multihead displays.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 22 Apr 2016 17:39:39 +0000 (18:39 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 22 Apr 2016 17:39:39 +0000 (18:39 +0100)
This requires a very shiny version of xscsize.

dot/xinitrc

index 215e27eb33c2b53e98c986d64655928cbeebcfea..81a7aaf44320f25ead82cf6b36c58a3d3334b5ca 100755 (executable)
@@ -112,9 +112,19 @@ export __mdw_sechost="`hostname`"
 
 ## Obtain the screen dimensions.
 case ",$XWIDTH,$XHEIGHT," in
-  *,,*) eval $(xscsize -bx) ;;
+  *,,*) eval $(xscsize -bx; xscsize -bmx) ;;
 esac
-info "screen size = $XWIDTH x $XHEIGHT"
+case ",$XNSCR," in
+  ,,)
+    XNSCR=1 XSCR0_X=0 XSCR0_Y=0 XSCR0_WIDTH=$XWIDTH XSCR0_HEIGHT=XHEIGHT
+    ;;
+esac
+i=0; while (( i < XNSCR )); do
+  eval "x=\$XSCR${i}_X y=\$XSCR${i}_Y
+       wd=\$XSCR${i}_WIDTH ht=\$XSCR${i}_HEIGHT"
+  info "screen #$i = ${wd}x${ht}+${x}+${y}"
+  i=$(( i + 1 ))
+done
 
 initialize () {
   ## Load the X resource database.
@@ -263,15 +273,15 @@ declare -i panelwd=64 xbound=$(( XWIDTH - panelwd ))
 ## and the toolbar, so we add on some rows which are later mysteriously
 ## subtracted.
 
-declare -i ecols="(xbound - t_wd - e_hextra)/e_colwd"
-if (( ecols < 2 && xbound > e_colwd * 2 + e_hextra )); then
-  ecols=2
-elif (( ecols < 1 )); then
-  ecols=1
+declare -i lim=XSCR0_WIDTH
+if (( lim > xbound )); then lim=xbound; fi
+declare -i ecols="(lim - t_wd - e_hextra)/e_colwd"
+if (( ecols < 2 && lim > 2*e_colwd + e_hextra )); then ecols=2
+elif (( ecols < 1 )); then ecols=1
 fi
 
 declare -i \
-  emacsx="ecols * e_colchars + e_cextra" \
+  emacsx="ecols*e_colchars + e_cextra" \
   emacsy="(XHEIGHT - e_vextra)/e_lineht"
 
 start-emacs () {
@@ -292,21 +302,34 @@ start-emacs () {
 start-xterms () {
 
   ## Initialize some parameters.
-  declare -i x="ecols * e_colwd + e_hextra" xb=xbound
-  declare -i n=0 pgx=0 l h y ht
-  declare -i hstd="35 * t_lineht + t_vextra" hmin="25 * t_lineht + t_vextra"
+  declare -i x="ecols*e_colwd + e_hextra" xb=xbound
+  declare -i n=0 pgx=0 l h y ht scr=0 ll=lim
+  declare -i hstd="35*t_lineht + t_vextra" hmin="25*t_lineht + t_vextra"
+  declare -i scrx scry scrwd scrht
+
+  eval "scrx=\$XSCR${scr}_X scry=\$XSCR${scr}_Y
+       scrwd=\$XSCR${scr}_WIDTH scrht=\$XSCR${scr}_HEIGHT"
 
   ## Do the placement.
   while :; do
 
     ## Start a new iteration.
-    if ((x + t_wd > xb)); then
-      if ((n >= 3)); then break; fi
-      x="pgx + XWIDTH" pgx="pgx + XWIDTH" xb="xb + XWIDTH"
+    if ((x + t_wd > ll)); then
+      scr=$(( scr + 1 ))
+      if (( scr >= XNSCR )); then
+       if (( n >= 3 )); then break; fi
+       pgx=$(( pgx + XWIDTH )) xb=$(( xb + XWIDTH ))
+       scr=0
+      fi
+      eval "scrx=\$XSCR${scr}_X scry=\$XSCR${scr}_Y
+           scrwd=\$XSCR${scr}_WIDTH scrht=\$XSCR${scr}_HEIGHT"
+      x=$(( pgx + scrx ))
+      ll=$(( x + scrwd ))
+      if (( ll > xb )); then ll=xb; fi
     fi
 
     ## Make large xterms.
-    y=0 ht=XHEIGHT
+    y=scry ht=scrht
     while ((ht - hstd >= hmin)); do
       run bgclients $term $geom 80x35+$x+$y
       y="y + hstd" ht="ht - hstd" n="n + 1"