<commit_before>-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.Combo
-- Copyright   :  (c) <NAME> <<EMAIL>>
-- License     :  BSD-style (see LICENSE)
-- 
-- Maintainer  :  <NAME> <<EMAIL>>
-- Stability   :  unstable
-- Portability :  unportable
--
-- A layout that combines multiple layouts.
--
-----------------------------------------------------------------------------

module XMonadContrib.Combo (
                            -- * Usage
                            -- $usage 
                            combo
                           ) where

import XMonad
import StackSet ( integrate, differentiate )

-- $usage
--
-- To use this layout write, in your Config.hs:
-- 
-- > import XMonadContrib.Combo 
-- 
-- and add something like
-- 
-- > combo [(full,1),(tabbed,1)] (twoPane 0.03 0.5)
--
-- to your defaultLayouts.

combo :: [(Layout, Int)] -> Layout -> Layout
combo origls super = Layout { doLayout = \r s -> arrange r (integrate s), modifyLayout = message }
    where arrange _ [] = return []
          arrange r [w] = return [(w,r)]
          arrange rinput origws =
              do rs <- map snd `fmap` runLayout super rinput (differentiate $ take (length origls) origws)
                 let wss [] _ = []
                     wss [_] ws = [ws]
                     wss (n:ns) ws = take len1 ws : wss ns (drop len1 ws)
                         where len1 = min n (length ws - length ns)
                 out <- sequence $ zipWith3 runLayout (map fst origls) rs
                                                      (map differentiate $
                                                       wss (take (length rs) $ map snd origls) origws)
                 return $ concat out
          message m = do msuper' <- modifyLayout super m
                         case msuper' of
                           Nothing -> return Nothing
                           Just super' -> return $ Just $ combo origls super'<commit_msg>fix leak in Combo. We leaked decorations, since UnDoLayout wasn't passed to the actual layouts that had decorations attached.  :(<commit_after>-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.Combo
-- Copyright   :  (c) <NAME> <<EMAIL>>
-- License     :  BSD-style (see LICENSE)
-- 
-- Maintainer  :  <NAME> <<EMAIL>>
-- Stability   :  unstable
-- Portability :  unportable
--
-- A layout that combines multiple layouts.
--
-----------------------------------------------------------------------------

module XMonadContrib.Combo (
                            -- * Usage
                            -- $usage 
                            combo
                           ) where

import XMonad
import StackSet ( integrate, differentiate )
import Operations ( UnDoLayout(UnDoLayout) )

-- $usage
--
-- To use this layout write, in your Config.hs:
-- 
-- > import XMonadContrib.Combo 
-- 
-- and add something like
-- 
-- > combo [(full,1),(tabbed,1)] (twoPane 0.03 0.5)
--
-- to your defaultLayouts.

combo :: [(Layout, Int)] -> Layout -> Layout
combo origls super = Layout { doLayout = \r s -> arrange r (integrate s), modifyLayout = message }
    where arrange _ [] = return []
          arrange r [w] = return [(w,r)]
          arrange rinput origws =
              do rs <- map snd `fmap` runLayout super rinput (differentiate $ take (length origls) origws)
                 let wss [] _ = []
                     wss [_] ws = [ws]
                     wss (n:ns) ws = take len1 ws : wss ns (drop len1 ws)
                         where len1 = min n (length ws - length ns)
                 out <- sequence $ zipWith3 runLayout (map fst origls) rs
                                                      (map differentiate $
                                                       wss (take (length rs) $ map snd origls) origws)
                 return $ concat out
          message m | Just UnDoLayout <- fromMessage m =
                         do (super':ls') <- broadcastPrivate UnDoLayout (super:map fst origls)
                            return $ Just $ combo (zip ls' $ map snd origls) super'
          message m = do msuper' <- modifyLayout super m
                         case msuper' of
                           Nothing -> return Nothing
                           Just super' -> return $ Just $ combo origls super'

broadcastPrivate :: Message a => a -> [Layout] -> X [Layout]
broadcastPrivate a ol = mapM f ol
    where f l = do ml' <- modifyLayout l (SomeMessage a) `catchX` return (Just l)
                   return $ maybe l id ml'
{'fraction_non_alphanumeric': 0.16507798960138648, 'fraction_numerical': 0.004766031195840554, 'mean_word_length': 1.1943916349809887, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1703019', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1149, 'n_words': 406}