<div dir="ltr">The simplest thing will be to wrap just the call to `getWindowAttributes`, if that's the one you expect to fail. It is not conveniently possible to wrap `X` actions; so instead, something like<div><br></div><div> withDisplay $ \d -> do</div><div> ws <- gets windowset</div><div> ewa <- io $ try (getWindowAttributes d w)</div><div> case ewa of</div><div> Left e -> io (putStrLn "HELP! do something!")</div><div> Right wa -> do</div><div> let bw = (fromIntegral . wa_border_width) wa</div><div> {- ... etc. -}</div><div><br></div><div>~d</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 12, 2016 at 10:24 AM, Adam Sjøgren <span dir="ltr"><<a href="mailto:asjo@koldfront.dk" target="_blank">asjo@koldfront.dk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am trying to modify xmonad to handle exceptions thrown in<br>
getWindowAttributes.<br>
<br>
Since I am still copy/paste-coding, I need some help.<br>
<br>
Take a function like this, which I have seen crashes in (especially when<br>
using Gimp):<br>
<br>
floatLocation :: Window -> X (ScreenId, W.RationalRect)<br>
floatLocation w = withDisplay $ \d -> do<br>
ws <- gets windowset<br>
wa <- io $ getWindowAttributes d w<br>
let bw = (fromIntegral . wa_border_width) wa<br>
sc <- fromMaybe (W.current ws) <$> pointScreen (fi $ wa_x wa) (fi $ wa_y wa)<br>
<br>
let sr = screenRect . W.screenDetail $ sc<br>
rr = W.RationalRect ((fi (wa_x wa) - fi (rect_x sr)) % fi (rect_width sr))<br>
((fi (wa_y wa) - fi (rect_y sr)) % fi (rect_height sr))<br>
(fi (wa_width wa + bw*2) % fi (rect_width sr))<br>
(fi (wa_height wa + bw*2) % fi (rect_height sr))<br>
<br>
return (W.screen sc, rr)<br>
where fi x = fromIntegral x<br>
<br>
I somehow need to wrap the code from getWindowAttributes and on, in<br>
something that "does the right thing" if gWA throws an exception.<br>
<br>
In other places, I have done something like this:<br>
<br>
sendConfigureEvent :: Display -> XEventPtr -> Window -> Event -> IO ()<br>
sendConfigureEvent dpy ev w e = C.handle (\(C.SomeException _) -> putStrLn "sendConfigureEvent failed") $ do<br>
wa <- io $ getWindowAttributes dpy w<br>
setEventType ev configureNotify<br>
setConfigureEvent ev w w<br>
(wa_x wa) (wa_y wa) (wa_width wa)<br>
(wa_height wa) (ev_border_width e) none (wa_override_redirect wa)<br>
sendEvent dpy w False 0 ev<br>
<br>
which works, but in floatLocation the type is X and not IO, and ...<br>
well, what's a boy to do?<br>
<br>
<br>
Best regards,<br>
<br>
Adam<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
"It's part of our policy not to be taken seriously" Adam Sjøgren<br>
<a href="mailto:asjo@koldfront.dk">asjo@koldfront.dk</a><br>
<br>
_______________________________________________<br>
xmonad mailing list<br>
<a href="mailto:xmonad@haskell.org">xmonad@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad</a><br>
</font></span></blockquote></div><br></div>