xmonad-contrib icon indicating copy to clipboard operation
xmonad-contrib copied to clipboard

Add a LayoutClass to allow different layouts for portrait and landscape monitors.

Open gcoakes opened this issue 5 years ago • 4 comments

Problem Description

I wrote a simple instance of LayoutClass which will allow you to specify two different layouts, one for portrait and one for landscape. I wanted to scope out whether this would be accepted as a PR before I took the effort of integrating it with xmonad-contrib directly rather than just in my config.

Configuration File

Please include the smallest configuration file that reproduces the problem you are experiencing:

data EitherRatio p l a = EitherRatio (p a) (l a)
  deriving (Show, Read)

instance (LayoutClass p a, LayoutClass l a) => LayoutClass (EitherRatio p l) a where
  runLayout (W.Workspace i (EitherRatio p l) ms) r@(Rectangle rx ry rw rh)
    | rw < rh = do
        (lrs, newP) <- runLayout (W.Workspace i p ms) r
        return $ (lrs, fmap (`EitherRatio` l) newP)
    | rw >= rh = do
        (lrs, newL) <- runLayout (W.Workspace i l ms) r
        return $ (lrs, fmap (EitherRatio p) newL)

  handleMessage (EitherRatio p l) msg = do
    mp <- handleMessage p msg
    ml <- handleMessage l msg
    return $ case (mp, ml) of
      (Just np, Just nl) -> Just $ EitherRatio np nl
      (Just np, Nothing) -> Just $ EitherRatio np l
      (Nothing, Just nl) -> Just $ EitherRatio p nl
      _                  -> Nothing

  description (EitherRatio p l) =
    "[ " ++ description p ++ " | " ++ description l ++ " ]"

Checklist

gcoakes avatar Jun 09 '20 00:06 gcoakes

There's already a layout modifier that does this by comparing to a fixed horizontal size, which is less than ideal, so I don't see a reason it would be rejected.

geekosaur avatar Jun 09 '20 11:06 geekosaur

Might be a good idea to have them both in one module, but the XMonad.Layout.PerScreen name seems non-intuitive to me (I wouldn't look there if I was trying to find it), so maybe it's not as good an idea after all. :-)

liskin avatar Jun 09 '20 19:06 liskin

Looks great to me! And generally speaking, the bar for including new modules in xmonad-contrib is not that high---as long as it won't make xmonad crash and would be useful to someone, there's no good reason to exclude it. So your contribution would be most welcome.

byorgey avatar Jun 09 '20 20:06 byorgey

I'm not going to be pursuing this PR anymore. There were some issues associated with stale window decorations, and I've since stopped using it. If anyone wants to pick this up, I still think it would be useful to the project, but I won't personally be using it.

gcoakes avatar Jun 21 '20 16:06 gcoakes