Permalink
Browse files

A little 64-bit type safety in Afloat.[mh].

  • Loading branch information...
1 parent 6882a59 commit aab22e206c3c7c55774ea903d7acc72f4566958e @millenomi committed Apr 1, 2010
Showing with 34 additions and 21 deletions.
  1. +3 −3 Afloat.h
  2. +31 −18 Afloat.m
View
@@ -32,9 +32,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- (IBAction) showAdjustEffectsPanel:(id) sender;
-- (float) currentAlphaValueForWindow:(NSWindow*) w;
-- (void) setAlphaValue:(float) f forWindow:(NSWindow*) window animated:(BOOL) animate;
-- (void) setAlphaValueByDelta:(float) f forWindow:(NSWindow*) window animate:(BOOL) animate;
+- (CGFloat) currentAlphaValueForWindow:(NSWindow*) w;
+- (void) setAlphaValue:(CGFloat) f forWindow:(NSWindow*) window animated:(BOOL) animate;
+- (void) setAlphaValueByDelta:(CGFloat) f forWindow:(NSWindow*) window animate:(BOOL) animate;
- (void) setAlphaValueAnimatesOnMouseOver:(BOOL) animates forWindow:(NSWindow*) window;
- (BOOL) alphaValueAnimatesOnMouseOverForWindow:(NSWindow*) window;
View
@@ -48,6 +48,7 @@ - (void) beginTrackingWindow:(NSWindow*) w;
- (void) endTrackingWindow:(NSWindow*) w;
- (BOOL) isWindowIgnoredByAfloat:(NSWindow*) w;
+- (NSWindow*) highestWindowInHierarchyFor:(NSWindow*) w;
@end
@@ -165,13 +166,8 @@ - (NSBundle*) bundle {
- (IBAction) toggleAlwaysOnTop:(id) sender {
NSWindow* c = [self currentWindow];
- L0Log(@"window = %@ titled %@", c, [c title]);
- L0Log(@"windows = %@", [NSApp orderedWindows]);
- for (NSWindow* w in [NSApp orderedWindows]) {
- L0Log(@"titled = %@", [w title]);
- L0Log(@"visible = %d", [w isVisible]);
- }
- [self setKeptAfloat:![self isWindowKeptAfloat:c] forWindow:c showBadgeAnimation:YES];
+ if (c)
+ [self setKeptAfloat:![self isWindowKeptAfloat:c] forWindow:c showBadgeAnimation:YES];
}
- (BOOL) validateMenuItem:(NSMenuItem*) item {
@@ -237,18 +233,27 @@ - (BOOL) isWindowOnAllSpaces:(NSWindow*) w {
return [w collectionBehavior] == NSWindowCollectionBehaviorCanJoinAllSpaces;
}
+- (NSWindow*) highestWindowInHierarchyFor:(NSWindow*) w;
+{
+ while ([w parentWindow])
+ w = [w parentWindow];
+
+ return w;
+}
+
- (NSWindow*) currentWindow {
NSWindow* w;
- w = [NSApp keyWindow];
+ w = [self highestWindowInHierarchyFor:[NSApp keyWindow]];
if (![self isWindowIgnoredByAfloat:w]) return w;
- w = [NSApp mainWindow];
+ w = [self highestWindowInHierarchyFor:[NSApp mainWindow]];
if (![self isWindowIgnoredByAfloat:w]) return w;
for (NSWindow* window in [NSApp orderedWindows]) {
- if (![self isWindowIgnoredByAfloat:window])
- return window;
+ w = [self highestWindowInHierarchyFor:window];
+ if (![self isWindowIgnoredByAfloat:w])
+ return w;
}
return nil;
@@ -259,34 +264,42 @@ - (BOOL) isWindowIgnoredByAfloat:(NSWindow*) w {
}
- (IBAction) makeTranslucent:(id) sender {
- [self setAlphaValue:kAfloatTranslucentAlphaValue forWindow:[self currentWindow] animated:YES];
+ NSWindow* c = [self currentWindow];
+ if (c)
+ [self setAlphaValue:kAfloatTranslucentAlphaValue forWindow:[self currentWindow] animated:YES];
}
- (IBAction) makeOpaque:(id) sender {
- [self setAlphaValue:1.0 forWindow:[self currentWindow] animated:YES];
+ NSWindow* c = [self currentWindow];
+ if (c)
+ [self setAlphaValue:1.0 forWindow:[self currentWindow] animated:YES];
}
- (IBAction) makeMoreTransparent:(id) sender {
- [self setAlphaValueByDelta:-0.1 forWindow:[self currentWindow] animate:NO];
+ NSWindow* c = [self currentWindow];
+ if (c)
+ [self setAlphaValueByDelta:-0.1 forWindow:[self currentWindow] animate:NO];
}
- (IBAction) makeLessTransparent:(id) sender {
- [self setAlphaValueByDelta:0.1 forWindow:[self currentWindow] animate:NO];
+ NSWindow* c = [self currentWindow];
+ if (c)
+ [self setAlphaValueByDelta:0.1 forWindow:[self currentWindow] animate:NO];
}
-- (float) currentAlphaValueForWindow:(NSWindow*) window {
+- (CGFloat) currentAlphaValueForWindow:(NSWindow*) window {
id alphaValue = [AfloatStorage sharedValueForWindow:window key:kAfloatLastAlphaValueKey];
return (alphaValue)? [alphaValue floatValue] : [window alphaValue];
}
-- (void) setAlphaValueByDelta:(float) delta forWindow:(NSWindow*) window animate:(BOOL) animate {
+- (void) setAlphaValueByDelta:(CGFloat) delta forWindow:(NSWindow*) window animate:(BOOL) animate {
if (!window) return;
float a = [self currentAlphaValueForWindow:window];
[self setAlphaValue:a + delta forWindow:window animated:animate];
}
-- (void) setAlphaValue:(float) f forWindow:(NSWindow*) window animated:(BOOL) animate {
+- (void) setAlphaValue:(CGFloat) f forWindow:(NSWindow*) window animated:(BOOL) animate {
if (!window) return;
if (f > 1.0)

0 comments on commit aab22e2

Please sign in to comment.