Unlike the python code you linked, the Haskell X11 library from XMonad mimics the C library closely. What we want to do here is:
- Call
changeWindowAttributes
specifying the attribute(s) we want to change. Here we want to specify the "event mask" attribute.
- Before that call, write inside
swaPtr
the actual event mask we want to set, using set_event_mask :: Ptr SetWindowAttributes -> EventMask -> IO ()
.
The final code should read like:
X11.allocaSetWindowAttributes $ \swaPtr ->
X11.set_event_mask swaPtr X11.propertyChangeMask
X11.changeWindowAttributes disp root X11.cWEventMask swaPtr
Minor digression: it is very unfortunate that X11.propertyChangeMask
and X11.cWEventMask
have the same type in C, and further also have the same type in Haskell. A newtype
wrapper here would have prevented your original code, that tries to pass an event mask as an attribute mask. Arguably, even in C one would have used a lightweight struct EventMask { unsigned long em; }
to prevent similar type confusion. For some reason (which I can't fathom), C libraries often abstain to pass structs as parameters, as if they still wanted to be compatible with pre-ISO, pre-ANSI, K&R C, even when they are created in much more modern times.