-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngineerLayout.hs
More file actions
48 lines (44 loc) · 1.97 KB
/
EngineerLayout.hs
File metadata and controls
48 lines (44 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TupleSections #-}
module EngineerLayout (Engineer(Engineer), WindowFn(..)) where
import XMonad hiding (state)
import XMonad.StackSet
import qualified Data.List as List
import Data.Bifunctor(second)
class (Read b, Show b) => WindowFn fn b | fn -> b where
windowFunction :: fn -> Window -> X b
data Engineer fn b l a = Engineer
{ specifyWindow :: fn
, matchers :: [[(b, RationalRect)]]
, defaultLayout :: l a
} deriving (Show,Read)
instance (WindowFn fn b, Show b, Ord b, Show fn, Read b, LayoutClass l Window) => LayoutClass (Engineer fn b l) Window where
description _ = "Engineer"
runLayout (Workspace i (Engineer fn matchMap fallBackLayout) ms ) baseRect =
maybe defLayout engineerLayout ms
where
-- wrap l inside Engineer
wrapLayout = fmap (second (fmap (Engineer fn matchMap)))
defLayout = wrapLayout $ runLayout (Workspace i fallBackLayout ms) baseRect
engineerLayout s =
layoutMatch >>= maybe defLayout
(return . (,layoutState) . zip ws . map scaleRect)
where
ws = integrate s
scaleRect = scaleRationalRect baseRect
progTypes = mapM (windowFunction fn) ws
layoutState = Just (Engineer fn matchMap fallBackLayout)
layoutMatch = pickLayout <$> progTypes
pickLayout programs =
match >>= Just . orderMatch programs
where
match = List.find ((== List.sort programs ) . List.sort . map fst) matchMap
orderMatch (progType:xs) (matchTuple@(matcherType,matcherPositions):ys) =
if progType == matcherType
then matcherPositions:orderMatch xs ys
-- shuffle matcher to look for rest. if match code is correct, is finite
else orderMatch (progType:xs) (ys ++ [matchTuple])
orderMatch _ [] = []
orderMatch [] y = map snd y