Skip to content

Instantly share code, notes, and snippets.

@LSLeary
Created September 11, 2025 16:38
Show Gist options
  • Save LSLeary/28e2157ccb7eb83cf6b63d9a5aed4dd0 to your computer and use it in GitHub Desktop.
Save LSLeary/28e2157ccb7eb83cf6b63d9a5aed4dd0 to your computer and use it in GitHub Desktop.
xmonad: switch to the previous layout (experimental)
module PrevLayout (prevLayout) where
import XMonad
import qualified XMonad.StackSet as W
prevLayout :: X ()
prevLayout = do
ss@W.StackSet{ W.current = c@W.Screen{ W.workspace = ws }} <- gets windowset
mp <- findPrev (description (W.layout ws)) (W.layout ws)
case mp of
Nothing -> pure ()
Just p -> windows
$ const ss{ W.current = c{ W.workspace = ws{ W.layout = p } } }
where
findPrev cur l = do
ml' <- handleMessage l (SomeMessage NextLayout)
case ml' of
Nothing -> pure Nothing
Just l' -> if description l' == cur
then pure (Just l)
else findPrev cur l'
@Aster89
Copy link

Aster89 commented Sep 11, 2025

BTW, findPrev (description (W.layout ws)) (W.layout ws) is the same as description >>= findPrev $ W.layout, in the name of the function monad 🤣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment