From fe02406c72d16972b3cad7337a67ecce9778e1cd Mon Sep 17 00:00:00 2001 From: Adam Vogt Date: Fri, 3 Jul 2009 04:15:07 +0200 Subject: Refactor A.OnScreen to use Maybe Monad Ignore-this: d45331ad77662b356f12b3912ea3eac0 darcs-hash:20090703021507-1499c-c61642f78b6ab4c12d7f16cbf573bc7e5494a530.gz --- XMonad/Actions/OnScreen.hs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'XMonad/Actions/OnScreen.hs') diff --git a/XMonad/Actions/OnScreen.hs b/XMonad/Actions/OnScreen.hs index 3b37300..783f124 100644 --- a/XMonad/Actions/OnScreen.hs +++ b/XMonad/Actions/OnScreen.hs @@ -22,7 +22,10 @@ module XMonad.Actions.OnScreen ( ) where import XMonad.StackSet +import Control.Monad(guard) import Data.List +import Data.Maybe(fromMaybe) +import Data.Function(on) -- $usage -- @@ -58,7 +61,7 @@ import Data.List -- A more basic version inside the default keybindings would be: -- -- > , ((modMask .|. controlMask, xK_1) windows (viewOnScreen 0 "1")) --- +-- -- where 0 is the first screen and "1" the workspace with the tag "1". -- -- For detailed instructions on editing your key bindings, see @@ -73,22 +76,16 @@ onScreen :: (Eq sid, Eq i) -> i -- ^ index of the workspace -> StackSet i l a sid sd -- ^ current stack -> StackSet i l a sid sd -onScreen defFunc sc i st - | screen (current st) /= sc = - case ( find ((i==) . tag) (hidden st) - , find ((sc==) . screen) (screens st) - , find ((sc==) . screen) (visible st)) of - - (Just x, Just s, Just o) -> - let newScreen = s { workspace = x } - in st { visible = newScreen : (deleteBy (equating screen) newScreen (visible 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 +onScreen defFunc sc i st = fromMaybe (defFunc i st) $ do + -- on unfocused current screen + guard $ screen (current st) /= sc + x <- find ((i==) . tag ) (hidden st) + s <- find ((sc==) . screen) (screens st) + o <- find ((sc==) . screen) (visible st) + let newScreen = s { workspace = x } + return st { visible = newScreen : deleteBy ((==) `on` screen) newScreen (visible st) + , hidden = workspace o : deleteBy ((==) `on` tag) x (hidden st) + } -- | Switch to workspace 'i' on screen 'sc'. If 'i' is visible use 'greedyView' -- to switch the current workspace with workspace 'i'. -- cgit v1.2.3