Index: Source/x11/XGServerEvent.m =================================================================== --- Source/x11/XGServerEvent.m (revision 25410) +++ Source/x11/XGServerEvent.m (working copy) @@ -1212,6 +1212,46 @@ cWin->map_state = IsUnmapped; cWin->visibility = -1; } +#if 1 + /* We move focus to another window so that window manager will not + randomly assign the focus. */ + NSWindow *key_win = [NSApp keyWindow]; + if (key_win == nil) + key_win = [NSApp mainWindow]; + if ((key_win == nil) && [[NSApp windows] count]) + { + int i, count = [[NSApp windows] count]; + for (i = 0; i < count; i++) + { + key_win = [[NSApp windows] objectAtIndex: i]; + if ((cWin != 0) && [key_win windowNumber] == cWin->ident) + { + NSLog(@"Found self"); + key_win = nil; + continue; + } + if ([key_win isKindOfClass: [NSWindow class]]) + { + if ([key_win canBecomeKeyWindow] == NO) + { + /* Get GSCacheWindow or NSIconWindow sometimes */ + key_win = nil; + continue; + } + } +#if 0 + if (key_win != nswin) + break; + key_win = nil; +#endif + } + } + if (key_win == nil) + key_win = [[NSApp mainMenu] window]; + int key_num = [key_win windowNumber]; +NSLog(@"Set Input Focus to %d", key_num); + [GSServerForWindow(key_win) setinputfocus: key_num]; +#endif break; // like MapNotify but occurs before the request is carried out