Index: Source/NSApplication.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSApplication.m,v retrieving revision 1.254 diff -u -r1.254 NSApplication.m --- Source/NSApplication.m 11 Nov 2003 19:40:18 -0000 1.254 +++ Source/NSApplication.m 12 Nov 2003 15:10:53 -0000 @@ -931,7 +931,7 @@ [[_inactive objectAtIndex: i] orderFrontRegardless]; } [_inactive removeAllObjects]; - if (_hidden_key != nil + if ([self keyWindow] == nil && _hidden_key != nil && [[self windows] indexOfObjectIdenticalTo: _hidden_key] != NSNotFound) { [_hidden_key makeKeyWindow]; @@ -949,8 +949,17 @@ } else if ([self mainWindow] != nil) { - [[self mainWindow] orderFront: self]; + [[self mainWindow] makeKeyAndOrderFront: self]; } + else + { + /* We need give input focus to some window otherwise we'll never get + keyboard events. FIXME: doesn't work. */ + NSWindow *menu_window= [[self mainMenu] window]; + NSDebugLLog(@"Focus", @"No key on activation - make menu key"); + [GSServerForWindow(menu_window) setinputfocus: + [menu_window windowNumber]]; + } [nc postNotificationName: NSApplicationDidBecomeActiveNotification object: self]; @@ -975,6 +984,10 @@ _hidden_key = [self keyWindow]; [_hidden_key resignKeyWindow]; } + // FIXME: main window is not saved for when the app is activated again. + // This is not a problem if it is also key, and I'm not sure if it + // is a problem at all. May be annoying in the case of workspace switch. + [[self mainWindow] resignMainWindow]; for (i = 0; i < count; i++) { NSModalSession theSession; @@ -1496,13 +1509,11 @@ if (!theEvent) NSDebugLLog(@"NSEvent", @"NSEvent is nil!\n"); if (type == NSMouseMoved) - NSDebugLLog(@"NSMotionEvent", @"Send move (%d) to window %@", - type, ((window != nil) ? [window description] - : @"No window")); + NSDebugLLog(@"NSMotionEvent", @"Send move (%d) to window %d", + type, [window windowNumber]); else - NSDebugLLog(@"NSEvent", @"Send NSEvent type: %d to window %@", - type, ((window != nil) ? [window description] - : @"No window")); + NSDebugLLog(@"NSEvent", @"Send NSEvent type: %d to window %d", + type, [window windowNumber]); if (window) [window sendEvent: theEvent]; else if (type == NSRightMouseDown) @@ -1884,6 +1895,8 @@ [nc postNotificationName: NSApplicationWillUnhideNotification object: self]; + _app_is_hidden = NO; + count = [_hidden count]; for (i = 0; i < count; i++) { @@ -1896,8 +1909,6 @@ [_hidden_key makeKeyAndOrderFront: self]; _hidden_key = nil; } - - _app_is_hidden = NO; [nc postNotificationName: NSApplicationDidUnhideNotification object: self]; Index: Source/NSWindow.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSWindow.m,v retrieving revision 1.295 diff -u -r1.295 NSWindow.m --- Source/NSWindow.m 11 Nov 2003 19:40:18 -0000 1.295 +++ Source/NSWindow.m 12 Nov 2003 15:10:58 -0000 @@ -2852,10 +2857,6 @@ { BOOL wasKey = _f.is_key; - if ([NSApp isActive] == NO && self != [NSApp iconWindow]) - { - [NSApp activateIgnoringOtherApps: YES]; - } if (_f.has_closed == NO) { v = [_contentView hitTest: [theEvent locationInWindow]]; @@ -2863,6 +2864,10 @@ { [self makeKeyAndOrderFront: self]; } + if ([NSApp isActive] == NO && self != [NSApp iconWindow]) + { + [NSApp activateIgnoringOtherApps: YES]; + } if (_firstResponder != v) { [self makeFirstResponder: v]; @@ -3075,19 +3080,17 @@ { /* Window Manager just deminiaturized us */ [self deminiaturize: self]; - //[self _didDeminiaturize: self]; } - if ([NSApp isHidden]) + if ([NSApp modalWindow] + && self != [NSApp modalWindow]) { - /* This often occurs when hidding an app, since a bunch - of windows get hidden at once, and the WM is searching - for a window to take focus after each one gets - hidden. */ - NSDebugLLog(@"Focus", @"WM take focus while hiding"); + /* Ignore this request. We're in a modal loop and the + user pressed on the title bar of another window. */ break; } if ([self canBecomeKeyWindow] == YES) { + NSDebugLLog(@"Focus", @"Making %d key", _windowNum); [self makeKeyWindow]; [self makeMainWindow]; [NSApp activateIgnoringOtherApps: YES];