如何在Xmonad中创建和处理自定义消息?

时间:2017-07-08 10:16:42

标签: 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 l@(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找到Maybe的实例声明后知道。

1 个答案:

答案 0 :(得分:0)

想出来。您只需添加其他布局'在列表中。

基本上所有msum都会得到第一个Just值并返回它,例如: msum [Nothing, Nothing, Just 1, Just 2, Nothing]将返回Just 1

  pureMessage l@(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) }