* Source/NSScreen.m (_initWithScreenNumber:): add self as observer to

NSApplicationDidChangeScreenParametersNotification.
(frame): use `_frame` ivar since libs-back recreates screens list.
(dealloc): remove observer.
(applicationDidChangeScreenParameters:): update _frame and _depth
ivars for bad behaving objects which retain NSScreen and not observing
screen parameters changes.
This commit is contained in:
Sergii Stoian 2020-01-24 19:48:28 +02:00
parent 41dc7fa9cd
commit 731abde796
2 changed files with 30 additions and 1 deletions

View file

@ -1,3 +1,13 @@
2020-01-24 Sergii Stoian <stoyan255@gmail.com>
* Source/NSScreen.m (_initWithScreenNumber:): add self as observer to
NSApplicationDidChangeScreenParametersNotification.
(frame): use `_frame` ivar since libs-back recreates screens list.
(dealloc): remove observer.
(applicationDidChangeScreenParameters:): update _frame and _depth
ivars for bad behaving objects which retain NSScreen and not observing
screen parameters changes.
2020-01-23 Sergii Stoian <stoyan255@gmail.com>
* Source/NSApplication (finishLaunching): observer for

View file

@ -228,6 +228,14 @@ static NSMutableArray *screenArray = nil;
_depth = [srv windowDepthForScreen: _screenNumber];
_supportedWindowDepths = NULL;
/* Register self as observer to screen events. */
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(applicationDidChangeScreenParameters:)
name: NSApplicationDidChangeScreenParametersNotification
object: nil];
return self;
}
@ -255,7 +263,7 @@ static NSMutableArray *screenArray = nil;
*/
- (NSRect) frame
{
return [GSCurrentServer() boundsForScreen: _screenNumber];
return _frame;
}
- (NSString*) description
@ -408,6 +416,7 @@ static NSMutableArray *screenArray = nil;
// Release the memory for the depths array.
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
// _supportedWindowDepths can be NULL since it may or may not
// be necessary to get this info. The most common use of NSScreen
// is to get the depth and frame attributes.
@ -452,6 +461,16 @@ static NSMutableArray *screenArray = nil;
return 1.0;
}
// This notification callback shouldn't be called. But some objects (NSWindow)
// may retain NSScren instance and not handle screen parameters changes.
// Update our ivars for them.
- (void) applicationDidChangeScreenParameters: (NSNotification*)aNotification
{
GSDisplayServer *srv = GSCurrentServer();
_frame = [srv boundsForScreen: _screenNumber];
_depth = [srv windowDepthForScreen: _screenNumber];
}
@end