Skip to content

Commit

Permalink
Dock Autohide Module
Browse files Browse the repository at this point in the history
This commit adds a new module that adds the ability for FMN to store/restore the "autohide" status of the Dock.

NOTE: Right now, the module does not have a corresponding user-interface component, so it is always enabled.

darcs-hash:20060917211218-3181a-5465d085477f0761e92801068875debcc680be7c.gz
  • Loading branch information
dnoblet committed Sep 17, 2006
1 parent b5197d4 commit c3b5319
Show file tree
Hide file tree
Showing 10 changed files with 432 additions and 2 deletions.
22 changes: 22 additions & 0 deletions DockModule-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.DockModule</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>NSPrincipalClass</key>
<string>FMNDockModule</string>
</dict>
</plist>
19 changes: 19 additions & 0 deletions DockRestorable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// DockRestorable.h
// FMN
//
// Created by David Noblet on 9/16/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "FMNRestorable.h"

@interface DockRestorable : NSObject<FMNRestorable> {
//NSDictionary* dockPrefs;
Boolean autohidePref;
}

- (id) initWithCurrent;

@end
148 changes: 148 additions & 0 deletions DockRestorable.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
//
// DockRestorable.m
// FMN
//
// Created by David Noblet on 9/16/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//

#import "DockRestorable.h"

#define DOCK CFSTR("com.apple.dock")
#define USER kCFPreferencesCurrentUser
#define HOST kCFPreferencesAnyHost
#define AUTOHIDE CFSTR("autohide")

@implementation DockRestorable

/*- (void) logDockPrefs
{
NSEnumerator *enumerator = [dockPrefs keyEnumerator];
id key;

while ((key = [enumerator nextObject]))
{
id value = [dockPrefs valueForKey: key];
NSLog(@"@@@@@@@@@@ Key: '%@'; Value: '%@' @@@@@@@@@@@@@", key, value);
}
}*/

+ (Boolean) getDockAutohide
{
Boolean success;
return CFPreferencesGetAppBooleanValue (
AUTOHIDE,
DOCK,
&success
) && success;
}

- (id) initWithCurrent
{
self = [super init];
if(!self)
return nil;

NSLog(@"Storing Dock Preferences");

CFPreferencesAppSynchronize(DOCK);

/*NSArray* keys;
keys = (NSArray*) CFPreferencesCopyKeyList (
DOCK,
USER,
HOST
);

dockPrefs = (NSDictionary*) CFPreferencesCopyMultiple (
(CFArrayRef) keys,
DOCK,
USER,
HOST
);
[keys release];*/

autohidePref = [DockRestorable getDockAutohide];

NSLog(@"Storing Dock Autohide Preference: %d",autohidePref);

//[self logDockPrefs];

return self;
}

- (void) restore
{
NSLog(@"Restoring Dock Preferences");
/*[self logDockPrefs];

CFPreferencesSetMultiple (
(CFDictionaryRef) dockPrefs,
nil,
DOCK,
USER,
HOST
);*/

NSLog(@"Restoring Dock Autohide Preference: %d",autohidePref);

if([DockRestorable getDockAutohide] != autohidePref)
{
CFPreferencesSetValue(
AUTOHIDE,
autohidePref ? kCFBooleanTrue : kCFBooleanFalse,
DOCK,
USER,
HOST
);

CFPreferencesAppSynchronize(DOCK);

/*CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
CFNotificationCenterPostNotification (
center,
CFSTR("com.apple.dock.prefchanged"),
DOCK,
nil, true
);*/

/*
tell application "System Events"
keystroke "d" using {command down, option down}
end tell
*/

NSString *s = [NSString stringWithFormat:
@"tell application \"System Events\"\n"
@"\tkeystroke \"d\" using {command down, option down}\n"
@"end tell\n"];
NSAppleScript *scriptObj = [[NSAppleScript alloc] initWithSource:s];
if (scriptObj)
{
NSDictionary *errInfo;
NSAppleEventDescriptor *aed = [scriptObj executeAndReturnError:&errInfo];
[scriptObj release];
if (!aed)
{
NSLog(@"Got Error in deleteLoginItem");
}
}
}
}

- (int) priority
{
// We want this to be restored before the window positions and sizes
return kRestorableDefaultPriority+1;
}

- (void) dealloc
{
/*if(dockPrefs)
{
[dockPrefs release];
}*/
[super dealloc];
}

@end
25 changes: 24 additions & 1 deletion FMN.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ - (void) handlePreDisplayConfigurationChange
-[startDate timeIntervalSinceNow]);
}

int restorableCompare(id a, id b, void* c)
{
FMNRestorableRef r1 = (FMNRestorableRef)a;
FMNRestorableRef r2 = (FMNRestorableRef)b;

int p1 = [r1 priority];
int p2 = [r2 priority];

if(p1 > p2)
{
return NSOrderedAscending;
}
else if (p1 == p2)
{
return NSOrderedSame;
}

return NSOrderedDescending;
}

- (void) handlePostDisplayConfigurationChange
{
NSLog(@"======== Screen configuration changed! ========");
Expand All @@ -77,7 +97,7 @@ - (void) handlePostDisplayConfigurationChange
[[CGDisplayConfiguration configWithCurrent] retain];

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

if (!restorables)
Expand All @@ -87,6 +107,9 @@ - (void) handlePostDisplayConfigurationChange
return;
}

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

NSEnumerator* enumerator = [restorables objectEnumerator];
FMNRestorableRef restorable;
while (restorable = [enumerator nextObject])
Expand Down
Loading

0 comments on commit c3b5319

Please sign in to comment.