diff --git a/ChangeLog b/ChangeLog index 8f9815a2d..38b095eac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-05-31 Wolfgang Lux + + * Source/NSWindow.m (-orderWindow:relativeTo:): Take care of hide + on deactivate windows. + * Source/NSWindow.m (-setHidesOnDeactivate:): Hide/unhide receiver + when the flag is changed and the application is not active. + + * Source/NSWindow.m (-_isWindowInactive:, _setWindow:inactivate:): + New private NSApplication category to support management of hide + on deactivate windows. + + * Source/NSApplication.m (-deactivate): Fix order of actions when + hiding inactive windows. + 2011-05-31 Wolfgang Lux * Source/NSImage.m (-bestRepresentationForDevice): Prefer diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 4a4416aa4..ea1200a8e 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -1433,8 +1433,12 @@ static NSSize scaledIconSizeForSize(NSSize imageSize) if ([win hidesOnDeactivate] == YES) { - [_inactive addObject: win]; + /* NB Order is important here. When a hide on deactivate window + is ordered out while the application is inactive, it gets + removed from the _inactive list. Therefore, we must first + order out the window and then add it to the _inactive list. */ [win orderOut: self]; + [_inactive addObject: win]; } } diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 4cb77f66f..dda47810b 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -124,6 +124,11 @@ BOOL GSViewAcceptsDrag(NSView *v, id dragInfo); - (id) _initWithScreenNumber: (int)screen; @end +@interface NSApplication(Inactive) +- (BOOL) _isWindowInactive: (NSWindow *)window; +- (void) _setWindow: (NSWindow *)window inactive: (BOOL)inactive; +@end + /* * Category for internal methods (for use only within the NSWindow class itself @@ -1716,7 +1721,7 @@ many times. { /* Windows need to be constrained when displayed or resized - but only titled windows are constrained. Also, and this is the tricky part, - don't constrain if we are merely unhidding the window or if it's + don't constrain if we are merely unhiding the window or if it's already visible and is just being reordered. */ if ((_styleMask & NSTitledWindowMask) && [NSApp isHidden] == NO @@ -1734,6 +1739,14 @@ many times. } } + /* If a hide on deactivate window is explicitly ordered in or out while + the application is not active, remove it from the list of inactive + windows. */ + if ([self hidesOnDeactivate] && ![NSApp isActive]) + { + [NSApp _setWindow: self inactive: NO]; + } + // Draw content before backend window ordering if (display) [_wv display]; @@ -1841,6 +1854,28 @@ many times. if (flag != _f.hides_on_deactivate) { _f.hides_on_deactivate = flag; + if (![NSApp isActive]) + { + if (flag) + { + if (_f.visible) + { + /* Order is important here. We must first order out the window + and then add it to the inactive list, since -orderOut: + removes the receiver from the inactive list. */ + [self orderOut: nil]; + [NSApp _setWindow: self inactive: YES]; + } + } + else + { + if ([NSApp _isWindowInactive: self]) + { + [NSApp _setWindow: self inactive: NO]; + [self orderFront: nil]; + } + } + } } } @@ -5532,6 +5567,25 @@ current key view.
} @end +@implementation NSApplication(Inactive) +- (BOOL) _isWindowInactive: (NSWindow *)window +{ + return [_inactive containsObject: window]; +} + +- (void) _setWindow: (NSWindow *)window inactive: (BOOL)inactive +{ + if (inactive) + { + [_inactive addObject: window]; + } + else + { + [_inactive removeObject: window]; + } +} +@end + BOOL GSViewAcceptsDrag(NSView *v, id dragInfo) { NSPasteboard *pb = [dragInfo draggingPasteboard];