xmonad / xmonad-contrib

Contributed modules for xmonad
https://xmonad.org
BSD 3-Clause "New" or "Revised" License
584 stars 274 forks source link

Prefer safe alternatives to getWindowAttributes #647

Closed slotThe closed 2 years ago

slotThe commented 2 years ago

Description

Since X11 is unlikely to get safe bindings anytime soon, I figured this was better than nothing.

X.Prelude: Add safeGetWindowAttributes

Move the function from X.U.DebugWindow, where it was defined already. This is a safe version of getWindowAttributes, returning a Maybe instead of throwing an exception, in case the window attributes could not be retrieved.

Prefer safe alternatives to getWindowAttributes

Whenever possible, prefer the safe wrappers withWindowAttributes or safeGetWindowAttributes to getWindowAttributes.

Places where these are not applicable are limited to layouts, where there is not good "default value" to give back in case these calls fail. In these cases, we let the exception handling of the layout mechanism handle it and fall back to the Full layout.

Fixes: https://github.com/xmonad/xmonad-contrib/issues/146

Checklist

slotThe commented 2 years ago

Will merge in a few days if no one objects

liskin commented 2 years ago

I haven't had time to go through the code in detail but the general idea looks all right, so don't expect me to object. There's also nothing stopping you from adding the safe alternatives to X11 if you feel that's right, but it'd mean some painful dependency bumps so it'd have to be worth it long-term.

slotThe commented 2 years ago

There's also nothing stopping you from adding the safe alternatives to X11 if you feel that's right, but it'd mean some painful dependency bumps so it'd have to be worth it long-term.

Exactly; I think I'd only do this if I was actually planning on a safe API for X11 but I'm not really going to do anything close to that anytime soon