{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE RecordWildCards #-}
module XMonad.Actions.CopyWindow (
copy, copyToAll, copyWindow, runOrCopy
, killAllOtherCopies, kill1, taggedWindows, copiesOfOn
, wsContainingCopies, copiesPP
) where
import XMonad
import XMonad.Prelude
import Control.Arrow ((&&&))
import qualified Data.List as L
import XMonad.Actions.WindowGo
import XMonad.Hooks.StatusBar.PP (PP(..), WS(..), isHidden)
import qualified XMonad.StackSet as W
copiesPP :: (WorkspaceId -> String) -> PP -> X PP
copiesPP :: (WorkspaceId -> WorkspaceId) -> PP -> X PP
copiesPP WorkspaceId -> WorkspaceId
wtoS PP
pp = do
[WorkspaceId]
copies <- X [WorkspaceId]
wsContainingCopies
let check :: WS -> Bool
check WS{[Window]
WindowSet
WindowSpace
PP
wsPP :: WS -> PP
wsWS :: WS -> WindowSpace
wsWindowSet :: WS -> WindowSet
wsUrgents :: WS -> [Window]
wsPP :: PP
wsWS :: WindowSpace
wsWindowSet :: WindowSet
wsUrgents :: [Window]
..} = forall i l a. Workspace i l a -> i
W.tag WindowSpace
wsWS forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [WorkspaceId]
copies
let printer :: ReaderT WS Maybe (WorkspaceId -> WorkspaceId)
printer = (forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (WS -> Bool
isHidden forall (m :: * -> *). Monad m => m Bool -> m Bool -> m Bool
<&&> WS -> Bool
check) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (f :: * -> *). Alternative f => Bool -> f ()
guard) forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> WorkspaceId -> WorkspaceId
wtoS
forall (m :: * -> *) a. Monad m => a -> m a
return PP
pp{ ppPrinters :: ReaderT WS Maybe (WorkspaceId -> WorkspaceId)
ppPrinters = ReaderT WS Maybe (WorkspaceId -> WorkspaceId)
printer forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> PP -> ReaderT WS Maybe (WorkspaceId -> WorkspaceId)
ppPrinters PP
pp }
copy :: (Eq s, Eq i, Eq a) => i -> W.StackSet i l a s sd -> W.StackSet i l a s sd
copy :: forall s i a l sd.
(Eq s, Eq i, Eq a) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
copy i
n StackSet i l a s sd
s | Just a
w <- forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek StackSet i l a s sd
s = forall a i s l sd.
(Eq a, Eq i, Eq s) =>
a -> i -> StackSet i l a s sd -> StackSet i l a s sd
copyWindow a
w i
n StackSet i l a s sd
s
| Bool
otherwise = StackSet i l a s sd
s
copyToAll :: (Eq s, Eq i, Eq a) => W.StackSet i l a s sd -> W.StackSet i l a s sd
copyToAll :: forall s i a l sd.
(Eq s, Eq i, Eq a) =>
StackSet i l a s sd -> StackSet i l a s sd
copyToAll StackSet i l a s sd
s = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall s i a l sd.
(Eq s, Eq i, Eq a) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
copy forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i l a. Workspace i l a -> i
W.tag) StackSet i l a s sd
s (forall i l a s sd. StackSet i l a s sd -> [Workspace i l a]
W.workspaces StackSet i l a s sd
s)
copyWindow :: (Eq a, Eq i, Eq s) => a -> i -> W.StackSet i l a s sd -> W.StackSet i l a s sd
copyWindow :: forall a i s l sd.
(Eq a, Eq i, Eq s) =>
a -> i -> StackSet i l a s sd -> StackSet i l a s sd
copyWindow a
w i
n = forall {s} {l} {sd}.
Eq s =>
StackSet i l a s sd -> StackSet i l a s sd
copy'
where copy' :: StackSet i l a s sd -> StackSet i l a s sd
copy' StackSet i l a s sd
s = if i
n forall i l a s sd. Eq i => i -> StackSet i l a s sd -> Bool
`W.tagMember` StackSet i l a s sd
s
then forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
W.view (forall i l a s sd. StackSet i l a s sd -> i
W.currentTag StackSet i l a s sd
s) forall a b. (a -> b) -> a -> b
$ forall {a} {i} {l} {s} {sd}.
Eq a =>
a -> StackSet i l a s sd -> StackSet i l a s sd
insertUp' a
w forall a b. (a -> b) -> a -> b
$ forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
W.view i
n StackSet i l a s sd
s
else StackSet i l a s sd
s
insertUp' :: a -> StackSet i l a s sd -> StackSet i l a s sd
insertUp' a
a = 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 (forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. a -> [a] -> [a] -> Stack a
W.Stack a
a [] [])
(\(W.Stack a
t [a]
l [a]
r) -> if a
a forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` a
tforall a. a -> [a] -> [a]
:[a]
lforall a. [a] -> [a] -> [a]
++[a]
r
then forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. a -> [a] -> [a] -> Stack a
W.Stack a
t [a]
l [a]
r
else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. a -> [a] -> [a] -> Stack a
W.Stack a
a (forall a. Eq a => a -> [a] -> [a]
L.delete a
a [a]
l) (forall a. Eq a => a -> [a] -> [a]
L.delete a
a (a
tforall a. a -> [a] -> [a]
:[a]
r)))
runOrCopy :: String -> Query Bool -> X ()
runOrCopy :: WorkspaceId -> Query Bool -> X ()
runOrCopy = X () -> Query Bool -> X ()
copyMaybe forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). MonadIO m => WorkspaceId -> m ()
spawn
copyMaybe :: X () -> Query Bool -> X ()
copyMaybe :: X () -> Query Bool -> X ()
copyMaybe X ()
f Query Bool
qry = Query Bool -> ManageHook -> X () -> X ()
ifWindow Query Bool
qry forall {l} {sd}.
Query (Endo (StackSet WorkspaceId l Window ScreenId sd))
copyWin X ()
f
where copyWin :: Query (Endo (StackSet WorkspaceId l Window ScreenId sd))
copyWin = forall r (m :: * -> *). MonadReader r m => m r
ask forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> forall s. (s -> s) -> Query (Endo s)
doF (\StackSet WorkspaceId l Window ScreenId sd
ws -> forall a i s l sd.
(Eq a, Eq i, Eq s) =>
a -> i -> StackSet i l a s sd -> StackSet i l a s sd
copyWindow Window
w (forall i l a s sd. StackSet i l a s sd -> i
W.currentTag StackSet WorkspaceId l Window ScreenId sd
ws) StackSet WorkspaceId l Window ScreenId sd
ws)
kill1 :: X ()
kill1 :: X ()
kill1 = do WindowSet
ss <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState -> WindowSet
windowset
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust (forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek WindowSet
ss) forall a b. (a -> b) -> a -> b
$ \Window
w -> if forall a i l s sd. Eq a => a -> StackSet i l a s sd -> Bool
W.member Window
w forall a b. (a -> b) -> a -> b
$ forall {a} {i} {l} {s} {sd}.
Eq a =>
a -> StackSet i l a s sd -> StackSet i l a s sd
delete'' Window
w WindowSet
ss
then (WindowSet -> WindowSet) -> X ()
windows forall a b. (a -> b) -> a -> b
$ forall {a} {i} {l} {s} {sd}.
Eq a =>
a -> StackSet i l a s sd -> StackSet i l a s sd
delete'' Window
w
else X ()
kill
where delete'' :: a -> StackSet i l a s sd -> StackSet i l a s sd
delete'' a
w = 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 forall a. Maybe a
Nothing (forall a. (a -> Bool) -> Stack a -> Maybe (Stack a)
W.filter (forall a. Eq a => a -> a -> Bool
/= a
w))
killAllOtherCopies :: X ()
killAllOtherCopies :: X ()
killAllOtherCopies = do WindowSet
ss <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState -> WindowSet
windowset
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust (forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek WindowSet
ss) forall a b. (a -> b) -> a -> b
$ \Window
w -> (WindowSet -> WindowSet) -> X ()
windows forall a b. (a -> b) -> a -> b
$
forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
W.view (forall i l a s sd. StackSet i l a s sd -> i
W.currentTag WindowSet
ss) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall {sid} {b} {a} {l} {sd}.
(Eq sid, Eq b, Eq a) =>
a -> StackSet b l a sid sd -> StackSet b l a sid sd
delFromAllButCurrent Window
w
where
delFromAllButCurrent :: a -> StackSet b l a sid sd -> StackSet b l a sid sd
delFromAllButCurrent a
w StackSet b l a sid sd
ss = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall {s} {i} {a} {l} {sd}.
(Eq s, Eq i, Eq a) =>
a -> i -> StackSet i l a s sd -> StackSet i l a s sd
delWinFromWorkspace a
w forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i l a. Workspace i l a -> i
W.tag)
StackSet b l a sid sd
ss
(forall i l a s sd. StackSet i l a s sd -> [Workspace i l a]
W.hidden StackSet b l a sid sd
ss forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (forall i l a sid sd. StackSet i l a sid sd -> [Screen i l a sid sd]
W.visible StackSet b l a sid sd
ss))
delWinFromWorkspace :: a -> i -> StackSet i l a s sd -> StackSet i l a s sd
delWinFromWorkspace a
w i
wid = forall {s} {i} {s} {l} {a} {sd} {l} {a} {sd}.
(Eq s, Eq i, Eq s) =>
i
-> (StackSet i l a s sd -> StackSet i l a s sd)
-> StackSet i l a s sd
-> StackSet i l a s sd
viewing i
wid forall a b. (a -> b) -> a -> b
$ 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 forall a. Maybe a
Nothing (forall a. (a -> Bool) -> Stack a -> Maybe (Stack a)
W.filter (forall a. Eq a => a -> a -> Bool
/= a
w))
viewing :: i
-> (StackSet i l a s sd -> StackSet i l a s sd)
-> StackSet i l a s sd
-> StackSet i l a s sd
viewing i
wis StackSet i l a s sd -> StackSet i l a s sd
f StackSet i l a s sd
ss = forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
W.view (forall i l a s sd. StackSet i l a s sd -> i
W.currentTag StackSet i l a s sd
ss) forall a b. (a -> b) -> a -> b
$ StackSet i l a s sd -> StackSet i l a s sd
f forall a b. (a -> b) -> a -> b
$ forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
W.view i
wis StackSet i l a s sd
ss
wsContainingCopies :: X [WorkspaceId]
wsContainingCopies :: X [WorkspaceId]
wsContainingCopies = do
WindowSet
ws <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState -> WindowSet
windowset
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a i. Eq a => Maybe a -> [(i, [a])] -> [i]
copiesOfOn (forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek WindowSet
ws) (forall i l a. [Workspace i l a] -> [(i, [a])]
taggedWindows forall a b. (a -> b) -> a -> b
$ forall i l a s sd. StackSet i l a s sd -> [Workspace i l a]
W.hidden WindowSet
ws)
taggedWindows :: [W.Workspace i l a] -> [(i, [a])]
taggedWindows :: forall i l a. [Workspace i l a] -> [(i, [a])]
taggedWindows = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a -> b) -> a -> b
$ forall i l a. Workspace i l a -> i
W.tag forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& forall a. Maybe (Stack a) -> [a]
W.integrate' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack
copiesOfOn :: (Eq a) => Maybe a -> [(i, [a])] -> [i]
copiesOfOn :: forall a i. Eq a => Maybe a -> [(i, [a])] -> [i]
copiesOfOn Maybe a
foc [(i, [a])]
tw = forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] a -> [i]
hasCopyOf Maybe a
foc
where hasCopyOf :: a -> [i]
hasCopyOf a
f = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter ((a
f forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) [(i, [a])]
tw