{-# LANGUAGE ViewPatterns #-}
module XMonad.Actions.RotSlaves (
rotSlaves', rotSlavesUp, rotSlavesDown,
rotAll', rotAllUp, rotAllDown,
rotUp, rotDown
) where
import XMonad
import XMonad.StackSet
import XMonad.Prelude
rotSlavesUp,rotSlavesDown :: X ()
rotSlavesUp :: X ()
rotSlavesUp = (WindowSet -> WindowSet) -> X ()
windows ((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ (Stack Window -> Stack Window) -> WindowSet -> WindowSet
forall a i l s sd.
(Stack a -> Stack a) -> StackSet i l a s sd -> StackSet i l a s sd
modify' (([Window] -> [Window]) -> Stack Window -> Stack Window
forall a. ([a] -> [a]) -> Stack a -> Stack a
rotSlaves' [Window] -> [Window]
forall a. [a] -> [a]
rotUp)
rotSlavesDown :: X ()
rotSlavesDown = (WindowSet -> WindowSet) -> X ()
windows ((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ (Stack Window -> Stack Window) -> WindowSet -> WindowSet
forall a i l s sd.
(Stack a -> Stack a) -> StackSet i l a s sd -> StackSet i l a s sd
modify' (([Window] -> [Window]) -> Stack Window -> Stack Window
forall a. ([a] -> [a]) -> Stack a -> Stack a
rotSlaves' [Window] -> [Window]
forall a. [a] -> [a]
rotDown)
rotSlaves' :: ([a] -> [a]) -> Stack a -> Stack a
rotSlaves' :: forall a. ([a] -> [a]) -> Stack a -> Stack a
rotSlaves' [a] -> [a]
_ s :: Stack a
s@(Stack a
_ [] []) = Stack a
s
rotSlaves' [a] -> [a]
f (Stack a
t [] [a]
rs) = a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
Stack a
t [] ([a] -> [a]
f [a]
rs)
rotSlaves' [a] -> [a]
f s :: Stack a
s@(Stack a
_ [a]
ls [a]
_ ) = a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
Stack a
t' ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
revls') [a]
rs'
where ([a] -> NonEmpty a
forall a. HasCallStack => [a] -> NonEmpty a
notEmpty -> a
master :| [a]
ws) = Stack a -> [a]
forall a. Stack a -> [a]
integrate Stack a
s
([a]
revls', [a] -> NonEmpty a
forall a. HasCallStack => [a] -> NonEmpty a
notEmpty -> a
t' :| [a]
rs') = Int -> [a] -> ([a], [a])
forall a. Int -> [a] -> ([a], [a])
splitAt ([a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
ls) (a
mastera -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a] -> [a]
f [a]
ws)
rotAllUp,rotAllDown :: X ()
rotAllUp :: X ()
rotAllUp = (WindowSet -> WindowSet) -> X ()
windows ((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ (Stack Window -> Stack Window) -> WindowSet -> WindowSet
forall a i l s sd.
(Stack a -> Stack a) -> StackSet i l a s sd -> StackSet i l a s sd
modify' (([Window] -> [Window]) -> Stack Window -> Stack Window
forall a. ([a] -> [a]) -> Stack a -> Stack a
rotAll' [Window] -> [Window]
forall a. [a] -> [a]
rotUp)
rotAllDown :: X ()
rotAllDown = (WindowSet -> WindowSet) -> X ()
windows ((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ (Stack Window -> Stack Window) -> WindowSet -> WindowSet
forall a i l s sd.
(Stack a -> Stack a) -> StackSet i l a s sd -> StackSet i l a s sd
modify' (([Window] -> [Window]) -> Stack Window -> Stack Window
forall a. ([a] -> [a]) -> Stack a -> Stack a
rotAll' [Window] -> [Window]
forall a. [a] -> [a]
rotDown)
rotAll' :: ([a] -> [a]) -> Stack a -> Stack a
rotAll' :: forall a. ([a] -> [a]) -> Stack a -> Stack a
rotAll' [a] -> [a]
f Stack a
s = a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
Stack a
r ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
revls) [a]
rs
where ([a]
revls, [a] -> NonEmpty a
forall a. HasCallStack => [a] -> NonEmpty a
notEmpty -> a
r :| [a]
rs) = Int -> [a] -> ([a], [a])
forall a. Int -> [a] -> ([a], [a])
splitAt ([a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (Stack a -> [a]
forall a. Stack a -> [a]
up Stack a
s)) ([a] -> [a]
f (Stack a -> [a]
forall a. Stack a -> [a]
integrate Stack a
s))
rotUp :: [a] -> [a]
rotUp :: forall a. [a] -> [a]
rotUp [a]
l = Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
drop Int
1 [a]
l [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
take Int
1 [a]
l
rotDown :: [a] -> [a]
rotDown :: forall a. [a] -> [a]
rotDown = [a] -> [a]
forall a. [a] -> [a]
reverse ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
forall a. [a] -> [a]
rotUp ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> [a]
forall a. [a] -> [a]
reverse