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) (Ratio Integer
0, Ratio Integer
0) Window
win
Direction2D
D -> ChangeDim -> G -> Window -> X ()
keysResizeWindow (Int
0, Int
delta) (Ratio Integer
0, Ratio Integer
0) Window
win
Direction2D
R -> ChangeDim -> G -> Window -> X ()
keysResizeWindow (Int
delta, Int
0) (Ratio Integer
0, Ratio Integer
0) Window
win
Direction2D
L -> ChangeDim -> G -> Window -> X ()
keysResizeWindow (-Int
delta, Int
0) (Ratio Integer
0, Ratio Integer
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) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (Display -> X ()) -> X ()
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X ()) -> X ()) -> (Display -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \Display
d ->
Display -> Window -> (WindowAttributes -> X ()) -> X ()
withWindowAttributes Display
d Window
w ((WindowAttributes -> X ()) -> X ())
-> (WindowAttributes -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \WindowAttributes
wa -> do
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> Int32 -> Int32 -> IO ()
moveWindow Display
d Window
w (Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fi (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fi (WindowAttributes -> CInt
wa_x WindowAttributes
wa) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
dx))
(Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fi (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fi (WindowAttributes -> CInt
wa_y WindowAttributes
wa) Int -> Int -> Int
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 (Int32
x,Int32
y) (Ratio Integer
gx, Ratio Integer
gy) Window
w = X Bool -> X () -> X ()
whenX (Window -> X Bool
isClient Window
w) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (Display -> X ()) -> X ()
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X ()) -> X ()) -> (Display -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \Display
d ->
Display -> Window -> (WindowAttributes -> X ()) -> X ()
withWindowAttributes Display
d Window
w ((WindowAttributes -> X ()) -> X ())
-> (WindowAttributes -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \WindowAttributes
wa -> do
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> Int32 -> Int32 -> IO ()
moveWindow Display
d Window
w (Int32
x Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
- Ratio Integer -> Int32
forall b. Integral b => Ratio Integer -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Ratio Integer
gx Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* CInt -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fi (WindowAttributes -> CInt
wa_width WindowAttributes
wa)))
(Int32
y Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
- Ratio Integer -> Int32
forall b. Integral b => Ratio Integer -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Ratio Integer
gy Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* CInt -> Ratio Integer
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 = (SizeHints -> P -> D -> ChangeDim -> G -> (P, D))
-> ChangeDim -> G -> Window -> X ()
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 = (SizeHints -> P -> D -> ChangeDim -> D -> (P, D))
-> ChangeDim -> D -> Window -> X ()
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 (Int32
x,Int32
y) (Word32
w,Word32
h) (Int
dx,Int
dy) (Word32
ax, Word32
ay) = ((Ratio Integer -> Int32
forall b. Integral b => Ratio Integer -> b
forall a b. (RealFrac a, Integral b) => a -> b
round Ratio Integer
nx, Ratio Integer -> Int32
forall b. Integral b => Ratio Integer -> b
forall a b. (RealFrac a, Integral b) => a -> b
round Ratio Integer
ny), (Word32
nw, Word32
nh))
where
(Word32
nw, Word32
nh) = SizeHints -> ChangeDim -> D
forall a. Integral a => SizeHints -> (a, a) -> D
applySizeHintsContents SizeHints
sh (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fi Word32
w Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
dx, Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fi Word32
h Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
dy)
nx :: Rational
nx :: Ratio Integer
nx = Word32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fi (Word32
ax Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
* Word32
w Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ Word32
nw Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
* (Int32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fi Int32
x Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
ax)) Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/ Word32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fi Word32
w
ny :: Rational
ny :: Ratio Integer
ny = Word32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fi (Word32
ay Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
* Word32
h Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
+ Word32
nh Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
* (Int32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fi Int32
y Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
ay)) Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/ Word32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fi Word32
h
keysResizeWindow' :: SizeHints -> P -> D -> ChangeDim -> G -> (P,D)
keysResizeWindow' :: SizeHints -> P -> D -> ChangeDim -> G -> (P, D)
keysResizeWindow' SizeHints
sh (Int32
x,Int32
y) (Word32
w,Word32
h) (Int
dx,Int
dy) (Ratio Integer
gx, Ratio Integer
gy) = ((Int32
nx, Int32
ny), (Word32
nw, Word32
nh))
where
(Word32
nw, Word32
nh) = SizeHints -> ChangeDim -> D
forall a. Integral a => SizeHints -> (a, a) -> D
applySizeHintsContents SizeHints
sh (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fi Word32
w Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
dx, Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fi Word32
h Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
dy)
nx :: Int32
nx = Ratio Integer -> Int32
forall b. Integral b => Ratio Integer -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Ratio Integer -> Int32) -> Ratio Integer -> Int32
forall a b. (a -> b) -> a -> b
$ Int32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fi Int32
x Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
+ Ratio Integer
gx Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* Word32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fi Word32
w Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
- Ratio Integer
gx Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* Word32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fi Word32
nw
ny :: Int32
ny = Ratio Integer -> Int32
forall b. Integral b => Ratio Integer -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (Ratio Integer -> Int32) -> Ratio Integer -> Int32
forall a b. (a -> b) -> a -> b
$ Int32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fi Int32
y Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
+ Ratio Integer
gy Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* Word32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fi Word32
h Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
- Ratio Integer
gy Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* Word32 -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fi Word32
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) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (Display -> X ()) -> X ()
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X ()) -> X ()) -> (Display -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \Display
d ->
Display -> Window -> (WindowAttributes -> X ()) -> X ()
withWindowAttributes Display
d Window
w ((WindowAttributes -> X ()) -> X ())
-> (WindowAttributes -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \WindowAttributes
wa -> do
sh <- IO SizeHints -> X SizeHints
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO SizeHints -> X SizeHints) -> IO SizeHints -> X SizeHints
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO SizeHints
getWMNormalHints Display
d Window
w
let wa_dim = (CInt -> Word32
forall a b. (Integral a, Num b) => a -> b
fi (CInt -> Word32) -> CInt -> Word32
forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_width WindowAttributes
wa, CInt -> Word32
forall a b. (Integral a, Num b) => a -> b
fi (CInt -> Word32) -> CInt -> Word32
forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_height WindowAttributes
wa)
wa_pos = (CInt -> Int32
forall a b. (Integral a, Num b) => a -> b
fi (CInt -> Int32) -> CInt -> Int32
forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_x WindowAttributes
wa, CInt -> Int32
forall a b. (Integral a, Num b) => a -> b
fi (CInt -> Int32) -> CInt -> Int32
forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_y WindowAttributes
wa)
(wn_pos, wn_dim) = f sh wa_pos wa_dim move resize
io $ resizeWindow d w `uncurry` wn_dim
io $ moveWindow d w `uncurry` wn_pos
float w