suggested by Kuba Ober, replaced topLevelWidgets() with a static list guarded by mutex