2017-07-08 67 views
0

我想實現自定義消息以通過自定義佈局進行處理。如何在Xmonad中創建和處理自定義消息?

data ModifySideContainer = IncrementLeftColumnContainer | IncrementRightColumnContainer deriving Typeable 
instance Message ModifySideContainer 

我也不太清楚瞭如何在pureMessagehttps://hackage.haskell.org/package/xmonad-0.13/docs/XMonad-Core.html#v:pureMessage

這是我目前PureMessage的實現(自定義佈局內)處理自定義消息:

pureMessage [email protected](MiddleColumn sr mcc deltaInc _) m = msum [ 
    fmap resize  (fromMessage m), 
    fmap incmastern (fromMessage m) 
    ] 
    where 
     resize Expand = l {splitRatio = (min 0.5 $ sr + deltaInc)} 
     resize Shrink = l {splitRatio = (max 0 $ sr - deltaInc)} 
     incmastern (IncMasterN x) = l { middleColumnCount = max 0 (mcc+x) } 

我不不太明白這個邏輯是如何工作的(我從某處複製它),msum在這裏做什麼?我想我會知道,一旦我找到的實例聲明mplus

回答

0

想通了。你只需要在列表中添加額外的「佈局」。

基本上所有msum確實是得到的第一個Just值並返回例如: msum [Nothing, Nothing, Just 1, Just 2, Nothing]將返回Just 1

pureMessage [email protected](MiddleColumn sRatio mcc deltaInc _ leftCount rightCount) m = msum [ 
    fmap resize  (fromMessage m), 
    fmap incmastern (fromMessage m), 
    fmap incSideContainer (fromMessage m) 
    ] 
    where 
     incSideContainer IncrementLeftColumnContainer = l 
     { leftContainerCount = leftCount + 1, rightContainerCount = rightCount - 1} 
     incSideContainer IncrementRightColumnContainer = l 
     { leftContainerCount = leftCount - 1, rightContainerCount = rightCount + 1} 
     resize Expand = l {splitRatio = (min 0.5 $ sRatio + deltaInc)} 
     resize Shrink = l {splitRatio = (max 0 $ sRatio - deltaInc)} 
     incmastern (IncMasterN x) = l { middleColumnCount = max 0 (mcc+x) } 
相關問題