module XMonad.Actions.OnScreen (
onScreen
, onScreen'
, Focus(..)
, viewOnScreen
, greedyViewOnScreen
, onlyOnScreen
, toggleOnScreen
, toggleGreedyOnScreen
) where
import XMonad
import XMonad.Prelude (fromMaybe, guard, empty)
import XMonad.StackSet hiding (new)
data Focus = FocusNew
| FocusCurrent
| FocusTag WorkspaceId
| FocusTagVisible WorkspaceId
onScreen :: (WindowSet -> WindowSet)
-> Focus
-> ScreenId
-> WindowSet
-> WindowSet
onScreen :: (WindowSet -> WindowSet)
-> Focus -> ScreenId -> WindowSet -> WindowSet
onScreen WindowSet -> WindowSet
f Focus
foc ScreenId
sc WindowSet
st = forall a. a -> Maybe a -> a
fromMaybe WindowSet
st forall a b. (a -> b) -> a -> b
$ do
WorkspaceId
ws <- forall s i l a sd. Eq s => s -> StackSet i l a s sd -> Maybe i
lookupWorkspace ScreenId
sc WindowSet
st
let fStack :: WindowSet
fStack = WindowSet -> WindowSet
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
view WorkspaceId
ws WindowSet
st
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Focus -> WindowSet -> WindowSet -> WindowSet
setFocus Focus
foc WindowSet
st WindowSet
fStack
setFocus :: Focus
-> WindowSet
-> WindowSet
-> WindowSet
setFocus :: Focus -> WindowSet -> WindowSet -> WindowSet
setFocus Focus
FocusNew WindowSet
_ WindowSet
new = WindowSet
new
setFocus Focus
FocusCurrent WindowSet
old WindowSet
new =
case forall s i l a sd. Eq s => s -> StackSet i l a s sd -> Maybe i
lookupWorkspace (forall i l a sid sd. Screen i l a sid sd -> sid
screen forall a b. (a -> b) -> a -> b
$ forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
current WindowSet
old) WindowSet
new of
Maybe WorkspaceId
Nothing -> WindowSet
new
Just WorkspaceId
i -> forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
view WorkspaceId
i WindowSet
new
setFocus (FocusTag WorkspaceId
i) WindowSet
_ WindowSet
new = forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
view WorkspaceId
i WindowSet
new
setFocus (FocusTagVisible WorkspaceId
i) WindowSet
old WindowSet
new =
if WorkspaceId
i forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall a b. (a -> b) -> [a] -> [b]
map (forall i l a. Workspace i l a -> i
tag forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
workspace) (forall i l a sid sd. StackSet i l a sid sd -> [Screen i l a sid sd]
visible WindowSet
old)
then Focus -> WindowSet -> WindowSet -> WindowSet
setFocus (WorkspaceId -> Focus
FocusTag WorkspaceId
i) WindowSet
old WindowSet
new
else Focus -> WindowSet -> WindowSet -> WindowSet
setFocus Focus
FocusCurrent WindowSet
old WindowSet
new
onScreen' :: X ()
-> Focus
-> ScreenId
-> X ()
onScreen' :: X () -> Focus -> ScreenId -> X ()
onScreen' X ()
x Focus
foc ScreenId
sc = do
WindowSet
st <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState -> WindowSet
windowset
case forall s i l a sd. Eq s => s -> StackSet i l a s sd -> Maybe i
lookupWorkspace ScreenId
sc WindowSet
st of
Maybe WorkspaceId
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just WorkspaceId
ws -> do
(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
view WorkspaceId
ws
X ()
x
(WindowSet -> WindowSet) -> X ()
windows forall a b. (a -> b) -> a -> b
$ Focus -> WindowSet -> WindowSet -> WindowSet
setFocus Focus
foc WindowSet
st
viewOnScreen :: ScreenId
-> WorkspaceId
-> WindowSet
-> WindowSet
viewOnScreen :: ScreenId -> WorkspaceId -> WindowSet -> WindowSet
viewOnScreen ScreenId
sid WorkspaceId
i =
(WindowSet -> WindowSet)
-> Focus -> ScreenId -> WindowSet -> WindowSet
onScreen (forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
view WorkspaceId
i) (WorkspaceId -> Focus
FocusTag WorkspaceId
i) ScreenId
sid
greedyViewOnScreen :: ScreenId
-> WorkspaceId
-> WindowSet
-> WindowSet
greedyViewOnScreen :: ScreenId -> WorkspaceId -> WindowSet -> WindowSet
greedyViewOnScreen ScreenId
sid WorkspaceId
i =
(WindowSet -> WindowSet)
-> Focus -> ScreenId -> WindowSet -> WindowSet
onScreen (forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
greedyView WorkspaceId
i) (WorkspaceId -> Focus
FocusTagVisible WorkspaceId
i) ScreenId
sid
onlyOnScreen :: ScreenId
-> WorkspaceId
-> WindowSet
-> WindowSet
onlyOnScreen :: ScreenId -> WorkspaceId -> WindowSet -> WindowSet
onlyOnScreen ScreenId
sid WorkspaceId
i =
(WindowSet -> WindowSet)
-> Focus -> ScreenId -> WindowSet -> WindowSet
onScreen (forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
view WorkspaceId
i) Focus
FocusCurrent ScreenId
sid
toggleOnScreen :: ScreenId
-> WorkspaceId
-> WindowSet
-> WindowSet
toggleOnScreen :: ScreenId -> WorkspaceId -> WindowSet -> WindowSet
toggleOnScreen ScreenId
sid WorkspaceId
i =
(WindowSet -> WindowSet)
-> Focus -> ScreenId -> WindowSet -> WindowSet
onScreen ((WorkspaceId -> WindowSet -> WindowSet)
-> WorkspaceId -> WindowSet -> WindowSet
toggleOrView' forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
view WorkspaceId
i) Focus
FocusCurrent ScreenId
sid
toggleGreedyOnScreen :: ScreenId
-> WorkspaceId
-> WindowSet
-> WindowSet
toggleGreedyOnScreen :: ScreenId -> WorkspaceId -> WindowSet -> WindowSet
toggleGreedyOnScreen ScreenId
sid WorkspaceId
i =
(WindowSet -> WindowSet)
-> Focus -> ScreenId -> WindowSet -> WindowSet
onScreen ((WorkspaceId -> WindowSet -> WindowSet)
-> WorkspaceId -> WindowSet -> WindowSet
toggleOrView' forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
greedyView WorkspaceId
i) Focus
FocusCurrent ScreenId
sid
toggleOrView' :: (WorkspaceId -> WindowSet -> WindowSet)
-> WorkspaceId
-> WindowSet
-> WindowSet
toggleOrView' :: (WorkspaceId -> WindowSet -> WindowSet)
-> WorkspaceId -> WindowSet -> WindowSet
toggleOrView' WorkspaceId -> WindowSet -> WindowSet
f WorkspaceId
i WindowSet
st = forall a. a -> Maybe a -> a
fromMaybe (WorkspaceId -> WindowSet -> WindowSet
f WorkspaceId
i WindowSet
st) forall a b. (a -> b) -> a -> b
$ do
let st' :: [Workspace WorkspaceId (Layout Window) Window]
st' = forall i l a sid sd. StackSet i l a sid sd -> [Workspace i l a]
hidden WindowSet
st
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ WorkspaceId
i forall a. Eq a => a -> a -> Bool
== (forall i l a. Workspace i l a -> i
tag forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
workspace forall a b. (a -> b) -> a -> b
$ forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
current WindowSet
st)
case [Workspace WorkspaceId (Layout Window) Window]
st' of
[] -> forall (f :: * -> *) a. Alternative f => f a
empty
(Workspace WorkspaceId (Layout Window) Window
h : [Workspace WorkspaceId (Layout Window) Window]
_) -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ WorkspaceId -> WindowSet -> WindowSet
f (forall i l a. Workspace i l a -> i
tag Workspace WorkspaceId (Layout Window) Window
h) WindowSet
st