diff options
author | Daniel Schoepe <daniel.schoepe@gmail.com> | 2009-09-19 21:17:17 +0200 |
---|---|---|
committer | Daniel Schoepe <daniel.schoepe@gmail.com> | 2009-09-19 21:17:17 +0200 |
commit | c1a6ed7be8b090cea63a70fa86ee614d011d0f63 (patch) | |
tree | 2611d41215616daba97a239330d85a00123f44e6 /XMonad/Layout | |
parent | 3bd3fd1d4bd1af1ffe306307a80387c82d304664 (diff) | |
download | XMonadContrib-c1a6ed7be8b090cea63a70fa86ee614d011d0f63.tar.gz XMonadContrib-c1a6ed7be8b090cea63a70fa86ee614d011d0f63.tar.xz XMonadContrib-c1a6ed7be8b090cea63a70fa86ee614d011d0f63.zip |
Factor out direction types and put them in X.U.Types
Ignore-this: b2255ec2754fcdf797b1ce2c082642ba
This patch factors out commonly used direction types like
data Direction
darcs-hash:20090919191717-7f603-09c283e51a0b886d260008676d71e3daf31f4394.gz
Diffstat (limited to 'XMonad/Layout')
-rw-r--r-- | XMonad/Layout/Gaps.hs | 20 | ||||
-rw-r--r-- | XMonad/Layout/LayoutHints.hs | 16 | ||||
-rw-r--r-- | XMonad/Layout/SubLayouts.hs | 7 | ||||
-rw-r--r-- | XMonad/Layout/WindowNavigation.hs | 17 |
4 files changed, 30 insertions, 30 deletions
diff --git a/XMonad/Layout/Gaps.hs b/XMonad/Layout/Gaps.hs index 7164b65..9f7e057 100644 --- a/XMonad/Layout/Gaps.hs +++ b/XMonad/Layout/Gaps.hs @@ -28,7 +28,7 @@ module XMonad.Layout.Gaps ( -- * Usage -- $usage - Direction(..), + Direction2D(..), GapSpec, gaps, GapMessage(..) ) where @@ -36,8 +36,8 @@ module XMonad.Layout.Gaps ( import XMonad.Core import Graphics.X11 (Rectangle(..)) -import XMonad.Hooks.ManageDocks (Direction(..)) import XMonad.Layout.LayoutModifier +import XMonad.Util.Types (Direction2D(..)) import Data.List (delete) @@ -79,19 +79,19 @@ import Data.List (delete) -- | A manual gap configuration. Each side of the screen on which a -- gap is enabled is paired with a size in pixels. -type GapSpec = [(Direction,Int)] +type GapSpec = [(Direction2D,Int)] -- | The gap state. The first component is the configuration (which -- gaps are allowed, and their current size), the second is the gaps -- which are currently active. -data Gaps a = Gaps GapSpec [Direction] +data Gaps a = Gaps GapSpec [Direction2D] deriving (Show, Read) -- | Messages which can be sent to a gap modifier. data GapMessage = ToggleGaps -- ^ Toggle all gaps. - | ToggleGap !Direction -- ^ Toggle a single gap. - | IncGap !Int !Direction -- ^ Increase a gap by a certain number of pixels. - | DecGap !Int !Direction -- ^ Decrease a gap. + | ToggleGap !Direction2D -- ^ Toggle a single gap. + | IncGap !Int !Direction2D -- ^ Increase a gap by a certain number of pixels. + | DecGap !Int !Direction2D -- ^ Decrease a gap. deriving (Typeable) instance Message GapMessage @@ -121,16 +121,16 @@ applyGaps gs r = foldr applyGap r (activeGaps gs) activeGaps :: Gaps a -> GapSpec activeGaps (Gaps conf cur) = filter ((`elem` cur) . fst) conf -toggleGaps :: GapSpec -> [Direction] -> [Direction] +toggleGaps :: GapSpec -> [Direction2D] -> [Direction2D] toggleGaps conf [] = map fst conf toggleGaps _ _ = [] -toggleGap :: GapSpec -> [Direction] -> Direction -> [Direction] +toggleGap :: GapSpec -> [Direction2D] -> Direction2D -> [Direction2D] toggleGap conf cur d | d `elem` cur = delete d cur | d `elem` (map fst conf) = d:cur | otherwise = cur -incGap :: GapSpec -> Direction -> Int -> GapSpec +incGap :: GapSpec -> Direction2D -> Int -> GapSpec incGap gs d i = map (\(dir,j) -> if dir == d then (dir,max (j+i) 0) else (dir,j)) gs fi :: (Num b, Integral a) => a -> b diff --git a/XMonad/Layout/LayoutHints.hs b/XMonad/Layout/LayoutHints.hs index 91a067f..29a7d3d 100644 --- a/XMonad/Layout/LayoutHints.hs +++ b/XMonad/Layout/LayoutHints.hs @@ -26,10 +26,10 @@ import XMonad(LayoutClass(runLayout), mkAdjust, Window, Dimension, Position, Rectangle(Rectangle),D) import qualified XMonad.StackSet as W -import XMonad.Hooks.ManageDocks(Direction(..)) import XMonad.Layout.Decoration(isInStack) import XMonad.Layout.LayoutModifier(ModifiedLayout(..), LayoutModifier(modifyLayout, redoLayout, modifierDescription)) +import XMonad.Util.Types(Direction2D(..)) import Control.Applicative((<$>)) import Control.Arrow(Arrow((***), first, second)) import Control.Monad(Monad(return), mapM, join) @@ -151,7 +151,7 @@ applyHints s root (((w,lrect@(Rectangle a b c d)),adj):xs) = next = applyHints s root $ mapSnd growOther' xs in (w,redr):next -growOther :: (Position, Position) -> Rectangle -> Set Direction -> Rectangle -> Rectangle +growOther :: (Position, Position) -> Rectangle -> Set Direction2D -> Rectangle -> Rectangle growOther ds lrect fds r | dirs <- flipDir <$> Set.toList (Set.intersection adj fds) , not $ any (uncurry opposite) $ cross dirs = @@ -161,20 +161,20 @@ growOther ds lrect fds r adj = adjacent lrect r cross xs = [ (a,b) | a <- xs, b <- xs ] - flipDir :: Direction -> Direction + flipDir :: Direction2D -> Direction2D flipDir d = case d of { L -> R; U -> D; R -> L; D -> U } - opposite :: Direction -> Direction -> Bool + opposite :: Direction2D -> Direction2D -> Bool opposite x y = flipDir x == y -- | Leave the opposite edges where they were -grow :: Direction -> (Position,Position) -> Rectangle -> Rectangle +grow :: Direction2D -> (Position,Position) -> Rectangle -> Rectangle grow L (px,_ ) (Rectangle x y w h) = Rectangle (x-px) y (w+fromIntegral px) h grow U (_ ,py) (Rectangle x y w h) = Rectangle x (y-py) w (h+fromIntegral py) grow R (px,_ ) (Rectangle x y w h) = Rectangle x y (w+fromIntegral px) h grow D (_ ,py) (Rectangle x y w h) = Rectangle x y w (h+fromIntegral py) -comparingEdges :: ([Position] -> [Position] -> Bool) -> Rectangle -> Rectangle -> Set Direction +comparingEdges :: ([Position] -> [Position] -> Bool) -> Rectangle -> Rectangle -> Set Direction2D comparingEdges surrounds r1 r2 = Set.fromList $ map fst $ filter snd [ (\k -> (dir,k)) $ any and [[dir `elem` [R,L], allEq [a,c,w,y], [b,d] `surrounds` [x,z]] ,[dir `elem` [U,D], allEq [b,d,x,z], [a,c] `surrounds` [w,y]]] @@ -190,7 +190,7 @@ comparingEdges surrounds r1 r2 = Set.fromList $ map fst $ filter snd [ (\k -> (d -- first is shrunk, assuming that the root window is fully covered: -- one direction for a common edge -- two directions for a common corner -adjacent :: Rectangle -> Rectangle -> Set Direction +adjacent :: Rectangle -> Rectangle -> Set Direction2D adjacent = comparingEdges (all . onClosedInterval) -- | True whenever two edges touch. not (Set.null $ adjacent x y) ==> touching x y @@ -219,7 +219,7 @@ centerPlacement = centerPlacement' clamp 1 -> 1 _ -> 0 -freeDirs :: Rectangle -> Rectangle -> Set Direction +freeDirs :: Rectangle -> Rectangle -> Set Direction2D freeDirs root = Set.fromList . uncurry (++) . (lr *** ud) . centerPlacement' signum root where diff --git a/XMonad/Layout/SubLayouts.hs b/XMonad/Layout/SubLayouts.hs index bb533f6..5d97bae 100644 --- a/XMonad/Layout/SubLayouts.hs +++ b/XMonad/Layout/SubLayouts.hs @@ -40,8 +40,9 @@ import XMonad.Layout.LayoutModifier(LayoutModifier(handleMess, modifyLayout, import XMonad.Layout.Simplest(Simplest(..)) import XMonad.Layout.Tabbed(defaultTheme, shrinkText, TabbedDecoration, addTabs) -import XMonad.Layout.WindowNavigation(Direction, Navigate(Apply)) +import XMonad.Layout.WindowNavigation(Navigate(Apply)) import XMonad.Util.Invisible(Invisible(..)) +import XMonad.Util.Types(Direction2D(..)) import XMonad import Control.Applicative((<$>),(<*)) import Control.Arrow(Arrow(second, (&&&))) @@ -261,13 +262,13 @@ instance Typeable a => Message (GroupMsg a) -- -- @pushWindow@ and @pullWindow@ move individual windows between groups. They -- are less effective at preserving window positions. -pullGroup,pushGroup,pullWindow,pushWindow :: Direction -> Navigate +pullGroup,pushGroup,pullWindow,pushWindow :: Direction2D -> Navigate pullGroup = mergeNav (\o c -> sendMessage $ Merge o c) pushGroup = mergeNav (\o c -> sendMessage $ Merge c o) pullWindow = mergeNav (\o c -> sendMessage $ Migrate o c) pushWindow = mergeNav (\o c -> sendMessage $ Migrate c o) -mergeNav :: (Window -> Window -> X ()) -> Direction -> Navigate +mergeNav :: (Window -> Window -> X ()) -> Direction2D -> Navigate mergeNav f = Apply (\o -> withFocused (f o)) -- | Apply a function on the stack belonging to the currently focused group. It diff --git a/XMonad/Layout/WindowNavigation.hs b/XMonad/Layout/WindowNavigation.hs index 0dd6d43..34660be 100644 --- a/XMonad/Layout/WindowNavigation.hs +++ b/XMonad/Layout/WindowNavigation.hs @@ -18,7 +18,7 @@ module XMonad.Layout.WindowNavigation ( -- * Usage -- $usage windowNavigation, configurableNavigation, - Navigate(..), Direction(..), + Navigate(..), Direction2D(..), MoveWindowToWindow(..), navigateColor, navigateBrightness, noNavigateBorders, defaultWNConfig @@ -29,10 +29,9 @@ import XMonad hiding (Point) import qualified XMonad.StackSet as W import XMonad.Layout.LayoutModifier import XMonad.Util.Invisible +import XMonad.Util.Types (Direction2D(..)) import XMonad.Util.XUtils -import XMonad.Hooks.ManageDocks (Direction(..)) - -- $usage -- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@: -- @@ -67,8 +66,8 @@ import XMonad.Hooks.ManageDocks (Direction(..)) data MoveWindowToWindow a = MoveWindowToWindow a a deriving ( Read, Show, Typeable ) instance Typeable a => Message (MoveWindowToWindow a) -data Navigate = Go Direction | Swap Direction | Move Direction - | Apply (Window -> X()) Direction -- ^ Apply action with destination window +data Navigate = Go Direction2D | Swap Direction2D | Move Direction2D + | Apply (Window -> X()) Direction2D -- ^ Apply action with destination window deriving ( Typeable ) instance Message Navigate @@ -188,7 +187,7 @@ instance LayoutModifier WindowNavigation Window where handleMessOrMaybeModifyIt (WindowNavigation conf (I $ Just (NS pt wrs))) (SomeMessage Hide) handleMessOrMaybeModifyIt _ _ = return Nothing -navigable :: Direction -> Point -> [(Window, Rectangle)] -> [(Window, Rectangle)] +navigable :: Direction2D -> Point -> [(Window, Rectangle)] -> [(Window, Rectangle)] navigable d pt = sortby d . filter (inr d pt . snd) sc :: Pixel -> Window -> X () @@ -197,11 +196,11 @@ sc c win = withDisplay $ \dpy -> io $ setWindowBorder dpy win c center :: Rectangle -> Point center (Rectangle x y w h) = P (fromIntegral x + fromIntegral w/2) (fromIntegral y + fromIntegral h/2) -centerd :: Direction -> Point -> Rectangle -> Point +centerd :: Direction2D -> Point -> Rectangle -> Point centerd d (P xx yy) (Rectangle x y w h) | d == U || d == D = P xx (fromIntegral y + fromIntegral h/2) | otherwise = P (fromIntegral x + fromIntegral w/2) yy -inr :: Direction -> Point -> Rectangle -> Bool +inr :: Direction2D -> Point -> Rectangle -> Bool inr D (P x y) (Rectangle l yr w h) = x >= fromIntegral l && x < fromIntegral l + fromIntegral w && y < fromIntegral yr + fromIntegral h inr U (P x y) (Rectangle l yr w _) = x >= fromIntegral l && x < fromIntegral l + fromIntegral w && @@ -215,7 +214,7 @@ inrect :: Point -> Rectangle -> Bool inrect (P x y) (Rectangle a b w h) = x > fromIntegral a && x < fromIntegral a + fromIntegral w && y > fromIntegral b && y < fromIntegral b + fromIntegral h -sortby :: Direction -> [(a,Rectangle)] -> [(a,Rectangle)] +sortby :: Direction2D -> [(a,Rectangle)] -> [(a,Rectangle)] sortby U = sortBy (\(_,Rectangle _ y _ _) (_,Rectangle _ y' _ _) -> compare y' y) sortby D = sortBy (\(_,Rectangle _ y _ _) (_,Rectangle _ y' _ _) -> compare y y') sortby R = sortBy (\(_,Rectangle x _ _ _) (_,Rectangle x' _ _ _) -> compare x x') |