module XMonad.Actions.SwapPromote
(
MasterHistory (..)
, getMasterHistoryMap
, getMasterHistoryFromTag
, getMasterHistoryCurrent
, getMasterHistoryFromWindow
, modifyMasterHistoryFromTag
, modifyMasterHistoryCurrent
, masterHistoryHook
, masterHistoryHook'
, updateMasterHistory
, swapPromote
, swapPromote'
, swapIn
, swapIn'
, swapHybrid
, swapHybrid'
, swapApply
, swapPromoteStack
, swapInStack
, swapHybridStack
, cycleN
, split
, split'
, merge
, merge'
, stackSplit
, stackMerge
) where
import XMonad
import XMonad.Prelude
import qualified XMonad.StackSet as W
import qualified XMonad.Util.ExtensibleState as XS
import qualified Data.Map as M
import qualified Data.Set as S
import Control.Arrow
import qualified Data.List.NonEmpty as NE
newtype MasterHistory = MasterHistory
{ MasterHistory -> Map WorkspaceId [Window]
getMasterHistory :: M.Map WorkspaceId [Window]
} deriving (ReadPrec [MasterHistory]
ReadPrec MasterHistory
Int -> ReadS MasterHistory
ReadS [MasterHistory]
(Int -> ReadS MasterHistory)
-> ReadS [MasterHistory]
-> ReadPrec MasterHistory
-> ReadPrec [MasterHistory]
-> Read MasterHistory
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS MasterHistory
readsPrec :: Int -> ReadS MasterHistory
$creadList :: ReadS [MasterHistory]
readList :: ReadS [MasterHistory]
$creadPrec :: ReadPrec MasterHistory
readPrec :: ReadPrec MasterHistory
$creadListPrec :: ReadPrec [MasterHistory]
readListPrec :: ReadPrec [MasterHistory]
Read,Int -> MasterHistory -> ShowS
[MasterHistory] -> ShowS
MasterHistory -> WorkspaceId
(Int -> MasterHistory -> ShowS)
-> (MasterHistory -> WorkspaceId)
-> ([MasterHistory] -> ShowS)
-> Show MasterHistory
forall a.
(Int -> a -> ShowS)
-> (a -> WorkspaceId) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MasterHistory -> ShowS
showsPrec :: Int -> MasterHistory -> ShowS
$cshow :: MasterHistory -> WorkspaceId
show :: MasterHistory -> WorkspaceId
$cshowList :: [MasterHistory] -> ShowS
showList :: [MasterHistory] -> ShowS
Show)
instance ExtensionClass MasterHistory where
initialValue :: MasterHistory
initialValue = Map WorkspaceId [Window] -> MasterHistory
MasterHistory Map WorkspaceId [Window]
forall k a. Map k a
M.empty
getMasterHistoryMap :: X (M.Map WorkspaceId [Window])
getMasterHistoryMap :: X (Map WorkspaceId [Window])
getMasterHistoryMap = (MasterHistory -> Map WorkspaceId [Window])
-> X (Map WorkspaceId [Window])
forall a (m :: * -> *) b.
(ExtensionClass a, XLike m) =>
(a -> b) -> m b
XS.gets MasterHistory -> Map WorkspaceId [Window]
getMasterHistory
getMasterHistoryFromTag :: WorkspaceId -> X [Window]
getMasterHistoryFromTag :: WorkspaceId -> X [Window]
getMasterHistoryFromTag WorkspaceId
t = [Window] -> WorkspaceId -> Map WorkspaceId [Window] -> [Window]
forall k a. Ord k => a -> k -> Map k a -> a
M.findWithDefault [] WorkspaceId
t (Map WorkspaceId [Window] -> [Window])
-> X (Map WorkspaceId [Window]) -> X [Window]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> X (Map WorkspaceId [Window])
getMasterHistoryMap
getMasterHistoryCurrent :: X [Window]
getMasterHistoryCurrent :: X [Window]
getMasterHistoryCurrent = (XState -> WorkspaceId) -> X WorkspaceId
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> WorkspaceId
forall i l a s sd. StackSet i l a s sd -> i
W.currentTag (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> WorkspaceId)
-> (XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> WorkspaceId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
windowset)
X WorkspaceId -> (WorkspaceId -> X [Window]) -> X [Window]
forall a b. X a -> (a -> X b) -> X b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= WorkspaceId -> X [Window]
getMasterHistoryFromTag
getMasterHistoryFromWindow :: Window -> X [Window]
getMasterHistoryFromWindow :: Window -> X [Window]
getMasterHistoryFromWindow Window
w = (XState -> Maybe WorkspaceId) -> X (Maybe WorkspaceId)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (Window
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Maybe WorkspaceId
forall a i l s sd. Eq a => a -> StackSet i l a s sd -> Maybe i
W.findTag Window
w (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Maybe WorkspaceId)
-> (XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> Maybe WorkspaceId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
windowset)
X (Maybe WorkspaceId)
-> (Maybe WorkspaceId -> X [Window]) -> X [Window]
forall a b. X a -> (a -> X b) -> X b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= X [Window]
-> (WorkspaceId -> X [Window]) -> Maybe WorkspaceId -> X [Window]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Window] -> X [Window]
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return []) WorkspaceId -> X [Window]
getMasterHistoryFromTag
modifyMasterHistoryFromTag :: WorkspaceId -> ([Window] -> [Window]) -> X ()
modifyMasterHistoryFromTag :: WorkspaceId -> ([Window] -> [Window]) -> X ()
modifyMasterHistoryFromTag WorkspaceId
t [Window] -> [Window]
f = (MasterHistory -> MasterHistory) -> X ()
forall a (m :: * -> *).
(ExtensionClass a, XLike m) =>
(a -> a) -> m ()
XS.modify ((MasterHistory -> MasterHistory) -> X ())
-> (MasterHistory -> MasterHistory) -> X ()
forall a b. (a -> b) -> a -> b
$ \(MasterHistory Map WorkspaceId [Window]
m) ->
let l :: [Window]
l = [Window] -> WorkspaceId -> Map WorkspaceId [Window] -> [Window]
forall k a. Ord k => a -> k -> Map k a -> a
M.findWithDefault [] WorkspaceId
t Map WorkspaceId [Window]
m
in Map WorkspaceId [Window] -> MasterHistory
MasterHistory (Map WorkspaceId [Window] -> MasterHistory)
-> Map WorkspaceId [Window] -> MasterHistory
forall a b. (a -> b) -> a -> b
$ WorkspaceId
-> [Window] -> Map WorkspaceId [Window] -> Map WorkspaceId [Window]
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert WorkspaceId
t ([Window] -> [Window]
f [Window]
l) Map WorkspaceId [Window]
m
modifyMasterHistoryCurrent :: ([Window] -> [Window]) -> X ()
modifyMasterHistoryCurrent :: ([Window] -> [Window]) -> X ()
modifyMasterHistoryCurrent [Window] -> [Window]
f = (XState -> WorkspaceId) -> X WorkspaceId
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> WorkspaceId
forall i l a s sd. StackSet i l a s sd -> i
W.currentTag (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> WorkspaceId)
-> (XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> WorkspaceId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
windowset)
X WorkspaceId -> (WorkspaceId -> X ()) -> X ()
forall a b. X a -> (a -> X b) -> X b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (WorkspaceId -> ([Window] -> [Window]) -> X ())
-> ([Window] -> [Window]) -> WorkspaceId -> X ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip WorkspaceId -> ([Window] -> [Window]) -> X ()
modifyMasterHistoryFromTag [Window] -> [Window]
f
masterHistoryHook :: X ()
masterHistoryHook :: X ()
masterHistoryHook = Bool -> ([Window] -> [Window] -> [Window]) -> X ()
masterHistoryHook' Bool
True [Window] -> [Window] -> [Window]
updateMasterHistory
masterHistoryHook' :: Bool
-> ([Window] -> [Window] -> [Window])
-> X ()
masterHistoryHook' :: Bool -> ([Window] -> [Window] -> [Window]) -> X ()
masterHistoryHook' Bool
removeWorkspaces [Window] -> [Window] -> [Window]
historyModifier = do
StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
wset <- (XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X (StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
windowset
let W.Workspace WorkspaceId
wid Layout Window
_ Maybe (Stack Window)
mst = 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)
-> (StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> 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
-> Workspace WorkspaceId (Layout Window) Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Workspace WorkspaceId (Layout Window) Window
forall a b. (a -> b) -> a -> b
$ StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
wset
tags :: [WorkspaceId]
tags = (Workspace WorkspaceId (Layout Window) Window -> WorkspaceId)
-> [Workspace WorkspaceId (Layout Window) Window] -> [WorkspaceId]
forall a b. (a -> b) -> [a] -> [b]
map Workspace WorkspaceId (Layout Window) Window -> WorkspaceId
forall i l a. Workspace i l a -> i
W.tag ([Workspace WorkspaceId (Layout Window) Window] -> [WorkspaceId])
-> [Workspace WorkspaceId (Layout Window) Window] -> [WorkspaceId]
forall a b. (a -> b) -> a -> b
$ StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> [Workspace WorkspaceId (Layout Window) Window]
forall i l a s sd. StackSet i l a s sd -> [Workspace i l a]
W.workspaces StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
wset
st :: [Window]
st = Maybe (Stack Window) -> [Window]
forall a. Maybe (Stack a) -> [a]
W.integrate' Maybe (Stack Window)
mst
(MasterHistory -> MasterHistory) -> X ()
forall a (m :: * -> *).
(ExtensionClass a, XLike m) =>
(a -> a) -> m ()
XS.modify ((MasterHistory -> MasterHistory) -> X ())
-> (MasterHistory -> MasterHistory) -> X ()
forall a b. (a -> b) -> a -> b
$ \(MasterHistory Map WorkspaceId [Window]
mm) ->
let mm' :: Map WorkspaceId [Window]
mm' = if Bool
removeWorkspaces
then Map WorkspaceId [Window]
-> Set WorkspaceId -> Map WorkspaceId [Window]
forall k a. Ord k => Map k a -> Set k -> Map k a
restrictKeys Map WorkspaceId [Window]
mm (Set WorkspaceId -> Map WorkspaceId [Window])
-> Set WorkspaceId -> Map WorkspaceId [Window]
forall a b. (a -> b) -> a -> b
$ [WorkspaceId] -> Set WorkspaceId
forall a. Ord a => [a] -> Set a
S.fromList [WorkspaceId]
tags
else Map WorkspaceId [Window]
mm
ms :: [Window]
ms = [Window] -> WorkspaceId -> Map WorkspaceId [Window] -> [Window]
forall k a. Ord k => a -> k -> Map k a -> a
M.findWithDefault [] WorkspaceId
wid Map WorkspaceId [Window]
mm'
ms' :: [Window]
ms' = [Window] -> [Window] -> [Window]
historyModifier [Window]
ms [Window]
st
in Map WorkspaceId [Window] -> MasterHistory
MasterHistory (Map WorkspaceId [Window] -> MasterHistory)
-> Map WorkspaceId [Window] -> MasterHistory
forall a b. (a -> b) -> a -> b
$ WorkspaceId
-> [Window] -> Map WorkspaceId [Window] -> Map WorkspaceId [Window]
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert WorkspaceId
wid [Window]
ms' Map WorkspaceId [Window]
mm'
restrictKeys :: Ord k => M.Map k a -> S.Set k -> M.Map k a
restrictKeys :: forall k a. Ord k => Map k a -> Set k -> Map k a
restrictKeys Map k a
m Set k
s = (k -> a -> Bool) -> Map k a -> Map k a
forall k a. (k -> a -> Bool) -> Map k a -> Map k a
M.filterWithKey (\k
k a
_ -> k
k k -> Set k -> Bool
forall a. Ord a => a -> Set a -> Bool
`S.member` Set k
s) Map k a
m
updateMasterHistory :: [Window]
-> [Window]
-> [Window]
updateMasterHistory :: [Window] -> [Window] -> [Window]
updateMasterHistory [Window]
_ [] = []
updateMasterHistory [Window]
ms ws :: [Window]
ws@(Window
w:[Window]
_) = (Window
w Window -> [Window] -> [Window]
forall a. a -> [a] -> [a]
: Window -> [Window] -> [Window]
forall a. Eq a => a -> [a] -> [a]
delete Window
w [Window]
ms) [Window] -> [Window] -> [Window]
forall a. Eq a => [a] -> [a] -> [a]
`intersect` [Window]
ws
swapPromote :: Bool -> X Bool
swapPromote :: Bool -> X Bool
swapPromote = (Bool
-> (Maybe Window -> Stack Window -> (Bool, Stack Window))
-> X Bool)
-> (Maybe Window -> Stack Window -> (Bool, Stack Window))
-> Bool
-> X Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip Bool
-> (Maybe Window -> Stack Window -> (Bool, Stack Window)) -> X Bool
swapApply Maybe Window -> Stack Window -> (Bool, Stack Window)
swapPromoteStack
swapPromote' :: Bool -> X ()
swapPromote' :: Bool -> X ()
swapPromote' = X Bool -> X ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (X Bool -> X ()) -> (Bool -> X Bool) -> Bool -> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> X Bool
swapPromote
swapIn :: Bool -> X Bool
swapIn :: Bool -> X Bool
swapIn = (Bool
-> (Maybe Window -> Stack Window -> (Bool, Stack Window))
-> X Bool)
-> (Maybe Window -> Stack Window -> (Bool, Stack Window))
-> Bool
-> X Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip Bool
-> (Maybe Window -> Stack Window -> (Bool, Stack Window)) -> X Bool
swapApply Maybe Window -> Stack Window -> (Bool, Stack Window)
swapInStack
swapIn' :: Bool -> X ()
swapIn' :: Bool -> X ()
swapIn' = X Bool -> X ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (X Bool -> X ()) -> (Bool -> X Bool) -> Bool -> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> X Bool
swapIn
swapHybrid :: Bool -> X Bool
swapHybrid :: Bool -> X Bool
swapHybrid = (Bool
-> (Maybe Window -> Stack Window -> (Bool, Stack Window))
-> X Bool)
-> (Maybe Window -> Stack Window -> (Bool, Stack Window))
-> Bool
-> X Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip Bool
-> (Maybe Window -> Stack Window -> (Bool, Stack Window)) -> X Bool
swapApply Maybe Window -> Stack Window -> (Bool, Stack Window)
swapHybridStack
swapHybrid' :: Bool -> X ()
swapHybrid' :: Bool -> X ()
swapHybrid' = X Bool -> X ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (X Bool -> X ()) -> (Bool -> X Bool) -> Bool -> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> X Bool
swapHybrid
swapApply :: Bool
-> (Maybe Window -> W.Stack Window -> (Bool,W.Stack Window))
-> X Bool
swapApply :: Bool
-> (Maybe Window -> Stack Window -> (Bool, Stack Window)) -> X Bool
swapApply Bool
ignoreFloats Maybe Window -> Stack Window -> (Bool, Stack Window)
swapFunction = do
Map Window RationalRect
fl <- (XState -> Map Window RationalRect) -> X (Map Window RationalRect)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((XState -> Map Window RationalRect)
-> X (Map Window RationalRect))
-> (XState -> Map Window RationalRect)
-> X (Map Window RationalRect)
forall a b. (a -> b) -> a -> b
$ StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Map Window RationalRect
forall i l a sid sd. StackSet i l a sid sd -> Map a RationalRect
W.floating (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Map Window RationalRect)
-> (XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> Map Window RationalRect
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
windowset
Maybe (Stack Window)
st <- (XState -> Maybe (Stack Window)) -> X (Maybe (Stack Window))
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((XState -> Maybe (Stack Window)) -> X (Maybe (Stack Window)))
-> (XState -> Maybe (Stack Window)) -> X (Maybe (Stack Window))
forall a b. (a -> b) -> a -> b
$ 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
[Window]
ch <- X [Window]
getMasterHistoryCurrent
let swapApply' :: Stack Window -> (Bool, Maybe (Stack Window), b -> [Window])
swapApply' Stack Window
s1 =
let fl' :: Set Window
fl' = if Bool
ignoreFloats then Map Window RationalRect -> Set Window
forall k a. Map k a -> Set k
M.keysSet Map Window RationalRect
fl else Set Window
forall a. Set a
S.empty
ff :: Window -> Bool
ff = Bool -> Bool -> Bool
(||) (Bool -> Bool -> Bool)
-> (Window -> Bool) -> Window -> Bool -> Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Window -> Set Window -> Bool
forall a. Ord a => a -> Set a -> Bool
`S.notMember` Set Window
fl') (Window -> Bool -> Bool) -> (Window -> Bool) -> Window -> Bool
forall a b. (Window -> a -> b) -> (Window -> a) -> Window -> b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Window -> Window -> Bool
forall a. Eq a => a -> a -> Bool
== Stack Window -> Window
forall a. Stack a -> a
W.focus Stack Window
s1)
fh :: [Window]
fh = (Window -> Bool) -> [Window] -> [Window]
forall a. (a -> Bool) -> [a] -> [a]
filter Window -> Bool
ff [Window]
ch
pm :: Maybe Window
pm = [Window] -> Maybe Window
forall a. [a] -> Maybe a
listToMaybe ([Window] -> Maybe Window)
-> ([Window] -> [Window]) -> [Window] -> Maybe Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Window] -> [Window]
forall a. Int -> [a] -> [a]
drop Int
1 ([Window] -> Maybe Window) -> [Window] -> Maybe Window
forall a b. (a -> b) -> a -> b
$ [Window]
fh
([(Int, Window)]
r,Stack Window
s2) = Stack Window -> Set Window -> ([(Int, Window)], Stack Window)
forall a b.
(Num a, Enum a, Ord b) =>
Stack b -> Set b -> ([(a, b)], Stack b)
stackSplit Stack Window
s1 Set Window
fl' :: ([(Int,Window)],W.Stack Window)
(Bool
b,Stack Window
s3) = Maybe Window -> Stack Window -> (Bool, Stack Window)
swapFunction Maybe Window
pm Stack Window
s2
s4 :: Stack Window
s4 = Stack Window -> [(Int, Window)] -> Stack Window
forall a b. (Ord a, Num a) => Stack b -> [(a, b)] -> Stack b
stackMerge Stack Window
s3 [(Int, Window)]
r
mh :: b -> [Window]
mh = let w :: Window
w = NonEmpty Window -> Window
forall a. NonEmpty a -> a
NE.head (NonEmpty Window -> Window)
-> (Stack Window -> NonEmpty Window) -> Stack Window -> Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Window] -> NonEmpty Window
forall a. HasCallStack => [a] -> NonEmpty a
notEmpty ([Window] -> NonEmpty Window)
-> (Stack Window -> [Window]) -> Stack Window -> NonEmpty Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack Window -> [Window]
forall a. Stack a -> [a]
W.integrate (Stack Window -> Window) -> Stack Window -> Window
forall a b. (a -> b) -> a -> b
$ Stack Window
s3
in [Window] -> b -> [Window]
forall a b. a -> b -> a
const ([Window] -> b -> [Window]) -> [Window] -> b -> [Window]
forall a b. (a -> b) -> a -> b
$ Window
w Window -> [Window] -> [Window]
forall a. a -> [a] -> [a]
: Window -> [Window] -> [Window]
forall a. Eq a => a -> [a] -> [a]
delete Window
w [Window]
ch
in (Bool
b,Stack Window -> Maybe (Stack Window)
forall a. a -> Maybe a
Just Stack Window
s4,b -> [Window]
forall {b}. b -> [Window]
mh)
(Bool
x,Maybe (Stack Window)
y,[Window] -> [Window]
z) = (Bool, Maybe (Stack Window), [Window] -> [Window])
-> (Stack Window
-> (Bool, Maybe (Stack Window), [Window] -> [Window]))
-> Maybe (Stack Window)
-> (Bool, Maybe (Stack Window), [Window] -> [Window])
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool
False,Maybe (Stack Window)
forall a. Maybe a
Nothing,[Window] -> [Window]
forall a. a -> a
id) Stack Window -> (Bool, Maybe (Stack Window), [Window] -> [Window])
forall {b}.
Stack Window -> (Bool, Maybe (Stack Window), b -> [Window])
swapApply' Maybe (Stack Window)
st
([Window] -> [Window]) -> X ()
modifyMasterHistoryCurrent [Window] -> [Window]
z
(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
$ Maybe (Stack Window)
-> (Stack Window -> Maybe (Stack Window))
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall a i l s sd.
Maybe (Stack a)
-> (Stack a -> Maybe (Stack a))
-> StackSet i l a s sd
-> StackSet i l a s sd
W.modify Maybe (Stack Window)
forall a. Maybe a
Nothing ((Stack Window -> Maybe (Stack Window))
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> (Maybe (Stack Window) -> Stack Window -> Maybe (Stack Window))
-> Maybe (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
. Maybe (Stack Window) -> Stack Window -> Maybe (Stack Window)
forall a b. a -> b -> a
const (Maybe (Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> Maybe (Stack Window)
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall a b. (a -> b) -> a -> b
$ Maybe (Stack Window)
y
Bool -> X Bool
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
x
swapPromoteStack :: Maybe Window -> W.Stack Window -> (Bool,W.Stack Window)
swapPromoteStack :: Maybe Window -> Stack Window -> (Bool, Stack Window)
swapPromoteStack Maybe Window
_ st :: Stack Window
st@(W.Stack Window
_x [] []) = (Bool
False,Stack Window
st)
swapPromoteStack Maybe Window
Nothing st :: Stack Window
st@(W.Stack Window
_x [] [Window]
_r) = (Bool
True,Stack Window
st)
swapPromoteStack (Just Window
pm) (W.Stack Window
x [] [Window]
r) =
let ([Window]
r',[Window]
l') = ([Window] -> [Window]
forall a. [a] -> [a]
reverse ([Window] -> [Window])
-> ([Window] -> [Window])
-> ([Window], [Window])
-> ([Window], [Window])
forall b c b' c'. (b -> c) -> (b' -> c') -> (b, b') -> (c, c')
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** Int -> [Window] -> [Window]
forall a. Int -> [a] -> [a]
cycleN Int
1) (([Window], [Window]) -> ([Window], [Window]))
-> ([Window], [Window]) -> ([Window], [Window])
forall a b. (a -> b) -> a -> b
$ (Window -> Bool) -> [Window] -> ([Window], [Window])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (Window -> Window -> Bool
forall a. Eq a => a -> a -> Bool
/= Window
pm) ([Window] -> ([Window], [Window]))
-> [Window] -> ([Window], [Window])
forall a b. (a -> b) -> a -> b
$ [Window] -> [Window]
forall a. [a] -> [a]
reverse [Window]
r
st' :: Stack Window
st' = Window -> [Window] -> [Window] -> Stack Window
forall a. a -> [a] -> [a] -> Stack a
W.Stack Window
x [Window]
l' [Window]
r'
b :: Bool
b = [Window] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Window]
l'
in (Bool
b,Stack Window
st')
swapPromoteStack Maybe Window
_ (W.Stack Window
x [Window]
l [Window]
r) =
let r' :: [Window]
r' = ([Window] -> [Window] -> [Window]
forall a. [a] -> [a] -> [a]
++ [Window]
r) ([Window] -> [Window])
-> ([Window] -> [Window]) -> [Window] -> [Window]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Window] -> [Window]
forall a. Int -> [a] -> [a]
cycleN Int
1 ([Window] -> [Window])
-> ([Window] -> [Window]) -> [Window] -> [Window]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Window] -> [Window]
forall a. [a] -> [a]
reverse ([Window] -> [Window]) -> [Window] -> [Window]
forall a b. (a -> b) -> a -> b
$ [Window]
l
st' :: Stack Window
st' = Window -> [Window] -> [Window] -> Stack Window
forall a. a -> [a] -> [a] -> Stack a
W.Stack Window
x [] [Window]
r'
in (Bool
False,Stack Window
st')
swapInStack :: Maybe Window -> W.Stack Window -> (Bool,W.Stack Window)
swapInStack :: Maybe Window -> Stack Window -> (Bool, Stack Window)
swapInStack Maybe Window
_ st :: Stack Window
st@(W.Stack Window
_x [] []) = (Bool
False,Stack Window
st)
swapInStack Maybe Window
Nothing st :: Stack Window
st@(W.Stack Window
_x [] [Window]
_r) = (Bool
True,Stack Window
st)
swapInStack (Just Window
pm) (W.Stack Window
x [] [Window]
r) =
let (Window
x',[Window]
r') = case (Window -> Bool) -> [Window] -> ([Window], [Window])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (Window -> Window -> Bool
forall a. Eq a => a -> a -> Bool
/= Window
pm) [Window]
r of
([Window]
__,[]) -> (Window
x,[Window]
r)
([Window]
sl,[Window]
sr) -> (Window
pm,[Window]
sl [Window] -> [Window] -> [Window]
forall a. [a] -> [a] -> [a]
++ Window
x Window -> [Window] -> [Window]
forall a. a -> [a] -> [a]
: Int -> [Window] -> [Window]
forall a. Int -> [a] -> [a]
drop Int
1 [Window]
sr)
st' :: Stack Window
st' = Window -> [Window] -> [Window] -> Stack Window
forall a. a -> [a] -> [a] -> Stack a
W.Stack Window
x' [] [Window]
r'
b :: Bool
b = Window
x' Window -> Window -> Bool
forall a. Eq a => a -> a -> Bool
== Window
x
in (Bool
b,Stack Window
st')
swapInStack Maybe Window
_ (W.Stack Window
x [Window]
l [Window]
r) =
let l' :: [Window]
l' = [Window] -> [Window]
forall a. HasCallStack => [a] -> [a]
init [Window]
l [Window] -> [Window] -> [Window]
forall a. [a] -> [a] -> [a]
++ [Window
x]
x' :: Window
x' = [Window] -> Window
forall a. HasCallStack => [a] -> a
last [Window]
l
st' :: Stack Window
st' = Window -> [Window] -> [Window] -> Stack Window
forall a. a -> [a] -> [a] -> Stack a
W.Stack Window
x' [Window]
l' [Window]
r
in (Bool
False,Stack Window
st')
swapHybridStack :: Maybe Window -> W.Stack Window -> (Bool,W.Stack Window)
swapHybridStack :: Maybe Window -> Stack Window -> (Bool, Stack Window)
swapHybridStack Maybe Window
m st :: Stack Window
st@(W.Stack Window
_ [] [Window]
_) = Maybe Window -> Stack Window -> (Bool, Stack Window)
swapInStack Maybe Window
m Stack Window
st
swapHybridStack Maybe Window
m Stack Window
st = Maybe Window -> Stack Window -> (Bool, Stack Window)
swapPromoteStack Maybe Window
m Stack Window
st
cycleN :: Int -> [a] -> [a]
cycleN :: forall a. Int -> [a] -> [a]
cycleN Int
n [a]
ls =
let l :: Int
l = [a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
ls
in Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
take Int
l ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
drop (Int
n Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
l) ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ [a] -> [a]
forall a. HasCallStack => [a] -> [a]
cycle [a]
ls
split :: (Num a, Enum a) => (b -> Bool) -> [b] -> ([(a,b)],[b])
split :: forall a b.
(Num a, Enum a) =>
(b -> Bool) -> [b] -> ([(a, b)], [b])
split b -> Bool
p [b]
l =
let (a
_,[(a, b)]
ys,[b]
ns) = (b -> Bool) -> a -> [b] -> (a, [(a, b)], [b])
forall a b.
(Num a, Enum a) =>
(b -> Bool) -> a -> [b] -> (a, [(a, b)], [b])
split' b -> Bool
p a
0 [b]
l
in ([(a, b)]
ys,[b]
ns)
split' :: (Num a, Enum a) => (b -> Bool) -> a -> [b] -> (a,[(a,b)],[b])
split' :: forall a b.
(Num a, Enum a) =>
(b -> Bool) -> a -> [b] -> (a, [(a, b)], [b])
split' b -> Bool
p a
i [b]
l =
let accumulate :: (a, b) -> (a, [(a, b)], [(a, b)]) -> (a, [(a, b)], [(a, b)])
accumulate (a, b)
e (a
c,[(a, b)]
ys,[(a, b)]
ns) = if b -> Bool
p ((a, b) -> b
forall a b. (a, b) -> b
snd (a, b)
e)
then (a
ca -> a -> a
forall a. Num a => a -> a -> a
+a
1,(a, b)
e(a, b) -> [(a, b)] -> [(a, b)]
forall a. a -> [a] -> [a]
:[(a, b)]
ys,[(a, b)]
ns)
else (a
ca -> a -> a
forall a. Num a => a -> a -> a
+a
1,[(a, b)]
ys,(a, b)
e(a, b) -> [(a, b)] -> [(a, b)]
forall a. a -> [a] -> [a]
:[(a, b)]
ns)
(a
c',[(a, b)]
ys',[(a, b)]
ns') = ((a, b) -> (a, [(a, b)], [(a, b)]) -> (a, [(a, b)], [(a, b)]))
-> (a, [(a, b)], [(a, b)]) -> [(a, b)] -> (a, [(a, b)], [(a, b)])
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (a, b) -> (a, [(a, b)], [(a, b)]) -> (a, [(a, b)], [(a, b)])
forall {a} {a}.
Num a =>
(a, b) -> (a, [(a, b)], [(a, b)]) -> (a, [(a, b)], [(a, b)])
accumulate (a
0,[],[]) ([(a, b)] -> (a, [(a, b)], [(a, b)]))
-> [(a, b)] -> (a, [(a, b)], [(a, b)])
forall a b. (a -> b) -> a -> b
$ [a] -> [b] -> [(a, b)]
forall a b. [a] -> [b] -> [(a, b)]
zip [a
i..] [b]
l
in (a
c',[(a, b)]
ys',((a, b) -> b) -> [(a, b)] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map (a, b) -> b
forall a b. (a, b) -> b
snd [(a, b)]
ns')
merge :: (Ord a, Num a) => [(a,b)] -> [b] -> [b]
merge :: forall a b. (Ord a, Num a) => [(a, b)] -> [b] -> [b]
merge [(a, b)]
il [b]
ul =
let (a
_,[(a, b)]
il',[b]
ul') = a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
forall a b.
(Ord a, Num a) =>
a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
merge' a
0 [(a, b)]
il [b]
ul
in [b]
ul' [b] -> [b] -> [b]
forall a. [a] -> [a] -> [a]
++ ((a, b) -> b) -> [(a, b)] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map (a, b) -> b
forall a b. (a, b) -> b
snd [(a, b)]
il'
merge' :: (Ord a, Num a) => a -> [(a,b)] -> [b] -> (a,[(a,b)],[b])
merge' :: forall a b.
(Ord a, Num a) =>
a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
merge' a
i il :: [(a, b)]
il@((a
j,b
a):[(a, b)]
ps) ul :: [b]
ul@(b
b:[b]
bs) = if a
j a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
i
then let (a
x,[(a, b)]
y,[b]
z) = a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
forall a b.
(Ord a, Num a) =>
a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
merge' (a
ia -> a -> a
forall a. Num a => a -> a -> a
+a
1) [(a, b)]
ps [b]
ul
in (a
x,[(a, b)]
y,b
ab -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
z)
else let (a
x,[(a, b)]
y,[b]
z) = a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
forall a b.
(Ord a, Num a) =>
a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
merge' (a
ia -> a -> a
forall a. Num a => a -> a -> a
+a
1) [(a, b)]
il [b]
bs
in (a
x,[(a, b)]
y,b
bb -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
z)
merge' a
i [] (b
b:[b]
bs) =
let (a
x,[(a, b)]
y,[b]
z) = a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
forall a b.
(Ord a, Num a) =>
a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
merge' (a
ia -> a -> a
forall a. Num a => a -> a -> a
+a
1) [] [b]
bs
in (a
x,[(a, b)]
y,b
bb -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
z)
merge' a
i il :: [(a, b)]
il@((a
j,b
a):[(a, b)]
ps) [] = if a
j a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
i
then let (a
x,[(a, b)]
y,[b]
z) = a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
forall a b.
(Ord a, Num a) =>
a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
merge' (a
ia -> a -> a
forall a. Num a => a -> a -> a
+a
1) [(a, b)]
ps []
in (a
x,[(a, b)]
y,b
ab -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
z)
else (a
i,[(a, b)]
il,[])
merge' a
i [] [] =
(a
i,[],[])
stackSplit :: (Num a, Enum a, Ord b) => W.Stack b -> S.Set b -> ([(a,b)],W.Stack b)
stackSplit :: forall a b.
(Num a, Enum a, Ord b) =>
Stack b -> Set b -> ([(a, b)], Stack b)
stackSplit (W.Stack b
x [b]
l [b]
r) Set b
s =
let (a
c,[(a, b)]
fl,[b]
tl) = (b -> Bool) -> a -> [b] -> (a, [(a, b)], [b])
forall a b.
(Num a, Enum a) =>
(b -> Bool) -> a -> [b] -> (a, [(a, b)], [b])
split' (b -> Set b -> Bool
forall a. Ord a => a -> Set a -> Bool
`S.member` Set b
s) a
0 ([b] -> [b]
forall a. [a] -> [a]
reverse [b]
l)
(a
_,[(a, b)]
fr,[b]
tr) = (b -> Bool) -> a -> [b] -> (a, [(a, b)], [b])
forall a b.
(Num a, Enum a) =>
(b -> Bool) -> a -> [b] -> (a, [(a, b)], [b])
split' (b -> Set b -> Bool
forall a. Ord a => a -> Set a -> Bool
`S.member` Set b
s) (a
ca -> a -> a
forall a. Num a => a -> a -> a
+a
1) [b]
r
in ([(a, b)]
fl[(a, b)] -> [(a, b)] -> [(a, b)]
forall a. [a] -> [a] -> [a]
++[(a, b)]
fr,b -> [b] -> [b] -> Stack b
forall a. a -> [a] -> [a] -> Stack a
W.Stack b
x ([b] -> [b]
forall a. [a] -> [a]
reverse [b]
tl) [b]
tr)
stackMerge :: (Ord a, Num a) => W.Stack b -> [(a,b)] -> W.Stack b
stackMerge :: forall a b. (Ord a, Num a) => Stack b -> [(a, b)] -> Stack b
stackMerge (W.Stack b
x [b]
l [b]
r) [(a, b)]
il =
let (a
i,[(a, b)]
il1,[b]
l') = a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
forall a b.
(Ord a, Num a) =>
a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
merge' a
0 [(a, b)]
il ([b] -> [b]
forall a. [a] -> [a]
reverse [b]
l)
(a
_,[(a, b)]
il2,[b]
r') = a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
forall a b.
(Ord a, Num a) =>
a -> [(a, b)] -> [b] -> (a, [(a, b)], [b])
merge' (a
ia -> a -> a
forall a. Num a => a -> a -> a
+a
1) [(a, b)]
il1 [b]
r
in b -> [b] -> [b] -> Stack b
forall a. a -> [a] -> [a] -> Stack a
W.Stack b
x ([b] -> [b]
forall a. [a] -> [a]
reverse [b]
l') ([b]
r' [b] -> [b] -> [b]
forall a. [a] -> [a] -> [a]
++ ((a, b) -> b) -> [(a, b)] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map (a, b) -> b
forall a b. (a, b) -> b
snd [(a, b)]
il2)