Skip to content

Commit

Permalink
More debugging info and serialization work
Browse files Browse the repository at this point in the history
This has the additional debugging info I've added to figure out the Leopard problems.  It also contains some work I did to move towards being able to save and restore configurations across an FMN reboot.  I would separate these patches but life's too short, and it does compile properly at the moment.

darcs-hash:20071105203347-759cc-927f46bda88978835694aca4b4a6a8e78f1b33b2.gz
  • Loading branch information
n8gray committed Nov 5, 2007
1 parent 0e919b7 commit 78c3064
Show file tree
Hide file tree
Showing 22 changed files with 231 additions and 25 deletions.
2 changes: 1 addition & 1 deletion AXApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import <Carbon/Carbon.h>
#import "FMNWindowGroup.h"

@interface AXApplication : NSObject<FMNWindowGroup> {
@interface AXApplication : NSObject<FMNWindowGroup,NSCoding> {
@protected AXUIElementRef appElement;
@protected ProcessSerialNumber psn;
@protected pid_t pid;
Expand Down
26 changes: 26 additions & 0 deletions AXApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,30 @@ - (void) dealloc
[super dealloc];
}

- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:appName forKey:@"AXAappName"];
[encoder encodeBytes:(const uint8_t*)&appElement
length:sizeof(AXUIElementRef)
forKey:@"AXAappElement"];
[encoder encodeInt64:(int64_t)pid forKey:@"AXApid"];
[encoder encodeBytes:(const uint8_t*)&psn
length:sizeof(ProcessSerialNumber)
forKey:@"AXApsn"];

}

- (id)initWithCoder:(NSCoder *)decoder
{
unsigned dummy;
self = [super init];
appName = [[decoder decodeObjectForKey:@"AXAappName"] retain];
appElement = *(AXUIElementRef *)[decoder decodeBytesForKey:@"AXAappElement"
returnedLength:&dummy];
pid = (pid_t)[decoder decodeInt64ForKey:@"AXApid"];
psn = *(ProcessSerialNumber *)[decoder decodeBytesForKey:@"AXApsn"
returnedLength:&dummy];
return self;
}

@end
2 changes: 1 addition & 1 deletion AXWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "FMNWindow.h"
#import "AXApplication.h"

@interface AXWindow : NSObject <FMNWindow> {
@interface AXWindow : NSObject <FMNWindow,NSCoding> {
AXUIElementRef windowElement;
AXApplication *windowApp;
}
Expand Down
30 changes: 30 additions & 0 deletions AXWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ - (void) setWindowPosition : (NSPoint) pos Context : (NSDictionary*) context
userInfo : nil
];
}
NSPoint afterPos = [self getWindowPosition];
if (afterPos.x != pos.x || afterPos.y != pos.y)
{
NSLog(@"Failed to set position of %@ ((%f, %f) != (%f, %f)), and Accessibility API lied.",
self, pos.x, pos.y, afterPos.x, afterPos.y);
}
CFRelease(value);
}

Expand All @@ -145,6 +151,12 @@ - (void) setWindowSize : (NSSize) size Context : (NSDictionary*) context
userInfo : nil
];
}
NSSize afterSize = [self getWindowSize];
if (afterSize.width != size.width || afterSize.height != size.height)
{
NSLog(@"Failed to set size of %@ ((%f, %f) != (%f, %f)), and Accessibility API lied.",
self, size.width, size.height, afterSize.width, afterSize.height);
}
CFRelease(value);
}

Expand All @@ -168,4 +180,22 @@ - (void) dealloc
[super dealloc];
}

- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:windowApp forKey:@"AXWwindowApp"];
[encoder encodeBytes:(const uint8_t*)&windowElement
length:sizeof(AXUIElementRef)
forKey:@"AXWwindowElement"];
}

- (id)initWithCoder:(NSCoder *)decoder
{
unsigned dummy;
self = [super init];
windowApp = [[decoder decodeObjectForKey:@"AXWwindowApp"] retain];
windowElement = *(AXUIElementRef *)[decoder decodeBytesForKey:@"AXWwindowElement"
returnedLength:&dummy];
return self;
}

@end
2 changes: 1 addition & 1 deletion CGDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <Cocoa/Cocoa.h>
#import "FMNDisplay.h"

@interface CGDisplay : NSObject <FMNDisplay> {
@interface CGDisplay : NSObject <FMNDisplay,NSCoding> {
@protected CGDirectDisplayID displayID;
@protected NSRect orientation;
}
Expand Down
27 changes: 27 additions & 0 deletions CGDisplay.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,31 @@ - (void) dealloc
[super dealloc];
}

- (NSString*) description
{
NSRect r = [self getDisplayOrientation];

return [NSString stringWithFormat:
@"CGDisplay 0x%x: %fx%f at (%f, %f)",
(int)displayID, r.size.width, r.size.height, r.origin.x, r.origin.y];
}

- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeBytes:(const uint8_t *)&displayID
length:sizeof(CGDirectDisplayID)
forKey:@"CGDdisplayID"];
[encoder encodeRect:orientation forKey:@"CGDorientation"];
}

- (id)initWithCoder:(NSCoder *)decoder
{
unsigned dummy;
self = [super init];
displayID = *(CGDirectDisplayID *)[decoder decodeBytesForKey:@"CGDisplayID"
returnedLength:&dummy];
orientation = [decoder decodeRectForKey:@"CGDorientation"];
return self;
}

@end
2 changes: 1 addition & 1 deletion CGDisplayConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#define CG_MAX_DISPLAYS 128

@interface CGDisplayConfiguration : NSObject<NSCopying,FMNDisplayConfiguration> {
@interface CGDisplayConfiguration : NSObject<NSCopying,FMNDisplayConfiguration,NSCoding> {
@protected NSMutableArray* displays;
@protected FMNDisplayRef mainDisplay;
}
Expand Down
12 changes: 12 additions & 0 deletions CGDisplayConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,16 @@ - (void) dealloc
[super dealloc];
}

- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:displays forKey:@"CGDCdisplays"];
}

- (id)initWithCoder:(NSCoder *)decoder
{
self = [super init];
displays = [[decoder decodeObjectForKey:@"CGDCdisplays"] retain];
return self;
}

@end
3 changes: 3 additions & 0 deletions DevelNotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ leak.

Things that still bug n8:

* Need to track which disp is main -- coordinate system origin is at top-left of
of main display.

* The "launch at login" preference doesn't require FMN to be running, so we
shouldn't disable it when FMN isn't running.

Expand Down
41 changes: 36 additions & 5 deletions FMN.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ - (void) unregisterScreenChangeNotificationHandler
FMN_CGDisplayReconfigurationCallback,self);
}

NSString* describeCurrentConfiguration() {
CGDisplayConfiguration *dc = [CGDisplayConfiguration configWithCurrent];
NSString *s = [dc description];
return s;
}

- (void) handlePreDisplayConfigurationChange
{
NSLog(@"******** Screen configuration about to be changed! ********");
NSLog(@"Current configuration: %@", describeCurrentConfiguration());
NSDate *startDate = [NSDate date];

// Save the current restorables
Expand Down Expand Up @@ -105,6 +112,7 @@ - (NSDictionary*) getRestorationContext : (FMNDisplayConfigurationRef) previousD
- (void) handlePostDisplayConfigurationChange
{
NSLog(@"======== Screen configuration changed! ========");
NSLog(@"New configuration: %@", describeCurrentConfiguration());
NSDate *startDate = [NSDate date];
FMNDisplayConfigurationRef previousDisplayConfiguration =
currentDisplayConfiguration;
Expand Down Expand Up @@ -196,9 +204,6 @@ - (id) init
{
return nil;
}

// Initialize dictionary of screen configurations
screenConfigurations = [[NSMutableDictionary alloc] init];

// Initialize the current display configuration
currentDisplayConfiguration =
Expand All @@ -210,6 +215,11 @@ - (id) init
[[FMNModuleLoader allPluginsOfBundle:mainBundle
withProtocol:@protocol(FMNModule)] retain];

// XXX: Deserialize?

// Initialize dictionary of screen configurations
screenConfigurations = [[NSMutableDictionary alloc] init];

[self activateFMN];

return self;
Expand Down Expand Up @@ -253,6 +263,18 @@ - (void) dealloc
[super dealloc];
}

/* Archive the stored configurations */
- (BOOL) archiveDisplayConfigurationsToFile:(NSString *)path
{
return [NSKeyedArchiver archiveRootObject:screenConfigurations toFile:path];
}

/* Load stored configs from a file */
- (void) loadDisplayConfigurationsFromFile:(NSString *)path
{
screenConfigurations = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
}

@end

static void FMN_CGDisplayReconfigurationCallback (
Expand All @@ -262,11 +284,20 @@ static void FMN_CGDisplayReconfigurationCallback (
)
{
FMN* fmn = (FMN*) userInfo;
static int state = 0;

NSLog(@"Got %@display change notification on 0x%x, is %@main",
(flags & kCGDisplayBeginConfigurationFlag) ? @"pre-" : @"post-",
display, CGDisplayIsMain(display)? @"":@"not ");

// Only want to react once, not once per screen
if (!CGDisplayIsMain(display))
//if (!CGDisplayIsMain(display))
if (state == 1 || state == 2){
state++;
return;

}
state = (state + 1) % 4;

if(flags == kCGDisplayBeginConfigurationFlag)
{
[fmn handlePreDisplayConfigurationChange];
Expand Down
11 changes: 7 additions & 4 deletions FMN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
0E57434B0AA4C2B400A42972 /* Flower.icns in Resources */ = {isa = PBXBuildFile; fileRef = 0E5743490AA4C2B400A42972 /* Flower.icns */; };
660640E70ABD233800D7D5D7 /* FMNDockModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 660640E60ABD233800D7D5D7 /* FMNDockModule.m */; };
660640ED0ABD23A800D7D5D7 /* DockModule.plugin in Copy Files into Forget-Me-Not.app */ = {isa = PBXBuildFile; fileRef = 660640D90ABD227D00D7D5D7 /* DockModule.plugin */; };
660641140ABD273600D7D5D7 /* DockRestorable.h in Copy Files into Forget-Me-Not.app */ = {isa = PBXBuildFile; fileRef = 660641120ABD273600D7D5D7 /* DockRestorable.h */; };
660641150ABD273600D7D5D7 /* DockRestorable.m in Sources */ = {isa = PBXBuildFile; fileRef = 660641130ABD273600D7D5D7 /* DockRestorable.m */; };
6613E2B80A676588003DA5B2 /* FMN.m in Sources */ = {isa = PBXBuildFile; fileRef = 6613E2B70A676588003DA5B2 /* FMN.m */; };
6629992F0A6E0386005757CB /* CGDisplay.m in Sources */ = {isa = PBXBuildFile; fileRef = 6629992E0A6E0386005757CB /* CGDisplay.m */; };
Expand Down Expand Up @@ -197,7 +196,6 @@
dstSubfolderSpec = 16;
files = (
660640ED0ABD23A800D7D5D7 /* DockModule.plugin in Copy Files into Forget-Me-Not.app */,
660641140ABD273600D7D5D7 /* DockRestorable.h in Copy Files into Forget-Me-Not.app */,
);
name = "Copy Files into Forget-Me-Not.app";
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -287,7 +285,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; includeInIndex = 0; lastKnownFileType = wrapper.application; path = "Forget-Me-Not.app"; sourceTree = BUILT_PRODUCTS_DIR; };
8D1107320486CEB800E47090 /* Forget-Me-Not.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Forget-Me-Not.app"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -663,9 +661,11 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "FMN" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 29B97314FDCFA39411CA2CEA /* FMN */;
projectDirPath = "";
projectRoot = "";
targets = (
8D1107260486CEB800E47090 /* Forget-Me-Not App */,
0E4DE4A40A9BCADA001C9EEF /* AXModule */,
Expand Down Expand Up @@ -1276,15 +1276,16 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_OTHER_PREPROCESSOR_FLAGS = "-C";
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 All @@ -1297,7 +1298,9 @@
ppc,
i386,
);
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_OTHER_PREPROCESSOR_FLAGS = "-C";
INFOPLIST_PREFIX_HEADER = version.h;
Expand Down
4 changes: 3 additions & 1 deletion FMNAXModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "FMNAXModule.h"
#import "AXApplication.h"

#define MAX_WORKSPACE 16

@implementation FMNAXModule

- (void) setExclusions:(NSArray *)ex
Expand Down Expand Up @@ -63,7 +65,7 @@ - (NSArray *) getRestorables
NSDate *ws_startDate = [NSDate date];

int i;
for(i=0; i<20; ++i)
for(i=0; i<MAX_WORKSPACE; ++i)
{
int ws_ret = CGSSetWorkspace(cid,i);
NSLog (@"Setting workspace: %d (ret=%d)", i, ws_ret);
Expand Down
4 changes: 2 additions & 2 deletions FMNDisplayConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@protocol FMNDisplayConfiguration

+ (id<NSObject,NSCopying,FMNDisplayConfiguration>) configWithCurrent;
+ (id<NSObject,NSCopying,FMNDisplayConfiguration,NSCoding>) configWithCurrent;

- (unsigned) getDisplayCount;
- (FMNDisplayRef) getMainDisplay;
Expand All @@ -21,5 +21,5 @@

@end

typedef id<NSObject,NSCopying,FMNDisplayConfiguration>
typedef id<NSObject,NSCopying,FMNDisplayConfiguration,NSCoding>
FMNDisplayConfigurationRef;
2 changes: 1 addition & 1 deletion FMNWindowOrientation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "FMNWindow.h"
#import "FMNRestorable.h"

@interface FMNWindowOrientation : NSObject <FMNRestorable> {
@interface FMNWindowOrientation : NSObject <FMNRestorable,NSCoding> {
@protected NSPoint position;
@protected NSSize size;
@protected FMNWindowRef window;
Expand Down
16 changes: 16 additions & 0 deletions FMNWindowOrientation.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,20 @@ - (void) dealloc
[super dealloc];
}

- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodePoint:position forKey:@"FMNWOposition"];
[encoder encodeSize:size forKey:@"FMNWOsize"];
[encoder encodeObject:window forKey:@"FMNWOwindow"];
}

- (id)initWithCoder:(NSCoder *)decoder
{
self = [super init];
position = [decoder decodePointForKey:@"FMNWOposition"];
size = [decoder decodeSizeForKey:@"FMNWOsize"];
window = [[decoder decodeObjectForKey:@"FMNWOwindow"] retain];
return self;
}

@end
Loading

0 comments on commit 78c3064

Please sign in to comment.