diff --git a/FMN.xcodeproj/project.pbxproj b/FMN.xcodeproj/project.pbxproj index 919b014..6da8289 100644 --- a/FMN.xcodeproj/project.pbxproj +++ b/FMN.xcodeproj/project.pbxproj @@ -287,7 +287,7 @@ 66D404820ABCE52B0014F0F4 /* AutolaunchPrefpaneModule-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "AutolaunchPrefpaneModule-Info.plist"; sourceTree = ""; }; 66D405010ABCEE2D0014F0F4 /* AutolaunchPrefpaneModule.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = AutolaunchPrefpaneModule.nib; path = PreferencePane/AutolaunchPrefpaneModule.nib; sourceTree = ""; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; - 8D1107320486CEB800E47090 /* Forget-Me-Not.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Forget-Me-Not.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 8D1107320486CEB800E47090 /* Forget-Me-Not.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = "Forget-Me-Not.app"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ diff --git a/FMNAXModule.m b/FMNAXModule.m index 21c9414..b39973b 100644 --- a/FMNAXModule.m +++ b/FMNAXModule.m @@ -46,44 +46,71 @@ - (void) dealloc [super dealloc]; } +typedef int CGSConnection; + +extern OSStatus CGSGetWorkspace(const CGSConnection cid, int *workspace); +extern OSStatus CGSSetWorkspace(const CGSConnection cid, int workspace); +extern CGSConnection _CGSDefaultConnection(void); + - (NSArray *) getRestorables { - NSArray* launchedApplications = - [[NSWorkspace sharedWorkspace] launchedApplications]; - - NSEnumerator* enumerator = [launchedApplications objectEnumerator]; NSMutableArray* orientations = [NSMutableArray arrayWithCapacity : 100]; - ProcessSerialNumber psn; - NSDictionary* appInfo; - while (appInfo = [enumerator nextObject]) + int workspace = 0; + + CGSConnection cid = _CGSDefaultConnection(); + CGSGetWorkspace(cid,&workspace); + + NSDate *ws_startDate = [NSDate date]; + + int i; + for(i=0; i<20; ++i) { - NSNumber* tmp; - tmp = [appInfo objectForKey:@"NSApplicationProcessSerialNumberLow"]; - psn.lowLongOfPSN = [tmp longValue]; - tmp = [appInfo objectForKey:@"NSApplicationProcessSerialNumberHigh"]; - psn.highLongOfPSN = [tmp longValue]; - NSString *name = [appInfo objectForKey:@"NSApplicationName"]; - NSString *bundleID = [appInfo objectForKey:@"NSApplicationBundleIdentifier"]; - if (mExclusions != nil && [mExclusions containsObject:bundleID]) { - NSLog (@"Skipping excluded app: \"%@\" (%@)", name, bundleID); - continue; - } + int ws_ret = CGSSetWorkspace(cid,i); + NSLog (@"Setting workspace: %d (ret=%d)", i, ws_ret); + + NSArray* launchedApplications = + [[NSWorkspace sharedWorkspace] launchedApplications]; + NSEnumerator* enumerator = [launchedApplications objectEnumerator]; + NSDate *startDate = [NSDate date]; - @try - { - AXApplication* app = [AXApplication configWithPSN:psn appName:name]; - NSArray *appOrientations = [app getCurrentWindowOrientations]; - [orientations addObjectsFromArray : appOrientations]; - NSLog(@"%@: Got %d windows in %f seconds", name, - [appOrientations count], -[startDate timeIntervalSinceNow]); - } - @catch (NSException* ex) + ProcessSerialNumber psn; + NSDictionary* appInfo; + while (appInfo = [enumerator nextObject]) { - NSLog(@"%@: %@ (after %f seconds)", name, [ex reason], - -[startDate timeIntervalSinceNow]); + NSNumber* tmp; + tmp = [appInfo objectForKey:@"NSApplicationProcessSerialNumberLow"]; + psn.lowLongOfPSN = [tmp longValue]; + tmp = [appInfo objectForKey:@"NSApplicationProcessSerialNumberHigh"]; + psn.highLongOfPSN = [tmp longValue]; + NSString *name = [appInfo objectForKey:@"NSApplicationName"]; + NSString *bundleID = [appInfo objectForKey:@"NSApplicationBundleIdentifier"]; + if (mExclusions != nil && [mExclusions containsObject:bundleID]) { + NSLog (@"Skipping excluded app: \"%@\" (%@)", name, bundleID); + continue; + } + + @try + { + AXApplication* app = [AXApplication configWithPSN:psn appName:name]; + NSArray *appOrientations = [app getCurrentWindowOrientations]; + [orientations addObjectsFromArray : appOrientations]; + NSLog(@"%@: Got %d windows in %f seconds", name, + [appOrientations count], -[startDate timeIntervalSinceNow]); + } + @catch (NSException* ex) + { + NSLog(@"%@: %@ (after %f seconds)", name, [ex reason], + -[startDate timeIntervalSinceNow]); + } } + } + + NSLog(@"AX: Got %d windows in %f seconds", + [orientations count], -[ws_startDate timeIntervalSinceNow]); + + CGSSetWorkspace(cid,workspace); return orientations; } diff --git a/version.h b/version.h index f59b4ef..7613857 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ -#define FMN_VERSION 1.0.2 -#define FMN_VERSION_STRING "1.0.2" -#define FMN_VERSION_NSSTRING @"1.0.2" \ No newline at end of file +#define FMN_VERSION 1.0.3 +#define FMN_VERSION_STRING "1.0.3" +#define FMN_VERSION_NSSTRING @"1.0.3"