<commit_before>-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.ConstrainedResize
-- Copyright   :  (c) <NAME>
-- License     :  BSD3-style (see LICENSE)
-- 
-- Maintainer  :  <<EMAIL>>
-- 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)
<commit_msg>Comments for ConstrainedResize<commit_after>-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.ConstrainedResize
-- Copyright   :  (c) <NAME>
-- License     :  BSD3-style (see LICENSE)
-- 
-- Maintainer  :  <<EMAIL>>
-- 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 )) ]
--
-- The line without the shiftMask replaces the standard mouse resize function call, so it's
-- not completely necessary but seems neater this way.

-- %import qualified XMonadContrib.ConstrainedResize as Sqr
-- %mousebind , ((modMask, button3), (\\w -> focus w >> Sqr.mouseResizeWindow w False))
-- %mousebind , ((modMask .|. shiftMask, button3), (\\w -> focus w >> Sqr.mouseResizeWindow w True))

-- | 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)

{'fraction_non_alphanumeric': 0.18360113421550095, 'fraction_numerical': 0.005907372400756144, 'mean_word_length': 1.8913934426229508, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4470497', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1238, 'n_words': 410}