|
| 1 | +#import "SSYBackgroundAwareWindow.h" |
| 2 | +#import "SSYProcessTyper.h" |
| 3 | + |
| 4 | +@implementation SSYBackgroundAwareWindow |
| 5 | + |
| 6 | +- (BOOL)keepHidden { |
| 7 | + return ([SSYProcessTyper currentType] != SSYProcessTyperTypeForeground) ; |
| 8 | +} |
| 9 | + |
| 10 | +- (BOOL)canBecomeKeyWindow { |
| 11 | + if ([self keepHidden]) { |
| 12 | + return NO ; |
| 13 | + } |
| 14 | + return [super canBecomeKeyWindow] ; |
| 15 | +} |
| 16 | + |
| 17 | +- (BOOL)canBecomeMainWindow { |
| 18 | + if ([self keepHidden]) { |
| 19 | + return NO ; |
| 20 | + } |
| 21 | + return [super canBecomeMainWindow] ; |
| 22 | +} |
| 23 | + |
| 24 | +#if 0 |
| 25 | +#warning Experimenting with More Windowlessness |
| 26 | +// I found it not necessary to override these methods, so I didn't. |
| 27 | +// But maybe I didn't find all the corner cases. Someday, I might? |
| 28 | + |
| 29 | +/* |
| 30 | + @brief Override which becomes a no-op if the the current process is not a |
| 31 | + foreground process (currentType != SSYProcessTyperTypeForeground), otherwise |
| 32 | + invokes super |
| 33 | + */ |
| 34 | +- (void)displayIfNeeded { |
| 35 | + if ([self keepHidden]) { |
| 36 | + return ; |
| 37 | + } |
| 38 | + [super displayIfNeeded] ; |
| 39 | +} |
| 40 | + |
| 41 | +- (void)display { |
| 42 | + if ([self keepHidden]) { |
| 43 | + return ; |
| 44 | + } |
| 45 | + [super display] ; |
| 46 | +} |
| 47 | + |
| 48 | +- (void)orderFrontRegardless { |
| 49 | + if ([self keepHidden]) { |
| 50 | + return ; |
| 51 | + } |
| 52 | + [super orderFrontRegardless] ; |
| 53 | +} |
| 54 | + |
| 55 | +- (void)orderFront:(id)sender { |
| 56 | + if ([self keepHidden]) { |
| 57 | + return ; |
| 58 | + } |
| 59 | + [super display] ; |
| 60 | +} |
| 61 | + |
| 62 | +- (void)orderBack:(id)sender { |
| 63 | + if ([self keepHidden]) { |
| 64 | + return ; |
| 65 | + } |
| 66 | + [super orderFront:sender] ; |
| 67 | +} |
| 68 | + |
| 69 | +- (void)makeMainWindow { |
| 70 | + if ([self keepHidden]) { |
| 71 | + return ; |
| 72 | + } |
| 73 | + [super makeMainWindow] ; |
| 74 | +} |
| 75 | + |
| 76 | +- (void)makeKeyWindow { |
| 77 | + if ([self keepHidden]) { |
| 78 | + return ; |
| 79 | + } |
| 80 | + [super makeKeyWindow] ; |
| 81 | +} |
| 82 | + |
| 83 | +- (void)makeKeyAndOrderFront:(id)sender { |
| 84 | + if ([self keepHidden]) { |
| 85 | + return ; |
| 86 | + } |
| 87 | + [super makeKeyAndOrderFront:sender] ; |
| 88 | +} |
| 89 | + |
| 90 | +- (void)orderWindow:(NSWindowOrderingMode)orderingMode relativeTo:(NSInteger)otherWindowNumber { |
| 91 | + if ([self keepHidden]) { |
| 92 | + return ; |
| 93 | + } |
| 94 | + [super orderWindow:orderingMode relativeTo:otherWindowNumber] ; |
| 95 | +} |
| 96 | + |
| 97 | +#endif |
| 98 | + |
| 99 | +@end |
0 commit comments