module XMonad.Actions.TiledWindowDragging
(
dragWindow
)
where
import XMonad
import XMonad.Prelude
import qualified XMonad.StackSet as W
import XMonad.Layout.DraggingVisualizer
dragWindow :: Window -> X ()
dragWindow :: Word64 -> X ()
dragWindow Word64
window = X Bool -> X () -> X ()
whenX (Word64 -> X Bool
isClient Word64
window) (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
dpy ->
Display -> Word64 -> (WindowAttributes -> X ()) -> X ()
withWindowAttributes Display
dpy Word64
window ((WindowAttributes -> X ()) -> X ())
-> (WindowAttributes -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \WindowAttributes
wa -> do
Word64 -> X ()
focus Word64
window
(offsetX, offsetY) <- Word64 -> X (Int, Int)
getPointerOffset Word64
window
let (winX, winY, winWidth, winHeight) = getWindowPlacement wa
mouseDrag
(\Position
posX Position
posY ->
let rect :: Rectangle
rect = Position -> Position -> Word32 -> Word32 -> Rectangle
Rectangle (Position -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Int -> Position
forall a b. (Integral a, Num b) => a -> b
fi Int
winX Position -> Position -> Position
forall a. Num a => a -> a -> a
+ (Position
posX Position -> Position -> Position
forall a. Num a => a -> a -> a
- Int -> Position
forall a b. (Integral a, Num b) => a -> b
fi Int
offsetX)))
(Position -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Int -> Position
forall a b. (Integral a, Num b) => a -> b
fi Int
winY Position -> Position -> Position
forall a. Num a => a -> a -> a
+ (Position
posY Position -> Position -> Position
forall a. Num a => a -> a -> a
- Int -> Position
forall a b. (Integral a, Num b) => a -> b
fi Int
offsetY)))
(Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fi Int
winWidth)
(Int -> Word32
forall a b. (Integral a, Num b) => a -> b
fi Int
winHeight)
in DraggingVisualizerMsg -> X ()
forall a. Message a => a -> X ()
sendMessage (DraggingVisualizerMsg -> X ()) -> DraggingVisualizerMsg -> X ()
forall a b. (a -> b) -> a -> b
$ Word64 -> Rectangle -> DraggingVisualizerMsg
DraggingWindow Word64
window Rectangle
rect
)
(sendMessage DraggingStopped >> performWindowSwitching window)
getPointerOffset :: Window -> X (Int, Int)
getPointerOffset :: Word64 -> X (Int, Int)
getPointerOffset Word64
win = do
(_, _, _, oX, oY, _, _, _) <- (Display
-> X (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier))
-> X (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
forall a. (Display -> X a) -> X a
withDisplay (\Display
d -> IO (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
-> X (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
-> X (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier))
-> IO (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
-> X (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
forall a b. (a -> b) -> a -> b
$ Display
-> Word64
-> IO (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
queryPointer Display
d Word64
win)
return (fi oX, fi oY)
getWindowPlacement :: WindowAttributes -> (Int, Int, Int, Int)
getWindowPlacement :: WindowAttributes -> (Int, Int, Int, Int)
getWindowPlacement WindowAttributes
wa = (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fi (CInt -> Int) -> CInt -> Int
forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_x WindowAttributes
wa, CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fi (CInt -> Int) -> CInt -> Int
forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_y WindowAttributes
wa, CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fi (CInt -> Int) -> CInt -> Int
forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_width WindowAttributes
wa, CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fi (CInt -> Int) -> CInt -> Int
forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_height WindowAttributes
wa)
performWindowSwitching :: Window -> X ()
performWindowSwitching :: Word64 -> X ()
performWindowSwitching Word64
win = do
root <- (XConf -> Word64) -> X Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Word64
theRoot
(_, _, selWin, _, _, _, _, _) <- withDisplay (\Display
d -> IO (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
-> X (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
-> X (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier))
-> IO (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
-> X (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
forall a b. (a -> b) -> a -> b
$ Display
-> Word64
-> IO (Bool, Word64, Word64, CInt, CInt, CInt, CInt, Modifier)
queryPointer Display
d Word64
root)
ws <- gets windowset
let allWindows = StackSet WorkspaceId (Layout Word64) Word64 ScreenId ScreenDetail
-> [Word64]
forall i l a s sd. StackSet i l a s sd -> [a]
W.index StackSet WorkspaceId (Layout Word64) Word64 ScreenId ScreenDetail
ws
when ((win `elem` allWindows) && (selWin `elem` allWindows)) $ do
let allWindowsSwitched = (Word64 -> Word64) -> [Word64] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map (Word64 -> Word64 -> Word64 -> Word64
forall {a}. Eq a => a -> a -> a -> a
switchEntries Word64
win Word64
selWin) [Word64]
allWindows
(ls, t : rs) <- pure $ break (== win) allWindowsSwitched
let newStack = Word64 -> [Word64] -> [Word64] -> Stack Word64
forall a. a -> [a] -> [a] -> Stack a
W.Stack Word64
t ([Word64] -> [Word64]
forall a. [a] -> [a]
reverse [Word64]
ls) [Word64]
rs
windows $ W.modify' $ const newStack
where
switchEntries :: a -> a -> a -> a
switchEntries a
a a
b a
x | a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a = a
b
| a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b = a
a
| Bool
otherwise = a
x