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
Window
rootw <- Display -> ScreenNumber -> IO Window
rootWindow Display
dpy ScreenNumber
dflt
Window
wmSnAtom <- Display -> String -> Bool -> IO Window
internAtom Display
dpy (String
"WM_S" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show ScreenNumber
dflt) Bool
False
Window
currentWmSnOwner <- Display -> Window -> IO Window
xGetSelectionOwner Display
dpy Window
wmSnAtom
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Window
currentWmSnOwner forall a. Eq a => a -> a -> Bool
/= Window
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 -> Window -> Window -> IO ()
selectInput Display
dpy Window
currentWmSnOwner Window
structureNotifyMask
Window
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 -> Window -> IO ()
set_event_mask Ptr SetWindowAttributes
attributes Window
propertyChangeMask
let screen :: Screen
screen = Display -> Screen
defaultScreenOfDisplay Display
dpy
let visual :: Visual
visual = Screen -> Visual
defaultVisualOfScreen Screen
screen
let attrmask :: Window
attrmask = Window
cWOverrideRedirect forall a. Bits a => a -> a -> a
.|. Window
cWEventMask
Display
-> Window
-> Position
-> Position
-> ScreenNumber
-> ScreenNumber
-> CInt
-> CInt
-> CInt
-> Visual
-> Window
-> Ptr SetWindowAttributes
-> IO Window
createWindow Display
dpy Window
rootw (-Position
100) (-Position
100) ScreenNumber
1 ScreenNumber
1 CInt
0 CInt
copyFromParent CInt
copyFromParent Visual
visual Window
attrmask Ptr SetWindowAttributes
attributes
String -> IO ()
putStrLn String
"Replacing existing window manager..."
Display -> Window -> Window -> Window -> IO ()
xSetSelectionOwner Display
dpy Window
wmSnAtom Window
netWmSnOwner Window
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 -> Window -> Window -> XEventPtr -> IO ()
windowEvent Display
dpy Window
currentWmSnOwner Window
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