{-# LANGUAGE ViewPatterns #-}
module XMonad.Actions.CycleWindows (
cycleRecentWindows,
cycleStacks',
rotOpposite', rotOpposite,
rotFocused', rotFocusedUp, rotFocusedDown, shiftToFocus',
rotUnfocused', rotUnfocusedUp, rotUnfocusedDown,
rotUp, rotDown
) where
import XMonad
import XMonad.Prelude
import qualified XMonad.StackSet as W
import qualified Data.List.NonEmpty as NE
import XMonad.Actions.RotSlaves
import Control.Arrow (second)
cycleRecentWindows :: [KeySym]
-> KeySym
-> KeySym
-> X ()
cycleRecentWindows :: [Window] -> Window -> Window -> X ()
cycleRecentWindows = (Stack Window -> [Stack Window])
-> [Window] -> Window -> Window -> X ()
cycleStacks' Stack Window -> [Stack Window]
forall {a}. (Eq a, Show a, Read a) => Stack a -> [Stack a]
stacks where
stacks :: Stack a -> [Stack a]
stacks Stack a
s = (a -> Stack a) -> [a] -> [Stack a]
forall a b. (a -> b) -> [a] -> [b]
map (a -> Stack a -> Stack a
forall a. (Eq a, Show a, Read a) => a -> Stack a -> Stack a
`shiftToFocus'` Stack a
s) (Stack a -> [a]
forall {a}. Stack a -> [a]
wins Stack a
s)
wins :: Stack a -> [a]
wins (W.Stack a
t [a]
l [a]
r) = a
t a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
r [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a] -> [a]
forall a. [a] -> [a]
reverse [a]
l
cycleStacks' :: (W.Stack Window -> [W.Stack Window])
-> [KeySym]
-> KeySym
-> KeySym
-> X ()
cycleStacks' :: (Stack Window -> [Stack Window])
-> [Window] -> Window -> Window -> X ()
cycleStacks' Stack Window -> [Stack Window]
filteredPerms [Window]
mods Window
keyNext Window
keyPrev = do
XConf {theRoot :: XConf -> Window
theRoot = Window
root, display :: XConf -> Display
display = Display
d} <- X XConf
forall r (m :: * -> *). MonadReader r m => m r
ask
[Stack Window]
stacks <- (XState -> [Stack Window]) -> X [Stack Window]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((XState -> [Stack Window]) -> X [Stack Window])
-> (XState -> [Stack Window]) -> X [Stack Window]
forall a b. (a -> b) -> a -> b
$ [Stack Window]
-> (Stack Window -> [Stack Window])
-> Maybe (Stack Window)
-> [Stack Window]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] Stack Window -> [Stack Window]
filteredPerms (Maybe (Stack Window) -> [Stack Window])
-> (XState -> Maybe (Stack Window)) -> XState -> [Stack Window]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace WorkspaceId (Layout Window) Window
-> Maybe (Stack Window)
forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack (Workspace WorkspaceId (Layout Window) Window
-> Maybe (Stack Window))
-> (XState -> Workspace WorkspaceId (Layout Window) Window)
-> XState
-> Maybe (Stack Window)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Workspace WorkspaceId (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Workspace WorkspaceId (Layout Window) Window)
-> (XState
-> Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> Workspace WorkspaceId (Layout Window) Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> (XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
windowset
let evt :: IO (EventType, Window)
evt = (XEventPtr -> IO (EventType, Window)) -> IO (EventType, Window)
forall a. (XEventPtr -> IO a) -> IO a
allocaXEvent ((XEventPtr -> IO (EventType, Window)) -> IO (EventType, Window))
-> (XEventPtr -> IO (EventType, Window)) -> IO (EventType, Window)
forall a b. (a -> b) -> a -> b
$
\XEventPtr
p -> do Display -> Window -> XEventPtr -> IO ()
maskEvent Display
d (Window
keyPressMask Window -> Window -> Window
forall a. Bits a => a -> a -> a
.|. Window
keyReleaseMask) XEventPtr
p
KeyEvent {ev_event_type :: Event -> EventType
ev_event_type = EventType
t, ev_keycode :: Event -> KeyCode
ev_keycode = KeyCode
c} <- XEventPtr -> IO Event
getEvent XEventPtr
p
Window
s <- Display -> KeyCode -> CInt -> IO Window
keycodeToKeysym Display
d KeyCode
c CInt
0
(EventType, Window) -> IO (EventType, Window)
forall (m :: * -> *) a. Monad m => a -> m a
return (EventType
t, Window
s)
choose :: Int -> (EventType, Window) -> X ()
choose Int
n (EventType
t, Window
s)
| EventType
t EventType -> EventType -> Bool
forall a. Eq a => a -> a -> Bool
== EventType
keyPress Bool -> Bool -> Bool
&& Window
s Window -> Window -> Bool
forall a. Eq a => a -> a -> Bool
== Window
keyNext = IO (EventType, Window) -> X (EventType, Window)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io IO (EventType, Window)
evt X (EventType, Window) -> ((EventType, Window) -> X ()) -> X ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> (EventType, Window) -> X ()
choose (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
| EventType
t EventType -> EventType -> Bool
forall a. Eq a => a -> a -> Bool
== EventType
keyPress Bool -> Bool -> Bool
&& Window
s Window -> Window -> Bool
forall a. Eq a => a -> a -> Bool
== Window
keyPrev = IO (EventType, Window) -> X (EventType, Window)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io IO (EventType, Window)
evt X (EventType, Window) -> ((EventType, Window) -> X ()) -> X ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> (EventType, Window) -> X ()
choose (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)
| EventType
t EventType -> EventType -> Bool
forall a. Eq a => a -> a -> Bool
== EventType
keyPress Bool -> Bool -> Bool
&& Window
s Window -> [Window] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Window
xK_0..Window
xK_9] = IO (EventType, Window) -> X (EventType, Window)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io IO (EventType, Window)
evt X (EventType, Window) -> ((EventType, Window) -> X ()) -> X ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> (EventType, Window) -> X ()
choose (Window -> Int
numKeyToN Window
s)
| EventType
t EventType -> EventType -> Bool
forall a. Eq a => a -> a -> Bool
== EventType
keyRelease Bool -> Bool -> Bool
&& Window
s Window -> [Window] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Window]
mods = () -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = Int -> X ()
doStack Int
n X () -> X (EventType, Window) -> X (EventType, Window)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO (EventType, Window) -> X (EventType, Window)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io IO (EventType, Window)
evt X (EventType, Window) -> ((EventType, Window) -> X ()) -> X ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> (EventType, Window) -> X ()
choose Int
n
doStack :: Int -> X ()
doStack Int
n = (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ()
windows ((StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ())
-> (Stack Window
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> Stack Window
-> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Stack Window -> Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall a i l s sd.
(Stack a -> Stack a) -> StackSet i l a s sd -> StackSet i l a s sd
W.modify' ((Stack Window -> Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> (Stack Window -> Stack Window -> Stack Window)
-> Stack Window
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack Window -> Stack Window -> Stack Window
forall a b. a -> b -> a
const (Stack Window -> X ()) -> Stack Window -> X ()
forall a b. (a -> b) -> a -> b
$ [Stack Window]
stacks [Stack Window] -> Int -> Stack Window
forall {a}. [a] -> Int -> a
`cycref` Int
n
IO CInt -> X CInt
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO CInt -> X CInt) -> IO CInt -> X CInt
forall a b. (a -> b) -> a -> b
$ Display -> Window -> Bool -> CInt -> CInt -> Window -> IO CInt
grabKeyboard Display
d Window
root Bool
False CInt
grabModeAsync CInt
grabModeAsync Window
currentTime
IO (EventType, Window) -> X (EventType, Window)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io IO (EventType, Window)
evt X (EventType, Window) -> ((EventType, Window) -> X ()) -> X ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> (EventType, Window) -> X ()
choose Int
1
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO ()
ungrabKeyboard Display
d Window
currentTime
where cycref :: [a] -> Int -> a
cycref [a]
l Int
i = [a]
l [a] -> Int -> a
forall {a}. [a] -> Int -> a
!! (Int
i Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
l)
numKeyToN :: Window -> Int
numKeyToN = Int -> Int -> Int
forall a. Num a => a -> a -> a
subtract Int
48 (Int -> Int) -> (Window -> Int) -> Window -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WorkspaceId -> Int
forall a. Read a => WorkspaceId -> a
read (WorkspaceId -> Int) -> (Window -> WorkspaceId) -> Window -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Window -> WorkspaceId
forall a. Show a => a -> WorkspaceId
show
shiftToFocus' :: (Eq a, Show a, Read a) => a -> W.Stack a -> W.Stack a
shiftToFocus' :: forall a. (Eq a, Show a, Read a) => a -> Stack a -> Stack a
shiftToFocus' a
w s :: Stack a
s@(W.Stack a
_ [a]
ls [a]
_) = a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
w ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
revls') [a]
rs'
where ([a]
revls', [a]
rs') = Int -> [a] -> ([a], [a])
forall a. Int -> [a] -> ([a], [a])
splitAt ([a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
ls) ([a] -> ([a], [a])) -> ([a] -> [a]) -> [a] -> ([a], [a])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
filter (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
w) ([a] -> ([a], [a])) -> [a] -> ([a], [a])
forall a b. (a -> b) -> a -> b
$ Stack a -> [a]
forall {a}. Stack a -> [a]
W.integrate Stack a
s
rotOpposite :: X()
rotOpposite :: X ()
rotOpposite = (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ()
windows ((StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ())
-> (StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ()
forall a b. (a -> b) -> a -> b
$ (Stack Window -> Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall a i l s sd.
(Stack a -> Stack a) -> StackSet i l a s sd -> StackSet i l a s sd
W.modify' Stack Window -> Stack Window
forall a. Stack a -> Stack a
rotOpposite'
rotOpposite' :: W.Stack a -> W.Stack a
rotOpposite' :: forall a. Stack a -> Stack a
rotOpposite' (W.Stack a
t [a]
l [a]
r) = a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
t' [a]
l' [a]
r'
where rrvl :: [a]
rrvl = [a]
r [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a] -> [a]
forall a. [a] -> [a]
reverse [a]
l
part :: Int
part = ([a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
rrvl Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
([a]
l', [a] -> NonEmpty a
forall a. HasCallStack => [a] -> NonEmpty a
notEmpty -> a
t' :| [a]
r') = ([a] -> [a]) -> ([a], [a]) -> ([a], [a])
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second [a] -> [a]
forall a. [a] -> [a]
reverse (([a], [a]) -> ([a], [a]))
-> ([a] -> ([a], [a])) -> [a] -> ([a], [a])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [a] -> ([a], [a])
forall a. Int -> [a] -> ([a], [a])
splitAt ([a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
l) ([a] -> ([a], [a])) -> [a] -> ([a], [a])
forall a b. (a -> b) -> a -> b
$
[a] -> [a]
forall a. [a] -> [a]
reverse (Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
take Int
part [a]
rrvl [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ a
t a -> [a] -> [a]
forall a. a -> [a] -> [a]
: Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
drop Int
part [a]
rrvl)
rotFocusedUp :: X ()
rotFocusedUp :: X ()
rotFocusedUp = (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ()
windows ((StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ())
-> ((Stack Window -> Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> (Stack Window -> Stack Window)
-> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Stack Window -> Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall a i l s sd.
(Stack a -> Stack a) -> StackSet i l a s sd -> StackSet i l a s sd
W.modify' ((Stack Window -> Stack Window) -> X ())
-> (Stack Window -> Stack Window) -> X ()
forall a b. (a -> b) -> a -> b
$ ([Window] -> [Window]) -> Stack Window -> Stack Window
forall a. ([a] -> [a]) -> Stack a -> Stack a
rotFocused' [Window] -> [Window]
forall a. [a] -> [a]
rotUp
rotFocusedDown :: X ()
rotFocusedDown :: X ()
rotFocusedDown = (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ()
windows ((StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ())
-> ((Stack Window -> Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> (Stack Window -> Stack Window)
-> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Stack Window -> Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall a i l s sd.
(Stack a -> Stack a) -> StackSet i l a s sd -> StackSet i l a s sd
W.modify' ((Stack Window -> Stack Window) -> X ())
-> (Stack Window -> Stack Window) -> X ()
forall a b. (a -> b) -> a -> b
$ ([Window] -> [Window]) -> Stack Window -> Stack Window
forall a. ([a] -> [a]) -> Stack a -> Stack a
rotFocused' [Window] -> [Window]
forall a. [a] -> [a]
rotDown
rotFocused' :: ([a] -> [a]) -> W.Stack a -> W.Stack a
rotFocused' :: forall a. ([a] -> [a]) -> Stack a -> Stack a
rotFocused' [a] -> [a]
_ s :: Stack a
s@(W.Stack a
_ [] []) = Stack a
s
rotFocused' [a] -> [a]
f (W.Stack a
t [] (a
r:[a]
rs)) = a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
t' [] (a
ra -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
rs')
where ([a] -> NonEmpty a
forall a. HasCallStack => [a] -> NonEmpty a
notEmpty -> a
t' :| [a]
rs') = [a] -> [a]
f (a
ta -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
rs)
rotFocused' [a] -> [a]
f s :: Stack a
s@W.Stack{} = ([a] -> [a]) -> Stack a -> Stack a
forall a. ([a] -> [a]) -> Stack a -> Stack a
rotSlaves' [a] -> [a]
f Stack a
s
rotUnfocusedUp :: X ()
rotUnfocusedUp :: X ()
rotUnfocusedUp = (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ()
windows ((StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ())
-> ((Stack Window -> Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> (Stack Window -> Stack Window)
-> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Stack Window -> Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall a i l s sd.
(Stack a -> Stack a) -> StackSet i l a s sd -> StackSet i l a s sd
W.modify' ((Stack Window -> Stack Window) -> X ())
-> (Stack Window -> Stack Window) -> X ()
forall a b. (a -> b) -> a -> b
$ ([Window] -> [Window]) -> Stack Window -> Stack Window
forall a. ([a] -> [a]) -> Stack a -> Stack a
rotUnfocused' [Window] -> [Window]
forall a. [a] -> [a]
rotUp
rotUnfocusedDown :: X ()
rotUnfocusedDown :: X ()
rotUnfocusedDown = (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ()
windows ((StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X ())
-> ((Stack Window -> Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> (Stack Window -> Stack Window)
-> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Stack Window -> Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall a i l s sd.
(Stack a -> Stack a) -> StackSet i l a s sd -> StackSet i l a s sd
W.modify' ((Stack Window -> Stack Window) -> X ())
-> (Stack Window -> Stack Window) -> X ()
forall a b. (a -> b) -> a -> b
$ ([Window] -> [Window]) -> Stack Window -> Stack Window
forall a. ([a] -> [a]) -> Stack a -> Stack a
rotUnfocused' [Window] -> [Window]
forall a. [a] -> [a]
rotDown
rotUnfocused' :: ([a] -> [a]) -> W.Stack a -> W.Stack a
rotUnfocused' :: forall a. ([a] -> [a]) -> Stack a -> Stack a
rotUnfocused' [a] -> [a]
_ s :: Stack a
s@(W.Stack a
_ [] []) = Stack a
s
rotUnfocused' [a] -> [a]
f s :: Stack a
s@(W.Stack a
_ [] [a]
_ ) = ([a] -> [a]) -> Stack a -> Stack a
forall a. ([a] -> [a]) -> Stack a -> Stack a
rotSlaves' [a] -> [a]
f Stack a
s
rotUnfocused' [a] -> [a]
f (W.Stack a
t [a]
ls [a]
rs) = a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
t ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
revls') [a]
rs'
where (a
master :| [a]
revls) = NonEmpty a -> NonEmpty a
forall a. NonEmpty a -> NonEmpty a
NE.reverse (let a
l:[a]
ll = [a]
ls in a
l a -> [a] -> NonEmpty a
forall a. a -> [a] -> NonEmpty a
:| [a]
ll)
([a]
revls',[a]
rs') = Int -> [a] -> ([a], [a])
forall a. Int -> [a] -> ([a], [a])
splitAt ([a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
ls) ([a] -> [a]
f ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ a
mastera -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
revls [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a]
rs)
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