Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added focus follows mouse #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
Build
build
TemporaryItems
.DS_Store
.DS_Store
Afloat.xcodeproj/project.xcworkspace/xcuserdata
Afloat.xcodeproj/xcuserdata
AfloatScripting/AfloatScripting.xcodeproj/xcuserdata
2 changes: 2 additions & 0 deletions Afloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- (IBAction) makeMoreTransparent:(id) sender;
- (IBAction) makeLessTransparent:(id) sender;

- (IBAction) toggleFocusFollowsMouse:(id)sender;

- (IBAction) showAdjustEffectsPanel:(id) sender;

- (CGFloat) currentAlphaValueForWindow:(NSWindow*) w;
Expand Down
26 changes: 21 additions & 5 deletions Afloat.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ - (void) install {

// Scripting support.
[self installScriptingSupport];

// Set up tracking rectangles
for(NSWindow *window in [NSApp windows]) {
[self beginTrackingWindow:window];
}
}

- (NSUInteger) indexForInstallingInMenu:(NSMenu*) m {
Expand Down Expand Up @@ -180,6 +185,8 @@ - (BOOL) validateMenuItem:(NSMenuItem*) item {
return c != nil;
} else if ([item action] == @selector(showWindowFileInFinder:))
return [[self currentWindow] representedURL]? [[[self currentWindow] representedURL] isFileURL] : NO;
else if ([item action] == @selector(toggleFocusFollowsMouse:))
[item setState:[[AfloatStorage globalValueForKey:@"FocusFollowsMouse"] boolValue] ? NSOnState : NSOffState];

return YES;
}
Expand Down Expand Up @@ -309,11 +316,6 @@ - (void) setAlphaValue:(CGFloat) f forWindow:(NSWindow*) window animated:(BOOL)

[AfloatStorage setSharedValue:[NSNumber numberWithFloat:f] window:window key:kAfloatLastAlphaValueKey];

if (f == 1.0)
[self endTrackingWindow:window];
else
[self beginTrackingWindow:window];

if (animate) {
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.3];
Expand Down Expand Up @@ -366,10 +368,18 @@ - (void) mouseEntered:(NSEvent*) e {
L0Log(@"%@", e);

[self animateFadeInForWindow:[e window]];

BOOL focusFollowsMouse = [[AfloatStorage globalValueForKey:@"FocusFollowsMouse"] boolValue];
BOOL modsDown = ([NSEvent modifierFlags] & NSCommandKeyMask) ? YES : NO;
if(focusFollowsMouse && !modsDown && ![[e window] isKeyWindow]) {
[[e window] makeKeyAndOrderFront:nil];
[NSApp activateIgnoringOtherApps:YES];
}
}

- (void) windowDidBecomeMain:(NSNotification*) n {
[self animateFadeInForWindow:[n object]];
[self beginTrackingWindow:[n object]];
}

- (void) animateFadeInForWindow:(NSWindow*) w {
Expand All @@ -390,6 +400,7 @@ - (void) mouseExited:(NSEvent*) e {

- (void) windowDidResignMain:(NSNotification*) n {
[self animateFadeOutForWindow:[n object]];
[self beginTrackingWindow:[n object]];
}

- (void) animateFadeOutForWindow:(NSWindow*) w {
Expand All @@ -406,6 +417,11 @@ - (void) animateFadeOutForWindow:(NSWindow*) w {

}

- (IBAction) toggleFocusFollowsMouse:(id)sender {
[AfloatStorage setGlobalValue:@(![[AfloatStorage globalValueForKey:@"FocusFollowsMouse"] boolValue])
forKey:@"FocusFollowsMouse"];
}

- (IBAction) showAdjustEffectsPanel:(id) sender {
NSWindow* w = [self currentWindow];
if (!w) { NSBeep(); return; }
Expand Down
9 changes: 2 additions & 7 deletions Afloat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
089C1669FE841209C02AAC07 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
LastUpgradeCheck = 0510;
};
buildConfigurationList = 1DEB913E08733D840010E9CD /* Build configuration list for PBXProject "Afloat" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -509,12 +509,10 @@
);
GCC_C_LANGUAGE_STANDARD = c99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_GC = supported;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Afloat_Prefix.pch;
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
GCC_PREPROCESSOR_DEFINITIONS = "";
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Library/Bundles";
LIBRARY_SEARCH_PATHS = (
Expand All @@ -525,7 +523,6 @@
PRODUCT_NAME = Afloat;
SDKROOT = macosx;
WRAPPER_EXTENSION = bundle;
ZERO_LINK = YES;
};
name = Debug;
};
Expand All @@ -540,8 +537,6 @@
"\"$(SRCROOT)\"",
);
GCC_C_LANGUAGE_STANDARD = c99;
GCC_ENABLE_OBJC_GC = supported;
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Afloat_Prefix.pch;
INFOPLIST_FILE = Info.plist;
Expand Down
2 changes: 1 addition & 1 deletion AfloatBadgeController.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ typedef NSUInteger AfloatBadgeType;
unsigned int enqueuedFades;
}

@property(retain) NSWindow* parentWindow;
@property(retain, nonatomic) NSWindow* parentWindow;

- (id) initAttachedToWindow:(NSWindow*) parentWindow;
+ (id) badgeControllerForWindow:(NSWindow*) w;
Expand Down
2 changes: 1 addition & 1 deletion AfloatPanelController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef enum {

- (IBAction) disableAllOverlays:(id) sender;

@property(retain) NSWindow* parentWindow;
@property(retain, nonatomic) NSWindow* parentWindow;
@property CGFloat alphaValue;
// @property(getter=isKeptAfloat) BOOL keptAfloat;
@property AfloatWindowState windowState;
Expand Down
3 changes: 3 additions & 0 deletions AfloatStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ (id) sharedValueForWindow:(NSWindow*) w key:(NSString*) k;
+ (void) setSharedValue:(id) v window:(NSWindow*) w key:(NSString*) k;

+ (id) globalValueForKey:(NSString *) k;
+ (void) setGlobalValue:(id) v forKey:(NSString *) k;

- (id) valueForWindow:(NSWindow*) w key:(NSString*) k;
- (void) setValue:(id) v forWindow:(NSWindow*) w key:(NSString*) k;

Expand Down
45 changes: 41 additions & 4 deletions AfloatStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ - (id) valueForWindow:(NSWindow*) w key:(NSString*) k {

- (void) setValue:(id) v forWindow:(NSWindow*) w key:(NSString*) k {
NSMutableDictionary* d = [self mutableDictionaryForWindow:w];
[d setObject:v forKey:k];
if(v)
[d setObject:v forKey:k];
else
[d removeObjectForKey:k];
[self saveWindowIfRequired:w];
}

Expand Down Expand Up @@ -101,9 +104,6 @@ - (BOOL) canSaveWindow:(NSWindow*) w category:(NSString**) cat key:(NSString**)
if (key) *key = [w frameAutosaveName];
return YES;
}



return NO;
}

Expand Down Expand Up @@ -155,6 +155,43 @@ + (void) setSharedValue:(id) v window:(NSWindow*) w key:(NSString*) k {
[[self sharedStorage] setValue:v forWindow:w key:k];
}

+ (void)_withGlobalStorage:(BOOL (^)(NSMutableDictionary *storage)) block
{
NSString *bundleIdentifier = [[NSBundle bundleForClass:self] bundleIdentifier];
NSString *storagePath = [[NSString stringWithFormat:@"~/Library/Preferences/%@.plist", bundleIdentifier] stringByExpandingTildeInPath];
NSDistributedLock *lock = [NSDistributedLock lockWithPath:[storagePath stringByAppendingPathExtension:@"lockfile"]];

while(![lock tryLock]) {
usleep(100);
}

NSMutableDictionary *storage = [NSMutableDictionary dictionaryWithContentsOfFile:storagePath]
?: [NSMutableDictionary new];
if(block(storage))
[storage writeToFile:storagePath atomically:YES];

[lock unlock];
}

+ (id) globalValueForKey:(NSString *) k {
__block id value;
[self _withGlobalStorage:^(NSMutableDictionary *storage) {
value = [storage objectForKey:k];
return NO;
}];
return value;
}

+ (void) setGlobalValue:(id) v forKey:(NSString *) k {
[self _withGlobalStorage:^(NSMutableDictionary *storage) {
if(v)
[storage setObject:v forKey:k];
else
[storage removeObjectForKey:k];
return YES;
}];
}

@synthesize delegate = _delegate;

@end
2 changes: 1 addition & 1 deletion AfloatWindowIdentifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ - (void) dealloc {
@synthesize category = _category, key = _key, canMatchMultipleWindows = _canMatchMultipleWindows;

+ (NSArray*) allIdentifiersForWindow:(NSWindow*) w {
NSMutableArray* results = [NSArray array];
NSMutableArray* results = [NSMutableArray array];

for (Class c in [self identifierSubclasses]) {
if ([c canInitWithWindow:w])
Expand Down
5 changes: 1 addition & 4 deletions Afloat_Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#define L0LogS(x) NSLog(@"<Afloat - DEBUG: '%s'>: " x, __func__)

#else

// this removes any "unused variables" warnings for variables
// that are only used to log debug values.
#define L0Log(x, args...) do { {args;} } while(0)
#define L0Log(x, args...) do {} while(0)
#define L0LogS(x) do {} while(0)

#endif // DEBUG
Expand Down
Loading