Fixed multi-screen support on window frame restore

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@35241 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2012-06-27 18:10:40 +00:00
parent 35441d506c
commit d888d2ec77
3 changed files with 87 additions and 17 deletions

View file

@ -1,3 +1,14 @@
2012-06-27 Marcian Lytwyn <marcian.lytwyn@advcsi.com>
* Source/NSWindow.m - Fix [NSWindow screen] method according
to documented behavior (return screen that window show up
the most or nil). Fix [NSWindow setFrameFromString] to account for
possible nil screen on input frame and throw window on main screen
in this case. This is to fix an issue with windows not properly
showing up when moved to another monitor during multi-monitor
usage and then the extra monitor(s) are removed.
* Source/NSScreen.m - Added -description method for more information.
2012-06-27 Marcian Lytwyn <marcian.lytwyn@advcsi.com> 2012-06-27 Marcian Lytwyn <marcian.lytwyn@advcsi.com>
*** NSOpenSavePanelDelegate *** *** NSOpenSavePanelDelegate ***

View file

@ -119,6 +119,7 @@ static NSMutableArray *screenArray = nil;
[screenArray addObject: screen]; [screenArray addObject: screen];
RELEASE(screen); RELEASE(screen);
} }
NSLog(@"NSScreen:screens: %@", screenArray);
return [NSArray arrayWithArray: screenArray]; return [NSArray arrayWithArray: screenArray];
} }
@ -258,6 +259,15 @@ static NSMutableArray *screenArray = nil;
return _frame; return _frame;
} }
- (NSString*)description
{
NSMutableString *description = [NSMutableString stringWithString:[super description]];
[description appendFormat:@"number: %ld\n",(long)_screenNumber];
[description appendFormat:@"frame: %@\n",NSStringFromRect(_frame)];
return([[description copy] autorelease]);
}
/** /**
* <p> * <p>
* This method generates a dictionary containing information * This method generates a dictionary containing information

View file

@ -164,6 +164,7 @@ static GSWindowAnimationDelegate *animationDelegate;
- (void) _lossOfKeyOrMainWindow; - (void) _lossOfKeyOrMainWindow;
- (NSView *) _windowView; - (NSView *) _windowView;
- (NSScreen *) _screenForFrame:(NSRect)frame;
@end @end
@implementation NSWindow (GNUstepPrivate) @implementation NSWindow (GNUstepPrivate)
@ -379,11 +380,39 @@ has blocked and waited for events.
return _wv; return _wv;
} }
/* Support method to properly implement the 'screen' method for NSWindow.
According to documentation the 'screen' method should return the screen
that the window "show up the most or nil". This method supports the 'screen'
method and internal requests for the correct 'screen' based on the
supplied frame request.
*/
- (NSScreen *) _screenForFrame:(NSRect)frame
{
NSInteger largest = 0;
NSArray *screens = [NSScreen screens];
NSInteger index = 0;
NSScreen *theScreen = nil;
for (index = 0; index < [screens count]; ++index)
{
NSScreen *screen = [screens objectAtIndex:index];
NSRect sframe = [screen frame];
NSRect iframe = NSIntersectionRect(frame, sframe);
NSInteger isize = NSWidth(iframe) * NSHeight(iframe);
if (isize > largest)
{
largest = isize;
theScreen = screen;
}
}
NSDebugLLog(@"NSWindow", @"%s: frame: %@ screen: %@ size: %ld\n", __PRETTY_FUNCTION__,
NSStringFromRect(frame), theScreen, (long)largest);
return theScreen;
}
@end @end
@interface NSMiniWindow : NSWindow @interface NSMiniWindow : NSWindow
@end @end
@ -2553,6 +2582,7 @@ many times.
/** Returns the screen the window is on. */ /** Returns the screen the window is on. */
- (NSScreen *) screen - (NSScreen *) screen
{ {
ASSIGN(_screen, [self _screenForFrame:_frame]);
return _screen; return _screen;
} }
@ -4638,11 +4668,13 @@ current key view.<br />
/* /*
* Check that the window will come up on screen * Check that the window will come up on screen
*/ */
#if 0 // Not valid since screen frame x/y values can be negative...
if (fRect.origin.x + fRect.size.width < 0) if (fRect.origin.x + fRect.size.width < 0)
{ {
NSLog(@"Bad screen frame - window is off screen"); NSLog(@"Bad screen frame - window is off screen");
return; return;
} }
#endif
// if toolbar is showing, adjust saved frame to add the toolbar back in // if toolbar is showing, adjust saved frame to add the toolbar back in
if ([_toolbar isVisible]) if ([_toolbar isVisible])
@ -4694,7 +4726,18 @@ current key view.<br />
* The screen rectangle gives the area of the screen in which * The screen rectangle gives the area of the screen in which
* the window could be placed (ie a rectangle excluding the dock). * the window could be placed (ie a rectangle excluding the dock).
*/ */
nRect = [[self screen] visibleFrame]; NSScreen *screen = [self _screenForFrame:fRect];
// Check whether a portion is showing somewhere...
if (screen == nil)
{
// If the window doesn't show up on any screen then we need
// to move it so it can be seen and assign it to the main
// screen...
screen = [NSScreen mainScreen];
NSDebugLLog(@"NSWindow", @"%s: re-assigning to main screen\n", __PRETTY_FUNCTION__);
}
nRect = [screen visibleFrame];
/* /*
* If the new screen drawable area has moved relative to the one in * If the new screen drawable area has moved relative to the one in
@ -4745,6 +4788,9 @@ current key view.<br />
} }
} }
// Make sure we are using the new screen we are applying to...
ASSIGN(_screen, screen);
/* /*
* Set frame. * Set frame.
*/ */
@ -4804,12 +4850,15 @@ current key view.<br />
* the window could be placed (ie a rectangle excluding the dock). * the window could be placed (ie a rectangle excluding the dock).
*/ */
sRect = [[self screen] visibleFrame]; sRect = [[self screen] visibleFrame];
NSString *autosaveString = [NSString stringWithFormat: @"%d %d %d %d %d %d % d %d ",
return [NSString stringWithFormat: @"%d %d %d %d %d %d % d %d ",
(int)fRect.origin.x, (int)fRect.origin.y, (int)fRect.origin.x, (int)fRect.origin.y,
(int)fRect.size.width, (int)fRect.size.height, (int)fRect.size.width, (int)fRect.size.height,
(int)sRect.origin.x, (int)sRect.origin.y, (int)sRect.origin.x, (int)sRect.origin.y,
(int)sRect.size.width, (int)sRect.size.height]; (int)sRect.size.width, (int)sRect.size.height];
NSDebugLLog(@"NSWindow", @"%s:autosaveName: %@ frame string: %@", __PRETTY_FUNCTION__,
_autosaveName, autosaveString);
return autosaveString;
} }
/* /*