{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, DeriveDataTypeable, TypeSynonymInstances, PatternGuards #-}------------------------------------------------------------------------------- |-- Module : XMonad.Layout.Gaps-- Copyright : (c) 2008 Brent Yorgey-- License : BSD3---- Maintainer : <byorgey@gmail.com>-- Stability : unstable-- Portability : unportable---- Create manually-sized gaps along edges of the screen which will not-- be used for tiling, along with support for toggling gaps on and-- off.---- Note that "XMonad.Hooks.ManageDocks" is the preferred solution for-- leaving space for your dock-type applications (status bars,-- toolbars, docks, etc.), since it automatically sets up appropriate-- gaps, allows them to be toggled, etc. However, this module may-- still be useful in some situations where the automated approach of-- ManageDocks does not work; for example, to work with a dock-type-- application that does not properly set the STRUTS property, or to-- leave part of the screen blank which is truncated by a projector,-- and so on.-----------------------------------------------------------------------------moduleXMonad.Layout.Gaps(-- * Usage-- $usageDirection2D(..),GapSpec,gaps,GapMessage(..))whereimportXMonad.CoreimportGraphics.X11(Rectangle(..))importXMonad.Layout.LayoutModifierimportXMonad.Util.Types(Direction2D(..))importData.List(delete)-- $usage-- You can use this module by importing it into your @~\/.xmonad\/xmonad.hs@ file:---- > import XMonad.Layout.Gaps---- and applying the 'gaps' modifier to your layouts as follows (for-- example):---- > layoutHook = gaps [(U,18), (R,23)] $ Tall 1 (3/100) (1/2) ||| Full -- leave gaps at the top and right---- You can additionally add some keybindings to toggle or modify the gaps,-- for example:---- > , ((modm .|. controlMask, xK_g), sendMessage $ ToggleGaps) -- toggle all gaps-- > , ((modm .|. controlMask, xK_t), sendMessage $ ToggleGap U) -- toggle the top gap-- > , ((modm .|. controlMask, xK_w), sendMessage $ IncGap R 5) -- increment the right-hand gap-- > , ((modm .|. controlMask, xK_q), sendMessage $ DecGap R 5) -- decrement the right-hand gap---- If you want complete control over all gaps, you could include-- something like this in your keybindings, assuming in this case you-- are using 'XMonad.Util.EZConfig.mkKeymap' or-- 'XMonad.Util.EZConfig.additionalKeysP' from "XMonad.Util.EZConfig"-- for string keybinding specifications:---- > ++-- > [ ("M-g " ++ f ++ " " ++ k, sendMessage $ m d)-- > | (k, d) <- [("a",L), ("s",D), ("w",U), ("d",R)]-- > , (f, m) <- [("v", ToggleGap), ("h", IncGap 10), ("f", DecGap 10)]-- > ]---- Given the above keybinding definition, for example, you could type-- @M-g, v, a@ to toggle the top gap.---- To configure gaps differently per-screen, use-- "XMonad.Layout.PerScreen" (coming soon).-- | A manual gap configuration. Each side of the screen on which a-- gap is enabled is paired with a size in pixels.typeGapSpec=[(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.dataGapsa=GapsGapSpec[Direction2D]deriving(Show,Read)-- | Messages which can be sent to a gap modifier.dataGapMessage=ToggleGaps-- ^ Toggle all gaps.|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)instanceMessageGapMessageinstanceLayoutModifierGapsawheremodifyLayoutgwr=runLayoutw(applyGapsgr)pureMess(Gapsconfcur)m|JustToggleGaps<-fromMessagem=Just$Gapsconf(toggleGapsconfcur)|Just(ToggleGapd)<-fromMessagem=Just$Gapsconf(toggleGapconfcurd)|Just(IncGapid)<-fromMessagem=Just$Gaps(incGapconfdi)cur|Just(DecGapid)<-fromMessagem=Just$Gaps(incGapconfd(-i))cur|otherwise=NothingapplyGaps::Gapsa->Rectangle->RectangleapplyGapsgsr=foldrapplyGapr(activeGapsgs)whereapplyGap(U,z)(Rectanglexywh)=Rectanglex(y+fiz)w(h-fiz)applyGap(D,z)(Rectanglexywh)=Rectanglexyw(h-fiz)applyGap(L,z)(Rectanglexywh)=Rectangle(x+fiz)y(w-fiz)happlyGap(R,z)(Rectanglexywh)=Rectanglexy(w-fiz)hactiveGaps::Gapsa->GapSpecactiveGaps(Gapsconfcur)=filter((`elem`cur).fst)conftoggleGaps::GapSpec->[Direction2D]->[Direction2D]toggleGapsconf[]=mapfstconftoggleGaps__=[]toggleGap::GapSpec->[Direction2D]->Direction2D->[Direction2D]toggleGapconfcurd|d`elem`cur=deletedcur|d`elem`(mapfstconf)=d:cur|otherwise=curincGap::GapSpec->Direction2D->Int->GapSpecincGapgsdi=map(\(dir,j)->ifdir==dthen(dir,max(j+i)0)else(dir,j))gsfi::(Numb,Integrala)=>a->bfi=fromIntegral-- | Add togglable manual gaps to a layout.gaps::GapSpec-- ^ The gaps to allow, paired with their initial sizes.->la-- ^ The layout to modify.->ModifiedLayoutGapslagapsg=ModifiedLayout(Gapsg(mapfstg))