From ad9639398dfb0a960f7e4a2ee9bc9f5c3819806f Mon Sep 17 00:00:00 2001 From: mail Date: Tue, 23 Oct 2007 00:01:32 +0200 Subject: STRUT aware gap toggling (clean patch) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this patch, ManageDocks would only set the gap according to a window’s STRUT when the window is first mapped. This information would then get lost when the user toggle the gap. Now, when the user toggles the Gap, all present windows are scanned for STRUT settings, and the gap is set accordingly. No need to manually configure the gap anymore. This is the same patch as before, but independant of the Hooks patches, and with more documentation. darcs-hash:20071022220132-c9905-fb953a07a9c15ed37a40b47d83763f434de47fcf.gz --- ManageDocks.hs | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/ManageDocks.hs b/ManageDocks.hs index 16015bd..13aa7db 100644 --- a/ManageDocks.hs +++ b/ManageDocks.hs @@ -12,16 +12,16 @@ -- layouts. It also detects window with STRUT set and modifies the -- gap accordingly. -- --- Cheveats: --- --- * Only acts on STRUT apps on creation, not if you move or close them --- --- * To reset the gap, press Mod-b twice and restart xmonad (Mod-q) +-- It also allows you to reset the gap to reflect the state of current STRUT +-- windows (for example, after you resized or closed a panel), and to toggle the Gap +-- in a STRUT-aware fashion. ----------------------------------------------------------------------------- module XMonadContrib.ManageDocks ( -- * Usage -- $usage manageDocksHook + ,resetGap + ,toggleGap ) where import Control.Monad.Reader @@ -30,7 +30,8 @@ import Operations import qualified StackSet as W import Graphics.X11.Xlib import Graphics.X11.Xlib.Extras -import Data.Word +import Data.Word (Word32) +import Data.Maybe (catMaybes) -- $usage -- Add the imports to your configuration file and add the mangeHook: @@ -40,10 +41,15 @@ import Data.Word -- > manageHook w _ _ _ = manageDocksHook w -- -- and comment out the default `manageHook _ _ _ _ = return id` line. +-- +-- Then you can bind resetGap or toggleGap as you wish: +-- +-- > , ((modMask, xK_b), toggleGap) -- %import XMonadContrib.ManageDocks -- %def -- comment out default manageHook definition above if you uncomment this: -- %def manageHook w _ _ _ = manageDocksHook w +-- %keybind , ((modMask, xK_b), toggleGap) -- | @@ -58,8 +64,8 @@ manageDocksHook w = do if isDock then do reveal w return (W.delete w) - else do - return id + else do + return id -- | -- Checks if a window is a DOCK window @@ -96,6 +102,32 @@ getProp a w = withDisplay $ \dpy -> io $ getWindowProperty32 dpy a w setGap :: (Int, Int, Int, Int) -> X () setGap gap = modifyGap (\_ -> max4 gap) + +-- | +-- Goes through the list of windows and find the gap so that all STRUT +-- settings are satisfied. +calcGap :: X (Int, Int, Int, Int) +calcGap = withDisplay $ \dpy -> do + rootw <- asks theRoot + -- We don’t keep track of dock like windows, so we find all of them here + (_,_,wins) <- io $ queryTree dpy rootw + struts <- catMaybes `fmap` mapM getStrut wins + return $ foldl max4 (0,0,0,0) struts + +-- | +-- Adjusts the gap to the STRUTs of all current Windows +resetGap :: X () +resetGap = do + newGap <- calcGap + modifyGap (\_ _ -> newGap) + +-- | +-- Removes the gap or, if already removed, sets the gap according to the windows’ STRUT +toggleGap :: X () +toggleGap = do + newGap <- calcGap + modifyGap (\_ old -> if old == (0,0,0,0) then newGap else (0,0,0,0)) + -- | -- Piecewise maximum of a 4-tuple of Ints max4 :: (Int, Int, Int, Int) -> (Int, Int, Int, Int) -> (Int, Int, Int, Int) -- cgit v1.2.3