module XMonad.Actions.FloatKeys (
keysMoveWindow,
keysMoveWindowTo,
keysResizeWindow,
keysAbsResizeWindow,
directionMoveWindow,
directionResizeWindow,
Direction2D(..),
P, G, ChangeDim
) where
import XMonad
import XMonad.Prelude (fi)
import XMonad.Util.Types
directionMoveWindow :: Int -> Direction2D -> Window -> X ()
directionMoveWindow :: Int -> Direction2D -> Window -> X ()
directionMoveWindow Int
delta Direction2D
dir Window
win = case Direction2D
dir of
Direction2D
U -> ChangeDim -> Window -> X ()
keysMoveWindow (Int
0, -Int
delta) Window
win
Direction2D
D -> ChangeDim -> Window -> X ()
keysMoveWindow (Int
0, Int
delta) Window
win
Direction2D
R -> ChangeDim -> Window -> X ()
keysMoveWindow (Int
delta, Int
0) Window
win
Direction2D
L -> ChangeDim -> Window -> X ()
keysMoveWindow (-Int
delta, Int
0) Window
win
directionResizeWindow :: Int -> Direction2D -> Window -> X ()
directionResizeWindow :: Int -> Direction2D -> Window -> X ()
directionResizeWindow Int
delta Direction2D
dir Window
win = case Direction2D
dir of
Direction2D
U -> ChangeDim -> G -> Window -> X ()
keysResizeWindow (Int
0, -Int
delta) (Rational
0, Rational
0) Window
win
Direction2D
D -> ChangeDim -> G -> Window -> X ()
keysResizeWindow (Int
0, Int
delta) (Rational
0, Rational
0) Window
win
Direction2D
R -> ChangeDim -> G -> Window -> X ()
keysResizeWindow (Int
delta, Int
0) (Rational
0, Rational
0) Window
win
Direction2D
L -> ChangeDim -> G -> Window -> X ()
keysResizeWindow (-Int
delta, Int
0) (Rational
0, Rational
0) Window
win
keysMoveWindow :: ChangeDim -> Window -> X ()
keysMoveWindow :: ChangeDim -> Window -> X ()
keysMoveWindow (Int
dx,Int
dy) Window
w = X Bool -> X () -> X ()
whenX (Window -> X Bool
isClient Window
w) forall a b. (a -> b) -> a -> b
$ forall a. (Display -> X a) -> X a
withDisplay forall a b. (a -> b) -> a -> b
$ \Display
d ->
Display -> Window -> (WindowAttributes -> X ()) -> X ()
withWindowAttributes Display
d Window
w forall a b. (a -> b) -> a -> b
$ \WindowAttributes
wa -> do
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io forall a b. (a -> b) -> a -> b
$ Display -> Window -> Position -> Position -> IO ()
moveWindow Display
d Window
w (forall a b. (Integral a, Num b) => a -> b
fi (forall a b. (Integral a, Num b) => a -> b
fi (WindowAttributes -> CInt
wa_x WindowAttributes
wa) forall a. Num a => a -> a -> a
+ Int
dx))
(forall a b. (Integral a, Num b) => a -> b
fi (forall a b. (Integral a, Num b) => a -> b
fi (WindowAttributes -> CInt
wa_y WindowAttributes
wa) forall a. Num a => a -> a -> a
+ Int
dy))
Window -> X ()
float Window
w
keysMoveWindowTo :: P -> G -> Window -> X ()
keysMoveWindowTo :: P -> G -> Window -> X ()
keysMoveWindowTo (Position
x,Position
y) (Rational
gx, Rational
gy) Window
w = X Bool -> X () -> X ()
whenX (Window -> X Bool
isClient Window
w) forall a b. (a -> b) -> a -> b
$ forall a. (Display -> X a) -> X a
withDisplay forall a b. (a -> b) -> a -> b
$ \Display
d ->
Display -> Window -> (WindowAttributes -> X ()) -> X ()
withWindowAttributes Display
d Window
w forall a b. (a -> b) -> a -> b
$ \WindowAttributes
wa -> do
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io forall a b. (a -> b) -> a -> b
$ Display -> Window -> Position -> Position -> IO ()
moveWindow Display
d Window
w (Position
x forall a. Num a => a -> a -> a
- forall a b. (RealFrac a, Integral b) => a -> b
round (Rational
gx forall a. Num a => a -> a -> a
* forall a b. (Integral a, Num b) => a -> b
fi (WindowAttributes -> CInt
wa_width WindowAttributes
wa)))
(Position
y forall a. Num a => a -> a -> a
- forall a b. (RealFrac a, Integral b) => a -> b
round (Rational
gy forall a. Num a => a -> a -> a
* forall a b. (Integral a, Num b) => a -> b
fi (WindowAttributes -> CInt
wa_height WindowAttributes
wa)))
Window -> X ()
float Window
w
type G = (Rational, Rational)
type P = (Position, Position)
type ChangeDim = (Int, Int)
keysResizeWindow :: ChangeDim -> G -> Window -> X ()
keysResizeWindow :: ChangeDim -> G -> Window -> X ()
keysResizeWindow = forall a b.
(SizeHints -> P -> D -> a -> b -> (P, D))
-> a -> b -> Window -> X ()
keysMoveResize SizeHints -> P -> D -> ChangeDim -> G -> (P, D)
keysResizeWindow'
keysAbsResizeWindow :: ChangeDim -> D -> Window -> X ()
keysAbsResizeWindow :: ChangeDim -> D -> Window -> X ()
keysAbsResizeWindow = forall a b.
(SizeHints -> P -> D -> a -> b -> (P, D))
-> a -> b -> Window -> X ()
keysMoveResize SizeHints -> P -> D -> ChangeDim -> D -> (P, D)
keysAbsResizeWindow'
keysAbsResizeWindow' :: SizeHints -> P -> D -> ChangeDim -> D -> (P,D)
keysAbsResizeWindow' :: SizeHints -> P -> D -> ChangeDim -> D -> (P, D)
keysAbsResizeWindow' SizeHints
sh (Position
x,Position
y) (Dimension
w,Dimension
h) (Int
dx,Int
dy) (Dimension
ax, Dimension
ay) = ((forall a b. (RealFrac a, Integral b) => a -> b
round Rational
nx, forall a b. (RealFrac a, Integral b) => a -> b
round Rational
ny), (Dimension
nw, Dimension
nh))
where
(Dimension
nw, Dimension
nh) = forall a. Integral a => SizeHints -> (a, a) -> D
applySizeHintsContents SizeHints
sh (forall a b. (Integral a, Num b) => a -> b
fi Dimension
w forall a. Num a => a -> a -> a
+ Int
dx, forall a b. (Integral a, Num b) => a -> b
fi Dimension
h forall a. Num a => a -> a -> a
+ Int
dy)
nx :: Rational
nx :: Rational
nx = forall a b. (Integral a, Num b) => a -> b
fi (Dimension
ax forall a. Num a => a -> a -> a
* Dimension
w forall a. Num a => a -> a -> a
+ Dimension
nw forall a. Num a => a -> a -> a
* (forall a b. (Integral a, Num b) => a -> b
fi Position
x forall a. Num a => a -> a -> a
- Dimension
ax)) forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fi Dimension
w
ny :: Rational
ny :: Rational
ny = forall a b. (Integral a, Num b) => a -> b
fi (Dimension
ay forall a. Num a => a -> a -> a
* Dimension
h forall a. Num a => a -> a -> a
+ Dimension
nh forall a. Num a => a -> a -> a
* (forall a b. (Integral a, Num b) => a -> b
fi Position
y forall a. Num a => a -> a -> a
- Dimension
ay)) forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fi Dimension
h
keysResizeWindow' :: SizeHints -> P -> D -> ChangeDim -> G -> (P,D)
keysResizeWindow' :: SizeHints -> P -> D -> ChangeDim -> G -> (P, D)
keysResizeWindow' SizeHints
sh (Position
x,Position
y) (Dimension
w,Dimension
h) (Int
dx,Int
dy) (Rational
gx, Rational
gy) = ((Position
nx, Position
ny), (Dimension
nw, Dimension
nh))
where
(Dimension
nw, Dimension
nh) = forall a. Integral a => SizeHints -> (a, a) -> D
applySizeHintsContents SizeHints
sh (forall a b. (Integral a, Num b) => a -> b
fi Dimension
w forall a. Num a => a -> a -> a
+ Int
dx, forall a b. (Integral a, Num b) => a -> b
fi Dimension
h forall a. Num a => a -> a -> a
+ Int
dy)
nx :: Position
nx = forall a b. (RealFrac a, Integral b) => a -> b
round forall a b. (a -> b) -> a -> b
$ forall a b. (Integral a, Num b) => a -> b
fi Position
x forall a. Num a => a -> a -> a
+ Rational
gx forall a. Num a => a -> a -> a
* forall a b. (Integral a, Num b) => a -> b
fi Dimension
w forall a. Num a => a -> a -> a
- Rational
gx forall a. Num a => a -> a -> a
* forall a b. (Integral a, Num b) => a -> b
fi Dimension
nw
ny :: Position
ny = forall a b. (RealFrac a, Integral b) => a -> b
round forall a b. (a -> b) -> a -> b
$ forall a b. (Integral a, Num b) => a -> b
fi Position
y forall a. Num a => a -> a -> a
+ Rational
gy forall a. Num a => a -> a -> a
* forall a b. (Integral a, Num b) => a -> b
fi Dimension
h forall a. Num a => a -> a -> a
- Rational
gy forall a. Num a => a -> a -> a
* forall a b. (Integral a, Num b) => a -> b
fi Dimension
nh
keysMoveResize :: (SizeHints -> P -> D -> a -> b -> (P,D)) -> a -> b -> Window -> X ()
keysMoveResize :: forall a b.
(SizeHints -> P -> D -> a -> b -> (P, D))
-> a -> b -> Window -> X ()
keysMoveResize SizeHints -> P -> D -> a -> b -> (P, D)
f a
move b
resize Window
w = X Bool -> X () -> X ()
whenX (Window -> X Bool
isClient Window
w) forall a b. (a -> b) -> a -> b
$ forall a. (Display -> X a) -> X a
withDisplay forall a b. (a -> b) -> a -> b
$ \Display
d ->
Display -> Window -> (WindowAttributes -> X ()) -> X ()
withWindowAttributes Display
d Window
w forall a b. (a -> b) -> a -> b
$ \WindowAttributes
wa -> do
SizeHints
sh <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
io forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO SizeHints
getWMNormalHints Display
d Window
w
let wa_dim :: D
wa_dim = (forall a b. (Integral a, Num b) => a -> b
fi forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_width WindowAttributes
wa, forall a b. (Integral a, Num b) => a -> b
fi forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_height WindowAttributes
wa)
wa_pos :: P
wa_pos = (forall a b. (Integral a, Num b) => a -> b
fi forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_x WindowAttributes
wa, forall a b. (Integral a, Num b) => a -> b
fi forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_y WindowAttributes
wa)
(P
wn_pos, D
wn_dim) = SizeHints -> P -> D -> a -> b -> (P, D)
f SizeHints
sh P
wa_pos D
wa_dim a
move b
resize
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io forall a b. (a -> b) -> a -> b
$ Display -> Window -> Dimension -> Dimension -> IO ()
resizeWindow Display
d Window
w forall a b c. (a -> b -> c) -> (a, b) -> c
`uncurry` D
wn_dim
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io forall a b. (a -> b) -> a -> b
$ Display -> Window -> Position -> Position -> IO ()
moveWindow Display
d Window
w forall a b c. (a -> b -> c) -> (a, b) -> c
`uncurry` P
wn_pos
Window -> X ()
float Window
w