Discussion:
[xmonad] Slowly, slowly getting calls to getWindowAttributes in XMonad to handle exceptions
Adam Sjøgren
2015-12-31 22:53:13 UTC
Permalink
While fixing the "borders of RGBA-windows are weirdly coloured"-bug¹,
having changed X11's getWindowAttributes to throw an exception on error,
I am trying to work my way through the various calls to
getWindowAttributes in the XMonad source, and handle the exceptions.

With my (lacking) knowledge, it's proving somewhat difficult. Let me
show you the latest call I have been trying to tackle:

-- manage a new window
handle (MapRequestEvent {ev_window = w}) = withDisplay $ \dpy -> do
wa <- io $ getWindowAttributes dpy w -- ignore override windows
-- need to ignore mapping requests by managed windows not on the current workspace
managed <- isClient w
when (not (wa_override_redirect wa) && not managed) $ do manage w

What needs to happen is that I need to wrap this, so if
getWindowAttributes throws an exception, something reasonable happens.

Right.

As the code does nothing if wa_override_redirect is set, maybe it makes
sense to assume that if wa isn't available, wa_o_r probably isn't
set(?), so we then need to go on and "do manage w" if "not managed" in
that case.

Ok. But how?

I've tried a number of combinations of wrapping C.handle around this,
similar to what I have found before², but I certainly need (to read a
lot more, or, some) help - I keep getting IO () when I need X (), or the
opposite, and stuff like that.


Best regards,

Adam


¹ https://github.com/xmonad/xmonad/pull/9 depending on https://github.com/xmonad/X11/pull/35
² An attempt at one of the other calls to getWindowAttributes: https://github.com/asjo/xmonad/commit/8c2b6047a9adf5689b6082c806dc20bb6501f6d9
(compiles and works, but really created by guess, trial and error).
--
"Sprecken Sie deutsch, baby" Adam Sjøgren
***@koldfront.dk
Brandon Allbery
2016-01-01 03:54:20 UTC
Permalink
Post by Adam Sjøgren
-- manage a new window
handle (MapRequestEvent {ev_window = w}) = withDisplay $ \dpy -> do
wa <- io $ getWindowAttributes dpy w -- ignore override windows
-- need to ignore mapping requests by managed windows not on the current workspace
managed <- isClient w
when (not (wa_override_redirect wa) && not managed) $ do manage w
What needs to happen is that I need to wrap this, so if
getWindowAttributes throws an exception, something reasonable happens.
What exceptions are you expecting? The only one I'd expect is no such
window, in which case you kinda want to abort anyway.

I've tried a number of combinations of wrapping C.handle around this,
Post by Adam Sjøgren
similar to what I have found before², but I certainly need (to read a
lot more, or, some) help - I keep getting IO () when I need X (), or the
opposite, and stuff like that.
http://xmonad.org/xmonad-docs/xmonad/XMonad-Core.html#v:catchX to catch
exceptions from code producing X something.
http://xmonad.org/xmonad-docs/xmonad/XMonad-Core.html#v:catchIO to catch
exceptions from code producing IO something.

(Don't feel too bad about this, it's actually a surprisingly hard problem
in the general case. MonadBaseControl grew out of trying to deal with it in
various situations, because it's hard to do "catch" properly in a monad
over IO and impossible to do "bracket" properly. Specific cases can be
done, as above catchX / catchIO, but even then require some thinking to
write in the first place.)
--
brandon s allbery kf8nh sine nomine associates
***@gmail.com ***@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Adam Sjøgren
2016-01-01 14:41:32 UTC
Permalink
Post by Brandon Allbery
Post by Adam Sjøgren
-- manage a new window
handle (MapRequestEvent {ev_window = w}) = withDisplay $ \dpy -> do
wa <- io $ getWindowAttributes dpy w -- ignore override windows
-- need to ignore mapping requests by managed windows not on the current workspace
managed <- isClient w
when (not (wa_override_redirect wa) && not managed) $ do manage w
What needs to happen is that I need to wrap this, so if
getWindowAttributes throws an exception, something reasonable happens.
What exceptions are you expecting? The only one I'd expect is no such
window, in which case you kinda want to abort anyway.
I have put a "putStrLn" in before each call to getWindowAttributes in my
local XMonad, and I am recording every time it crashes, so I am not
expecting an exception in this place, I had one!

Just aborting altogether I think I can manage - I will give it a shot.

Thanks!
Post by Brandon Allbery
Post by Adam Sjøgren
I've tried a number of combinations of wrapping C.handle around this,
similar to what I have found before², but I certainly need (to read a
lot more, or, some) help - I keep getting IO () when I need X (), or
the opposite, and stuff like that.
http://xmonad.org/xmonad-docs/xmonad/XMonad-Core.html#v:catchX to catch
exceptions from code producing X something.
http://xmonad.org/xmonad-docs/xmonad/XMonad-Core.html#v:catchIO to catch
exceptions from code producing IO something.
(Don't feel too bad about this, it's actually a surprisingly hard problem
in the general case. MonadBaseControl grew out of trying to deal with it in
various situations, because it's hard to do "catch" properly in a monad
over IO and impossible to do "bracket" properly. Specific cases can be
done, as above catchX / catchIO, but even then require some thinking to
write in the first place.)
(Given how low I am on the understanding-ladder, I don't feel bad at all
- I've just come to realize that I need to solve "real" problems to get
anywhere, but sometimes I get stuck, and sometimes I am too lazy to loop
back to reading up on Haskell, so I ask instead. Thanks for helping!)


Best regards,

Adam
--
"They misunderestimated me." Adam Sjøgren
***@koldfront.dk
Loading...