Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer safe alternatives to getWindowAttributes #647

Merged
merged 2 commits into from
Nov 28, 2021

Conversation

slotThe
Copy link
Member

@slotThe slotThe commented Nov 13, 2021

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: #146

Checklist

  • I've read CONTRIBUTING.md

  • I've considered how to best test these changes (property, unit,
    manually, ...) and concluded: it compiles...!

  • I updated the CHANGES.md file
    I'm not sure this warrants an entry since it's not a user-facing change.

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.
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: xmonad#146
@slotThe
Copy link
Member Author

slotThe commented Nov 25, 2021

Will merge in a few days if no one objects

@liskin
Copy link
Member

liskin commented Nov 25, 2021

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
Copy link
Member Author

slotThe commented Nov 28, 2021

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

@slotThe slotThe merged commit 28aa164 into xmonad:master Nov 28, 2021
@slotThe slotThe deleted the safe-window-attrs branch October 25, 2022 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unsafe getWindowAttributes calls in ~20 modules
2 participants