In xmonad it can be useful to have different keybindings for different layouts, or respond to other events differently depending on the active layout. This can be accomplished by looking up the active layout in the hook. For this we define a utility function:

import XMonad

-- Get the name of the active layout.
getActiveLayoutDescription :: X String
getActiveLayoutDescription = do
workspaces <- gets windowset
return $description . S.layout . S.workspace . S.current$ workspaces

We can use this function in keybindings as follows. Here I’m using the BinarySpacePartition layout, and my other layouts are based on Tall. Depending on whether I have BSP active or not, I send different messages.

-- ...

"BSP" -> sendMessage $ExpandTowards R _ -> sendMessage Expand ) , ((mod4Mask .|. shiftMask, xK_h), do layout <- getActiveLayoutDescription case layout of "BSP" -> sendMessage$ ExpandTowards L
]