{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, PatternGuards #-}
module XMonad.Layout.MouseResizableTile (
mouseResizableTile,
mouseResizableTileMirrored,
MRTMessage (ShrinkSlave, ExpandSlave, SetMasterFraction, SetLeftSlaveFraction, SetRightSlaveFraction),
nmaster,
masterFrac,
slaveFrac,
fracIncrement,
isMirrored,
draggerType,
DraggerType (..),
MouseResizableTile,
) where
import XMonad hiding (tile, splitVertically, splitHorizontallyBy)
import XMonad.Prelude
import qualified XMonad.StackSet as W
import XMonad.Util.XUtils
import Graphics.X11 as X
data MRTMessage = SetMasterFraction Rational
| SetLeftSlaveFraction Int Rational
| SetRightSlaveFraction Int Rational
| ShrinkSlave
| ExpandSlave
instance Message MRTMessage
data DraggerInfo = MasterDragger Position Rational
| LeftSlaveDragger Position Rational Int
| RightSlaveDragger Position Rational Int
deriving (Int -> DraggerInfo -> ShowS
[DraggerInfo] -> ShowS
DraggerInfo -> String
(Int -> DraggerInfo -> ShowS)
-> (DraggerInfo -> String)
-> ([DraggerInfo] -> ShowS)
-> Show DraggerInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DraggerInfo -> ShowS
showsPrec :: Int -> DraggerInfo -> ShowS
$cshow :: DraggerInfo -> String
show :: DraggerInfo -> String
$cshowList :: [DraggerInfo] -> ShowS
showList :: [DraggerInfo] -> ShowS
Show, ReadPrec [DraggerInfo]
ReadPrec DraggerInfo
Int -> ReadS DraggerInfo
ReadS [DraggerInfo]
(Int -> ReadS DraggerInfo)
-> ReadS [DraggerInfo]
-> ReadPrec DraggerInfo
-> ReadPrec [DraggerInfo]
-> Read DraggerInfo
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS DraggerInfo
readsPrec :: Int -> ReadS DraggerInfo
$creadList :: ReadS [DraggerInfo]
readList :: ReadS [DraggerInfo]
$creadPrec :: ReadPrec DraggerInfo
readPrec :: ReadPrec DraggerInfo
$creadListPrec :: ReadPrec [DraggerInfo]
readListPrec :: ReadPrec [DraggerInfo]
Read)
type DraggerWithRect = (Rectangle, Glyph, DraggerInfo)
type DraggerWithWin = (Window, DraggerInfo)
data DraggerType = FixedDragger
{ DraggerType -> Word32
gapWidth :: Dimension
, DraggerType -> Word32
draggerWidth :: Dimension
}
| BordersDragger
deriving (Int -> DraggerType -> ShowS
[DraggerType] -> ShowS
DraggerType -> String
(Int -> DraggerType -> ShowS)
-> (DraggerType -> String)
-> ([DraggerType] -> ShowS)
-> Show DraggerType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DraggerType -> ShowS
showsPrec :: Int -> DraggerType -> ShowS
$cshow :: DraggerType -> String
show :: DraggerType -> String
$cshowList :: [DraggerType] -> ShowS
showList :: [DraggerType] -> ShowS
Show, ReadPrec [DraggerType]
ReadPrec DraggerType
Int -> ReadS DraggerType
ReadS [DraggerType]
(Int -> ReadS DraggerType)
-> ReadS [DraggerType]
-> ReadPrec DraggerType
-> ReadPrec [DraggerType]
-> Read DraggerType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS DraggerType
readsPrec :: Int -> ReadS DraggerType
$creadList :: ReadS [DraggerType]
readList :: ReadS [DraggerType]
$creadPrec :: ReadPrec DraggerType
readPrec :: ReadPrec DraggerType
$creadListPrec :: ReadPrec [DraggerType]
readListPrec :: ReadPrec [DraggerType]
Read)
type DraggerGeometry = (Position, Dimension, Position, Dimension)
data MouseResizableTile a = MRT { forall a. MouseResizableTile a -> Int
nmaster :: Int,
forall a. MouseResizableTile a -> Ratio Integer
masterFrac :: Rational,
forall a. MouseResizableTile a -> Ratio Integer
slaveFrac :: Rational,
forall a. MouseResizableTile a -> Ratio Integer
fracIncrement :: Rational,
forall a. MouseResizableTile a -> [Ratio Integer]
leftFracs :: [Rational],
forall a. MouseResizableTile a -> [Ratio Integer]
rightFracs :: [Rational],
forall a. MouseResizableTile a -> [DraggerWithWin]
draggers :: [DraggerWithWin],
forall a. MouseResizableTile a -> DraggerType
draggerType :: DraggerType,
forall a. MouseResizableTile a -> Int
focusPos :: Int,
forall a. MouseResizableTile a -> Int
numWindows :: Int,
forall a. MouseResizableTile a -> Bool
isMirrored :: Bool
} deriving (Int -> MouseResizableTile a -> ShowS
[MouseResizableTile a] -> ShowS
MouseResizableTile a -> String
(Int -> MouseResizableTile a -> ShowS)
-> (MouseResizableTile a -> String)
-> ([MouseResizableTile a] -> ShowS)
-> Show (MouseResizableTile a)
forall a. Int -> MouseResizableTile a -> ShowS
forall a. [MouseResizableTile a] -> ShowS
forall a. MouseResizableTile a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> MouseResizableTile a -> ShowS
showsPrec :: Int -> MouseResizableTile a -> ShowS
$cshow :: forall a. MouseResizableTile a -> String
show :: MouseResizableTile a -> String
$cshowList :: forall a. [MouseResizableTile a] -> ShowS
showList :: [MouseResizableTile a] -> ShowS
Show, ReadPrec [MouseResizableTile a]
ReadPrec (MouseResizableTile a)
Int -> ReadS (MouseResizableTile a)
ReadS [MouseResizableTile a]
(Int -> ReadS (MouseResizableTile a))
-> ReadS [MouseResizableTile a]
-> ReadPrec (MouseResizableTile a)
-> ReadPrec [MouseResizableTile a]
-> Read (MouseResizableTile a)
forall a. ReadPrec [MouseResizableTile a]
forall a. ReadPrec (MouseResizableTile a)
forall a. Int -> ReadS (MouseResizableTile a)
forall a. ReadS [MouseResizableTile a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Int -> ReadS (MouseResizableTile a)
readsPrec :: Int -> ReadS (MouseResizableTile a)
$creadList :: forall a. ReadS [MouseResizableTile a]
readList :: ReadS [MouseResizableTile a]
$creadPrec :: forall a. ReadPrec (MouseResizableTile a)
readPrec :: ReadPrec (MouseResizableTile a)
$creadListPrec :: forall a. ReadPrec [MouseResizableTile a]
readListPrec :: ReadPrec [MouseResizableTile a]
Read)
mouseResizableTile :: MouseResizableTile a
mouseResizableTile :: forall a. MouseResizableTile a
mouseResizableTile = Int
-> Ratio Integer
-> Ratio Integer
-> Ratio Integer
-> [Ratio Integer]
-> [Ratio Integer]
-> [DraggerWithWin]
-> DraggerType
-> Int
-> Int
-> Bool
-> MouseResizableTile a
forall a.
Int
-> Ratio Integer
-> Ratio Integer
-> Ratio Integer
-> [Ratio Integer]
-> [Ratio Integer]
-> [DraggerWithWin]
-> DraggerType
-> Int
-> Int
-> Bool
-> MouseResizableTile a
MRT Int
1 Ratio Integer
0.5 Ratio Integer
0.5 Ratio Integer
0.03 [] [] [] (Word32 -> Word32 -> DraggerType
FixedDragger Word32
6 Word32
6) Int
0 Int
0 Bool
False
mouseResizableTileMirrored :: MouseResizableTile a
mouseResizableTileMirrored :: forall a. MouseResizableTile a
mouseResizableTileMirrored = MouseResizableTile (ZonkAny 0)
forall a. MouseResizableTile a
mouseResizableTile { isMirrored = True }
instance LayoutClass MouseResizableTile Window where
doLayout :: MouseResizableTile Word64
-> Rectangle
-> Stack Word64
-> X ([(Word64, Rectangle)], Maybe (MouseResizableTile Word64))
doLayout MouseResizableTile Word64
st Rectangle
sr (W.Stack Word64
w [Word64]
l [Word64]
r) = do
drg <- DraggerType -> X DraggerGeometry
draggerGeometry (DraggerType -> X DraggerGeometry)
-> DraggerType -> X DraggerGeometry
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64 -> DraggerType
forall a. MouseResizableTile a -> DraggerType
draggerType MouseResizableTile Word64
st
let wins = [Word64] -> [Word64]
forall a. [a] -> [a]
reverse [Word64]
l [Word64] -> [Word64] -> [Word64]
forall a. [a] -> [a] -> [a]
++ Word64
w Word64 -> [Word64] -> [Word64]
forall a. a -> [a] -> [a]
: [Word64]
r
num = [Word64] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Word64]
wins
sr' = Rectangle -> Rectangle -> Rectangle
forall {p}. p -> p -> p
mirrorAdjust Rectangle
sr (Rectangle -> Rectangle
mirrorRect Rectangle
sr)
(rects, preparedDraggers) = tile (nmaster st) (masterFrac st)
(leftFracs st ++ repeat (slaveFrac st))
(rightFracs st ++ repeat (slaveFrac st)) sr' num drg
rects' = (Rectangle -> Rectangle) -> [Rectangle] -> [Rectangle]
forall a b. (a -> b) -> [a] -> [b]
map ((Rectangle -> Rectangle)
-> (Rectangle -> Rectangle) -> Rectangle -> Rectangle
forall {p}. p -> p -> p
mirrorAdjust Rectangle -> Rectangle
forall a. a -> a
id Rectangle -> Rectangle
mirrorRect (Rectangle -> Rectangle)
-> (Rectangle -> Rectangle) -> Rectangle -> Rectangle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rectangle -> Rectangle -> Rectangle
sanitizeRectangle Rectangle
sr') [Rectangle]
rects
mapM_ deleteDragger $ draggers st
(draggerWrs, newDraggers) <- mapAndUnzipM
(createDragger sr . adjustForMirror (isMirrored st))
preparedDraggers
return (draggerWrs ++ zip wins rects', Just $ st { draggers = newDraggers,
focusPos = length l,
numWindows = length wins })
where
mirrorAdjust :: p -> p -> p
mirrorAdjust p
a p
b = if MouseResizableTile Word64 -> Bool
forall a. MouseResizableTile a -> Bool
isMirrored MouseResizableTile Word64
st
then p
b
else p
a
handleMessage :: MouseResizableTile Word64
-> SomeMessage -> X (Maybe (MouseResizableTile Word64))
handleMessage MouseResizableTile Word64
st SomeMessage
m
| Just (IncMasterN Int
d) <- SomeMessage -> Maybe IncMasterN
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m =
Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64)))
-> Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a. a -> Maybe a
Just (MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64))
-> MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64
st { nmaster = max 0 (nmaster st + d) }
| Just Resize
Shrink <- SomeMessage -> Maybe Resize
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m =
Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64)))
-> Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a. a -> Maybe a
Just (MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64))
-> MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64
st { masterFrac = max 0 (masterFrac st - fracIncrement st) }
| Just Resize
Expand <- SomeMessage -> Maybe Resize
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m =
Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64)))
-> Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a. a -> Maybe a
Just (MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64))
-> MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64
st { masterFrac = min 1 (masterFrac st + fracIncrement st) }
| Just MRTMessage
ShrinkSlave <- SomeMessage -> Maybe MRTMessage
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m =
Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64)))
-> Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a. a -> Maybe a
Just (MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64))
-> MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64
-> Ratio Integer -> MouseResizableTile Word64
forall a.
MouseResizableTile a -> Ratio Integer -> MouseResizableTile a
modifySlave MouseResizableTile Word64
st (- MouseResizableTile Word64 -> Ratio Integer
forall a. MouseResizableTile a -> Ratio Integer
fracIncrement MouseResizableTile Word64
st)
| Just MRTMessage
ExpandSlave <- SomeMessage -> Maybe MRTMessage
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m =
Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64)))
-> Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a. a -> Maybe a
Just (MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64))
-> MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64
-> Ratio Integer -> MouseResizableTile Word64
forall a.
MouseResizableTile a -> Ratio Integer -> MouseResizableTile a
modifySlave MouseResizableTile Word64
st (MouseResizableTile Word64 -> Ratio Integer
forall a. MouseResizableTile a -> Ratio Integer
fracIncrement MouseResizableTile Word64
st)
| Just (SetMasterFraction Ratio Integer
f) <- SomeMessage -> Maybe MRTMessage
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m =
Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64)))
-> Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a. a -> Maybe a
Just (MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64))
-> MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64
st { masterFrac = max 0 (min 1 f) }
| Just (SetLeftSlaveFraction Int
pos Ratio Integer
f) <- SomeMessage -> Maybe MRTMessage
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m =
Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64)))
-> Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a. a -> Maybe a
Just (MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64))
-> MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64
st { leftFracs = replaceAtPos (slaveFrac st)
(leftFracs st) pos (max 0 (min 1 f)) }
| Just (SetRightSlaveFraction Int
pos Ratio Integer
f) <- SomeMessage -> Maybe MRTMessage
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m =
Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64)))
-> Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a. a -> Maybe a
Just (MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64))
-> MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64
st { rightFracs = replaceAtPos (slaveFrac st)
(rightFracs st) pos (max 0 (min 1 f)) }
| Just Event
e <- SomeMessage -> Maybe Event
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m :: Maybe Event = [DraggerWithWin] -> Bool -> Event -> X ()
handleResize (MouseResizableTile Word64 -> [DraggerWithWin]
forall a. MouseResizableTile a -> [DraggerWithWin]
draggers MouseResizableTile Word64
st) (MouseResizableTile Word64 -> Bool
forall a. MouseResizableTile a -> Bool
isMirrored MouseResizableTile Word64
st) Event
e X ()
-> X (Maybe (MouseResizableTile Word64))
-> X (Maybe (MouseResizableTile Word64))
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (MouseResizableTile Word64)
forall a. Maybe a
Nothing
| Just LayoutMessages
Hide <- SomeMessage -> Maybe LayoutMessages
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m = X ()
releaseResources X ()
-> X (Maybe (MouseResizableTile Word64))
-> X (Maybe (MouseResizableTile Word64))
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a. a -> Maybe a
Just (MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64))
-> MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64
st { draggers = [] })
| Just LayoutMessages
ReleaseResources <- SomeMessage -> Maybe LayoutMessages
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m = X ()
releaseResources X ()
-> X (Maybe (MouseResizableTile Word64))
-> X (Maybe (MouseResizableTile Word64))
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a. a -> Maybe a
Just (MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64))
-> MouseResizableTile Word64 -> Maybe (MouseResizableTile Word64)
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64
st { draggers = [] })
where releaseResources :: X ()
releaseResources = (DraggerWithWin -> X ()) -> [DraggerWithWin] -> X ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ DraggerWithWin -> X ()
deleteDragger ([DraggerWithWin] -> X ()) -> [DraggerWithWin] -> X ()
forall a b. (a -> b) -> a -> b
$ MouseResizableTile Word64 -> [DraggerWithWin]
forall a. MouseResizableTile a -> [DraggerWithWin]
draggers MouseResizableTile Word64
st
handleMessage MouseResizableTile Word64
_ SomeMessage
_ = Maybe (MouseResizableTile Word64)
-> X (Maybe (MouseResizableTile Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (MouseResizableTile Word64)
forall a. Maybe a
Nothing
description :: MouseResizableTile Word64 -> String
description MouseResizableTile Word64
st = ShowS
mirror String
"MouseResizableTile"
where mirror :: ShowS
mirror = if MouseResizableTile Word64 -> Bool
forall a. MouseResizableTile a -> Bool
isMirrored MouseResizableTile Word64
st then (String
"Mirror " String -> ShowS
forall a. [a] -> [a] -> [a]
++) else ShowS
forall a. a -> a
id
draggerGeometry :: DraggerType -> X DraggerGeometry
draggerGeometry :: DraggerType -> X DraggerGeometry
draggerGeometry (FixedDragger Word32
g Word32
d) =
DraggerGeometry -> X DraggerGeometry
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Int32) -> Word32 -> Int32
forall a b. (a -> b) -> a -> b
$ Word32
g Word32 -> Word32 -> Word32
forall a. Integral a => a -> a -> a
`div` Word32
2, Word32
g, Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Int32) -> Word32 -> Int32
forall a b. (a -> b) -> a -> b
$ Word32
d Word32 -> Word32 -> Word32
forall a. Integral a => a -> a -> a
`div` Word32
2, Word32
d)
draggerGeometry DraggerType
BordersDragger = do
wins <- (XState
-> StackSet String (Layout Word64) Word64 ScreenId ScreenDetail)
-> X (StackSet String (Layout Word64) Word64 ScreenId ScreenDetail)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState
-> StackSet String (Layout Word64) Word64 ScreenId ScreenDetail
windowset
w <- case W.peek wins of
Just Word64
win -> Word64 -> X Word32
getBorderWidth Word64
win
Maybe Word64
_ -> (XConf -> Word32) -> X Word32
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (XConfig Layout -> Word32
forall (l :: * -> *). XConfig l -> Word32
borderWidth (XConfig Layout -> Word32)
-> (XConf -> XConfig Layout) -> XConf -> Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XConf -> XConfig Layout
config)
return (0, 0, fromIntegral w, 2*w)
getBorderWidth :: Window -> X Dimension
getBorderWidth :: Word64 -> X Word32
getBorderWidth Word64
win = do
d <- (XConf -> Display) -> X Display
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Display
display
(_,_,_,_,_,w,_) <- io $ X.getGeometry d win
return w
adjustForMirror :: Bool -> DraggerWithRect -> DraggerWithRect
adjustForMirror :: Bool -> DraggerWithRect -> DraggerWithRect
adjustForMirror Bool
False DraggerWithRect
dragger = DraggerWithRect
dragger
adjustForMirror Bool
True (Rectangle
draggerRect, Glyph
draggerCursor, DraggerInfo
draggerInfo) =
(Rectangle -> Rectangle
mirrorRect Rectangle
draggerRect, Glyph
draggerCursor', DraggerInfo
draggerInfo)
where
draggerCursor' :: Glyph
draggerCursor' = if Glyph
draggerCursor Glyph -> Glyph -> Bool
forall a. Eq a => a -> a -> Bool
== Glyph
xC_sb_h_double_arrow
then Glyph
xC_sb_v_double_arrow
else Glyph
xC_sb_h_double_arrow
modifySlave :: MouseResizableTile a -> Rational -> MouseResizableTile a
modifySlave :: forall a.
MouseResizableTile a -> Ratio Integer -> MouseResizableTile a
modifySlave MouseResizableTile a
st Ratio Integer
delta =
let pos :: Int
pos = MouseResizableTile a -> Int
forall a. MouseResizableTile a -> Int
focusPos MouseResizableTile a
st
num :: Int
num = MouseResizableTile a -> Int
forall a. MouseResizableTile a -> Int
numWindows MouseResizableTile a
st
nmaster' :: Int
nmaster' = MouseResizableTile a -> Int
forall a. MouseResizableTile a -> Int
nmaster MouseResizableTile a
st
leftFracs' :: [Ratio Integer]
leftFracs' = MouseResizableTile a -> [Ratio Integer]
forall a. MouseResizableTile a -> [Ratio Integer]
leftFracs MouseResizableTile a
st
rightFracs' :: [Ratio Integer]
rightFracs' = MouseResizableTile a -> [Ratio Integer]
forall a. MouseResizableTile a -> [Ratio Integer]
rightFracs MouseResizableTile a
st
slFrac :: Ratio Integer
slFrac = MouseResizableTile a -> Ratio Integer
forall a. MouseResizableTile a -> Ratio Integer
slaveFrac MouseResizableTile a
st
draggersLeft :: Int
draggersLeft = Int
nmaster' Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
draggersRight :: Int
draggersRight = (Int
num Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nmaster') Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
in if Int
pos Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
nmaster'
then if Int
draggersLeft Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
then let draggerPos :: Int
draggerPos = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min (Int
draggersLeft Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int
pos
oldFraction :: Ratio Integer
oldFraction = ([Ratio Integer]
leftFracs' [Ratio Integer] -> [Ratio Integer] -> [Ratio Integer]
forall a. [a] -> [a] -> [a]
++ Ratio Integer -> [Ratio Integer]
forall a. a -> [a]
repeat Ratio Integer
slFrac) [Ratio Integer] -> Int -> Ratio Integer
forall a. HasCallStack => [a] -> Int -> a
!! Int
draggerPos
in MouseResizableTile a
st { leftFracs = replaceAtPos slFrac leftFracs' draggerPos
(max 0 (min 1 (oldFraction + delta))) }
else MouseResizableTile a
st
else if Int
draggersRight Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
then let draggerPos :: Int
draggerPos = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min (Int
draggersRight Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (Int
pos Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nmaster')
oldFraction :: Ratio Integer
oldFraction = ([Ratio Integer]
rightFracs' [Ratio Integer] -> [Ratio Integer] -> [Ratio Integer]
forall a. [a] -> [a] -> [a]
++ Ratio Integer -> [Ratio Integer]
forall a. a -> [a]
repeat Ratio Integer
slFrac) [Ratio Integer] -> Int -> Ratio Integer
forall a. HasCallStack => [a] -> Int -> a
!! Int
draggerPos
in MouseResizableTile a
st { rightFracs = replaceAtPos slFrac rightFracs' draggerPos
(max 0 (min 1 (oldFraction + delta))) }
else MouseResizableTile a
st
replaceAtPos :: (Num t, Eq t) => Rational -> [Rational] -> t -> Rational -> [Rational]
replaceAtPos :: forall t.
(Num t, Eq t) =>
Ratio Integer
-> [Ratio Integer] -> t -> Ratio Integer -> [Ratio Integer]
replaceAtPos Ratio Integer
_ [] t
0 Ratio Integer
x' = [Ratio Integer
x']
replaceAtPos Ratio Integer
d [] t
pos Ratio Integer
x' = Ratio Integer
d Ratio Integer -> [Ratio Integer] -> [Ratio Integer]
forall a. a -> [a] -> [a]
: Ratio Integer
-> [Ratio Integer] -> t -> Ratio Integer -> [Ratio Integer]
forall t.
(Num t, Eq t) =>
Ratio Integer
-> [Ratio Integer] -> t -> Ratio Integer -> [Ratio Integer]
replaceAtPos Ratio Integer
d [] (t
pos t -> t -> t
forall a. Num a => a -> a -> a
- t
1) Ratio Integer
x'
replaceAtPos Ratio Integer
_ (Ratio Integer
_:[Ratio Integer]
xs) t
0 Ratio Integer
x' = Ratio Integer
x' Ratio Integer -> [Ratio Integer] -> [Ratio Integer]
forall a. a -> [a] -> [a]
: [Ratio Integer]
xs
replaceAtPos Ratio Integer
d (Ratio Integer
x:[Ratio Integer]
xs) t
pos Ratio Integer
x' = Ratio Integer
x Ratio Integer -> [Ratio Integer] -> [Ratio Integer]
forall a. a -> [a] -> [a]
: Ratio Integer
-> [Ratio Integer] -> t -> Ratio Integer -> [Ratio Integer]
forall t.
(Num t, Eq t) =>
Ratio Integer
-> [Ratio Integer] -> t -> Ratio Integer -> [Ratio Integer]
replaceAtPos Ratio Integer
d [Ratio Integer]
xs (t
pos t -> t -> t
forall a. Num a => a -> a -> a
-t
1 ) Ratio Integer
x'
sanitizeRectangle :: Rectangle -> Rectangle -> Rectangle
sanitizeRectangle :: Rectangle -> Rectangle -> Rectangle
sanitizeRectangle (Rectangle Int32
sx Int32
sy Word32
swh Word32
sht) (Rectangle Int32
x Int32
y Word32
wh Word32
ht) =
Int32 -> Int32 -> Word32 -> Word32 -> Rectangle
Rectangle (Int32 -> Int32 -> Int32 -> Int32
forall a. Ord a => a -> a -> a -> a
within Int32
0 (Int32
sx Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
swh) Int32
x) (Int32 -> Int32 -> Int32 -> Int32
forall a. Ord a => a -> a -> a -> a
within Int32
0 (Int32
sy Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
sht) Int32
y)
(Word32 -> Word32 -> Word32 -> Word32
forall a. Ord a => a -> a -> a -> a
within Word32
1 Word32
swh Word32
wh) (Word32 -> Word32 -> Word32 -> Word32
forall a. Ord a => a -> a -> a -> a
within Word32
1 Word32
sht Word32
ht)
within :: (Ord a) => a -> a -> a -> a
within :: forall a. Ord a => a -> a -> a -> a
within a
low a
high a
a = a -> a -> a
forall a. Ord a => a -> a -> a
max a
low (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ a -> a -> a
forall a. Ord a => a -> a -> a
min a
high a
a
tile :: Int -> Rational -> [Rational] -> [Rational] -> Rectangle -> Int -> DraggerGeometry -> ([Rectangle], [DraggerWithRect])
tile :: Int
-> Ratio Integer
-> [Ratio Integer]
-> [Ratio Integer]
-> Rectangle
-> Int
-> DraggerGeometry
-> ([Rectangle], [DraggerWithRect])
tile Int
nmaster' Ratio Integer
masterFrac' [Ratio Integer]
leftFracs' [Ratio Integer]
rightFracs' Rectangle
sr Int
num DraggerGeometry
drg
| Int
num Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
nmaster' = [Ratio Integer]
-> Rectangle
-> Bool
-> Int
-> DraggerGeometry
-> ([Rectangle], [DraggerWithRect])
forall r.
RealFrac r =>
[r]
-> Rectangle
-> Bool
-> Int
-> DraggerGeometry
-> ([Rectangle], [DraggerWithRect])
splitVertically (Int -> [Ratio Integer] -> [Ratio Integer]
forall a. Int -> [a] -> [a]
take (Int
num Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [Ratio Integer]
leftFracs') Rectangle
sr Bool
True Int
0 DraggerGeometry
drg
| Int
nmaster' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = [Ratio Integer]
-> Rectangle
-> Bool
-> Int
-> DraggerGeometry
-> ([Rectangle], [DraggerWithRect])
forall r.
RealFrac r =>
[r]
-> Rectangle
-> Bool
-> Int
-> DraggerGeometry
-> ([Rectangle], [DraggerWithRect])
splitVertically (Int -> [Ratio Integer] -> [Ratio Integer]
forall a. Int -> [a] -> [a]
take (Int
num Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [Ratio Integer]
rightFracs') Rectangle
sr Bool
False Int
0 DraggerGeometry
drg
| Bool
otherwise = ([Rectangle]
leftRects [Rectangle] -> [Rectangle] -> [Rectangle]
forall a. [a] -> [a] -> [a]
++ [Rectangle]
rightRects, DraggerWithRect
masterDragger DraggerWithRect -> [DraggerWithRect] -> [DraggerWithRect]
forall a. a -> [a] -> [a]
: [DraggerWithRect]
leftDraggers [DraggerWithRect] -> [DraggerWithRect] -> [DraggerWithRect]
forall a. [a] -> [a] -> [a]
++ [DraggerWithRect]
rightDraggers)
where ((Rectangle
sr1, Rectangle
sr2), DraggerWithRect
masterDragger) = Ratio Integer
-> Rectangle
-> DraggerGeometry
-> ((Rectangle, Rectangle), DraggerWithRect)
forall r.
RealFrac r =>
r
-> Rectangle
-> DraggerGeometry
-> ((Rectangle, Rectangle), DraggerWithRect)
splitHorizontallyBy Ratio Integer
masterFrac' Rectangle
sr DraggerGeometry
drg
([Rectangle]
leftRects, [DraggerWithRect]
leftDraggers) = [Ratio Integer]
-> Rectangle
-> Bool
-> Int
-> DraggerGeometry
-> ([Rectangle], [DraggerWithRect])
forall r.
RealFrac r =>
[r]
-> Rectangle
-> Bool
-> Int
-> DraggerGeometry
-> ([Rectangle], [DraggerWithRect])
splitVertically (Int -> [Ratio Integer] -> [Ratio Integer]
forall a. Int -> [a] -> [a]
take (Int
nmaster' Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [Ratio Integer]
leftFracs') Rectangle
sr1 Bool
True Int
0 DraggerGeometry
drg
([Rectangle]
rightRects, [DraggerWithRect]
rightDraggers) = [Ratio Integer]
-> Rectangle
-> Bool
-> Int
-> DraggerGeometry
-> ([Rectangle], [DraggerWithRect])
forall r.
RealFrac r =>
[r]
-> Rectangle
-> Bool
-> Int
-> DraggerGeometry
-> ([Rectangle], [DraggerWithRect])
splitVertically (Int -> [Ratio Integer] -> [Ratio Integer]
forall a. Int -> [a] -> [a]
take (Int
num Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nmaster' Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [Ratio Integer]
rightFracs') Rectangle
sr2 Bool
False Int
0 DraggerGeometry
drg
splitVertically :: RealFrac r => [r] -> Rectangle -> Bool -> Int -> DraggerGeometry -> ([Rectangle], [DraggerWithRect])
splitVertically :: forall r.
RealFrac r =>
[r]
-> Rectangle
-> Bool
-> Int
-> DraggerGeometry
-> ([Rectangle], [DraggerWithRect])
splitVertically [] Rectangle
r Bool
_ Int
_ DraggerGeometry
_ = ([Rectangle
r], [])
splitVertically (r
f:[r]
fx) (Rectangle Int32
sx Int32
sy Word32
sw Word32
sh) Bool
isLeft Int
num drg :: DraggerGeometry
drg@(Int32
drOff, Word32
drSz, Int32
drOff2, Word32
drSz2) =
let nextRect :: Rectangle
nextRect = Int32 -> Int32 -> Word32 -> Word32 -> Rectangle
Rectangle Int32
sx Int32
sy Word32
sw (Word32 -> Rectangle) -> Word32 -> Rectangle
forall a b. (a -> b) -> a -> b
$ Word32
smallh Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32 -> Word32 -> Word32
forall a. Integral a => a -> a -> a
div Word32
drSz Word32
2
([Rectangle]
otherRects, [DraggerWithRect]
otherDragger) = [r]
-> Rectangle
-> Bool
-> Int
-> DraggerGeometry
-> ([Rectangle], [DraggerWithRect])
forall r.
RealFrac r =>
[r]
-> Rectangle
-> Bool
-> Int
-> DraggerGeometry
-> ([Rectangle], [DraggerWithRect])
splitVertically [r]
fx
(Int32 -> Int32 -> Word32 -> Word32 -> Rectangle
Rectangle Int32
sx (Int32
sy Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
smallh Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Int32
drOff)
Word32
sw (Word32
sh Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
smallh Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32 -> Word32 -> Word32
forall a. Integral a => a -> a -> a
div Word32
drSz Word32
2))
Bool
isLeft (Int
num Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) DraggerGeometry
drg
draggerRect :: Rectangle
draggerRect = Int32 -> Int32 -> Word32 -> Word32 -> Rectangle
Rectangle Int32
sx (Int32
sy Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
smallh Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
- Int32
drOff2) Word32
sw Word32
drSz2
draggerInfo :: DraggerInfo
draggerInfo = if Bool
isLeft
then Int32 -> Ratio Integer -> Int -> DraggerInfo
LeftSlaveDragger Int32
sy (Word32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
sh) Int
num
else Int32 -> Ratio Integer -> Int -> DraggerInfo
RightSlaveDragger Int32
sy (Word32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
sh) Int
num
nextDragger :: DraggerWithRect
nextDragger = (Rectangle
draggerRect, Glyph
xC_sb_v_double_arrow, DraggerInfo
draggerInfo)
in (Rectangle
nextRect Rectangle -> [Rectangle] -> [Rectangle]
forall a. a -> [a] -> [a]
: [Rectangle]
otherRects, DraggerWithRect
nextDragger DraggerWithRect -> [DraggerWithRect] -> [DraggerWithRect]
forall a. a -> [a] -> [a]
: [DraggerWithRect]
otherDragger)
where smallh :: Word32
smallh = r -> Word32
forall b. Integral b => r -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor (r -> Word32) -> r -> Word32
forall a b. (a -> b) -> a -> b
$ Word32 -> r
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
sh r -> r -> r
forall a. Num a => a -> a -> a
* r
f
splitHorizontallyBy :: RealFrac r => r -> Rectangle -> DraggerGeometry -> ((Rectangle, Rectangle), DraggerWithRect)
splitHorizontallyBy :: forall r.
RealFrac r =>
r
-> Rectangle
-> DraggerGeometry
-> ((Rectangle, Rectangle), DraggerWithRect)
splitHorizontallyBy r
f (Rectangle Int32
sx Int32
sy Word32
sw Word32
sh) (Int32
drOff, Word32
drSz, Int32
drOff2, Word32
drSz2) =
((Rectangle
leftHalf, Rectangle
rightHalf), (Rectangle
draggerRect, Glyph
xC_sb_h_double_arrow, DraggerInfo
draggerInfo))
where leftw :: Word32
leftw = r -> Word32
forall b. Integral b => r -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor (r -> Word32) -> r -> Word32
forall a b. (a -> b) -> a -> b
$ Word32 -> r
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
sw r -> r -> r
forall a. Num a => a -> a -> a
* r
f
leftHalf :: Rectangle
leftHalf = Int32 -> Int32 -> Word32 -> Word32 -> Rectangle
Rectangle Int32
sx Int32
sy (Word32
leftw Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
drSz Word32 -> Word32 -> Word32
forall a. Integral a => a -> a -> a
`div` Word32
2) Word32
sh
rightHalf :: Rectangle
rightHalf = Int32 -> Int32 -> Word32 -> Word32 -> Rectangle
Rectangle (Int32
sx Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
leftw Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Int32
drOff) Int32
sy
(Word32
sw Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
leftw Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
drSz Word32 -> Word32 -> Word32
forall a. Integral a => a -> a -> a
`div` Word32
2) Word32
sh
draggerRect :: Rectangle
draggerRect = Int32 -> Int32 -> Word32 -> Word32 -> Rectangle
Rectangle (Int32
sx Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
leftw Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
- Int32
drOff2) Int32
sy Word32
drSz2 Word32
sh
draggerInfo :: DraggerInfo
draggerInfo = Int32 -> Ratio Integer -> DraggerInfo
MasterDragger Int32
sx (Word32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
sw)
createDragger :: Rectangle -> DraggerWithRect -> X ((Window, Rectangle), DraggerWithWin)
createDragger :: Rectangle
-> DraggerWithRect -> X ((Word64, Rectangle), DraggerWithWin)
createDragger Rectangle
sr (Rectangle
draggerRect, Glyph
draggerCursor, DraggerInfo
draggerInfo) = do
let draggerRect' :: Rectangle
draggerRect' = Rectangle -> Rectangle -> Rectangle
sanitizeRectangle Rectangle
sr Rectangle
draggerRect
draggerWin <- Glyph -> Rectangle -> X Word64
createInputWindow Glyph
draggerCursor Rectangle
draggerRect'
return ((draggerWin, draggerRect'), (draggerWin, draggerInfo))
deleteDragger :: DraggerWithWin -> X ()
deleteDragger :: DraggerWithWin -> X ()
deleteDragger (Word64
draggerWin, DraggerInfo
_) = Word64 -> X ()
deleteWindow Word64
draggerWin
handleResize :: [DraggerWithWin] -> Bool -> Event -> X ()
handleResize :: [DraggerWithWin] -> Bool -> Event -> X ()
handleResize [DraggerWithWin]
draggers' Bool
isM ButtonEvent { ev_window :: Event -> Word64
ev_window = Word64
ew, ev_event_type :: Event -> Word32
ev_event_type = Word32
et }
| Word32
et Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
buttonPress, Just DraggerInfo
x <- Word64 -> [DraggerWithWin] -> Maybe DraggerInfo
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Word64
ew [DraggerWithWin]
draggers' = case DraggerInfo
x of
MasterDragger Int32
lb Ratio Integer
r -> ((Int32 -> Int32 -> Int32) -> Int32 -> Int32 -> Int32)
-> Int32 -> Ratio Integer -> (Ratio Integer -> MRTMessage) -> X ()
forall {a} {t} {t} {t}.
(Message a, Fractional t, Integral t) =>
((t -> t -> t) -> Int32 -> Int32 -> t)
-> t -> t -> (t -> a) -> X ()
mouseDrag' (Int32 -> Int32 -> Int32) -> Int32 -> Int32 -> Int32
forall a. a -> a
id Int32
lb Ratio Integer
r Ratio Integer -> MRTMessage
SetMasterFraction
LeftSlaveDragger Int32
lb Ratio Integer
r Int
num -> ((Int32 -> Int32 -> Int32) -> Int32 -> Int32 -> Int32)
-> Int32 -> Ratio Integer -> (Ratio Integer -> MRTMessage) -> X ()
forall {a} {t} {t} {t}.
(Message a, Fractional t, Integral t) =>
((t -> t -> t) -> Int32 -> Int32 -> t)
-> t -> t -> (t -> a) -> X ()
mouseDrag' (Int32 -> Int32 -> Int32) -> Int32 -> Int32 -> Int32
forall a b c. (a -> b -> c) -> b -> a -> c
flip Int32
lb Ratio Integer
r (Int -> Ratio Integer -> MRTMessage
SetLeftSlaveFraction Int
num)
RightSlaveDragger Int32
lb Ratio Integer
r Int
num -> ((Int32 -> Int32 -> Int32) -> Int32 -> Int32 -> Int32)
-> Int32 -> Ratio Integer -> (Ratio Integer -> MRTMessage) -> X ()
forall {a} {t} {t} {t}.
(Message a, Fractional t, Integral t) =>
((t -> t -> t) -> Int32 -> Int32 -> t)
-> t -> t -> (t -> a) -> X ()
mouseDrag' (Int32 -> Int32 -> Int32) -> Int32 -> Int32 -> Int32
forall a b c. (a -> b -> c) -> b -> a -> c
flip Int32
lb Ratio Integer
r (Int -> Ratio Integer -> MRTMessage
SetRightSlaveFraction Int
num)
where
chooseAxis :: Bool -> p -> p -> p
chooseAxis Bool
isM' p
axis1 p
axis2 = if Bool
isM' then p
axis2 else p
axis1
mouseDrag' :: ((t -> t -> t) -> Int32 -> Int32 -> t)
-> t -> t -> (t -> a) -> X ()
mouseDrag' (t -> t -> t) -> Int32 -> Int32 -> t
flp t
lowerBound t
range t -> a
msg = ((Int32 -> Int32 -> X ()) -> X () -> X ())
-> X () -> (Int32 -> Int32 -> X ()) -> X ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Int32 -> Int32 -> X ()) -> X () -> X ()
mouseDrag (() -> X ()
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) ((Int32 -> Int32 -> X ()) -> X ())
-> (Int32 -> Int32 -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \Int32
x Int32
y -> do
let axis :: t
axis = (t -> t -> t) -> Int32 -> Int32 -> t
flp (Bool -> t -> t -> t
forall {p}. Bool -> p -> p -> p
chooseAxis Bool
isM) Int32
x Int32
y
fraction :: t
fraction = t -> t
forall a b. (Integral a, Num b) => a -> b
fromIntegral (t
axis t -> t -> t
forall a. Num a => a -> a -> a
- t
lowerBound) t -> t -> t
forall a. Fractional a => a -> a -> a
/ t
range
a -> X ()
forall a. Message a => a -> X ()
sendMessage (t -> a
msg t
fraction)
handleResize [DraggerWithWin]
_ Bool
_ Event
_ = () -> X ()
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
createInputWindow :: Glyph -> Rectangle -> X Window
createInputWindow :: Glyph -> Rectangle -> X Word64
createInputWindow Glyph
cursorGlyph Rectangle
r = (Display -> X Word64) -> X Word64
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X Word64) -> X Word64)
-> (Display -> X Word64) -> X Word64
forall a b. (a -> b) -> a -> b
$ \Display
d -> do
win <- Display -> Rectangle -> X Word64
mkInputWindow Display
d Rectangle
r
io $ selectInput d win (exposureMask .|. buttonPressMask)
cursor <- io $ createFontCursor d cursorGlyph
io $ defineCursor d win cursor
io $ freeCursor d cursor
showWindow win
return win
mkInputWindow :: Display -> Rectangle -> X Window
mkInputWindow :: Display -> Rectangle -> X Word64
mkInputWindow Display
d (Rectangle Int32
x Int32
y Word32
w Word32
h) = do
rw <- (XConf -> Word64) -> X Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Word64
theRoot
let screen = Display -> Screen
defaultScreenOfDisplay Display
d
visual = Screen -> Visual
defaultVisualOfScreen Screen
screen
attrmask = Word64
cWOverrideRedirect
io $ allocaSetWindowAttributes $
\Ptr SetWindowAttributes
attributes -> do
Ptr SetWindowAttributes -> Bool -> IO ()
set_override_redirect Ptr SetWindowAttributes
attributes Bool
True
Display
-> Word64
-> Int32
-> Int32
-> Word32
-> Word32
-> CInt
-> CInt
-> CInt
-> Visual
-> Word64
-> Ptr SetWindowAttributes
-> IO Word64
createWindow Display
d Word64
rw Int32
x Int32
y Word32
w Word32
h CInt
0 CInt
0 CInt
inputOnly Visual
visual Word64
attrmask Ptr SetWindowAttributes
attributes