{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# LANGUAGE MultiParamTypeClasses, Rank2Types #-}
module XMonad.Layout.Groups.Helpers (
swapUp
, swapDown
, swapMaster
, focusUp
, focusDown
, focusMaster
, toggleFocusFloat
, swapGroupUp
, swapGroupDown
, swapGroupMaster
, focusGroupUp
, focusGroupDown
, focusGroupMaster
, moveToGroupUp
, moveToGroupDown
, moveToNewGroupUp
, moveToNewGroupDown
, splitGroup ) where
import XMonad hiding ((|||))
import qualified XMonad.StackSet as W
import qualified XMonad.Layout.Groups as G
import XMonad.Actions.MessageFeedback (sendMessageB)
import XMonad.Prelude (unless)
import qualified Data.Map as M
alt :: G.ModifySpec -> (WindowSet -> WindowSet) -> X ()
alt :: ModifySpec -> (WindowSet -> WindowSet) -> X ()
alt ModifySpec
f WindowSet -> WindowSet
g = GroupsMessage -> X () -> X ()
alt2 (ModifySpec -> GroupsMessage
G.Modify ModifySpec
f) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (WindowSet -> WindowSet) -> X ()
windows WindowSet -> WindowSet
g
alt2 :: G.GroupsMessage -> X () -> X ()
alt2 :: GroupsMessage -> X () -> X ()
alt2 GroupsMessage
m X ()
x = do Bool
b <- GroupsMessage -> X Bool
forall a. Message a => a -> X Bool
sendMessageB GroupsMessage
m
Bool -> X () -> X ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
b X ()
x
swapUp :: X ()
swapUp :: X ()
swapUp = ModifySpec -> (WindowSet -> WindowSet) -> X ()
alt ModifySpec
G.swapUp WindowSet -> WindowSet
forall i l a s sd. StackSet i l a s sd -> StackSet i l a s sd
W.swapUp
swapDown :: X ()
swapDown :: X ()
swapDown = ModifySpec -> (WindowSet -> WindowSet) -> X ()
alt ModifySpec
G.swapDown WindowSet -> WindowSet
forall i l a s sd. StackSet i l a s sd -> StackSet i l a s sd
W.swapDown
swapMaster :: X ()
swapMaster :: X ()
swapMaster = ModifySpec -> (WindowSet -> WindowSet) -> X ()
alt ModifySpec
G.swapMaster WindowSet -> WindowSet
forall i l a s sd. StackSet i l a s sd -> StackSet i l a s sd
W.swapMaster
focusUp :: X ()
focusUp :: X ()
focusUp = X () -> X () -> X ()
ifFloat X ()
focusFloatUp X ()
focusNonFloatUp
focusDown :: X ()
focusDown :: X ()
focusDown = X () -> X () -> X ()
ifFloat X ()
focusFloatDown X ()
focusNonFloatDown
focusMaster :: X ()
focusMaster :: X ()
focusMaster = ModifySpec -> (WindowSet -> WindowSet) -> X ()
alt ModifySpec
G.focusMaster WindowSet -> WindowSet
forall i l a s sd. StackSet i l a s sd -> StackSet i l a s sd
W.shiftMaster
toggleFocusFloat :: X ()
toggleFocusFloat :: X ()
toggleFocusFloat = X () -> X () -> X ()
ifFloat X ()
focusNonFloat X ()
focusFloatUp
getFloats :: X [Window]
getFloats :: X [Window]
getFloats = (XState -> [Window]) -> X [Window]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((XState -> [Window]) -> X [Window])
-> (XState -> [Window]) -> X [Window]
forall a b. (a -> b) -> a -> b
$ Map Window RationalRect -> [Window]
forall k a. Map k a -> [k]
M.keys (Map Window RationalRect -> [Window])
-> (XState -> Map Window RationalRect) -> XState -> [Window]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> Map Window RationalRect
forall i l a sid sd. StackSet i l a sid sd -> Map a RationalRect
W.floating (WindowSet -> Map Window RationalRect)
-> (XState -> WindowSet) -> XState -> Map Window RationalRect
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState -> WindowSet
windowset
getWindows :: X [Window]
getWindows :: X [Window]
getWindows = (XState -> [Window]) -> X [Window]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((XState -> [Window]) -> X [Window])
-> (XState -> [Window]) -> X [Window]
forall a b. (a -> b) -> a -> b
$ Maybe (Stack Window) -> [Window]
forall a. Maybe (Stack a) -> [a]
W.integrate' (Maybe (Stack Window) -> [Window])
-> (XState -> Maybe (Stack Window)) -> XState -> [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
. WindowSet
-> 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 (WindowSet
-> Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> (XState -> WindowSet)
-> XState
-> Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState -> WindowSet
windowset
ifFloat :: X () -> X () -> X ()
ifFloat :: X () -> X () -> X ()
ifFloat X ()
x1 X ()
x2 = (Window -> X ()) -> X ()
withFocused ((Window -> X ()) -> X ()) -> (Window -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \Window
w -> do [Window]
floats <- X [Window]
getFloats
if Window
w Window -> [Window] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Window]
floats then X ()
x1 else X ()
x2
focusNonFloat :: X ()
focusNonFloat :: X ()
focusNonFloat = GroupsMessage -> X () -> X ()
alt2 GroupsMessage
G.Refocus X ()
helper
where helper :: X ()
helper = (Window -> X ()) -> X ()
withFocused ((Window -> X ()) -> X ()) -> (Window -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \Window
w -> do
[Window]
ws <- X [Window]
getWindows
[Window]
floats <- X [Window]
getFloats
let ([Window]
before, [Window]
after) = (Window -> Bool) -> [Window] -> ([Window], [Window])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (Window -> Window -> Bool
forall a. Eq a => a -> a -> Bool
/=Window
w) [Window]
ws
case (Window -> Bool) -> [Window] -> [Window]
forall a. (a -> Bool) -> [a] -> [a]
filter (Window -> [Window] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Window]
floats) ([Window] -> [Window]) -> [Window] -> [Window]
forall a b. (a -> b) -> a -> b
$ [Window]
after [Window] -> [Window] -> [Window]
forall a. [a] -> [a] -> [a]
++ [Window]
before of
[] -> () -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Window
w':[Window]
_ -> Window -> X ()
focus Window
w'
focusHelper :: (Bool -> Bool)
-> ([Window] -> [Window])
-> X ()
focusHelper :: (Bool -> Bool) -> ([Window] -> [Window]) -> X ()
focusHelper Bool -> Bool
f [Window] -> [Window]
g = (Window -> X ()) -> X ()
withFocused ((Window -> X ()) -> X ()) -> (Window -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \Window
w -> do
[Window]
ws <- X [Window]
getWindows
let ([Window]
before, Window
_:[Window]
after) = (Window -> Bool) -> [Window] -> ([Window], [Window])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (Window -> Window -> Bool
forall a. Eq a => a -> a -> Bool
/=Window
w) [Window]
ws
let toFocus :: [Window]
toFocus = [Window] -> [Window]
g ([Window] -> [Window]) -> [Window] -> [Window]
forall a b. (a -> b) -> a -> b
$ [Window]
after [Window] -> [Window] -> [Window]
forall a. [a] -> [a] -> [a]
++ [Window]
before
[Window]
floats <- X [Window]
getFloats
case (Window -> Bool) -> [Window] -> [Window]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
f (Bool -> Bool) -> (Window -> Bool) -> Window -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Window -> [Window] -> Bool) -> [Window] -> Window -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip Window -> [Window] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem [Window]
floats) [Window]
toFocus of
[] -> () -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Window
w':[Window]
_ -> Window -> X ()
focus Window
w'
focusNonFloatUp :: X ()
focusNonFloatUp :: X ()
focusNonFloatUp = GroupsMessage -> X () -> X ()
alt2 (ModifySpec -> GroupsMessage
G.Modify ModifySpec
G.focusUp) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (Bool -> Bool) -> ([Window] -> [Window]) -> X ()
focusHelper Bool -> Bool
not [Window] -> [Window]
forall a. [a] -> [a]
reverse
focusNonFloatDown :: X ()
focusNonFloatDown :: X ()
focusNonFloatDown = GroupsMessage -> X () -> X ()
alt2 (ModifySpec -> GroupsMessage
G.Modify ModifySpec
G.focusDown) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (Bool -> Bool) -> ([Window] -> [Window]) -> X ()
focusHelper Bool -> Bool
not [Window] -> [Window]
forall a. a -> a
id
focusFloatUp :: X ()
focusFloatUp :: X ()
focusFloatUp = (Bool -> Bool) -> ([Window] -> [Window]) -> X ()
focusHelper Bool -> Bool
forall a. a -> a
id [Window] -> [Window]
forall a. [a] -> [a]
reverse
focusFloatDown :: X ()
focusFloatDown :: X ()
focusFloatDown = (Bool -> Bool) -> ([Window] -> [Window]) -> X ()
focusHelper Bool -> Bool
forall a. a -> a
id [Window] -> [Window]
forall a. a -> a
id
wrap :: G.ModifySpec -> X ()
wrap :: ModifySpec -> X ()
wrap ModifySpec
x = GroupsMessage -> X ()
forall a. Message a => a -> X ()
sendMessage (ModifySpec -> GroupsMessage
G.Modify ModifySpec
x)
swapGroupUp :: X ()
swapGroupUp :: X ()
swapGroupUp = ModifySpec -> X ()
wrap ModifySpec
G.swapGroupUp
swapGroupDown :: X ()
swapGroupDown :: X ()
swapGroupDown = ModifySpec -> X ()
wrap ModifySpec
G.swapGroupDown
swapGroupMaster :: X ()
swapGroupMaster :: X ()
swapGroupMaster = ModifySpec -> X ()
wrap ModifySpec
G.swapGroupMaster
focusGroupUp :: X ()
focusGroupUp :: X ()
focusGroupUp = ModifySpec -> X ()
wrap ModifySpec
G.focusGroupUp
focusGroupDown :: X ()
focusGroupDown :: X ()
focusGroupDown = ModifySpec -> X ()
wrap ModifySpec
G.focusGroupDown
focusGroupMaster :: X ()
focusGroupMaster :: X ()
focusGroupMaster = ModifySpec -> X ()
wrap ModifySpec
G.focusGroupMaster
moveToGroupUp :: Bool -> X ()
moveToGroupUp :: Bool -> X ()
moveToGroupUp Bool
b = ModifySpec -> X ()
wrap (Bool -> ModifySpec
G.moveToGroupUp Bool
b)
moveToGroupDown :: Bool -> X ()
moveToGroupDown :: Bool -> X ()
moveToGroupDown Bool
b = ModifySpec -> X ()
wrap (Bool -> ModifySpec
G.moveToGroupDown Bool
b)
moveToNewGroupUp :: X ()
moveToNewGroupUp :: X ()
moveToNewGroupUp = ModifySpec -> X ()
wrap ModifySpec
G.moveToNewGroupUp
moveToNewGroupDown :: X ()
moveToNewGroupDown :: X ()
moveToNewGroupDown = ModifySpec -> X ()
wrap ModifySpec
G.moveToNewGroupDown
splitGroup :: X ()
splitGroup :: X ()
splitGroup = ModifySpec -> X ()
wrap ModifySpec
G.splitGroup