From 3ed85a9de0dd6a9b6184ec0af0d37af29f5bf3c3 Mon Sep 17 00:00:00 2001 From: Lukas Mai Date: Fri, 4 Apr 2008 23:56:15 +0200 Subject: XMonad.Operations: applySizeHint reshuffle Make applySizeHints take window borders into account. Move old functionality to applySizeHintsContents. Add new mkAdjust function that generates a custom autohinter for a window. darcs-hash:20080404215615-462cf-e6c1373d13ec4c6b0d675778125c75d76fbc896f --- XMonad/Operations.hs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'XMonad') diff --git a/XMonad/Operations.hs b/XMonad/Operations.hs index 7daf309..74505c3 100644 --- a/XMonad/Operations.hs +++ b/XMonad/Operations.hs @@ -479,8 +479,8 @@ mouseResizeWindow w = whenX (isClient w) $ withDisplay $ \d -> do io $ warpPointer d none w 0 0 0 0 (fromIntegral (wa_width wa)) (fromIntegral (wa_height wa)) mouseDrag (\ex ey -> do io $ resizeWindow d w `uncurry` - applySizeHints sh (ex - fromIntegral (wa_x wa), - ey - fromIntegral (wa_y wa))) + applySizeHintsContents sh (ex - fromIntegral (wa_x wa), + ey - fromIntegral (wa_y wa))) (float w) -- --------------------------------------------------------------------- @@ -488,10 +488,26 @@ mouseResizeWindow w = whenX (isClient w) $ withDisplay $ \d -> do type D = (Dimension, Dimension) +-- | Given a window, build an adjuster function that will reduce the given +-- dimensions according to the window's border width and size hints. +mkAdjust :: Window -> X (D -> D) +mkAdjust w = withDisplay $ \d -> liftIO $ do + sh <- getWMNormalHints d w + bw <- fmap (fromIntegral . wa_border_width) $ getWindowAttributes d w + return $ applySizeHints bw sh + +-- | Reduce the dimensions if needed to comply to the given SizeHints, taking +-- window borders into account. +applySizeHints :: Integral a => Dimension -> SizeHints -> (a, a) -> D +applySizeHints bw sh = + tmap (+ 2 * bw) . applySizeHintsContents sh . tmap (subtract $ 2 * fromIntegral bw) + where + tmap f (x, y) = (f x, f y) + -- | Reduce the dimensions if needed to comply to the given SizeHints. -applySizeHints :: Integral a => SizeHints -> (a,a) -> D -applySizeHints sh (w,h) = applySizeHints' sh (fromIntegral $ max 1 w, - fromIntegral $ max 1 h) +applySizeHintsContents :: Integral a => SizeHints -> (a, a) -> D +applySizeHintsContents sh (w, h) = + applySizeHints' sh (fromIntegral $ max 1 w, fromIntegral $ max 1 h) -- | XXX comment me applySizeHints' :: SizeHints -> D -> D -- cgit v1.2.3