aboutsummaryrefslogtreecommitdiffstats
path: root/ConstrainedResize.hs
diff options
context:
space:
mode:
authorDougal Stanton <dougal@dougalstanton.net>2007-10-19 19:35:08 +0200
committerDougal Stanton <dougal@dougalstanton.net>2007-10-19 19:35:08 +0200
commit293b6edc3abfe9dfbb40a85a9e360ac1feb6016e (patch)
treee73d3ed6447e30a8d6495e6873296a4a89cffb8e /ConstrainedResize.hs
parentcc249928fc54e3e86c360a523958ba39a9437dff (diff)
downloadXMonadContrib-293b6edc3abfe9dfbb40a85a9e360ac1feb6016e.tar.gz
XMonadContrib-293b6edc3abfe9dfbb40a85a9e360ac1feb6016e.tar.xz
XMonadContrib-293b6edc3abfe9dfbb40a85a9e360ac1feb6016e.zip
Add ConstrainedResize module
Constrain the aspect ratio of floated windows by holding down shift darcs-hash:20071019173508-1b04a-2554bbd0f1cf36ebfe187f7a1863e80fe6eda9c6.gz
Diffstat (limited to 'ConstrainedResize.hs')
-rw-r--r--ConstrainedResize.hs54
1 files changed, 54 insertions, 0 deletions
diff --git a/ConstrainedResize.hs b/ConstrainedResize.hs
new file mode 100644
index 0000000..7a553aa
--- /dev/null
+++ b/ConstrainedResize.hs
@@ -0,0 +1,54 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : XMonadContrib.ConstrainedResize
+-- Copyright : (c) Dougal Stanton
+-- License : BSD3-style (see LICENSE)
+--
+-- Maintainer : <dougal@dougalstanton.net>
+-- Stability : unstable
+-- Portability : unportable
+--
+-- Lets you constrain the aspect ratio of a floating
+-- window by holding shift while you resize.
+--
+-- Useful for making a nice circular XClock window.
+--
+-----------------------------------------------------------------------------
+
+module XMonadContrib.ConstrainedResize (
+ -- * Usage
+ -- $usage
+ XMonadContrib.ConstrainedResize.mouseResizeWindow
+) where
+
+import XMonad
+import Operations
+import Graphics.X11.Xlib
+import Graphics.X11.Xlib.Extras
+
+-- $usage
+-- Put something like this in your Config.hs file:
+--
+-- > import qualified XMonadContrib.ConstrainedResize as Sqr
+-- > mouseBindings = M.fromList
+-- > [ ...
+-- > , ((modMask, button3), (\w -> focus w >> Sqr.mouseResizeWindow w False))
+-- > , ((modMask .|. shiftMask, button3), (\w -> focus w >> Sqr.mouseResizeWindow w True )) ]
+
+-- %import qualified XMonadContrib.ConstrainedResize as Sqr
+-- %mousebind , ((modMask, button3), (\\w -> focus w >> Sqr.mouseResizeWindow w False))
+
+-- | Resize (floating) window with optional aspect ratio constraints.
+mouseResizeWindow :: Window -> Bool -> X ()
+mouseResizeWindow w c = whenX (isClient w) $ withDisplay $ \d -> do
+ io $ raiseWindow d w
+ wa <- io $ getWindowAttributes d w
+ sh <- io $ getWMNormalHints d w
+ io $ warpPointer d none w 0 0 0 0 (fromIntegral (wa_width wa)) (fromIntegral (wa_height wa))
+ mouseDrag (\ex ey -> do
+ let x = ex - fromIntegral (wa_x wa)
+ y = ey - fromIntegral (wa_y wa)
+ sz = if c then (max x y, max x y) else (x,y)
+ io $ resizeWindow d w `uncurry`
+ applySizeHints sh sz)
+ (float w)