From: Mark Wooding Date: Sat, 23 Apr 2016 11:42:38 +0000 (+0100) Subject: dot/xinitrc: Overhaul the Emacs/terminal allocation algorithm. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/30ab13b5d8bde81bd57d3bfd8c350666bb6e6e2e?ds=sidebyside;hp=-c dot/xinitrc: Overhaul the Emacs/terminal allocation algorithm. It's now different. I hadn't given thought to really large monitors when I came up with the original algorithm. I think the new one is more sensible, but we'll see. --- 30ab13b5d8bde81bd57d3bfd8c350666bb6e6e2e diff --git a/dot/xinitrc b/dot/xinitrc index 7f6d415..5a98ebf 100755 --- a/dot/xinitrc +++ b/dot/xinitrc @@ -266,18 +266,25 @@ declare -i panelwd=64 xbound=$(( XWIDTH - panelwd )) ## Choose a width for Emacs. ## -## We'd like it to be as wide as possible, allowing for a column of xterms -## down the right hand side. However, I'd prefer a double-width Emacs to a -## single-width Emacs and xterms. If it's not going to work at all, a single -## Emacs column will have to do. Also, there's a strange thing with Emacs21 -## and the toolbar, so we add on some rows which are later mysteriously -## subtracted. - +## We're going to make a single frame of Emacs, which will be automatically +## divvied into columns; the rest of the space will be tiled with xterms. If +## we have multiple screens, then Emacs can have the first screen and we'll +## fill the rest with terminals. Otherwise, we'll try to have N columns of +## Emacs, and N - 1 columns of xterms; if that doesn't work, we'll make do +## with N - 2 columns of xterms. +## +## So, let W be the available width; let E and T be the widths of an Emacs +## column (e_colwd) and terminal (t_wd), respectively, and let E0 be the +## additive width of Emacs's existence (e_hextra). If we have more than one +## screen, then instead, let T be zero. To start out, then, we let N = 1 + +## floor((W - E - E0)/(E + T)). If W - E0 - (N + 1) E - (N - 1)*T >= 0, then +## we increase N by one. 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 +declare -i twd=t_wd; if (( XNSCR > 1 )); then twd=0; fi +declare -i ecols=$(( (lim - e_colwd - e_hextra)/(e_colwd + twd) + 1 )) +if (( lim - e_hextra - (ecols + 1)*e_colwd - (ecols - 1)*twd >= 0 )); then + ecols=$(( ecols + 1 )) fi declare -i \