Search code examples
xmonadxmonad-contrib

XMonad (or xmonad-contrib) function to read current layout name?


Say I have an XMonad layout that I named "foo" via XMonad.Layout.Renamed.

I've got a keybinding that I would like bound to a different X () depending on the current layout of the focused workspace. For example, something along the lines of:

case () of
() | currentLayoutName == "foo" -> fooAction
   | otherwise                  -> barAction

..but how can I implement currentLayoutName?


Solution

  • Just traverse down the StackSet to the current workspace to the layout description.

    -- Imports
    …
    import qualified XMonad.StackSet as W
    …
    
    -- Key bindings
    …
    , ((modm, xK_F1), do
        wset <- gets windowset
        let ldesc = description . W.layout . W.workspace . W.current $ wset
        case ldesc of
            "foo" -> fooAction
            _     -> barAction
      )
    …