mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 03:20:21 -07:00
31 lines
1.0 KiB
Haskell
31 lines
1.0 KiB
Haskell
module XMonadContrib.SwapFocus ( swapFocus ) where
|
|
|
|
-- swaps focus with last-focussed window.
|
|
|
|
-- To use:
|
|
-- import XMonadContrib.SwapFocus ( swapFocus )
|
|
|
|
-- , ((modMask .|. shiftMask, xK_Tab), swapFocus)
|
|
|
|
import Control.Monad.State
|
|
|
|
import Operations ( refresh )
|
|
import XMonad ( X, WindowSet, windowset )
|
|
import StackSet ( StackSet, peekStack, popFocus, pushFocus, current )
|
|
|
|
sf :: (Integral i, Integral j, Ord a) => StackSet i j a -> Maybe (StackSet i j a)
|
|
sf w = do let i = current w
|
|
f1 <- peekStack i w
|
|
f2 <- peekStack i $ popFocus i f1 w
|
|
return $ pushFocus i f2 $ pushFocus i f1 w
|
|
|
|
swapFocus :: X ()
|
|
swapFocus = smartwindows sf
|
|
|
|
-- | smartwindows. Modify the current window list with a pure function, and only refresh if necesary
|
|
smartwindows :: (WindowSet -> Maybe WindowSet) -> X ()
|
|
smartwindows f = do w <- gets windowset
|
|
case (f w) of Just f' -> do modify $ \s -> s { windowset = f' }
|
|
refresh
|
|
Nothing -> return ()
|