aboutsummaryrefslogtreecommitdiffstats
path: root/MagicFocus.hs
diff options
context:
space:
mode:
authorAndrea Rossato <andrea.rossato@unibz.it>2007-09-26 13:43:07 +0200
committerAndrea Rossato <andrea.rossato@unibz.it>2007-09-26 13:43:07 +0200
commit15b0b93cf6b5c176edb9b095b8143e1d4547a4e4 (patch)
tree5b7c890be89a815dd2b53c8d8ef9a59f4ac5fa64 /MagicFocus.hs
parent97d3915692401b74d4aefc8e0e70a362251edc3f (diff)
downloadXMonadContrib-15b0b93cf6b5c176edb9b095b8143e1d4547a4e4.tar.gz
XMonadContrib-15b0b93cf6b5c176edb9b095b8143e1d4547a4e4.tar.xz
XMonadContrib-15b0b93cf6b5c176edb9b095b8143e1d4547a4e4.zip
make MagicFocus work with the new Layout class
darcs-hash:20070926114307-32816-d45cfc1350e47adc222f7f7667649344f51049e1.gz
Diffstat (limited to 'MagicFocus.hs')
-rw-r--r--MagicFocus.hs34
1 files changed, 23 insertions, 11 deletions
diff --git a/MagicFocus.hs b/MagicFocus.hs
index 7bce455..0f7230b 100644
--- a/MagicFocus.hs
+++ b/MagicFocus.hs
@@ -11,26 +11,38 @@
-- Automagically put the focused window in the master area.
-----------------------------------------------------------------------------
-module XMonadContrib.MagicFocus (
- -- * Usage
- -- $usage
- magicFocus) where
+module XMonadContrib.MagicFocus
+ (-- * Usage
+ -- $usage
+ MagicFocus(MagicFocus)
+ ) where
-import Graphics.X11.Xlib (Window)
+import Graphics.X11.Xlib
import XMonad
import StackSet
-- $usage
-- > import XMonadContrib.MagicFocus
--- > defaultLayouts = [ magicFocus tiled , magicFocus $ mirror tiled ]
+-- > defaultLayouts = [ SomeLayout $ MagicFocus tiled , SomeLayout $ MagicFocus $ Mirror tiled ]
-- %import XMonadContrib.MagicFocus
--- %layout , magicFocus tiled
--- %layout , magicFocus $ mirror tiled
+-- %layout , SomeLayout $ MagicFocus tiled
+-- %layout , SomeLayout $ MagicFocus $ Mirror tiled
-magicFocus :: Layout Window -> Layout Window
-magicFocus l = l { doLayout = \r s -> withWindowSet (return . peek) >>= (doLayout l) r . swap s
- , modifyLayout = \x -> fmap magicFocus `fmap` modifyLayout l x }
+
+data MagicFocus l a = MagicFocus (l a) deriving ( Show , Read )
+
+instance (Layout l Window) => Layout (MagicFocus l) Window where
+ doLayout = magicFocus
+
+magicFocus :: Layout l Window => MagicFocus l Window -> Rectangle
+ -> Stack Window -> X ([(Window, Rectangle)], Maybe (MagicFocus l Window))
+magicFocus (MagicFocus l) r s =
+ withWindowSet $ \wset -> do
+ (ws,nl) <- doLayout l r (swap s $ peek wset)
+ case nl of
+ Nothing -> return (ws, Nothing)
+ Just l' -> return (ws, Just $ MagicFocus l')
swap :: (Eq a) => Stack a -> Maybe a -> Stack a
swap (Stack f u d) focused | Just f == focused = Stack f [] (reverse u ++ d)