aboutsummaryrefslogtreecommitdiffstats
path: root/NoBorders.hs
blob: 5419eeb3789547599ab9bd5c154853ef2f8e9069 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, TypeSynonymInstances #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.NoBorders
-- Copyright   :  (c) David Roundy <droundy@darcs.net>
-- License     :  BSD3-style (see LICENSE)
--
-- Maintainer  :  David Roundy <droundy@darcs.net>
-- Stability   :  unstable
-- Portability :  unportable
--
-- Make a given layout display without borders.  This is useful for
-- full-screen or tabbed layouts, where you don't really want to waste a
-- couple of pixels of real estate just to inform yourself that the visible
-- window has focus.
--
-----------------------------------------------------------------------------

module XMonadContrib.NoBorders (
                                -- * Usage
                                -- $usage
                                noBorders,
                                smartBorders,
                                withBorder
                               ) where

import Control.Monad.State ( gets )
import Graphics.X11.Xlib

import XMonad
import XMonadContrib.LayoutModifier
import {-# SOURCE #-} Config (borderWidth)
import qualified StackSet as W
import Data.List ((\\))

-- $usage
-- You can use this module with the following in your Config.hs file:
--
-- > import XMonadContrib.NoBorders
--
-- and modify the defaultLayouts to call noBorders on the layouts you want to lack
-- borders
--
-- > defaultLayouts = [ Layout (noBorders Full), ... ]

-- %import XMonadContrib.NoBorders
-- %layout -- prepend noBorders to default layouts above to remove their borders, like so:
-- %layout , noBorders Full

-- todo, use an InvisibleList.
data WithBorder a = WithBorder Dimension [a] deriving ( Read, Show )

instance LayoutModifier WithBorder Window where
    modifierDescription (WithBorder 0 _) = "NoBorders"
    modifierDescription (WithBorder n _) = "Borders " ++ show n

    unhook (WithBorder _ s) = setBorders borderWidth s

    redoLayout (WithBorder n s) _ _ wrs = do
        setBorders borderWidth (s \\ ws)
        setBorders n ws
        return (wrs, Just $ WithBorder n ws)
     where
        ws = map fst wrs

noBorders :: LayoutClass l Window => l Window -> ModifiedLayout WithBorder l Window
noBorders = ModifiedLayout $ WithBorder 0 []

withBorder :: LayoutClass l a => Dimension -> l a -> ModifiedLayout WithBorder l a
withBorder b = ModifiedLayout $ WithBorder b []

setBorders :: Dimension -> [Window] -> X ()
setBorders bw ws = withDisplay $ \d -> mapM_ (\w -> io $ setWindowBorderWidth d w bw) ws

data SmartBorder a = SmartBorder [a] deriving (Read, Show)

instance LayoutModifier SmartBorder Window where
    modifierDescription _ = "SmartBorder"

    unhook (SmartBorder s) = setBorders borderWidth s

    redoLayout (SmartBorder s) _ _ wrs = do
        ss <- gets (W.screens . windowset)

        if singleton ws && singleton ss
            then do
                setBorders borderWidth (s \\ ws)
                setBorders 0 ws
                return (wrs, Just $ SmartBorder ws)
            else do
                setBorders borderWidth s
                return (wrs, Just $ SmartBorder [])
     where
        ws = map fst wrs
        singleton = null . drop 1

smartBorders :: LayoutClass l a => l a -> ModifiedLayout SmartBorder l a
smartBorders = ModifiedLayout (SmartBorder [])