[英]How can I modify the windowSet in XMonad?
I have a function that looks like:我有一个看起来像的函数:
sinkFocus :: StackSet i l a s sd -> Maybe (StackSet i l a s sd)
sinkFocus = (fmap . flip sink) <*> peek
However I would like an X ()
so that I can use it.但是我想要一个X ()
以便我可以使用它。 For example additionalKeys
uses an X ()
.例如additionalKeys
使用X ()
。
The documentation says that X
is a IO
with some state and reader transformers, so I am under the impression that the StackSet
is contained within the state of X
.文档说X
是一个带有一些状态和读取器转换器的IO
,所以我的印象是StackSet
包含在X
的状态中。 So in theory it should be possible to modify the relevant part of the state.所以理论上应该可以修改状态的相关部分。 However the state accessible is XState
not the StackState
I want, so I need to be able to turn my function on StackState
to one on XState
.然而,可访问的状态是XState
而不是我想要的StackState
,所以我需要能够将StackState
上的函数StackState
为XState
上的XState
。
This would be easy enough if I had a function of the type如果我有一个类型的函数,这将很容易
(StackSet i l a s sd -> StackSet i l a s sd) -> X ()
However after digging around in the documentation I haven't been able to piece together a way to do this yet.然而,在文档中挖掘之后,我还没有能够拼凑出一种方法来做到这一点。 Is there a way to take a function on StackSet
and make an X ()
that performs that function?有没有办法在StackSet
上获取一个函数并创建一个X ()
来执行该函数?
The X
monad has an instance of MonadState
X
monad 有一个MonadState
实例
instance MonadState XState X
So we can use modify
as所以我们可以使用modify
为
modify :: (XState -> XState) -> X ()
So we need to turn out function to one on XState
s.所以我们需要在XState
函数转换为 1。 And if we look at the definition如果我们看一下定义
XState
windowset :: !WindowSet
mapped :: !(Set Window)
waitingUnmap :: !(Map Window Int)
dragging :: !(Maybe (Position -> Position -> X (), X ()))
numberlockMask :: !KeyMask
extensibleState :: !(Map String (Either String StateExtension))
we will see WindowSet
which is a type alias for a particular StackState
.我们将看到WindowSet
,它是特定StackState
的类型别名。 So you can turn a function from StackState
s into one on XState
s like so:所以,你可以把从函数StackState
在S成一个XState
就像这样:
overWindowSet :: (WindowSet -> WindowSet) -> XState -> XState
overWindowSet f xState = xState { windowset = f (windowset xState) }
This can be combined with modify
to make the complete function you would like:这可以与modify
结合使用以制作您想要的完整功能:
modify . overWindowSet
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.