module XMonad.Actions.Warp (
banish,
banishScreen,
Corner(..),
warpToScreen,
warpToWindow
) where
import XMonad.Prelude
import XMonad
import XMonad.StackSet as W
data Corner = UpperLeft | UpperRight | LowerLeft | LowerRight
banish :: Corner -> X ()
banish :: Corner -> X ()
banish Corner
direction = case Corner
direction of
Corner
LowerRight -> Ratio Integer -> Ratio Integer -> X ()
warpToWindow Ratio Integer
1 Ratio Integer
1
Corner
LowerLeft -> Ratio Integer -> Ratio Integer -> X ()
warpToWindow Ratio Integer
0 Ratio Integer
1
Corner
UpperLeft -> Ratio Integer -> Ratio Integer -> X ()
warpToWindow Ratio Integer
0 Ratio Integer
0
Corner
UpperRight -> Ratio Integer -> Ratio Integer -> X ()
warpToWindow Ratio Integer
1 Ratio Integer
0
banishScreen :: Corner -> X ()
banishScreen :: Corner -> X ()
banishScreen Corner
direction = case Corner
direction of
Corner
LowerRight -> Ratio Integer -> Ratio Integer -> X ()
warpToCurrentScreen Ratio Integer
1 Ratio Integer
1
Corner
LowerLeft -> Ratio Integer -> Ratio Integer -> X ()
warpToCurrentScreen Ratio Integer
0 Ratio Integer
1
Corner
UpperLeft -> Ratio Integer -> Ratio Integer -> X ()
warpToCurrentScreen Ratio Integer
0 Ratio Integer
0
Corner
UpperRight -> Ratio Integer -> Ratio Integer -> X ()
warpToCurrentScreen Ratio Integer
1 Ratio Integer
0
where
warpToCurrentScreen :: Ratio Integer -> Ratio Integer -> X ()
warpToCurrentScreen Ratio Integer
h Ratio Integer
v =
do ws <- (XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X (StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
windowset
warpToScreen (W.screen $ current ws) h v
windows (const ws)
fraction :: (Integral a, Integral b) => Rational -> a -> b
fraction :: forall a b. (Integral a, Integral b) => Ratio Integer -> a -> b
fraction Ratio Integer
f a
x = Ratio Integer -> b
forall b. Integral b => Ratio Integer -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor (Ratio Integer
f Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* a -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
x)
warp :: Window -> Position -> Position -> X ()
warp :: Window -> Int32 -> Int32 -> X ()
warp Window
w Int32
x Int32
y = (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 -> 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
-> Window
-> Int32
-> Int32
-> Word32
-> Word32
-> Int32
-> Int32
-> IO ()
warpPointer Display
d Window
none Window
w Int32
0 Int32
0 Word32
0 Word32
0 Int32
x Int32
y
warpToWindow :: Rational -> Rational -> X ()
warpToWindow :: Ratio Integer -> Ratio Integer -> X ()
warpToWindow Ratio Integer
h Ratio Integer
v = (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 -> (Window -> X ()) -> X ()
withFocused ((Window -> X ()) -> X ()) -> (Window -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \Window
w ->
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 ->
Window -> Int32 -> Int32 -> X ()
warp Window
w (Ratio Integer -> CInt -> Int32
forall a b. (Integral a, Integral b) => Ratio Integer -> a -> b
fraction Ratio Integer
h (WindowAttributes -> CInt
wa_width WindowAttributes
wa)) (Ratio Integer -> CInt -> Int32
forall a b. (Integral a, Integral b) => Ratio Integer -> a -> b
fraction Ratio Integer
v (WindowAttributes -> CInt
wa_height WindowAttributes
wa))
warpToScreen :: ScreenId -> Rational -> Rational -> X ()
warpToScreen :: ScreenId -> Ratio Integer -> Ratio Integer -> X ()
warpToScreen ScreenId
n Ratio Integer
h Ratio Integer
v = do
root <- (XConf -> Window) -> X Window
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Window
theRoot
StackSet{current = x, visible = xs} <- gets windowset
whenJust (fmap (screenRect . W.screenDetail) . find ((n==) . W.screen) $ x : xs)
$ \Rectangle
r ->
Window -> Int32 -> Int32 -> X ()
warp Window
root (Rectangle -> Int32
rect_x Rectangle
r Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Ratio Integer -> Word32 -> Int32
forall a b. (Integral a, Integral b) => Ratio Integer -> a -> b
fraction Ratio Integer
h (Rectangle -> Word32
rect_width Rectangle
r))
(Rectangle -> Int32
rect_y Rectangle
r Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Ratio Integer -> Word32 -> Int32
forall a b. (Integral a, Integral b) => Ratio Integer -> a -> b
fraction Ratio Integer
v (Rectangle -> Word32
rect_height Rectangle
r))