aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Layout/ResizeScreen.hs
blob: 4b56e96e53ab556ff99e2c1d7aa76dde0cd3f595 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, PatternGuards #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Layout.ResizeScreen
-- Copyright   :  (c) 2007 Andrea Rossato
-- License     :  BSD-style (see xmonad/LICENSE)
--
-- Maintainer  :  andrea.rossato@unibz.it
-- Stability   :  unstable
-- Portability :  unportable
--
-- A layout transformer to have a layout respect a given screen
-- geometry
-----------------------------------------------------------------------------

module XMonad.Layout.ResizeScreen
    ( -- * Usage:
      -- $usage
      resizeHorizontal
    , resizeVertical
    , withNewRectangle
    , ResizeScreen (..)
    ) where

import Control.Arrow (second)
import Control.Applicative ((<$>))

import XMonad
import XMonad.Util.XUtils (fi)

-- $usage
-- You can use this module by importing it into your
-- @~\/.xmonad\/xmonad.hs@ file:
--
-- > import XMonad.Layout.ResizeScreen
--
-- and modifying your layoutHook as follows (for example):
--
-- > layoutHook = resizeHorizontal 40 Full
--
-- For more detailed instructions on editing the layoutHook see:
--
-- "XMonad.Doc.Extending#Editing_the_layout_hook"

resizeHorizontal :: Int -> l a -> ResizeScreen l a
resizeHorizontal = ResizeScreen H

resizeVertical :: Int -> l a -> ResizeScreen l a
resizeVertical = ResizeScreen V

withNewRectangle  :: Rectangle -> l a -> ResizeScreen l a
withNewRectangle = WithNewScreen

data ResizeScreen l a = ResizeScreen ResizeMode Int (l a)
                      | WithNewScreen Rectangle (l a)
                        deriving (Read, Show)
data ResizeMode = H | V deriving (Read, Show)

instance (LayoutClass l a) => LayoutClass (ResizeScreen l) a where
    doLayout m (Rectangle x y w h ) s
        | ResizeScreen H i l <- m = resize (ResizeScreen V i) l (Rectangle (x + fi i) y (w - fi i) h)
        | ResizeScreen V i l <- m = resize (ResizeScreen H i) l (Rectangle x (y + fi i) w (h - fi i))
        | WithNewScreen  r l <- m = resize (WithNewScreen  r) l r
        | otherwise               = return ([],Nothing)
       where resize t l' nr = second (fmap t) <$> doLayout l' nr s

    handleMessage rs m
        | ResizeScreen  t i l <- rs = go (ResizeScreen t i) l
        | WithNewScreen r   l <- rs = go (WithNewScreen  r) l
        | otherwise                 = return Nothing
        where go tp lay = do ml' <- handleMessage lay m
                             return (tp `fmap` ml')

    emptyLayout rs re
        | ResizeScreen  t i l <- rs = go (ResizeScreen t i) l
        | WithNewScreen r   l <- rs = go (WithNewScreen  r) l
        | otherwise                 = return ([],Nothing)
        where go tp lay = do (wrs,ml) <- emptyLayout lay re
                             return (wrs, tp `fmap` ml)

    description _ = []