Merge final version of the proper fix for KeePass freezing the window manager

This is the version of the patch as modified by Dominik to fix the issue. It should be the version
rolled out with 2.24.