diff options
-rw-r--r-- | Config.hs | 21 | ||||
-rw-r--r-- | Main.hs | 22 | ||||
-rw-r--r-- | Operations.hs | 35 | ||||
-rw-r--r-- | XMonad.hs | 18 |
4 files changed, 63 insertions, 33 deletions
@@ -49,10 +49,6 @@ workspaces = 9 modMask :: KeyMask modMask = mod1Mask --- The default size for the left pane. -defaultLeftWidth :: Rational -defaultLeftWidth = 1%2 - -- How much to change the size of the windows on the left by default. defaultDelta :: Rational defaultDelta = 3%100 @@ -61,16 +57,25 @@ defaultDelta = 3%100 numlockMask :: KeySym numlockMask = lockMask --- What layout to start in. See the definition of Layout in XMonad.hs for options. -defaultLayout :: Layout -defaultLayout = Full + + +-- What layout to start in, and what the default proportion for the +-- left pane should be in the tiled layout. See LayoutDesc and +-- friends in XMonad.hs for options. +startingLayoutDesc :: LayoutDesc +startingLayoutDesc = LayoutDesc { layoutType = Full + , tileFraction = 1%2 + } + + -- The keys list. keys :: M.Map (KeyMask, KeySym) (X ()) keys = M.fromList $ [ ((modMask .|. shiftMask, xK_Return), spawn "xterm") , ((modMask, xK_p ), spawn "exe=`dmenu_path | dmenu` && exec $exe") - , ((controlMask, xK_space ), spawn "gmrun") +-- Stealing Ctrl + Space is evil. +-- , ((controlMask, xK_space ), spawn "gmrun") , ((modMask, xK_Tab ), raise GT) , ((modMask, xK_j ), raise GT) , ((modMask, xK_k ), raise LT) @@ -41,17 +41,17 @@ main = do xinesc <- getScreenInfo dpy let st = XState - { display = dpy - , screen = dflt - , xineScreens = xinesc - , wsOnScreen = M.fromList $ map (\n -> (n,n)) [0..((length xinesc)-1)] - , theRoot = rootw - , wmdelete = wmdelt - , wmprotocols = wmprot - , dimensions = (displayWidth dpy dflt, displayHeight dpy dflt) - , workspace = W.empty workspaces - , layout = defaultLayout - , leftWidth = defaultLeftWidth + { display = dpy + , screen = dflt + , xineScreens = xinesc + , wsOnScreen = M.fromList $ map (\n -> (n,n)) [0..((length xinesc)-1)] + , theRoot = rootw + , wmdelete = wmdelt + , wmprotocols = wmprot + , dimensions = (displayWidth dpy dflt, displayHeight dpy dflt) + , workspace = W.empty workspaces + , defaultLayoutDesc = startingLayoutDesc + , layoutDescs = M.empty } xSetErrorHandler -- in C, I'm too lazy to write the binding diff --git a/Operations.hs b/Operations.hs index 70f6530..d4fd329 100644 --- a/Operations.hs +++ b/Operations.hs @@ -17,6 +17,7 @@ import XMonad import qualified StackSet as W + -- --------------------------------------------------------------------- -- Managing windows @@ -28,8 +29,10 @@ refresh = do ws2sc <- gets wsOnScreen xinesc <- gets xineScreens d <- gets display - l <- gets layout - ratio <- gets leftWidth + fls <- gets layoutDescs + dfltfl <- gets defaultLayoutDesc + -- l <- gets layout + -- ratio <- gets leftWidth let move w a b c e = io $ moveResizeWindow d w a b c e flip mapM_ (M.assocs ws2sc) $ \(n, scn) -> do let sc = xinesc !! scn @@ -37,6 +40,9 @@ refresh = do sy = rect_y sc sw = rect_width sc sh = rect_height sc + fl = M.findWithDefault dfltfl n fls + l = layoutType fl + ratio = tileFraction fl case l of Full -> whenJust (W.peekStack n ws) $ \w -> do move w sx sy sw sh @@ -53,20 +59,25 @@ refresh = do whenJust (W.peek ws) (io . raiseWindow d) -- this is always Just whenJust (W.peek ws) setFocus --- | switchLayout. Switch to another layout scheme. +-- | switchLayout. Switch to another layout scheme. Switches the current workspace. switchLayout :: X () -switchLayout = do - modify (\s -> s {layout = case layout s of - Full -> Tile - Tile -> Full }) - refresh +switchLayout = layout $ \fl -> fl { layoutType = case layoutType fl of + Full -> Tile + Tile -> Full } -- | changeWidth. Change the width of the main window in tiling mode. changeWidth :: Rational -> X () changeWidth delta = do - -- the min/max stuff is to make sure that 0 <= leftWidth <= 1 - modify (\s -> s {leftWidth = min 1 $ max 0 $ leftWidth s + delta}) - refresh + layout $ \fl -> fl { tileFraction = min 1 $ max 0 $ tileFraction fl + delta } + +-- | layout. Modify the current workspace's layout with a pure function and refresh. +layout :: (LayoutDesc -> LayoutDesc) -> X () +layout f = do modify $ \s -> let fls = layoutDescs s + n = W.current . workspace $ s + fl = M.findWithDefault (defaultLayoutDesc s) n fls + in s { layoutDescs = M.insert n (f fl) fls } + refresh + -- | windows. Modify the current window list with a pure function, and refresh windows :: (WorkSpace -> WorkSpace) -> X () @@ -208,3 +219,5 @@ restart :: IO () restart = do prog <- getProgName args <- getArgs executeFile prog True args Nothing + + @@ -15,7 +15,7 @@ -- module XMonad ( - X, WorkSpace, XState(..), Layout(..), + X, WorkSpace, XState(..), Layout(..), LayoutDesc(..), runX, io, withDisplay, isRoot, spawn, trace, whenJust ) where @@ -43,9 +43,13 @@ data XState = XState , wmprotocols :: {-# UNPACK #-} !Atom , dimensions :: {-# UNPACK #-} !(Int,Int) , workspace :: {-# UNPACK #-} !WorkSpace -- ^ workspace list - , layout :: {-# UNPACK #-} !Layout + , defaultLayoutDesc :: {-# UNPACK #-} !LayoutDesc + , layoutDescs :: {-# UNPACK #-} !(M.Map Int LayoutDesc) + -- ^ mapping of workspaces to descriptions of their layouts + + -- , layout :: {-# UNPACK #-} !Layout -- how much of the screen the main window should take - , leftWidth :: {-# UNPACK #-} !Rational + -- , leftWidth :: {-# UNPACK #-} !Rational } type WorkSpace = StackSet Window @@ -53,6 +57,14 @@ type WorkSpace = StackSet Window -- | The different layout modes data Layout = Full | Tile +-- | A full description of a particular workspace's layout parameters. +data LayoutDesc = LayoutDesc { layoutType :: !Layout + , tileFraction :: !Rational + } + + + + -- | The X monad, a StateT transformer over IO encapuslating the window -- manager state newtype X a = X (StateT XState IO a) |