aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Hooks
diff options
context:
space:
mode:
authorAdam Vogt <vogt.adam@gmail.com>2009-09-30 22:49:14 +0200
committerAdam Vogt <vogt.adam@gmail.com>2009-09-30 22:49:14 +0200
commit6b814c405e0432391e3dff2bfeac6ef8efffaaba (patch)
tree16219ae68998e844eeb382f0cec0134ca8a88a55 /XMonad/Hooks
parentbf1a224948695888a0688c25b754b50c43306b34 (diff)
downloadXMonadContrib-6b814c405e0432391e3dff2bfeac6ef8efffaaba.tar.gz
XMonadContrib-6b814c405e0432391e3dff2bfeac6ef8efffaaba.tar.xz
XMonadContrib-6b814c405e0432391e3dff2bfeac6ef8efffaaba.zip
Use ErrorT instead of nested case for H.WorkspaceByPos
Ignore-this: c3f96fbbf0ce917c4962b297dea3b174 darcs-hash:20090930204914-1499c-a1a2913a3a5356119c7ebf936731e5bc1b25ba9c.gz
Diffstat (limited to 'XMonad/Hooks')
-rw-r--r--XMonad/Hooks/WorkspaceByPos.hs37
1 files changed, 13 insertions, 24 deletions
diff --git a/XMonad/Hooks/WorkspaceByPos.hs b/XMonad/Hooks/WorkspaceByPos.hs
index 779c948..fbd3d77 100644
--- a/XMonad/Hooks/WorkspaceByPos.hs
+++ b/XMonad/Hooks/WorkspaceByPos.hs
@@ -22,9 +22,11 @@ module XMonad.Hooks.WorkspaceByPos (
import XMonad
import qualified XMonad.StackSet as W
+import XMonad.Util.XUtils (fi)
import Data.Maybe
import Control.Applicative((<$>))
+import Control.Monad.Error ((<=<),guard,lift,runErrorT,throwError)
-- $usage
-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
@@ -36,30 +38,17 @@ import Control.Applicative((<$>))
-- > main = xmonad defaultConfig { manageHook = myManageHook }
workspaceByPos :: ManageHook
-workspaceByPos = ask >>= \w -> do
- b <- liftX $ needsMoving w
- case b of
- Nothing -> idHook
- Just wkspc -> doShift wkspc
+workspaceByPos = (maybe idHook doShift <=< liftX . needsMoving) =<< ask
needsMoving :: Window -> X (Maybe WorkspaceId)
needsMoving w = withDisplay $ \d -> do
- -- only relocate windows with non-zero position
- wa <- io $ getWindowAttributes d w
- if ((wa_x wa) == 0) && ((wa_y wa) == 0)
- then return Nothing
- else do
- ws <- gets windowset
- sc <- fromMaybe (W.current ws)
- <$> pointScreen (fi $ wa_x wa) (fi $ wa_y wa)
- maybeWkspc <- screenWorkspace (W.screen sc)
- case maybeWkspc of
- Nothing -> return Nothing
- Just wkspc -> do
- let currentWksp = W.currentTag ws
- if currentWksp == wkspc
- then return Nothing
- else return (Just wkspc)
-
-fi :: (Integral a, Num b) => a -> b
-fi = fromIntegral
+ -- only relocate windows with non-zero position
+ wa <- io $ getWindowAttributes d w
+ fmap (const Nothing `either` Just) . runErrorT $ do
+ guard $ wa_x wa == 0 && wa_y wa == 0
+ ws <- gets windowset
+ sc <- lift $ fromMaybe (W.current ws)
+ <$> pointScreen (fi $ wa_x wa) (fi $ wa_y wa)
+ Just wkspc <- lift $ screenWorkspace (W.screen sc)
+ guard $ W.currentTag ws /= wkspc
+ return wkspc `asTypeOf` throwError ""