Skip to content

Commit

Permalink
Virtual desktop support
Browse files Browse the repository at this point in the history
Added support for restoring windows on multiple desktops. Right now, FMN scans the first 20 desktops for windows by default; in the future, however, we may want to make this configurable (especially if Apple does not fix the bug in the Accessibility API that necessitates this fix in the first place).

darcs-hash:20070717191913-3181a-c4a84204b1715fa38bf15bdd15ae928e48f98fba.gz
  • Loading branch information
dnoblet committed Jul 17, 2007
1 parent 84dfd4c commit 5053cfd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 33 deletions.
2 changes: 1 addition & 1 deletion FMN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
66D404820ABCE52B0014F0F4 /* AutolaunchPrefpaneModule-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "AutolaunchPrefpaneModule-Info.plist"; sourceTree = "<group>"; };
66D405010ABCEE2D0014F0F4 /* AutolaunchPrefpaneModule.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = AutolaunchPrefpaneModule.nib; path = PreferencePane/AutolaunchPrefpaneModule.nib; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
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 */
Expand Down
85 changes: 56 additions & 29 deletions FMNAXModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define FMN_VERSION 1.0.2
#define FMN_VERSION_STRING "1.0.2"
#define FMN_VERSION_NSSTRING @"1.0.2"
#define FMN_VERSION 1.0.3
#define FMN_VERSION_STRING "1.0.3"
#define FMN_VERSION_NSSTRING @"1.0.3"

0 comments on commit 5053cfd

Please sign in to comment.