module XMonad.Util.Replace
(
replace
) where
import XMonad
import XMonad.Prelude
replace :: IO ()
replace :: IO ()
replace = do
Display
dpy <- String -> IO Display
openDisplay String
""
let dflt :: ScreenNumber
dflt = Display -> ScreenNumber
defaultScreen Display
dpy
ScreenNumber
rootw <- Display -> ScreenNumber -> IO ScreenNumber
rootWindow Display
dpy ScreenNumber
dflt
ScreenNumber
wmSnAtom <- Display -> String -> Bool -> IO ScreenNumber
internAtom Display
dpy (String
"WM_S" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show ScreenNumber
dflt) Bool
False
ScreenNumber
currentWmSnOwner <- Display -> ScreenNumber -> IO ScreenNumber
xGetSelectionOwner Display
dpy ScreenNumber
wmSnAtom
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (ScreenNumber
currentWmSnOwner forall a. Eq a => a -> a -> Bool
/= ScreenNumber
0) forall a b. (a -> b) -> a -> b
$ do
String -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ String
"Screen " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show ScreenNumber
dflt forall a. [a] -> [a] -> [a]
++ String
" on display \""
forall a. [a] -> [a] -> [a]
++ Display -> String
displayString Display
dpy forall a. [a] -> [a] -> [a]
++ String
"\" already has a window manager."
Display -> ScreenNumber -> ScreenNumber -> IO ()
selectInput Display
dpy ScreenNumber
currentWmSnOwner ScreenNumber
structureNotifyMask
ScreenNumber
netWmSnOwner <- forall a. (Ptr SetWindowAttributes -> IO a) -> IO a
allocaSetWindowAttributes forall a b. (a -> b) -> a -> b
$ \Ptr SetWindowAttributes
attributes -> do
Ptr SetWindowAttributes -> Bool -> IO ()
set_override_redirect Ptr SetWindowAttributes
attributes Bool
True
Ptr SetWindowAttributes -> ScreenNumber -> IO ()
set_event_mask Ptr SetWindowAttributes
attributes ScreenNumber
propertyChangeMask
let screen :: Screen
screen = Display -> Screen
defaultScreenOfDisplay Display
dpy
let visual :: Visual
visual = Screen -> Visual
defaultVisualOfScreen Screen
screen
let attrmask :: ScreenNumber
attrmask = ScreenNumber
cWOverrideRedirect forall a. Bits a => a -> a -> a
.|. ScreenNumber
cWEventMask
Display
-> ScreenNumber
-> Position
-> Position
-> ScreenNumber
-> ScreenNumber
-> CInt
-> CInt
-> CInt
-> Visual
-> ScreenNumber
-> Ptr SetWindowAttributes
-> IO ScreenNumber
createWindow Display
dpy ScreenNumber
rootw (-Position
100) (-Position
100) ScreenNumber
1 ScreenNumber
1 CInt
0 CInt
copyFromParent CInt
copyFromParent Visual
visual ScreenNumber
attrmask Ptr SetWindowAttributes
attributes
String -> IO ()
putStrLn String
"Replacing existing window manager..."
Display -> ScreenNumber -> ScreenNumber -> ScreenNumber -> IO ()
xSetSelectionOwner Display
dpy ScreenNumber
wmSnAtom ScreenNumber
netWmSnOwner ScreenNumber
currentTime
String -> IO ()
putStr String
"Waiting for other window manager to terminate... "
forall a. (a -> a) -> a
fix forall a b. (a -> b) -> a -> b
$ \IO ()
again -> do
ScreenNumber
evt <- forall a. (XEventPtr -> IO a) -> IO a
allocaXEvent forall a b. (a -> b) -> a -> b
$ \XEventPtr
event -> do
Display -> ScreenNumber -> ScreenNumber -> XEventPtr -> IO ()
windowEvent Display
dpy ScreenNumber
currentWmSnOwner ScreenNumber
structureNotifyMask XEventPtr
event
XEventPtr -> IO ScreenNumber
get_EventType XEventPtr
event
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (ScreenNumber
evt forall a. Eq a => a -> a -> Bool
/= ScreenNumber
destroyNotify) IO ()
again
String -> IO ()
putStrLn String
"done"
Display -> IO ()
closeDisplay Display
dpy