Permalink
Browse files

Checks the NSWindow for it's scale factor and relays that information…

… down the display tree triggering redraws and whatnot as it goes.
  • Loading branch information...
1 parent 5660984 commit cafaa08840a6c27298125cdaddf9166cfc037450 @BigZaphod committed Jun 12, 2012
Showing with 30 additions and 20 deletions.
  1. +3 −3 UIKit/Classes/UIScreen.h
  2. +27 −17 UIKit/Classes/UIScreen.m
View
@@ -50,8 +50,8 @@ extern NSString *const UIScreenModeDidChangeNotification;
@property (nonatomic, readonly) CGRect bounds;
@property (nonatomic, readonly) CGRect applicationFrame;
-@property (nonatomic, readonly, copy) NSArray *availableModes; // only ever returns the currentMode
-@property (nonatomic, retain) UIScreenMode *currentMode; // ignores any attempt to set this (for now)
-@property (nonatomic, readonly) CGFloat scale; // always returns 1 for now
+@property (nonatomic, readonly, copy) NSArray *availableModes; // only ever returns the currentMode
+@property (nonatomic, retain) UIScreenMode *currentMode; // ignores any attempt to set this
+@property (nonatomic, readonly) CGFloat scale;
@end
View
@@ -39,6 +39,7 @@
#import "UIScreenMode+UIPrivate.h"
#import "UIWindow.h"
#import "UIKitView.h"
+#import "UIView+UIPrivate.h"
NSString *const UIScreenDidConnectNotification = @"UIScreenDidConnectNotification";
NSString *const UIScreenDidDisconnectNotification = @"UIScreenDidDisconnectNotification";
@@ -78,14 +79,6 @@ - (id)init
_layer = [[CALayer layer] retain];
_layer.delegate = self; // required to get the magic of the UIViewLayoutManager...
_layer.layoutManager = [UIViewLayoutManager layoutManager];
-
- // NOTE: This line adds a 10.6 depedency The commented out line after this would appear to do a similar thing and should work on 10.5,
- // but ironically, it then makes the UIImageView images render upside down. I suspect this has to do with flipped-ness of images, but
- // in trying to track that down I noticed that I'm using at least one 10.6-only NSImage method in there already, so I decided it wasn't
- // worth the effort right now to bother with 10.5 support since there'd be a couple changes there and who knows what other things are
- // lurking around that only works on 10.6. Got bigger fish to fry right now.
- _layer.geometryFlipped = YES;
- //_layer.sublayerTransform = CATransform3DMakeScale(1,-1,1);
_grabber = [[UIImageView alloc] initWithImage:[UIImage _windowResizeGrabberImage]];
_grabber.layer.zPosition = 10000;
@@ -114,7 +107,11 @@ - (void)dealloc
- (CGFloat)scale
{
- return 1;
+ if ([[_UIKitView window] respondsToSelector:@selector(backingScaleFactor)]) {
+ return [[_UIKitView window] backingScaleFactor];
+ } else {
+ return 1;
+ }
}
- (void)_setPopoverController:(UIPopoverController *)controller
@@ -183,15 +180,35 @@ - (CALayer *)_layer
return _layer;
}
+- (void)_UIKitViewFrameDidChange
+{
+ NSDictionary *userInfo = (self.currentMode)? [NSDictionary dictionaryWithObject:self.currentMode forKey:@"_previousMode"] : nil;
+ self.currentMode = [UIScreenMode screenModeWithNSView:_UIKitView];
+ [[NSNotificationCenter defaultCenter] postNotificationName:UIScreenModeDidChangeNotification object:self userInfo:userInfo];
+}
+
+- (void)_NSScreenDidChange
+{
+ for (UIWindow *window in [[UIApplication sharedApplication].windows reverseObjectEnumerator]) {
+ if (window.screen == self) {
+ [window _didMoveToScreen];
+ }
+ }
+}
+
- (void)_setUIKitView:(id)theView
{
if (_UIKitView != theView) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSViewFrameDidChangeNotification object:_UIKitView];
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidChangeScreenNotification object:nil];
+
if ((_UIKitView = theView)) {
[_allScreens addObject:[NSValue valueWithNonretainedObject:self]];
self.currentMode = [UIScreenMode screenModeWithNSView:_UIKitView];
[[NSNotificationCenter defaultCenter] postNotificationName:UIScreenDidConnectNotification object:self];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_UIKitViewFrameDidChange:) name:NSViewFrameDidChangeNotification object:_UIKitView];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_UIKitViewFrameDidChange) name:NSViewFrameDidChangeNotification object:_UIKitView];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_NSScreenDidChange) name:NSWindowDidChangeScreenNotification object:[_UIKitView window]];
+ [self _NSScreenDidChange];
} else {
self.currentMode = nil;
[_allScreens removeObject:[NSValue valueWithNonretainedObject:self]];
@@ -200,13 +217,6 @@ - (void)_setUIKitView:(id)theView
}
}
-- (void)_UIKitViewFrameDidChange:(NSNotification *)note
-{
- NSDictionary *userInfo = (self.currentMode)? [NSDictionary dictionaryWithObject:self.currentMode forKey:@"_previousMode"] : nil;
- self.currentMode = [UIScreenMode screenModeWithNSView:_UIKitView];
- [[NSNotificationCenter defaultCenter] postNotificationName:UIScreenModeDidChangeNotification object:self userInfo:userInfo];
-}
-
- (NSArray *)availableModes
{
return (self.currentMode)? [NSArray arrayWithObject:self.currentMode] : nil;

0 comments on commit cafaa08

Please sign in to comment.