mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-01 20:51:52 -07:00
FlexibleResize - Resize from edge, don't move adjust at opposite edge
When resizing other corners than bottom-right, instead of adjusting to even columns/rows on the opposite side to it the same way as if resizing was made from the bottom right. Also add the possibility to add an area in the middle of an edge where only that edge is resized, not the closest corner.
This commit is contained in:
@@ -15,7 +15,8 @@
|
|||||||
module XMonad.Actions.FlexibleResize (
|
module XMonad.Actions.FlexibleResize (
|
||||||
-- * Usage
|
-- * Usage
|
||||||
-- $usage
|
-- $usage
|
||||||
XMonad.Actions.FlexibleResize.mouseResizeWindow
|
XMonad.Actions.FlexibleResize.mouseResizeWindow,
|
||||||
|
XMonad.Actions.FlexibleResize.mouseResizeEdgeWindow
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import XMonad
|
import XMonad
|
||||||
@@ -35,33 +36,46 @@ import Foreign.C.Types
|
|||||||
|
|
||||||
-- | Resize a floating window from whichever corner the mouse is
|
-- | Resize a floating window from whichever corner the mouse is
|
||||||
-- closest to.
|
-- closest to.
|
||||||
mouseResizeWindow :: Window -> X ()
|
mouseResizeWindow
|
||||||
mouseResizeWindow w = whenX (isClient w) $ withDisplay $ \d -> do
|
:: Window -- ^ The window to resize.
|
||||||
|
-> X ()
|
||||||
|
mouseResizeWindow = mouseResizeEdgeWindow 0
|
||||||
|
|
||||||
|
|
||||||
|
-- | Resize a floating window from whichever corner or edge the mouse is
|
||||||
|
-- closest to.
|
||||||
|
mouseResizeEdgeWindow
|
||||||
|
:: Rational -- ^ The size of the area where only one edge is resized.
|
||||||
|
-> Window -- ^ The window to resize.
|
||||||
|
-> X ()
|
||||||
|
mouseResizeEdgeWindow edge w = whenX (isClient w) $ withDisplay $ \d -> do
|
||||||
io $ raiseWindow d w
|
io $ raiseWindow d w
|
||||||
wa <- io $ getWindowAttributes d w
|
wa <- io $ getWindowAttributes d w
|
||||||
sh <- io $ getWMNormalHints d w
|
sh <- io $ getWMNormalHints d w
|
||||||
(_, _, _, _, _, ix, iy, _) <- io $ queryPointer d w
|
(_, _, _, _, _, ix, iy, _) <- io $ queryPointer d w
|
||||||
let
|
let
|
||||||
[pos_x, pos_y, width, height] = map (fromIntegral . ($ wa)) [wa_x, wa_y, wa_width, wa_height]
|
[pos_x, pos_y, width, height] = map (fi . ($ wa)) [wa_x, wa_y, wa_width, wa_height]
|
||||||
west = firstHalf ix width
|
west = findPos ix width
|
||||||
north = firstHalf iy height
|
north = findPos iy height
|
||||||
(cx, fx, gx) = mkSel west width pos_x
|
(cx, fx, gx) = mkSel west width pos_x
|
||||||
(cy, fy, gy) = mkSel north height pos_y
|
(cy, fy, gy) = mkSel north height pos_y
|
||||||
io $ warpPointer d none w 0 0 0 0 cx cy
|
io $ warpPointer d none w 0 0 0 0 cx cy
|
||||||
mouseDrag (\ex ey -> do
|
mouseDrag (\ex ey -> do let (nw,nh) = applySizeHintsContents sh (gx ex, gy ey)
|
||||||
wa' <- io $ getWindowAttributes d w
|
io $ moveResizeWindow d w (fx nw) (fy nh) nw nh)
|
||||||
let [px, py] = map (fromIntegral . ($ wa')) [wa_x, wa_y]
|
|
||||||
io $ moveResizeWindow d w (fx px (fromIntegral ex))
|
|
||||||
(fy py (fromIntegral ey))
|
|
||||||
`uncurry` applySizeHintsContents sh (gx $ fromIntegral ex, gy $ fromIntegral ey))
|
|
||||||
(float w)
|
(float w)
|
||||||
where
|
where
|
||||||
firstHalf :: CInt -> Position -> Bool
|
findPos :: CInt -> Position -> Maybe Bool
|
||||||
firstHalf a b = fromIntegral a * 2 <= b
|
findPos m s = if p < 0.5 - edge/2
|
||||||
cfst = curry fst
|
then Just True
|
||||||
csnd = curry snd
|
else if p < 0.5 + edge/2
|
||||||
mkSel :: Bool -> Position -> Position -> (Position, a -> a -> a, CInt -> Position)
|
then Nothing
|
||||||
mkSel b k p =
|
else Just False
|
||||||
if b
|
where p = fi m / fi s
|
||||||
then (0, csnd, ((k + p) -) . fromIntegral)
|
mkSel :: Maybe Bool -> Position -> Position -> (Position, Dimension -> Position, Position -> Dimension)
|
||||||
else (k, cfst, subtract p . fromIntegral)
|
mkSel b k p = case b of
|
||||||
|
Just True -> (0, (fi k + fi p -).fi, (fi k + fi p -).fi)
|
||||||
|
Nothing -> (k `div` 2, const p, const $ fi k)
|
||||||
|
Just False -> (k, const p, subtract (fi p) . fi)
|
||||||
|
|
||||||
|
fi :: (Num b, Integral a) => a -> b
|
||||||
|
fi = fromIntegral
|
||||||
|
Reference in New Issue
Block a user