Skip to content

Commit

Permalink
fix issue #40 - apparently the notification i was
Browse files Browse the repository at this point in the history
using for screen changes is not in lion anymore.
  • Loading branch information
Jigish Patel committed Mar 6, 2012
1 parent 5fdcb6b commit f3f3982
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 8 deletions.
1 change: 1 addition & 0 deletions Slate/Constants.h
Expand Up @@ -193,6 +193,7 @@ extern NSString *const ORDERED;

// Notifications
extern NSString *const NOTIFICATION_SCREEN_CHANGE;
extern NSString *const NOTIFICATION_SCREEN_CHANGE_LION;

// Applications
extern NSString *const FINDER;
Expand Down
1 change: 1 addition & 0 deletions Slate/Constants.m
Expand Up @@ -195,6 +195,7 @@

// Notifications
NSString *const NOTIFICATION_SCREEN_CHANGE = @"O3DeviceTimingChanged";
NSString *const NOTIFICATION_SCREEN_CHANGE_LION = @" com.apple.BezelServices.BMDisplayHWReconfiguredEvent";

// Applications
NSString *const FINDER = @"Finder";
Expand Down
4 changes: 4 additions & 0 deletions Slate/ScreenWrapper.h
Expand Up @@ -29,6 +29,10 @@

+ (void)updateLeftToRightToDefault;
+ (void)updateLeftToRightToDefault:(NSArray *)theScreens;
+ (void)updateScreenResolutions;
+ (void)updateScreenResolutions:(NSArray *)theScreens;
+ (void)updateStatics;
+ (BOOL)hasScreenConfigChanged;
- (id)initWithScreens:(NSArray *)theScreens; // Used for testing
- (NSInteger)getScreenCount;
- (NSInteger)convertDefaultOrderToLeftToRightOrder:(NSInteger)screenId;
Expand Down
32 changes: 31 additions & 1 deletion Slate/ScreenWrapper.m
Expand Up @@ -25,6 +25,7 @@
#import "SlateLogger.h"

static NSMutableArray *leftToRightToDefault = nil;
static NSString *resolutions = nil;

@implementation ScreenWrapper

Expand All @@ -33,7 +34,7 @@ @implementation ScreenWrapper
+ (void)initialize {
if (!leftToRightToDefault) {
leftToRightToDefault = [[NSMutableArray alloc] init];
[ScreenWrapper updateLeftToRightToDefault];
[ScreenWrapper updateStatics];
}
}

Expand Down Expand Up @@ -72,6 +73,35 @@ + (void)updateLeftToRightToDefault:(NSArray *)theScreens {
}
}

+ (void)updateScreenResolutions {
[ScreenWrapper updateScreenResolutions:[NSScreen screens]];
}

+ (void)updateScreenResolutions:(NSArray *)theScreens {
resolutions = @"";
for (NSScreen *screen in theScreens) {
NSRect screenRect =[screen frame];
resolutions = [resolutions stringByAppendingFormat:@"%i%@%i,",(int)screenRect.size.width,X,(int)screenRect.size.height];
}
}

+ (void)updateStatics {
[ScreenWrapper updateLeftToRightToDefault];
[ScreenWrapper updateScreenResolutions];
}

+ (BOOL)hasScreenConfigChanged {
NSString *oldResolutions = [NSString stringWithString:resolutions];
NSArray *oldLeftToRight = [NSArray arrayWithArray:leftToRightToDefault];
[ScreenWrapper updateStatics];
if (![oldResolutions isEqualToString:resolutions]) return YES;
if ([oldLeftToRight count] != [leftToRightToDefault count]) return YES;
for (NSInteger i = 0; i < [oldLeftToRight count]; i++) {
if ([[oldLeftToRight objectAtIndex:i] integerValue] != [[leftToRightToDefault objectAtIndex:i] integerValue]) return YES;
}
return NO;
}

- (id)init {
return [self initWithScreens:[NSScreen screens]];
}
Expand Down
1 change: 0 additions & 1 deletion Slate/SlateAppDelegate.h
Expand Up @@ -38,7 +38,6 @@
- (IBAction)currentWindowInfo;
- (void)loadConfig;
- (void)registerHotKeys;
- (void)processNotification:(id)notification;

OSStatus OnHotKeyEvent(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData);
OSStatus OnHotKeyReleasedEvent(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData);
Expand Down
5 changes: 0 additions & 5 deletions Slate/SlateAppDelegate.m
Expand Up @@ -139,11 +139,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

}

- (void)processNotification:(id)notification {
SlateLogger(@"Notification: %@", notification);
SlateLogger(@"Notification Name: %@", [notification name]);
}

- (void)awakeFromNib {
currentHintOperation = nil;

Expand Down
1 change: 1 addition & 0 deletions Slate/SlateConfig.h
Expand Up @@ -55,5 +55,6 @@
- (void)addSnapshot:(Snapshot *)snapshot name:(NSString *)name saveToDisk:(BOOL)saveToDisk isStack:(BOOL)isStack;
- (void)deleteSnapshot:(NSString *)name pop:(BOOL)pop;
- (Snapshot *)popSnapshot:(NSString *)name remove:(BOOL)remove;
//- (void)processNotification:(id)notification;

@end
9 changes: 8 additions & 1 deletion Slate/SlateConfig.m
Expand Up @@ -63,6 +63,8 @@ - (id)init {
// Listen for screen change notifications
NSNotificationCenter *nc = [NSDistributedNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(onScreenChange:) name:NOTIFICATION_SCREEN_CHANGE object:nil];
[nc addObserver:self selector:@selector(onScreenChange:) name:NOTIFICATION_SCREEN_CHANGE_LION object:nil];
//[nc addObserver:self selector:@selector(processNotification:) name:nil object:nil];
}
return self;
}
Expand Down Expand Up @@ -347,9 +349,14 @@ - (NSString *)replaceAliases:(NSString *)line {
return line;
}

/*- (void)processNotification:(id)notification {
SlateLogger(@"Notification: %@", notification);
SlateLogger(@"Notification Name: <%@>", [notification name]);
}*/

- (void)onScreenChange:(id)notification {
SlateLogger(@"onScreenChange");
[ScreenWrapper updateLeftToRightToDefault];
[ScreenWrapper updateStatics];
ScreenWrapper *sw = [[ScreenWrapper alloc] init];
NSInteger screenCount = [sw getScreenCount];
NSMutableArray *resolutions = [[NSMutableArray alloc] initWithCapacity:10];
Expand Down

0 comments on commit f3f3982

Please sign in to comment.