- if (newFocusWnd != menu->Window->Window.Handle)
- /* When in GameMode, the menu's parent window will lose focus when the menu is opened.
- * This is sadly necessary as we need to do an activating ShowWindow() for the menu
- * to pop up over the gamemode window
- */
- fgDeactivateMenu(menu->ParentWindow);
+ /* see if there is an active menu whose window matches the one that got focus */
+ enumerator.found = GL_FALSE;
+ enumerator.data = (void*) newFocusWnd;
+ fgEnumMenus(fghcbIsActiveMenu, &enumerator);
+ if (enumerator.found)
+ menu = (SFG_Menu*) enumerator.data;
+
+ if ( !menu )
+ {
+ /* window that got focus was not one of the active menus. That means we'll
+ * close the active menu's unless the window that got focus was their parent */
+ menu = fgGetActiveMenu();
+
+ if (newFocusWnd != menu->ParentWindow->Window.Handle)
+ {
+ /* focus shifted to another window than the menu's parent, close menus */
+ fgDeactivateMenu(menu->ParentWindow);
+ return;
+ }
+ }