Search code examples
xmonad

User state in Xmonad


Is it possible to have a user state in Xmonad?

I'm using global variables right now, but I wonder if there's a proper way to do it within Xmonad. (Eg: in parsec, there's a user state, so you would use Parser TYPE ... where TYPE is the type of the user state and is queryable with getState, putState, and modifyState.)


Solution

  • Layout states in Xmonad can be specified/modified in the config.hs module, but Xmonad has also got extensible states that you can implement. I would recommend you look at both. The docs on the Haskell Extensible States lists the module as 'unstable' but i think it's a fair while since that documentation was updated (about three years?)

    The [sample] code looks something like this:

     {-# LANGUAGE DeriveDataTypeable #-}
    import qualified XMonad.Util.ExtensibleState as XS
    
    data ListStorage = ListStorage [Integer] deriving Typeable
    instance ExtensionClass ListStorage where
    initialValue = ListStorage []
    
    .. XS.put (ListStorage [23,42])
    
     (e.g.)  put :: ExtensionClass a => a -> X ()