Skip to content

Commit

Permalink
Leopard Updates
Browse files Browse the repository at this point in the history
darcs-hash:20071103032051-3181a-54aff581b06742e796fa37933fff56892aa34557.gz
  • Loading branch information
dnoblet committed Nov 3, 2007
1 parent 5053cfd commit 0e919b7
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 22 deletions.
18 changes: 13 additions & 5 deletions AXWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,16 @@ - (NSSize) getWindowSize
return size;
}

- (void) setWindowPosition : (NSPoint) pos
- (void) setWindowPosition : (NSPoint) pos Context : (NSDictionary*) context
{
NSNumber* off_x =
(NSNumber*) [context objectForKey:@"com.fmn.x-coordinate-offset"];
NSNumber* off_y =
(NSNumber*) [context objectForKey:@"com.fmn.y-coordinate-offset"];

pos.x += [off_x floatValue];
pos.y += [off_y floatValue];

CFTypeRef value;
value = AXValueCreate(kAXValueCGPointType,&pos);
if(AXUIElementSetAttributeValue(windowElement,kAXPositionAttribute,value)
Expand All @@ -119,7 +127,7 @@ - (void) setWindowPosition : (NSPoint) pos
CFRelease(value);
}

- (void) setWindowSize : (NSSize) size
- (void) setWindowSize : (NSSize) size Context : (NSDictionary*) context
{
CFTypeRef value;
value = AXValueCreate(kAXValueCGSizeType,&size);
Expand All @@ -140,10 +148,10 @@ - (void) setWindowSize : (NSSize) size
CFRelease(value);
}

- (void) setWindowSize : (NSSize) size Position : (NSPoint) pos
- (void) setWindowSize : (NSSize) size Position : (NSPoint) pos Context : (NSDictionary*) context
{
[self setWindowPosition : pos];
[self setWindowSize : size];
[self setWindowPosition : pos Context : context];
[self setWindowSize : size Context : context];
}

- (void) dealloc
Expand Down
1 change: 1 addition & 0 deletions CGDisplayConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@interface CGDisplayConfiguration : NSObject<NSCopying,FMNDisplayConfiguration> {
@protected NSMutableArray* displays;
@protected FMNDisplayRef mainDisplay;
}

@end
17 changes: 17 additions & 0 deletions CGDisplayConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ - (id) initWithCurrent
if (![super init])
return nil;

mainDisplay = 0;
displays = 0;

int i;
Expand All @@ -39,6 +40,9 @@ - (id) initWithCurrent
{
[displays addObject: [[[CGDisplay alloc] initWithDisplayID:
screenList_p[i]] autorelease]];
if(CGDisplayIsMain(screenList_p[i]))
mainDisplay = [[CGDisplay alloc] initWithDisplayID:
screenList_p[i]];
}
[displays sortUsingSelector : @selector(compare:)];

Expand All @@ -60,6 +64,11 @@ - (FMNDisplayRef) getDisplay : (unsigned) i
return [displays objectAtIndex : i];
}

- (FMNDisplayRef) getMainDisplay
{
return mainDisplay;
}

- (BOOL) isEqual : (id) obj
{
//return [self hash] == [obj hash];
Expand All @@ -79,6 +88,9 @@ - (BOOL) isEqual : (id) obj

int i;

if(![[self getMainDisplay] isEqual : [display getMainDisplay]])
return NO;

for(i=0; i<display_count; ++i)
{
if(![[self getDisplay : i] isEqual : [display getDisplay : i]])
Expand Down Expand Up @@ -117,6 +129,11 @@ - (id) copyWithZone : (NSZone *) zone

- (void) dealloc
{
if(mainDisplay)
{
[mainDisplay release];
}

if(displays)
{
[displays release];
Expand Down
2 changes: 1 addition & 1 deletion DockRestorable.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ - (id) initWithCurrent
return self;
}

- (void) restore
- (void) restoreWithContext : (NSDictionary*) context
{
NSLog(@"Restoring Dock Preferences");
/*[self logDockPrefs];
Expand Down
44 changes: 37 additions & 7 deletions FMN.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ - (void) handlePreDisplayConfigurationChange
NSDate *startDate = [NSDate date];

// Save the current restorables
NSMutableArray *restorables = [NSMutableArray arrayWithCapacity:20];
NSMutableSet *restorables = [NSMutableSet setWithCapacity:20];
NSEnumerator* enumerator = [fmnModules objectEnumerator];
FMNModuleRef module;
while (module = [enumerator nextObject]) {
Expand Down Expand Up @@ -85,38 +85,67 @@ int restorableCompare(id a, id b, void* c)
return NSOrderedDescending;
}

- (NSDictionary*) getRestorationContext : (FMNDisplayConfigurationRef) previousDisplayConfiguration
{
NSMutableDictionary* context =
[NSMutableDictionary dictionaryWithCapacity:10];

NSRect prev = [[previousDisplayConfiguration getMainDisplay] getDisplayOrientation];
NSRect curr = [[currentDisplayConfiguration getMainDisplay] getDisplayOrientation];

NSNumber* off_x = [NSNumber numberWithFloat:(prev.origin.x - curr.origin.x)];
NSNumber* off_y = [NSNumber numberWithFloat:(prev.origin.y - curr.origin.y)];

[context setObject:off_x forKey:@"com.fmn.x-coordinate-offset"];
[context setObject:off_y forKey:@"com.fmn.y-coordinate-offset"];

return context;
}

- (void) handlePostDisplayConfigurationChange
{
NSLog(@"======== Screen configuration changed! ========");
NSDate *startDate = [NSDate date];

[currentDisplayConfiguration release];
FMNDisplayConfigurationRef previousDisplayConfiguration =
currentDisplayConfiguration;

// Get the new display configuration
currentDisplayConfiguration =
[[CGDisplayConfiguration configWithCurrent] retain];

NSDictionary* restorationContext =
[self getRestorationContext : previousDisplayConfiguration];

// Try to retrieve the restorables associated with the new config
NSMutableArray* restorables =
NSMutableSet* restorableSet =
[screenConfigurations objectForKey : currentDisplayConfiguration];

if (!restorables)
if (!restorableSet)
{
NSLog(@"Encountered a new display configuration: %@",
currentDisplayConfiguration);
return;
}

NSMutableArray* restorables = [NSMutableArray arrayWithCapacity:[restorableSet count]];
NSEnumerator* set = [restorableSet objectEnumerator];

FMNRestorableRef restorable;
while(restorable = [set nextObject])
{
[restorables addObject:restorable];
}

// Sort the restorables, according to priority
[restorables sortUsingFunction:restorableCompare context:nil];

NSEnumerator* enumerator = [restorables objectEnumerator];
FMNRestorableRef restorable;

while (restorable = [enumerator nextObject])
{
@try
{
[restorable restore];
[restorable restoreWithContext : restorationContext];
}
@catch (NSException* ex)
{
Expand All @@ -129,6 +158,7 @@ - (void) handlePostDisplayConfigurationChange
currentDisplayConfiguration);
/* May want to remove the restorables from screenConfigurations at this
point -- it's just going to be discarded at the next config change */
[previousDisplayConfiguration release];
}

- (BOOL) activateFMN
Expand Down
5 changes: 5 additions & 0 deletions FMN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@
AppKit,
"-lX11",
"-lXmu",
"-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib",
);
PREBINDING = NO;
PRODUCT_NAME = X11Module;
Expand Down Expand Up @@ -1044,6 +1045,7 @@
AppKit,
"-lX11",
"-lXmu",
"-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib",
);
PREBINDING = NO;
PRODUCT_NAME = X11Module;
Expand Down Expand Up @@ -1280,6 +1282,9 @@
INFOPLIST_PREFIX_HEADER = version.h;
INFOPLIST_PREPROCESS = YES;
INFOPLIST_PREPROCESSOR_DEFINITIONS = "";
MACOSX_DEPLOYMENT_TARGET_i386 = 10.4;
MACOSX_DEPLOYMENT_TARGET_ppc = 10.4;
OTHER_LDFLAGS = "-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib";
PREBINDING = NO;
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
};
Expand Down
1 change: 1 addition & 0 deletions FMNDisplayConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
+ (id<NSObject,NSCopying,FMNDisplayConfiguration>) configWithCurrent;

- (unsigned) getDisplayCount;
- (FMNDisplayRef) getMainDisplay;
- (FMNDisplayRef) getDisplay : (unsigned) i;

- (NSString*) description;
Expand Down
2 changes: 1 addition & 1 deletion FMNRestorable.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum
*/
@protocol FMNRestorable

- (void) restore;
- (void) restoreWithContext : (NSDictionary*) context;
- (int) priority;

@end
Expand Down
6 changes: 3 additions & 3 deletions FMNWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
- (NSPoint) getWindowPosition;
- (NSSize) getWindowSize;

- (void) setWindowPosition : (NSPoint) pos;
- (void) setWindowSize : (NSSize) size;
- (void) setWindowSize : (NSSize) size Position : (NSPoint) pos;
- (void) setWindowPosition : (NSPoint) pos Context : (NSDictionary*) context;
- (void) setWindowSize : (NSSize) size Context : (NSDictionary*) context;
- (void) setWindowSize : (NSSize) size Position : (NSPoint) pos Context : (NSDictionary*) context;

@end

Expand Down
6 changes: 2 additions & 4 deletions FMNWindowOrientation.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ - (id) initWithWindow : (FMNWindowRef) win
return self;
}

- (void) restore
- (void) restoreWithContext : (NSDictionary*) context
{
/*[window setWindowPosition : position];
[window setWindowSize : size];*/
[window setWindowSize: size Position: position];
[window setWindowSize: size Position: position Context: context];
NSLog(@"Restored %@", window);
}

Expand Down
2 changes: 1 addition & 1 deletion X11Restorable.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ - (void) dealloc
[super dealloc];
}

- (void) restore
- (void) restoreWithContext : (NSDictionary*) context
{
if ([mX11Bridge openDisplay]) {
NSDate *startDate = [NSDate date];
Expand Down

0 comments on commit 0e919b7

Please sign in to comment.