aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Hooks
diff options
context:
space:
mode:
authorAdam Vogt <vogt.adam@gmail.com>2009-11-11 03:25:13 +0100
committerAdam Vogt <vogt.adam@gmail.com>2009-11-11 03:25:13 +0100
commit3758137f7534652d68a80f427090e53301631816 (patch)
tree4ff3aa8e98b2cdc14cdceb1d42051a2787735cd8 /XMonad/Hooks
parent7f979da1ca28c1178df34295344491e1c5dedb7c (diff)
downloadXMonadContrib-3758137f7534652d68a80f427090e53301631816.tar.gz
XMonadContrib-3758137f7534652d68a80f427090e53301631816.tar.xz
XMonadContrib-3758137f7534652d68a80f427090e53301631816.zip
Use ExtensibleState in H.FloatNext
Ignore-this: 760d95a685af080466cb4164d1096423 darcs-hash:20091111022513-1499c-09d1a8ca0f1f4b764af7407954f6fe4725f739a5.gz
Diffstat (limited to 'XMonad/Hooks')
-rw-r--r--XMonad/Hooks/FloatNext.hs31
1 files changed, 15 insertions, 16 deletions
diff --git a/XMonad/Hooks/FloatNext.hs b/XMonad/Hooks/FloatNext.hs
index 37bdf90..451939f 100644
--- a/XMonad/Hooks/FloatNext.hs
+++ b/XMonad/Hooks/FloatNext.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE DeriveDataTypeable #-}
-----------------------------------------------------------------------------
-- |
-- Module : XMonad.Hooks.FloatNext
@@ -38,37 +39,35 @@ module XMonad.Hooks.FloatNext ( -- * Usage
import Prelude hiding (all)
import XMonad
+import XMonad.Util.ExtensibleState
-import Control.Monad (join)
+import Control.Monad (join,guard)
import Control.Applicative ((<$>))
import Control.Arrow (first, second)
-import Control.Concurrent.MVar
-import System.IO.Unsafe (unsafePerformIO)
-
{- Helper functions -}
-modifyMVar2 :: MVar a -> (a -> a) -> IO ()
-modifyMVar2 v f = modifyMVar_ v (return . f)
-
_set :: ((a -> a) -> (Bool, Bool) -> (Bool, Bool)) -> a -> X ()
-_set f b = io $ modifyMVar2 floatModeMVar (f $ const b)
+_set f b = modifyState' (f $ const b)
_toggle :: ((Bool -> Bool) -> (Bool, Bool) -> (Bool, Bool)) -> X ()
-_toggle f = io $ modifyMVar2 floatModeMVar (f not)
+_toggle f = modifyState' (f not)
_get :: ((Bool, Bool) -> a) -> X a
-_get f = io $ f <$> readMVar floatModeMVar
+_get f = f . getFloatMode <$> getState
_pp :: ((Bool, Bool) -> Bool) -> String -> (String -> String) -> X (Maybe String)
-_pp f s st = _get f >>= \b -> if b then return $ Just $ st s else return Nothing
-
+_pp f s st = (\b -> guard b >> Just (st s)) <$> _get f
{- The current state is kept here -}
-floatModeMVar :: MVar (Bool, Bool)
-floatModeMVar = unsafePerformIO $ newMVar (False, False)
+data FloatMode = FloatMode { getFloatMode :: (Bool,Bool) } deriving (Typeable)
+
+instance ExtensionClass FloatMode where
+ initialValue = FloatMode (False,False)
+modifyState' :: ((Bool,Bool) -> (Bool,Bool)) -> X ()
+modifyState' f = modifyState (FloatMode . f . getFloatMode)
-- $usage
-- This module provides actions (that can be set as keybindings)
@@ -97,8 +96,8 @@ floatModeMVar = unsafePerformIO $ newMVar (False, False)
-- | This 'ManageHook' will selectively float windows as set
-- by 'floatNext' and 'floatAllNew'.
floatNextHook :: ManageHook
-floatNextHook = do (next, all) <- io $ takeMVar floatModeMVar
- io $ putMVar floatModeMVar (False, all)
+floatNextHook = do (next, all) <- liftX $ getFloatMode <$> getState
+ liftX $ putState $ FloatMode (False, all)
if next || all then doFloat else idHook