aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter De Wachter <pdewacht@gmail.com>2007-06-04 21:27:53 +0200
committerPeter De Wachter <pdewacht@gmail.com>2007-06-04 21:27:53 +0200
commit78fff7fbb83f34b047c368fced0a5eb2efbfb6d1 (patch)
treeda1bd023682142585ab1b873b48af3ccb4fa029c
parentf2c9837e1b1f4d4e807545516fd3367746d5bbac (diff)
downloadxmonad-78fff7fbb83f34b047c368fced0a5eb2efbfb6d1.tar.gz
xmonad-78fff7fbb83f34b047c368fced0a5eb2efbfb6d1.tar.xz
xmonad-78fff7fbb83f34b047c368fced0a5eb2efbfb6d1.zip
size hints infrastructure
darcs-hash:20070604192753-06a25-20a4752a79da48c1f08b4a9556174c18928d844f.gz
-rw-r--r--Operations.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/Operations.hs b/Operations.hs
index 450e123..d35c20d 100644
--- a/Operations.hs
+++ b/Operations.hs
@@ -482,3 +482,36 @@ mouseResizeWindow w = withDisplay $ \d -> do
-- x <- f d w wa
-- mouseDrag $ \(_,_,_,ex,ey,_,_,_,_,_) -> g x ex ey d w wa
-- float w
+
+
+------------------------------------------------------------------------
+-- size hints
+
+-- | Reduce the dimensions if needed to comply to the given SizeHints.
+applySizeHints :: SizeHints -> (Dimension, Dimension) -> (Dimension, Dimension)
+applySizeHints sh =
+ maybe id applyMaxSizeHint (sh_max_size sh) .
+ maybe id (\(bw, bh) (w, h) -> (w+bw, h+bh)) (sh_base_size sh) .
+ maybe id applyResizeIncHint (sh_resize_inc sh) .
+ maybe id applyAspectHint (sh_aspect sh) .
+ maybe id (\(bw, bh) (w, h) -> (w-bw, h-bh)) (sh_base_size sh)
+
+-- | Reduce the dimensions so their aspect ratio falls between the two given aspect ratios.
+applyAspectHint :: ((Dimension, Dimension), (Dimension, Dimension)) -> (Dimension, Dimension) -> (Dimension, Dimension)
+applyAspectHint ((minx, miny), (maxx, maxy)) (w, h)
+ | or [minx < 1, miny < 1, maxx < 1, maxy < 1] = (w, h)
+ | w * maxy > h * maxx = (h * maxx `div` maxy, h)
+ | w * miny < h * minx = (w, w * miny `div` minx)
+ | otherwise = (w, h)
+
+-- | Reduce the dimensions so they are a multiple of the size increments.
+applyResizeIncHint :: (Dimension, Dimension) -> (Dimension, Dimension) -> (Dimension, Dimension)
+applyResizeIncHint (iw, ih) (w, h)
+ | iw > 0 && ih > 0 = (w - w `mod` iw, h - h `mod` ih)
+ | otherwise = (w, h)
+
+-- | Reduce the dimensions if they exceed the given maximum dimensions.
+applyMaxSizeHint :: (Dimension, Dimension) -> (Dimension, Dimension) -> (Dimension, Dimension)
+applyMaxSizeHint (maxw, maxh) (w, h)
+ | maxw > 0 && maxh > 0 = (min w maxw, min h maxh)
+ | otherwise = (w, h)