<div dir="ltr">In general, we do things like this with layout modifiers so they can be applied to more than one layout. In this case, you might get some ideas from X.L.Magnifier or X.L.Maximize: the former enlarges the focused window in a layout, the latter lets you pop out a window to "almost fullscreen" (it has a gap which IIRC can be configured in recent versions). There's also X.L.IfMax which lets you conditionalize on how many windows a layout has, so you almost have the pieces needed to build what you want (X.L.Magnifier with X.L.IfMax is not quite it because there's no gap, and X.L.Maximize needs to be triggered by a keypress).</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jan 4, 2020 at 4:41 AM Dusan Popovic <<a href="mailto:dpx@binaryapparatus.com">dpx@binaryapparatus.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
With being near impossible to get any non 16:9 monitor, and using big<br>
monitor (27" or bigger), any single terminal/editor takes entire screen<br>
when using Tall layout. This makes all the text aligned at the left edge<br>
of the monitor, which forces me to either sit facing the left half of<br>
the monitor or stretch my neck 90+% of time. I decided to modify Tall<br>
layout, so that with single window open it doesn't take all the space,<br>
while with more than one window open it behaves exactly as Tall already<br>
does.<br>
<br>
I am really beginner in haskell but I can do basic stuff, so I chopped<br>
built in Tall layout, modified it a bit, added to xmonad.hs. While it<br>
works well I am convinced there must be more elegant way to do the same,<br>
so I am curious how to do it better.<br>
<br>
Steps I took to make it work:<br>
<br>
1. Chop LANGUAGE directive from xmonad-git/src/XMonad/Layout.hs and add<br>
to my xmonad.hs at the top. I would love to avoid having<br>
FlexibleInstances in my xmonad.hs.<br>
<br>
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, PatternGuards, TypeSynonymInstances, DeriveDataTypeable #-}<br>
<br>
2. Chop and modify Tall layout, add it to xmonad.sh, most important part<br>
being 'tile54 f (Rectangle sx sy sw sh) nmaster 1' function that matches<br>
when there is only one window.<br>
<br>
import Control.Arrow ((***), second)<br>
import Control.Monad<br>
import Graphics.X11 (Rectangle(..))<br>
<br>
data Tall54 a = Tall54 { tallNMaster :: !Int -- ^ The default number of windows in the master pane (default: 1)<br>
, tallRatioIncrement :: !Rational -- ^ Percent of screen to increment by when resizing panes (default: 3/100)<br>
, tallRatio :: !Rational -- ^ Default proportion of screen occupied by master pane (default: 1/2)<br>
}<br>
deriving (Show, Read)<br>
<br>
instance LayoutClass Tall54 a where<br>
pureLayout (Tall54 nmaster _ frac) r s = zip ws rs<br>
where ws = W.integrate s<br>
rs = tile54 frac r nmaster (length ws)<br>
<br>
pureMessage (Tall54 nmaster delta frac) m =<br>
msum [fmap resize (fromMessage m)<br>
,fmap incmastern (fromMessage m)]<br>
<br>
where resize Shrink = Tall54 nmaster delta (max 0 $ frac-delta)<br>
resize Expand = Tall54 nmaster delta (min 1 $ frac+delta)<br>
incmastern (IncMasterN d) = Tall54 (max 0 (nmaster+d)) delta frac<br>
<br>
description _ = "Tall54"<br>
<br>
tile54<br>
:: Rational -- ^ @frac@, what proportion of the screen to devote to the master area<br>
-> Rectangle -- ^ @r@, the rectangle representing the screen<br>
-> Int -- ^ @nmaster@, the number of windows in the master pane<br>
-> Int -- ^ @n@, the total number of windows to tile<br>
-> [Rectangle]<br>
tile54 f (Rectangle sx sy sw sh) nmaster 1 = [Rectangle sx1 sy sw1 sh]<br>
where sx1 = sx + sm1<br>
sm1 = fromIntegral (sw - sw1) `div` 2<br>
sw1 = 5 * fromIntegral (sh `div` 4)<br>
tile54 f r nmaster n = if n <= nmaster || nmaster == 0<br>
then splitVertically n r<br>
else splitVertically nmaster r1 ++ splitVertically (n-nmaster) r2 -- two columns<br>
where (r1,r2) = splitHorizontallyBy f r<br>
<br>
3. Add new layout in the list, keeping standard Tall as second one. In<br>
rare cases when I want single window taking entire screen I can switch<br>
to Tall.<br>
<br>
As a result, when I open single terminal or editor window it is<br>
centered, simulating old 5:4 monitors. More than one window and it is<br>
standard Tall layout. I have attached my xmonad.hs if somebody wants to<br>
try.<br>
<br>
So finally questions:<br>
<br>
1. Anybody needs this apart from me? How do you cope with<br>
'teaminal/editor being too far to the left'?<br>
<br>
2. Is there a better way to write this layout (in xmonad.hs) without<br>
butchering parts of code from Layout.hs? Since I am learning haskell I<br>
believe any pointers would be very useful.<br>
<br>
Cheers,<br>
Dusan<br>
_______________________________________________<br>
xmonad mailing list<br>
<a href="mailto:xmonad@haskell.org" target="_blank">xmonad@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>brandon s allbery kf8nh</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a></div></div></div></div></div>