Refactor A.OnScreen to use Maybe Monad

This commit is contained in:
Adam Vogt
2009-07-03 02:15:07 +00:00
parent 7e6fed9bf0
commit 9c3b472470

View File

@@ -22,7 +22,10 @@ module XMonad.Actions.OnScreen (
) where ) where
import XMonad.StackSet import XMonad.StackSet
import Control.Monad(guard)
import Data.List import Data.List
import Data.Maybe(fromMaybe)
import Data.Function(on)
-- $usage -- $usage
-- --
@@ -58,7 +61,7 @@ import Data.List
-- A more basic version inside the default keybindings would be: -- A more basic version inside the default keybindings would be:
-- --
-- > , ((modMask .|. controlMask, xK_1) windows (viewOnScreen 0 "1")) -- > , ((modMask .|. controlMask, xK_1) windows (viewOnScreen 0 "1"))
-- --
-- where 0 is the first screen and "1" the workspace with the tag "1". -- where 0 is the first screen and "1" the workspace with the tag "1".
-- --
-- For detailed instructions on editing your key bindings, see -- For detailed instructions on editing your key bindings, see
@@ -73,22 +76,16 @@ onScreen :: (Eq sid, Eq i)
-> i -- ^ index of the workspace -> i -- ^ index of the workspace
-> StackSet i l a sid sd -- ^ current stack -> StackSet i l a sid sd -- ^ current stack
-> StackSet i l a sid sd -> StackSet i l a sid sd
onScreen defFunc sc i st onScreen defFunc sc i st = fromMaybe (defFunc i st) $ do
| screen (current st) /= sc = -- on unfocused current screen
case ( find ((i==) . tag) (hidden st) guard $ screen (current st) /= sc
, find ((sc==) . screen) (screens st) x <- find ((i==) . tag ) (hidden st)
, find ((sc==) . screen) (visible st)) of s <- find ((sc==) . screen) (screens st)
o <- find ((sc==) . screen) (visible st)
(Just x, Just s, Just o) -> let newScreen = s { workspace = x }
let newScreen = s { workspace = x } return st { visible = newScreen : deleteBy ((==) `on` screen) newScreen (visible st)
in st { visible = newScreen : (deleteBy (equating screen) newScreen (visible st)) , hidden = workspace o : deleteBy ((==) `on` tag) x (hidden st)
, hidden = (workspace o) : (deleteBy (equating tag) x (hidden st)) }
}
_ -> defFunc i st -- no valid screen id/workspace already visible
| otherwise = defFunc i st -- on current screen
where equating f x y = f x == f y
-- | Switch to workspace 'i' on screen 'sc'. If 'i' is visible use 'greedyView' -- | Switch to workspace 'i' on screen 'sc'. If 'i' is visible use 'greedyView'
-- to switch the current workspace with workspace 'i'. -- to switch the current workspace with workspace 'i'.