aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Config/Monad.hs
blob: db290977efe97d8538696713afb1ae5b3e0aef88 (plain) (blame)
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
49
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

-- experimental, not expected to work

{- our goal:
config = do
    add layout Full
    set terminal "urxvt"
    add keys [blah blah blah]
-}

{-
ideas:
    composability!
    "only once" features like avoidStruts, ewmhDesktops
-}

module XMonad.Config.Monad where

import XMonad hiding (terminal, keys)
import qualified XMonad as X
import Control.Monad.Writer
import Data.Monoid
import Data.Accessor
import Data.Accessor.Basic hiding (set)

-- Ugly!  To fix this we'll need to change the kind of XConfig.
newtype LayoutList a = LL [Layout a] deriving Monoid

type W = Dual (Endo (XConfig LayoutList))
mkW = Dual . Endo

newtype Config a = C (WriterT W IO a)
    deriving (Functor, Monad, MonadWriter W)

-- references:
layout = fromSetGet (\x c -> c { layoutHook = x }) layoutHook
terminal = fromSetGet (\x c -> c { X.terminal = x }) X.terminal
keys = fromSetGet (\x c -> c { X.keys = x }) X.keys

set :: Accessor (XConfig LayoutList) a -> a -> Config () 
set r x = tell (mkW $ r ^= x)
add r x = tell (mkW (r ^: mappend x))

--
example :: Config ()
example = do
    add layout $ LL [Layout $ Full] -- make this better
    set terminal "urxvt"