-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Actions.NoBorders
-- Description :  Helper functions for dealing with window borders.
-- Copyright   :  (c) Lukas Mai
-- License     :  BSD3-style (see LICENSE)
--
-- Maintainer  :  Lukas Mai <l.mai@web.de>
-- Stability   :  stable
-- Portability :  unportable
--
-- This module provides helper functions for dealing with window borders.
--
-----------------------------------------------------------------------------

module XMonad.Actions.NoBorders (
    toggleBorder
) where

import XMonad

-- | Toggle the border of the currently focused window. To use it, add a
-- keybinding like so:
--
-- > , ((modm,  xK_g ),   withFocused toggleBorder)
--
toggleBorder :: Window -> X ()
toggleBorder :: Window -> X ()
toggleBorder Window
w = do
    Dimension
bw <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (forall (l :: * -> *). XConfig l -> Dimension
borderWidth forall b c a. (b -> c) -> (a -> b) -> a -> c
. XConf -> XConfig Layout
config)
    forall a. (Display -> X a) -> X a
withDisplay forall a b. (a -> b) -> a -> b
$ \Display
d -> Display -> Window -> (WindowAttributes -> X ()) -> X ()
withWindowAttributes Display
d Window
w forall a b. (a -> b) -> a -> b
$ \WindowAttributes
wa -> forall (m :: * -> *) a. MonadIO m => IO a -> m a
io forall a b. (a -> b) -> a -> b
$
        if WindowAttributes -> CInt
wa_border_width WindowAttributes
wa forall a. Eq a => a -> a -> Bool
== CInt
0
            then Display -> Window -> Dimension -> IO ()
setWindowBorderWidth Display
d Window
w Dimension
bw
            else Display -> Window -> Dimension -> IO ()
setWindowBorderWidth Display
d Window
w Dimension
0